VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkDecimatePro.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00085 #ifndef __vtkDecimatePro_h 00086 #define __vtkDecimatePro_h 00087 00088 #include "vtkFiltersCoreModule.h" // For export macro 00089 #include "vtkPolyDataAlgorithm.h" 00090 00091 #include "vtkCell.h" // Needed for VTK_CELL_SIZE 00092 00093 class vtkDoubleArray; 00094 class vtkPriorityQueue; 00095 00096 class VTKFILTERSCORE_EXPORT vtkDecimatePro : public vtkPolyDataAlgorithm 00097 { 00098 public: 00099 vtkTypeMacro(vtkDecimatePro,vtkPolyDataAlgorithm); 00100 void PrintSelf(ostream& os, vtkIndent indent); 00101 00108 static vtkDecimatePro *New(); 00109 00111 00119 vtkSetClampMacro(TargetReduction,double,0.0,1.0); 00120 vtkGetMacro(TargetReduction,double); 00122 00124 00127 vtkSetMacro(PreserveTopology,int); 00128 vtkGetMacro(PreserveTopology,int); 00129 vtkBooleanMacro(PreserveTopology,int); 00131 00133 00136 vtkSetClampMacro(FeatureAngle,double,0.0,180.0); 00137 vtkGetMacro(FeatureAngle,double); 00139 00141 00145 vtkSetMacro(Splitting,int); 00146 vtkGetMacro(Splitting,int); 00147 vtkBooleanMacro(Splitting,int); 00149 00151 00154 vtkSetClampMacro(SplitAngle,double,0.0,180.0); 00155 vtkGetMacro(SplitAngle,double); 00157 00159 00165 vtkSetMacro(PreSplitMesh,int); 00166 vtkGetMacro(PreSplitMesh,int); 00167 vtkBooleanMacro(PreSplitMesh,int); 00169 00171 00175 vtkSetClampMacro(MaximumError,double,0.0,VTK_DOUBLE_MAX); 00176 vtkGetMacro(MaximumError,double); 00178 00180 00187 vtkSetMacro(AccumulateError,int); 00188 vtkGetMacro(AccumulateError,int); 00189 vtkBooleanMacro(AccumulateError,int); 00191 00193 00197 vtkSetMacro(ErrorIsAbsolute,int); 00198 vtkGetMacro(ErrorIsAbsolute,int); 00200 00202 00203 vtkSetClampMacro(AbsoluteError,double,0.0,VTK_DOUBLE_MAX); 00204 vtkGetMacro(AbsoluteError,double); 00206 00208 00210 vtkSetMacro(BoundaryVertexDeletion,int); 00211 vtkGetMacro(BoundaryVertexDeletion,int); 00212 vtkBooleanMacro(BoundaryVertexDeletion,int); 00214 00216 00220 vtkSetClampMacro(Degree,int,25,VTK_CELL_SIZE); 00221 vtkGetMacro(Degree,int); 00223 00225 00228 vtkSetClampMacro(InflectionPointRatio,double,1.001,VTK_DOUBLE_MAX); 00229 vtkGetMacro(InflectionPointRatio,double); 00231 00232 00238 vtkIdType GetNumberOfInflectionPoints(); 00239 00244 void GetInflectionPoints(double *inflectionPoints); 00245 00251 double *GetInflectionPoints(); 00252 00254 00257 vtkSetMacro(OutputPointsPrecision,int); 00258 vtkGetMacro(OutputPointsPrecision,int); 00260 00261 protected: 00262 vtkDecimatePro(); 00263 ~vtkDecimatePro(); 00264 00265 int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); 00266 00267 double TargetReduction; 00268 double FeatureAngle; 00269 double MaximumError; 00270 double AbsoluteError; 00271 int ErrorIsAbsolute; 00272 int AccumulateError; 00273 double SplitAngle; 00274 int Splitting; 00275 int PreSplitMesh; 00276 int BoundaryVertexDeletion; 00277 int PreserveTopology; 00278 int Degree; 00279 double InflectionPointRatio; 00280 vtkDoubleArray *InflectionPoints; 00281 int OutputPointsPrecision; 00282 00283 // to replace a static object 00284 vtkIdList *Neighbors; 00285 vtkPriorityQueue *EdgeLengths; 00286 00287 void SplitMesh(); 00288 int EvaluateVertex(vtkIdType ptId, unsigned short int numTris, 00289 vtkIdType *tris, vtkIdType fedges[2]); 00290 vtkIdType FindSplit(int type, vtkIdType fedges[2], vtkIdType& pt1, 00291 vtkIdType& pt2, vtkIdList *CollapseTris); 00292 int IsValidSplit(int index); 00293 void SplitLoop(vtkIdType fedges[2], vtkIdType& n1, vtkIdType *l1, 00294 vtkIdType& n2, vtkIdType *l2); 00295 void SplitVertex(vtkIdType ptId,int type, unsigned short int numTris, 00296 vtkIdType *tris, int insert); 00297 int CollapseEdge(int type, vtkIdType ptId, vtkIdType collapseId, 00298 vtkIdType pt1, vtkIdType pt2, vtkIdList *CollapseTris); 00299 void DistributeError(double error); 00300 00301 // 00302 // Special classes for manipulating data 00303 // 00304 //BTX - begin tcl exclude 00305 // 00306 // Special structures for building loops 00307 class LocalVertex 00308 { 00309 public: 00310 vtkIdType id; 00311 double x[3]; 00312 double FAngle; 00313 }; 00314 typedef LocalVertex *LocalVertexPtr; 00315 00316 class LocalTri 00317 { 00318 public: 00319 vtkIdType id; 00320 double area; 00321 double n[3]; 00322 vtkIdType verts[3]; 00323 }; 00324 typedef LocalTri *LocalTriPtr; 00325 00326 class VertexArray; 00327 friend class VertexArray; 00328 class VertexArray { //;prevent man page generation 00329 public: 00330 VertexArray(const vtkIdType sz) 00331 {this->MaxId = -1; this->Array = new LocalVertex[sz];}; 00332 ~VertexArray() 00333 { 00334 if (this->Array) 00335 { 00336 delete [] this->Array; 00337 } 00338 }; 00339 vtkIdType GetNumberOfVertices() {return this->MaxId + 1;}; 00340 void InsertNextVertex(LocalVertex& v) 00341 {this->MaxId++; this->Array[this->MaxId] = v;}; 00342 LocalVertex& GetVertex(vtkIdType i) {return this->Array[i];}; 00343 void Reset() {this->MaxId = -1;}; 00344 00345 LocalVertex *Array; // pointer to data 00346 vtkIdType MaxId; // maximum index inserted thus far 00347 }; 00348 00349 class TriArray; 00350 friend class TriArray; 00351 class TriArray { //;prevent man page generation 00352 public: 00353 TriArray(const vtkIdType sz) 00354 {this->MaxId = -1; this->Array = new LocalTri[sz];}; 00355 ~TriArray() 00356 { 00357 if (this->Array) 00358 { 00359 delete [] this->Array; 00360 } 00361 }; 00362 vtkIdType GetNumberOfTriangles() {return this->MaxId + 1;}; 00363 void InsertNextTriangle(LocalTri& t) 00364 {this->MaxId++; this->Array[this->MaxId] = t;}; 00365 LocalTri& GetTriangle(vtkIdType i) {return this->Array[i];}; 00366 void Reset() {this->MaxId = -1;}; 00367 00368 LocalTri *Array; // pointer to data 00369 vtkIdType MaxId; // maximum index inserted thus far 00370 }; 00371 //ETX - end tcl exclude 00372 // 00373 00374 private: 00375 void InitializeQueue(vtkIdType numPts); 00376 void DeleteQueue(); 00377 void Insert(vtkIdType id, double error= -1.0); 00378 int Pop(double &error); 00379 double DeleteId(vtkIdType id); 00380 void Reset(); 00381 00382 vtkPriorityQueue *Queue; 00383 vtkDoubleArray *VertexError; 00384 00385 VertexArray *V; 00386 TriArray *T; 00387 00388 // Use to be static variables used by object 00389 vtkPolyData *Mesh; //operate on this data structure 00390 double Pt[3]; //least squares plane point 00391 double Normal[3]; //least squares plane normal 00392 double LoopArea; //the total area of all triangles in a loop 00393 double CosAngle; //Cosine of dihedral angle 00394 double Tolerance; //Intersection tolerance 00395 double X[3]; //coordinates of current point 00396 int NumCollapses; //Number of times edge collapses occur 00397 int NumMerges; //Number of times vertex merges occur 00398 int Split; //Controls whether and when vertex splitting occurs 00399 int VertexDegree; //Maximum number of triangles that can use a vertex 00400 vtkIdType NumberOfRemainingTris; //Number of triangles left in the mesh 00401 double TheSplitAngle; //Split angle 00402 int SplitState; //State of the splitting process 00403 double Error; //Maximum allowable surface error 00404 00405 private: 00406 vtkDecimatePro(const vtkDecimatePro&); // Not implemented. 00407 void operator=(const vtkDecimatePro&); // Not implemented. 00408 }; 00409 00410 #endif 00411 00412