MEPP2 Project
Vertex_comparators.hpp
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 #pragma once
12 
13 #include <boost/graph/graph_traits.hpp>
14 #include <boost/graph/properties.hpp>
15 
17 
18 #include <limits>
19 #include <iterator>
20 
21 namespace FEVV {
22 namespace Comparator
23 {
24  template <typename Graph, typename PointMap, typename GeometryTraits = FEVV::Geometry_traits<Graph> >
26  {
27  public:
28  typedef boost::graph_traits<Graph> GraphTraits;
30  typedef typename GeometryTraits::Scalar Scalar;
31  typedef typename GeometryTraits::Point Point;
32  private:
33  const Graph& _g;
34  const PointMap& _pm;
35  const GeometryTraits _gt;
36  public:
37  Vertex_comparator(const Graph& g, const PointMap& pm) :_g(g), _pm(pm), _gt(GeometryTraits(g)) {}
38  Vertex_comparator(const Graph& g, const PointMap& pm, const GeometryTraits& gt) :_g(g), _pm(pm), _gt(gt) {}
40  {
41  if(v1==v2)
42  return false;
43 
44  if(v1==GraphTraits::null_vertex())
45  {
46  return false;
47  }
48 
49  if(v2==GraphTraits::null_vertex())
50  {
51  return false;
52  }
53 
54  Point pv1 = get(_pm, v1);
55  Point pv2 = get(_pm, v2);
56 
57  if (fabs(_gt.get_x(pv1) - _gt.get_x(pv2)) > std::numeric_limits<Scalar>::epsilon())
58  return _gt.get_x(pv1) < _gt.get_x(pv2);
59  else if(fabs(_gt.get_y(pv1) - _gt.get_y(pv2)) > std::numeric_limits<Scalar>::epsilon())
60  return _gt.get_y(pv1) < _gt.get_y(pv2);
61  else if(fabs(_gt.get_z(pv1) - _gt.get_z(pv2)) > std::numeric_limits<Scalar>::epsilon())
62  return _gt.get_z(pv1) < _gt.get_z(pv2);
63 
64  auto e_v1 = in_edges(v1,_g),
65  e_v2 = in_edges(v2,_g);
66 
67  auto e_v1_deg = std::distance(e_v1.first, e_v1.second),
68  e_v2_deg = std::distance(e_v2.first, e_v2.second);
69  if( e_v1_deg != e_v2_deg)
70  return e_v1_deg < e_v2_deg ;
71 
72  e_v1_deg=e_v2_deg=0;
73  decltype(e_v1_deg) e_v1_min_deg = 1000, e_v1_max_deg = 0, e_v2_min_deg = 1000, e_v2_max_deg = 0;
74  auto iter_e_v = e_v1.first;
75  for( ; iter_e_v!=e_v1.second; ++iter_e_v)
76  {
77  auto e_vopp = (source(*iter_e_v, _g)!=v1)?in_edges(source(*iter_e_v, _g),_g):in_edges(target(*iter_e_v, _g),_g);
78  auto current_deg = std::distance(e_vopp.first, e_vopp.second);
79  if (current_deg < e_v1_min_deg)
80  e_v1_min_deg = current_deg;
81  if (current_deg > e_v1_max_deg)
82  e_v1_max_deg = current_deg;
83  e_v1_deg += current_deg;
84  }
85 
86  iter_e_v = e_v2.first;
87  for( ; iter_e_v!=e_v2.second; ++iter_e_v)
88  {
89  auto e_vopp = (source(*iter_e_v, _g)!=v2)?in_edges(source(*iter_e_v, _g),_g):in_edges(target(*iter_e_v, _g),_g);
90  auto current_deg = std::distance(e_vopp.first, e_vopp.second);
91  if (current_deg < e_v2_min_deg)
92  e_v2_min_deg = current_deg;
93  if (current_deg > e_v2_max_deg)
94  e_v2_max_deg = current_deg;
95  e_v2_deg += current_deg;
96  }
97 
98  if( e_v1_deg != e_v2_deg)
99  return e_v1_deg < e_v2_deg ;
100 
101  if (e_v1_min_deg != e_v2_min_deg)
102  return e_v1_min_deg < e_v2_min_deg;
103 
104  if (e_v1_max_deg != e_v2_max_deg)
105  return e_v1_max_deg < e_v2_max_deg;
106 
107  return false;
108  }
109  };
111  template <typename Graph, typename PointMap, typename GeometryTraits = FEVV::Geometry_traits<Graph> >
112  static
113  Vertex_comparator<Graph, PointMap, GeometryTraits>
114  get_vertex_comparator(const Graph& g, const PointMap& pm) { return Vertex_comparator<Graph, PointMap, GeometryTraits>(g, pm); }
115 } // namespace Container
116 } // namespace FEVV
117 
FEVV::Comparator::Vertex_comparator::GraphTraits
boost::graph_traits< Graph > GraphTraits
Definition: Vertex_comparators.hpp:28
FEVV::Comparator::get_vertex_comparator
static Vertex_comparator< Graph, PointMap, GeometryTraits > get_vertex_comparator(const Graph &g, const PointMap &pm)
Definition: Vertex_comparators.hpp:114
FEVV::Comparator::Vertex_comparator
Definition: Vertex_comparators.hpp:26
Point
AIFMesh::Point Point
Definition: Graph_properties_aif.h:21
FEVV::Comparator::Vertex_comparator::Vertex_comparator
Vertex_comparator(const Graph &g, const PointMap &pm, const GeometryTraits &gt)
Definition: Vertex_comparators.hpp:38
FEVV::DataStructures::AIF::source
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor source(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor e, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the source vertex of e.
Definition: Graph_traits_aif.h:387
FEVV::Comparator::Vertex_comparator::Point
GeometryTraits::Point Point
Definition: Vertex_comparators.hpp:31
FEVV::get
FEVV::PCLPointCloudPointMap::value_type get(const FEVV::PCLPointCloudPointMap &pm, FEVV::PCLPointCloudPointMap::key_type key)
Specialization of get(point_map, key) for PCLPointCloud.
Definition: Graph_properties_pcl_point_cloud.h:117
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::Comparator::Vertex_comparator::_g
const Graph & _g
Definition: Vertex_comparators.hpp:33
FEVV::DataStructures::AIF::target
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor target(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor e, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the target vertex of e.
Definition: Graph_traits_aif.h:400
Geometry_traits.h
FEVV::Comparator::Vertex_comparator::vertex_descriptor
GraphTraits::vertex_descriptor vertex_descriptor
Definition: Vertex_comparators.hpp:29
FEVV::DataStructures::AIF::in_edges
std::pair< typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::in_edge_iterator, typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::in_edge_iterator > in_edges(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor u, const FEVV::DataStructures::AIF::AIFMesh &)
Definition: Graph_traits_aif.h:451
FEVV::Comparator::Vertex_comparator::_gt
const GeometryTraits _gt
Definition: Vertex_comparators.hpp:35
FEVV::Comparator::Vertex_comparator::Scalar
GeometryTraits::Scalar Scalar
Definition: Vertex_comparators.hpp:30
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
FEVV::Filters::fabs
double fabs(const v_Curv< HalfedgeGraph > &input)
Definition: curvature.hpp:54
FEVV::Comparator::Vertex_comparator::Vertex_comparator
Vertex_comparator(const Graph &g, const PointMap &pm)
Definition: Vertex_comparators.hpp:37
FEVV::Comparator::Vertex_comparator::operator()
bool operator()(vertex_descriptor v1, vertex_descriptor v2)
Definition: Vertex_comparators.hpp:39
epsilon
const float epsilon
Definition: core.h:51
FEVV::Comparator::Vertex_comparator::_pm
const PointMap & _pm
Definition: Vertex_comparators.hpp:34