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 
45 namespace 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> void
63  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> void
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> size_t
106  std::vector<boost::reference_wrapper<Graph> >& subgraphs);
107 
108 
109  /** Split a given graph into subgraphs based on the values in a given
110  * vertex color map.
111  *
112  * Each created subgraph is filled with the vertices that have the same
113  * color according to the color map. Consequently, the number of created
114  * subgraphs is equal to the number of unique colors in the provided map.
115  * The subgraphs are guaranteed to be sorted in the increasing order of
116  * the color.
117  *
118  * In order to allow creation of subgraphs, the graph type should be an
119  * instantiation of boost::subgraph template. Note that the graph is
120  * passed by non-const reference, because subgraph creation modifies the
121  * parent graph. Also, note that the created subgraphs are output as
122  * references wrapped with boost::reference_wrapper. The reason is that
123  * the factory function for subgraph creation in BGL returns newly created
124  * subgraphs by reference.
125  *
126  * \param[in] graph an input graph
127  * \param[in] color_map a color map that defines vertex colors
128  * \param[out] subgraphs a vector of references to created subgraps
129  *
130  * \return the number of created subgraphs
131  *
132  * \author Sergey Alexandrov
133  * \ingroup graph
134  * */
135  template <typename Graph, typename ColorMap> size_t
137  ColorMap color_map,
138  std::vector<boost::reference_wrapper<Graph> >& subgraphs);
139 
140 
141  /** Create two subgraphs of a given graph, one containing the points with
142  * the given indices, and the other containing the remaining points.
143  *
144  * In order to allow creation of subgraphs, the graph type should be an
145  * instantiation of boost::subgraph template. Note that the graph is
146  * passed by non-const reference, because subgraph creation modifies the
147  * parent graph. Also, note that the created subgraphs are output as
148  * references wrapped with boost::reference_wrapper. The reason is that
149  * the factory function for subgraph creation in BGL returns newly created
150  * subgraphs by reference.
151  *
152  * \param[in] graph an input graph
153  * \param[in] indices indices of points to be inserted in the first
154  * subgraph
155  * \param[out] subgraphs a vector of references to created subgraps
156  *
157  * \author Sergey Alexandrov
158  * \ingroup graph */
159  template <typename Graph> void
161  const pcl::PointIndices& indices,
162  std::vector<boost::reference_wrapper<Graph> >& subgraphs);
163 
164 
165  /** Create subgraphs of a given graph containing vertices from a given
166  * indices vector.
167  *
168  * For each set of indices in the \p indices vector this function will
169  * create a subgraph containing corresponding vertices of the parent
170  * graph. An additional subgraph containing all the remaining vertices
171  * (not included in any other subgraph) will be created as well.
172  *
173  * In order to allow creation of subgraphs, the graph type should be an
174  * instantiation of boost::subgraph template. Note that the graph is
175  * passed by non-const reference, because subgraph creation modifies the
176  * parent graph. Also, note that the created subgraphs are output as
177  * references wrapped with boost::reference_wrapper. The reason is that
178  * the factory function for subgraph creation in BGL returns newly created
179  * subgraphs by reference.
180  *
181  * \param[in] graph an input graph
182  * \param[in] indices a vector of indices of points to be inserted in the
183  * subgraphs
184  * \param[out] subgraphs a vector of references to created subgraps
185  *
186  * \author Sergey Alexandrov
187  * \ingroup graph */
188  template <typename Graph> void
190  const std::vector<pcl::PointIndices>& indices,
191  std::vector<boost::reference_wrapper<Graph> >& subgraphs);
192 
193 
194  /** Apply bilateral filtering to a given point cloud graph.
195  *
196  * \c Graph has to be a model of concepts::PointCloudGraphConcept.
197  *
198  * \author Sergey Alexandrov
199  * \ingroup graph */
200  template <typename Graph> void
201  smoothen(Graph& graph, float spatial_sigma, float influence_sigma);
202 
203 }
204 
205 
206 
207 #include "common.hpp"
208 
209 #endif /* PCL_GRAPH_COMMON_H */
210 
pcl::graph::createSubgraphsFromColorMap
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:163
pcl::graph::smoothen
void smoothen(Graph &graph, float spatial_sigma, float influence_sigma)
Apply bilateral filtering to a given point cloud graph.
Definition: common.hpp:259
common.hpp
pcl::graph::computeNormalsAndCurvatures
void computeNormalsAndCurvatures(Graph &graph, bool neighborhood_1ring=false)
Compute normals and curvatures for all vertices in a graph.
Definition: common.hpp:55
pcl::graph::createSubgraphsFromConnectedComponents
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:142
pcl::graph
Definition: common.h:45
pcl::graph::indices
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...
Definition: point_cloud_graph.h:737
armarx::Graph
boost::subgraph< CloudGraph > Graph
Definition: Common.h:54
pcl::graph::computeSignedCurvatures
void computeSignedCurvatures(Graph &graph)
Compute the type of curvature (concave/convex) for each vertex.
Definition: common.hpp:111
ColorMap
Definition: color.h:10
pcl::graph::createSubgraphsFromIndices
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:199