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=========================================================================*/
24
25#ifndef vtkBitArray_h
26#define vtkBitArray_h
27
28#include "vtkCommonCoreModule.h" // For export macro
29#include "vtkDataArray.h"
30
31class vtkBitArrayLookup;
32
33class VTKCOMMONCORE_EXPORT vtkBitArray : public vtkDataArray
34{
35public:
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
72 bool SetNumberOfValues(vtkIdType number) override;
73
81
87
93 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
94
101 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
102
109 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
110
117
122 double* GetTuple(vtkIdType i) override;
123
127 void GetTuple(vtkIdType i, double* tuple) override;
128
130
133 void SetTuple(vtkIdType i, const float* tuple) override;
134 void SetTuple(vtkIdType i, const double* tuple) override;
136
138
142 void InsertTuple(vtkIdType i, const float* tuple) override;
143 void InsertTuple(vtkIdType i, const double* tuple) override;
145
147
150 vtkIdType InsertNextTuple(const float* tuple) override;
151 vtkIdType InsertNextTuple(const double* tuple) override;
153
155
160 void RemoveTuple(vtkIdType id) override;
161 void RemoveFirstTuple() override;
162 void RemoveLastTuple() override;
164
171 void SetComponent(vtkIdType i, int j, double c) override;
172
176 void Squeeze() override;
177
181 vtkTypeBool Resize(vtkIdType numTuples) override;
182
186 int GetValue(vtkIdType id) const;
187
192 void SetValue(vtkIdType id, int value);
193
197 void InsertValue(vtkIdType id, int i);
198
202 void SetVariantValue(vtkIdType idx, vtkVariant value) override;
203
207 void InsertVariantValue(vtkIdType idx, vtkVariant value) override;
208
210
215 void InsertComponent(vtkIdType i, int j, double c) override;
216
220 unsigned char* GetPointer(vtkIdType id) { 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 { return static_cast<void*>(this->GetPointer(id)); }
235
239 void DeepCopy(vtkDataArray* da) override;
240 void DeepCopy(vtkAbstractArray* aa) override { this->Superclass::DeepCopy(aa); }
241
243
254#ifndef __VTK_WRAP__
256 unsigned char* array, vtkIdType size, int save, int deleteMethod = VTK_DATA_ARRAY_DELETE);
257#endif
258 void SetVoidArray(void* array, vtkIdType size, int save) override
259 {
260 this->SetArray(static_cast<unsigned char*>(array), size, save);
261 }
262 void SetVoidArray(void* array, vtkIdType size, int save, int deleteMethod) override
263 {
264 this->SetArray(static_cast<unsigned char*>(array), size, save, deleteMethod);
265 }
266
267
274 void SetArrayFreeFunction(void (*callback)(void*)) override;
275
280
282
286 void LookupValue(vtkVariant value, vtkIdList* ids) override;
288 void LookupValue(int value, vtkIdList* ids);
290
299 void DataChanged() override;
300
306 void ClearLookup() override;
307
308protected:
310 ~vtkBitArray() override;
311
324
325 unsigned char* Array; // pointer to data
326 unsigned char* ResizeAndExtend(vtkIdType sz);
327 // function to resize data
328
329 int TupleSize; // used for data conversion
330 double* Tuple;
331
332 void (*DeleteFunction)(void*);
333
334private:
335 // hide superclass' DeepCopy() from the user and the compiler
336 void DeepCopy(vtkDataArray& da) { this->vtkDataArray::DeepCopy(&da); }
337
338private:
339 vtkBitArray(const vtkBitArray&) = delete;
340 void operator=(const vtkBitArray&) = delete;
341
342 vtkBitArrayLookup* Lookup;
343 void UpdateLookup();
344};
345
346inline void vtkBitArray::SetValue(vtkIdType id, int value)
347{
348 this->Array[id / 8] =
349 static_cast<unsigned char>((value != 0) ? (this->Array[id / 8] | (0x80 >> id % 8))
350 : (this->Array[id / 8] & (~(0x80 >> id % 8))));
351 this->DataChanged();
352}
353
355{
356 if (id >= this->Size)
357 {
358 if (!this->ResizeAndExtend(id + 1))
359 {
360 return;
361 }
362 }
363 this->Array[id / 8] =
364 static_cast<unsigned char>((i != 0) ? (this->Array[id / 8] | (0x80 >> id % 8))
365 : (this->Array[id / 8] & (~(0x80 >> id % 8))));
366 if (id > this->MaxId)
367 {
368 this->MaxId = id;
370 }
371 this->DataChanged();
372}
373
375{
376 this->SetValue(id, value.ToInt());
377}
378
380{
381 this->InsertValue(id, value.ToInt());
382}
383
385{
386 this->InsertValue(this->MaxId + 1, i);
387 this->DataChanged();
388 return this->MaxId;
389}
390
392{
393 this->ResizeAndExtend(this->MaxId + 1);
394}
395#endif
Abstract superclass to iterate over elements in an vtkAbstractArray.
dynamic, self-adjusting array of bits
Definition vtkBitArray.h:34
int GetValue(vtkIdType id) const
Get the data at a particular index.
void * WriteVoidPointer(vtkIdType id, vtkIdType number) override
Get the address of a particular data index.
unsigned char * WritePointer(vtkIdType id, vtkIdType number)
Get the address of a particular data 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.
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.
void SetValue(vtkIdType id, int value)
Set the data at a particular index.
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.
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.
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.
vtkIdType InsertNextTuple(const float *tuple) override
Insert (memory allocation performed) the tuple onto the end of the array.
vtkArrayIterator * NewIterator() override
Returns a new vtkBitArrayIterator instance.
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.
void RemoveFirstTuple() override
These methods remove tuples from the data array.
double * Tuple
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(* DeleteFunction)(void *)
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.
unsigned char * GetPointer(vtkIdType id)
Direct manipulation of the underlying data.
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)
double * GetTuple(vtkIdType i) override
Get a pointer to a tuple at the ith location.
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.
void RemoveTuple(vtkIdType id) override
These methods remove tuples from the data array.
void * GetVoidPointer(vtkIdType id) override
Return a void pointer.
unsigned char * ResizeAndExtend(vtkIdType sz)
~vtkBitArray() override
unsigned char * Array
int GetDataTypeSize() const override
Return the size of the underlying data type.
Definition vtkBitArray.h:61
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.
@ VTK_DATA_ARRAY_FREE
Definition vtkBitArray.h:38
@ VTK_DATA_ARRAY_DELETE
Definition vtkBitArray.h:39
@ VTK_DATA_ARRAY_USER_DEFINED
Definition vtkBitArray.h:41
@ VTK_DATA_ARRAY_ALIGNED_FREE
Definition vtkBitArray.h:40
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:60
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.
static vtkBitArray * New()
void InsertVariantValue(vtkIdType idx, vtkVariant value) override
Inserts values from a variant and checks to ensure there is enough memory.
void Squeeze() override
Free any unneeded memory.
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.
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
list of point or cell ids
Definition vtkIdList.h:31
a simple class to control print indentation
Definition vtkIndent.h:34
A atomic type representing the union of many types.
Definition vtkVariant.h:64
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
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