Point Cloud Library (PCL)  1.8.1
common.h
Go to the documentation of this file.
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 the copyright holder(s) 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_COMMON_H_
39 #define PCL_COMMON_H_
40 
41 #include <pcl/pcl_base.h>
42 #include <cfloat>
43 
44 /**
45  * \file pcl/common/common.h
46  * Define standard C methods and C++ classes that are common to all methods
47  * \ingroup common
48  */
49 
50 /*@{*/
51 namespace pcl
52 {
53  /** \brief Compute the smallest angle between two 3D vectors in radians (default) or degree.
54  * \param v1 the first 3D vector (represented as a \a Eigen::Vector4f)
55  * \param v2 the second 3D vector (represented as a \a Eigen::Vector4f)
56  * \return the angle between v1 and v2 in radians or degrees
57  * \note Handles rounding error for parallel and anti-parallel vectors
58  * \ingroup common
59  */
60  inline double
61  getAngle3D (const Eigen::Vector4f &v1, const Eigen::Vector4f &v2, const bool in_degree = false);
62 
63  /** \brief Compute the smallest angle between two 3D vectors in radians (default) or degree.
64  * \param v1 the first 3D vector (represented as a \a Eigen::Vector3f)
65  * \param v2 the second 3D vector (represented as a \a Eigen::Vector3f)
66  * \param in_degree determine if angle should be in radians or degrees
67  * \return the angle between v1 and v2 in radians or degrees
68  * \ingroup common
69  */
70  inline double
71  getAngle3D (const Eigen::Vector3f &v1, const Eigen::Vector3f &v2, const bool in_degree = false);
72 
73 
74  /** \brief Compute both the mean and the standard deviation of an array of values
75  * \param values the array of values
76  * \param mean the resultant mean of the distribution
77  * \param stddev the resultant standard deviation of the distribution
78  * \ingroup common
79  */
80  inline void
81  getMeanStd (const std::vector<float> &values, double &mean, double &stddev);
82 
83  /** \brief Get a set of points residing in a box given its bounds
84  * \param cloud the point cloud data message
85  * \param min_pt the minimum bounds
86  * \param max_pt the maximum bounds
87  * \param indices the resultant set of point indices residing in the box
88  * \ingroup common
89  */
90  template <typename PointT> inline void
91  getPointsInBox (const pcl::PointCloud<PointT> &cloud, Eigen::Vector4f &min_pt,
92  Eigen::Vector4f &max_pt, std::vector<int> &indices);
93 
94  /** \brief Get the point at maximum distance from a given point and a given pointcloud
95  * \param cloud the point cloud data message
96  * \param pivot_pt the point from where to compute the distance
97  * \param max_pt the point in cloud that is the farthest point away from pivot_pt
98  * \ingroup common
99  */
100  template<typename PointT> inline void
101  getMaxDistance (const pcl::PointCloud<PointT> &cloud, const Eigen::Vector4f &pivot_pt, Eigen::Vector4f &max_pt);
102 
103  /** \brief Get the point at maximum distance from a given point and a given pointcloud
104  * \param cloud the point cloud data message
105  * \param pivot_pt the point from where to compute the distance
106  * \param indices the vector of point indices to use from \a cloud
107  * \param max_pt the point in cloud that is the farthest point away from pivot_pt
108  * \ingroup common
109  */
110  template<typename PointT> inline void
111  getMaxDistance (const pcl::PointCloud<PointT> &cloud, const std::vector<int> &indices,
112  const Eigen::Vector4f &pivot_pt, Eigen::Vector4f &max_pt);
113 
114  /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud
115  * \param cloud the point cloud data message
116  * \param min_pt the resultant minimum bounds
117  * \param max_pt the resultant maximum bounds
118  * \ingroup common
119  */
120  template <typename PointT> inline void
121  getMinMax3D (const pcl::PointCloud<PointT> &cloud, PointT &min_pt, PointT &max_pt);
122 
123  /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud
124  * \param cloud the point cloud data message
125  * \param min_pt the resultant minimum bounds
126  * \param max_pt the resultant maximum bounds
127  * \ingroup common
128  */
129  template <typename PointT> inline void
130  getMinMax3D (const pcl::PointCloud<PointT> &cloud,
131  Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
132 
133  /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud
134  * \param cloud the point cloud data message
135  * \param indices the vector of point indices to use from \a cloud
136  * \param min_pt the resultant minimum bounds
137  * \param max_pt the resultant maximum bounds
138  * \ingroup common
139  */
140  template <typename PointT> inline void
141  getMinMax3D (const pcl::PointCloud<PointT> &cloud, const std::vector<int> &indices,
142  Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
143 
144  /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud
145  * \param cloud the point cloud data message
146  * \param indices the vector of point indices to use from \a cloud
147  * \param min_pt the resultant minimum bounds
148  * \param max_pt the resultant maximum bounds
149  * \ingroup common
150  */
151  template <typename PointT> inline void
152  getMinMax3D (const pcl::PointCloud<PointT> &cloud, const pcl::PointIndices &indices,
153  Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
154 
155  /** \brief Compute the radius of a circumscribed circle for a triangle formed of three points pa, pb, and pc
156  * \param pa the first point
157  * \param pb the second point
158  * \param pc the third point
159  * \return the radius of the circumscribed circle
160  * \ingroup common
161  */
162  template <typename PointT> inline double
163  getCircumcircleRadius (const PointT &pa, const PointT &pb, const PointT &pc);
164 
165  /** \brief Get the minimum and maximum values on a point histogram
166  * \param histogram the point representing a multi-dimensional histogram
167  * \param len the length of the histogram
168  * \param min_p the resultant minimum
169  * \param max_p the resultant maximum
170  * \ingroup common
171  */
172  template <typename PointT> inline void
173  getMinMax (const PointT &histogram, int len, float &min_p, float &max_p);
174 
175  /** \brief Calculate the area of a polygon given a point cloud that defines the polygon
176  * \param polygon point cloud that contains those vertices that comprises the polygon. Vertices are stored in counterclockwise.
177  * \return the polygon area
178  * \ingroup common
179  */
180  template<typename PointT> inline float
182 
183  /** \brief Get the minimum and maximum values on a point histogram
184  * \param cloud the cloud containing multi-dimensional histograms
185  * \param idx point index representing the histogram that we need to compute min/max for
186  * \param field_name the field name containing the multi-dimensional histogram
187  * \param min_p the resultant minimum
188  * \param max_p the resultant maximum
189  * \ingroup common
190  */
191  PCL_EXPORTS void
192  getMinMax (const pcl::PCLPointCloud2 &cloud, int idx, const std::string &field_name,
193  float &min_p, float &max_p);
194 
195  /** \brief Compute both the mean and the standard deviation of an array of values
196  * \param values the array of values
197  * \param mean the resultant mean of the distribution
198  * \param stddev the resultant standard deviation of the distribution
199  * \ingroup common
200  */
201  PCL_EXPORTS void
202  getMeanStdDev (const std::vector<float> &values, double &mean, double &stddev);
203 
204 }
205 /*@}*/
206 #include <pcl/common/impl/common.hpp>
207 
208 #endif //#ifndef PCL_COMMON_H_
void getPointsInBox(const pcl::PointCloud< PointT > &cloud, Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt, std::vector< int > &indices)
Get a set of points residing in a box given its bounds.
Definition: common.hpp:87
double getAngle3D(const Eigen::Vector4f &v1, const Eigen::Vector4f &v2, const bool in_degree=false)
Compute the smallest angle between two 3D vectors in radians (default) or degree. ...
Definition: common.hpp:46
void getMinMax(const PointT &histogram, int len, float &min_p, float &max_p)
Get the minimum and maximum values on a point histogram.
Definition: common.hpp:393
void getMaxDistance(const pcl::PointCloud< PointT > &cloud, const Eigen::Vector4f &pivot_pt, Eigen::Vector4f &max_pt)
Get the point at maximum distance from a given point and a given pointcloud.
Definition: common.hpp:130
float calculatePolygonArea(const pcl::PointCloud< PointT > &polygon)
Calculate the area of a polygon given a point cloud that defines the polygon.
Definition: common.hpp:407
void getMeanStd(const std::vector< float > &values, double &mean, double &stddev)
Compute both the mean and the standard deviation of an array of values.
Definition: common.hpp:71
void getMinMax3D(const pcl::PointCloud< PointT > &cloud, PointT &min_pt, PointT &max_pt)
Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud...
Definition: common.hpp:228
PointCloud represents the base class in PCL for storing collections of 3D points. ...
double getCircumcircleRadius(const PointT &pa, const PointT &pb, const PointT &pc)
Compute the radius of a circumscribed circle for a triangle formed of three points pa...
Definition: common.hpp:376
A point structure representing Euclidean xyz coordinates, and the RGB color.
PCL_EXPORTS void getMeanStdDev(const std::vector< float > &values, double &mean, double &stddev)
Compute both the mean and the standard deviation of an array of values.