VTK: Common/Core/vtkBitArray.h Source File

| VTK 9.3.1

vtkBitArray.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
19 #ifndef vtkBitArray_h
20 #define vtkBitArray_h
21
22 #include "vtkCommonCoreModule.h" // For export macro
23 #include "vtkDataArray.h"
24
25 VTK_ABI_NAMESPACE_BEGIN
26 class vtkBitArrayLookup;
27
28 class VTKCOMMONCORE_EXPORT vtkBitArray : public vtkDataArray
29 {
30 public:
31 enum DeleteMethod
32 {
33 VTK_DATA_ARRAY_FREE = vtkAbstractArray::VTK_DATA_ARRAY_FREE,
34 VTK_DATA_ARRAY_DELETE = vtkAbstractArray::VTK_DATA_ARRAY_DELETE,
35 VTK_DATA_ARRAY_ALIGNED_FREE = vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
36 VTK_DATA_ARRAY_USER_DEFINED = vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
37 };
38
39 static vtkBitArray* New();
40 vtkTypeMacro(vtkBitArray, vtkDataArray);
41 void PrintSelf(ostream& os, vtkIndent indent) override;
42
47 vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext = 1000) override;
48
52 void Initialize() override;
53
54 // satisfy vtkDataArray API
55 int GetDataType() const override { return VTK_BIT; }
56 int GetDataTypeSize() const override { return 0; }
57
61 void SetNumberOfTuples(vtkIdType number) override;
62
67 bool SetNumberOfValues(vtkIdType number) override;
68
77 void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source) override;
78
85 void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source) override;
86
94 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
95
103 void InsertTuplesStartingAt(
104 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
105
113 void InsertTuples(
114 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
115
123 vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray* source) override;
124
129 double* GetTuple(vtkIdType i) override;
130
134 void GetTuple(vtkIdType i, double* tuple) override;
135
137
142 void SetTuple(vtkIdType i, const float* tuple) override;
143 void SetTuple(vtkIdType i, const double* tuple) override;
145
147
153 void InsertTuple(vtkIdType i, const float* tuple) override;
154 void InsertTuple(vtkIdType i, const double* tuple) override;
156
158
163 vtkIdType InsertNextTuple(const float* tuple) override;
164 vtkIdType InsertNextTuple(const double* tuple) override;
166
168
175 void RemoveTuple(vtkIdType id) override;
176 void RemoveFirstTuple() override;
177 void RemoveLastTuple() override;
179
188 void SetComponent(vtkIdType i, int j, double c) override;
189
193 void Squeeze() override;
194
198 vtkTypeBool Resize(vtkIdType numTuples) override;
199
203 int GetValue(vtkIdType id) const;
204
211 void SetValue(vtkIdType id, int value);
212
218 void InsertValue(vtkIdType id, int i);
219
225 void SetVariantValue(vtkIdType idx, vtkVariant value) override;
226
232 void InsertVariantValue(vtkIdType idx, vtkVariant value) override;
233
234 vtkIdType InsertNextValue(int i);
235
242 void InsertComponent(vtkIdType i, int j, double c) override;
243
247 unsigned char* GetPointer(vtkIdType id) { return this->Array + id / 8; }
248
254 unsigned char* WritePointer(vtkIdType id, vtkIdType number);
255
256 void* WriteVoidPointer(vtkIdType id, vtkIdType number) override
257 {
258 return this->WritePointer(id, number);
259 }
260
261 void* GetVoidPointer(vtkIdType id) override { return static_cast<void*>(this->GetPointer(id)); }
262
266 void DeepCopy(vtkDataArray* da) override;
267 void DeepCopy(vtkAbstractArray* aa) override { this->Superclass::DeepCopy(aa); }
268
270
281 #ifndef __VTK_WRAP__
282 void SetArray(
283 unsigned char* array, vtkIdType size, int save, int deleteMethod = VTK_DATA_ARRAY_DELETE);
284 #endif
285 void SetVoidArray(void* array, vtkIdType size, int save) override
286 {
287 this->SetArray(static_cast<unsigned char*>(array), size, save);
288 }
289 void SetVoidArray(void* array, vtkIdType size, int save, int deleteMethod) override
290 {
291 this->SetArray(static_cast<unsigned char*>(array), size, save, deleteMethod);
292 }
294
301 void SetArrayFreeFunction(void (*callback)(void*)) override;
302
306 VTK_NEWINSTANCE vtkArrayIterator* NewIterator() override;
307
309
312 vtkIdType LookupValue(vtkVariant value) override;
313 void LookupValue(vtkVariant value, vtkIdList* ids) override;
314 vtkIdType LookupValue(int value);
315 void LookupValue(int value, vtkIdList* ids);
317
326 void DataChanged() override;
327
333 void ClearLookup() override;
334
335 protected:
336 vtkBitArray();
337 ~vtkBitArray() override;
338
350 virtual void InitializeUnusedBitsInLastByte();
351
352 unsigned char* Array; // pointer to data
353 unsigned char* ResizeAndExtend(vtkIdType sz);
354 // function to resize data
355
356 int TupleSize; // used for data conversion
357 double* Tuple;
358
359 void (*DeleteFunction)(void*);
360
361 private:
362 // hide superclass' DeepCopy() from the user and the compiler
363 void DeepCopy(vtkDataArray& da) { this->vtkDataArray::DeepCopy(&da); }
364
365 vtkBitArray(const vtkBitArray&) = delete;
366 void operator=(const vtkBitArray&) = delete;
367
368 vtkBitArrayLookup* Lookup;
369 void UpdateLookup();
370 };
371
372 inline void vtkBitArray::SetValue(vtkIdType id, int value)
373 {
374 this->Array[id / 8] =
375 static_cast<unsigned char>((value != 0) ? (this->Array[id / 8] | (0x80 >> id % 8))
376 : (this->Array[id / 8] & (~(0x80 >> id % 8))));
377 this->DataChanged();
378 }
379
380 inline void vtkBitArray::InsertValue(vtkIdType id, int i)
381 {
382 if (id >= this->Size)
383 {
384 if (!this->ResizeAndExtend(id + 1))
385 {
386 return;
387 }
388 }
389 this->Array[id / 8] =
390 static_cast<unsigned char>((i != 0) ? (this->Array[id / 8] | (0x80 >> id % 8))
391 : (this->Array[id / 8] & (~(0x80 >> id % 8))));
392 if (id > this->MaxId)
393 {
394 this->MaxId = id;
395 this->InitializeUnusedBitsInLastByte();
396 }
397 this->DataChanged();
398 }
399
400 inline void vtkBitArray::SetVariantValue(vtkIdType id, vtkVariant value)
401 {
402 this->SetValue(id, value.ToInt());
403 }
404
405 inline void vtkBitArray::InsertVariantValue(vtkIdType id, vtkVariant value)
406 {
407 this->InsertValue(id, value.ToInt());
408 }
409
410 inline vtkIdType vtkBitArray::InsertNextValue(int i)
411 {
412 this->InsertValue(this->MaxId + 1, i);
413 this->DataChanged();
414 return this->MaxId;
415 }
416
417 inline void vtkBitArray::Squeeze()
418 {
419 this->ResizeAndExtend(this->MaxId + 1);
420 }
421 VTK_ABI_NAMESPACE_END
422 #endif
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:76
vtkAbstractArray::DeepCopy
virtual void DeepCopy(vtkAbstractArray *da)
Deep copy of data.
vtkAbstractArray::MaxId
vtkIdType MaxId
Definition: vtkAbstractArray.h:696
vtkAbstractArray::DeleteMethod
DeleteMethod
Definition: vtkAbstractArray.h:330
vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
@ VTK_DATA_ARRAY_USER_DEFINED
Definition: vtkAbstractArray.h:334
vtkAbstractArray::VTK_DATA_ARRAY_FREE
@ VTK_DATA_ARRAY_FREE
Definition: vtkAbstractArray.h:331
vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE
@ VTK_DATA_ARRAY_ALIGNED_FREE
Definition: vtkAbstractArray.h:333
vtkAbstractArray::VTK_DATA_ARRAY_DELETE
@ VTK_DATA_ARRAY_DELETE
Definition: vtkAbstractArray.h:332
vtkAbstractArray::Size
vtkIdType Size
Definition: vtkAbstractArray.h:695
vtkAbstractArray::SetVariantValue
virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Set a value in the array from a variant.
vtkAbstractArray::InsertVariantValue
virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Insert a value into the array from a variant.
vtkAbstractArray::Squeeze
virtual void Squeeze()=0
Free any unnecessary memory.
vtkArrayIterator
Abstract superclass to iterate over elements in an vtkAbstractArray.
Definition: vtkArrayIterator.h:42
vtkBitArray
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:29
vtkBitArray::GetValue
int GetValue(vtkIdType id) const
Get the data at a particular index.
vtkBitArray::InsertNextTuple
vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray *source) override
Insert the jth tuple in the source array, at the end in this array.
vtkBitArray::InsertNextTuple
vtkIdType InsertNextTuple(const double *tuple) override
Insert (memory allocation performed) the tuple onto the end of the array.
vtkBitArray::DataChanged
void DataChanged() override
Tell the array explicitly that the data has changed.
vtkBitArray::GetPointer
unsigned char * GetPointer(vtkIdType id)
Direct manipulation of the underlying data.
Definition: vtkBitArray.h:247
vtkBitArray::GetTuple
double * GetTuple(vtkIdType i) override
Get a pointer to a tuple at the ith location.
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,...
vtkBitArray::SetNumberOfTuples
void SetNumberOfTuples(vtkIdType number) override
Set the number of n-tuples in the array.
vtkBitArray::SetVariantValue
void SetVariantValue(vtkIdType idx, vtkVariant value) override
Set a value in the array from a variant.
Definition: vtkBitArray.h:400
vtkBitArray::SetValue
void SetValue(vtkIdType id, int value)
Set the data at a particular index.
Definition: vtkBitArray.h:372
vtkBitArray::Allocate
vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext=1000) override
Allocate memory for this array.
vtkBitArray::InsertTuple
void InsertTuple(vtkIdType i, const double *tuple) override
Insert (memory allocation performed) the tuple into the ith location in the array.
vtkBitArray::GetTuple
void GetTuple(vtkIdType i, double *tuple) override
Copy the tuple value into a user-provided array.
vtkBitArray::vtkBitArray
vtkBitArray()
vtkBitArray::LookupValue
void LookupValue(vtkVariant value, vtkIdList *ids) override
Return the indices where a specific value appears.
vtkBitArray::SetTuple
void SetTuple(vtkIdType i, const double *tuple) override
Set the tuple value at the ith location in the array.
vtkBitArray::ResizeAndExtend
unsigned char * ResizeAndExtend(vtkIdType sz)
vtkBitArray::InsertComponent
void InsertComponent(vtkIdType i, int j, double c) override
Insert the data component at ith tuple and jth component location.
vtkBitArray::LookupValue
void LookupValue(int value, vtkIdList *ids)
Return the indices where a specific value appears.
vtkBitArray::DeepCopy
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
Definition: vtkBitArray.h:267
vtkBitArray::SetComponent
void SetComponent(vtkIdType i, int j, double c) override
Set the data component at the ith tuple and jth component location.
vtkBitArray::SetTuple
void SetTuple(vtkIdType i, const float *tuple) override
Set the tuple value at the ith location in the array.
vtkBitArray::NewIterator
vtkArrayIterator * NewIterator() override
Returns a new vtkBitArrayIterator instance.
vtkBitArray::InsertNextTuple
vtkIdType InsertNextTuple(const float *tuple) override
Insert (memory allocation performed) the tuple onto the end of the array.
vtkBitArray::Resize
vtkTypeBool Resize(vtkIdType numTuples) override
Resize the array while conserving the data.
vtkBitArray::InsertValue
void InsertValue(vtkIdType id, int i)
Inserts values and checks to make sure there is enough memory.
Definition: vtkBitArray.h:380
vtkBitArray::RemoveFirstTuple
void RemoveFirstTuple() override
These methods remove tuples from the data array.
vtkBitArray::Tuple
double * Tuple
Definition: vtkBitArray.h:357
vtkBitArray::InsertTuple
void InsertTuple(vtkIdType i, const float *tuple) override
Insert (memory allocation performed) the tuple into the ith location in the array.
vtkBitArray::Initialize
void Initialize() override
Release storage and reset array to initial state.
vtkBitArray::InsertTuplesStartingAt
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...
vtkBitArray::SetNumberOfValues
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...
vtkBitArray::SetVoidArray
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:289
vtkBitArray::WritePointer
unsigned char * WritePointer(vtkIdType id, vtkIdType number)
Get the address of a particular data index.
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::InsertNextValue
vtkIdType InsertNextValue(int i)
Definition: vtkBitArray.h:410
vtkBitArray::TupleSize
int TupleSize
Definition: vtkBitArray.h:356
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::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkBitArray::SetVoidArray
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:285
vtkBitArray::RemoveTuple
void RemoveTuple(vtkIdType id) override
These methods remove tuples from the data array.
vtkBitArray::GetVoidPointer
void * GetVoidPointer(vtkIdType id) override
Return a void pointer.
Definition: vtkBitArray.h:261
vtkBitArray::WriteVoidPointer
void * WriteVoidPointer(vtkIdType id, vtkIdType number) override
Get the address of a particular data index.
Definition: vtkBitArray.h:256
vtkBitArray::~vtkBitArray
~vtkBitArray() override
vtkBitArray::Array
unsigned char * Array
Definition: vtkBitArray.h:352
vtkBitArray::GetDataTypeSize
int GetDataTypeSize() const override
Return the size of the underlying data type.
Definition: vtkBitArray.h:56
vtkBitArray::RemoveLastTuple
void RemoveLastTuple() override
These methods remove tuples from the data array.
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::DeepCopy
void DeepCopy(vtkDataArray *da) override
Deep copy of another bit array.
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::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.
vtkBitArray::GetDataType
int GetDataType() const override
Return the underlying data type.
Definition: vtkBitArray.h:55
vtkBitArray::LookupValue
vtkIdType LookupValue(int value)
Return the indices where a specific value appears.
vtkBitArray::LookupValue
vtkIdType LookupValue(vtkVariant value) override
Return the indices where a specific value appears.
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:405
vtkBitArray::Squeeze
void Squeeze() override
Free any unneeded memory.
Definition: vtkBitArray.h:417
vtkBitArray::InitializeUnusedBitsInLastByte
virtual void InitializeUnusedBitsInLastByte()
This method should be called whenever MaxId needs to be changed, as this method fills the unused bits...
vtkBitArray::ClearLookup
void ClearLookup() override
Delete the associated fast lookup data structure on this array, if it exists.
vtkBitArray::New
static vtkBitArray * New()
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
vtkDataArray::DeepCopy
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:32
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkVariant
A type representing the union of many types.
Definition: vtkVariant.h:62
vtkVariant::ToInt
int ToInt(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
vtkX3D::value
@ value
Definition: vtkX3D.h:220
vtkX3D::size
@ size
Definition: vtkX3D.h:253
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:64
source
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:964
vtkDataArray.h
vtkIdType
int vtkIdType
Definition: vtkType.h:315
VTK_BIT
#define VTK_BIT
Definition: vtkType.h:32
save
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
Definition: vtkVariantBoostSerialization.h:46
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:32