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

vtkGreedyTerrainDecimation.h

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