00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00100 #ifndef __vtkDecimatePro_h
00101 #define __vtkDecimatePro_h
00102
00103 #include "vtkPolyDataToPolyDataFilter.h"
00104
00105 #include "vtkCell.h"
00106
00107 class vtkFloatArray;
00108 class vtkPriorityQueue;
00109
00110 class VTK_GRAPHICS_EXPORT vtkDecimatePro : public vtkPolyDataToPolyDataFilter
00111 {
00112 public:
00113 vtkTypeRevisionMacro(vtkDecimatePro,vtkPolyDataToPolyDataFilter);
00114 void PrintSelf(ostream& os, vtkIndent indent);
00115
00122 static vtkDecimatePro *New();
00123
00125
00131 vtkSetClampMacro(TargetReduction,float,0.0,1.0);
00132 vtkGetMacro(TargetReduction,float);
00134
00136
00139 vtkSetMacro(PreserveTopology,int);
00140 vtkGetMacro(PreserveTopology,int);
00141 vtkBooleanMacro(PreserveTopology,int);
00143
00145
00148 vtkSetClampMacro(FeatureAngle,float,0.0,180.0);
00149 vtkGetMacro(FeatureAngle,float);
00151
00153
00157 vtkSetMacro(Splitting,int);
00158 vtkGetMacro(Splitting,int);
00159 vtkBooleanMacro(Splitting,int);
00161
00163
00166 vtkSetClampMacro(SplitAngle,float,0.0,180.0);
00167 vtkGetMacro(SplitAngle,float);
00169
00171
00177 vtkSetMacro(PreSplitMesh,int);
00178 vtkGetMacro(PreSplitMesh,int);
00179 vtkBooleanMacro(PreSplitMesh,int);
00181
00183
00187 vtkSetClampMacro(MaximumError,float,0.0,VTK_LARGE_FLOAT);
00188 vtkGetMacro(MaximumError,float);
00190
00192
00199 vtkSetMacro(AccumulateError,int);
00200 vtkGetMacro(AccumulateError,int);
00201 vtkBooleanMacro(AccumulateError,int);
00203
00205
00209 vtkSetMacro(ErrorIsAbsolute,int);
00210 vtkGetMacro(ErrorIsAbsolute,int);
00212
00214
00215 vtkSetClampMacro(AbsoluteError,float,0.0,VTK_LARGE_FLOAT);
00216 vtkGetMacro(AbsoluteError,float);
00218
00220
00222 vtkSetMacro(BoundaryVertexDeletion,int);
00223 vtkGetMacro(BoundaryVertexDeletion,int);
00224 vtkBooleanMacro(BoundaryVertexDeletion,int);
00226
00228
00232 vtkSetClampMacro(Degree,int,25,VTK_CELL_SIZE);
00233 vtkGetMacro(Degree,int);
00235
00237
00240 vtkSetClampMacro(InflectionPointRatio,float,1.001,VTK_LARGE_FLOAT);
00241 vtkGetMacro(InflectionPointRatio,float);
00243
00244
00250 vtkIdType GetNumberOfInflectionPoints();
00251
00256 void GetInflectionPoints(float *inflectionPoints);
00257
00263 float *GetInflectionPoints();
00264
00265 protected:
00266 vtkDecimatePro();
00267 ~vtkDecimatePro();
00268
00269 void Execute();
00270
00271 float TargetReduction;
00272 float FeatureAngle;
00273 float MaximumError;
00274 float AbsoluteError;
00275 int ErrorIsAbsolute;
00276 int AccumulateError;
00277 float SplitAngle;
00278 int Splitting;
00279 int PreSplitMesh;
00280 int BoundaryVertexDeletion;
00281 int PreserveTopology;
00282 int Degree;
00283 float InflectionPointRatio;
00284 vtkFloatArray *InflectionPoints;
00285
00286
00287 vtkIdList *Neighbors;
00288 vtkPriorityQueue *EdgeLengths;
00289
00290 void SplitMesh();
00291 int EvaluateVertex(vtkIdType ptId, unsigned short int numTris,
00292 vtkIdType *tris, vtkIdType fedges[2]);
00293 vtkIdType FindSplit(int type, vtkIdType fedges[2], vtkIdType& pt1,
00294 vtkIdType& pt2, vtkIdList *CollapseTris);
00295 int IsValidSplit(int index);
00296 void SplitLoop(vtkIdType fedges[2], vtkIdType& n1, vtkIdType *l1,
00297 vtkIdType& n2, vtkIdType *l2);
00298 void SplitVertex(vtkIdType ptId,int type, unsigned short int numTris,
00299 vtkIdType *tris, int insert);
00300 int CollapseEdge(int type, vtkIdType ptId, vtkIdType collapseId,
00301 vtkIdType pt1, vtkIdType pt2, vtkIdList *CollapseTris);
00302 void DistributeError(float error);
00303
00304
00305
00306
00307
00308
00309
00310 class LocalVertex
00311 {
00312 public:
00313 vtkIdType id;
00314 float x[3];
00315 float FAngle;
00316 };
00317 typedef LocalVertex *LocalVertexPtr;
00318
00319 class LocalTri
00320 {
00321 public:
00322 vtkIdType id;
00323 float area;
00324 float n[3];
00325 vtkIdType verts[3];
00326 };
00327 typedef LocalTri *LocalTriPtr;
00328
00329 class VertexArray;
00330 friend class VertexArray;
00331 class VertexArray {
00332 public:
00333 VertexArray(const vtkIdType sz)
00334 {this->MaxId = -1; this->Array = new LocalVertex[sz];};
00335 ~VertexArray()
00336 {
00337 if (this->Array)
00338 {
00339 delete [] this->Array;
00340 }
00341 };
00342 vtkIdType GetNumberOfVertices() {return this->MaxId + 1;};
00343 void InsertNextVertex(LocalVertex& v)
00344 {this->MaxId++; this->Array[this->MaxId] = v;};
00345 LocalVertex& GetVertex(vtkIdType i) {return this->Array[i];};
00346 void Reset() {this->MaxId = -1;};
00347
00348 LocalVertex *Array;
00349 vtkIdType MaxId;
00350 };
00351
00352 class TriArray;
00353 friend class TriArray;
00354 class TriArray {
00355 public:
00356 TriArray(const vtkIdType sz)
00357 {this->MaxId = -1; this->Array = new LocalTri[sz];};
00358 ~TriArray()
00359 {
00360 if (this->Array)
00361 {
00362 delete [] this->Array;
00363 }
00364 };
00365 vtkIdType GetNumberOfTriangles() {return this->MaxId + 1;};
00366 void InsertNextTriangle(LocalTri& t)
00367 {this->MaxId++; this->Array[this->MaxId] = t;};
00368 LocalTri& GetTriangle(vtkIdType i) {return this->Array[i];};
00369 void Reset() {this->MaxId = -1;};
00370
00371 LocalTri *Array;
00372 vtkIdType MaxId;
00373 };
00374
00375
00376
00377 private:
00378 void InitializeQueue(vtkIdType numPts);
00379 void DeleteQueue();
00380 void Insert(vtkIdType id, float error= -1.0);
00381 int Pop(float &error);
00382 float DeleteId(vtkIdType id);
00383 void Reset();
00384
00385 vtkPriorityQueue *Queue;
00386 vtkFloatArray *VertexError;
00387
00388 VertexArray *V;
00389 TriArray *T;
00390
00391
00392 vtkPolyData *Mesh;
00393 float Pt[3];
00394 float Normal[3];
00395 float LoopArea;
00396 float CosAngle;
00397 float Tolerance;
00398 float X[3];
00399 int NumCollapses;
00400 int NumMerges;
00401 int Split;
00402 int VertexDegree;
00403 vtkIdType NumberOfRemainingTris;
00404 float TheSplitAngle;
00405 int SplitState;
00406 float Error;
00407
00408 private:
00409 vtkDecimatePro(const vtkDecimatePro&);
00410 void operator=(const vtkDecimatePro&);
00411 };
00412
00413 #endif
00414
00415