pfh.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2010-2012, Willow Garage, Inc.
00006  *  Copyright (c) 2012-, Open Perception, Inc.
00007  *
00008  *  All rights reserved.
00009  *
00010  *  Redistribution and use in source and binary forms, with or without
00011  *  modification, are permitted provided that the following conditions
00012  *  are met:
00013  *
00014  *   * Redistributions of source code must retain the above copyright
00015  *     notice, this list of conditions and the following disclaimer.
00016  *   * Redistributions in binary form must reproduce the above
00017  *     copyright notice, this list of conditions and the following
00018  *     disclaimer in the documentation and/or other materials provided
00019  *     with the distribution.
00020  *   * Neither the name of the copyright holder(s) nor the names of its
00021  *     contributors may be used to endorse or promote products derived
00022  *     from this software without specific prior written permission.
00023  *
00024  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00031  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035  *  POSSIBILITY OF SUCH DAMAGE.
00036  *
00037  */
00038 
00039 #include <pcl/features/pfh_tools.h>
00040 #include <pcl/features/impl/pfh.hpp>
00041 #include <pcl/features/impl/pfhrgb.hpp>
00042 
00044 bool
00045 pcl::computePairFeatures (const Eigen::Vector4f &p1, const Eigen::Vector4f &n1, 
00046                           const Eigen::Vector4f &p2, const Eigen::Vector4f &n2,
00047                           float &f1, float &f2, float &f3, float &f4)
00048 {
00049   Eigen::Vector4f dp2p1 = p2 - p1;
00050   dp2p1[3] = 0.0f;
00051   f4 = dp2p1.norm ();
00052 
00053   if (f4 == 0.0f)
00054   {
00055     PCL_DEBUG ("[pcl::computePairFeatures] Euclidean distance between points is 0!\n");
00056     f1 = f2 = f3 = f4 = 0.0f;
00057     return (false);
00058   }
00059 
00060   Eigen::Vector4f n1_copy = n1,
00061                   n2_copy = n2;
00062   n1_copy[3] = n2_copy[3] = 0.0f;
00063   float angle1 = n1_copy.dot (dp2p1) / f4;
00064 
00065   // Make sure the same point is selected as 1 and 2 for each pair
00066   float angle2 = n2_copy.dot (dp2p1) / f4;
00067   if (acos (fabs (angle1)) > acos (fabs (angle2)))
00068   {
00069     // switch p1 and p2
00070     n1_copy = n2;
00071     n2_copy = n1;
00072     n1_copy[3] = n2_copy[3] = 0.0f;
00073     dp2p1 *= (-1);
00074     f3 = -angle2;
00075   }
00076   else
00077     f3 = angle1;
00078 
00079   // Create a Darboux frame coordinate system u-v-w
00080   // u = n1; v = (p_idx - q_idx) x u / || (p_idx - q_idx) x u ||; w = u x v
00081   Eigen::Vector4f v = dp2p1.cross3 (n1_copy);
00082   v[3] = 0.0f;
00083   float v_norm = v.norm ();
00084   if (v_norm == 0.0f)
00085   {
00086     PCL_DEBUG ("[pcl::computePairFeatures] Norm of Delta x U is 0!\n");
00087     f1 = f2 = f3 = f4 = 0.0f;
00088     return (false);
00089   }
00090   // Normalize v
00091   v /= v_norm;
00092 
00093   Eigen::Vector4f w = n1_copy.cross3 (v);
00094   // Do not have to normalize w - it is a unit vector by construction
00095 
00096   v[3] = 0.0f;
00097   f2 = v.dot (n2_copy);
00098   w[3] = 0.0f;
00099   // Compute f1 = arctan (w * n2, u * n2) i.e. angle of n2 in the x=u, y=w coordinate system
00100   f1 = atan2f (w.dot (n2_copy), n1_copy.dot (n2_copy)); // @todo optimize this
00101 
00102   return (true);
00103 }
00104 
00106 bool
00107 pcl::computeRGBPairFeatures (const Eigen::Vector4f &p1, const Eigen::Vector4f &n1, const Eigen::Vector4i &colors1,
00108                              const Eigen::Vector4f &p2, const Eigen::Vector4f &n2, const Eigen::Vector4i &colors2,
00109                              float &f1, float &f2, float &f3, float &f4, float &f5, float &f6, float &f7)
00110 {
00111   Eigen::Vector4f dp2p1 = p2 - p1;
00112   dp2p1[3] = 0.0f;
00113   f4 = dp2p1.norm ();
00114 
00115   if (f4 == 0.0f)
00116   {
00117     PCL_DEBUG ("Euclidean distance between points is 0!\n");
00118     f1 = f2 = f3 = f4 = 0.0f;
00119     return (false);
00120   }
00121 
00122   Eigen::Vector4f n1_copy = n1,
00123       n2_copy = n2;
00124   n1_copy[3] = n2_copy[3] = 0.0f;
00125   float angle1 = n1_copy.dot (dp2p1) / f4;
00126 
00127   f3 = angle1;
00128 
00129   // Create a Darboux frame coordinate system u-v-w
00130   // u = n1; v = (p_idx - q_idx) x u / || (p_idx - q_idx) x u ||; w = u x v
00131   Eigen::Vector4f v = dp2p1.cross3 (n1_copy);
00132   v[3] = 0.0f;
00133   float v_norm = v.norm ();
00134   if (v_norm == 0.0f)
00135   {
00136     PCL_DEBUG ("Norm of Delta x U is 0!\n");
00137     f1 = f2 = f3 = f4 = 0.0f;
00138     return (false);
00139   }
00140   // Normalize v
00141   v /= v_norm;
00142 
00143   Eigen::Vector4f w = n1_copy.cross3 (v);
00144   // Do not have to normalize w - it is a unit vector by construction
00145 
00146   v[3] = 0.0f;
00147   f2 = v.dot (n2_copy);
00148   w[3] = 0.0f;
00149   // Compute f1 = arctan (w * n2, u * n2) i.e. angle of n2 in the x=u, y=w coordinate system
00150   f1 = atan2f (w.dot (n2_copy), n1_copy.dot (n2_copy)); // @todo optimize this
00151 
00152   // everything before was standard 4D-Darboux frame feature pair
00153   // now, for the experimental color stuff
00154   f5 = (colors2[0] != 0) ? static_cast<float> (colors1[0] / colors2[0]) : 1.0f;
00155   f6 = (colors2[1] != 0) ? static_cast<float> (colors1[1] / colors2[1]) : 1.0f;
00156   f7 = (colors2[2] != 0) ? static_cast<float> (colors1[2] / colors2[2]) : 1.0f;
00157 
00158   // make sure the ratios are in the [-1, 1] interval
00159   if (f5 > 1.0f) f5 = - 1.0f / f5;
00160   if (f6 > 1.0f) f6 = - 1.0f / f6;
00161   if (f7 > 1.0f) f7 = - 1.0f / f7;
00162 
00163   return (true);
00164 }
00165 
00166 #ifndef PCL_NO_PRECOMPILE
00167 #include <pcl/point_types.h>
00168 #include <pcl/impl/instantiate.hpp>
00169 // Instantiations of specific point types
00170 #ifdef PCL_ONLY_CORE_POINT_TYPES
00171   PCL_INSTANTIATE_PRODUCT(PFHEstimation, ((pcl::PointXYZ)(pcl::PointXYZI)(pcl::PointXYZRGB)(pcl::PointXYZRGBA))((pcl::Normal))((pcl::PFHSignature125)))
00172   PCL_INSTANTIATE_PRODUCT(PFHRGBEstimation, ((pcl::PointXYZRGBA)(pcl::PointXYZRGB)(pcl::PointXYZRGBNormal))
00173                           ((pcl::Normal)(pcl::PointXYZRGBNormal))
00174                           ((pcl::PFHRGBSignature250)))
00175 #else
00176   PCL_INSTANTIATE_PRODUCT(PFHEstimation, (PCL_XYZ_POINT_TYPES)(PCL_NORMAL_POINT_TYPES)((pcl::PFHSignature125)))
00177   PCL_INSTANTIATE_PRODUCT(PFHRGBEstimation, ((pcl::PointXYZRGB)(pcl::PointXYZRGBA)(pcl::PointXYZRGBNormal))
00178                           (PCL_NORMAL_POINT_TYPES)
00179                           ((pcl::PFHRGBSignature250)))
00180 #endif
00181 #endif    // PCL_NO_PRECOMPILE
00182 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:28:14