VTK  9.6.20260227
vtkBitArrayIterator.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
9
10#ifndef vtkBitArrayIterator_h
11#define vtkBitArrayIterator_h
12
13#include "vtkArrayIterator.h"
14#include "vtkBitArray.h" // For vtkBitArray
15#include "vtkCommonCoreModule.h" // For export macro
16#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_7_0
17#include "vtkObjectFactory.h" // For VTK_STANDARD_NEW_BODY
18
19VTK_ABI_NAMESPACE_BEGIN
20class VTK_DEPRECATED_IN_9_7_0("Use vtkArrayDispatch") VTKCOMMONCORE_EXPORT vtkBitArrayIterator
21 : public vtkArrayIterator
22{
23public:
26 void PrintSelf(ostream& os, vtkIndent indent) override
27 {
28 this->Superclass::PrintSelf(os, indent);
29 }
30
38 void Initialize(vtkAbstractArray* array) override
39 {
41 if (!b && array)
42 {
43 vtkErrorMacro("vtkBitArrayIterator can iterate only over vtkBitArray.");
44 return;
45 }
46 this->SetArray(b);
47 }
48
52 vtkAbstractArray* GetArray() { return this->Array; }
53
58 {
59 if (!this->Array)
60 {
61 return nullptr;
62 }
63
64 vtkIdType numComps = this->Array->GetNumberOfComponents();
65 if (this->TupleSize < numComps)
66 {
67 this->TupleSize = static_cast<int>(numComps);
68 delete[] this->Tuple;
69 this->Tuple = new int[this->TupleSize];
70 }
71 vtkIdType loc = id * numComps;
72 for (int j = 0; j < numComps; j++)
73 {
74 this->Tuple[j] = this->Array->GetValue(loc + j);
75 }
76 return this->Tuple;
77 }
78
83 {
84 if (this->Array)
85 {
86 return this->Array->GetValue(id);
87 }
88 vtkErrorMacro("Array Iterator not initialized.");
89 return 0;
90 }
91
96 {
97 if (this->Array)
98 {
99 return this->Array->GetNumberOfTuples();
100 }
101 return 0;
102 }
103
108 {
109 if (this->Array)
110 {
111 return this->Array->GetNumberOfTuples() * this->Array->GetNumberOfComponents();
112 }
113 return 0;
114 }
115
120 {
121 if (this->Array)
122 {
123 return this->Array->GetNumberOfComponents();
124 }
125 return 0;
126 }
127
131 int GetDataType() const override
132 {
133 if (this->Array)
134 {
135 return this->Array->GetDataType();
136 }
137 return 0;
138 }
139
143 int GetDataTypeSize() const
144 {
145 if (this->Array)
146 {
147 return this->Array->GetDataTypeSize();
148 }
149 return 0;
150 }
151
156 void SetValue(vtkIdType id, int value)
157 {
158 if (this->Array)
159 {
160 this->Array->SetValue(id, value);
161 }
162 }
163
167 typedef int ValueType;
168
169protected:
171 {
172 this->Array = nullptr;
173 this->Tuple = nullptr;
174 this->TupleSize = 0;
175 }
177 {
178 this->SetArray(nullptr);
179 delete[] this->Tuple;
180 }
181
182 int* Tuple;
184 void SetArray(vtkBitArray* b) { vtkSetObjectBodyMacro(Array, vtkBitArray, b); }
186
187private:
189 void operator=(const vtkBitArrayIterator&) = delete;
190};
191
192VTK_ABI_NAMESPACE_END
193#endif
Abstract superclass for all arrays.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetValue(vtkIdType id, int value)
Sets the value at the index.
int GetDataType() const override
Get the data type from the underlying array.
vtkAbstractArray * GetArray()
Get the array.
static vtkBitArrayIterator * New()
int GetNumberOfComponents() const
Must be called only after Initialize.
int GetValue(vtkIdType id)
Must be called only after Initialize.
int * GetTuple(vtkIdType id)
Must be called only after Initialize.
void Initialize(vtkAbstractArray *array) override
Set the array this iterator will iterate over.
void SetArray(vtkBitArray *b)
vtkIdType GetNumberOfValues() const
Must be called only after Initialize.
int GetDataTypeSize() const
Get the data type size from the underlying array.
vtkIdType GetNumberOfTuples() const
Must be called only after Initialize.
int ValueType
Data type of a value.
dynamic, self-adjusting array of bits
Definition vtkBitArray.h:33
a simple class to control print indentation
Definition vtkIndent.h:108
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
ArrayT * vtkArrayDownCast(vtkAbstractArray *array)
vtkArrayDownCast is to be used by generic (e.g.
#define VTK_DEPRECATED_IN_9_7_0(reason)
#define VTK_STANDARD_NEW_BODY(thisClass)
int vtkIdType
Definition vtkType.h:363