Skip to content

Commit

Permalink
added explicit code for PointXYZRGBA instantiations
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://svn.pointclouds.org/pcl/trunk@4212 a9d63959-f2ad-4865-b262-bf0e56cfafb6
  • Loading branch information
rbrusu committed Feb 3, 2012
1 parent 8888caf commit 4d3cb8c
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 86 deletions.
2 changes: 1 addition & 1 deletion surface/src/organized_fast_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))

143 changes: 76 additions & 67 deletions tracking/include/pcl/tracking/hsv_color_coherence.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,73 +16,82 @@ namespace pcl
template <typename PointInT>
class HSVColorCoherence: public PointCoherence<PointInT>
{
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<PointInT> ()
, 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<PointInT> ()
, 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_;

};
}
}

Expand Down
71 changes: 54 additions & 17 deletions tracking/include/pcl/tracking/impl/hsv_color_coherence.hpp
Original file line number Diff line number Diff line change
@@ -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_

Expand All @@ -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
Expand Down Expand Up @@ -67,35 +107,36 @@ namespace pcl
int vmin = b, diff;
int vr, vg;

v = std::max<int>(v, g);
v = std::max<int>(v, r);
vmin = std::min<int>(vmin, g);
vmin = std::min<int>(vmin, r);
v = std::max<int> (v, g);
v = std::max<int> (v, r);
vmin = std::min<int> (vmin, g);
vmin = std::min<int> (vmin, r);

diff = v - vmin;
vr = v == r ? -1 : 0;
vg = v == g ? -1 : 0;

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 <typename PointInT> double
HSVColorCoherence<PointInT>::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,
Expand All @@ -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));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tracking/src/hsv_color_coherence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));

0 comments on commit 4d3cb8c

Please sign in to comment.