1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkSmoothPolyDataFilter.h,v $
6 Date: $Date: 2002/01/22 15:29:45 $
7 Version: $Revision: 1.23 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notice for more information.
17 =========================================================================*/
18 // .NAME vtkSmoothPolyDataFilter.h - adjust point positions using Laplacian smoothing
19 // .SECTION Description
20 // vtkSmoothPolyDataFilter.h is a filter that adjusts point coordinates using
21 // Laplacian smoothing. The effect is to "relax" the mesh, making the cells
22 // better shaped and the vertices more evenly distributed. Note that this
23 // filter operates on the lines, polygons, and triangle strips composing an
24 // instance of vtkPolyData. Vertex or poly-vertex cells are never modified.
26 // The algorithm proceeds as follows. For each vertex v, a topological and
27 // geometric analysis is performed to determine which vertices are connected
28 // to v, and which cells are connected to v. Then, a connectivity array is
29 // constructed for each vertex. (The connectivity array is a list of lists
30 // of vertices that directly attach to each vertex.) Next, an iteration
31 // phase begins over all vertices. For each vertex v, the coordinates of v
32 // are modified according to an average of the connected vertices. (A
33 // relaxation factor is available to control the amount of displacement of
34 // v). The process repeats for each vertex. This pass over the list of
35 // vertices is a single iteration. Many iterations (generally around 20 or
36 // so) are repeated until the desired result is obtained.
38 // There are some special instance variables used to control the execution
39 // of this filter. (These ivars basically control what vertices can be
40 // smoothed, and the creation of the connectivity array.) The
41 // BoundarySmoothing ivar enables/disables the smoothing operation on
42 // vertices that are on the "boundary" of the mesh. A boundary vertex is one
43 // that is surrounded by a semi-cycle of polygons (or used by a single
46 // Another important ivar is FeatureEdgeSmoothing. If this ivar is
47 // enabled, then interior vertices are classified as either "simple",
48 // "interior edge", or "fixed", and smoothed differently. (Interior
49 // vertices are manifold vertices surrounded by a cycle of polygons; or used
50 // by two line cells.) The classification is based on the number of feature
51 // edges attached to v. A feature edge occurs when the angle between the two
52 // surface normals of a polygon sharing an edge is greater than the
53 // FeatureAngle ivar. Then, vertices used by no feature edges are classified
54 // "simple", vertices used by exactly two feature edges are classified
55 // "interior edge", and all others are "fixed" vertices.
57 // Once the classification is known, the vertices are smoothed
58 // differently. Corner (i.e., fixed) vertices are not smoothed at all.
59 // Simple vertices are smoothed as before (i.e., average of connected
60 // vertex coordinates). Interior edge vertices are smoothed only along
61 // their two connected edges, and only if the angle between the edges
62 // is less than the EdgeAngle ivar.
64 // The total smoothing can be controlled by using two ivars. The
65 // NumberOfIterations is a cap on the maximum number of smoothing passes.
66 // The Convergence ivar is a limit on the maximum point motion. If the
67 // maximum motion during an iteration is less than Convergence, then the
68 // smoothing process terminates. (Convergence is expressed as a fraction of
69 // the diagonal of the bounding box.)
71 // There are two instance variables that control the generation of error
72 // data. If the ivar GenerateErrorScalars is on, then a scalar value indicating
73 // the distance of each vertex from its original position is computed. If the
74 // ivar GenerateErrorVectors is on, then a vector representing change in
75 // position is computed.
77 // Optionally you can further control the smoothing process by defining a
78 // second input: the Source. If defined, the input mesh is constrained to
79 // lie on the surface defined by the Source ivar.
83 // The Laplacian operation reduces high frequency information in the geometry
84 // of the mesh. With excessive smoothing important details may be lost, and
85 // the surface may shrink towards the centroid. Enabling FeatureEdgeSmoothing
86 // helps reduce this effect, but cannot entirely eliminate it. You may also
87 // wish to try vtkWindowedSincPolyDataFilter. It does a better job of
88 // minimizing shrinkage.
91 // vtkWindowedSincPolyDataFilter vtkDecimate vtkDecimatePro
93 #ifndef __vtkSmoothPolyDataFilter_h
94 #define __vtkSmoothPolyDataFilter_h
96 #include "vtkPolyDataToPolyDataFilter.h"
98 class vtkSmoothPoints;
100 class VTK_GRAPHICS_EXPORT vtkSmoothPolyDataFilter : public vtkPolyDataToPolyDataFilter
103 vtkTypeRevisionMacro(vtkSmoothPolyDataFilter,vtkPolyDataToPolyDataFilter);
104 void PrintSelf(ostream& os, vtkIndent indent);
107 // Construct object with number of iterations 20; relaxation factor .01;
108 // feature edge smoothing turned off; feature
109 // angle 45 degrees; edge angle 15 degrees; and boundary smoothing turned
110 // on. Error scalars and vectors are not generated (by default). The
111 // convergence criterion is 0.0 of the bounding box diagonal.
112 static vtkSmoothPolyDataFilter *New();
115 // Specify a convergence criterion for the iteration
116 // process. Smaller numbers result in more smoothing iterations.
117 vtkSetClampMacro(Convergence,float,0.0,1.0);
118 vtkGetMacro(Convergence,float);
121 // Specify the number of iterations for Laplacian smoothing,
122 vtkSetClampMacro(NumberOfIterations,int,0,VTK_LARGE_INTEGER);
123 vtkGetMacro(NumberOfIterations,int);
126 // Specify the relaxation factor for Laplacian smoothing. As in all
127 // iterative methods, the stability of the process is sensitive to
128 // this parameter. In general, small relaxation factors and large
129 // numbers of iterations are more stable than larger relaxation
130 // factors and smaller numbers of iterations.
131 vtkSetMacro(RelaxationFactor,float);
132 vtkGetMacro(RelaxationFactor,float);
135 // Turn on/off smoothing along sharp interior edges.
136 vtkSetMacro(FeatureEdgeSmoothing,int);
137 vtkGetMacro(FeatureEdgeSmoothing,int);
138 vtkBooleanMacro(FeatureEdgeSmoothing,int);
141 // Specify the feature angle for sharp edge identification.
142 vtkSetClampMacro(FeatureAngle,float,0.0,180.0);
143 vtkGetMacro(FeatureAngle,float);
146 // Specify the edge angle to control smoothing along edges (either interior
148 vtkSetClampMacro(EdgeAngle,float,0.0,180.0);
149 vtkGetMacro(EdgeAngle,float);
152 // Turn on/off the smoothing of vertices on the boundary of the mesh.
153 vtkSetMacro(BoundarySmoothing,int);
154 vtkGetMacro(BoundarySmoothing,int);
155 vtkBooleanMacro(BoundarySmoothing,int);
158 // Turn on/off the generation of scalar distance values.
159 vtkSetMacro(GenerateErrorScalars,int);
160 vtkGetMacro(GenerateErrorScalars,int);
161 vtkBooleanMacro(GenerateErrorScalars,int);
164 // Turn on/off the generation of error vectors.
165 vtkSetMacro(GenerateErrorVectors,int);
166 vtkGetMacro(GenerateErrorVectors,int);
167 vtkBooleanMacro(GenerateErrorVectors,int);
170 // Specify the source object which is used to constrain smoothing. The
171 // source defines a surface that the input (as it is smoothed) is
172 // constrained to lie upon.
173 void SetSource(vtkPolyData *source);
174 vtkPolyData *GetSource();
177 vtkSmoothPolyDataFilter();
178 ~vtkSmoothPolyDataFilter() {};
183 int NumberOfIterations;
184 float RelaxationFactor;
185 int FeatureEdgeSmoothing;
188 int BoundarySmoothing;
189 int GenerateErrorScalars;
190 int GenerateErrorVectors;
192 vtkSmoothPoints *SmoothPoints;
194 vtkSmoothPolyDataFilter(const vtkSmoothPolyDataFilter&); // Not implemented.
195 void operator=(const vtkSmoothPolyDataFilter&); // Not implemented.