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 
292  void LookupValue(vtkVariant value, vtkIdList* ids) override;
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
vtkAbstractArray::SetArrayFreeFunction
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...
vtkAbstractArray::Initialize
virtual void Initialize()=0
Release storage and reset array to initial state.
vtkAbstractArray::LookupValue
virtual vtkIdType LookupValue(vtkVariant value)=0
Return the value indices where a specific value appears.
vtkBitArray::SetVoidArray
void SetVoidArray(void *array, vtkIdType size, int save) override
Definition: vtkBitArray.h:264
vtkAbstractArray::Squeeze
virtual void Squeeze()=0
Free any unnecessary memory.
vtkAbstractArray::DeleteMethod
DeleteMethod
Definition: vtkAbstractArray.h:333
vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE
Definition: vtkAbstractArray.h:337
vtkAbstractArray::NewIterator
virtual vtkArrayIterator * NewIterator()=0
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
vtkDataArray::InsertTuple
void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Insert the tuple at srcTupleIdx in the source array into this array at dstTupleIdx.
vtkBitArray::Squeeze
void Squeeze() override
Free any unneeded memory.
Definition: vtkBitArray.h:405
vtkX3D::value
Definition: vtkX3D.h:220
vtkAbstractArray::VTK_DATA_ARRAY_DELETE
Definition: vtkAbstractArray.h:336
vtkBitArray::SetNumberOfValues
void SetNumberOfValues(vtkIdType number) override
Fast method based setting of values without memory checks.
Definition: vtkBitArray.h:340
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkDataArray::RemoveLastTuple
virtual void RemoveLastTuple()
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkAbstractArray::SetNumberOfTuples
virtual void SetNumberOfTuples(vtkIdType numTuples)=0
Set the number of tuples (a component group) in the array.
save
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
Definition: vtkVariantBoostSerialization.h:65
vtkAbstractArray::Size
vtkIdType Size
Definition: vtkAbstractArray.h:687
vtkAbstractArray::VTK_DATA_ARRAY_FREE
Definition: vtkAbstractArray.h:335
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
vtkBitArray::Tuple
double * Tuple
Definition: vtkBitArray.h:323
vtkDataArray::InsertTuples
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...
vtkBitArray::GetPointer
unsigned char * GetPointer(vtkIdType id)
Direct manipulation of the underlying data.
Definition: vtkBitArray.h:222
vtkDataArray::GetTuple
virtual double * GetTuple(vtkIdType tupleIdx)=0
Get the data tuple at tupleIdx.
vtkAbstractArray::Allocate
virtual vtkTypeBool Allocate(vtkIdType numValues, vtkIdType ext=1000)=0
Allocate memory for this array.
vtkAbstractArray::InsertVariantValue
virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Insert a value into the array from a variant.
vtkBitArray::GetDataTypeSize
int GetDataTypeSize() override
Return the size of the underlying data type.
Definition: vtkBitArray.h:64
source
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:825
vtkBitArray::TupleSize
int TupleSize
Definition: vtkBitArray.h:322
vtkDataArray::InsertComponent
virtual void InsertComponent(vtkIdType tupleIdx, int compIdx, double value)
Insert value at the location specified by tupleIdx and compIdx.
vtkBitArray::Array
unsigned char * Array
Definition: vtkBitArray.h:318
vtkBitArray::InsertValue
void InsertValue(vtkIdType id, int i)
Inserts values and checks to make sure there is enough memory.
Definition: vtkBitArray.h:362
vtkBitArray::DataChanged
void DataChanged() override
Tell the array explicitly that the data has changed.
vtkBitArray::GetDataType
int GetDataType() override
Return the underlying data type.
Definition: vtkBitArray.h:63
vtkBitArray::SetValue
void SetValue(vtkIdType id, int value)
Set the data at a particular index.
Definition: vtkBitArray.h:347
vtkDataArray::SetTuple
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.
vtkBitArray::InsertVariantValue
void InsertVariantValue(vtkIdType idx, vtkVariant value) override
Inserts values from a variant and checks to ensure there is enough memory.
Definition: vtkBitArray.h:393
vtkDataArray::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
Definition: vtkAbstractArray.h:338
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkBitArray::GetVoidPointer
void * GetVoidPointer(vtkIdType id) override
Return a void pointer.
Definition: vtkBitArray.h:237
vtkVariant
A atomic type representing the union of many types.
Definition: vtkVariant.h:71
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:36
vtkDataArray::SetComponent
virtual void SetComponent(vtkIdType tupleIdx, int compIdx, double value)
Set the data component at the location specified by tupleIdx and compIdx to value.
vtkX3D::size
Definition: vtkX3D.h:253
vtkBitArray::WriteVoidPointer
void * WriteVoidPointer(vtkIdType id, vtkIdType number) override
Get the address of a particular data index.
Definition: vtkBitArray.h:232
vtkBitArray::InsertNextValue
vtkIdType InsertNextValue(int i)
Definition: vtkBitArray.h:398
vtkBitArray::ResizeAndExtend
unsigned char * ResizeAndExtend(vtkIdType sz)
vtkAbstractArray::SetVariantValue
virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Set a value in the array from a variant.
vtkBitArray::SetVoidArray
void SetVoidArray(void *array, vtkIdType size, int save, int deleteMethod) override
Definition: vtkBitArray.h:268
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:78
vtkDataArray.h
vtkVariant::ToInt
int ToInt(bool *valid) const
vtkBitArray::Allocate
vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext=1000) override
Allocate memory for this array.
vtkAbstractArray::DeepCopy
virtual void DeepCopy(vtkAbstractArray *da)
Deep copy of data.
vtkArrayIterator
Abstract superclass to iterate over elements in an vtkAbstractArray.
Definition: vtkArrayIterator.h:52
vtkDataArray::RemoveFirstTuple
virtual void RemoveFirstTuple()
Definition: vtkDataArray.h:253
vtkBitArray::DeepCopy
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
Definition: vtkBitArray.h:246
vtkDataArray::InsertNextTuple
vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Insert the tuple from srcTupleIdx in the source array at the end of this array.
vtkBitArray
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:36
VTK_BIT
#define VTK_BIT
Definition: vtkType.h:48
vtkAbstractArray::ClearLookup
virtual void ClearLookup()=0
Delete the associated fast lookup data structure on this array, if it exists.
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:39
vtkAbstractArray::MaxId
vtkIdType MaxId
Definition: vtkAbstractArray.h:688
vtkDataArray::DeepCopy
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
vtkAbstractArray::DataChanged
virtual void DataChanged()=0
Tell the array explicitly that the data has changed.
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkDataArray::RemoveTuple
virtual void RemoveTuple(vtkIdType tupleIdx)=0
These methods remove tuples from the data array.
vtkAbstractArray::Resize
virtual vtkTypeBool Resize(vtkIdType numTuples)=0
Resize the array to the requested number of tuples and preserve data.
vtkBitArray::SetVariantValue
void SetVariantValue(vtkIdType idx, vtkVariant value) override
Set a value in the array from a variant.
Definition: vtkBitArray.h:388
vtkAbstractArray::SetNumberOfValues
virtual void SetNumberOfValues(vtkIdType numValues)
Specify the number of values (tuples * components) for this object to hold.