Skip to content

Commit 7ce3c5f

Browse files
author
Arnaud Gelas
committed
STYLE: create an opaque pointer for the vertex error map.
1 parent b7c5422 commit 7ce3c5f

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

Graphics/vtkDecimatePolylineFilter.cxx

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
#include "vtkPriorityQueue.h"
3030
#include <vtkstd/vector>
3131
#include <vtkstd/queue>
32+
#include <vtkstd/map>
33+
34+
struct vtkDecimatePolylineFilter::vtkDecimatePolylineVertexErrorSTLMap
35+
{
36+
vtkstd::map< int, double > VertexErrorMap;
37+
};
38+
3239

3340
vtkStandardNewMacro(vtkDecimatePolylineFilter);
3441

@@ -39,11 +46,13 @@ vtkDecimatePolylineFilter::vtkDecimatePolylineFilter()
3946
this->TargetReduction = 0.90;
4047
this->Closed = true;
4148
this->PriorityQueue = vtkSmartPointer< vtkPriorityQueue >::New();
49+
this->ErrorMap = new vtkDecimatePolylineVertexErrorSTLMap;
4250
}
4351

4452
//---------------------------------------------------------------------
4553
vtkDecimatePolylineFilter::~vtkDecimatePolylineFilter()
4654
{
55+
delete this->ErrorMap;
4756
}
4857

4958
//---------------------------------------------------------------------
@@ -118,13 +127,13 @@ int vtkDecimatePolylineFilter::RequestData(
118127

119128
for ( i = 0; i < numPts; ++i )
120129
{
121-
this->VertexErrorMap[i] = 0.;
130+
this->ErrorMap->VertexErrorMap[i] = 0.;
122131
}
123132

124133
for ( i = 0; i < numPts; ++i )
125134
{
126135
error = ComputeError( input, GetPrev(i), i, GetNext(i) );
127-
this->VertexErrorMap[i] = error;
136+
this->ErrorMap->VertexErrorMap[i] = error;
128137
this->PriorityQueue->Insert( error, i );
129138
}//for all points in polyline
130139

@@ -139,26 +148,27 @@ int vtkDecimatePolylineFilter::RequestData(
139148
i = this->PriorityQueue->Pop( );
140149
--currentNumPts;
141150
UpdateError( input, i );
142-
this->VertexErrorMap.erase( i );
151+
this->ErrorMap->VertexErrorMap.erase( i );
143152
}
144153

145154
// What's left over is now spit out as a new polyline
146155
newId = newLines->InsertNextCell( currentNumPts + 1);
147156
outCD->CopyData( inCD, cellId, newId );
148157

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() )
152161
{
153162
newId = newPts->InsertNextPoint( inputPoints->GetPoint( it->first ) );
154163
newLines->InsertCellPoint( newId );
155164
outPD->CopyData( inPD, it->first, newId );
165+
++it;
156166
}
157167
if( this->Closed )
158168
{
159169
newId = newPts->InsertNextPoint( newPts->GetPoint( 0 ) );
160170
newLines->InsertCellPoint( 0 );
161-
outPD->CopyData( inPD, this->VertexErrorMap.begin()->first, newId );
171+
outPD->CopyData( inPD, this->ErrorMap->VertexErrorMap.begin()->first, newId );
162172
}
163173

164174
// Clean up in preparation for the next line
@@ -176,13 +186,13 @@ int vtkDecimatePolylineFilter::RequestData(
176186
//---------------------------------------------------------------------
177187
int vtkDecimatePolylineFilter::GetPrev( int iId )
178188
{
179-
std::map< int, double >::iterator it = this->VertexErrorMap.find( iId );
189+
vtkstd::map< int, double >::iterator it = this->ErrorMap->VertexErrorMap.find( iId );
180190

181-
if( it == this->VertexErrorMap.begin() )
191+
if( it == this->ErrorMap->VertexErrorMap.begin() )
182192
{
183193
if( this->Closed )
184194
{
185-
it = this->VertexErrorMap.end();
195+
it = this->ErrorMap->VertexErrorMap.end();
186196
--it;
187197
return it->first;
188198
}
@@ -200,14 +210,16 @@ int vtkDecimatePolylineFilter::GetPrev( int iId )
200210
//---------------------------------------------------------------------
201211
int vtkDecimatePolylineFilter::GetNext( int iId )
202212
{
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();
205217
--end_it;
206218
if( it == end_it )
207219
{
208220
if( this->Closed )
209221
{
210-
return this->VertexErrorMap.begin()->first;
222+
return this->ErrorMap->VertexErrorMap.begin()->first;
211223
}
212224
else
213225
{
@@ -229,12 +241,12 @@ void vtkDecimatePolylineFilter::UpdateError( vtkPolyData* input, int iId )
229241
int next_next = GetNext( next );
230242

231243
double prev_error = ComputeError( input, prev_prev, prev, next );
232-
this->VertexErrorMap[prev] = prev_error;
244+
this->ErrorMap->VertexErrorMap[prev] = prev_error;
233245
this->PriorityQueue->DeleteId( prev );
234246
this->PriorityQueue->Insert( prev_error, prev );
235247

236248
double next_error = ComputeError( input, prev, next, next_next );
237-
this->VertexErrorMap[next] = next_error;
249+
this->ErrorMap->VertexErrorMap[next] = next_error;
238250
this->PriorityQueue->DeleteId( next );
239251
this->PriorityQueue->Insert( next_error, next );
240252
}

Graphics/vtkDecimatePolylineFilter.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include <vtkSmartPointer.h>
4141

4242
#include "vtkPolyDataAlgorithm.h"
43-
#include "vtkstd/map"
4443

4544
class vtkPriorityQueue;
4645

@@ -76,10 +75,12 @@ class VTK_GRAPHICS_EXPORT vtkDecimatePolylineFilter : public vtkPolyDataAlgorith
7675
int GetPrev( int iId );
7776
int GetNext( int iId );
7877

79-
bool Closed;
80-
double TargetReduction;
81-
vtkstd::map< int, double > VertexErrorMap;
82-
vtkSmartPointer< vtkPriorityQueue > PriorityQueue;
78+
struct vtkDecimatePolylineVertexErrorSTLMap;
79+
vtkDecimatePolylineVertexErrorSTLMap* ErrorMap;
80+
81+
vtkSmartPointer< vtkPriorityQueue > PriorityQueue;
82+
bool Closed;
83+
double TargetReduction;
8384

8485
private:
8586
vtkDecimatePolylineFilter(const vtkDecimatePolylineFilter&); // Not implemented.

0 commit comments

Comments
 (0)