VTK  9.3.1
vtkGreedyTerrainDecimation.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
58 #ifndef vtkGreedyTerrainDecimation_h
59 #define vtkGreedyTerrainDecimation_h
60 
61 #include "vtkFiltersHybridModule.h" // For export macro
62 #include "vtkPolyDataAlgorithm.h"
63 
64 VTK_ABI_NAMESPACE_BEGIN
65 class vtkPriorityQueue;
66 class vtkDataArray;
67 class vtkPointData;
68 class vtkIdList;
69 class vtkDoubleArray;
70 class vtkFloatArray;
71 
72 // PIMPL Encapsulation for STL containers
73 class vtkGreedyTerrainDecimationTerrainInfoType;
74 class vtkGreedyTerrainDecimationPointInfoType;
75 
76 #define VTK_ERROR_NUMBER_OF_TRIANGLES 0
77 #define VTK_ERROR_SPECIFIED_REDUCTION 1
78 #define VTK_ERROR_ABSOLUTE 2
79 #define VTK_ERROR_RELATIVE 3
80 
81 class VTKFILTERSHYBRID_EXPORT vtkGreedyTerrainDecimation : public vtkPolyDataAlgorithm
82 {
83 public:
85  void PrintSelf(ostream& os, vtkIndent indent) override;
86 
91 
93 
99  vtkSetClampMacro(ErrorMeasure, int, VTK_ERROR_NUMBER_OF_TRIANGLES, VTK_ERROR_RELATIVE);
100  vtkGetMacro(ErrorMeasure, int);
102  {
103  this->SetErrorMeasure(VTK_ERROR_NUMBER_OF_TRIANGLES);
104  }
106  {
107  this->SetErrorMeasure(VTK_ERROR_SPECIFIED_REDUCTION);
108  }
109  void SetErrorMeasureToAbsoluteError() { this->SetErrorMeasure(VTK_ERROR_ABSOLUTE); }
110  void SetErrorMeasureToRelativeError() { this->SetErrorMeasure(VTK_ERROR_RELATIVE); }
112 
114 
120  vtkSetClampMacro(NumberOfTriangles, vtkIdType, 2, VTK_ID_MAX);
121  vtkGetMacro(NumberOfTriangles, vtkIdType);
123 
125 
130  vtkSetClampMacro(Reduction, double, 0.0, 1.0);
131  vtkGetMacro(Reduction, double);
133 
135 
140  vtkSetClampMacro(AbsoluteError, double, 0.0, VTK_DOUBLE_MAX);
141  vtkGetMacro(AbsoluteError, double);
143 
145 
151  vtkSetClampMacro(RelativeError, double, 0.0, VTK_DOUBLE_MAX);
152  vtkGetMacro(RelativeError, double);
154 
156 
160  vtkSetMacro(BoundaryVertexDeletion, vtkTypeBool);
161  vtkGetMacro(BoundaryVertexDeletion, vtkTypeBool);
162  vtkBooleanMacro(BoundaryVertexDeletion, vtkTypeBool);
164 
166 
169  vtkSetMacro(ComputeNormals, vtkTypeBool);
170  vtkGetMacro(ComputeNormals, vtkTypeBool);
171  vtkBooleanMacro(ComputeNormals, vtkTypeBool);
173 
174 protected:
176  ~vtkGreedyTerrainDecimation() override;
177 
179  int FillInputPortInformation(int port, vtkInformation* info) override;
180 
183  void ComputePointNormal(int i, int j, float n[3]);
184 
185  // ivars that the API addresses
188  double Reduction;
191  vtkTypeBool BoundaryVertexDeletion; // Can we delete boundary vertices?
192 
193  // Used for convenience
200  double Tolerance;
202  int Dimensions[3];
203  double Origin[3];
204  double Spacing[3];
206  double Length;
207 
208  // Bookkeeping arrays
209  vtkPriorityQueue* TerrainError; // errors for each pt in height field
210  vtkGreedyTerrainDecimationTerrainInfoType* TerrainInfo; // owning triangle for each pt
211  vtkGreedyTerrainDecimationPointInfoType* PointInfo; // map mesh pt id to input pt id
212 
213  // Make a guess at initial allocation
214  void EstimateOutputSize(vtkIdType numInputPts, vtkIdType& numPts, vtkIdType& numTris);
215 
216  // Returns non-zero if the error measure is satisfied.
217  virtual int SatisfiesErrorMeasure(double error);
218 
219  // Insert all the boundary vertices into the TIN
220  void InsertBoundaryVertices();
221 
222  // Insert a point into the triangulation; get a point from the triangulation
223  vtkIdType AddPointToTriangulation(vtkIdType inputPtId);
224  vtkIdType InsertNextPoint(vtkIdType inputPtId, double x[3]);
225  double* GetPoint(vtkIdType id);
226  void GetPoint(vtkIdType id, double x[3]);
227 
228  // Helper functions
229  void GetTerrainPoint(int i, int j, double x[3]);
230  void ComputeImageCoordinates(vtkIdType inputPtId, int ij[2]);
231  int InCircle(double x[3], double x1[3], double x2[3], double x3[3]);
232  vtkIdType FindTriangle(double x[3], vtkIdType ptIds[3], vtkIdType tri, double tol,
233  vtkIdType nei[3], vtkIdList* neighbors, int& status);
234  void CheckEdge(vtkIdType ptId, double x[3], vtkIdType p1, vtkIdType p2, vtkIdType tri, int depth);
235 
236  void UpdateTriangles(vtkIdType meshPtId); // update all points connected to this point
237  void UpdateTriangle(vtkIdType triId, vtkIdType p1, vtkIdType p2, vtkIdType p3);
238  void UpdateTriangle(vtkIdType triId, int ij1[2], int ij2[2], int ij3[2], double h[3]);
239 
240  int CharacterizeTriangle(int ij1[2], int ij2[2], int ij[3], int*& min, int*& max, int*& midL,
241  int*& midR, int*& mid, int mid2[2], double h[3], double& hMin, double& hMax, double& hL,
242  double& hR);
243 
244 private:
246  void operator=(const vtkGreedyTerrainDecimation&) = delete;
247 };
248 
249 VTK_ABI_NAMESPACE_END
250 #endif
#define VTK_ERROR_SPECIFIED_REDUCTION
represent and manipulate point attribute data
Definition: vtkPointData.h:29
#define VTK_DOUBLE_MAX
Definition: vtkType.h:154
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:30
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:315
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
dynamic, self-adjusting array of double
a list of ids arranged in priority order
static vtkPolyDataAlgorithm * New()
int vtkTypeBool
Definition: vtkABI.h:64
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:28
list of point or cell ids
Definition: vtkIdList.h:22
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
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 GetPoint(int i, int j, int k, double pnt[3])
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:319
#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.