Point Cloud Library (PCL)  1.11.1-dev
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 #pragma once
39 
40 #include <pcl/point_cloud.h> // for PointCloud
41 #include <pcl/PointIndices.h> // for PointIndices
42 namespace pcl { struct PCLPointCloud2; }
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 #ifdef __SSE__
74  /** \brief Compute the approximate arccosine of four values at once using SSE instructions.
75  *
76  * The approximation used is \f$ (1.59121552+x*(-0.15461442+x*0.05354897))*\sqrt{0.89286965-0.89282669*x}+0.06681017+x*(-0.09402311+x*0.02708663) \f$.
77  * The average error is 0.00012 rad. This approximation is more accurate than other approximations of acos, but also uses a few more operations.
78  * \param x four floats, each should be in [0; 1]. They must not be greater than 1 since acos is undefined there.
79  * They should not be less than 0 because there the approximation is less precise
80  * \return the four arccosines, each in [0; pi/2]
81  * \ingroup common
82  */
83  inline __m128
84  acos_SSE (const __m128 &x);
85 
86  /** \brief Similar to getAngle3D, but four times in parallel using SSE instructions.
87  *
88  * This behaves like \f$ min(getAngle3D(dot_product), \pi-getAngle3D(dot_product)) \f$.
89  * All vectors must be normalized (length is 1.0).
90  * Since an approximate acos is used, the results may be slightly imprecise.
91  * \param[in] the x components of the first four vectors
92  * \param[in] the y components of the first four vectors
93  * \param[in] the z components of the first four vectors
94  * \param[in] the x components of the second four vectors
95  * \param[in] the y components of the second four vectors
96  * \param[in] the z components of the second four vectors
97  * \return the four angles in radians in [0; pi/2]
98  * \ingroup common
99  */
100  inline __m128
101  getAcuteAngle3DSSE (const __m128 &x1, const __m128 &y1, const __m128 &z1, const __m128 &x2, const __m128 &y2, const __m128 &z2);
102 #endif // ifdef __SSE__
103 
104 #ifdef __AVX__
105  /** \brief Compute the approximate arccosine of eight values at once using AVX instructions.
106  *
107  * The approximation used is \f$ (1.59121552+x*(-0.15461442+x*0.05354897))*\sqrt{0.89286965-0.89282669*x}+0.06681017+x*(-0.09402311+x*0.02708663) \f$.
108  * The average error is 0.00012 rad. This approximation is more accurate than other approximations of acos, but also uses a few more operations.
109  * \param x eight floats, each should be in [0; 1]. They must not be greater than 1 since acos is undefined there.
110  * They should not be less than 0 because there the approximation is less precise
111  * \return the eight arccosines, each in [0; pi/2]
112  * \ingroup common
113  */
114  inline __m256
115  acos_AVX (const __m256 &x);
116 
117  /** \brief Similar to getAngle3D, but eight times in parallel using AVX instructions.
118  *
119  * This behaves like \f$ min(getAngle3D(dot_product), \pi-getAngle3D(dot_product)) \f$.
120  * All vectors must be normalized (length is 1.0).
121  * Since an approximate acos is used, the results may be slightly imprecise.
122  * \param[in] the x components of the first eight vectors
123  * \param[in] the y components of the first eight vectors
124  * \param[in] the z components of the first eight vectors
125  * \param[in] the x components of the second eight vectors
126  * \param[in] the y components of the second eight vectors
127  * \param[in] the z components of the second eight vectors
128  * \return the eight angles in radians in [0; pi/2]
129  * \ingroup common
130  */
131  inline __m256
132  getAcuteAngle3DAVX (const __m256 &x1, const __m256 &y1, const __m256 &z1, const __m256 &x2, const __m256 &y2, const __m256 &z2);
133 #endif // ifdef __AVX__
134 
135  /** \brief Compute both the mean and the standard deviation of an array of values
136  * \param values the array of values
137  * \param mean the resultant mean of the distribution
138  * \param stddev the resultant standard deviation of the distribution
139  * \ingroup common
140  */
141  inline void
142  getMeanStd (const std::vector<float> &values, double &mean, double &stddev);
143 
144  /** \brief Get a set of points residing in a box given its bounds
145  * \param cloud the point cloud data message
146  * \param min_pt the minimum bounds
147  * \param max_pt the maximum bounds
148  * \param indices the resultant set of point indices residing in the box
149  * \ingroup common
150  */
151  template <typename PointT> inline void
152  getPointsInBox (const pcl::PointCloud<PointT> &cloud, Eigen::Vector4f &min_pt,
153  Eigen::Vector4f &max_pt, Indices &indices);
154 
155  /** \brief Get the point at maximum distance from a given point and a given pointcloud
156  * \param cloud the point cloud data message
157  * \param pivot_pt the point from where to compute the distance
158  * \param max_pt the point in cloud that is the farthest point away from pivot_pt
159  * \ingroup common
160  */
161  template<typename PointT> inline void
162  getMaxDistance (const pcl::PointCloud<PointT> &cloud, const Eigen::Vector4f &pivot_pt, Eigen::Vector4f &max_pt);
163 
164  /** \brief Get the point at maximum distance from a given point and a given pointcloud
165  * \param cloud the point cloud data message
166  * \param indices the vector of point indices to use from \a cloud
167  * \param pivot_pt the point from where to compute the distance
168  * \param max_pt the point in cloud that is the farthest point away from pivot_pt
169  * \ingroup common
170  */
171  template<typename PointT> inline void
172  getMaxDistance (const pcl::PointCloud<PointT> &cloud, const Indices &indices,
173  const Eigen::Vector4f &pivot_pt, Eigen::Vector4f &max_pt);
174 
175  /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud
176  * \param[in] cloud the point cloud data message
177  * \param[out] min_pt the resultant minimum bounds
178  * \param[out] max_pt the resultant maximum bounds
179  * \ingroup common
180  */
181  template <typename PointT> inline void
182  getMinMax3D (const pcl::PointCloud<PointT> &cloud, PointT &min_pt, PointT &max_pt);
183 
184  /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud
185  * \param[in] cloud the point cloud data message
186  * \param[out] min_pt the resultant minimum bounds
187  * \param[out] max_pt the resultant maximum bounds
188  * \ingroup common
189  */
190  template <typename PointT> inline void
191  getMinMax3D (const pcl::PointCloud<PointT> &cloud,
192  Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
193 
194  /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud
195  * \param[in] cloud the point cloud data message
196  * \param[in] indices the vector of point indices to use from \a cloud
197  * \param[out] min_pt the resultant minimum bounds
198  * \param[out] max_pt the resultant maximum bounds
199  * \ingroup common
200  */
201  template <typename PointT> inline void
202  getMinMax3D (const pcl::PointCloud<PointT> &cloud, const Indices &indices,
203  Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
204 
205  /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud
206  * \param[in] cloud the point cloud data message
207  * \param[in] indices the vector of point indices to use from \a cloud
208  * \param[out] min_pt the resultant minimum bounds
209  * \param[out] max_pt the resultant maximum bounds
210  * \ingroup common
211  */
212  template <typename PointT> inline void
213  getMinMax3D (const pcl::PointCloud<PointT> &cloud, const pcl::PointIndices &indices,
214  Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
215 
216  /** \brief Compute the radius of a circumscribed circle for a triangle formed of three points pa, pb, and pc
217  * \param pa the first point
218  * \param pb the second point
219  * \param pc the third point
220  * \return the radius of the circumscribed circle
221  * \ingroup common
222  */
223  template <typename PointT> inline double
224  getCircumcircleRadius (const PointT &pa, const PointT &pb, const PointT &pc);
225 
226  /** \brief Get the minimum and maximum values on a point histogram
227  * \param histogram the point representing a multi-dimensional histogram
228  * \param len the length of the histogram
229  * \param min_p the resultant minimum
230  * \param max_p the resultant maximum
231  * \ingroup common
232  */
233  template <typename PointT> inline void
234  getMinMax (const PointT &histogram, int len, float &min_p, float &max_p);
235 
236  /** \brief Calculate the area of a polygon given a point cloud that defines the polygon
237  * \param polygon point cloud that contains those vertices that comprises the polygon. Vertices are stored in counterclockwise.
238  * \return the polygon area
239  * \ingroup common
240  */
241  template<typename PointT> inline float
243 
244  /** \brief Get the minimum and maximum values on a point histogram
245  * \param cloud the cloud containing multi-dimensional histograms
246  * \param idx point index representing the histogram that we need to compute min/max for
247  * \param field_name the field name containing the multi-dimensional histogram
248  * \param min_p the resultant minimum
249  * \param max_p the resultant maximum
250  * \ingroup common
251  */
252  PCL_EXPORTS void
253  getMinMax (const pcl::PCLPointCloud2 &cloud, int idx, const std::string &field_name,
254  float &min_p, float &max_p);
255 
256  /** \brief Compute both the mean and the standard deviation of an array of values
257  * \param values the array of values
258  * \param mean the resultant mean of the distribution
259  * \param stddev the resultant standard deviation of the distribution
260  * \ingroup common
261  */
262  PCL_EXPORTS void
263  getMeanStdDev (const std::vector<float> &values, double &mean, double &stddev);
264 
265 }
266 /*@}*/
267 #include <pcl/common/impl/common.hpp>
pcl
Definition: convolution.h:46
pcl::getPointsInBox
void getPointsInBox(const pcl::PointCloud< PointT > &cloud, Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt, Indices &indices)
Get a set of points residing in a box given its bounds.
Definition: common.hpp:154
pcl::getMeanStd
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:124
pcl::getCircumcircleRadius
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:443
pcl::getMeanStdDev
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.
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: distances.h:55
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:628
pcl::getAngle3D
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:47
pcl::calculatePolygonArea
float calculatePolygonArea(const pcl::PointCloud< PointT > &polygon)
Calculate the area of a polygon given a point cloud that defines the polygon.
Definition: common.hpp:474
pcl::getMaxDistance
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:197
pcl::PointIndices
Definition: PointIndices.h:11
pcl::Indices
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:131
pcl::PCLPointCloud2
Definition: PCLPointCloud2.h:16
pcl::getMinMax3D
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:295
pcl::getMinMax
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:460
PCL_EXPORTS
#define PCL_EXPORTS
Definition: pcl_macros.h:323