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 =========================================================================*/
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  {this->SetErrorMeasure(VTK_ERROR_NUMBER_OF_TRIANGLES);}
115  {this->SetErrorMeasure(VTK_ERROR_SPECIFIED_REDUCTION);}
117  {this->SetErrorMeasure(VTK_ERROR_ABSOLUTE);}
119  {this->SetErrorMeasure(VTK_ERROR_RELATIVE);}
121 
123 
129  vtkSetClampMacro(NumberOfTriangles,vtkIdType,2,VTK_ID_MAX);
130  vtkGetMacro(NumberOfTriangles,vtkIdType);
132 
134 
139  vtkSetClampMacro(Reduction,double,0.0,1.0);
140  vtkGetMacro(Reduction,double);
142 
144 
149  vtkSetClampMacro(AbsoluteError,double,0.0,VTK_DOUBLE_MAX);
150  vtkGetMacro(AbsoluteError,double);
152 
154 
160  vtkSetClampMacro(RelativeError,double,0.0,VTK_DOUBLE_MAX);
161  vtkGetMacro(RelativeError,double);
163 
165 
169  vtkSetMacro(BoundaryVertexDeletion,vtkTypeBool);
170  vtkGetMacro(BoundaryVertexDeletion,vtkTypeBool);
171  vtkBooleanMacro(BoundaryVertexDeletion,vtkTypeBool);
173 
175 
178  vtkSetMacro(ComputeNormals, vtkTypeBool);
179  vtkGetMacro(ComputeNormals, vtkTypeBool);
180  vtkBooleanMacro(ComputeNormals, vtkTypeBool);
182 
183 protected:
185  ~vtkGreedyTerrainDecimation() override;
186 
188  int FillInputPortInformation(int port, vtkInformation *info) override;
189 
192  void ComputePointNormal(int i, int j, float n[3]);
193 
194  //ivars that the API addresses
197  double Reduction;
200  vtkTypeBool BoundaryVertexDeletion; //Can we delete boundary vertices?
201 
202  //Used for convenience
209  double Tolerance;
211  int Dimensions[3];
212  double Origin[3];
213  double Spacing[3];
215  double Length;
216 
217  //Bookkeeping arrays
218  vtkPriorityQueue *TerrainError; //errors for each pt in height field
219  vtkGreedyTerrainDecimationTerrainInfoType *TerrainInfo; //owning triangle for each pt
220  vtkGreedyTerrainDecimationPointInfoType *PointInfo; //map mesh pt id to input pt id
221 
222  //Make a guess at initial allocation
223  void EstimateOutputSize(const vtkIdType numInputPts, vtkIdType &numPts, vtkIdType &numTris);
224 
225  //Returns non-zero if the error measure is satisfied.
226  virtual int SatisfiesErrorMeasure(double error);
227 
228  //Insert all the boundary vertices into the TIN
229  void InsertBoundaryVertices();
230 
231  //Insert a point into the triangulation; get a point from the triangulation
232  vtkIdType AddPointToTriangulation(vtkIdType inputPtId);
233  vtkIdType InsertNextPoint(vtkIdType inputPtId, double x[3]);
234  double *GetPoint(vtkIdType id);
235  void GetPoint(vtkIdType id, double x[3]);
236 
237  //Helper functions
238  void GetTerrainPoint(int i, int j, double x[3]);
239  void ComputeImageCoordinates(vtkIdType inputPtId, int ij[2]);
240  int InCircle (double x[3], double x1[3], double x2[3], double x3[3]);
241  vtkIdType FindTriangle(double x[3], vtkIdType ptIds[3], vtkIdType tri,
242  double tol, vtkIdType nei[3], vtkIdList *neighbors, int& status);
243  void CheckEdge(vtkIdType ptId, double x[3], vtkIdType p1, vtkIdType p2,
244  vtkIdType tri, int depth);
245 
246  void UpdateTriangles(vtkIdType meshPtId); //update all points connected to this point
247  void UpdateTriangle(vtkIdType triId, vtkIdType p1, vtkIdType p2, vtkIdType p3);
248  void UpdateTriangle(vtkIdType triId, int ij1[2], int ij2[2], int ij3[2], double h[4]);
249 
250  int CharacterizeTriangle(int ij1[2], int ij2[2], int ij[3],
251  int* &min, int* &max, int* &midL, int* &midR,
252  int* &mid, int mid2[2], double h[3], double &hMin, double &hMax,
253  double &hL, double &hR);
254 
255 private:
257  void operator=(const vtkGreedyTerrainDecimation&) = delete;
258 
259 };
260 
261 #endif
vtkGreedyTerrainDecimation::PointInfo
vtkGreedyTerrainDecimationPointInfoType * PointInfo
Definition: vtkGreedyTerrainDecimation.h:220
vtkGreedyTerrainDecimation::SetErrorMeasureToNumberOfTriangles
void SetErrorMeasureToNumberOfTriangles()
Definition: vtkGreedyTerrainDecimation.h:112
vtkGreedyTerrainDecimation::NumberOfTriangles
vtkIdType NumberOfTriangles
Definition: vtkGreedyTerrainDecimation.h:196
vtkPointData
represent and manipulate point attribute data
Definition: vtkPointData.h:37
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkFloatArray
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:41
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:41
vtkGreedyTerrainDecimation::OutputPD
vtkPointData * OutputPD
Definition: vtkGreedyTerrainDecimation.h:205
vtkGreedyTerrainDecimation::RelativeError
double RelativeError
Definition: vtkGreedyTerrainDecimation.h:199
vtkPriorityQueue
a list of ids arranged in priority order
Definition: vtkPriorityQueue.h:46
VTK_ERROR_ABSOLUTE
#define VTK_ERROR_ABSOLUTE
Definition: vtkGreedyTerrainDecimation.h:89
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
vtkGreedyTerrainDecimation::Heights
vtkDataArray * Heights
Definition: vtkGreedyTerrainDecimation.h:207
vtkPolyDataAlgorithm::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkGreedyTerrainDecimation::SetErrorMeasureToAbsoluteError
void SetErrorMeasureToAbsoluteError()
Definition: vtkGreedyTerrainDecimation.h:116
GetPoint
void GetPoint(const int i, const int j, const int k, double pnt[3])
vtkGreedyTerrainDecimation::MaximumNumberOfTriangles
vtkIdType MaximumNumberOfTriangles
Definition: vtkGreedyTerrainDecimation.h:214
vtkGreedyTerrainDecimation::BoundaryVertexDeletion
vtkTypeBool BoundaryVertexDeletion
Definition: vtkGreedyTerrainDecimation.h:200
max
#define max(a, b)
Definition: vtkX3DExporterFIWriterHelper.h:31
vtkGreedyTerrainDecimation::AbsoluteError
double AbsoluteError
Definition: vtkGreedyTerrainDecimation.h:198
vtkPolyDataAlgorithm.h
vtkGreedyTerrainDecimation::InputPD
vtkPointData * InputPD
Definition: vtkGreedyTerrainDecimation.h:204
vtkX3D::port
Definition: vtkX3D.h:447
vtkGreedyTerrainDecimation
reduce height field (represented as image) to reduced TIN
Definition: vtkGreedyTerrainDecimation.h:92
vtkGreedyTerrainDecimation::Neighbors
vtkIdList * Neighbors
Definition: vtkGreedyTerrainDecimation.h:210
vtkPolyDataAlgorithm::RequestData
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
This is called by the superclass.
vtkGreedyTerrainDecimation::Points
vtkDoubleArray * Points
Definition: vtkGreedyTerrainDecimation.h:206
vtkGreedyTerrainDecimation::Length
double Length
Definition: vtkGreedyTerrainDecimation.h:215
vtkGreedyTerrainDecimation::TerrainError
vtkPriorityQueue * TerrainError
Definition: vtkGreedyTerrainDecimation.h:218
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkGreedyTerrainDecimation::CurrentPointId
vtkIdType CurrentPointId
Definition: vtkGreedyTerrainDecimation.h:208
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:36
vtkGreedyTerrainDecimation::TerrainInfo
vtkGreedyTerrainDecimationTerrainInfoType * TerrainInfo
Definition: vtkGreedyTerrainDecimation.h:219
vtkPolyDataAlgorithm::FillInputPortInformation
int FillInputPortInformation(int port, vtkInformation *info) override
Fill the input port information objects for this algorithm.
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:86
vtkX3D::info
Definition: vtkX3D.h:376
vtkGreedyTerrainDecimation::ComputeNormals
vtkTypeBool ComputeNormals
Definition: vtkGreedyTerrainDecimation.h:190
vtkGreedyTerrainDecimation::Reduction
double Reduction
Definition: vtkGreedyTerrainDecimation.h:197
vtkGreedyTerrainDecimation::ErrorMeasure
int ErrorMeasure
Definition: vtkGreedyTerrainDecimation.h:195
vtkGreedyTerrainDecimation::SetErrorMeasureToSpecifiedReduction
void SetErrorMeasureToSpecifiedReduction()
Definition: vtkGreedyTerrainDecimation.h:114
VTK_ID_MAX
#define VTK_ID_MAX
Definition: vtkType.h:351
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
vtkGreedyTerrainDecimation::SetErrorMeasureToRelativeError
void SetErrorMeasureToRelativeError()
Definition: vtkGreedyTerrainDecimation.h:118
vtkDoubleArray
dynamic, self-adjusting array of double
Definition: vtkDoubleArray.h:41
vtkGreedyTerrainDecimation::Mesh
vtkPolyData * Mesh
Definition: vtkGreedyTerrainDecimation.h:203
vtkGreedyTerrainDecimation::Normals
vtkFloatArray * Normals
Definition: vtkGreedyTerrainDecimation.h:191
VTK_ERROR_NUMBER_OF_TRIANGLES
#define VTK_ERROR_NUMBER_OF_TRIANGLES
Definition: vtkGreedyTerrainDecimation.h:87
vtkGreedyTerrainDecimation::Tolerance
double Tolerance
Definition: vtkGreedyTerrainDecimation.h:209
VTK_DOUBLE_MAX
#define VTK_DOUBLE_MAX
Definition: vtkType.h:169
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkPolyDataAlgorithm::New
static vtkPolyDataAlgorithm * New()
VTK_ERROR_RELATIVE
#define VTK_ERROR_RELATIVE
Definition: vtkGreedyTerrainDecimation.h:90
h
vtkPolyDataAlgorithm
Superclass for algorithms that produce only polydata as output.
Definition: vtkPolyDataAlgorithm.h:44
VTK_ERROR_SPECIFIED_REDUCTION
#define VTK_ERROR_SPECIFIED_REDUCTION
Definition: vtkGreedyTerrainDecimation.h:88