37 #include "vtkDoubleArray.h"
40 #include "vtkInformation.h"
41 #include "vtkInformationVector.h"
42 #include "vtkObjectFactory.h"
44 #include "vtkPolyData.h"
45 #include "vtkPoints.h"
46 #include "vtkCellArray.h"
47 #include "vtkPointData.h"
48 #include "vtkCellData.h"
49 #include <vtkstd/list>
50 #include <vtkstd/vector>
51 #include <vtkstd/queue>
72 int prev,
int id,
int next)
74 vtkPoints *inputPoints = input->GetPoints();
76 double x1[3], x[3], x2[3];
78 inputPoints->GetPoint(prev, x1);
79 inputPoints->GetPoint(
id, x);
80 inputPoints->GetPoint(next, x2);
82 if ( vtkMath::Distance2BetweenPoints(x1, x2) == 0.0 )
88 return vtkLine::DistanceToLine(x, x1, x2);
96 vtkInformation *vtkNotUsed(request),
97 vtkInformationVector **inputVector,
98 vtkInformationVector *outputVector)
101 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
102 vtkInformation *outInfo = outputVector->GetInformationObject(0);
105 vtkPolyData *input = vtkPolyData::SafeDownCast(
106 inInfo->Get( vtkDataObject::DATA_OBJECT() ) );
107 vtkPolyData *output = vtkPolyData::SafeDownCast(
108 outInfo->Get( vtkDataObject::DATA_OBJECT() ) );
110 vtkCellArray *inputLines = input->GetLines();
111 vtkPoints * inputPoints = input->GetPoints();
113 if ( !inputLines || !inputPoints )
117 vtkIdType numLines = inputLines->GetNumberOfCells();
118 vtkIdType numPts = inputPoints->GetNumberOfPoints();
119 if ( numLines < 1 || numPts < 1 )
125 vtkPoints * newPts = vtkPoints::New();
126 vtkCellArray *newLines = vtkCellArray::New();
127 newLines->Allocate(numLines, 2);
128 vtkPointData *inPD = input->GetPointData();
129 vtkPointData *outPD = output->GetPointData();
130 vtkCellData * inCD = input->GetCellData();
131 vtkCellData * outCD = output->GetCellData();
132 outPD->CopyAllocate(inPD);
133 outCD->CopyAllocate(inCD);
136 vtkIdType i, cellId = 0, newId;
139 for ( i = 0; i < numPts; i++ )
144 for ( i = 0; i < numPts; i++ )
153 vtkIdType currentNumPts = this->
PriorityQueue->GetNumberOfItems();
154 while ( 1.0 - ( static_cast< double >( currentNumPts ) / static_cast< double >(
157 && currentNumPts > 2 )
166 newId = newLines->InsertNextCell(currentNumPts + 1);
167 outCD->CopyData(inCD, cellId, newId);
169 for ( std::map< int, double >::iterator it = this->
VertexErrorMap.begin();
173 newId = newPts->InsertNextPoint( inputPoints->GetPoint(it->first) );
174 newLines->InsertCellPoint(newId);
175 outPD->CopyData(inPD, it->first, newId);
179 newId = newPts->InsertNextPoint( newPts->GetPoint(0) );
180 newLines->InsertCellPoint(0);
181 outPD->CopyData(inPD, this->
VertexErrorMap.begin()->first, newId);
188 output->SetPoints(newPts);
189 output->SetLines(newLines);
200 std::map< int, double >::iterator it = this->
VertexErrorMap.find(iId);
225 std::map< int, double >::iterator it = this->
VertexErrorMap.find(iId);
226 std::map< int, double >::iterator end_it = this->
VertexErrorMap.end();
251 double prev_error =
ComputeError(input, prev_prev, prev, next);
257 double next_error =
ComputeError(input, prev, next, next_next);
266 this->Superclass::PrintSelf(os, indent);
int GetNext(const int &iId)
vtkCxxRevisionMacro(vtkPolylineDecimation,"$Revision: 1.1 $")
vtkPriorityQueue * PriorityQueue
vtkStandardNewMacro(vtkPolylineDecimation)
int RequestData(vtkInformation *vtkNotUsed(request), vtkInformationVector **inputVector, vtkInformationVector *outputVector)
double ComputeError(vtkPolyData *input, int prev, int id, int next)
void PrintSelf(ostream &os, vtkIndent indent)
int GetPrev(const int &iId)
std::map< int, double > VertexErrorMap
void UpdateError(vtkPolyData *input, const int &iId)