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