29
29
#include " vtkPriorityQueue.h"
30
30
#include < vtkstd/vector>
31
31
#include < vtkstd/queue>
32
+ #include < vtkstd/map>
33
+
34
+ struct vtkDecimatePolylineFilter ::vtkDecimatePolylineVertexErrorSTLMap
35
+ {
36
+ vtkstd::map< int , double > VertexErrorMap;
37
+ };
38
+
32
39
33
40
vtkStandardNewMacro (vtkDecimatePolylineFilter);
34
41
@@ -39,11 +46,13 @@ vtkDecimatePolylineFilter::vtkDecimatePolylineFilter()
39
46
this ->TargetReduction = 0.90 ;
40
47
this ->Closed = true ;
41
48
this ->PriorityQueue = vtkSmartPointer< vtkPriorityQueue >::New ();
49
+ this ->ErrorMap = new vtkDecimatePolylineVertexErrorSTLMap;
42
50
}
43
51
44
52
// ---------------------------------------------------------------------
45
53
vtkDecimatePolylineFilter::~vtkDecimatePolylineFilter ()
46
54
{
55
+ delete this ->ErrorMap ;
47
56
}
48
57
49
58
// ---------------------------------------------------------------------
@@ -118,13 +127,13 @@ int vtkDecimatePolylineFilter::RequestData(
118
127
119
128
for ( i = 0 ; i < numPts; ++i )
120
129
{
121
- this ->VertexErrorMap [i] = 0 .;
130
+ this ->ErrorMap -> VertexErrorMap [i] = 0 .;
122
131
}
123
132
124
133
for ( i = 0 ; i < numPts; ++i )
125
134
{
126
135
error = ComputeError ( input, GetPrev (i), i, GetNext (i) );
127
- this ->VertexErrorMap [i] = error;
136
+ this ->ErrorMap -> VertexErrorMap [i] = error;
128
137
this ->PriorityQueue ->Insert ( error, i );
129
138
}// for all points in polyline
130
139
@@ -139,26 +148,27 @@ int vtkDecimatePolylineFilter::RequestData(
139
148
i = this ->PriorityQueue ->Pop ( );
140
149
--currentNumPts;
141
150
UpdateError ( input, i );
142
- this ->VertexErrorMap .erase ( i );
151
+ this ->ErrorMap -> VertexErrorMap .erase ( i );
143
152
}
144
153
145
154
// What's left over is now spit out as a new polyline
146
155
newId = newLines->InsertNextCell ( currentNumPts + 1 );
147
156
outCD->CopyData ( inCD, cellId, newId );
148
157
149
- for ( std::map< int , double >::iterator it = this ->VertexErrorMap .begin ();
150
- it != this -> VertexErrorMap . end ();
151
- ++it )
158
+ std::map< int , double >::iterator it = this -> ErrorMap ->VertexErrorMap .begin ();
159
+
160
+ while ( it != this -> ErrorMap -> VertexErrorMap . end () )
152
161
{
153
162
newId = newPts->InsertNextPoint ( inputPoints->GetPoint ( it->first ) );
154
163
newLines->InsertCellPoint ( newId );
155
164
outPD->CopyData ( inPD, it->first , newId );
165
+ ++it;
156
166
}
157
167
if ( this ->Closed )
158
168
{
159
169
newId = newPts->InsertNextPoint ( newPts->GetPoint ( 0 ) );
160
170
newLines->InsertCellPoint ( 0 );
161
- outPD->CopyData ( inPD, this ->VertexErrorMap .begin ()->first , newId );
171
+ outPD->CopyData ( inPD, this ->ErrorMap -> VertexErrorMap .begin ()->first , newId );
162
172
}
163
173
164
174
// Clean up in preparation for the next line
@@ -176,13 +186,13 @@ int vtkDecimatePolylineFilter::RequestData(
176
186
// ---------------------------------------------------------------------
177
187
int vtkDecimatePolylineFilter::GetPrev ( int iId )
178
188
{
179
- std ::map< int , double >::iterator it = this ->VertexErrorMap .find ( iId );
189
+ vtkstd ::map< int , double >::iterator it = this -> ErrorMap ->VertexErrorMap .find ( iId );
180
190
181
- if ( it == this ->VertexErrorMap .begin () )
191
+ if ( it == this ->ErrorMap -> VertexErrorMap .begin () )
182
192
{
183
193
if ( this ->Closed )
184
194
{
185
- it = this ->VertexErrorMap .end ();
195
+ it = this ->ErrorMap -> VertexErrorMap .end ();
186
196
--it;
187
197
return it->first ;
188
198
}
@@ -200,14 +210,16 @@ int vtkDecimatePolylineFilter::GetPrev( int iId )
200
210
// ---------------------------------------------------------------------
201
211
int vtkDecimatePolylineFilter::GetNext ( int iId )
202
212
{
203
- std::map< int , double >::iterator it = this ->VertexErrorMap .find ( iId );
204
- std::map< int , double >::iterator end_it = this ->VertexErrorMap .end ();
213
+ vtkstd::map< int , double >::iterator
214
+ it = this ->ErrorMap ->VertexErrorMap .find ( iId );
215
+ vtkstd::map< int , double >::iterator
216
+ end_it = this ->ErrorMap ->VertexErrorMap .end ();
205
217
--end_it;
206
218
if ( it == end_it )
207
219
{
208
220
if ( this ->Closed )
209
221
{
210
- return this ->VertexErrorMap .begin ()->first ;
222
+ return this ->ErrorMap -> VertexErrorMap .begin ()->first ;
211
223
}
212
224
else
213
225
{
@@ -229,12 +241,12 @@ void vtkDecimatePolylineFilter::UpdateError( vtkPolyData* input, int iId )
229
241
int next_next = GetNext ( next );
230
242
231
243
double prev_error = ComputeError ( input, prev_prev, prev, next );
232
- this ->VertexErrorMap [prev] = prev_error;
244
+ this ->ErrorMap -> VertexErrorMap [prev] = prev_error;
233
245
this ->PriorityQueue ->DeleteId ( prev );
234
246
this ->PriorityQueue ->Insert ( prev_error, prev );
235
247
236
248
double next_error = ComputeError ( input, prev, next, next_next );
237
- this ->VertexErrorMap [next] = next_error;
249
+ this ->ErrorMap -> VertexErrorMap [next] = next_error;
238
250
this ->PriorityQueue ->DeleteId ( next );
239
251
this ->PriorityQueue ->Insert ( next_error, next );
240
252
}
0 commit comments