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:
40  {
43  VTK_DATA_ARRAY_ALIGNED_FREE=vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
45  };
46 
47  static vtkBitArray *New();
48  vtkTypeMacro(vtkBitArray,vtkDataArray);
49  void PrintSelf(ostream& os, vtkIndent indent) override;
50 
55  vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext=1000) override;
56 
60  void Initialize() override;
61 
62  // satisfy vtkDataArray API
63  int GetDataType() override {return VTK_BIT;}
64  int GetDataTypeSize() override { return 0; }
65 
69  void SetNumberOfTuples(vtkIdType number) override;
70 
77  void SetTuple(vtkIdType i, vtkIdType j,
78  vtkAbstractArray* source) override;
79 
85  vtkAbstractArray* source) override;
86 
92  void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
93  vtkAbstractArray *source) override;
94 
100  void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
101  vtkAbstractArray* source) override;
102 
109  vtkAbstractArray* source) override;
110 
115  double *GetTuple(vtkIdType i) override;
116 
120  void GetTuple(vtkIdType i, double * tuple) override;
121 
123 
126  void SetTuple(vtkIdType i, const float * tuple) override;
127  void SetTuple(vtkIdType i, const double * tuple) override;
129 
131 
135  void InsertTuple(vtkIdType i, const float * tuple) override;
136  void InsertTuple(vtkIdType i, const double * tuple) override;
138 
140 
143  vtkIdType InsertNextTuple(const float * tuple) override;
144  vtkIdType InsertNextTuple(const double * tuple) override;
146 
148 
153  void RemoveTuple(vtkIdType id) override;
154  void RemoveFirstTuple() override;
155  void RemoveLastTuple() override;
157 
164  void SetComponent(vtkIdType i, int j, double c) override;
165 
169  void Squeeze() override;
170 
174  vtkTypeBool Resize(vtkIdType numTuples) override;
175 
179  int GetValue(vtkIdType id);
180 
188  void SetNumberOfValues(vtkIdType number) override;
189 
194  void SetValue(vtkIdType id, int value);
195 
199  void InsertValue(vtkIdType id, int i);
200 
204  void SetVariantValue(vtkIdType idx, vtkVariant value) override;
205 
209  void InsertVariantValue(vtkIdType idx, vtkVariant value) override;
210 
211  vtkIdType InsertNextValue(int i);
212 
217  void InsertComponent(vtkIdType i, int j, double c) override;
218 
222  unsigned char *GetPointer(vtkIdType id)
223  { return this->Array + id/8; }
224 
230  unsigned char *WritePointer(vtkIdType id, vtkIdType number);
231 
232  void* WriteVoidPointer(vtkIdType id, vtkIdType number) override
233  {
234  return this->WritePointer(id, number);
235  }
236 
237  void *GetVoidPointer(vtkIdType id) override
238  {
239  return static_cast<void *>(this->GetPointer(id));
240  }
241 
245  void DeepCopy(vtkDataArray *da) override;
246  void DeepCopy(vtkAbstractArray* aa) override
247  { this->Superclass::DeepCopy(aa); }
248 
250 
261 #ifndef __VTK_WRAP__
262  void SetArray(unsigned char* array, vtkIdType size, int save, int deleteMethod=VTK_DATA_ARRAY_DELETE);
263 #endif
264  void SetVoidArray(void *array, vtkIdType size, int save) override
265  {
266  this->SetArray(static_cast<unsigned char *>(array), size, save);
267  }
268  void SetVoidArray(void *array, vtkIdType size, int save, int deleteMethod) override
269  {
270  this->SetArray(static_cast<unsigned char *>(array), size, save, deleteMethod);
271  }
273 
280  void SetArrayFreeFunction(void (*callback)(void *)) override;
281 
286 
288 
291  vtkIdType LookupValue(vtkVariant value) override;
292  void LookupValue(vtkVariant value, vtkIdList* ids) override;
293  vtkIdType LookupValue(int value);
294  void LookupValue(int value, vtkIdList* ids);
296 
305  void DataChanged() override;
306 
312  void ClearLookup() override;
313 
314 protected:
315  vtkBitArray();
316  ~vtkBitArray() override;
317 
318  unsigned char *Array; // pointer to data
319  unsigned char *ResizeAndExtend(vtkIdType sz);
320  // function to resize data
321 
322  int TupleSize; //used for data conversion
323  double *Tuple;
324 
325  void (*DeleteFunction)(void*);
326 
327 private:
328  // hide superclass' DeepCopy() from the user and the compiler
329  void DeepCopy(vtkDataArray &da) {this->vtkDataArray::DeepCopy(&da);}
330 
331 private:
332  vtkBitArray(const vtkBitArray&) = delete;
333  void operator=(const vtkBitArray&) = delete;
334 
335  vtkBitArrayLookup* Lookup;
336  void UpdateLookup();
337 
338 };
339 
341 {
342  this->Allocate(number);
343  this->MaxId = number - 1;
344  this->DataChanged();
345 }
346 
348 {
349  if (value)
350  {
351  this->Array[id/8] = static_cast<unsigned char>(
352  this->Array[id/8] | (0x80 >> id%8));
353  }
354  else
355  {
356  this->Array[id/8] = static_cast<unsigned char>(
357  this->Array[id/8] & (~(0x80 >> id%8)));
358  }
359  this->DataChanged();
360 }
361 
362 inline void vtkBitArray::InsertValue(vtkIdType id, int i)
363 {
364  if ( id >= this->Size )
365  {
366  if (!this->ResizeAndExtend(id+1))
367  {
368  return;
369  }
370  }
371  if (i)
372  {
373  this->Array[id/8] = static_cast<unsigned char>(
374  this->Array[id/8] | (0x80 >> id%8));
375  }
376  else
377  {
378  this->Array[id/8] = static_cast<unsigned char>(
379  this->Array[id/8] & (~(0x80 >> id%8)));
380  }
381  if ( id > this->MaxId )
382  {
383  this->MaxId = id;
384  }
385  this->DataChanged();
386 }
387 
389 {
390  this->SetValue(id, value.ToInt());
391 }
392 
394 {
395  this->InsertValue(id, value.ToInt());
396 }
397 
399 {
400  this->InsertValue (++this->MaxId,i);
401  this->DataChanged();
402  return this->MaxId;
403 }
404 
405 inline void vtkBitArray::Squeeze() {this->ResizeAndExtend (this->MaxId+1);}
406 
407 #endif
void Squeeze() override
Free any unneeded memory.
Definition: vtkBitArray.h:405
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:388
Abstract superclass for all arrays.
virtual vtkIdType LookupValue(vtkVariant value)=0
Return the value indices where a specific value appears.
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...
virtual void SetNumberOfValues(vtkIdType numValues)
Specify the number of values (tuples * components) for this object to hold.
void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Insert the tuple at srcTupleIdx in the source array into this array at dstTupleIdx.
void SetNumberOfValues(vtkIdType number) override
Fast method based setting of values without memory checks.
Definition: vtkBitArray.h:340
int vtkIdType
Definition: vtkType.h:347
int GetDataTypeSize() override
Return the size of the underlying data type.
Definition: vtkBitArray.h:64
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:362
virtual void Initialize()=0
Release storage and reset array to initial state.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void RemoveLastTuple()
These methods remove tuples from the data array.
A atomic type representing the union of many types.
Definition: vtkVariant.h:71
void SetValue(vtkIdType id, int value)
Set the data at a particular index.
Definition: vtkBitArray.h:347
int ToInt(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
int vtkTypeBool
Definition: vtkABI.h:69
void * GetVoidPointer(vtkIdType id) override
Return a void pointer.
Definition: vtkBitArray.h:237
virtual void SetComponent(vtkIdType tupleIdx, int compIdx, double value)
Set the data component at the location specified by tupleIdx and compIdx to value.
unsigned char * GetPointer(vtkIdType id)
Direct manipulation of the underlying data.
Definition: vtkBitArray.h:222
double * Tuple
Definition: vtkBitArray.h:323
unsigned char * Array
Definition: vtkBitArray.h:318
int GetDataType() override
Return the underlying data type.
Definition: vtkBitArray.h:63
virtual void ClearLookup()=0
Delete the associated fast lookup data structure on this array, if it exists.
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:393
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
virtual vtkArrayIterator * NewIterator()=0
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
void SetVoidArray(void *array, vtkIdType size, int save, int deleteMethod) override
This method lets the user specify data to be held by the array.
Definition: vtkBitArray.h:268
virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Insert a value into the array from a variant.
Abstract superclass to iterate over elements in an vtkAbstractArray.
virtual void InsertComponent(vtkIdType tupleIdx, int compIdx, double value)
Insert value at the location specified by tupleIdx and compIdx.
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
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 *)
virtual vtkTypeBool Allocate(vtkIdType numValues, vtkIdType ext=1000)=0
Allocate memory for this array.
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
Definition: vtkBitArray.h:246
virtual vtkTypeBool Resize(vtkIdType numTuples)=0
Resize the array to the requested number of tuples and preserve data.
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:36
virtual void SetArrayFreeFunction(void(*callback)(void *))=0
This method allows the user to specify a custom free function to be called when the array is dealloca...
void * WriteVoidPointer(vtkIdType id, vtkIdType number) override
Get the address of a particular data index.
Definition: vtkBitArray.h:232
vtkIdType InsertNextValue(int i)
Definition: vtkBitArray.h:398
#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.
virtual void Squeeze()=0
Free any unnecessary memory.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Set a value in the array from a variant.
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:264
virtual void RemoveFirstTuple()
These methods remove tuples from the data array.
Definition: vtkDataArray.h:253