Point Cloud Library (PCL)  1.9.1
ear_clipping.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * $Id$
35  *
36  */
37 
38 #ifndef PCL_SURFACE_EAR_CLIPPING_H_
39 #define PCL_SURFACE_EAR_CLIPPING_H_
40 
41 #include <pcl/point_types.h>
42 #include <pcl/surface/processing.h>
43 
44 namespace pcl
45 {
46 
47  /** \brief The ear clipping triangulation algorithm.
48  * The code is inspired by Flavien Brebion implementation, which is
49  * in n^3 and does not handle holes.
50  * \author Nicolas Burrus
51  * \ingroup surface
52  */
53  class PCL_EXPORTS EarClipping : public MeshProcessing
54  {
55  public:
56  typedef boost::shared_ptr<EarClipping> Ptr;
57  typedef boost::shared_ptr<const EarClipping> ConstPtr;
58 
61  /** \brief Empty constructor */
62  EarClipping () : MeshProcessing (), points_ ()
63  {
64  };
65 
66  protected:
67  /** \brief a Pointer to the point cloud data. */
69 
70  /** \brief This method should get called before starting the actual computation. */
71  bool
72  initCompute ();
73 
74  /** \brief The actual surface reconstruction method.
75  * \param[out] output the output polygonal mesh
76  */
77  void
78  performProcessing (pcl::PolygonMesh &output);
79 
80  /** \brief Triangulate one polygon.
81  * \param[in] vertices the set of vertices
82  * \param[out] output the resultant polygonal mesh
83  */
84  void
85  triangulate (const Vertices& vertices, PolygonMesh& output);
86 
87  /** \brief Compute the signed area of a polygon.
88  * \param[in] vertices the vertices representing the polygon
89  */
90  float
91  area (const std::vector<uint32_t>& vertices);
92 
93  /** \brief Check if the triangle (u,v,w) is an ear.
94  * \param[in] u the first triangle vertex
95  * \param[in] v the second triangle vertex
96  * \param[in] w the third triangle vertex
97  * \param[in] vertices a set of input vertices
98  */
99  bool
100  isEar (int u, int v, int w, const std::vector<uint32_t>& vertices);
101 
102  /** \brief Check if p is inside the triangle (u,v,w).
103  * \param[in] u the first triangle vertex
104  * \param[in] v the second triangle vertex
105  * \param[in] w the third triangle vertex
106  * \param[in] p the point to check
107  */
108  bool
109  isInsideTriangle (const Eigen::Vector3f& u,
110  const Eigen::Vector3f& v,
111  const Eigen::Vector3f& w,
112  const Eigen::Vector3f& p);
113 
114  /** \brief Compute the cross product between 2D vectors.
115  * \param[in] p1 the first 2D vector
116  * \param[in] p2 the first 2D vector
117  */
118  float
119  crossProduct (const Eigen::Vector2f& p1, const Eigen::Vector2f& p2) const
120  {
121  return p1[0]*p2[1] - p1[1]*p2[0];
122  }
123 
124  };
125 
126 }
127 
128 #endif // #ifndef PCL_SURFACE_EAR_CLIPPING_H_
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
EarClipping()
Empty constructor.
Definition: ear_clipping.h:62
Describes a set of vertices in a polygon mesh, by basically storing an array of indices.
Definition: Vertices.h:14
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
boost::shared_ptr< const EarClipping > ConstPtr
Definition: ear_clipping.h:57
pcl::PointCloud< pcl::PointXYZ >::Ptr points_
a Pointer to the point cloud data.
Definition: ear_clipping.h:64
Defines all the PCL implemented PointT point type structures.
float crossProduct(const Eigen::Vector2f &p1, const Eigen::Vector2f &p2) const
Compute the cross product between 2D vectors.
Definition: ear_clipping.h:119
pcl::PolygonMeshConstPtr input_mesh_
Input polygonal mesh.
Definition: processing.h:147
boost::shared_ptr< EarClipping > Ptr
Definition: ear_clipping.h:56
virtual bool initCompute()
Initialize computation.
The ear clipping triangulation algorithm.
Definition: ear_clipping.h:53