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 =========================================================================*/
28 #ifndef vtkBitArray_h
29 #define vtkBitArray_h
30 
31 #include "vtkCommonCoreModule.h" // For export macro
32 #include "vtkDataArray.h"
33 
34 class vtkBitArrayLookup;
35 
36 class VTKCOMMONCORE_EXPORT vtkBitArray : public vtkDataArray
37 {
38 public:
39  static vtkBitArray *New();
40  vtkTypeMacro(vtkBitArray,vtkDataArray);
41  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
42 
47  int Allocate(vtkIdType sz, vtkIdType ext=1000) VTK_OVERRIDE;
48 
52  void Initialize() VTK_OVERRIDE;
53 
54  // satisfy vtkDataArray API
55  int GetDataType() VTK_OVERRIDE {return VTK_BIT;}
56  int GetDataTypeSize() VTK_OVERRIDE { return 0; }
57 
61  void SetNumberOfTuples(vtkIdType number) VTK_OVERRIDE;
62 
69  void SetTuple(vtkIdType i, vtkIdType j,
70  vtkAbstractArray* source) VTK_OVERRIDE;
71 
77  vtkAbstractArray* source) VTK_OVERRIDE;
78 
84  void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
85  vtkAbstractArray *source) VTK_OVERRIDE;
86 
92  void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
93  vtkAbstractArray* source) VTK_OVERRIDE;
94 
101  vtkAbstractArray* source) VTK_OVERRIDE;
102 
107  double *GetTuple(vtkIdType i) VTK_OVERRIDE;
108 
112  void GetTuple(vtkIdType i, double * tuple) VTK_OVERRIDE;
113 
115 
118  void SetTuple(vtkIdType i, const float * tuple) VTK_OVERRIDE;
119  void SetTuple(vtkIdType i, const double * tuple) VTK_OVERRIDE;
121 
123 
127  void InsertTuple(vtkIdType i, const float * tuple) VTK_OVERRIDE;
128  void InsertTuple(vtkIdType i, const double * tuple) VTK_OVERRIDE;
130 
132 
135  vtkIdType InsertNextTuple(const float * tuple) VTK_OVERRIDE;
136  vtkIdType InsertNextTuple(const double * tuple) VTK_OVERRIDE;
138 
140 
145  void RemoveTuple(vtkIdType id) VTK_OVERRIDE;
146  void RemoveFirstTuple() VTK_OVERRIDE;
147  void RemoveLastTuple() VTK_OVERRIDE;
149 
156  void SetComponent(vtkIdType i, int j, double c) VTK_OVERRIDE;
157 
161  void Squeeze() VTK_OVERRIDE;
162 
166  int Resize(vtkIdType numTuples) VTK_OVERRIDE;
167 
171  int GetValue(vtkIdType id);
172 
180  void SetNumberOfValues(vtkIdType number) VTK_OVERRIDE;
181 
186  void SetValue(vtkIdType id, int value);
187 
191  void InsertValue(vtkIdType id, int i);
192 
196  void SetVariantValue(vtkIdType idx, vtkVariant value) VTK_OVERRIDE;
197 
201  void InsertVariantValue(vtkIdType idx, vtkVariant value) VTK_OVERRIDE;
202 
203  vtkIdType InsertNextValue(int i);
204 
209  void InsertComponent(vtkIdType i, int j, double c) VTK_OVERRIDE;
210 
214  unsigned char *GetPointer(vtkIdType id)
215  { return this->Array + id/8; }
216 
222  unsigned char *WritePointer(vtkIdType id, vtkIdType number);
223 
224  void* WriteVoidPointer(vtkIdType id, vtkIdType number) VTK_OVERRIDE
225  {
226  return this->WritePointer(id, number);
227  }
228 
229  void *GetVoidPointer(vtkIdType id) VTK_OVERRIDE
230  {
231  return static_cast<void *>(this->GetPointer(id));
232  }
233 
237  void DeepCopy(vtkDataArray *da) VTK_OVERRIDE;
238  void DeepCopy(vtkAbstractArray* aa) VTK_OVERRIDE
239  { this->Superclass::DeepCopy(aa); }
240 
242 
251 #ifndef __VTK_WRAP__
252  void SetArray(unsigned char* array, vtkIdType size, int save);
253 #endif
254  void SetVoidArray(void *array, vtkIdType size, int save) VTK_OVERRIDE
255  {
256  this->SetArray(static_cast<unsigned char *>(array), size, save);
257  }
258  void SetVoidArray(void *array, vtkIdType size, int save,
259  int vtkNotUsed(deleteMethod)) VTK_OVERRIDE
260  {
261  this->SetArray(static_cast<unsigned char *>(array), size, save);
262  }
264 
269 
271 
274  vtkIdType LookupValue(vtkVariant value) VTK_OVERRIDE;
275  void LookupValue(vtkVariant value, vtkIdList* ids) VTK_OVERRIDE;
276  vtkIdType LookupValue(int value);
277  void LookupValue(int value, vtkIdList* ids);
279 
288  void DataChanged() VTK_OVERRIDE;
289 
295  void ClearLookup() VTK_OVERRIDE;
296 
297 protected:
298  vtkBitArray();
299  ~vtkBitArray() VTK_OVERRIDE;
300 
301  unsigned char *Array; // pointer to data
302  unsigned char *ResizeAndExtend(vtkIdType sz);
303  // function to resize data
304 
305  int TupleSize; //used for data conversion
306  double *Tuple;
307 
308  int SaveUserArray;
309 
310 private:
311  // hide superclass' DeepCopy() from the user and the compiler
312  void DeepCopy(vtkDataArray &da) {this->vtkDataArray::DeepCopy(&da);}
313 
314 private:
315  vtkBitArray(const vtkBitArray&) VTK_DELETE_FUNCTION;
316  void operator=(const vtkBitArray&) VTK_DELETE_FUNCTION;
317 
318  vtkBitArrayLookup* Lookup;
319  void UpdateLookup();
320 
321 };
322 
323 inline void vtkBitArray::SetNumberOfValues(vtkIdType number)
324 {
325  this->Allocate(number);
326  this->MaxId = number - 1;
327  this->DataChanged();
328 }
329 
331 {
332  if (value)
333  {
334  this->Array[id/8] = static_cast<unsigned char>(
335  this->Array[id/8] | (0x80 >> id%8));
336  }
337  else
338  {
339  this->Array[id/8] = static_cast<unsigned char>(
340  this->Array[id/8] & (~(0x80 >> id%8)));
341  }
342  this->DataChanged();
343 }
344 
345 inline void vtkBitArray::InsertValue(vtkIdType id, int i)
346 {
347  if ( id >= this->Size )
348  {
349  if (!this->ResizeAndExtend(id+1))
350  {
351  return;
352  }
353  }
354  if (i)
355  {
356  this->Array[id/8] = static_cast<unsigned char>(
357  this->Array[id/8] | (0x80 >> id%8));
358  }
359  else
360  {
361  this->Array[id/8] = static_cast<unsigned char>(
362  this->Array[id/8] & (~(0x80 >> id%8)));
363  }
364  if ( id > this->MaxId )
365  {
366  this->MaxId = id;
367  }
368  this->DataChanged();
369 }
370 
372 {
373  this->SetValue(id, value.ToInt());
374 }
375 
377 {
378  this->InsertValue(id, value.ToInt());
379 }
380 
382 {
383  this->InsertValue (++this->MaxId,i);
384  this->DataChanged();
385  return this->MaxId;
386 }
387 
388 inline void vtkBitArray::Squeeze() {this->ResizeAndExtend (this->MaxId+1);}
389 
390 #endif
void Squeeze() override
Free any unneeded memory.
Definition: vtkBitArray.h:388
virtual void DataChanged()=0
Tell the array explicitly that the data has changed.
virtual void DeepCopy(vtkAbstractArray *da)
Deep copy of data.
void SetVariantValue(vtkIdType idx, vtkVariant value) override
Set a value in the array from a variant.
Definition: vtkBitArray.h:371
Abstract superclass for all arrays.
virtual double * GetTuple(vtkIdType tupleIdx)=0
Get the data tuple at tupleIdx.
void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Set the tuple at dstTupleIdx in this array to the tuple at srcTupleIdx in the source array...
void DeepCopy(vtkPistonReference *self, vtkPistonReference *other)
void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Insert the tuple at srcTupleIdx in the source array into this array at dstTupleIdx.
void SetVoidArray(void *array, vtkIdType size, int save, int vtkNotUsed(deleteMethod)) override
This method lets the user specify data to be held by the array.
Definition: vtkBitArray.h:258
int vtkIdType
Definition: vtkType.h:287
int GetDataTypeSize() override
Return the size of the underlying data type.
Definition: vtkBitArray.h:56
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
void InsertValue(vtkIdType id, int i)
Inserts values and checks to make sure there is enough memory.
Definition: vtkBitArray.h:345
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
A atomic type representing the union of many types.
Definition: vtkVariant.h:75
void SetValue(vtkIdType id, int value)
Set the data at a particular index.
Definition: vtkBitArray.h:330
int ToInt(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
void * GetVoidPointer(vtkIdType id) override
Return a void pointer.
Definition: vtkBitArray.h:229
a simple class to control print indentation
Definition: vtkIndent.h:39
list of point or cell ids
Definition: vtkIdList.h:36
void InsertVariantValue(vtkIdType idx, vtkVariant value) override
Inserts values from a variant and checks to ensure there is enough memory.
Definition: vtkBitArray.h:376
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
virtual VTK_NEWINSTANCE vtkArrayIterator * NewIterator()=0
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
Abstract superclass to iterate over elements in an vtkAbstractArray.
vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Insert the tuple from srcTupleIdx in the source array at the end of this array.
#define VTK_NEWINSTANCE
virtual int Allocate(vtkIdType numValues, vtkIdType ext=1000)=0
Allocate memory for this array.
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
Definition: vtkBitArray.h:238
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:36
void * WriteVoidPointer(vtkIdType id, vtkIdType number) override
Get the address of a particular data index.
Definition: vtkBitArray.h:224
vtkIdType InsertNextValue(int i)
Definition: vtkBitArray.h:381
#define VTK_BIT
Definition: vtkType.h:48
virtual void RemoveTuple(vtkIdType tupleIdx)=0
These methods remove tuples from the data array.
void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, vtkAbstractArray *source) override
Copy the tuples indexed in srcIds from the source array to the tuple locations indexed by dstIds in t...
virtual void SetNumberOfTuples(vtkIdType numTuples)=0
Set the number of tuples (a component group) in the array.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
void SetVoidArray(void *array, vtkIdType size, int save) override
This method lets the user specify data to be held by the array.
Definition: vtkBitArray.h:254
virtual void RemoveFirstTuple()
These methods remove tuples from the data array.
Definition: vtkDataArray.h:223