Point Cloud Library (PCL)  1.7.1
common.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 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 vectors in the [ 0, PI ) interval in 3D.
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
57  * \ingroup common
58  */
59  inline double
60  getAngle3D (const Eigen::Vector4f &v1, const Eigen::Vector4f &v2);
61 
62  /** \brief Compute both the mean and the standard deviation of an array of values
63  * \param values the array of values
64  * \param mean the resultant mean of the distribution
65  * \param stddev the resultant standard deviation of the distribution
66  * \ingroup common
67  */
68  inline void
69  getMeanStd (const std::vector<float> &values, double &mean, double &stddev);
70 
71  /** \brief Get a set of points residing in a box given its bounds
72  * \param cloud the point cloud data message
73  * \param min_pt the minimum bounds
74  * \param max_pt the maximum bounds
75  * \param indices the resultant set of point indices residing in the box
76  * \ingroup common
77  */
78  template <typename PointT> inline void
79  getPointsInBox (const pcl::PointCloud<PointT> &cloud, Eigen::Vector4f &min_pt,
80  Eigen::Vector4f &max_pt, std::vector<int> &indices);
81 
82  /** \brief Get the point at maximum distance from a given point and a given pointcloud
83  * \param cloud the point cloud data message
84  * \param pivot_pt the point from where to compute the distance
85  * \param max_pt the point in cloud that is the farthest point away from pivot_pt
86  * \ingroup common
87  */
88  template<typename PointT> inline void
89  getMaxDistance (const pcl::PointCloud<PointT> &cloud, const Eigen::Vector4f &pivot_pt, Eigen::Vector4f &max_pt);
90 
91  /** \brief Get the point at maximum distance from a given point and a given pointcloud
92  * \param cloud the point cloud data message
93  * \param pivot_pt the point from where to compute the distance
94  * \param indices the vector of point indices to use from \a cloud
95  * \param max_pt the point in cloud that is the farthest point away from pivot_pt
96  * \ingroup common
97  */
98  template<typename PointT> inline void
99  getMaxDistance (const pcl::PointCloud<PointT> &cloud, const std::vector<int> &indices,
100  const Eigen::Vector4f &pivot_pt, Eigen::Vector4f &max_pt);
101 
102  /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud
103  * \param cloud the point cloud data message
104  * \param min_pt the resultant minimum bounds
105  * \param max_pt the resultant maximum bounds
106  * \ingroup common
107  */
108  template <typename PointT> inline void
109  getMinMax3D (const pcl::PointCloud<PointT> &cloud, PointT &min_pt, PointT &max_pt);
110 
111  /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud
112  * \param cloud the point cloud data message
113  * \param min_pt the resultant minimum bounds
114  * \param max_pt the resultant maximum bounds
115  * \ingroup common
116  */
117  template <typename PointT> inline void
118  getMinMax3D (const pcl::PointCloud<PointT> &cloud,
119  Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
120 
121  /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud
122  * \param cloud the point cloud data message
123  * \param indices the vector of point indices to use from \a cloud
124  * \param min_pt the resultant minimum bounds
125  * \param max_pt the resultant maximum bounds
126  * \ingroup common
127  */
128  template <typename PointT> inline void
129  getMinMax3D (const pcl::PointCloud<PointT> &cloud, const std::vector<int> &indices,
130  Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
131 
132  /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud
133  * \param cloud the point cloud data message
134  * \param indices the vector of point indices to use from \a cloud
135  * \param min_pt the resultant minimum bounds
136  * \param max_pt the resultant maximum bounds
137  * \ingroup common
138  */
139  template <typename PointT> inline void
140  getMinMax3D (const pcl::PointCloud<PointT> &cloud, const pcl::PointIndices &indices,
141  Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
142 
143  /** \brief Compute the radius of a circumscribed circle for a triangle formed of three points pa, pb, and pc
144  * \param pa the first point
145  * \param pb the second point
146  * \param pc the third point
147  * \return the radius of the circumscribed circle
148  * \ingroup common
149  */
150  template <typename PointT> inline double
151  getCircumcircleRadius (const PointT &pa, const PointT &pb, const PointT &pc);
152 
153  /** \brief Get the minimum and maximum values on a point histogram
154  * \param histogram the point representing a multi-dimensional histogram
155  * \param len the length of the histogram
156  * \param min_p the resultant minimum
157  * \param max_p the resultant maximum
158  * \ingroup common
159  */
160  template <typename PointT> inline void
161  getMinMax (const PointT &histogram, int len, float &min_p, float &max_p);
162 
163  /** \brief Calculate the area of a polygon given a point cloud that defines the polygon
164  * \param polygon point cloud that contains those vertices that comprises the polygon. Vertices are stored in counterclockwise.
165  * \return the polygon area
166  * \ingroup common
167  */
168  template<typename PointT> inline float
170 
171  /** \brief Get the minimum and maximum values on a point histogram
172  * \param cloud the cloud containing multi-dimensional histograms
173  * \param idx point index representing the histogram that we need to compute min/max for
174  * \param field_name the field name containing the multi-dimensional histogram
175  * \param min_p the resultant minimum
176  * \param max_p the resultant maximum
177  * \ingroup common
178  */
179  PCL_EXPORTS void
180  getMinMax (const pcl::PCLPointCloud2 &cloud, int idx, const std::string &field_name,
181  float &min_p, float &max_p);
182 
183  /** \brief Compute both the mean and the standard deviation of an array of values
184  * \param values the array of values
185  * \param mean the resultant mean of the distribution
186  * \param stddev the resultant standard deviation of the distribution
187  * \ingroup common
188  */
189  PCL_EXPORTS void
190  getMeanStdDev (const std::vector<float> &values, double &mean, double &stddev);
191 
192 }
193 /*@}*/
194 #include <pcl/common/impl/common.hpp>
195 
196 #endif //#ifndef PCL_COMMON_H_
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:212
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:57
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:116
double getAngle3D(const Eigen::Vector4f &v1, const Eigen::Vector4f &v2)
Compute the smallest angle between two vectors in the [ 0, PI ) interval in 3D.
Definition: common.hpp:46
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:360
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.
A point structure representing Euclidean xyz coordinates, and the RGB color.
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:377
float calculatePolygonArea(const pcl::PointCloud< PointT > &polygon)
Calculate the area of a polygon given a point cloud that defines the polygon.
Definition: common.hpp:391
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:73