Thanks to visit codestin.com
Credit goes to vtk.org

VTK  9.5.20250922
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#include <cassert> // for assert
26
27VTK_ABI_NAMESPACE_BEGIN
28class vtkBitArrayLookup;
29
30class VTKCOMMONCORE_EXPORT vtkBitArray : public vtkDataArray
31{
32public:
34 {
37 VTK_DATA_ARRAY_ALIGNED_FREE = vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
38 VTK_DATA_ARRAY_USER_DEFINED = vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
39 };
40
41 static vtkBitArray* New();
42 vtkTypeMacro(vtkBitArray, vtkDataArray);
43 void PrintSelf(ostream& os, vtkIndent indent) override;
44
49 vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext = 1000) override;
50
54 void Initialize() override;
55
56 // satisfy vtkDataArray API
57 int GetDataType() const override { return VTK_BIT; }
58 int GetDataTypeSize() const override { return 0; }
59
63 void SetNumberOfTuples(vtkIdType number) override;
64
69 bool SetNumberOfValues(vtkIdType number) override;
70
80
88
96 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
97
106 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
107
116 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
117
126
131 double* GetTuple(vtkIdType i) override;
132
136 void GetTuple(vtkIdType i, double* tuple) override;
137
139
144 void SetTuple(vtkIdType i, const float* tuple) override;
145 void SetTuple(vtkIdType i, const double* tuple) override;
147
149
155 void InsertTuple(vtkIdType i, const float* tuple) override;
156 void InsertTuple(vtkIdType i, const double* tuple) override;
158
160
165 vtkIdType InsertNextTuple(const float* tuple) override;
166 vtkIdType InsertNextTuple(const double* tuple) override;
168
170
177 void RemoveTuple(vtkIdType id) override;
178 void RemoveFirstTuple() override;
179 void RemoveLastTuple() override;
181
190 void SetComponent(vtkIdType i, int j, double c) override;
191
195 void Squeeze() override;
196
200 vtkTypeBool Resize(vtkIdType numTuples) override;
201
205 int GetValue(vtkIdType id) const;
206
213 void SetValue(vtkIdType id, int value);
214
220 void InsertValue(vtkIdType id, int i);
221
227 void SetVariantValue(vtkIdType idx, vtkVariant value) override;
228
234 void InsertVariantValue(vtkIdType idx, vtkVariant value) override;
235
236 vtkIdType InsertNextValue(int i);
237
244 void InsertComponent(vtkIdType i, int j, double c) override;
245
249 unsigned char* GetPointer(vtkIdType id) { return this->Array + id / 8; }
250
256 unsigned char* WritePointer(vtkIdType id, vtkIdType number);
257
258 void* WriteVoidPointer(vtkIdType id, vtkIdType number) override
259 {
260 return this->WritePointer(id, number);
261 }
262
263 void* GetVoidPointer(vtkIdType id) override { return static_cast<void*>(this->GetPointer(id)); }
264
268 void DeepCopy(vtkDataArray* da) override;
269 void DeepCopy(vtkAbstractArray* aa) override { this->Superclass::DeepCopy(aa); }
270
272
283#ifndef __VTK_WRAP__
285 unsigned char* array, vtkIdType size, int save, int deleteMethod = VTK_DATA_ARRAY_DELETE);
286#endif
287 void SetVoidArray(void* array, vtkIdType size, int save) override
288 {
289 this->SetArray(static_cast<unsigned char*>(array), size, save);
290 }
291 void SetVoidArray(void* array, vtkIdType size, int save, int deleteMethod) override
292 {
293 this->SetArray(static_cast<unsigned char*>(array), size, save, deleteMethod);
294 }
296
303 void SetArrayFreeFunction(void (*callback)(void*)) override;
304
309
311
315 void LookupValue(vtkVariant value, vtkIdList* ids) override;
317 void LookupValue(int value, vtkIdList* ids);
319
328 void DataChanged() override;
329
335 void ClearLookup() override;
336
337protected:
339 ~vtkBitArray() override;
340
353
354 unsigned char* Array; // pointer to data
355 unsigned char* ResizeAndExtend(vtkIdType sz);
356 // function to resize data
357
358 int TupleSize; // used for data conversion
359 double* Tuple;
360
361 void (*DeleteFunction)(void*);
362
363private:
364 // hide superclass' DeepCopy() from the user and the compiler
365 void DeepCopy(vtkDataArray& da) { this->vtkDataArray::DeepCopy(&da); }
366
367 vtkBitArray(const vtkBitArray&) = delete;
368 void operator=(const vtkBitArray&) = delete;
369
370 vtkBitArrayLookup* Lookup;
371 void UpdateLookup();
372};
373
374inline void vtkBitArray::SetValue(vtkIdType id, int value)
375{
376 const auto bitsetDiv = std::div(id, static_cast<vtkIdType>(8));
377 const vtkIdType &bitsetId = bitsetDiv.quot, bitId = bitsetDiv.rem;
378 unsigned char mask = 0x80 >> bitId; // NOLINT(clang-analyzer-core.BitwiseShift)
379 this->Array[bitsetId] = static_cast<unsigned char>(
380 (value != 0) ? (this->Array[bitsetId] | mask) : (this->Array[bitsetId] & (~mask)));
381 this->DataChanged();
382}
383
385{
386 if (id >= this->Size)
387 {
388 if (!this->ResizeAndExtend(id + 1))
389 {
390 return;
391 }
392 }
393 this->Array[id / 8] =
394 static_cast<unsigned char>((i != 0) ? (this->Array[id / 8] | (0x80 >> id % 8))
395 : (this->Array[id / 8] & (~(0x80 >> id % 8))));
396 if (id > this->MaxId)
397 {
398 this->MaxId = id;
400 }
401 this->DataChanged();
402}
403
405{
406 this->SetValue(id, value.ToInt());
407}
408
410{
411 this->InsertValue(id, value.ToInt());
412}
413
415{
416 this->InsertValue(this->MaxId + 1, i);
417 this->DataChanged();
418 return this->MaxId;
419}
420
422{
423 this->ResizeAndExtend(this->MaxId + 1);
424}
425VTK_ABI_NAMESPACE_END
426#endif
Abstract superclass for all arrays.
Abstract superclass to iterate over elements in an vtkAbstractArray.
dynamic, self-adjusting array of bits
Definition vtkBitArray.h:31
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 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:58
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:57
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.
abstract superclass for arrays of numeric data
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
list of point or cell ids
Definition vtkIdList.h:133
a simple class to control print indentation
Definition vtkIndent.h:108
A type representing the union of many types.
Definition vtkVariant.h:162
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:64
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition vtkType.h:333
#define VTK_BIT
Definition vtkType.h:33
void save(Archiver &ar, const std::string &str, const unsigned int version)
#define VTK_NEWINSTANCE