VTK  9.2.5
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 
84 
90 
96  void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
97 
104  vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
105 
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:
313  ~vtkBitArray() override;
314 
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
Abstract superclass for all arrays.
virtual void DeepCopy(vtkAbstractArray *da)
Deep copy of data.
virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Set a value in the array from a variant.
virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Insert a value into the array from a variant.
virtual void Squeeze()=0
Free any unnecessary memory.
Abstract superclass to iterate over elements in an vtkAbstractArray.
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:37
int GetValue(vtkIdType id) const
Get the data at a particular index.
vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray *source) override
Insert the jth tuple in the source array, at the end in this array.
vtkIdType InsertNextTuple(const double *tuple) override
Insert (memory allocation performed) the tuple onto the end of the array.
void DataChanged() override
Tell the array explicitly that the data has changed.
unsigned char * GetPointer(vtkIdType id)
Direct manipulation of the underlying data.
Definition: vtkBitArray.h:223
double * GetTuple(vtkIdType i) override
Get a pointer to a tuple at the ith location.
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,...
void SetNumberOfTuples(vtkIdType number) override
Set the number of n-tuples in the array.
void SetVariantValue(vtkIdType idx, vtkVariant value) override
Set a value in the array from a variant.
Definition: vtkBitArray.h:377
void SetValue(vtkIdType id, int value)
Set the data at a particular index.
Definition: vtkBitArray.h:349
vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext=1000) override
Allocate memory for this array.
void InsertTuple(vtkIdType i, const double *tuple) override
Insert (memory allocation performed) the tuple into the ith location in the array.
void GetTuple(vtkIdType i, double *tuple) override
Copy the tuple value into a user-provided array.
void LookupValue(vtkVariant value, vtkIdList *ids) override
Return the indices where a specific value appears.
void SetTuple(vtkIdType i, const double *tuple) override
Set the tuple value at the ith location in the array.
unsigned char * ResizeAndExtend(vtkIdType sz)
void InsertComponent(vtkIdType i, int j, double c) override
Insert the data component at ith tuple and jth component location.
void LookupValue(int value, vtkIdList *ids)
Return the indices where a specific value appears.
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
Definition: vtkBitArray.h:243
void SetComponent(vtkIdType i, int j, double c) override
Set the data component at the ith tuple and jth component location.
void SetTuple(vtkIdType i, const float *tuple) override
Set the tuple value at the ith location in the array.
vtkArrayIterator * NewIterator() override
Returns a new vtkBitArrayIterator instance.
vtkIdType InsertNextTuple(const float *tuple) override
Insert (memory allocation performed) the tuple onto the end of the array.
vtkTypeBool Resize(vtkIdType numTuples) override
Resize the array while conserving the data.
void InsertValue(vtkIdType id, int i)
Inserts values and checks to make sure there is enough memory.
Definition: vtkBitArray.h:357
void RemoveFirstTuple() override
These methods remove tuples from the data array.
double * Tuple
Definition: vtkBitArray.h:333
void InsertTuple(vtkIdType i, const float *tuple) override
Insert (memory allocation performed) the tuple into the ith location in the array.
void Initialize() override
Release storage and reset array to initial state.
void InsertTuplesStartingAt(vtkIdType dstStart, vtkIdList *srcIds, vtkAbstractArray *source) override
Copy the tuples indexed in srcIds from the source array to the tuple locations starting at index dstS...
bool SetNumberOfValues(vtkIdType number) override
In addition to setting the number of values, this method also sets the unused bits of the last byte o...
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
unsigned char * WritePointer(vtkIdType id, vtkIdType number)
Get the address of a particular data index.
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...
vtkIdType InsertNextValue(int i)
Definition: vtkBitArray.h:387
void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source) override
Insert the jth tuple in the source array, at ith location in this array.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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
void RemoveTuple(vtkIdType id) override
These methods remove tuples from the data array.
void * GetVoidPointer(vtkIdType id) override
Return a void pointer.
Definition: vtkBitArray.h:237
void * WriteVoidPointer(vtkIdType id, vtkIdType number) override
Get the address of a particular data index.
Definition: vtkBitArray.h:232
~vtkBitArray() override
unsigned char * Array
Definition: vtkBitArray.h:328
int GetDataTypeSize() const override
Return the size of the underlying data type.
Definition: vtkBitArray.h:64
void RemoveLastTuple() override
These methods remove tuples from the data array.
void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source) override
Set the tuple at the ith location using the jth tuple in the source array.
void DeepCopy(vtkDataArray *da) override
Deep copy of another bit array.
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...
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.
int GetDataType() const override
Return the underlying data type.
Definition: vtkBitArray.h:63
vtkIdType LookupValue(int value)
Return the indices where a specific value appears.
vtkIdType LookupValue(vtkVariant value) override
Return the indices where a specific value appears.
void InsertVariantValue(vtkIdType idx, vtkVariant value) override
Inserts values from a variant and checks to ensure there is enough memory.
Definition: vtkBitArray.h:382
void Squeeze() override
Free any unneeded memory.
Definition: vtkBitArray.h:394
virtual void InitializeUnusedBitsInLastByte()
This method should be called whenever MaxId needs to be changed, as this method fills the unused bits...
void ClearLookup() override
Delete the associated fast lookup data structure on this array, if it exists.
static vtkBitArray * New()
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:165
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
list of point or cell ids
Definition: vtkIdList.h:143
a simple class to control print indentation
Definition: vtkIndent.h:119
A atomic type representing the union of many types.
Definition: vtkVariant.h:159
int ToInt(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
@ value
Definition: vtkX3D.h:226
@ size
Definition: vtkX3D.h:259
int vtkTypeBool
Definition: vtkABI.h:69
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition: vtkType.h:332
#define VTK_BIT
Definition: vtkType.h:44
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
#define VTK_NEWINSTANCE