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 delete [] this->Array; 00335 }; 00336 vtkIdType GetNumberOfVertices() {return this->MaxId + 1;}; 00337 void InsertNextVertex(LocalVertex& v) 00338 {this->MaxId++; this->Array[this->MaxId] = v;}; 00339 LocalVertex& GetVertex(vtkIdType i) {return this->Array[i];}; 00340 void Reset() {this->MaxId = -1;}; 00341 00342 LocalVertex *Array; // pointer to data 00343 vtkIdType MaxId; // maximum index inserted thus far 00344 }; 00345 00346 class TriArray; 00347 friend class TriArray; 00348 class TriArray { //;prevent man page generation 00349 public: 00350 TriArray(const vtkIdType sz) 00351 {this->MaxId = -1; this->Array = new LocalTri[sz];}; 00352 ~TriArray() 00353 { 00354 delete [] this->Array; 00355 }; 00356 vtkIdType GetNumberOfTriangles() {return this->MaxId + 1;}; 00357 void InsertNextTriangle(LocalTri& t) 00358 {this->MaxId++; this->Array[this->MaxId] = t;}; 00359 LocalTri& GetTriangle(vtkIdType i) {return this->Array[i];}; 00360 void Reset() {this->MaxId = -1;}; 00361 00362 LocalTri *Array; // pointer to data 00363 vtkIdType MaxId; // maximum index inserted thus far 00364 }; 00365 //ETX - end tcl exclude 00366 // 00367 00368 private: 00369 void InitializeQueue(vtkIdType numPts); 00370 void DeleteQueue(); 00371 void Insert(vtkIdType id, double error= -1.0); 00372 int Pop(double &error); 00373 double DeleteId(vtkIdType id); 00374 void Reset(); 00375 00376 vtkPriorityQueue *Queue; 00377 vtkDoubleArray *VertexError; 00378 00379 VertexArray *V; 00380 TriArray *T; 00381 00382 // Use to be static variables used by object 00383 vtkPolyData *Mesh; //operate on this data structure 00384 double Pt[3]; //least squares plane point 00385 double Normal[3]; //least squares plane normal 00386 double LoopArea; //the total area of all triangles in a loop 00387 double CosAngle; //Cosine of dihedral angle 00388 double Tolerance; //Intersection tolerance 00389 double X[3]; //coordinates of current point 00390 int NumCollapses; //Number of times edge collapses occur 00391 int NumMerges; //Number of times vertex merges occur 00392 int Split; //Controls whether and when vertex splitting occurs 00393 int VertexDegree; //Maximum number of triangles that can use a vertex 00394 vtkIdType NumberOfRemainingTris; //Number of triangles left in the mesh 00395 double TheSplitAngle; //Split angle 00396 int SplitState; //State of the splitting process 00397 double Error; //Maximum allowable surface error 00398 00399 private: 00400 vtkDecimatePro(const vtkDecimatePro&); // Not implemented. 00401 void operator=(const vtkDecimatePro&); // Not implemented. 00402 }; 00403 00404 #endif 00405 00406