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 =========================================================================*/
67 #ifndef vtkGreedyTerrainDecimation_h
68 #define vtkGreedyTerrainDecimation_h
69 
70 #include "vtkFiltersHybridModule.h" // For export macro
71 #include "vtkPolyDataAlgorithm.h"
72 
73 class vtkPriorityQueue;
74 class vtkDataArray;
75 class vtkPointData;
76 class vtkIdList;
77 class vtkDoubleArray;
78 class vtkFloatArray;
79 
80 //PIMPL Encapsulation for STL containers
81 class vtkGreedyTerrainDecimationTerrainInfoType;
82 class vtkGreedyTerrainDecimationPointInfoType;
83 
84 #define VTK_ERROR_NUMBER_OF_TRIANGLES 0
85 #define VTK_ERROR_SPECIFIED_REDUCTION 1
86 #define VTK_ERROR_ABSOLUTE 2
87 #define VTK_ERROR_RELATIVE 3
88 
89 class VTKFILTERSHYBRID_EXPORT vtkGreedyTerrainDecimation : public vtkPolyDataAlgorithm
90 {
91 public:
93  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
94 
99 
101 
107  vtkSetClampMacro(ErrorMeasure,int,VTK_ERROR_NUMBER_OF_TRIANGLES,VTK_ERROR_RELATIVE);
108  vtkGetMacro(ErrorMeasure,int);
110  {this->SetErrorMeasure(VTK_ERROR_NUMBER_OF_TRIANGLES);}
112  {this->SetErrorMeasure(VTK_ERROR_SPECIFIED_REDUCTION);}
114  {this->SetErrorMeasure(VTK_ERROR_ABSOLUTE);}
116  {this->SetErrorMeasure(VTK_ERROR_RELATIVE);}
118 
120 
126  vtkSetClampMacro(NumberOfTriangles,vtkIdType,2,VTK_ID_MAX);
127  vtkGetMacro(NumberOfTriangles,vtkIdType);
129 
131 
136  vtkSetClampMacro(Reduction,double,0.0,1.0);
137  vtkGetMacro(Reduction,double);
139 
141 
146  vtkSetClampMacro(AbsoluteError,double,0.0,VTK_DOUBLE_MAX);
147  vtkGetMacro(AbsoluteError,double);
149 
151 
157  vtkSetClampMacro(RelativeError,double,0.0,VTK_DOUBLE_MAX);
158  vtkGetMacro(RelativeError,double);
160 
162 
166  vtkSetMacro(BoundaryVertexDeletion,int);
167  vtkGetMacro(BoundaryVertexDeletion,int);
168  vtkBooleanMacro(BoundaryVertexDeletion,int);
170 
172 
175  vtkSetMacro(ComputeNormals, int);
176  vtkGetMacro(ComputeNormals, int);
177  vtkBooleanMacro(ComputeNormals, int);
179 
180 protected:
182  ~vtkGreedyTerrainDecimation() VTK_OVERRIDE;
183 
184  int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) VTK_OVERRIDE;
185  int FillInputPortInformation(int port, vtkInformation *info) VTK_OVERRIDE;
186 
187  int ComputeNormals;
188  vtkFloatArray* Normals;
189  void ComputePointNormal(int i, int j, float n[3]);
190 
191  //ivars that the API addresses
192  int ErrorMeasure;
193  vtkIdType NumberOfTriangles;
194  double Reduction;
195  double AbsoluteError;
196  double RelativeError;
197  int BoundaryVertexDeletion; //Can we delete boundary vertices?
198 
199  //Used for convenience
200  vtkPolyData *Mesh;
201  vtkPointData *InputPD;
202  vtkPointData *OutputPD;
203  vtkDoubleArray *Points;
204  vtkDataArray *Heights;
205  vtkIdType CurrentPointId;
206  double Tolerance;
207  vtkIdList *Neighbors;
208  int Dimensions[3];
209  double Origin[3];
210  double Spacing[3];
211  vtkIdType MaximumNumberOfTriangles;
212  double Length;
213 
214  //Bookeeping arrays
215  vtkPriorityQueue *TerrainError; //errors for each pt in height field
216  vtkGreedyTerrainDecimationTerrainInfoType *TerrainInfo; //owning triangle for each pt
217  vtkGreedyTerrainDecimationPointInfoType *PointInfo; //map mesh pt id to input pt id
218 
219  //Make a guess at initial allocation
220  void EstimateOutputSize(const vtkIdType numInputPts, vtkIdType &numPts, vtkIdType &numTris);
221 
222  //Returns non-zero if the error measure is satisfied.
223  virtual int SatisfiesErrorMeasure(double error);
224 
225  //Insert all the boundary vertices into the TIN
226  void InsertBoundaryVertices();
227 
228  //Insert a point into the triangulation; get a point from the triangulation
229  vtkIdType AddPointToTriangulation(vtkIdType inputPtId);
230  vtkIdType InsertNextPoint(vtkIdType inputPtId, double x[3]);
231  double *GetPoint(vtkIdType id);
232  void GetPoint(vtkIdType id, double x[3]);
233 
234  //Helper functions
235  void GetTerrainPoint(int i, int j, double x[3]);
236  void ComputeImageCoordinates(vtkIdType inputPtId, int ij[2]);
237  int InCircle (double x[3], double x1[3], double x2[3], double x3[3]);
238  vtkIdType FindTriangle(double x[3], vtkIdType ptIds[3], vtkIdType tri,
239  double tol, vtkIdType nei[3], vtkIdList *neighbors, int& status);
240  void CheckEdge(vtkIdType ptId, double x[3], vtkIdType p1, vtkIdType p2,
241  vtkIdType tri, int depth);
242 
243  void UpdateTriangles(vtkIdType meshPtId); //update all points connected to this point
244  void UpdateTriangle(vtkIdType triId, vtkIdType p1, vtkIdType p2, vtkIdType p3);
245  void UpdateTriangle(vtkIdType triId, int ij1[2], int ij2[2], int ij3[2], double h[4]);
246 
247  int CharacterizeTriangle(int ij1[2], int ij2[2], int ij[3],
248  int* &min, int* &max, int* &midL, int* &midR,
249  int* &mid, int mid2[2], double h[3], double &hMin, double &hMax,
250  double &hL, double &hR);
251 
252 private:
253  vtkGreedyTerrainDecimation(const vtkGreedyTerrainDecimation&) VTK_DELETE_FUNCTION;
254  void operator=(const vtkGreedyTerrainDecimation&) VTK_DELETE_FUNCTION;
255 
256 };
257 
258 #endif
#define VTK_ERROR_SPECIFIED_REDUCTION
represent and manipulate point attribute data
Definition: vtkPointData.h:31
#define VTK_DOUBLE_MAX
Definition: vtkType.h:167
Store vtkAlgorithm input/output information.
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:35
void SetErrorMeasureToAbsoluteError()
Specify how to terminate the algorithm: either as an absolute number of triangles, a relative number of triangles (normalized by the full resolution mesh), an absolute error (in the height field), or relative error (normalized by the length of the diagonal of the image).
int vtkIdType
Definition: vtkType.h:345
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
void GetPoint(const int i, const int j, const int k, double pnt[3])
dynamic, self-adjusting array of double
a list of ids arranged in priority order
static vtkPolyDataAlgorithm * New()
Superclass for algorithms that produce only polydata as output.
#define VTK_ERROR_ABSOLUTE
void SetErrorMeasureToRelativeError()
Specify how to terminate the algorithm: either as an absolute number of triangles, a relative number of triangles (normalized by the full resolution mesh), an absolute error (in the height field), or relative error (normalized by the length of the diagonal of the image).
a simple class to control print indentation
Definition: vtkIndent.h:33
list of point or cell ids
Definition: vtkIdList.h:30
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
void SetErrorMeasureToNumberOfTriangles()
Specify how to terminate the algorithm: either as an absolute number of triangles, a relative number of triangles (normalized by the full resolution mesh), an absolute error (in the height field), or relative error (normalized by the length of the diagonal of the image).
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
#define VTK_ERROR_NUMBER_OF_TRIANGLES
void SetErrorMeasureToSpecifiedReduction()
Specify how to terminate the algorithm: either as an absolute number of triangles, a relative number of triangles (normalized by the full resolution mesh), an absolute error (in the height field), or relative error (normalized by the length of the diagonal of the image).
#define VTK_ID_MAX
Definition: vtkType.h:349
#define VTK_ERROR_RELATIVE
Store zero or more vtkInformation instances.
vtkBooleanMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
reduce height field (represented as image) to reduced TIN
#define max(a, b)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.