VTK
vtkBitArray.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkBitArray.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
27 #ifndef vtkBitArray_h
28 #define vtkBitArray_h
29 
30 #include "vtkCommonCoreModule.h" // For export macro
31 #include "vtkDataArray.h"
32 
33 class vtkBitArrayLookup;
34 
36 {
37 public:
38  static vtkBitArray *New();
39  vtkTypeMacro(vtkBitArray,vtkDataArray);
40  void PrintSelf(ostream& os, vtkIndent indent);
41 
44  int Allocate(vtkIdType sz, vtkIdType ext=1000);
45 
47  void Initialize();
48 
49  // satisfy vtkDataArray API
50  int GetDataType() {return VTK_BIT;};
51  int GetDataTypeSize() { return 0; }
52 
54  void SetNumberOfTuples(vtkIdType number);
55 
61  virtual void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source);
62 
67 
69 
72  virtual void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
75 
77 
80  virtual void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
83 
88 
91  double *GetTuple(vtkIdType i);
92 
94  void GetTuple(vtkIdType i, double * tuple);
95 
97 
98  void SetTuple(vtkIdType i, const float * tuple);
99  void SetTuple(vtkIdType i, const double * tuple);
101 
103 
105  void InsertTuple(vtkIdType i, const float * tuple);
106  void InsertTuple(vtkIdType i, const double * tuple);
108 
110 
112  vtkIdType InsertNextTuple(const float * tuple);
113  vtkIdType InsertNextTuple(const double * tuple);
115 
117 
120  virtual void RemoveTuple(vtkIdType id);
121  virtual void RemoveFirstTuple();
122  virtual void RemoveLastTuple();
124 
129  void SetComponent(vtkIdType i, int j, double c);
130 
132  void Squeeze();
133 
135  virtual int Resize(vtkIdType numTuples);
136 
138  int GetValue(vtkIdType id);
139 
145  void SetNumberOfValues(vtkIdType number);
146 
149  void SetValue(vtkIdType id, int value);
150 
152  void InsertValue(vtkIdType id, int i);
153 
156 
160 
161  vtkIdType InsertNextValue(int i);
162 
166  virtual void InsertComponent(vtkIdType i, int j, double c);
167 
169  unsigned char *GetPointer(vtkIdType id) {return this->Array + id/8;}
170 
172 
175  unsigned char *WritePointer(vtkIdType id, vtkIdType number);
177  { return this->WritePointer(id, number); }
179  {
180  return static_cast<void *>(this->GetPointer(id));
181  }
183 
185 
186  void DeepCopy(vtkDataArray *da);
188  { this->Superclass::DeepCopy(aa); }
190 
192 
199 #ifndef __WRAP__
200  void SetArray(unsigned char* array, vtkIdType size, int save);
201 #endif
202  void SetVoidArray(void *array, vtkIdType size, int save)
203  {
204  this->SetArray(static_cast<unsigned char *>(array), size, save);
205  }
207 
210 
212 
214  virtual void LookupValue(vtkVariant value, vtkIdList* ids);
216  void LookupValue(int value, vtkIdList* ids);
218 
225  virtual void DataChanged();
226 
230  virtual void ClearLookup();
231 
232 protected:
233  vtkBitArray();
234  ~vtkBitArray();
235 
236  unsigned char *Array; // pointer to data
237  unsigned char *ResizeAndExtend(vtkIdType sz);
238  // function to resize data
239 
240  int TupleSize; //used for data conversion
241  double *Tuple;
242 
244 
245 private:
246  // hide superclass' DeepCopy() from the user and the compiler
247  void DeepCopy(vtkDataArray &da) {this->vtkDataArray::DeepCopy(&da);}
248 
249 private:
250  vtkBitArray(const vtkBitArray&); // Not implemented.
251  void operator=(const vtkBitArray&); // Not implemented.
252 
253  //BTX
254  vtkBitArrayLookup* Lookup;
255  void UpdateLookup();
256  //ETX
257 };
258 
260 {
261  this->Allocate(number);
262  this->MaxId = number - 1;
263  this->DataChanged();
264 }
265 
267 {
268  if (value)
269  {
270  this->Array[id/8] = static_cast<unsigned char>(
271  this->Array[id/8] | (0x80 >> id%8));
272  }
273  else
274  {
275  this->Array[id/8] = static_cast<unsigned char>(
276  this->Array[id/8] & (~(0x80 >> id%8)));
277  }
278  this->DataChanged();
279 }
280 
281 inline void vtkBitArray::InsertValue(vtkIdType id, int i)
282 {
283  if ( id >= this->Size )
284  {
285  if (!this->ResizeAndExtend(id+1))
286  {
287  return;
288  }
289  }
290  if (i)
291  {
292  this->Array[id/8] = static_cast<unsigned char>(
293  this->Array[id/8] | (0x80 >> id%8));
294  }
295  else
296  {
297  this->Array[id/8] = static_cast<unsigned char>(
298  this->Array[id/8] & (~(0x80 >> id%8)));
299  }
300  if ( id > this->MaxId )
301  {
302  this->MaxId = id;
303  }
304  this->DataChanged();
305 }
306 
308 {
309  this->SetValue(id, value.ToInt());
310 }
311 
313 {
314  this->InsertValue(id, value.ToInt());
315 }
316 
318 {
319  this->InsertValue (++this->MaxId,i);
320  this->DataChanged();
321  return this->MaxId;
322 }
323 
324 inline void vtkBitArray::Squeeze() {this->ResizeAndExtend (this->MaxId+1);}
325 
326 #endif
327 
virtual void DataChanged()
virtual double * GetTuple(vtkIdType i)=0
void SetVoidArray(void *array, vtkIdType size, int save)
Definition: vtkBitArray.h:202
virtual void DeepCopy(vtkAbstractArray *aa)
void InsertVariantValue(vtkIdType idx, vtkVariant value)
Definition: vtkBitArray.h:312
virtual void DataChanged()=0
virtual void DeepCopy(vtkAbstractArray *da)
Abstract superclass for all arrays.
virtual vtkIdType LookupValue(vtkVariant value)=0
#define VTKCOMMONCORE_EXPORT
virtual void RemoveFirstTuple()=0
virtual void SetNumberOfTuples(vtkIdType number)=0
virtual void InsertVariantValue(vtkIdType idx, vtkVariant value)=0
virtual void InsertComponent(vtkIdType i, int j, double c)
int vtkIdType
Definition: vtkType.h:247
void InsertValue(vtkIdType id, int i)
Definition: vtkBitArray.h:281
virtual void Initialize()=0
A atomic type representing the union of many types.
Definition: vtkVariant.h:78
void SetValue(vtkIdType id, int value)
Definition: vtkBitArray.h:266
int ToInt(bool *valid) const
virtual int Allocate(vtkIdType sz, vtkIdType ext=1000)=0
virtual void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source)=0
unsigned char * GetPointer(vtkIdType id)
Definition: vtkBitArray.h:169
double * Tuple
Definition: vtkBitArray.h:241
unsigned char * Array
Definition: vtkBitArray.h:236
void SetNumberOfValues(vtkIdType number)
Definition: vtkBitArray.h:259
virtual void ClearLookup()=0
a simple class to control print indentation
Definition: vtkIndent.h:38
virtual void RemoveLastTuple()=0
void SetVariantValue(vtkIdType idx, vtkVariant value)
Definition: vtkBitArray.h:307
void DeepCopy(vtkAbstractArray *aa)
Definition: vtkBitArray.h:187
list of point or cell ids
Definition: vtkIdList.h:35
virtual int Resize(vtkIdType numTuples)=0
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
virtual vtkArrayIterator * NewIterator()=0
int GetDataTypeSize()
Definition: vtkBitArray.h:51
Abstract superclass to iterate over elements in an vtkAbstractArray.
virtual void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source)=0
int GetDataType()
Definition: vtkBitArray.h:50
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
unsigned char * ResizeAndExtend(vtkIdType sz)
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:35
void * GetVoidPointer(vtkIdType id)
Definition: vtkBitArray.h:178
int Allocate(vtkIdType sz, vtkIdType ext=1000)
int SaveUserArray
Definition: vtkBitArray.h:243
virtual void SetComponent(vtkIdType i, int j, double c)
vtkIdType InsertNextValue(int i)
Definition: vtkBitArray.h:317
#define VTK_BIT
Definition: vtkType.h:25
void PrintSelf(ostream &os, vtkIndent indent)
void Squeeze()
Definition: vtkBitArray.h:324
virtual void RemoveTuple(vtkIdType id)=0
virtual void Squeeze()=0
virtual void SetVariantValue(vtkIdType idx, vtkVariant value)=0
static vtkObject * New()
void * WriteVoidPointer(vtkIdType id, vtkIdType number)
Definition: vtkBitArray.h:176
virtual vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray *source)=0
virtual void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, vtkAbstractArray *source)=0