Point Cloud Library (PCL)  1.7.0
vtk_mesh_smoothing_windowed_sinc.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_WINDOWED_SINC_H_
40 #define VTK_MESH_SMOOTHING_WINDOWED_SINC_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 vtkWindowedSincPolyDataFilter 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 MeshSmoothingWindowedSincVTK : public MeshProcessing
53  {
54  public:
55  /** \brief Empty constructor that sets the values of the algorithm parameters to the VTK defaults */
57  : MeshProcessing (),
58  num_iter_ (20),
59  pass_band_ (0.1f),
60  feature_edge_smoothing_ (false),
61  feature_angle_ (45.f),
62  edge_angle_ (15.f),
63  boundary_smoothing_ (true),
64  normalize_coordinates_ (false)
65  {};
66 
67  /** \brief Set the number of iterations for the smoothing filter.
68  * \param[in] num_iter the number of iterations
69  */
70  inline void
71  setNumIter (int num_iter)
72  {
73  num_iter_ = num_iter;
74  };
75 
76  /** \brief Get the number of iterations. */
77  inline int
78  getNumIter ()
79  {
80  return num_iter_;
81  };
82 
83  /** \brief Set the pass band value for windowed sinc filtering.
84  * \param[in] pass_band value for the pass band.
85  */
86  inline void
87  setPassBand (float pass_band)
88  {
89  pass_band_ = pass_band;
90  };
91 
92  /** \brief Get the pass band value. */
93  inline float
94  getPassBand ()
95  {
96  return pass_band_;
97  };
98 
99  /** \brief Turn on/off coordinate normalization. The positions can be translated and scaled such that they fit
100  * within a [-1, 1] prior to the smoothing computation. The default is off. The numerical stability of the
101  * solution can be improved by turning normalization on. If normalization is on, the coordinates will be rescaled
102  * to the original coordinate system after smoothing has completed.
103  * \param[in] normalize_coordinates decision whether to normalize coordinates or not
104  */
105  inline void
106  setNormalizeCoordinates (bool normalize_coordinates)
107  {
108  normalize_coordinates_ = normalize_coordinates;
109  }
110 
111  /** \brief Get whether the coordinate normalization is active or not */
112  inline bool
113  getNormalizeCoordinates ()
114  {
115  return normalize_coordinates_;
116  }
117 
118  /** \brief Turn on/off smoothing along sharp interior edges.
119  * \param[in] status decision whether to enable/disable smoothing along sharp interior edges
120  */
121  inline void
122  setFeatureEdgeSmoothing (bool feature_edge_smoothing)
123  {
124  feature_edge_smoothing_ = feature_edge_smoothing;
125  };
126 
127  /** \brief Get the status of the feature edge smoothing */
128  inline bool
129  getFeatureEdgeSmoothing ()
130  {
131  return feature_edge_smoothing_;
132  };
133 
134  /** \brief Specify the feature angle for sharp edge identification.
135  * \param[in] feature_angle the angle threshold for considering an edge to be sharp
136  */
137  inline void
138  setFeatureAngle (float feature_angle)
139  {
140  feature_angle_ = feature_angle;
141  };
142 
143  /** \brief Get the angle threshold for considering an edge to be sharp */
144  inline float
145  getFeatureAngle ()
146  {
147  return feature_angle_;
148  };
149 
150  /** \brief Specify the edge angle to control smoothing along edges (either interior or boundary).
151  * \param[in] edge_angle the angle to control smoothing along edges
152  */
153  inline void
154  setEdgeAngle (float edge_angle)
155  {
156  edge_angle_ = edge_angle;
157  };
158 
159  /** \brief Get the edge angle to control smoothing along edges */
160  inline float
161  getEdgeAngle ()
162  {
163  return edge_angle_;
164  };
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
178  getBoundarySmoothing ()
179  {
180  return boundary_smoothing_;
181  }
182 
183 
184  protected:
185  void
186  performProcessing (pcl::PolygonMesh &output);
187 
188  private:
189  vtkSmartPointer<vtkPolyData> vtk_polygons_;
190  int num_iter_;
191  float pass_band_;
192  bool feature_edge_smoothing_;
193  float feature_angle_;
194  float edge_angle_;
195  bool boundary_smoothing_;
196  bool normalize_coordinates_;
197  };
198 }
199 #endif /* VTK_MESH_SMOOTHING_WINDOWED_SINC_H_ */