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

vtkDecimate.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkDecimate.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 
00015      THIS CLASS IS PATENTED UNDER UNITED STATES PATENT NUMBER 5,559,388
00016      "Method for Reducting the Complexity of a Polygonal Mesh".
00017      Application of this software for commercial purposes requires 
00018      a license grant from GE. Contact:
00019 
00020          Carl B. Horton
00021          Sr. Counsel, Intellectual Property
00022          3000 N. Grandview Blvd., W-710
00023          Waukesha, WI  53188
00024          Phone:  (262) 513-4022
00025          E-Mail: [email protected]
00026 
00027      for more information.
00028 
00029 =========================================================================*/
00099 #ifndef __vtkDecimate_h
00100 #define __vtkDecimate_h
00101 
00102 #include "vtkPolyDataToPolyDataFilter.h"
00103 
00104 #include "vtkCell.h" // Needed for VTK_CELL_SIZE
00105 
00106 #define VTK_NUMBER_STATISTICS 12
00107 
00108 class vtkIdList;
00109 
00110 class VTK_PATENTED_EXPORT vtkDecimate : public vtkPolyDataToPolyDataFilter
00111 {
00112 public:
00113   static vtkDecimate *New();
00114   vtkTypeRevisionMacro(vtkDecimate,vtkPolyDataToPolyDataFilter);
00115   void PrintSelf(ostream& os, vtkIndent indent);
00116 
00118 
00120   vtkSetClampMacro(InitialError,double,0.0,1.0);
00121   vtkGetMacro(InitialError,double);
00123 
00125 
00127   vtkSetClampMacro(ErrorIncrement,double,0.0,1.0);
00128   vtkGetMacro(ErrorIncrement,double);
00130 
00132 
00134   vtkSetClampMacro(MaximumError,double,0.0,1.0);
00135   vtkGetMacro(MaximumError,double);
00137 
00139 
00142   vtkSetClampMacro(TargetReduction,double,0.0,1.0);
00143   vtkGetMacro(TargetReduction,double);
00145 
00147 
00149   vtkSetClampMacro(MaximumIterations,int,0,VTK_LARGE_INTEGER);
00150   vtkGetMacro(MaximumIterations,int);
00152 
00154 
00156   vtkSetClampMacro(MaximumSubIterations,int,1,VTK_LARGE_INTEGER);
00157   vtkGetMacro(MaximumSubIterations,int);
00159   
00161 
00162   vtkSetClampMacro(InitialFeatureAngle,double,0.0,180.0);
00163   vtkGetMacro(InitialFeatureAngle,double);
00165 
00167 
00169   vtkSetClampMacro(FeatureAngleIncrement,double,0.0,180.0);
00170   vtkGetMacro(FeatureAngleIncrement,double);
00172 
00174 
00175   vtkSetClampMacro(MaximumFeatureAngle,double,0.0,180.0);
00176   vtkGetMacro(MaximumFeatureAngle,double);
00178 
00180 
00181   vtkSetMacro(GenerateErrorScalars,int);
00182   vtkGetMacro(GenerateErrorScalars,int);
00183   vtkBooleanMacro(GenerateErrorScalars,int);
00185 
00187 
00188   vtkSetMacro(PreserveEdges,int);
00189   vtkGetMacro(PreserveEdges,int);
00190   vtkBooleanMacro(PreserveEdges,int);
00192 
00194 
00195   vtkSetMacro(BoundaryVertexDeletion,int);
00196   vtkGetMacro(BoundaryVertexDeletion,int);
00197   vtkBooleanMacro(BoundaryVertexDeletion,int);
00199 
00201 
00202   vtkSetClampMacro(AspectRatio,double,1.0,1000.0);
00203   vtkGetMacro(AspectRatio,double);
00205 
00207 
00209   vtkSetMacro(PreserveTopology,int);
00210   vtkGetMacro(PreserveTopology,int);
00211   vtkBooleanMacro(PreserveTopology,int);
00213 
00215 
00219   vtkSetClampMacro(Degree,int,25,VTK_CELL_SIZE);
00220   vtkGetMacro(Degree,int);
00222   
00224 
00227   vtkSetClampMacro(MaximumNumberOfSquawks,int,0,VTK_LARGE_INTEGER);
00228   vtkGetMacro(MaximumNumberOfSquawks,int);
00230   
00231 protected:
00232 
00233   //
00234   // Special classes for manipulating data
00235   //
00236   //BTX - begin tcl exclude
00237   //
00238   // Special structures for building loops
00239   class LocalVertex
00240   {
00241   public:
00242     vtkIdType     id;
00243     double   x[3];
00244     double   FAngle;
00245     int     deRefs; //monitor memory requirements; new only when necessary
00246     int     newRefs;
00247   };
00248   typedef LocalVertex *LocalVertexPtr;
00249     
00250   class LocalTri
00251   {
00252   public:
00253     vtkIdType     id;
00254     double   area;
00255     double   n[3];
00256     vtkIdType     verts[3];
00257   };
00258   typedef LocalTri *LocalTriPtr;
00259 
00260   class VertexArray;
00261   friend class VertexArray;
00262   class VertexArray { //;prevent man page generation
00263   public:
00264     VertexArray(const vtkIdType sz) 
00265       {this->MaxId = -1; this->Array = new LocalVertex[sz];};
00266     ~VertexArray() {if (this->Array) {delete [] this->Array;}};
00267     vtkIdType GetNumberOfVertices() {return this->MaxId + 1;};
00268     void InsertNextVertex(LocalVertex& v) 
00269       {this->MaxId++; this->Array[this->MaxId] = v;};
00270     LocalVertex& GetVertex(vtkIdType i) {return this->Array[i];};
00271     void Reset() {this->MaxId = -1;};
00272 
00273     LocalVertex *Array;  // pointer to data
00274     vtkIdType MaxId;             // maximum index inserted thus far
00275   };
00276 
00277   class TriArray;
00278   friend class TriArray;
00279   class TriArray { //;prevent man page generation
00280   public:
00281     TriArray(const vtkIdType sz) 
00282       {this->MaxId = -1; this->Array = new LocalTri[sz];};
00283     ~TriArray() {if (this->Array) {delete [] this->Array;}};
00284     vtkIdType GetNumberOfTriangles() {return this->MaxId + 1;};
00285     void InsertNextTriangle(LocalTri& t) 
00286       {this->MaxId++; this->Array[this->MaxId] = t;};
00287     LocalTri& GetTriangle(vtkIdType i) {return this->Array[i];};
00288     void Reset() {this->MaxId = -1;};
00289 
00290     LocalTri *Array;  // pointer to data
00291     vtkIdType MaxId;            // maximum index inserted thus far
00292   };
00293   //ETX - end tcl exclude
00294   //
00295 
00296   vtkDecimate();
00297   ~vtkDecimate();
00298 
00299   void Execute();
00300 
00301   double InitialFeatureAngle; // dihedral angle constraint
00302   double FeatureAngleIncrement;
00303   double MaximumFeatureAngle;
00304   int PreserveEdges; // do/don't worry about feature edges
00305   int BoundaryVertexDeletion;  
00306   double InitialError; // decimation error in fraction of bounding box
00307   double ErrorIncrement; // each iteration will bump error this amount
00308   double MaximumError; // maximum error
00309   double TargetReduction; //target reduction of mesh (fraction)
00310   int MaximumIterations; // maximum number of passes over data
00311   int MaximumSubIterations; // maximum non-incrementing passes
00312   double AspectRatio; // control triangle shape during triangulation
00313   int Degree; // maximum number of triangles incident on vertex
00314   int Stats[VTK_NUMBER_STATISTICS]; // keep track of interesting statistics
00315   int GenerateErrorScalars; // turn on/off vertex error scalar generation
00316   int MaximumNumberOfSquawks; //control number of error messages
00317   int PreserveTopology; //control whether mesh topology is preserved
00318   vtkIdList *Neighbors; // to replace static
00319   VertexArray *V; //to replace static
00320   TriArray *T; //to replace static
00321   
00322   void CreateOutput(vtkIdType numPts, vtkIdType numTris,
00323                     vtkIdType numEliminated, vtkPointData *pd,
00324                     vtkPoints *inPts);
00325   int BuildLoop(vtkIdType ptId, unsigned short int nTris, vtkIdType* tris);
00326   void EvaluateLoop(int& vtype, vtkIdType& numFEdges,
00327                     LocalVertexPtr fedges[]);
00328   int CanSplitLoop(LocalVertexPtr fedges[2], vtkIdType numVerts, 
00329                    LocalVertexPtr verts[], vtkIdType& n1,
00330                    LocalVertexPtr l1[], vtkIdType& n2,
00331                    LocalVertexPtr l2[], double& ar);
00332   void SplitLoop(LocalVertexPtr fedges[2], vtkIdType numVerts, 
00333                  LocalVertexPtr *verts, vtkIdType& n1,
00334                  LocalVertexPtr *l1, vtkIdType& n2, LocalVertexPtr *l2);
00335   void Triangulate(vtkIdType numVerts, LocalVertexPtr verts[]);
00336   int CheckError();
00337 private:
00338   vtkDecimate(const vtkDecimate&);  // Not implemented.
00339   void operator=(const vtkDecimate&);  // Not implemented.
00340 };
00341 
00342 #endif
00343 
00344