Point Cloud Library (PCL)  1.14.1-dev
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 #pragma once
39 
40 #include <pcl/point_types.h>
41 #include <pcl/surface/processing.h>
42 
43 namespace pcl
44 {
45 
46  /** \brief The ear clipping triangulation algorithm.
47  * The code is inspired by Flavien Brebion implementation, which is
48  * in n^3 and does not handle holes.
49  * \author Nicolas Burrus
50  * \ingroup surface
51  */
53  {
54  public:
55  using Ptr = shared_ptr<EarClipping>;
56  using ConstPtr = shared_ptr<const EarClipping>;
57 
60  /** \brief Empty constructor */
61  EarClipping () = default;
62 
63  protected:
64  /** \brief a Pointer to the point cloud data. */
66 
67  /** \brief This method should get called before starting the actual computation. */
68  bool
69  initCompute () override;
70 
71  /** \brief The actual surface reconstruction method.
72  * \param[out] output the output polygonal mesh
73  */
74  void
75  performProcessing (pcl::PolygonMesh &output) override;
76 
77  /** \brief Triangulate one polygon.
78  * \param[in] vertices the set of vertices
79  * \param[out] output the resultant polygonal mesh
80  */
81  void
82  triangulate (const Vertices& vertices, PolygonMesh& output);
83 
84  /** \brief Compute the signed area of a polygon.
85  * \param[in] vertices the vertices representing the polygon
86  */
87  float
88  area (const Indices& vertices);
89 
90  /** \brief Check if the triangle (u,v,w) is an ear.
91  * \param[in] u the first triangle vertex
92  * \param[in] v the second triangle vertex
93  * \param[in] w the third triangle vertex
94  * \param[in] vertices a set of input vertices
95  */
96  bool
97  isEar (int u, int v, int w, const Indices& vertices);
98 
99  /** \brief Check if p is inside the triangle (u,v,w).
100  * \param[in] u the first triangle vertex
101  * \param[in] v the second triangle vertex
102  * \param[in] w the third triangle vertex
103  * \param[in] p the point to check
104  */
105  bool
106  isInsideTriangle (const Eigen::Vector3f& u,
107  const Eigen::Vector3f& v,
108  const Eigen::Vector3f& w,
109  const Eigen::Vector3f& p);
110 
111  /** \brief Compute the cross product between 2D vectors.
112  * \param[in] p1 the first 2D vector
113  * \param[in] p2 the first 2D vector
114  */
115  float
116  crossProduct (const Eigen::Vector2f& p1, const Eigen::Vector2f& p2) const
117  {
118  return p1[0]*p2[1] - p1[1]*p2[0];
119  }
120 
121  };
122 
123 }
The ear clipping triangulation algorithm.
Definition: ear_clipping.h:53
float area(const Indices &vertices)
Compute the signed area of a polygon.
void triangulate(const Vertices &vertices, PolygonMesh &output)
Triangulate one polygon.
void performProcessing(pcl::PolygonMesh &output) override
The actual surface reconstruction method.
bool initCompute() override
This method should get called before starting the actual computation.
shared_ptr< EarClipping > Ptr
Definition: ear_clipping.h:55
bool isInsideTriangle(const Eigen::Vector3f &u, const Eigen::Vector3f &v, const Eigen::Vector3f &w, const Eigen::Vector3f &p)
Check if p is inside the triangle (u,v,w).
pcl::PointCloud< pcl::PointXYZ >::Ptr points_
a Pointer to the point cloud data.
Definition: ear_clipping.h:65
bool isEar(int u, int v, int w, const Indices &vertices)
Check if the triangle (u,v,w) is an ear.
shared_ptr< const EarClipping > ConstPtr
Definition: ear_clipping.h:56
float crossProduct(const Eigen::Vector2f &p1, const Eigen::Vector2f &p2) const
Compute the cross product between 2D vectors.
Definition: ear_clipping.h:116
EarClipping()=default
Empty constructor.
MeshProcessing represents the base class for mesh processing algorithms.
Definition: processing.h:95
virtual bool initCompute()
Initialize computation.
pcl::PolygonMeshConstPtr input_mesh_
Input polygonal mesh.
Definition: processing.h:147
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
Defines all the PCL implemented PointT point type structures.
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
#define PCL_EXPORTS
Definition: pcl_macros.h:323
Describes a set of vertices in a polygon mesh, by basically storing an array of indices.
Definition: Vertices.h:15