VTK  9.7.1
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
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 
19 VTK_ABI_NAMESPACE_BEGIN
21  : public vtkArrayIterator
22 {
23 public:
26  void PrintSelf(ostream& os, vtkIndent indent) override
27  {
28  this->Superclass::PrintSelf(os, indent);
29  }
30 
38  void Initialize(vtkAbstractArray* array) override
39  {
40  vtkBitArray* b = vtkArrayDownCast<vtkBitArray>(array);
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 
169 protected:
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 
187 private:
188  vtkBitArrayIterator(const vtkBitArrayIterator&) = delete;
189  void operator=(const vtkBitArrayIterator&) = delete;
190 };
191 
192 VTK_ABI_NAMESPACE_END
193 #endif
int GetNumberOfComponents() const
Must be called only after Initialize.
Iterator for vtkBitArray.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void Initialize(vtkAbstractArray *array) override
Set the array this iterator will iterate over.
Abstract superclass for all arrays.
vtkIdType GetNumberOfValues() const
Must be called only after Initialize.
void SetValue(vtkIdType id, int value)
Sets the value at the index.
int vtkIdType
Definition: vtkType.h:363
int ValueType
Data type of a value.
int GetDataType() const override
Get the data type from the underlying array.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkAbstractArray * GetArray()
Get the array.
a simple class to control print indentation
Definition: vtkIndent.h:28
static vtkBitArrayIterator * New()
#define VTK_STANDARD_NEW_BODY(thisClass)
int GetValue(vtkIdType id)
Must be called only after Initialize.
Abstract superclass to iterate over elements in an vtkAbstractArray.
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:32
vtkIdType GetNumberOfTuples() const
Must be called only after Initialize.
void SetArray(vtkBitArray *b)
int GetDataTypeSize() const
Get the data type size from the underlying array.
#define VTK_DEPRECATED_IN_9_7_0(reason)
int * GetTuple(vtkIdType id)
Must be called only after Initialize.