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