Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
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   
00066   float angle2 = n2_copy.dot (dp2p1) / f4;
00067   if (acos (fabs (angle1)) > acos (fabs (angle2)))
00068   {
00069     
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   
00080   
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   
00091   v /= v_norm;
00092 
00093   Eigen::Vector4f w = n1_copy.cross3 (v);
00094   
00095 
00096   v[3] = 0.0f;
00097   f2 = v.dot (n2_copy);
00098   w[3] = 0.0f;
00099   
00100   f1 = atan2f (w.dot (n2_copy), n1_copy.dot (n2_copy)); 
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   
00130   
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   
00141   v /= v_norm;
00142 
00143   Eigen::Vector4f w = n1_copy.cross3 (v);
00144   
00145 
00146   v[3] = 0.0f;
00147   f2 = v.dot (n2_copy);
00148   w[3] = 0.0f;
00149   
00150   f1 = atan2f (w.dot (n2_copy), n1_copy.dot (n2_copy)); 
00151 
00152   
00153   
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   
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 
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