vtkCleanPolyData.h 7.66 KB
Newer Older
Will Schroeder's avatar
Will Schroeder committed
1 2
/*=========================================================================

Ken Martin's avatar
Ken Martin committed
3
  Program:   Visualization Toolkit
Ken Martin's avatar
Ken Martin committed
4
  Module:    vtkCleanPolyData.h
Will Schroeder's avatar
Will Schroeder committed
5

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
Ken Martin's avatar
Ken Martin committed
9

10 11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
     PURPOSE.  See the above copyright notice for more information.
Will Schroeder's avatar
Will Schroeder committed
13 14

=========================================================================*/
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/**
 * @class   vtkCleanPolyData
 * @brief   merge duplicate points, and/or remove unused points and/or remove degenerate cells
 *
 * vtkCleanPolyData is a filter that takes polygonal data as input and
 * generates polygonal data as output. vtkCleanPolyData will merge duplicate
 * points (within specified tolerance and if enabled), eliminate points
 * that are not used in any cell, and if enabled, transform degenerate cells into
 * appropriate forms (for example, a triangle is converted into a line
 * if two points of triangle are merged).
 *
 * Conversion of degenerate cells is controlled by the flags
 * ConvertLinesToPoints, ConvertPolysToLines, ConvertStripsToPolys which act
 * cumulatively such that a degenerate strip may become a poly.
 * The full set is
 * Line with 1 points -> Vert (if ConvertLinesToPoints)
 * Poly with 2 points -> Line (if ConvertPolysToLines)
 * Poly with 1 points -> Vert (if ConvertPolysToLines && ConvertLinesToPoints)
 * Strp with 3 points -> Poly (if ConvertStripsToPolys)
 * Strp with 2 points -> Line (if ConvertStripsToPolys && ConvertPolysToLines)
 * Strp with 1 points -> Vert (if ConvertStripsToPolys && ConvertPolysToLines
 *   && ConvertLinesToPoints)
 *
38 39 40 41
 * Cells of type VTK_POLY_LINE will be converted to a vertex only if
 * ConvertLinesToPoints is on and all points are merged into one. Degenerate line
 * segments (with two identical end points) will be removed.
 *
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
 * If tolerance is specified precisely=0.0, then vtkCleanPolyData will use
 * the vtkMergePoints object to merge points (which is faster). Otherwise the
 * slower vtkIncrementalPointLocator is used.  Before inserting points into the point
 * locator, this class calls a function OperateOnPoint which can be used (in
 * subclasses) to further refine the cleaning process. See
 * vtkQuantizePolyDataPoints.
 *
 * Note that merging of points can be disabled. In this case, a point locator
 * will not be used, and points that are not used by any cells will be
 * eliminated, but never merged.
 *
 * @warning
 * Merging points can alter topology, including introducing non-manifold
 * forms. The tolerance should be chosen carefully to avoid these problems.
 * Subclasses should handle OperateOnBounds as well as OperateOnPoint
 * to ensure that the locator is correctly initialized (i.e. all modified
 * points must lie inside modified bounds).
 *
 * @warning
 * If you wish to operate on a set of coordinates
 * that has no cells, you must add a vtkPolyVertex cell with all of the points to the PolyData
 * (or use a vtkVertexGlyphFilter) before using the vtkCleanPolyData filter.
 *
 * @sa
 * vtkQuantizePolyDataPoints
*/
Will Schroeder's avatar
Will Schroeder committed
68

69 70
#ifndef vtkCleanPolyData_h
#define vtkCleanPolyData_h
Will Schroeder's avatar
Will Schroeder committed
71

72
#include "vtkFiltersCoreModule.h" // For export macro
73
#include "vtkPolyDataAlgorithm.h"
Will Schroeder's avatar
Will Schroeder committed
74

75
class vtkIncrementalPointLocator;
76

