Point Cloud Library (PCL)  1.7.0
/tmp/buildd/pcl-1.7-1.7.0/common/include/pcl/common/common.h
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the copyright holder(s) nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * $Id$
00035  *
00036  */
00037 
00038 #ifndef PCL_COMMON_H_
00039 #define PCL_COMMON_H_
00040 
00041 #include <pcl/pcl_base.h>
00042 #include <cfloat>
00043 
00044 /**
00045   * \file pcl/common/common.h
00046   * Define standard C methods and C++ classes that are common to all methods
00047   * \ingroup common
00048   */
00049 
00050 /*@{*/
00051 namespace pcl
00052 {
00053   /** \brief Compute the smallest angle between two vectors in the [ 0, PI ) interval in 3D.
00054     * \param v1 the first 3D vector (represented as a \a Eigen::Vector4f)
00055     * \param v2 the second 3D vector (represented as a \a Eigen::Vector4f)
00056     * \return the angle between v1 and v2
00057     * \ingroup common
00058     */
00059   inline double 
00060   getAngle3D (const Eigen::Vector4f &v1, const Eigen::Vector4f &v2);
00061 
00062   /** \brief Compute both the mean and the standard deviation of an array of values
00063     * \param values the array of values
00064     * \param mean the resultant mean of the distribution
00065     * \param stddev the resultant standard deviation of the distribution
00066     * \ingroup common
00067     */
00068   inline void 
00069   getMeanStd (const std::vector<float> &values, double &mean, double &stddev);
00070 
00071   /** \brief Get a set of points residing in a box given its bounds
00072     * \param cloud the point cloud data message
00073     * \param min_pt the minimum bounds
00074     * \param max_pt the maximum bounds
00075     * \param indices the resultant set of point indices residing in the box
00076     * \ingroup common
00077     */
00078   template <typename PointT> inline void 
00079   getPointsInBox (const pcl::PointCloud<PointT> &cloud, Eigen::Vector4f &min_pt,
00080                   Eigen::Vector4f &max_pt, std::vector<int> &indices);
00081 
00082   /** \brief Get the point at maximum distance from a given point and a given pointcloud
00083     * \param cloud the point cloud data message
00084     * \param pivot_pt the point from where to compute the distance
00085     * \param max_pt the point in cloud that is the farthest point away from pivot_pt
00086     * \ingroup common
00087     */
00088   template<typename PointT> inline void
00089   getMaxDistance (const pcl::PointCloud<PointT> &cloud, const Eigen::Vector4f &pivot_pt, Eigen::Vector4f &max_pt);
00090 
00091   /** \brief Get the point at maximum distance from a given point and a given pointcloud
00092     * \param cloud the point cloud data message
00093     * \param pivot_pt the point from where to compute the distance
00094     * \param indices the vector of point indices to use from \a cloud
00095     * \param max_pt the point in cloud that is the farthest point away from pivot_pt
00096     * \ingroup common
00097     */
00098   template<typename PointT> inline void
00099   getMaxDistance (const pcl::PointCloud<PointT> &cloud, const std::vector<int> &indices, 
00100                   const Eigen::Vector4f &pivot_pt, Eigen::Vector4f &max_pt);
00101 
00102   /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud
00103     * \param cloud the point cloud data message
00104     * \param min_pt the resultant minimum bounds
00105     * \param max_pt the resultant maximum bounds
00106     * \ingroup common
00107     */
00108   template <typename PointT> inline void 
00109   getMinMax3D (const pcl::PointCloud<PointT> &cloud, PointT &min_pt, PointT &max_pt);
00110   
00111   /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud
00112     * \param cloud the point cloud data message
00113     * \param min_pt the resultant minimum bounds
00114     * \param max_pt the resultant maximum bounds
00115     * \ingroup common
00116     */
00117   template <typename PointT> inline void 
00118   getMinMax3D (const pcl::PointCloud<PointT> &cloud, 
00119                Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
00120 
00121   /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud
00122     * \param cloud the point cloud data message
00123     * \param indices the vector of point indices to use from \a cloud
00124     * \param min_pt the resultant minimum bounds
00125     * \param max_pt the resultant maximum bounds
00126     * \ingroup common
00127     */
00128   template <typename PointT> inline void 
00129   getMinMax3D (const pcl::PointCloud<PointT> &cloud, const std::vector<int> &indices, 
00130                Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
00131 
00132   /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud
00133     * \param cloud the point cloud data message
00134     * \param indices the vector of point indices to use from \a cloud
00135     * \param min_pt the resultant minimum bounds
00136     * \param max_pt the resultant maximum bounds
00137     * \ingroup common
00138     */
00139   template <typename PointT> inline void 
00140   getMinMax3D (const pcl::PointCloud<PointT> &cloud, const pcl::PointIndices &indices, 
00141                Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
00142 
00143   /** \brief Compute the radius of a circumscribed circle for a triangle formed of three points pa, pb, and pc
00144     * \param pa the first point
00145     * \param pb the second point
00146     * \param pc the third point
00147     * \return the radius of the circumscribed circle
00148     * \ingroup common
00149     */
00150   template <typename PointT> inline double 
00151   getCircumcircleRadius (const PointT &pa, const PointT &pb, const PointT &pc);
00152 
00153   /** \brief Get the minimum and maximum values on a point histogram
00154     * \param histogram the point representing a multi-dimensional histogram
00155     * \param len the length of the histogram
00156     * \param min_p the resultant minimum 
00157     * \param max_p the resultant maximum 
00158     * \ingroup common
00159     */
00160   template <typename PointT> inline void 
00161   getMinMax (const PointT &histogram, int len, float &min_p, float &max_p);
00162 
00163   /** \brief Calculate the area of a polygon given a point cloud that defines the polygon 
00164     * \param polygon point cloud that contains those vertices that comprises the polygon. Vertices are stored in counterclockwise.
00165     * \return the polygon area 
00166     * \ingroup common
00167     */
00168   template<typename PointT> inline float
00169   calculatePolygonArea (const pcl::PointCloud<PointT> &polygon);
00170 
00171   /** \brief Get the minimum and maximum values on a point histogram
00172     * \param cloud the cloud containing multi-dimensional histograms
00173     * \param idx point index representing the histogram that we need to compute min/max for
00174     * \param field_name the field name containing the multi-dimensional histogram
00175     * \param min_p the resultant minimum 
00176     * \param max_p the resultant maximum 
00177     * \ingroup common
00178     */
00179   PCL_EXPORTS void 
00180   getMinMax (const pcl::PCLPointCloud2 &cloud, int idx, const std::string &field_name,
00181              float &min_p, float &max_p);
00182 
00183   /** \brief Compute both the mean and the standard deviation of an array of values
00184     * \param values the array of values
00185     * \param mean the resultant mean of the distribution
00186     * \param stddev the resultant standard deviation of the distribution
00187     * \ingroup common
00188     */
00189   PCL_EXPORTS void
00190   getMeanStdDev (const std::vector<float> &values, double &mean, double &stddev);
00191 
00192 }
00193 /*@}*/
00194 #include <pcl/common/impl/common.hpp>
00195 
00196 #endif  //#ifndef PCL_COMMON_H_