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

Graphics/vtkDecimatePro.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkDecimatePro.h,v $
00005   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00101 #ifndef __vtkDecimatePro_h
00102 #define __vtkDecimatePro_h
00103 
00104 #include "vtkPolyDataToPolyDataFilter.h"
00105 
00106 #include "vtkCell.h" // Needed for VTK_CELL_SIZE
00107 
00108 class vtkFloatArray;
00109 class vtkPriorityQueue;
00110 
00111 class VTK_GRAPHICS_EXPORT vtkDecimatePro : public vtkPolyDataToPolyDataFilter
00112 {
00113 public:
00114   vtkTypeRevisionMacro(vtkDecimatePro,vtkPolyDataToPolyDataFilter);
00115   void PrintSelf(ostream& os, vtkIndent indent);
00116 
00123   static vtkDecimatePro *New();
00124 
00126 
00132   vtkSetClampMacro(TargetReduction,float,0.0,1.0);
00133   vtkGetMacro(TargetReduction,float);
00135 
00137 
00140   vtkSetMacro(PreserveTopology,int);
00141   vtkGetMacro(PreserveTopology,int);
00142   vtkBooleanMacro(PreserveTopology,int);
00144 
00146 
00149   vtkSetClampMacro(FeatureAngle,float,0.0,180.0);
00150   vtkGetMacro(FeatureAngle,float);
00152 
00154 
00158   vtkSetMacro(Splitting,int);
00159   vtkGetMacro(Splitting,int);
00160   vtkBooleanMacro(Splitting,int);
00162 
00164 
00167   vtkSetClampMacro(SplitAngle,float,0.0,180.0);
00168   vtkGetMacro(SplitAngle,float);
00170 
00172 
00178   vtkSetMacro(PreSplitMesh,int);
00179   vtkGetMacro(PreSplitMesh,int);
00180   vtkBooleanMacro(PreSplitMesh,int);
00182 
00184 
00188   vtkSetClampMacro(MaximumError,float,0.0,VTK_LARGE_FLOAT);
00189   vtkGetMacro(MaximumError,float);
00191 
00193 
00200   vtkSetMacro(AccumulateError,int);
00201   vtkGetMacro(AccumulateError,int);
00202   vtkBooleanMacro(AccumulateError,int);
00204 
00206 
00210   vtkSetMacro(ErrorIsAbsolute,int);
00211   vtkGetMacro(ErrorIsAbsolute,int);
00213 
00215 
00216   vtkSetClampMacro(AbsoluteError,float,0.0,VTK_LARGE_FLOAT);
00217   vtkGetMacro(AbsoluteError,float);
00219 
00221 
00223   vtkSetMacro(BoundaryVertexDeletion,int);
00224   vtkGetMacro(BoundaryVertexDeletion,int);
00225   vtkBooleanMacro(BoundaryVertexDeletion,int);
00227 
00229 
00233   vtkSetClampMacro(Degree,int,25,VTK_CELL_SIZE);
00234   vtkGetMacro(Degree,int);
00236   
00238 
00241   vtkSetClampMacro(InflectionPointRatio,float,1.001,VTK_LARGE_FLOAT);
00242   vtkGetMacro(InflectionPointRatio,float);
00244 
00245 
00251   vtkIdType GetNumberOfInflectionPoints();
00252 
00257   void GetInflectionPoints(float *inflectionPoints);
00258 
00264   float *GetInflectionPoints();
00265 
00266 protected:
00267   vtkDecimatePro();
00268   ~vtkDecimatePro();
00269 
00270   void Execute();
00271 
00272   float TargetReduction;
00273   float FeatureAngle;
00274   float MaximumError;
00275   float AbsoluteError;
00276   int ErrorIsAbsolute;
00277   int AccumulateError;
00278   float SplitAngle;
00279   int Splitting;
00280   int PreSplitMesh;
00281   int BoundaryVertexDeletion;
00282   int PreserveTopology;
00283   int Degree;
00284   float InflectionPointRatio;
00285   vtkFloatArray *InflectionPoints;
00286 
00287   // to replace a static object
00288   vtkIdList *Neighbors;
00289   vtkPriorityQueue *EdgeLengths;
00290 
00291   void SplitMesh();
00292   int EvaluateVertex(vtkIdType ptId, unsigned short int numTris,
00293                      vtkIdType *tris, vtkIdType fedges[2]);
00294   vtkIdType FindSplit(int type, vtkIdType fedges[2], vtkIdType& pt1,
00295                       vtkIdType& pt2, vtkIdList *CollapseTris);
00296   int IsValidSplit(int index);
00297   void SplitLoop(vtkIdType fedges[2], vtkIdType& n1, vtkIdType *l1,
00298                  vtkIdType& n2, vtkIdType *l2);
00299   void SplitVertex(vtkIdType ptId,int type, unsigned short int numTris,
00300                    vtkIdType *tris, int insert);
00301   int CollapseEdge(int type, vtkIdType ptId, vtkIdType collapseId,
00302                    vtkIdType pt1, vtkIdType pt2, vtkIdList *CollapseTris);
00303   void DistributeError(float error);
00304 
00305   //
00306   // Special classes for manipulating data
00307   //
00308   //BTX - begin tcl exclude
00309   //
00310   // Special structures for building loops
00311   class LocalVertex
00312   {
00313   public:
00314     vtkIdType     id;
00315     float   x[3];
00316     float   FAngle;
00317   };
00318   typedef LocalVertex *LocalVertexPtr;
00319     
00320   class LocalTri
00321   {
00322   public:
00323     vtkIdType     id;
00324     float   area;
00325     float   n[3];
00326     vtkIdType     verts[3];
00327   };
00328   typedef LocalTri *LocalTriPtr;
00329 
00330   class VertexArray;
00331   friend class VertexArray;
00332   class VertexArray { //;prevent man page generation
00333   public:
00334     VertexArray(const vtkIdType sz) 
00335       {this->MaxId = -1; this->Array = new LocalVertex[sz];};
00336     ~VertexArray()
00337       {
00338         if (this->Array)
00339           {
00340           delete [] this->Array;
00341           }
00342       };
00343     vtkIdType GetNumberOfVertices() {return this->MaxId + 1;};
00344     void InsertNextVertex(LocalVertex& v) 
00345       {this->MaxId++; this->Array[this->MaxId] = v;};
00346     LocalVertex& GetVertex(vtkIdType i) {return this->Array[i];};
00347     void Reset() {this->MaxId = -1;};
00348 
00349     LocalVertex *Array; // pointer to data
00350     vtkIdType MaxId;             // maximum index inserted thus far
00351   };
00352 
00353   class TriArray;
00354   friend class TriArray;
00355   class TriArray { //;prevent man page generation
00356   public:
00357     TriArray(const vtkIdType sz) 
00358       {this->MaxId = -1; this->Array = new LocalTri[sz];};
00359     ~TriArray()
00360       {
00361         if (this->Array)
00362           {
00363           delete [] this->Array;
00364           }
00365       };
00366     vtkIdType GetNumberOfTriangles() {return this->MaxId + 1;};
00367     void InsertNextTriangle(LocalTri& t) 
00368       {this->MaxId++; this->Array[this->MaxId] = t;};
00369     LocalTri& GetTriangle(vtkIdType i) {return this->Array[i];};
00370     void Reset() {this->MaxId = -1;};
00371 
00372     LocalTri *Array;  // pointer to data
00373     vtkIdType MaxId;           // maximum index inserted thus far
00374   };
00375   //ETX - end tcl exclude
00376   //
00377 
00378 private:
00379   void InitializeQueue(vtkIdType numPts);
00380   void DeleteQueue();
00381   void Insert(vtkIdType id, float error= -1.0);
00382   int Pop(float &error);
00383   float DeleteId(vtkIdType id);
00384   void Reset();
00385 
00386   vtkPriorityQueue *Queue;
00387   vtkFloatArray *VertexError;
00388 
00389   VertexArray *V;
00390   TriArray *T;
00391 
00392   // Use to be static variables used by object
00393   vtkPolyData *Mesh; //operate on this data structure
00394   float Pt[3];      //least squares plane point
00395   float Normal[3];  //least squares plane normal
00396   float LoopArea;   //the total area of all triangles in a loop
00397   float CosAngle;   //Cosine of dihedral angle
00398   float Tolerance;  //Intersection tolerance
00399   float X[3];       //coordinates of current point
00400   int NumCollapses; //Number of times edge collapses occur
00401   int NumMerges;    //Number of times vertex merges occur
00402   int Split;        //Controls whether and when vertex splitting occurs
00403   int VertexDegree; //Maximum number of triangles that can use a vertex
00404   vtkIdType NumberOfRemainingTris; //Number of triangles left in the mesh
00405   float TheSplitAngle; //Split angle
00406   int SplitState;   //State of the splitting process
00407   float Error;      //Maximum allowable surface error
00408 
00409 private:
00410   vtkDecimatePro(const vtkDecimatePro&);  // Not implemented.
00411   void operator=(const vtkDecimatePro&);  // Not implemented.
00412 };
00413 
00414 #endif
00415 
00416