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

Hybrid/vtkGreedyTerrainDecimation.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkGreedyTerrainDecimation.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 =========================================================================*/
00083 #ifndef __vtkGreedyTerrainDecimation_h
00084 #define __vtkGreedyTerrainDecimation_h
00085 
00086 #include "vtkStructuredPointsToPolyDataFilter.h"
00087 
00088 class vtkPriorityQueue;
00089 class vtkDataArray;
00090 class vtkPointData;
00091 class vtkIdList;
00092 class vtkDoubleArray;
00093 
00094 //PIMPL Encapsulation for STL containers
00095 class vtkGreedyTerrainDecimationTerrainInfoType;
00096 class vtkGreedyTerrainDecimationPointInfoType;
00097 
00098 #define VTK_ERROR_NUMBER_OF_TRIANGLES 0
00099 #define VTK_ERROR_SPECIFIED_REDUCTION 1
00100 #define VTK_ERROR_ABSOLUTE            2
00101 #define VTK_ERROR_RELATIVE            3
00102 
00103 class VTK_HYBRID_EXPORT vtkGreedyTerrainDecimation : public vtkStructuredPointsToPolyDataFilter
00104 {
00105 public:
00106   vtkTypeRevisionMacro(vtkGreedyTerrainDecimation,vtkStructuredPointsToPolyDataFilter);
00107   void PrintSelf(ostream& os, vtkIndent indent);
00108 
00110   static vtkGreedyTerrainDecimation* New();
00111 
00113 
00118   vtkSetClampMacro(ErrorMeasure,int,VTK_ERROR_NUMBER_OF_TRIANGLES,VTK_ERROR_RELATIVE);
00119   vtkGetMacro(ErrorMeasure,int);
00120   void SetErrorMeasureToNumberOfTriangles() 
00121     {this->SetErrorMeasure(VTK_ERROR_NUMBER_OF_TRIANGLES);}
00122   void SetErrorMeasureToSpecifiedReduction() 
00123     {this->SetErrorMeasure(VTK_ERROR_SPECIFIED_REDUCTION);}
00124   void SetErrorMeasureToAbsoluteError() 
00125     {this->SetErrorMeasure(VTK_ERROR_ABSOLUTE);}
00126   void SetErrorMeasureToRelativeError() 
00127     {this->SetErrorMeasure(VTK_ERROR_RELATIVE);}
00129 
00131 
00135   vtkSetClampMacro(NumberOfTriangles,vtkIdType,2,VTK_LONG_MAX);
00136   vtkGetMacro(NumberOfTriangles,vtkIdType);
00138 
00140 
00143   vtkSetClampMacro(Reduction,float,0.0,1.0);
00144   vtkGetMacro(Reduction,float);
00146 
00148 
00152   vtkSetClampMacro(AbsoluteError,float,0.0,VTK_LARGE_FLOAT);
00153   vtkGetMacro(AbsoluteError,float);
00155 
00157 
00161   vtkSetClampMacro(RelativeError,float,0.0,VTK_LARGE_FLOAT);
00162   vtkGetMacro(RelativeError,float);
00164 
00166 
00168   vtkSetMacro(BoundaryVertexDeletion,int);
00169   vtkGetMacro(BoundaryVertexDeletion,int);
00170   vtkBooleanMacro(BoundaryVertexDeletion,int);
00172 
00173 protected:
00174   vtkGreedyTerrainDecimation();
00175   ~vtkGreedyTerrainDecimation();
00176 
00177   void Execute();
00178 
00179   //ivars that the API addresses
00180   int       ErrorMeasure;
00181   vtkIdType NumberOfTriangles;
00182   float     Reduction;
00183   float     AbsoluteError;
00184   float     RelativeError;
00185   int       BoundaryVertexDeletion; //Can we delete boundary vertices?
00186 
00187   //Used for convenience
00188   vtkPolyData    *Mesh;
00189   vtkPointData   *InputPD;
00190   vtkPointData   *OutputPD;
00191   vtkDoubleArray *Points;
00192   vtkDataArray   *Heights;
00193   vtkIdType      CurrentPointId;
00194   double         Tolerance;
00195   vtkIdList      *Neighbors;
00196   int            Dimensions[3];
00197   double         Origin[3];
00198   double         Spacing[3];
00199   vtkIdType      MaximumNumberOfTriangles;
00200   float          Length;
00201 
00202   //Bookeeping arrays
00203   vtkPriorityQueue                          *TerrainError; //errors for each pt in height field
00204   vtkGreedyTerrainDecimationTerrainInfoType *TerrainInfo;  //owning triangle for each pt
00205   vtkGreedyTerrainDecimationPointInfoType   *PointInfo;    //map mesh pt id to input pt id
00206   
00207   //Make a guess at initial allocation
00208   void EstimateOutputSize(const vtkIdType numInputPts, vtkIdType &numPts, vtkIdType &numTris);
00209   
00210   //Returns non-zero if the error measure is satisfied.
00211   virtual int SatisfiesErrorMeasure(double error);
00212 
00213   //Insert all the boundary vertices into the TIN
00214   void InsertBoundaryVertices();
00215     
00216   //Insert a point into the triangulation; get a point from the triangulation
00217   vtkIdType AddPointToTriangulation(vtkIdType inputPtId);
00218   vtkIdType InsertNextPoint(vtkIdType inputPtId, double x[3]);
00219   double *GetPoint(vtkIdType id);
00220   void GetPoint(vtkIdType id, double x[3]);
00221 
00222   //Helper functions
00223   void GetTerrainPoint(int i, int j, double x[3]);
00224   void ComputeImageCoordinates(vtkIdType inputPtId, int ij[2]);
00225   int InCircle (double x[3], double x1[3], double x2[3], double x3[3]);
00226   vtkIdType FindTriangle(double x[3], vtkIdType ptIds[3], vtkIdType tri,
00227                          double tol, vtkIdType nei[3], vtkIdList *neighbors, int& status);
00228   void CheckEdge(vtkIdType ptId, double x[3], vtkIdType p1, vtkIdType p2,
00229                  vtkIdType tri);
00230 
00231   void UpdateTriangles(vtkIdType meshPtId); //update all points connected to this point
00232   void UpdateTriangle(vtkIdType triId, vtkIdType p1, vtkIdType p2, vtkIdType p3);
00233   void UpdateTriangle(vtkIdType triId, int ij1[2], int ij2[2], int ij3[2], float h[4]);
00234 
00235   int CharacterizeTriangle(int ij1[2], int ij2[2], int ij[3],
00236                            int* &min, int* &max, int* &midL, int* &midR,
00237                            int* &mid, int mid2[2], float h[3], float &hMin, float &hMax, 
00238                            float &hL, float &hR);
00239 
00240 private:
00241   vtkGreedyTerrainDecimation(const vtkGreedyTerrainDecimation&);  // Not implemented.
00242   void operator=(const vtkGreedyTerrainDecimation&);  // Not implemented.
00243 
00244 };
00245 
00246 #endif
00247