common.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_COMMON_H
39#define PCL_GRAPH_COMMON_H
40
41#include <boost/ref.hpp>
42
43#include <pcl/PointIndices.h>
44
45namespace pcl::graph
46{
47
48 /** Compute normals and curvatures for all vertices in a graph.
49 *
50 * For each vertex the function finds its 1- or 2-ring neighbors and uses
51 * pcl::computePointNormal() to calculate normal and curvature. It also
52 * flips the calculated normal towards 0,0,0 viewpoint.
53 *
54 * \c Graph has to be a model of concepts::PointCloudGraphConcept.
55 *
56 * \param[in] neighborhood_1ring flag which controls whether 1- or 2- ring
57 * neighborhood is used. Default is 2-ring, which is slower, but produces
58 * smoother normals.
59 *
60 * \author Sergey Alexandrov
61 * \ingroup graph */
62 template <typename Graph>
63 void computeNormalsAndCurvatures(Graph& graph, bool neighborhood_1ring = false);
64
65
66 /** \brief Compute the type of curvature (concave/convex) for each vertex.
67 *
68 * The type of curvature is expressed through the sign. Convex curvature
69 * is positive and concave curvature is negative. The absolute values of
70 * curvatures are not altered by this function.
71 *
72 * TODO: add the formula.
73 *
74 * \c Graph has to be a model of concepts::PointCloudGraphConcept.
75 *
76 * \author Sergey Alexandrov
77 * \ingroup graph */
78 template <typename Graph>
79 void computeSignedCurvatures(Graph& graph);
80
81
82 /** Find connected components in a graph and create a subgraph for each of
83 * them.
84 *
85 * Each created subgraph is filled with the vertices that belong to the
86 * corresponding connected component.
87 *
88 * In order to allow creation of subgraphs, the graph type should be an
89 * instantiation of boost::subgraph template. Note that the graph is
90 * passed by non-const reference, because subgraph creation modifies the
91 * parent graph. Also, note that the created subgraphs are output as
92 * references wrapped with boost::reference_wrapper. The reason is that
93 * the factory function for subgraph creation in BGL returns newly created
94 * subgraphs by reference.
95 *
96 * \param[in] graph an input graph
97 * \param[out] subgraphs a vector of references to created subgraps
98 *
99 * \return the number of connected components
100 *
101 * \author Sergey Alexandrov
102 * \ingroup graph
103 * */
104 template <typename Graph>
105 size_t
107 std::vector<boost::reference_wrapper<Graph>>& subgraphs);
108
109
110 /** Split a given graph into subgraphs based on the values in a given
111 * vertex color map.
112 *
113 * Each created subgraph is filled with the vertices that have the same
114 * color according to the color map. Consequently, the number of created
115 * subgraphs is equal to the number of unique colors in the provided map.
116 * The subgraphs are guaranteed to be sorted in the increasing order of
117 * the color.
118 *
119 * In order to allow creation of subgraphs, the graph type should be an
120 * instantiation of boost::subgraph template. Note that the graph is
121 * passed by non-const reference, because subgraph creation modifies the
122 * parent graph. Also, note that the created subgraphs are output as
123 * references wrapped with boost::reference_wrapper. The reason is that
124 * the factory function for subgraph creation in BGL returns newly created
125 * subgraphs by reference.
126 *
127 * \param[in] graph an input graph
128 * \param[in] color_map a color map that defines vertex colors
129 * \param[out] subgraphs a vector of references to created subgraps
130 *
131 * \return the number of created subgraphs
132 *
133 * \author Sergey Alexandrov
134 * \ingroup graph
135 * */
136 template <typename Graph, typename ColorMap>
138 ColorMap color_map,
139 std::vector<boost::reference_wrapper<Graph>>& subgraphs);
140
141
142 /** Create two subgraphs of a given graph, one containing the points with
143 * the given indices, and the other containing the remaining points.
144 *
145 * In order to allow creation of subgraphs, the graph type should be an
146 * instantiation of boost::subgraph template. Note that the graph is
147 * passed by non-const reference, because subgraph creation modifies the
148 * parent graph. Also, note that the created subgraphs are output as
149 * references wrapped with boost::reference_wrapper. The reason is that
150 * the factory function for subgraph creation in BGL returns newly created
151 * subgraphs by reference.
152 *
153 * \param[in] graph an input graph
154 * \param[in] indices indices of points to be inserted in the first
155 * subgraph
156 * \param[out] subgraphs a vector of references to created subgraps
157 *
158 * \author Sergey Alexandrov
159 * \ingroup graph */
160 template <typename Graph>
162 const pcl::PointIndices& indices,
163 std::vector<boost::reference_wrapper<Graph>>& subgraphs);
164
165
166 /** Create subgraphs of a given graph containing vertices from a given
167 * indices vector.
168 *
169 * For each set of indices in the \p indices vector this function will
170 * create a subgraph containing corresponding vertices of the parent
171 * graph. An additional subgraph containing all the remaining vertices
172 * (not included in any other subgraph) will be created as well.
173 *
174 * In order to allow creation of subgraphs, the graph type should be an
175 * instantiation of boost::subgraph template. Note that the graph is
176 * passed by non-const reference, because subgraph creation modifies the
177 * parent graph. Also, note that the created subgraphs are output as
178 * references wrapped with boost::reference_wrapper. The reason is that
179 * the factory function for subgraph creation in BGL returns newly created
180 * subgraphs by reference.
181 *
182 * \param[in] graph an input graph
183 * \param[in] indices a vector of indices of points to be inserted in the
184 * subgraphs
185 * \param[out] subgraphs a vector of references to created subgraps
186 *
187 * \author Sergey Alexandrov
188 * \ingroup graph */
189 template <typename Graph>
191 const std::vector<pcl::PointIndices>& indices,
192 std::vector<boost::reference_wrapper<Graph>>& subgraphs);
193
194
195 /** Apply bilateral filtering to a given point cloud graph.
196 *
197 * \c Graph has to be a model of concepts::PointCloudGraphConcept.
198 *
199 * \author Sergey Alexandrov
200 * \ingroup graph */
201 template <typename Graph>
202 void smoothen(Graph& graph, float spatial_sigma, float influence_sigma);
203
204} // namespace pcl::graph
205
206#include "common.hpp"
207
208#endif /* PCL_GRAPH_COMMON_H */
void computeSignedCurvatures(Graph &graph)
Compute the type of curvature (concave/convex) for each vertex.
Definition common.hpp:111
pcl::PointIndices::Ptr indices(const PCG &g)
Retrieve the indices of the points of the point cloud stored in a point cloud graph that actually bel...
void computeNormalsAndCurvatures(Graph &graph, bool neighborhood_1ring=false)
Compute normals and curvatures for all vertices in a graph.
Definition common.hpp:55
size_t createSubgraphsFromColorMap(Graph &graph, ColorMap color_map, std::vector< boost::reference_wrapper< Graph > > &subgraphs)
Split a given graph into subgraphs based on the values in a given vertex color map.
Definition common.hpp:166
void createSubgraphsFromIndices(Graph &graph, const pcl::PointIndices &indices, std::vector< boost::reference_wrapper< Graph > > &subgraphs)
Create two subgraphs of a given graph, one containing the points with the given indices,...
Definition common.hpp:203
void smoothen(Graph &graph, float spatial_sigma, float influence_sigma)
Apply bilateral filtering to a given point cloud graph.
Definition common.hpp:265
size_t createSubgraphsFromConnectedComponents(Graph &graph, std::vector< boost::reference_wrapper< Graph > > &subgraphs)
Find connected components in a graph and create a subgraph for each of them.
Definition common.hpp:143