pfhrgb.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2011, Alexandru-Eugen Ichim
00005  *                      Willow Garage, Inc
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/or other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of Willow Garage, Inc. nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  *  $Id: pfhrgb.cpp 6144 2012-07-04 22:06:28Z rusu $
00036  */
00037 
00038 #include <pcl/point_types.h>
00039 #include <pcl/impl/instantiate.hpp>
00040 #include <pcl/features/pfhrgb.h>
00041 #include <pcl/features/impl/pfhrgb.hpp>
00042 
00044 bool
00045 pcl::computeRGBPairFeatures (const Eigen::Vector4f &p1, const Eigen::Vector4f &n1, const Eigen::Vector4i &colors1,
00046                              const Eigen::Vector4f &p2, const Eigen::Vector4f &n2, const Eigen::Vector4i &colors2,
00047                              float &f1, float &f2, float &f3, float &f4, float &f5, float &f6, float &f7)
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 ("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   f3 = angle1;
00066 
00067   // Create a Darboux frame coordinate system u-v-w
00068   // u = n1; v = (p_idx - q_idx) x u / || (p_idx - q_idx) x u ||; w = u x v
00069   Eigen::Vector4f v = dp2p1.cross3 (n1_copy);
00070   v[3] = 0.0f;
00071   float v_norm = v.norm ();
00072   if (v_norm == 0.0f)
00073   {
00074     PCL_DEBUG ("Norm of Delta x U is 0!\n");
00075     f1 = f2 = f3 = f4 = 0.0f;
00076     return (false);
00077   }
00078   // Normalize v
00079   v /= v_norm;
00080 
00081   Eigen::Vector4f w = n1_copy.cross3 (v);
00082   // Do not have to normalize w - it is a unit vector by construction
00083 
00084   v[3] = 0.0f;
00085   f2 = v.dot (n2_copy);
00086   w[3] = 0.0f;
00087   // Compute f1 = arctan (w * n2, u * n2) i.e. angle of n2 in the x=u, y=w coordinate system
00088   f1 = atan2f (w.dot (n2_copy), n1_copy.dot (n2_copy)); // @todo optimize this
00089 
00090   // everything before was standard 4D-Darboux frame feature pair
00091   // now, for the experimental color stuff
00092   f5 = (colors2[0] != 0) ? static_cast<float> (colors1[0] / colors2[0]) : 1.0f;
00093   f6 = (colors2[1] != 0) ? static_cast<float> (colors1[1] / colors2[1]) : 1.0f;
00094   f7 = (colors2[2] != 0) ? static_cast<float> (colors1[2] / colors2[2]) : 1.0f;
00095 
00096   // make sure the ratios are in the [-1, 1] interval
00097   if (f5 > 1.0f) f5 = - 1.0f / f5;
00098   if (f6 > 1.0f) f6 = - 1.0f / f6;
00099   if (f7 > 1.0f) f7 = - 1.0f / f7;
00100 
00101   return (true);
00102 }
00103 
00104 // Instantiations of specific point types
00105 #ifdef PCL_ONLY_CORE_POINT_TYPES
00106   PCL_INSTANTIATE_PRODUCT(PFHRGBEstimation, ((pcl::PointXYZRGBA)(pcl::PointXYZRGB)(pcl::PointXYZRGBNormal))
00107                           ((pcl::Normal)(pcl::PointXYZRGBNormal))
00108                           ((pcl::PFHRGBSignature250)))
00109 #else
00110   PCL_INSTANTIATE_PRODUCT(PFHRGBEstimation, ((pcl::PointXYZRGB)(pcl::PointXYZRGBA)(pcl::PointXYZRGBNormal))
00111                           (PCL_NORMAL_POINT_TYPES)
00112                           ((pcl::PFHRGBSignature250)))
00113 #endif


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:16:31