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,
44  VTK_DATA_ARRAY_USER_DEFINED=vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
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 
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 
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:
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
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.
vtkBitArray::RemoveFirstTuple
void RemoveFirstTuple() override
vtkAbstractArray::DeleteMethod
DeleteMethod
Definition: vtkAbstractArray.h:334
vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE
@ VTK_DATA_ARRAY_ALIGNED_FREE
Definition: vtkAbstractArray.h:337
vtkBitArray::SetArrayFreeFunction
void SetArrayFreeFunction(void(*callback)(void *)) override
This method allows the user to specify a custom free function to be called when the array is dealloca...
vtkBitArray::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::SetComponent
void SetComponent(vtkIdType i, int j, double c) override
Set the data component at the ith tuple and jth component location.
vtkBitArray::Squeeze
void Squeeze() override
Free any unneeded memory.
Definition: vtkBitArray.h:405
vtkX3D::value
@ value
Definition: vtkX3D.h:220
vtkAbstractArray::VTK_DATA_ARRAY_DELETE
@ 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
vtkBitArray::SetArray
void SetArray(unsigned char *array, vtkIdType size, int save, int deleteMethod=VTK_DATA_ARRAY_DELETE)
This method lets the user specify data to be held by 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
@ VTK_DATA_ARRAY_FREE
Definition: vtkAbstractArray.h:335
vtkBitArray::SetTuple
void SetTuple(vtkIdType i, const double *tuple) override
vtkBitArray::InsertNextTuple
vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray *source) override
Insert the jth tuple in the source array, at the end in this array.
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
vtkBitArray::Tuple
double * Tuple
Definition: vtkBitArray.h:323
vtkBitArray::GetPointer
unsigned char * GetPointer(vtkIdType id)
Direct manipulation of the underlying data.
Definition: vtkBitArray.h:222
vtkBitArray::LookupValue
void LookupValue(vtkVariant value, vtkIdList *ids) override
vtkBitArray::~vtkBitArray
~vtkBitArray() override
vtkBitArray::GetTuple
double * GetTuple(vtkIdType i) override
Get a pointer to a tuple at the ith location.
vtkBitArray::WritePointer
unsigned char * WritePointer(vtkIdType id, vtkIdType number)
Get the address of a particular data index.
vtkAbstractArray::InsertVariantValue
virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Insert a value into the array from a variant.
vtkBitArray::DeepCopy
void DeepCopy(vtkDataArray *da) override
Deep copy of another bit array.
vtkBitArray::LookupValue
vtkIdType LookupValue(vtkVariant value) override
Return the indices where a specific value appears.
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
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
vtkBitArray::SetNumberOfTuples
void SetNumberOfTuples(vtkIdType number) override
Set the number of n-tuples in the array.
vtkBitArray::InsertTuple
void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source) override
Insert the jth tuple in the source array, at ith location in this array.
vtkBitArray::New
static vtkBitArray * New()
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
vtkBitArray::InsertTuple
void InsertTuple(vtkIdType i, const double *tuple) override
vtkBitArray::InsertTuples
void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray *source) override
Copy n consecutive tuples starting at srcStart from the source array to this array,...
vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
@ VTK_DATA_ARRAY_USER_DEFINED
Definition: vtkAbstractArray.h:338
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:40
vtkBitArray::vtkBitArray
vtkBitArray()
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:72
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:37
vtkX3D::size
@ size
Definition: vtkX3D.h:253
vtkBitArray::Resize
vtkTypeBool Resize(vtkIdType numTuples) override
Resize the array while conserving the data.
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
vtkBitArray::InsertComponent
void InsertComponent(vtkIdType i, int j, double c) override
Insert the data component at ith tuple and jth component location.
vtkBitArray::InsertTuple
void InsertTuple(vtkIdType i, const float *tuple) override
Insert (memory allocation performed) the tuple into the ith location in the array.
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:79
vtkBitArray::RemoveTuple
void RemoveTuple(vtkIdType id) override
These methods remove tuples from the data array.
vtkBitArray::GetValue
int GetValue(vtkIdType id)
Get the data at a particular index.
vtkBitArray::LookupValue
vtkIdType LookupValue(int value)
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:53
vtkBitArray::LookupValue
void LookupValue(int value, vtkIdList *ids)
vtkBitArray::DeepCopy
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
Definition: vtkBitArray.h:246
vtkBitArray::SetTuple
void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source) override
Set the tuple at the ith location using the jth tuple in the source array.
vtkBitArray::ClearLookup
void ClearLookup() override
Delete the associated fast lookup data structure on this array, if it exists.
vtkBitArray::GetTuple
void GetTuple(vtkIdType i, double *tuple) override
Copy the tuple value into a user-provided array.
vtkBitArray
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:37
vtkBitArray::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
VTK_BIT
#define VTK_BIT
Definition: vtkType.h:48
vtkBitArray::InsertNextTuple
vtkIdType InsertNextTuple(const float *tuple) override
Insert (memory allocation performed) the tuple onto the end of the array.
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:39
vtkAbstractArray::MaxId
vtkIdType MaxId
Definition: vtkAbstractArray.h:688
vtkBitArray::SetTuple
void SetTuple(vtkIdType i, const float *tuple) override
Set the tuple value at the ith location in the array.
vtkDataArray::DeepCopy
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
vtkBitArray::InsertNextTuple
vtkIdType InsertNextTuple(const double *tuple) override
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkBitArray::NewIterator
vtkArrayIterator * NewIterator() override
Returns a new vtkBitArrayIterator instance.
vtkBitArray::Initialize
void Initialize() override
Release storage and reset array to initial state.
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.
vtkBitArray::RemoveLastTuple
void RemoveLastTuple() override