Point Cloud Library (PCL)  1.9.1
vtk_mesh_smoothing_laplacian.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2011, Willow Garage, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Willow Garage, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  * $Id$
36  *
37  */
38 
39 #ifndef VTK_MESH_SMOOTHING_LAPLACIAN_H_
40 #define VTK_MESH_SMOOTHING_LAPLACIAN_H_
41 
42 #include <pcl/surface/processing.h>
43 #include <pcl/surface/vtk_smoothing/vtk.h>
44 
45 namespace pcl
46 {
47  /** \brief PCL mesh smoothing based on the vtkSmoothPolyDataFilter algorithm from the VTK library.
48  * Please check out the original documentation for more details on the inner workings of the algorithm
49  * Warning: This wrapper does two fairly computationally expensive conversions from the PCL PolygonMesh
50  * data structure to the vtkPolyData data structure and back.
51  */
52  class PCL_EXPORTS MeshSmoothingLaplacianVTK : public MeshProcessing
53  {
54  public:
55  /** \brief Empty constructor that sets the values of the algorithm parameters to the VTK defaults */
57  : MeshProcessing ()
58  , vtk_polygons_ ()
59  , num_iter_ (20)
60  , convergence_ (0.0f)
61  , relaxation_factor_ (0.01f)
62  , feature_edge_smoothing_ (false)
63  , feature_angle_ (45.f)
64  , edge_angle_ (15.f)
65  , boundary_smoothing_ (true)
66  {};
67 
68  /** \brief Set the number of iterations for the smoothing filter.
69  * \param[in] num_iter the number of iterations
70  */
71  inline void
72  setNumIter (int num_iter)
73  {
74  num_iter_ = num_iter;
75  };
76 
77  /** \brief Get the number of iterations. */
78  inline int
80  {
81  return num_iter_;
82  };
83 
84  /** \brief Specify a convergence criterion for the iteration process. Smaller numbers result in more smoothing iterations.
85  * \param[in] convergence convergence criterion for the Laplacian smoothing
86  */
87  inline void
88  setConvergence (float convergence)
89  {
90  convergence_ = convergence;
91  };
92 
93  /** \brief Get the convergence criterion. */
94  inline float
96  {
97  return convergence_;
98  };
99 
100  /** \brief Specify the relaxation factor for Laplacian smoothing. As in all iterative methods,
101  * the stability of the process is sensitive to this parameter.
102  * In general, small relaxation factors and large numbers of iterations are more stable than larger relaxation
103  * factors and smaller numbers of iterations.
104  * \param[in] relaxation_factor the relaxation factor of the Laplacian smoothing algorithm
105  */
106  inline void
107  setRelaxationFactor (float relaxation_factor)
108  {
109  relaxation_factor_ = relaxation_factor;
110  };
111 
112  /** \brief Get the relaxation factor of the Laplacian smoothing */
113  inline float
115  {
116  return relaxation_factor_;
117  };
118 
119  /** \brief Turn on/off smoothing along sharp interior edges.
120  * \param[in] feature_edge_smoothing whether to enable/disable smoothing along sharp interior edges
121  */
122  inline void
123  setFeatureEdgeSmoothing (bool feature_edge_smoothing)
124  {
125  feature_edge_smoothing_ = feature_edge_smoothing;
126  };
127 
128  /** \brief Get the status of the feature edge smoothing */
129  inline bool
131  {
132  return feature_edge_smoothing_;
133  };
134 
135  /** \brief Specify the feature angle for sharp edge identification.
136  * \param[in] feature_angle the angle threshold for considering an edge to be sharp
137  */
138  inline void
139  setFeatureAngle (float feature_angle)
140  {
141  feature_angle_ = feature_angle;
142  };
143 
144  /** \brief Get the angle threshold for considering an edge to be sharp */
145  inline float
147  {
148  return feature_angle_;
149  };
150 
151  /** \brief Specify the edge angle to control smoothing along edges (either interior or boundary).
152  * \param[in] edge_angle the angle to control smoothing along edges
153  */
154  inline void
155  setEdgeAngle (float edge_angle)
156  {
157  edge_angle_ = edge_angle;
158  };
159 
160  /** \brief Get the edge angle to control smoothing along edges */
161  inline float
163  {
164  return edge_angle_;
165  };
166 
167  /** \brief Turn on/off the smoothing of vertices on the boundary of the mesh.
168  * \param[in] boundary_smoothing decision whether boundary smoothing is on or off
169  */
170  inline void
171  setBoundarySmoothing (bool boundary_smoothing)
172  {
173  boundary_smoothing_ = boundary_smoothing;
174  };
175 
176  /** \brief Get the status of the boundary smoothing */
177  inline bool
179  {
180  return boundary_smoothing_;
181  }
182 
183  protected:
184  void
185  performProcessing (pcl::PolygonMesh &output);
186 
187  private:
188  vtkSmartPointer<vtkPolyData> vtk_polygons_;
189 
190  /// Parameters
191  int num_iter_;
192  float convergence_;
193  float relaxation_factor_;
194  bool feature_edge_smoothing_;
195  float feature_angle_;
196  float edge_angle_;
197  bool boundary_smoothing_;
198  };
199 }
200 #endif /* VTK_MESH_SMOOTHING_LAPLACIAN_H_ */
float getRelaxationFactor()
Get the relaxation factor of the Laplacian smoothing.
void setFeatureEdgeSmoothing(bool feature_edge_smoothing)
Turn on/off smoothing along sharp interior edges.
bool getBoundarySmoothing()
Get the status of the boundary smoothing.
MeshSmoothingLaplacianVTK()
Empty constructor that sets the values of the algorithm parameters to the VTK defaults.
void setNumIter(int num_iter)
Set the number of iterations for the smoothing filter.
MeshProcessing represents the base class for mesh processing algorithms.
Definition: processing.h:94
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
float getConvergence()
Get the convergence criterion.
float getFeatureAngle()
Get the angle threshold for considering an edge to be sharp.
void setRelaxationFactor(float relaxation_factor)
Specify the relaxation factor for Laplacian smoothing.
PCL mesh smoothing based on the vtkSmoothPolyDataFilter algorithm from the VTK library.
void setEdgeAngle(float edge_angle)
Specify the edge angle to control smoothing along edges (either interior or boundary).
void setConvergence(float convergence)
Specify a convergence criterion for the iteration process.
float getEdgeAngle()
Get the edge angle to control smoothing along edges.
void setBoundarySmoothing(bool boundary_smoothing)
Turn on/off the smoothing of vertices on the boundary of the mesh.
int getNumIter()
Get the number of iterations.
bool getFeatureEdgeSmoothing()
Get the status of the feature edge smoothing.
void setFeatureAngle(float feature_angle)
Specify the feature angle for sharp edge identification.