VTK
vtkGreedyTerrainDecimation.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkGreedyTerrainDecimation.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
69 #ifndef __vtkGreedyTerrainDecimation_h
70 #define __vtkGreedyTerrainDecimation_h
71 
72 #include "vtkPolyDataAlgorithm.h"
73 
74 class vtkPriorityQueue;
75 class vtkDataArray;
76 class vtkPointData;
77 class vtkIdList;
78 class vtkDoubleArray;
79 class vtkFloatArray;
80 
81 //PIMPL Encapsulation for STL containers
82 class vtkGreedyTerrainDecimationTerrainInfoType;
83 class vtkGreedyTerrainDecimationPointInfoType;
84 
85 #define VTK_ERROR_NUMBER_OF_TRIANGLES 0
86 #define VTK_ERROR_SPECIFIED_REDUCTION 1
87 #define VTK_ERROR_ABSOLUTE 2
88 #define VTK_ERROR_RELATIVE 3
89 
91 {
92 public:
94  void PrintSelf(ostream& os, vtkIndent indent);
95 
98 
100 
105  vtkSetClampMacro(ErrorMeasure,int,VTK_ERROR_NUMBER_OF_TRIANGLES,VTK_ERROR_RELATIVE);
106  vtkGetMacro(ErrorMeasure,int);
108  {this->SetErrorMeasure(VTK_ERROR_NUMBER_OF_TRIANGLES);}
110  {this->SetErrorMeasure(VTK_ERROR_SPECIFIED_REDUCTION);}
112  {this->SetErrorMeasure(VTK_ERROR_ABSOLUTE);}
114  {this->SetErrorMeasure(VTK_ERROR_RELATIVE);}
116 
118 
122  vtkSetClampMacro(NumberOfTriangles,vtkIdType,2,VTK_LARGE_ID);
123  vtkGetMacro(NumberOfTriangles,vtkIdType);
125 
127 
130  vtkSetClampMacro(Reduction,double,0.0,1.0);
131  vtkGetMacro(Reduction,double);
133 
135 
139  vtkSetClampMacro(AbsoluteError,double,0.0,VTK_DOUBLE_MAX);
140  vtkGetMacro(AbsoluteError,double);
142 
144 
148  vtkSetClampMacro(RelativeError,double,0.0,VTK_DOUBLE_MAX);
149  vtkGetMacro(RelativeError,double);
151 
153 
155  vtkSetMacro(BoundaryVertexDeletion,int);
156  vtkGetMacro(BoundaryVertexDeletion,int);
157  vtkBooleanMacro(BoundaryVertexDeletion,int);
159 
161 
162  vtkSetMacro(ComputeNormals, int);
163  vtkGetMacro(ComputeNormals, int);
164  vtkBooleanMacro(ComputeNormals, int);
166 
167 protected:
170 
173 
176  void ComputePointNormal(int i, int j, float n[3]);
177 
178  //ivars that the API addresses
181  double Reduction;
184  int BoundaryVertexDeletion; //Can we delete boundary vertices?
185 
186  //Used for convenience
193  double Tolerance;
195  int Dimensions[3];
196  double Origin[3];
197  double Spacing[3];
199  double Length;
200 
201  //Bookeeping arrays
202  vtkPriorityQueue *TerrainError; //errors for each pt in height field
203  vtkGreedyTerrainDecimationTerrainInfoType *TerrainInfo; //owning triangle for each pt
204  vtkGreedyTerrainDecimationPointInfoType *PointInfo; //map mesh pt id to input pt id
205 
206  //Make a guess at initial allocation
207  void EstimateOutputSize(const vtkIdType numInputPts, vtkIdType &numPts, vtkIdType &numTris);
208 
209  //Returns non-zero if the error measure is satisfied.
210  virtual int SatisfiesErrorMeasure(double error);
211 
212  //Insert all the boundary vertices into the TIN
213  void InsertBoundaryVertices();
214 
215  //Insert a point into the triangulation; get a point from the triangulation
216  vtkIdType AddPointToTriangulation(vtkIdType inputPtId);
217  vtkIdType InsertNextPoint(vtkIdType inputPtId, double x[3]);
218  double *GetPoint(vtkIdType id);
219  void GetPoint(vtkIdType id, double x[3]);
220 
221  //Helper functions
222  void GetTerrainPoint(int i, int j, double x[3]);
223  void ComputeImageCoordinates(vtkIdType inputPtId, int ij[2]);
224  int InCircle (double x[3], double x1[3], double x2[3], double x3[3]);
225  vtkIdType FindTriangle(double x[3], vtkIdType ptIds[3], vtkIdType tri,
226  double tol, vtkIdType nei[3], vtkIdList *neighbors, int& status);
227  void CheckEdge(vtkIdType ptId, double x[3], vtkIdType p1, vtkIdType p2,
228  vtkIdType tri, int depth);
229 
230  void UpdateTriangles(vtkIdType meshPtId); //update all points connected to this point
231  void UpdateTriangle(vtkIdType triId, vtkIdType p1, vtkIdType p2, vtkIdType p3);
232  void UpdateTriangle(vtkIdType triId, int ij1[2], int ij2[2], int ij3[2], double h[4]);
233 
234  int CharacterizeTriangle(int ij1[2], int ij2[2], int ij[3],
235  int* &min, int* &max, int* &midL, int* &midR,
236  int* &mid, int mid2[2], double h[3], double &hMin, double &hMax,
237  double &hL, double &hR);
238 
239 private:
240  vtkGreedyTerrainDecimation(const vtkGreedyTerrainDecimation&); // Not implemented.
241  void operator=(const vtkGreedyTerrainDecimation&); // Not implemented.
242 
243 };
244 
245 #endif