38 #ifndef PCL_GRAPH_EDGE_WEIGHT_COMPUTER_H
39 #define PCL_GRAPH_EDGE_WEIGHT_COMPUTER_H
41 #include <boost/function.hpp>
195 template <
typename GraphT>
240 : policy_(SMALL_WEIGHT_IGNORE)
256 template <
typename EdgeWeightMap>
void
257 compute(GraphT& graph, EdgeWeightMap weights);
271 compute(graph, boost::get(boost::edge_weight, graph));
285 template <
typename TermT>
void
287 float convex_influence_multiplier = 1.0,
290 addTermImpl<TermT> (influence, convex_influence_multiplier, normalization,
291 typename boost::mpl::apply<typename TermT::is_compatible, PointT>::type());
298 template <
typename TermT>
void
302 addTermImpl<TermT> (influence, 1.0, normalization,
303 typename boost::mpl::apply<typename TermT::is_compatible, PointT>::type());
317 threshold_ = threshold;
324 balancing_function_ = func;
331 gaussian(
float val,
float influence)
333 return (influence > 0.0 ? std::exp(-val / influence) : 1.0);
343 ComputeFunction compute_;
345 float convex_influence_multiplier_;
347 Term(ComputeFunction f,
float i,
float c)
350 , convex_influence_multiplier_(
c)
355 getInfluence(
bool is_convex =
false)
const
357 return (influence_ * (is_convex ? convex_influence_multiplier_ : 1.0));
365 struct GloballyNormalizedTerm : Term
368 GloballyNormalizedTerm(
typename Term::ComputeFunction f,
float i,
float c)
374 init(
size_t num_edges)
376 edge_weights_.resize(num_edges, 0.0f);
377 total_weight_ = 0.0f;
381 round1(
const PointT& p1,
const PointT& p2,
size_t edge_id)
383 float weight = this->compute_(p1, p2);
384 edge_weights_[edge_id] = weight;
385 total_weight_ += weight;
392 average_ = total_weight_ / edge_weights_.size();
396 round2(
size_t edge_id)
398 return (edge_weights_[edge_id] / average_);
401 std::vector<float> edge_weights_;
410 struct LocallyNormalizedTerm : Term
413 LocallyNormalizedTerm(
typename Term::ComputeFunction f,
float i,
float c)
419 init(
size_t num_edges,
size_t num_vertices)
421 edge_weights_.resize(num_edges, 0.0f);
422 vertex_sums_.resize(num_vertices, 0.0f);
423 vertex_degrees_.resize(num_vertices, 0);
433 float weight = this->compute_(p1, p2);
434 edge_weights_[edge_id] = weight;
435 vertex_sums_[vertex1_id] += weight;
436 vertex_sums_[vertex2_id] += weight;
437 ++vertex_degrees_[vertex1_id];
438 ++vertex_degrees_[vertex2_id];
445 for (
size_t i = 0; i < vertex_sums_.size(); ++i)
446 if (vertex_degrees_[i])
448 vertex_sums_[i] /= vertex_degrees_[i];
453 round2(
size_t vertex1_id,
455 size_t edge_id)
const
457 float n = (vertex_sums_[vertex1_id] + vertex_sums_[vertex2_id]) / 2.0;
458 float weight = (n > 0.0f && this->getInfluence() > 0.0f)
459 ? edge_weights_[edge_id] / n
464 std::vector<float> edge_weights_;
465 std::vector<float> vertex_sums_;
466 std::vector<size_t> vertex_degrees_;
470 template <
typename TermT>
void
471 addTermImpl(
float influence,
472 float convex_influence_multiplier,
473 NormalizationType normalization,
474 boost::mpl::bool_<true>)
476 switch (normalization)
478 case NORMALIZATION_NONE:
480 terms_.push_back(Term(TermT::template compute<PointT>, influence, convex_influence_multiplier));
483 case NORMALIZATION_GLOBAL:
485 g_terms_.push_back(GloballyNormalizedTerm(TermT::template compute<PointT>, influence, convex_influence_multiplier));
488 case NORMALIZATION_LOCAL:
490 l_terms_.push_back(LocallyNormalizedTerm(TermT::template compute<PointT>, influence, convex_influence_multiplier));
498 template <
typename TermT>
void
499 addTermImpl(
float influence,
500 float convex_influence_multiplier,
501 NormalizationType normalization,
502 boost::mpl::bool_<false>)
506 std::vector<Term> terms_;
507 std::vector<GloballyNormalizedTerm> g_terms_;
508 std::vector<LocallyNormalizedTerm> l_terms_;
510 SmallWeightPolicy policy_;
512 TermBalancingFunction balancing_function_;