Main Page | Directories | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

vtkDecimatePro.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkDecimatePro.h,v $
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 =========================================================================*/
00097 #ifndef __vtkDecimatePro_h
00098 #define __vtkDecimatePro_h
00099 
00100 #include "vtkPolyDataToPolyDataFilter.h"
00101 
00102 #include "vtkCell.h" // Needed for VTK_CELL_SIZE
00103 
00104 class vtkDoubleArray;
00105 class vtkPriorityQueue;
00106 
00107 class VTK_GRAPHICS_EXPORT vtkDecimatePro : public vtkPolyDataToPolyDataFilter
00108 {
00109 public:
00110   vtkTypeRevisionMacro(vtkDecimatePro,vtkPolyDataToPolyDataFilter);
00111   void PrintSelf(ostream& os, vtkIndent indent);
00112 
00119   static vtkDecimatePro *New();
00120 
00122 
00130   vtkSetClampMacro(TargetReduction,double,0.0,1.0);
00131   vtkGetMacro(TargetReduction,double);
00133 
00135 
00138   vtkSetMacro(PreserveTopology,int);
00139   vtkGetMacro(PreserveTopology,int);
00140   vtkBooleanMacro(PreserveTopology,int);
00142 
00144 
00147   vtkSetClampMacro(FeatureAngle,double,0.0,180.0);
00148   vtkGetMacro(FeatureAngle,double);
00150 
00152 
00156   vtkSetMacro(Splitting,int);
00157   vtkGetMacro(Splitting,int);
00158   vtkBooleanMacro(Splitting,int);
00160 
00162 
00165   vtkSetClampMacro(SplitAngle,double,0.0,180.0);
00166   vtkGetMacro(SplitAngle,double);
00168 
00170 
00176   vtkSetMacro(PreSplitMesh,int);
00177   vtkGetMacro(PreSplitMesh,int);
00178   vtkBooleanMacro(PreSplitMesh,int);
00180 
00182 
00186   vtkSetClampMacro(MaximumError,double,0.0,VTK_DOUBLE_MAX);
00187   vtkGetMacro(MaximumError,double);
00189 
00191 
00198   vtkSetMacro(AccumulateError,int);
00199   vtkGetMacro(AccumulateError,int);
00200   vtkBooleanMacro(AccumulateError,int);
00202 
00204 
00208   vtkSetMacro(ErrorIsAbsolute,int);
00209   vtkGetMacro(ErrorIsAbsolute,int);
00211 
00213 
00214   vtkSetClampMacro(AbsoluteError,double,0.0,VTK_DOUBLE_MAX);
00215   vtkGetMacro(AbsoluteError,double);
00217 
00219 
00221   vtkSetMacro(BoundaryVertexDeletion,int);
00222   vtkGetMacro(BoundaryVertexDeletion,int);
00223   vtkBooleanMacro(BoundaryVertexDeletion,int);
00225 
00227 
00231   vtkSetClampMacro(Degree,int,25,VTK_CELL_SIZE);
00232   vtkGetMacro(Degree,int);
00234   
00236 
00239   vtkSetClampMacro(InflectionPointRatio,double,1.001,VTK_DOUBLE_MAX);
00240   vtkGetMacro(InflectionPointRatio,double);
00242 
00243 
00249   vtkIdType GetNumberOfInflectionPoints();
00250 
00255   void GetInflectionPoints(double *inflectionPoints);
00256 
00262   double *GetInflectionPoints();
00263 
00264 protected:
00265   vtkDecimatePro();
00266   ~vtkDecimatePro();
00267 
00268   void Execute();
00269 
00270   double TargetReduction;
00271   double FeatureAngle;
00272   double MaximumError;
00273   double AbsoluteError;
00274   int ErrorIsAbsolute;
00275   int AccumulateError;
00276   double SplitAngle;
00277   int Splitting;
00278   int PreSplitMesh;
00279   int BoundaryVertexDeletion;
00280   int PreserveTopology;
00281   int Degree;
00282   double InflectionPointRatio;
00283   vtkDoubleArray *InflectionPoints;
00284 
00285   // to replace a static object
00286   vtkIdList *Neighbors;
00287   vtkPriorityQueue *EdgeLengths;
00288 
00289   void SplitMesh();
00290   int EvaluateVertex(vtkIdType ptId, unsigned short int numTris,
00291                      vtkIdType *tris, vtkIdType fedges[2]);
00292   vtkIdType FindSplit(int type, vtkIdType fedges[2], vtkIdType& pt1,
00293                       vtkIdType& pt2, vtkIdList *CollapseTris);
00294   int IsValidSplit(int index);
00295   void SplitLoop(vtkIdType fedges[2], vtkIdType& n1, vtkIdType *l1,
00296                  vtkIdType& n2, vtkIdType *l2);
00297   void SplitVertex(vtkIdType ptId,int type, unsigned short int numTris,
00298                    vtkIdType *tris, int insert);
00299   int CollapseEdge(int type, vtkIdType ptId, vtkIdType collapseId,
00300                    vtkIdType pt1, vtkIdType pt2, vtkIdList *CollapseTris);
00301   void DistributeError(double error);
00302 
00303   //
00304   // Special classes for manipulating data
00305   //
00306   //BTX - begin tcl exclude
00307   //
00308   // Special structures for building loops
00309   class LocalVertex
00310   {
00311   public:
00312     vtkIdType     id;
00313     double   x[3];
00314     double   FAngle;
00315   };
00316   typedef LocalVertex *LocalVertexPtr;
00317     
00318   class LocalTri
00319   {
00320   public:
00321     vtkIdType     id;
00322     double   area;
00323     double   n[3];
00324     vtkIdType     verts[3];
00325   };
00326   typedef LocalTri *LocalTriPtr;
00327 
00328   class VertexArray;
00329   friend class VertexArray;
00330   class VertexArray { //;prevent man page generation
00331   public:
00332     VertexArray(const vtkIdType sz) 
00333       {this->MaxId = -1; this->Array = new LocalVertex[sz];};
00334     ~VertexArray()
00335       {
00336         if (this->Array)
00337           {
00338           delete [] this->Array;
00339           }
00340       };
00341     vtkIdType GetNumberOfVertices() {return this->MaxId + 1;};
00342     void InsertNextVertex(LocalVertex& v) 
00343       {this->MaxId++; this->Array[this->MaxId] = v;};
00344     LocalVertex& GetVertex(vtkIdType i) {return this->Array[i];};
00345     void Reset() {this->MaxId = -1;};
00346 
00347     LocalVertex *Array; // pointer to data
00348     vtkIdType MaxId;             // maximum index inserted thus far
00349   };
00350 
00351   class TriArray;
00352   friend class TriArray;
00353   class TriArray { //;prevent man page generation
00354   public:
00355     TriArray(const vtkIdType sz) 
00356       {this->MaxId = -1; this->Array = new LocalTri[sz];};
00357     ~TriArray()
00358       {
00359         if (this->Array)
00360           {
00361           delete [] this->Array;
00362           }
00363       };
00364     vtkIdType GetNumberOfTriangles() {return this->MaxId + 1;};
00365     void InsertNextTriangle(LocalTri& t) 
00366       {this->MaxId++; this->Array[this->MaxId] = t;};
00367     LocalTri& GetTriangle(vtkIdType i) {return this->Array[i];};
00368     void Reset() {this->MaxId = -1;};
00369 
00370     LocalTri *Array;  // pointer to data
00371     vtkIdType MaxId;           // maximum index inserted thus far
00372   };
00373   //ETX - end tcl exclude
00374   //
00375 
00376 private:
00377   void InitializeQueue(vtkIdType numPts);
00378   void DeleteQueue();
00379   void Insert(vtkIdType id, double error= -1.0);
00380   int Pop(double &error);
00381   double DeleteId(vtkIdType id);
00382   void Reset();
00383 
00384   vtkPriorityQueue *Queue;
00385   vtkDoubleArray *VertexError;
00386 
00387   VertexArray *V;
00388   TriArray *T;
00389 
00390   // Use to be static variables used by object
00391   vtkPolyData *Mesh; //operate on this data structure
00392   double Pt[3];      //least squares plane point
00393   double Normal[3];  //least squares plane normal
00394   double LoopArea;   //the total area of all triangles in a loop
00395   double CosAngle;   //Cosine of dihedral angle
00396   double Tolerance;  //Intersection tolerance
00397   double X[3];       //coordinates of current point
00398   int NumCollapses; //Number of times edge collapses occur
00399   int NumMerges;    //Number of times vertex merges occur
00400   int Split;        //Controls whether and when vertex splitting occurs
00401   int VertexDegree; //Maximum number of triangles that can use a vertex
00402   vtkIdType NumberOfRemainingTris; //Number of triangles left in the mesh
00403   double TheSplitAngle; //Split angle
00404   int SplitState;   //State of the splitting process
00405   double Error;      //Maximum allowable surface error
00406 
00407 private:
00408   vtkDecimatePro(const vtkDecimatePro&);  // Not implemented.
00409   void operator=(const vtkDecimatePro&);  // Not implemented.
00410 };
00411 
00412 #endif
00413 
00414