77
class VTKFILTERSCORE_EXPORT vtkCleanPolyData : public vtkPolyDataAlgorithm
Will Schroeder's avatar
Will Schroeder committed
78 79
{
public:
80
  static vtkCleanPolyData *New();
81
  void PrintSelf(ostream& os, vtkIndent indent) override;
82
  vtkTypeMacro(vtkCleanPolyData,vtkPolyDataAlgorithm);
Will Schroeder's avatar
Will Schroeder committed
83

84 85 86 87 88 89
  //@{
  /**
   * By default ToleranceIsAbsolute is false and Tolerance is
   * a fraction of Bounding box diagonal, if true, AbsoluteTolerance is
   * used when adding points to locator (merging)
   */
90 91 92
  vtkSetMacro(ToleranceIsAbsolute,vtkTypeBool);
  vtkBooleanMacro(ToleranceIsAbsolute,vtkTypeBool);
  vtkGetMacro(ToleranceIsAbsolute,vtkTypeBool);
93
  //@}
94

95 96 97 98 99
  //@{
  /**
   * Specify tolerance in terms of fraction of bounding box length.
   * Default is 0.0.
   */
Ken Martin's avatar
Ken Martin committed
100 101
  vtkSetClampMacro(Tolerance,double,0.0,1.0);
  vtkGetMacro(Tolerance,double);
102
  //@}
Will Schroeder's avatar
Will Schroeder committed
103

104 105 106 107
  //@{
  /**
   * Specify tolerance in absolute terms. Default is 1.0.
   */
Ken Martin's avatar
Ken Martin committed
108 109
  vtkSetClampMacro(AbsoluteTolerance,double,0.0,VTK_DOUBLE_MAX);
  vtkGetMacro(AbsoluteTolerance,double);
110
  //@}
111

112 113 114 115
  //@{
  /**
   * Turn on/off conversion of degenerate lines to points. Default is On.
   */
116 117 118
  vtkSetMacro(ConvertLinesToPoints,vtkTypeBool);
  vtkBooleanMacro(ConvertLinesToPoints,vtkTypeBool);
  vtkGetMacro(ConvertLinesToPoints,vtkTypeBool);
119
  //@}
120

121 122 123 124
  //@{
  /**
   * Turn on/off conversion of degenerate polys to lines. Default is On.
   */
125 126 127
  vtkSetMacro(ConvertPolysToLines,vtkTypeBool);
  vtkBooleanMacro(ConvertPolysToLines,vtkTypeBool);
  vtkGetMacro(ConvertPolysToLines,vtkTypeBool);
128
  //@}
129

130 131 132 133
  //@{
  /**
   * Turn on/off conversion of degenerate strips to polys. Default is On.
   */
134 135 136
  vtkSetMacro(ConvertStripsToPolys,vtkTypeBool);
  vtkBooleanMacro(ConvertStripsToPolys,vtkTypeBool);
  vtkGetMacro(ConvertStripsToPolys,vtkTypeBool);
137 138 139 140 141 142 143 144 145
  //@}

  //@{
  /**
   * Set/Get a boolean value that controls whether point merging is
   * performed. If on, a locator will be used, and points laying within
   * the appropriate tolerance may be merged. If off, points are never
   * merged. By default, merging is on.
   */
146 147 148
  vtkSetMacro(PointMerging,vtkTypeBool);
  vtkGetMacro(PointMerging,vtkTypeBool);
  vtkBooleanMacro(PointMerging,vtkTypeBool);
149
  //@}
150

151 152 153 154 155
  //@{
  /**
   * Set/Get a spatial locator for speeding the search process. By
   * default an instance of vtkMergePoints is used.
   */
156 157
  virtual void SetLocator(vtkIncrementalPointLocator *locator);
  vtkGetObjectMacro(Locator,vtkIncrementalPointLocator);
158
  //@}
Will Schroeder's avatar
Will Schroeder committed
159

160 161 162
  /**
   * Create default locator. Used to create one when none is specified.
   */
163
  void CreateDefaultLocator(vtkPolyData *input = nullptr);
164

165 166 167
  /**
   * Release locator
   */
168
  void ReleaseLocator() { this->SetLocator(nullptr); }
Will Schroeder's avatar
Will Schroeder committed
169

170 171 172
  /**
   * Get the MTime of this object also considering the locator.
   */
173
  vtkMTimeType GetMTime() override;
Charles Law's avatar
Charles Law committed
174

175 176 177
  /**
   * Perform operation on a point
   */
Ken Martin's avatar
Ken Martin committed
178
  virtual void OperateOnPoint(double in[3], double out[3]);
179

180 181 182
  /**
   * Perform operation on bounds
   */
Ken Martin's avatar
Ken Martin committed
183
  virtual void OperateOnBounds(double in[6], double out[6]);
184

185 186 187 188 189
  // This filter is difficult to stream.
  // To get invariant results, the whole input must be processed at once.
  // This flag allows the user to select whether strict piece invariance
  // is required.  By default it is on.  When off, the filter can stream,
  // but results may change.
190 191 192
  vtkSetMacro(PieceInvariant, vtkTypeBool);
  vtkGetMacro(PieceInvariant, vtkTypeBool);
  vtkBooleanMacro(PieceInvariant, vtkTypeBool);
193

194 195 196 197 198 199
  //@{
  /**
   * Set/get the desired precision for the output types. See the documentation
   * for the vtkAlgorithm::DesiredOutputPrecision enum for an explanation of
   * the available precision settings.
   */
200 201
  vtkSetMacro(OutputPointsPrecision,int);
  vtkGetMacro(OutputPointsPrecision,int);
202
  //@}
203

Will Schroeder's avatar
Will Schroeder committed
204
protected:
205
  vtkCleanPolyData();
206
 ~vtkCleanPolyData() override;
207

Will Schroeder's avatar
Will Schroeder committed
208
  // Usual data generation method
209 210
  int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override;
  int RequestUpdateExtent(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override;
Will Schroeder's avatar
Will Schroeder committed
211

212
  vtkTypeBool   PointMerging;
Ken Martin's avatar
Ken Martin committed
213 214
  double Tolerance;
  double AbsoluteTolerance;
215 216 217 218
  vtkTypeBool ConvertLinesToPoints;
  vtkTypeBool ConvertPolysToLines;
  vtkTypeBool ConvertStripsToPolys;
  vtkTypeBool ToleranceIsAbsolute;
219
  vtkIncrementalPointLocator *Locator;
220

221
  vtkTypeBool PieceInvariant;
222
  int OutputPointsPrecision;
223
private:
224 225
  vtkCleanPolyData(const vtkCleanPolyData&) = delete;
  void operator=(const vtkCleanPolyData&) = delete;
Will Schroeder's avatar
Will Schroeder committed
226 227 228
};

#endif