VTK  9.3.20240224
vtkQuadricDecimation.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
66 #ifndef vtkQuadricDecimation_h
67 #define vtkQuadricDecimation_h
68 
69 #include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_3_0
70 #include "vtkFiltersCoreModule.h" // For export macro
71 #include "vtkPolyDataAlgorithm.h"
72 
73 VTK_ABI_NAMESPACE_BEGIN
74 class vtkEdgeTable;
75 class vtkIdList;
76 class vtkPointData;
77 class vtkPriorityQueue;
78 class vtkDoubleArray;
79 
80 class VTKFILTERSCORE_EXPORT vtkQuadricDecimation : public vtkPolyDataAlgorithm
81 {
82 public:
84  void PrintSelf(ostream& os, vtkIndent indent) override;
86 
88 
93  vtkSetClampMacro(TargetReduction, double, 0.0, 1.0);
94  vtkGetMacro(TargetReduction, double);
96 
98 
103  vtkSetMacro(AttributeErrorMetric, vtkTypeBool);
104  vtkGetMacro(AttributeErrorMetric, vtkTypeBool);
105  vtkBooleanMacro(AttributeErrorMetric, vtkTypeBool);
107 
109 
116  vtkSetMacro(VolumePreservation, vtkTypeBool);
117  vtkGetMacro(VolumePreservation, vtkTypeBool);
118  vtkBooleanMacro(VolumePreservation, vtkTypeBool);
120 
122 
137  vtkSetMacro(Regularize, vtkTypeBool);
138  vtkGetMacro(Regularize, vtkTypeBool);
139  vtkBooleanMacro(Regularize, vtkTypeBool);
140  vtkSetMacro(Regularization, double);
141  vtkGetMacro(Regularization, double);
143 
145 
153  vtkSetMacro(WeighBoundaryConstraintsByLength, vtkTypeBool);
154  vtkGetMacro(WeighBoundaryConstraintsByLength, vtkTypeBool);
155  vtkBooleanMacro(WeighBoundaryConstraintsByLength, vtkTypeBool);
156  vtkSetMacro(BoundaryWeightFactor, double);
157  vtkGetMacro(BoundaryWeightFactor, double);
159 
161 
164  vtkGetMacro(MapPointData, bool);
165  vtkSetMacro(MapPointData, bool);
166  vtkBooleanMacro(MapPointData, bool);
168 
170 
176  vtkSetMacro(ScalarsAttribute, vtkTypeBool);
177  vtkGetMacro(ScalarsAttribute, vtkTypeBool);
178  vtkBooleanMacro(ScalarsAttribute, vtkTypeBool);
179  vtkSetMacro(VectorsAttribute, vtkTypeBool);
180  vtkGetMacro(VectorsAttribute, vtkTypeBool);
181  vtkBooleanMacro(VectorsAttribute, vtkTypeBool);
182  vtkSetMacro(NormalsAttribute, vtkTypeBool);
183  vtkGetMacro(NormalsAttribute, vtkTypeBool);
184  vtkBooleanMacro(NormalsAttribute, vtkTypeBool);
185  vtkSetMacro(TCoordsAttribute, vtkTypeBool);
186  vtkGetMacro(TCoordsAttribute, vtkTypeBool);
187  vtkBooleanMacro(TCoordsAttribute, vtkTypeBool);
188  vtkSetMacro(TensorsAttribute, vtkTypeBool);
189  vtkGetMacro(TensorsAttribute, vtkTypeBool);
190  vtkBooleanMacro(TensorsAttribute, vtkTypeBool);
192 
194 
199  vtkSetMacro(ScalarsWeight, double);
200  vtkSetMacro(VectorsWeight, double);
201  vtkSetMacro(NormalsWeight, double);
202  vtkSetMacro(TCoordsWeight, double);
203  vtkSetMacro(TensorsWeight, double);
204  vtkGetMacro(ScalarsWeight, double);
205  vtkGetMacro(VectorsWeight, double);
206  vtkGetMacro(NormalsWeight, double);
207  vtkGetMacro(TCoordsWeight, double);
208  vtkGetMacro(TensorsWeight, double);
210 
212 
216  vtkGetMacro(ActualReduction, double);
218 
219 protected:
222 
224 
229  int CollapseEdge(vtkIdType pt0Id, vtkIdType pt1Id);
230 
235 
240 
244  void ComputeQuadric(vtkIdType pointId);
245 
250  void AddQuadric(vtkIdType oldPtId, vtkIdType newPtId);
251 
253 
257  double ComputeCost(vtkIdType edgeId, double* x);
258  double ComputeCost2(vtkIdType edgeId, double* x);
260 
267 
272 
273  int IsGoodPlacement(vtkIdType pt0Id, vtkIdType pt1Id, const double* x);
275  const double t0[3], const double t1[3], const double t2[3], const double* x);
277  void UpdateEdgeData(vtkIdType pt0Id, vtkIdType pt1Id);
278 
280 
285  VTK_DEPRECATED_IN_9_3_0("Deprecated in favor of the method taking the indexes of both points on "
286  "the edge to interpolate point data")
287  void SetPointAttributeArray(vtkIdType ptId, const double* x);
288  void SetPointAttributeArray(vtkIdType ptId[2], const double* x);
289  void GetPointAttributeArray(vtkIdType ptId, double* x);
291 
296  void GetAttributeComponents();
297 
298  double TargetReduction;
299  double ActualReduction;
300  vtkTypeBool AttributeErrorMetric;
301  vtkTypeBool VolumePreservation;
302 
303  bool MapPointData = false;
304 
305  vtkTypeBool ScalarsAttribute;
306  vtkTypeBool VectorsAttribute;
307  vtkTypeBool NormalsAttribute;
308  vtkTypeBool TCoordsAttribute;
309  vtkTypeBool TensorsAttribute;
310 
311  double ScalarsWeight;
312  double VectorsWeight;
313  double NormalsWeight;
314  double TCoordsWeight;
315  double TensorsWeight;
316 
317  int NumberOfEdgeCollapses;
318  vtkEdgeTable* Edges;
319  vtkIdList* EndPoint1List;
320  vtkIdList* EndPoint2List;
321  vtkPriorityQueue* EdgeCosts;
322  vtkDoubleArray* TargetPoints;
323  int NumberOfComponents;
324  vtkPolyData* Mesh;
325 
327  {
328  double* Quadric;
329  };
330 
331  // One ErrorQuadric per point
333 
334  // Controlling regularization behavior
335  vtkTypeBool Regularize = false;
336  double Regularization = 0.05;
337 
338  // Controlling the boundary weighting behavior
339  vtkTypeBool WeighBoundaryConstraintsByLength = false;
340  double BoundaryWeightFactor = 1.0;
341 
342  // Contains 4 doubles per point. Length = nPoints * 4
344  int AttributeComponents[6];
345  double AttributeScale[6];
346 
347  // Temporary variables for performance
349  double* TempX;
350  double* TempQuad;
351  double* TempB;
352  double** TempA;
353  double* TempData;
354 
355 private:
357  void operator=(const vtkQuadricDecimation&) = delete;
358 };
359 
360 VTK_ABI_NAMESPACE_END
361 #endif
dynamic, self-adjusting array of double
keep track of edges (edge is pair of integer id's)
Definition: vtkEdgeTable.h:30
list of point or cell ids
Definition: vtkIdList.h:132
a simple class to control print indentation
Definition: vtkIndent.h:108
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
represent and manipulate point attribute data
Definition: vtkPointData.h:139
Superclass for algorithms that produce only polydata as output.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:180
a list of ids arranged in priority order
reduce the number of triangles in a mesh
void AddBoundaryConstraints()
Free boundary edges are weighted.
void FindAffectedEdges(vtkIdType p1Id, vtkIdType p2Id, vtkIdList *edges)
Find all edges that will have an endpoint change ids because of an edge collapse.
void ComputeNumberOfComponents()
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called by the superclass.
void ComputeQuadric(vtkIdType pointId)
Compute quadric for this vertex.
double ComputeCost2(vtkIdType edgeId, double *x)
Compute cost for contracting this edge and the point that gives us this cost.
vtkIdType GetEdgeCellId(vtkIdType p1Id, vtkIdType p2Id)
Find a cell that uses this edge.
double ComputeCost(vtkIdType edgeId, double *x)
Compute cost for contracting this edge and the point that gives us this cost.
int CollapseEdge(vtkIdType pt0Id, vtkIdType pt1Id)
Do the dirty work of eliminating the edge; return the number of triangles deleted.
~vtkQuadricDecimation() override
int TrianglePlaneCheck(const double t0[3], const double t1[3], const double t2[3], const double *x)
void InitializeQuadrics(vtkIdType numPts)
Compute quadric for all vertices.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void AddQuadric(vtkIdType oldPtId, vtkIdType newPtId)
Add the quadrics for these 2 points since the edge between them has been collapsed.
static vtkQuadricDecimation * New()
int IsGoodPlacement(vtkIdType pt0Id, vtkIdType pt1Id, const double *x)
void UpdateEdgeData(vtkIdType pt0Id, vtkIdType pt1Id)
int vtkTypeBool
Definition: vtkABI.h:64
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)
#define VTK_DEPRECATED_IN_9_3_0(reason)
int vtkIdType
Definition: vtkType.h:315