VTK  9.2.6
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  {
42  VTK_DATA_ARRAY_DELETE = vtkAbstractArray::VTK_DATA_ARRAY_DELETE,
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() const override { return VTK_BIT; }
64  int GetDataTypeSize() const override { return 0; }
65 
69  void SetNumberOfTuples(vtkIdType number) override;
70 
75  bool SetNumberOfValues(vtkIdType number) override;
76 
83  void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source) override;
84 
90 
96  void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
97 
104  vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
105 
111  void InsertTuples(
112  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
113 
120 
125  double* GetTuple(vtkIdType i) override;
126 
130  void GetTuple(vtkIdType i, double* tuple) override;
131 
133 
136  void SetTuple(vtkIdType i, const float* tuple) override;
137  void SetTuple(vtkIdType i, const double* tuple) override;
139 
141 
145  void InsertTuple(vtkIdType i, const float* tuple) override;
146  void InsertTuple(vtkIdType i, const double* tuple) override;
148 
150 
153  vtkIdType InsertNextTuple(const float* tuple) override;
154  vtkIdType InsertNextTuple(const double* tuple) override;
156 
158 
163  void RemoveTuple(vtkIdType id) override;
164  void RemoveFirstTuple() override;
165  void RemoveLastTuple() override;
167 
174  void SetComponent(vtkIdType i, int j, double c) override;
175 
179  void Squeeze() override;
180 
184  vtkTypeBool Resize(vtkIdType numTuples) override;
185 
189  int GetValue(vtkIdType id) const;
190 
195  void SetValue(vtkIdType id, int value);
196 
200  void InsertValue(vtkIdType id, int i);
201 
205  void SetVariantValue(vtkIdType idx, vtkVariant value) override;
206 
210  void InsertVariantValue(vtkIdType idx, vtkVariant value) override;
211 
212  vtkIdType InsertNextValue(int i);
213 
218  void InsertComponent(vtkIdType i, int j, double c) override;
219 
223  unsigned char* GetPointer(vtkIdType id) { 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 { return static_cast<void*>(this->GetPointer(id)); }
238 
242  void DeepCopy(vtkDataArray* da) override;
243  void DeepCopy(vtkAbstractArray* aa) override { this->Superclass::DeepCopy(aa); }
244 
246 
257 #ifndef __VTK_WRAP__
258  void SetArray(
259  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 
326  virtual void InitializeUnusedBitsInLastByte();
327 
328  unsigned char* Array; // pointer to data
329  unsigned char* ResizeAndExtend(vtkIdType sz);
330  // function to resize data
331 
332  int TupleSize; // used for data conversion
333  double* Tuple;
334 
335  void (*DeleteFunction)(void*);
336 
337 private:
338  // hide superclass' DeepCopy() from the user and the compiler
339  void DeepCopy(vtkDataArray& da) { this->vtkDataArray::DeepCopy(&da); }
340 
341 private:
342  vtkBitArray(const vtkBitArray&) = delete;
343  void operator=(const vtkBitArray&) = delete;
344 
345  vtkBitArrayLookup* Lookup;
346  void UpdateLookup();
347 };
348 
350 {
351  this->Array[id / 8] =
352  static_cast<unsigned char>((value != 0) ? (this->Array[id / 8] | (0x80 >> id % 8))
353  : (this->Array[id / 8] & (~(0x80 >> id % 8))));
354  this->DataChanged();
355 }
356 
357 inline void vtkBitArray::InsertValue(vtkIdType id, int i)
358 {
359  if (id >= this->Size)
360  {
361  if (!this->ResizeAndExtend(id + 1))
362  {
363  return;
364  }
365  }
366  this->Array[id / 8] =
367  static_cast<unsigned char>((i != 0) ? (this->Array[id / 8] | (0x80 >> id % 8))
368  : (this->Array[id / 8] & (~(0x80 >> id % 8))));
369  if (id > this->MaxId)
370  {
371  this->MaxId = id;
373  }
374  this->DataChanged();
375 }
376 
378 {
379  this->SetValue(id, value.ToInt());
380 }
381 
383 {
384  this->InsertValue(id, value.ToInt());
385 }
386 
388 {
389  this->InsertValue(this->MaxId + 1, i);
390  this->DataChanged();
391  return this->MaxId;
392 }
393 
394 inline void vtkBitArray::Squeeze()
395 {
396  this->ResizeAndExtend(this->MaxId + 1);
397 }
398 #endif
int GetDataType() const override
Return the underlying data type.
Definition: vtkBitArray.h:63
int GetDataTypeSize() const override
Return the size of the underlying data type.
Definition: vtkBitArray.h:64
void Squeeze() override
Free any unneeded memory.
Definition: vtkBitArray.h:394
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:377
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
See documentation from parent class.
void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source) override
See documentation from parent class.
int vtkIdType
Definition: vtkType.h:332
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:357
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:69
void SetValue(vtkIdType id, int value)
Set the data at a particular index.
Definition: vtkBitArray.h:349
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:223
double * Tuple
Definition: vtkBitArray.h:333
unsigned char * Array
Definition: vtkBitArray.h:328
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:33
void InsertVariantValue(vtkIdType idx, vtkVariant value) override
Inserts values from a variant and checks to ensure there is enough memory.
Definition: vtkBitArray.h:382
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
virtual vtkArrayIterator * NewIterator()=0
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
void InsertTuplesStartingAt(vtkIdType dstStart, vtkIdList *srcIds, vtkAbstractArray *source) override
See documentation from parent class.
void DataChanged() override
Tell the array explicitly that the data has changed.
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
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:265
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
See documentation from parent class.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define VTK_NEWINSTANCE
unsigned char * ResizeAndExtend(vtkIdType sz)
virtual void InitializeUnusedBitsInLastByte()
This method should be called whenever MaxId needs to be changed, as this method fills the unused bits...
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:243
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:387
#define VTK_BIT
Definition: vtkType.h:44
virtual void RemoveTuple(vtkIdType tupleIdx)=0
These methods remove tuples from the data array.
void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, vtkAbstractArray *source) override
See documentation from parent class.
virtual bool SetNumberOfValues(vtkIdType numValues)
Specify the number of values (tuples * components) for this object to hold.
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:261
virtual void RemoveFirstTuple()
These methods remove tuples from the data array.
Definition: vtkDataArray.h:236