VTK  9.2.6
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 =========================================================================*/
70 #ifndef vtkGreedyTerrainDecimation_h
71 #define vtkGreedyTerrainDecimation_h
72 
73 #include "vtkFiltersHybridModule.h" // For export macro
74 #include "vtkPolyDataAlgorithm.h"
75 
76 class vtkPriorityQueue;
77 class vtkDataArray;
78 class vtkPointData;
79 class vtkIdList;
80 class vtkDoubleArray;
81 class vtkFloatArray;
82 
83 // PIMPL Encapsulation for STL containers
84 class vtkGreedyTerrainDecimationTerrainInfoType;
85 class vtkGreedyTerrainDecimationPointInfoType;
86 
87 #define VTK_ERROR_NUMBER_OF_TRIANGLES 0
88 #define VTK_ERROR_SPECIFIED_REDUCTION 1
89 #define VTK_ERROR_ABSOLUTE 2
90 #define VTK_ERROR_RELATIVE 3
91 
92 class VTKFILTERSHYBRID_EXPORT vtkGreedyTerrainDecimation : public vtkPolyDataAlgorithm
93 {
94 public:
96  void PrintSelf(ostream& os, vtkIndent indent) override;
97 
102 
104 
110  vtkSetClampMacro(ErrorMeasure, int, VTK_ERROR_NUMBER_OF_TRIANGLES, VTK_ERROR_RELATIVE);
111  vtkGetMacro(ErrorMeasure, int);
113  {
114  this->SetErrorMeasure(VTK_ERROR_NUMBER_OF_TRIANGLES);
115  }
117  {
118  this->SetErrorMeasure(VTK_ERROR_SPECIFIED_REDUCTION);
119  }
120  void SetErrorMeasureToAbsoluteError() { this->SetErrorMeasure(VTK_ERROR_ABSOLUTE); }
121  void SetErrorMeasureToRelativeError() { this->SetErrorMeasure(VTK_ERROR_RELATIVE); }
123 
125 
131  vtkSetClampMacro(NumberOfTriangles, vtkIdType, 2, VTK_ID_MAX);
132  vtkGetMacro(NumberOfTriangles, vtkIdType);
134 
136 
141  vtkSetClampMacro(Reduction, double, 0.0, 1.0);
142  vtkGetMacro(Reduction, double);
144 
146 
151  vtkSetClampMacro(AbsoluteError, double, 0.0, VTK_DOUBLE_MAX);
152  vtkGetMacro(AbsoluteError, double);
154 
156 
162  vtkSetClampMacro(RelativeError, double, 0.0, VTK_DOUBLE_MAX);
163  vtkGetMacro(RelativeError, double);
165 
167 
171  vtkSetMacro(BoundaryVertexDeletion, vtkTypeBool);
172  vtkGetMacro(BoundaryVertexDeletion, vtkTypeBool);
173  vtkBooleanMacro(BoundaryVertexDeletion, vtkTypeBool);
175 
177 
180  vtkSetMacro(ComputeNormals, vtkTypeBool);
181  vtkGetMacro(ComputeNormals, vtkTypeBool);
182  vtkBooleanMacro(ComputeNormals, vtkTypeBool);
184 
185 protected:
187  ~vtkGreedyTerrainDecimation() override;
188 
190  int FillInputPortInformation(int port, vtkInformation* info) override;
191 
194  void ComputePointNormal(int i, int j, float n[3]);
195 
196  // ivars that the API addresses
199  double Reduction;
202  vtkTypeBool BoundaryVertexDeletion; // Can we delete boundary vertices?
203 
204  // Used for convenience
211  double Tolerance;
213  int Dimensions[3];
214  double Origin[3];
215  double Spacing[3];
217  double Length;
218 
219  // Bookkeeping arrays
220  vtkPriorityQueue* TerrainError; // errors for each pt in height field
221  vtkGreedyTerrainDecimationTerrainInfoType* TerrainInfo; // owning triangle for each pt
222  vtkGreedyTerrainDecimationPointInfoType* PointInfo; // map mesh pt id to input pt id
223 
224  // Make a guess at initial allocation
225  void EstimateOutputSize(const vtkIdType numInputPts, vtkIdType& numPts, vtkIdType& numTris);
226 
227  // Returns non-zero if the error measure is satisfied.
228  virtual int SatisfiesErrorMeasure(double error);
229 
230  // Insert all the boundary vertices into the TIN
231  void InsertBoundaryVertices();
232 
233  // Insert a point into the triangulation; get a point from the triangulation
234  vtkIdType AddPointToTriangulation(vtkIdType inputPtId);
235  vtkIdType InsertNextPoint(vtkIdType inputPtId, double x[3]);
236  double* GetPoint(vtkIdType id);
237  void GetPoint(vtkIdType id, double x[3]);
238 
239  // Helper functions
240  void GetTerrainPoint(int i, int j, double x[3]);
241  void ComputeImageCoordinates(vtkIdType inputPtId, int ij[2]);
242  int InCircle(double x[3], double x1[3], double x2[3], double x3[3]);
243  vtkIdType FindTriangle(double x[3], vtkIdType ptIds[3], vtkIdType tri, double tol,
244  vtkIdType nei[3], vtkIdList* neighbors, int& status);
245  void CheckEdge(vtkIdType ptId, double x[3], vtkIdType p1, vtkIdType p2, vtkIdType tri, int depth);
246 
247  void UpdateTriangles(vtkIdType meshPtId); // update all points connected to this point
248  void UpdateTriangle(vtkIdType triId, vtkIdType p1, vtkIdType p2, vtkIdType p3);
249  void UpdateTriangle(vtkIdType triId, int ij1[2], int ij2[2], int ij3[2], double h[4]);
250 
251  int CharacterizeTriangle(int ij1[2], int ij2[2], int ij[3], int*& min, int*& max, int*& midL,
252  int*& midR, int*& mid, int mid2[2], double h[3], double& hMin, double& hMax, double& hL,
253  double& hR);
254 
255 private:
257  void operator=(const vtkGreedyTerrainDecimation&) = delete;
258 };
259 
260 #endif
#define VTK_ERROR_SPECIFIED_REDUCTION
represent and manipulate point attribute data
Definition: vtkPointData.h:41
#define VTK_DOUBLE_MAX
Definition: vtkType.h:165
Store vtkAlgorithm input/output information.
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
This is called by the superclass.
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:41
vtkGreedyTerrainDecimationPointInfoType * PointInfo
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:332
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:90
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()
int vtkTypeBool
Definition: vtkABI.h:69
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:39
list of point or cell ids
Definition: vtkIdList.h:33
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
vtkGreedyTerrainDecimationTerrainInfoType * TerrainInfo
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).
#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:336
#define VTK_ERROR_RELATIVE
int FillInputPortInformation(int port, vtkInformation *info) override
Fill the input port information objects for this algorithm.
Store zero or more vtkInformation instances.
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.