38#ifndef PCL_SEGMENTATION_IMPL_RANDOM_WALKER_HPP
39#define PCL_SEGMENTATION_IMPL_RANDOM_WALKER_HPP
41#include <boost/bimap.hpp>
43#include <Eigen/Sparse>
48 namespace segmentation
64 template <
class Graph,
class EdgeWeightMap,
class VertexColorMap>
70 using Color =
typename boost::property_traits<VertexColorMap>::value_type;
71 using Weight =
typename boost::property_traits<EdgeWeightMap>::value_type;
78 using VertexIndexMap =
typename boost::property_map<Graph, boost::vertex_index_t>::type;
81 using Matrix = Eigen::Matrix<Weight, Eigen::Dynamic, Eigen::Dynamic>;
82 using Vector = Eigen::Matrix<Weight, Eigen::Dynamic, 1>;
105 using namespace boost;
118 using namespace boost;
120 using T = Eigen::Triplet<float>;
126 for (
tie (
vi, v_end) = vertices (
g_);
vi != v_end; ++
vi)
187 X.resize (
L.rows (),
B.cols ());
190 if (
L.rows () == 0 ||
B.cols () == 0)
193 Eigen::SimplicialCholesky<SparseMatrix, Eigen::Lower>
cg;
196 for (Eigen::Index i = 0; i <
B.cols (); ++i)
199 X.col (i) =
cg.solve (b);
200 if (
cg.info () != Eigen::Success)
211 using namespace boost;
213 for (Eigen::Index i = 0; i <
X.rows (); ++i)
226 using namespace boost;
229 for (Eigen::Index i = 0; i <
X.rows (); ++i)
232 for (std::size_t i = 0; i <
seeds_.size (); ++i)
240 for (Eigen::Index i = 0; i <
potentials.cols (); ++i)
244 template <
typename T>
static inline std::size_t
247 if (
bimap.right.count (value) != 0)
249 return bimap.right.at (value);
252 bimap.insert (
typename boost::bimap<std::size_t, T>::value_type (s, value));
279 template <
class Graph>
bool
283 boost::get (boost::edge_weight,
graph),
284 boost::get (boost::vertex_color,
graph));
287 template <
class Graph,
class EdgeWeightMap,
class VertexColorMap>
bool
292 using namespace boost;
310 return rw.segment ();
313 template <
class Graph,
class EdgeWeightMap,
class VertexColorMap>
bool
317 Eigen::Matrix<
typename boost::property_traits<EdgeWeightMap>::value_type, Eigen::Dynamic, Eigen::Dynamic>&
potentials,
318 std::map<
typename boost::property_traits<VertexColorMap>::value_type, std::size_t>&
colors_to_columns_map)
320 using namespace boost;
Iterator class for point clouds with or without given indices.
std::size_t size() const
Size of the range the iterator is going through.
Multilabel graph segmentation using random walks.
void computeVertexDegrees()
typename boost::property_map< Graph, boost::vertex_index_t >::type VertexIndexMap
boost::bimap< std::size_t, VertexDescriptor > L_vertex_bimap
typename boost::property_traits< VertexColorMap >::value_type Color
RandomWalker(Graph &g, EdgeWeightMap weights, VertexColorMap colors)
void getPotentials(Matrix &potentials, std::map< Color, std::size_t > &color_to_column_map)
std::vector< VertexDescriptor > seeds_
typename GraphTraits::out_edge_iterator OutEdgeIterator
Eigen::Matrix< Weight, Eigen::Dynamic, Eigen::Dynamic > Matrix
boost::graph_traits< Graph > GraphTraits
typename GraphTraits::edge_descriptor EdgeDescriptor
VertexIndexMap index_map_
typename boost::property_traits< EdgeWeightMap >::value_type Weight
VertexColorMap color_map_
typename GraphTraits::vertex_descriptor VertexDescriptor
static std::size_t insertInBimap(boost::bimap< std::size_t, T > &bimap, T value)
typename GraphTraits::edge_iterator EdgeIterator
std::vector< Weight > degree_storage_
EdgeWeightMap weight_map_
std::set< Color > colors_
VertexDegreeMap degree_map_
boost::iterator_property_map< typename std::vector< Weight >::iterator, VertexIndexMap > VertexDegreeMap
boost::bimap< std::size_t, Color > B_color_bimap
Eigen::Matrix< Weight, Eigen::Dynamic, 1 > Vector
Eigen::SparseMatrix< Weight > SparseMatrix
typename GraphTraits::vertex_iterator VertexIterator
bool randomWalker(Graph &graph)
Multilabel graph segmentation using random walks.