VTK  9.0.1
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  {
39  VTK_DATA_ARRAY_DELETE = vtkAbstractArray::VTK_DATA_ARRAY_DELETE,
40  VTK_DATA_ARRAY_ALIGNED_FREE = vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
41  VTK_DATA_ARRAY_USER_DEFINED = vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
42  };
43 
44  static vtkBitArray* New();
45  vtkTypeMacro(vtkBitArray, vtkDataArray);
46  void PrintSelf(ostream& os, vtkIndent indent) override;
47 
52  vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext = 1000) override;
53 
57  void Initialize() override;
58 
59  // satisfy vtkDataArray API
60  int GetDataType() const override { return VTK_BIT; }
61  int GetDataTypeSize() const override { return 0; }
62 
66  void SetNumberOfTuples(vtkIdType number) override;
67 
75 
81 
87  void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
88 
95  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
96 
103 
108  double* GetTuple(vtkIdType i) override;
109 
113  void GetTuple(vtkIdType i, double* tuple) override;
114 
116 
119  void SetTuple(vtkIdType i, const float* tuple) override;
120  void SetTuple(vtkIdType i, const double* tuple) override;
122 
124 
128  void InsertTuple(vtkIdType i, const float* tuple) override;
129  void InsertTuple(vtkIdType i, const double* tuple) override;
131 
133 
136  vtkIdType InsertNextTuple(const float* tuple) override;
137  vtkIdType InsertNextTuple(const double* tuple) override;
139 
141 
146  void RemoveTuple(vtkIdType id) override;
147  void RemoveFirstTuple() override;
148  void RemoveLastTuple() override;
150 
157  void SetComponent(vtkIdType i, int j, double c) override;
158 
162  void Squeeze() override;
163 
167  vtkTypeBool Resize(vtkIdType numTuples) override;
168 
172  int GetValue(vtkIdType id) const;
173 
178  void SetValue(vtkIdType id, int value);
179 
183  void InsertValue(vtkIdType id, int i);
184 
188  void SetVariantValue(vtkIdType idx, vtkVariant value) override;
189 
193  void InsertVariantValue(vtkIdType idx, vtkVariant value) override;
194 
195  vtkIdType InsertNextValue(int i);
196 
201  void InsertComponent(vtkIdType i, int j, double c) override;
202 
206  unsigned char* GetPointer(vtkIdType id) { return this->Array + id / 8; }
207 
213  unsigned char* WritePointer(vtkIdType id, vtkIdType number);
214 
215  void* WriteVoidPointer(vtkIdType id, vtkIdType number) override
216  {
217  return this->WritePointer(id, number);
218  }
219 
220  void* GetVoidPointer(vtkIdType id) override { return static_cast<void*>(this->GetPointer(id)); }
221 
225  void DeepCopy(vtkDataArray* da) override;
226  void DeepCopy(vtkAbstractArray* aa) override { this->Superclass::DeepCopy(aa); }
227 
229 
240 #ifndef __VTK_WRAP__
241  void SetArray(
242  unsigned char* array, vtkIdType size, int save, int deleteMethod = VTK_DATA_ARRAY_DELETE);
243 #endif
244  void SetVoidArray(void* array, vtkIdType size, int save) override
245  {
246  this->SetArray(static_cast<unsigned char*>(array), size, save);
247  }
248  void SetVoidArray(void* array, vtkIdType size, int save, int deleteMethod) override
249  {
250  this->SetArray(static_cast<unsigned char*>(array), size, save, deleteMethod);
251  }
253 
260  void SetArrayFreeFunction(void (*callback)(void*)) override;
261 
266 
268 
272  void LookupValue(vtkVariant value, vtkIdList* ids) override;
274  void LookupValue(int value, vtkIdList* ids);
276 
285  void DataChanged() override;
286 
292  void ClearLookup() override;
293 
294 protected:
296  ~vtkBitArray() 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  void (*DeleteFunction)(void*);
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&) = delete;
313  void operator=(const vtkBitArray&) = delete;
314 
315  vtkBitArrayLookup* Lookup;
316  void UpdateLookup();
317 };
318 
320 {
321  if (value)
322  {
323  this->Array[id / 8] = static_cast<unsigned char>(this->Array[id / 8] | (0x80 >> id % 8));
324  }
325  else
326  {
327  this->Array[id / 8] = static_cast<unsigned char>(this->Array[id / 8] & (~(0x80 >> id % 8)));
328  }
329  this->DataChanged();
330 }
331 
332 inline void vtkBitArray::InsertValue(vtkIdType id, int i)
333 {
334  if (id >= this->Size)
335  {
336  if (!this->ResizeAndExtend(id + 1))
337  {
338  return;
339  }
340  }
341  if (i)
342  {
343  this->Array[id / 8] = static_cast<unsigned char>(this->Array[id / 8] | (0x80 >> id % 8));
344  }
345  else
346  {
347  this->Array[id / 8] = static_cast<unsigned char>(this->Array[id / 8] & (~(0x80 >> id % 8)));
348  }
349  if (id > this->MaxId)
350  {
351  this->MaxId = id;
352  }
353  this->DataChanged();
354 }
355 
357 {
358  this->SetValue(id, value.ToInt());
359 }
360 
362 {
363  this->InsertValue(id, value.ToInt());
364 }
365 
367 {
368  this->InsertValue(++this->MaxId, i);
369  this->DataChanged();
370  return this->MaxId;
371 }
372 
373 inline void vtkBitArray::Squeeze()
374 {
375  this->ResizeAndExtend(this->MaxId + 1);
376 }
377 
378 #endif
vtkBitArray::SetVoidArray
void SetVoidArray(void *array, vtkIdType size, int save) override
Definition: vtkBitArray.h:244
vtkAbstractArray::Squeeze
virtual void Squeeze()=0
Free any unnecessary memory.
vtkBitArray::RemoveFirstTuple
void RemoveFirstTuple() override
vtkAbstractArray::DeleteMethod
DeleteMethod
Definition: vtkAbstractArray.h:322
vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE
@ VTK_DATA_ARRAY_ALIGNED_FREE
Definition: vtkAbstractArray.h:325
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:373
vtkX3D::value
@ value
Definition: vtkX3D.h:226
vtkAbstractArray::VTK_DATA_ARRAY_DELETE
@ VTK_DATA_ARRAY_DELETE
Definition: vtkAbstractArray.h:324
vtkIdType
int vtkIdType
Definition: vtkType.h:338
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:64
vtkAbstractArray::Size
vtkIdType Size
Definition: vtkAbstractArray.h:677
vtkAbstractArray::VTK_DATA_ARRAY_FREE
@ VTK_DATA_ARRAY_FREE
Definition: vtkAbstractArray.h:323
vtkBitArray::GetValue
int GetValue(vtkIdType id) const
Get the data at a particular index.
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:50
vtkBitArray::Tuple
double * Tuple
Definition: vtkBitArray.h:303
vtkBitArray::GetPointer
unsigned char * GetPointer(vtkIdType id)
Direct manipulation of the underlying data.
Definition: vtkBitArray.h:206
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::GetDataTypeSize
int GetDataTypeSize() const override
Return the size of the underlying data type.
Definition: vtkBitArray.h:61
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::TupleSize
int TupleSize
Definition: vtkBitArray.h:302
vtkBitArray::Array
unsigned char * Array
Definition: vtkBitArray.h:298
vtkBitArray::InsertValue
void InsertValue(vtkIdType id, int i)
Inserts values and checks to make sure there is enough memory.
Definition: vtkBitArray.h:332
vtkBitArray::DataChanged
void DataChanged() override
Tell the array explicitly that the data has changed.
vtkBitArray::SetValue
void SetValue(vtkIdType id, int value)
Set the data at a particular index.
Definition: vtkBitArray.h:319
vtkBitArray::SetNumberOfTuples
void SetNumberOfTuples(vtkIdType number) override
Set the number of n-tuples in the array.
vtkBitArray::GetDataType
int GetDataType() const override
Return the underlying data type.
Definition: vtkBitArray.h:60
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:361
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:326
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:34
vtkBitArray::vtkBitArray
vtkBitArray()
vtkBitArray::GetVoidPointer
void * GetVoidPointer(vtkIdType id) override
Return a void pointer.
Definition: vtkBitArray.h:220
vtkVariant
A atomic type representing the union of many types.
Definition: vtkVariant.h:66
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:31
vtkX3D::size
@ size
Definition: vtkX3D.h:259
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:215
vtkBitArray::InsertNextValue
vtkIdType InsertNextValue(int i)
Definition: vtkBitArray.h:366
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:248
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:76
vtkBitArray::RemoveTuple
void RemoveTuple(vtkIdType id) override
These methods remove tuples from the data array.
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:50
vtkBitArray::LookupValue
void LookupValue(int value, vtkIdList *ids)
vtkBitArray::DeepCopy
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
Definition: vtkBitArray.h:226
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:34
source
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:959
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:42
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:42
vtkAbstractArray::MaxId
vtkIdType MaxId
Definition: vtkAbstractArray.h:678
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:356
vtkBitArray::RemoveLastTuple
void RemoveLastTuple() override