1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkBitArrayIterator.cxx
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 =========================================================================*/
15 #include "vtkBitArrayIterator.h"
16
17 #include "vtkBitArray.h"
18 #include "vtkObjectFactory.h"
19
20 vtkStandardNewMacro(vtkBitArrayIterator);
21 vtkCxxSetObjectMacro(vtkBitArrayIterator, Array, vtkBitArray);
22 //-----------------------------------------------------------------------------
vtkBitArrayIterator()23 vtkBitArrayIterator::vtkBitArrayIterator()
24 {
25 this->Array = 0;
26 this->Tuple = 0;
27 this->TupleSize = 0;
28 }
29
30 //-----------------------------------------------------------------------------
~vtkBitArrayIterator()31 vtkBitArrayIterator::~vtkBitArrayIterator()
32 {
33 this->SetArray(0);
34 delete [] this->Tuple;
35 }
36
37 //-----------------------------------------------------------------------------
Initialize(vtkAbstractArray * a)38 void vtkBitArrayIterator::Initialize(vtkAbstractArray* a)
39 {
40 vtkBitArray* b = vtkBitArray::SafeDownCast(a);
41 if (!b && a)
42 {
43 vtkErrorMacro("vtkBitArrayIterator can iterate only over vtkBitArray.");
44 return;
45 }
46 this->SetArray(b);
47 }
48
49 //-----------------------------------------------------------------------------
GetArray()50 vtkAbstractArray* vtkBitArrayIterator::GetArray()
51 {
52 return this->Array;
53 }
54
55 //-----------------------------------------------------------------------------
GetTuple(vtkIdType id)56 int* vtkBitArrayIterator::GetTuple(vtkIdType id)
57 {
58 if (!this->Array)
59 {
60 return 0;
61 }
62
63 vtkIdType numComps = this->Array->GetNumberOfComponents();
64 if (this->TupleSize < numComps)
65 {
66 this->TupleSize = static_cast<int>(numComps);
67 delete [] this->Tuple;
68 this->Tuple = new int [this->TupleSize];
69 }
70 vtkIdType loc = id * numComps;
71 for (int j = 0; j < numComps; j++)
72 {
73 this->Tuple[j] = this->Array->GetValue(loc + j);
74 }
75 return this->Tuple;
76 }
77
78 //-----------------------------------------------------------------------------
GetValue(vtkIdType id)79 int vtkBitArrayIterator::GetValue(vtkIdType id)
80 {
81 if (this->Array)
82 {
83 return this->Array->GetValue(id);
84 }
85 vtkErrorMacro("Array Iterator not initialized.");
86 return 0;
87 }
88
89 //-----------------------------------------------------------------------------
SetValue(vtkIdType id,int value)90 void vtkBitArrayIterator::SetValue(vtkIdType id, int value)
91 {
92 if (this->Array)
93 {
94 this->Array->SetValue(id, value);
95 }
96 }
97
98 //-----------------------------------------------------------------------------
GetNumberOfTuples()99 vtkIdType vtkBitArrayIterator::GetNumberOfTuples()
100 {
101 if (this->Array)
102 {
103 return this->Array->GetNumberOfTuples();
104 }
105 return 0;
106 }
107 //-----------------------------------------------------------------------------
GetNumberOfValues()108 vtkIdType vtkBitArrayIterator::GetNumberOfValues()
109 {
110 if (this->Array)
111 {
112 return this->Array->GetNumberOfTuples() * this->Array->GetNumberOfComponents();
113 }
114 return 0;
115 }
116 //-----------------------------------------------------------------------------
GetNumberOfComponents()117 int vtkBitArrayIterator::GetNumberOfComponents()
118 {
119 if (this->Array)
120 {
121 return this->Array->GetNumberOfComponents();
122 }
123 return 0;
124 }
125
126 //-----------------------------------------------------------------------------
GetDataType()127 int vtkBitArrayIterator::GetDataType()
128 {
129 if (this->Array)
130 {
131 return this->Array->GetDataType();
132 }
133 return 0;
134 }
135 //-----------------------------------------------------------------------------
GetDataTypeSize()136 int vtkBitArrayIterator::GetDataTypeSize()
137 {
138 if (this->Array)
139 {
140 return this->Array->GetDataTypeSize();
141 }
142 return 0;
143 }
144
145 //-----------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)146 void vtkBitArrayIterator::PrintSelf(ostream& os, vtkIndent indent)
147 {
148 this->Superclass::PrintSelf(os, indent);
149 }
150