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:
37  {
40  VTK_DATA_ARRAY_ALIGNED_FREE=vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
42  };
43 
44  static vtkBitArray *New();
45  vtkTypeMacro(vtkBitArray,vtkDataArray);
46  void PrintSelf(ostream& os, vtkIndent indent) override;
47 
52  int Allocate(vtkIdType sz, vtkIdType ext=1000) override;
53 
57  void Initialize() override;
58 
59  // satisfy vtkDataArray API
60  int GetDataType() override {return VTK_BIT;}
61  int GetDataTypeSize() override { return 0; }
62 
66  void SetNumberOfTuples(vtkIdType number) override;
67 
74  void SetTuple(vtkIdType i, vtkIdType j,
75  vtkAbstractArray* source) override;
76 
82  vtkAbstractArray* source) override;
83 
89  void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
90  vtkAbstractArray *source) override;
91 
97  void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
98  vtkAbstractArray* source) override;
99 
106  vtkAbstractArray* source) override;
107 
112  double *GetTuple(vtkIdType i) override;
113 
117  void GetTuple(vtkIdType i, double * tuple) override;
118 
120 
123  void SetTuple(vtkIdType i, const float * tuple) override;
124  void SetTuple(vtkIdType i, const double * tuple) override;
126 
128 
132  void InsertTuple(vtkIdType i, const float * tuple) override;
133  void InsertTuple(vtkIdType i, const double * tuple) override;
135 
137 
140  vtkIdType InsertNextTuple(const float * tuple) override;
141  vtkIdType InsertNextTuple(const double * tuple) override;
143 
145 
150  void RemoveTuple(vtkIdType id) override;
151  void RemoveFirstTuple() override;
152  void RemoveLastTuple() override;
154 
161  void SetComponent(vtkIdType i, int j, double c) override;
162 
166  void Squeeze() override;
167 
171  int Resize(vtkIdType numTuples) override;
172 
176  int GetValue(vtkIdType id);
177 
185  void SetNumberOfValues(vtkIdType number) override;
186 
191  void SetValue(vtkIdType id, int value);
192 
196  void InsertValue(vtkIdType id, int i);
197 
201  void SetVariantValue(vtkIdType idx, vtkVariant value) override;
202 
206  void InsertVariantValue(vtkIdType idx, vtkVariant value) override;
207 
208  vtkIdType InsertNextValue(int i);
209 
214  void InsertComponent(vtkIdType i, int j, double c) override;
215 
219  unsigned char *GetPointer(vtkIdType id)
220  { return this->Array + id/8; }
221 
227  unsigned char *WritePointer(vtkIdType id, vtkIdType number);
228 
229  void* WriteVoidPointer(vtkIdType id, vtkIdType number) override
230  {
231  return this->WritePointer(id, number);
232  }
233 
234  void *GetVoidPointer(vtkIdType id) override
235  {
236  return static_cast<void *>(this->GetPointer(id));
237  }
238 
242  void DeepCopy(vtkDataArray *da) override;
243  void DeepCopy(vtkAbstractArray* aa) override
244  { this->Superclass::DeepCopy(aa); }
245 
247 
258 #ifndef __VTK_WRAP__
259  void SetArray(unsigned char* array, vtkIdType size, int save, int deleteMethod=VTK_DATA_ARRAY_DELETE);
260 #endif
261  void SetVoidArray(void *array, vtkIdType size, int save) override
262  {
263  this->SetArray(static_cast<unsigned char *>(array), size, save);
264  }
265  void SetVoidArray(void *array, vtkIdType size, int save, int deleteMethod) override
266  {
267  this->SetArray(static_cast<unsigned char *>(array), size, save, deleteMethod);
268  }
270 
277  void SetArrayFreeFunction(void (*callback)(void *)) override;
278 
283 
285 
289  void LookupValue(vtkVariant value, vtkIdList* ids) override;
291  void LookupValue(int value, vtkIdList* ids);
293 
302  void DataChanged() override;
303 
309  void ClearLookup() override;
310 
311 protected:
312  vtkBitArray();
313  ~vtkBitArray() override;
314 
315  unsigned char *Array; // pointer to data
316  unsigned char *ResizeAndExtend(vtkIdType sz);
317  // function to resize data
318 
319  int TupleSize; //used for data conversion
320  double *Tuple;
321 
322  void (*DeleteFunction)(void*);
323 
324 private:
325  // hide superclass' DeepCopy() from the user and the compiler
326  void DeepCopy(vtkDataArray &da) {this->vtkDataArray::DeepCopy(&da);}
327 
328 private:
329  vtkBitArray(const vtkBitArray&) = delete;
330  void operator=(const vtkBitArray&) = delete;
331 
332  vtkBitArrayLookup* Lookup;
333  void UpdateLookup();
334 
335 };
336 
338 {
339  this->Allocate(number);
340  this->MaxId = number - 1;
341  this->DataChanged();
342 }
343 
345 {
346  if (value)
347  {
348  this->Array[id/8] = static_cast<unsigned char>(
349  this->Array[id/8] | (0x80 >> id%8));
350  }
351  else
352  {
353  this->Array[id/8] = static_cast<unsigned char>(
354  this->Array[id/8] & (~(0x80 >> id%8)));
355  }
356  this->DataChanged();
357 }
358 
359 inline void vtkBitArray::InsertValue(vtkIdType id, int i)
360 {
361  if ( id >= this->Size )
362  {
363  if (!this->ResizeAndExtend(id+1))
364  {
365  return;
366  }
367  }
368  if (i)
369  {
370  this->Array[id/8] = static_cast<unsigned char>(
371  this->Array[id/8] | (0x80 >> id%8));
372  }
373  else
374  {
375  this->Array[id/8] = static_cast<unsigned char>(
376  this->Array[id/8] & (~(0x80 >> id%8)));
377  }
378  if ( id > this->MaxId )
379  {
380  this->MaxId = id;
381  }
382  this->DataChanged();
383 }
384 
386 {
387  this->SetValue(id, value.ToInt());
388 }
389 
391 {
392  this->InsertValue(id, value.ToInt());
393 }
394 
396 {
397  this->InsertValue (++this->MaxId,i);
398  this->DataChanged();
399  return this->MaxId;
400 }
401 
402 inline void vtkBitArray::Squeeze() {this->ResizeAndExtend (this->MaxId+1);}
403 
404 #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:261
vtkAbstractArray::Squeeze
virtual void Squeeze()=0
Free any unnecessary memory.
vtkAbstractArray::DeleteMethod
DeleteMethod
Definition: vtkAbstractArray.h:330
vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE
Definition: vtkAbstractArray.h:334
vtkAbstractArray::Resize
virtual int Resize(vtkIdType numTuples)=0
Resize the array to the requested number of tuples and preserve data.
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:402
vtkX3D::value
Definition: vtkX3D.h:220
vtkAbstractArray::VTK_DATA_ARRAY_DELETE
Definition: vtkAbstractArray.h:333
vtkBitArray::SetNumberOfValues
void SetNumberOfValues(vtkIdType number) override
Fast method based setting of values without memory checks.
Definition: vtkBitArray.h:337
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:684
vtkAbstractArray::VTK_DATA_ARRAY_FREE
Definition: vtkAbstractArray.h:332
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
vtkBitArray::Tuple
double * Tuple
Definition: vtkBitArray.h:320
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:219
vtkDataArray::GetTuple
virtual double * GetTuple(vtkIdType tupleIdx)=0
Get the data tuple at tupleIdx.
vtkAbstractArray::InsertVariantValue
virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Insert a value into the array from a variant.
vtkBitArray::Allocate
int Allocate(vtkIdType sz, vtkIdType ext=1000) override
Allocate memory for this array.
vtkBitArray::GetDataTypeSize
int GetDataTypeSize() override
Return the size of the underlying data type.
Definition: vtkBitArray.h:61
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:319
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:315
vtkBitArray::InsertValue
void InsertValue(vtkIdType id, int i)
Inserts values and checks to make sure there is enough memory.
Definition: vtkBitArray.h:359
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:60
vtkBitArray::SetValue
void SetValue(vtkIdType id, int value)
Set the data at a particular index.
Definition: vtkBitArray.h:344
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:390
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:335
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkBitArray::GetVoidPointer
void * GetVoidPointer(vtkIdType id) override
Return a void pointer.
Definition: vtkBitArray.h:234
vtkVariant
A atomic type representing the union of many types.
Definition: vtkVariant.h:65
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:30
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:229
vtkBitArray::InsertNextValue
vtkIdType InsertNextValue(int i)
Definition: vtkBitArray.h:395
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:265
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:75
vtkDataArray.h
vtkVariant::ToInt
int ToInt(bool *valid) const
vtkAbstractArray::DeepCopy
virtual void DeepCopy(vtkAbstractArray *da)
Deep copy of data.
vtkArrayIterator
Abstract superclass to iterate over elements in an vtkAbstractArray.
Definition: vtkArrayIterator.h:49
vtkDataArray::RemoveFirstTuple
virtual void RemoveFirstTuple()
Definition: vtkDataArray.h:247
vtkBitArray::DeepCopy
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
Definition: vtkBitArray.h:243
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:33
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:685
vtkDataArray::DeepCopy
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
vtkAbstractArray::Allocate
virtual int Allocate(vtkIdType numValues, vtkIdType ext=1000)=0
Allocate memory for this array.
vtkAbstractArray::DataChanged
virtual void DataChanged()=0
Tell the array explicitly that the data has changed.
vtkDataArray::RemoveTuple
virtual void RemoveTuple(vtkIdType tupleIdx)=0
These methods remove tuples from the data array.
vtkBitArray::SetVariantValue
void SetVariantValue(vtkIdType idx, vtkVariant value) override
Set a value in the array from a variant.
Definition: vtkBitArray.h:385
vtkAbstractArray::SetNumberOfValues
virtual void SetNumberOfValues(vtkIdType numValues)
Specify the number of values (tuples * components) for this object to hold.