VTK
dox/Filters/Hybrid/vtkGreedyTerrainDecimation.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkGreedyTerrainDecimation.h
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 =========================================================================*/
00069 #ifndef __vtkGreedyTerrainDecimation_h
00070 #define __vtkGreedyTerrainDecimation_h
00071 
00072 #include "vtkFiltersHybridModule.h" // For export macro
00073 #include "vtkPolyDataAlgorithm.h"
00074 
00075 class vtkPriorityQueue;
00076 class vtkDataArray;
00077 class vtkPointData;
00078 class vtkIdList;
00079 class vtkDoubleArray;
00080 class vtkFloatArray;
00081 
00082 //PIMPL Encapsulation for STL containers
00083 class vtkGreedyTerrainDecimationTerrainInfoType;
00084 class vtkGreedyTerrainDecimationPointInfoType;
00085 
00086 #define VTK_ERROR_NUMBER_OF_TRIANGLES 0
00087 #define VTK_ERROR_SPECIFIED_REDUCTION 1
00088 #define VTK_ERROR_ABSOLUTE            2
00089 #define VTK_ERROR_RELATIVE            3
00090 
00091 class VTKFILTERSHYBRID_EXPORT vtkGreedyTerrainDecimation : public vtkPolyDataAlgorithm
00092 {
00093 public:
00094   vtkTypeMacro(vtkGreedyTerrainDecimation,vtkPolyDataAlgorithm);
00095   void PrintSelf(ostream& os, vtkIndent indent);
00096 
00098   static vtkGreedyTerrainDecimation* New();
00099 
00101 
00106   vtkSetClampMacro(ErrorMeasure,int,VTK_ERROR_NUMBER_OF_TRIANGLES,VTK_ERROR_RELATIVE);
00107   vtkGetMacro(ErrorMeasure,int);
00108   void SetErrorMeasureToNumberOfTriangles()
00109     {this->SetErrorMeasure(VTK_ERROR_NUMBER_OF_TRIANGLES);}
00110   void SetErrorMeasureToSpecifiedReduction()
00111     {this->SetErrorMeasure(VTK_ERROR_SPECIFIED_REDUCTION);}
00112   void SetErrorMeasureToAbsoluteError()
00113     {this->SetErrorMeasure(VTK_ERROR_ABSOLUTE);}
00114   void SetErrorMeasureToRelativeError()
00115     {this->SetErrorMeasure(VTK_ERROR_RELATIVE);}
00117 
00119 
00123   vtkSetClampMacro(NumberOfTriangles,vtkIdType,2,VTK_ID_MAX);
00124   vtkGetMacro(NumberOfTriangles,vtkIdType);
00126 
00128 
00131   vtkSetClampMacro(Reduction,double,0.0,1.0);
00132   vtkGetMacro(Reduction,double);
00134 
00136 
00140   vtkSetClampMacro(AbsoluteError,double,0.0,VTK_DOUBLE_MAX);
00141   vtkGetMacro(AbsoluteError,double);
00143 
00145 
00149   vtkSetClampMacro(RelativeError,double,0.0,VTK_DOUBLE_MAX);
00150   vtkGetMacro(RelativeError,double);
00152 
00154 
00156   vtkSetMacro(BoundaryVertexDeletion,int);
00157   vtkGetMacro(BoundaryVertexDeletion,int);
00158   vtkBooleanMacro(BoundaryVertexDeletion,int);
00160 
00162 
00163   vtkSetMacro(ComputeNormals, int);
00164   vtkGetMacro(ComputeNormals, int);
00165   vtkBooleanMacro(ComputeNormals, int);
00167 
00168 protected:
00169   vtkGreedyTerrainDecimation();
00170   ~vtkGreedyTerrainDecimation();
00171 
00172   virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
00173   virtual int FillInputPortInformation(int port, vtkInformation *info);
00174 
00175   int ComputeNormals;
00176   vtkFloatArray* Normals;
00177   void ComputePointNormal(int i, int j, float n[3]);
00178 
00179   //ivars that the API addresses
00180   int       ErrorMeasure;
00181   vtkIdType NumberOfTriangles;
00182   double    Reduction;
00183   double    AbsoluteError;
00184   double    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   double         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, int depth);
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], double 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], double h[3], double &hMin, double &hMax,
00238                            double &hL, double &hR);
00239 
00240 private:
00241   vtkGreedyTerrainDecimation(const vtkGreedyTerrainDecimation&);  // Not implemented.
00242   void operator=(const vtkGreedyTerrainDecimation&);  // Not implemented.
00243 
00244 };
00245 
00246 #endif