From 4d3cb8c30ffe3103e2118dc8e1c31384494206f1 Mon Sep 17 00:00:00 2001 From: "Radu B. Rusu" Date: Fri, 3 Feb 2012 05:48:18 +0000 Subject: [PATCH] added explicit code for PointXYZRGBA instantiations git-svn-id: svn+ssh://svn.pointclouds.org/pcl/trunk@4212 a9d63959-f2ad-4865-b262-bf0e56cfafb6 --- surface/src/organized_fast_mesh.cpp | 2 +- .../pcl/tracking/hsv_color_coherence.h | 143 ++++++++++-------- .../pcl/tracking/impl/hsv_color_coherence.hpp | 71 ++++++--- tracking/src/hsv_color_coherence.cpp | 2 +- 4 files changed, 132 insertions(+), 86 deletions(-) diff --git a/surface/src/organized_fast_mesh.cpp b/surface/src/organized_fast_mesh.cpp index ee76df3292d..a7c673e4d78 100644 --- a/surface/src/organized_fast_mesh.cpp +++ b/surface/src/organized_fast_mesh.cpp @@ -40,5 +40,5 @@ #include "pcl/point_types.h" // Instantiations of specific point types -PCL_INSTANTIATE(OrganizedFastMesh, (pcl::PointXYZ)(pcl::PointXYZRGB)) +PCL_INSTANTIATE(OrganizedFastMesh, (pcl::PointXYZ)(pcl::PointXYZRGB)(pcl::PointXYZRGBA)) diff --git a/tracking/include/pcl/tracking/hsv_color_coherence.h b/tracking/include/pcl/tracking/hsv_color_coherence.h index 70ab0ae1711..3b2e9bce7df 100644 --- a/tracking/include/pcl/tracking/hsv_color_coherence.h +++ b/tracking/include/pcl/tracking/hsv_color_coherence.h @@ -16,73 +16,82 @@ namespace pcl template class HSVColorCoherence: public PointCoherence { - public: - - /** \brief initialize the weights of the computation. - weight_, h_weight_, s_weight_ default to 1.0 and - v_weight_ defaults to 0.0. - */ - HSVColorCoherence () - : PointCoherence () - , weight_ (1.0) - , h_weight_ (1.0) - , s_weight_ (1.0) - , v_weight_ (0.0) - {} - - /** \brief set the weight of coherence - * \param weight the weight of coherence. - */ - inline void setWeight (double weight) { weight_ = weight; } - - /** \brief get the weight (w) of coherence */ - inline double getWeight () { return weight_; } - - /** \brief set the hue weight (w_h) of coherence - * \param weight the hue weight (w_h) of coherence. - */ - inline void setHWeight (double weight) { h_weight_ = weight; } - - /** \brief get the hue weight (w_h) of coherence */ - inline double getHWeight () { return h_weight_; } - - /** \brief set the saturation weight (w_s) of coherence - * \param weight the saturation weight (w_s) of coherence. - */ - inline void setSWeight (double weight) { s_weight_ = weight; } - - /** \brief get the saturation weight (w_s) of coherence */ - inline double getSWeight () { return s_weight_; } - - /** \brief set the value weight (w_v) of coherence - * \param weight the value weight (w_v) of coherence. - */ - inline void setVWeight (double weight) { v_weight_ = weight; } - - /** \brief get the value weight (w_v) of coherence */ - inline double getVWeight () { return v_weight_; } - - protected: - - /** \brief return the color coherence between the two points. - * \param source instance of source point. - * \param target instance of target point. - */ - double computeCoherence (PointInT &source, PointInT &target); - - /** \brief the weight of coherence (w) */ - double weight_; - - /** \brief the hue weight (w_h) */ - double h_weight_; - - /** \brief the saturation weight (w_s) */ - double s_weight_; - - /** \brief the value weight (w_v) */ - double v_weight_; - - }; + public: + + /** \brief initialize the weights of the computation. + weight_, h_weight_, s_weight_ default to 1.0 and + v_weight_ defaults to 0.0. + */ + HSVColorCoherence () + : PointCoherence () + , weight_ (1.0) + , h_weight_ (1.0) + , s_weight_ (1.0) + , v_weight_ (0.0) + {} + + /** \brief set the weight of coherence + * \param[in] weight the weight of coherence. + */ + inline void + setWeight (double weight) { weight_ = weight; } + + /** \brief get the weight (w) of coherence */ + inline double + getWeight () { return weight_; } + + /** \brief set the hue weight (w_h) of coherence + * \param[in] weight the hue weight (w_h) of coherence. + */ + inline void + setHWeight (double weight) { h_weight_ = weight; } + + /** \brief get the hue weight (w_h) of coherence */ + inline double + getHWeight () { return h_weight_; } + + /** \brief set the saturation weight (w_s) of coherence + * \param[in] weight the saturation weight (w_s) of coherence. + */ + inline void + setSWeight (double weight) { s_weight_ = weight; } + + /** \brief get the saturation weight (w_s) of coherence */ + inline double + getSWeight () { return s_weight_; } + + /** \brief set the value weight (w_v) of coherence + * \param[in] weight the value weight (w_v) of coherence. + */ + inline void + setVWeight (double weight) { v_weight_ = weight; } + + /** \brief get the value weight (w_v) of coherence */ + inline double + getVWeight () { return v_weight_; } + + protected: + + /** \brief return the color coherence between the two points. + * \param[in] source instance of source point. + * \param[in] target instance of target point. + */ + double + computeCoherence (PointInT &source, PointInT &target); + + /** \brief the weight of coherence (w) */ + double weight_; + + /** \brief the hue weight (w_h) */ + double h_weight_; + + /** \brief the saturation weight (w_s) */ + double s_weight_; + + /** \brief the value weight (w_v) */ + double v_weight_; + + }; } } diff --git a/tracking/include/pcl/tracking/impl/hsv_color_coherence.hpp b/tracking/include/pcl/tracking/impl/hsv_color_coherence.hpp index 5694c721899..0af3792da1b 100644 --- a/tracking/include/pcl/tracking/impl/hsv_color_coherence.hpp +++ b/tracking/include/pcl/tracking/impl/hsv_color_coherence.hpp @@ -1,3 +1,41 @@ +/* + * Software License Agreement (BSD License) + * + * Point Cloud Library (PCL) - www.pointclouds.org + * Copyright (c) 2010-2011, Willow Garage, Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Willow Garage, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * $Id: pcl_base.h 4093 2012-01-31 04:54:52Z rusu $ + * + */ #ifndef PCL_TRACKING_IMPL_HSV_COLOR_COHERENCE_H_ #define PCL_TRACKING_IMPL_HSV_COLOR_COHERENCE_H_ @@ -20,7 +58,9 @@ namespace pcl long long_value; } RGBValue; - void RGB2HSV(int r, int g, int b, float& fh, float& fs, float& fv) + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void + RGB2HSV (int r, int g, int b, float& fh, float& fs, float& fv) { // mostly copied from opencv-svn/modules/imgproc/src/color.cpp // revision is 4351 @@ -67,10 +107,10 @@ namespace pcl int vmin = b, diff; int vr, vg; - v = std::max(v, g); - v = std::max(v, r); - vmin = std::min(vmin, g); - vmin = std::min(vmin, r); + v = std::max (v, g); + v = std::max (v, r); + vmin = std::min (vmin, g); + vmin = std::min (vmin, r); diff = v - vmin; vr = v == r ? -1 : 0; @@ -78,24 +118,25 @@ namespace pcl s = diff * div_table[v] >> hsv_shift; h = (vr & (g - b)) + - (~vr & ((vg & (b - r + 2 * diff)) - + ((~vg) & (r - g + 4 * diff)))); + (~vr & ((vg & (b - r + 2 * diff)) + + ((~vg) & (r - g + 4 * diff)))); h = (h * div_table[diff] * hscale + - (1 << (hsv_shift + 6))) >> (7 + hsv_shift); + (1 << (hsv_shift + 6))) >> (7 + hsv_shift); h += h < 0 ? hr : 0; fh = h / 180.0; fs = s / 255.0; fv = v / 255.0; } - + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template double HSVColorCoherence::computeCoherence (PointInT &source, PointInT &target) { // convert color space from RGB to HSV RGBValue source_rgb, target_rgb; - source_rgb.float_value = (source.rgb); - target_rgb.float_value = (target.rgb); + source_rgb.float_value = source.rgba; + target_rgb.float_value = target.rgba; float source_h, source_s, source_v, target_h, target_s, target_v; RGB2HSV (source_rgb.Red, source_rgb.Blue, source_rgb.Green, @@ -105,20 +146,16 @@ namespace pcl // hue value is in 0 ~ 2pi, but circulated. const float _h_diff = fabs (source_h - target_h); float h_diff; - if ( _h_diff > 0.5) - { + if (_h_diff > 0.5) h_diff = h_weight_ * (_h_diff - 0.5) * (_h_diff - 0.5); - } else - { h_diff = h_weight_ * _h_diff * _h_diff; - } const float s_diff = s_weight_ * (source_s - target_s) * (source_s - target_s); const float v_diff = v_weight_ * (source_v - target_v) * (source_v - target_v); const float diff2 = h_diff + s_diff + v_diff; - return 1.0 / (1.0 + weight_ * diff2); + return (1.0 / (1.0 + weight_ * diff2)); } } } diff --git a/tracking/src/hsv_color_coherence.cpp b/tracking/src/hsv_color_coherence.cpp index 2b35588227b..e0677cbb19e 100644 --- a/tracking/src/hsv_color_coherence.cpp +++ b/tracking/src/hsv_color_coherence.cpp @@ -5,4 +5,4 @@ #include "pcl/tracking/hsv_color_coherence.h" #include "pcl/tracking/impl/hsv_color_coherence.hpp" -PCL_INSTANTIATE_PRODUCT(HSVColorCoherence, ((pcl::PointXYZRGB) (pcl::PointXYZRGBNormal))); +PCL_INSTANTIATE_PRODUCT(HSVColorCoherence, ((pcl::PointXYZRGB)(pcl::PointXYZRGBNormal)(pcl::PointXYZRGBA)));