VTK
dox/Filters/Core/vtkDecimatePro.h
Go to the documentation of this file.
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 
00253 protected:
00254   vtkDecimatePro();
00255   ~vtkDecimatePro();
00256 
00257   int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
00258 
00259   double TargetReduction;
00260   double FeatureAngle;
00261   double MaximumError;
00262   double AbsoluteError;
00263   int ErrorIsAbsolute;
00264   int AccumulateError;
00265   double SplitAngle;
00266   int Splitting;
00267   int PreSplitMesh;
00268   int BoundaryVertexDeletion;
00269   int PreserveTopology;
00270   int Degree;
00271   double InflectionPointRatio;
00272   vtkDoubleArray *InflectionPoints;
00273 
00274   // to replace a static object
00275   vtkIdList *Neighbors;
00276   vtkPriorityQueue *EdgeLengths;
00277 
00278   void SplitMesh();
00279   int EvaluateVertex(vtkIdType ptId, unsigned short int numTris,
00280                      vtkIdType *tris, vtkIdType fedges[2]);
00281   vtkIdType FindSplit(int type, vtkIdType fedges[2], vtkIdType& pt1,
00282                       vtkIdType& pt2, vtkIdList *CollapseTris);
00283   int IsValidSplit(int index);
00284   void SplitLoop(vtkIdType fedges[2], vtkIdType& n1, vtkIdType *l1,
00285                  vtkIdType& n2, vtkIdType *l2);
00286   void SplitVertex(vtkIdType ptId,int type, unsigned short int numTris,
00287                    vtkIdType *tris, int insert);
00288   int CollapseEdge(int type, vtkIdType ptId, vtkIdType collapseId,
00289                    vtkIdType pt1, vtkIdType pt2, vtkIdList *CollapseTris);
00290   void DistributeError(double error);
00291 
00292   //
00293   // Special classes for manipulating data
00294   //
00295   //BTX - begin tcl exclude
00296   //
00297   // Special structures for building loops
00298   class LocalVertex
00299   {
00300   public:
00301     vtkIdType     id;
00302     double   x[3];
00303     double   FAngle;
00304   };
00305   typedef LocalVertex *LocalVertexPtr;
00306 
00307   class LocalTri
00308   {
00309   public:
00310     vtkIdType     id;
00311     double   area;
00312     double   n[3];
00313     vtkIdType     verts[3];
00314   };
00315   typedef LocalTri *LocalTriPtr;
00316 
00317   class VertexArray;
00318   friend class VertexArray;
00319   class VertexArray { //;prevent man page generation
00320   public:
00321     VertexArray(const vtkIdType sz)
00322       {this->MaxId = -1; this->Array = new LocalVertex[sz];};
00323     ~VertexArray()
00324       {
00325         if (this->Array)
00326           {
00327           delete [] this->Array;
00328           }
00329       };
00330     vtkIdType GetNumberOfVertices() {return this->MaxId + 1;};
00331     void InsertNextVertex(LocalVertex& v)
00332       {this->MaxId++; this->Array[this->MaxId] = v;};
00333     LocalVertex& GetVertex(vtkIdType i) {return this->Array[i];};
00334     void Reset() {this->MaxId = -1;};
00335 
00336     LocalVertex *Array; // pointer to data
00337     vtkIdType MaxId;             // maximum index inserted thus far
00338   };
00339 
00340   class TriArray;
00341   friend class TriArray;
00342   class TriArray { //;prevent man page generation
00343   public:
00344     TriArray(const vtkIdType sz)
00345       {this->MaxId = -1; this->Array = new LocalTri[sz];};
00346     ~TriArray()
00347       {
00348         if (this->Array)
00349           {
00350           delete [] this->Array;
00351           }
00352       };
00353     vtkIdType GetNumberOfTriangles() {return this->MaxId + 1;};
00354     void InsertNextTriangle(LocalTri& t)
00355       {this->MaxId++; this->Array[this->MaxId] = t;};
00356     LocalTri& GetTriangle(vtkIdType i) {return this->Array[i];};
00357     void Reset() {this->MaxId = -1;};
00358 
00359     LocalTri *Array;  // pointer to data
00360     vtkIdType MaxId;           // maximum index inserted thus far
00361   };
00362   //ETX - end tcl exclude
00363   //
00364 
00365 private:
00366   void InitializeQueue(vtkIdType numPts);
00367   void DeleteQueue();
00368   void Insert(vtkIdType id, double error= -1.0);
00369   int Pop(double &error);
00370   double DeleteId(vtkIdType id);
00371   void Reset();
00372 
00373   vtkPriorityQueue *Queue;
00374   vtkDoubleArray *VertexError;
00375 
00376   VertexArray *V;
00377   TriArray *T;
00378 
00379   // Use to be static variables used by object
00380   vtkPolyData *Mesh; //operate on this data structure
00381   double Pt[3];      //least squares plane point
00382   double Normal[3];  //least squares plane normal
00383   double LoopArea;   //the total area of all triangles in a loop
00384   double CosAngle;   //Cosine of dihedral angle
00385   double Tolerance;  //Intersection tolerance
00386   double X[3];       //coordinates of current point
00387   int NumCollapses; //Number of times edge collapses occur
00388   int NumMerges;    //Number of times vertex merges occur
00389   int Split;        //Controls whether and when vertex splitting occurs
00390   int VertexDegree; //Maximum number of triangles that can use a vertex
00391   vtkIdType NumberOfRemainingTris; //Number of triangles left in the mesh
00392   double TheSplitAngle; //Split angle
00393   int SplitState;   //State of the splitting process
00394   double Error;      //Maximum allowable surface error
00395 
00396 private:
00397   vtkDecimatePro(const vtkDecimatePro&);  // Not implemented.
00398   void operator=(const vtkDecimatePro&);  // Not implemented.
00399 };
00400 
00401 #endif
00402 
00403