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 =========================================================================*/
25 #ifndef vtkBitArray_h
26 #define vtkBitArray_h
27 
28 #include "vtkCommonCoreModule.h" // For export macro
29 #include "vtkDataArray.h"
30 
31 class vtkBitArrayLookup;
32 
33 class VTKCOMMONCORE_EXPORT vtkBitArray : public vtkDataArray
34 {
35 public:
36  static vtkBitArray *New();
37  vtkTypeMacro(vtkBitArray,vtkDataArray);
38  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
39 
44  int Allocate(vtkIdType sz, vtkIdType ext=1000) VTK_OVERRIDE;
45 
49  void Initialize() VTK_OVERRIDE;
50 
51  // satisfy vtkDataArray API
52  int GetDataType() VTK_OVERRIDE {return VTK_BIT;}
53  int GetDataTypeSize() VTK_OVERRIDE { return 0; }
54 
58  void SetNumberOfTuples(vtkIdType number) VTK_OVERRIDE;
59 
66  void SetTuple(vtkIdType i, vtkIdType j,
67  vtkAbstractArray* source) VTK_OVERRIDE;
68 
74  vtkAbstractArray* source) VTK_OVERRIDE;
75 
81  void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
82  vtkAbstractArray *source) VTK_OVERRIDE;
83 
89  void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
90  vtkAbstractArray* source) VTK_OVERRIDE;
91 
98  vtkAbstractArray* source) VTK_OVERRIDE;
99 
104  double *GetTuple(vtkIdType i) VTK_OVERRIDE;
105 
109  void GetTuple(vtkIdType i, double * tuple) VTK_OVERRIDE;
110 
112 
115  void SetTuple(vtkIdType i, const float * tuple) VTK_OVERRIDE;
116  void SetTuple(vtkIdType i, const double * tuple) VTK_OVERRIDE;
118 
120 
124  void InsertTuple(vtkIdType i, const float * tuple) VTK_OVERRIDE;
125  void InsertTuple(vtkIdType i, const double * tuple) VTK_OVERRIDE;
127 
129 
132  vtkIdType InsertNextTuple(const float * tuple) VTK_OVERRIDE;
133  vtkIdType InsertNextTuple(const double * tuple) VTK_OVERRIDE;
135 
137 
142  void RemoveTuple(vtkIdType id) VTK_OVERRIDE;
143  void RemoveFirstTuple() VTK_OVERRIDE;
144  void RemoveLastTuple() VTK_OVERRIDE;
146 
153  void SetComponent(vtkIdType i, int j, double c) VTK_OVERRIDE;
154 
158  void Squeeze() VTK_OVERRIDE;
159 
163  int Resize(vtkIdType numTuples) VTK_OVERRIDE;
164 
168  int GetValue(vtkIdType id);
169 
177  void SetNumberOfValues(vtkIdType number) VTK_OVERRIDE;
178 
183  void SetValue(vtkIdType id, int value);
184 
188  void InsertValue(vtkIdType id, int i);
189 
193  void SetVariantValue(vtkIdType idx, vtkVariant value) VTK_OVERRIDE;
194 
198  void InsertVariantValue(vtkIdType idx, vtkVariant value) VTK_OVERRIDE;
199 
200  vtkIdType InsertNextValue(int i);
201 
206  void InsertComponent(vtkIdType i, int j, double c) VTK_OVERRIDE;
207 
211  unsigned char *GetPointer(vtkIdType id)
212  { return this->Array + id/8; }
213 
219  unsigned char *WritePointer(vtkIdType id, vtkIdType number);
220 
221  void* WriteVoidPointer(vtkIdType id, vtkIdType number) VTK_OVERRIDE
222  {
223  return this->WritePointer(id, number);
224  }
225 
226  void *GetVoidPointer(vtkIdType id) VTK_OVERRIDE
227  {
228  return static_cast<void *>(this->GetPointer(id));
229  }
230 
234  void DeepCopy(vtkDataArray *da) VTK_OVERRIDE;
235  void DeepCopy(vtkAbstractArray* aa) VTK_OVERRIDE
236  { this->Superclass::DeepCopy(aa); }
237 
239 
248 #ifndef __VTK_WRAP__
249  void SetArray(unsigned char* array, vtkIdType size, int save);
250 #endif
251  void SetVoidArray(void *array, vtkIdType size, int save) VTK_OVERRIDE
252  {
253  this->SetArray(static_cast<unsigned char *>(array), size, save);
254  }
255  void SetVoidArray(void *array, vtkIdType size, int save,
256  int vtkNotUsed(deleteMethod)) VTK_OVERRIDE
257  {
258  this->SetArray(static_cast<unsigned char *>(array), size, save);
259  }
261 
266 
268 
271  vtkIdType LookupValue(vtkVariant value) VTK_OVERRIDE;
272  void LookupValue(vtkVariant value, vtkIdList* ids) VTK_OVERRIDE;
273  vtkIdType LookupValue(int value);
274  void LookupValue(int value, vtkIdList* ids);
276 
285  void DataChanged() VTK_OVERRIDE;
286 
292  void ClearLookup() VTK_OVERRIDE;
293 
294 protected:
295  vtkBitArray();
296  ~vtkBitArray() VTK_OVERRIDE;
297 
298  unsigned char *Array; // pointer to data
299  unsigned char *ResizeAndExtend(vtkIdType sz);
300  // function to resize data
301 
302  int TupleSize; //used for data conversion
303  double *Tuple;
304 
305  int SaveUserArray;
306 
307 private:
308  // hide superclass' DeepCopy() from the user and the compiler
309  void DeepCopy(vtkDataArray &da) {this->vtkDataArray::DeepCopy(&da);}
310 
311 private:
312  vtkBitArray(const vtkBitArray&) VTK_DELETE_FUNCTION;
313  void operator=(const vtkBitArray&) VTK_DELETE_FUNCTION;
314 
315  vtkBitArrayLookup* Lookup;
316  void UpdateLookup();
317 
318 };
319 
320 inline void vtkBitArray::SetNumberOfValues(vtkIdType number)
321 {
322  this->Allocate(number);
323  this->MaxId = number - 1;
324  this->DataChanged();
325 }
326 
328 {
329  if (value)
330  {
331  this->Array[id/8] = static_cast<unsigned char>(
332  this->Array[id/8] | (0x80 >> id%8));
333  }
334  else
335  {
336  this->Array[id/8] = static_cast<unsigned char>(
337  this->Array[id/8] & (~(0x80 >> id%8)));
338  }
339  this->DataChanged();
340 }
341 
342 inline void vtkBitArray::InsertValue(vtkIdType id, int i)
343 {
344  if ( id >= this->Size )
345  {
346  if (!this->ResizeAndExtend(id+1))
347  {
348  return;
349  }
350  }
351  if (i)
352  {
353  this->Array[id/8] = static_cast<unsigned char>(
354  this->Array[id/8] | (0x80 >> id%8));
355  }
356  else
357  {
358  this->Array[id/8] = static_cast<unsigned char>(
359  this->Array[id/8] & (~(0x80 >> id%8)));
360  }
361  if ( id > this->MaxId )
362  {
363  this->MaxId = id;
364  }
365  this->DataChanged();
366 }
367 
369 {
370  this->SetValue(id, value.ToInt());
371 }
372 
374 {
375  this->InsertValue(id, value.ToInt());
376 }
377 
379 {
380  this->InsertValue (++this->MaxId,i);
381  this->DataChanged();
382  return this->MaxId;
383 }
384 
385 inline void vtkBitArray::Squeeze() {this->ResizeAndExtend (this->MaxId+1);}
386 
387 #endif
void Squeeze() override
Free any unneeded memory.
Definition: vtkBitArray.h:385
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:368
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 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:255
int vtkIdType
Definition: vtkType.h:345
int GetDataTypeSize() override
Return the size of the underlying data type.
Definition: vtkBitArray.h:53
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:342
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:69
void SetValue(vtkIdType id, int value)
Set the data at a particular index.
Definition: vtkBitArray.h:327
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:226
a simple class to control print indentation
Definition: vtkIndent.h:33
list of point or cell ids
Definition: vtkIdList.h:30
void InsertVariantValue(vtkIdType idx, vtkVariant value) override
Inserts values from a variant and checks to ensure there is enough memory.
Definition: vtkBitArray.h:373
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
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:235
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:33
void * WriteVoidPointer(vtkIdType id, vtkIdType number) override
Get the address of a particular data index.
Definition: vtkBitArray.h:221
vtkIdType InsertNextValue(int i)
Definition: vtkBitArray.h:378
#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:251
virtual void RemoveFirstTuple()
These methods remove tuples from the data array.
Definition: vtkDataArray.h:217