edge_weight_computer_terms.h
Go to the documentation of this file.
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2014-, Open Perception, Inc.
6 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 * * Neither the name of the copyright holder(s) nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 *
36 */
37
38#ifndef PCL_GRAPH_EDGE_WEIGHT_COMPUTER_TERMS_H
39#define PCL_GRAPH_EDGE_WEIGHT_COMPUTER_TERMS_H
40
41#include <pcl/point_types.h>
42
44{
45
46 /** Squared Euclidean distance between points.
47 *
48 * \f[
49 * d_{xyz}(v_i,v_j) = ||p_i-p_j||^2
50 * \f]
51 *
52 * Requires that the point type has *x*, *y*, and *z* fields.
53 *
54 * \ingroup graph
55 * \author Sergey Alexandrov
56 */
57 struct XYZ
58 {
59 typedef pcl::traits::has_xyz<boost::mpl::_1> is_compatible;
60
61 template <typename PointT>
62 float static compute(const PointT& p1, const PointT& p2)
63 {
64 return (p2.getVector3fMap() - p1.getVector3fMap()).squaredNorm();
65 }
66 };
67
68 /** Angular distance between normals.
69 *
70 * \f[
71 * d_{normal}(v_i,v_j) = \frac{||n_i-n_j||^2}{2}
72 * \f]
73 *
74 * Requires that the point type has *normal_x*, *normal_y*, and
75 * *normal_z* fields.
76 *
77 * \ingroup graph
78 * \author Sergey Alexandrov
79 */
80 struct Normal
81 {
82 typedef pcl::traits::has_normal<boost::mpl::_1> is_compatible;
83
84 template <typename PointT>
85 float static compute(const PointT& p1, const PointT& p2)
86 {
87 return (0.5 * (p1.getNormalVector3fMap() - p2.getNormalVector3fMap()).squaredNorm());
88 }
89 };
90
91 /** Product of curvatures.
92 *
93 * \f[
94 * d_{curvature}(v_i,v_j) = c_i \cdot c_j
95 * \f]
96 *
97 * Requires that the point type has *curvature* field.
98 *
99 * \ingroup graph
100 * \author Sergey Alexandrov
101 */
103 {
104 typedef pcl::traits::has_curvature<boost::mpl::_1> is_compatible;
105
106 template <typename PointT>
107 float static compute(const PointT& p1, const PointT& p2)
108 {
109 return (std::fabs(p1.curvature) * std::fabs(p2.curvature));
110 }
111 };
112
113 /** Squared Euclidean distance in RGB space.
114 *
115 * \f[
116 * d_{xyz}(v_i,v_j) = ||rgb_i-rgb_j||^2
117 * \f]
118 *
119 * Requires that the point type has *rgb* or *rgba* field.
120 *
121 * \ingroup graph
122 * \author Sergey Alexandrov
123 */
124 struct RGB
125 {
126 typedef pcl::traits::has_color<boost::mpl::_1> is_compatible;
127
128 template <typename PointT>
129 float static compute(const PointT& p1, const PointT& p2)
130 {
131 return ((p1.getBGRVector3cMap().template cast<float>() -
132 p2.getBGRVector3cMap().template cast<float>())
133 .norm() /
134 255.0f);
135 }
136 };
137
138} // namespace pcl::graph::terms
139
140
141#endif /* PCL_GRAPH_EDGE_WEIGHT_COMPUTER_TERMS_H */
pcl::traits::has_curvature< boost::mpl::_1 > is_compatible
static float compute(const PointT &p1, const PointT &p2)
Angular distance between normals.
pcl::traits::has_normal< boost::mpl::_1 > is_compatible
static float compute(const PointT &p1, const PointT &p2)
Squared Euclidean distance in RGB space.
pcl::traits::has_color< boost::mpl::_1 > is_compatible
static float compute(const PointT &p1, const PointT &p2)
Squared Euclidean distance between points.
pcl::traits::has_xyz< boost::mpl::_1 > is_compatible
static float compute(const PointT &p1, const PointT &p2)