MEPP2 Project
Edge_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 #include <cmath>
21 
22 namespace FEVV {
23 namespace Comparator
24 {
25  template <typename Graph,
26  typename PointMap,
27  typename EdgeWeightMap = typename FEVV::Edge_pmap_traits<Graph,
29  >::pmap_type,
30  typename GeometryTraits = FEVV::Geometry_traits<Graph> >
32  {
33  public:
34  typedef boost::graph_traits<Graph> GraphTraits;
36  typedef typename GraphTraits::edge_descriptor edge_descriptor;
37  typedef typename GeometryTraits::Scalar Scalar;
38  typedef typename GeometryTraits::Point Point;
39  private:
40  const Graph& _g;
41  const PointMap& _pm;
42  EdgeWeightMap _ew;
43  const GeometryTraits _gt;
44  public:
45  Edge_comparator(const Graph& g, const PointMap& pm) :_g(g), _pm(pm), _ew(0, get(boost::edge_index, g)), _gt(GeometryTraits(g)) {}
46  Edge_comparator(const Graph& g, const PointMap& pm, const GeometryTraits& gt):_g(g), _pm(pm), _ew(0, get(boost::edge_index, g)), _gt(gt) {}
47  Edge_comparator(const Graph& g, const PointMap& pm, const EdgeWeightMap& ew) :_g(g), _pm(pm), _ew(ew), _gt(GeometryTraits(g)) {}
48  Edge_comparator(const Graph& g, const PointMap& pm, const EdgeWeightMap& ew, const GeometryTraits& gt) :_g(g), _pm(pm), _ew(ew), _gt(gt) {}
49  Edge_comparator(const Edge_comparator& other): _g(other._g), _pm(other._pm), _ew(other._ew), _gt(other._gt) {}
51  {
52  if(e1==e2)
53  return false;
54 
55  if(e1==GraphTraits::null_edge())
56  {
57  return false;
58  }
59 
60  if(e2==GraphTraits::null_edge())
61  {
62  return false;
63  }
64 
65  if (_ew.storage_begin()!= _ew.storage_end())
66  {
67  Scalar val_e1 = get(_ew, e1), val_e2 = get(_ew, e2);
68 
69  if (val_e1 < val_e2)
70  return true;
71  else if (val_e1 > val_e2)
72  return false;
73  }
74  Point pe1_pv1 = get(_pm, source(e1, _g));
75  Point pe1_pv2 = get(_pm, target(e1, _g));
76 
77  Point pe2_pv1 = get(_pm, source(e2, _g));
78  Point pe2_pv2 = get(_pm, target(e2, _g));
79 
80  Point minie1(0,0,0), maxie1(0,0,0), minie2(0,0,0), maxie2(0,0,0);
81  bool minie1_is_pe1_pv1 = false,
82  minie2_is_pe2_pv1 = false;
83  if( _gt.get_x(pe1_pv1) < _gt.get_x(pe1_pv2) )
84  {
85  minie1 = pe1_pv1; minie1_is_pe1_pv1 = true;
86  maxie1 = pe1_pv2;
87  }
88  else if( _gt.get_x(pe1_pv1) > _gt.get_x(pe1_pv2) )
89  {
90  maxie1 = pe1_pv1;
91  minie1 = pe1_pv2;
92  }
93  else if( _gt.get_y(pe1_pv1) < _gt.get_y(pe1_pv2) )
94  {
95  minie1 = pe1_pv1; minie1_is_pe1_pv1 = true;
96  maxie1 = pe1_pv2;
97  }
98  else if( _gt.get_y(pe1_pv1) > _gt.get_y(pe1_pv2) )
99  {
100  maxie1 = pe1_pv1;
101  minie1 = pe1_pv2;
102  }
103  else if( _gt.get_z(pe1_pv1) < _gt.get_z(pe1_pv2) )
104  {
105  minie1 = pe1_pv1; minie1_is_pe1_pv1 = true;
106  maxie1 = pe1_pv2;
107  }
108  else if( _gt.get_z(pe1_pv1) > _gt.get_z(pe1_pv2) )
109  {
110  maxie1 = pe1_pv1;
111  minie1 = pe1_pv2;
112  }
113  else minie1 = maxie1 = pe1_pv1;
115  if( _gt.get_x(pe2_pv1) < _gt.get_x(pe2_pv2) )
116  {
117  minie2 = pe2_pv1; minie2_is_pe2_pv1 = true;
118  maxie2 = pe2_pv2;
119  }
120  else if( _gt.get_x(pe2_pv1) > _gt.get_x(pe2_pv2) )
121  {
122  maxie2 = pe2_pv1;
123  minie2 = pe2_pv2;
124  }
125  else if( _gt.get_y(pe2_pv1) < _gt.get_y(pe2_pv2) )
126  {
127  minie2 = pe2_pv1; minie2_is_pe2_pv1 = true;
128  maxie2 = pe2_pv2;
129  }
130  else if( _gt.get_y(pe2_pv1) > _gt.get_y(pe2_pv2) )
131  {
132  maxie2 = pe2_pv1;
133  minie2 = pe2_pv2;
134  }
135  else if( _gt.get_z(pe2_pv1) < _gt.get_z(pe2_pv2) )
136  {
137  minie2 = pe2_pv1; minie2_is_pe2_pv1 = true;
138  maxie2 = pe2_pv2;
139  }
140  else if( _gt.get_z(pe2_pv1) > _gt.get_z(pe2_pv2) )
141  {
142  maxie2 = pe2_pv1;
143  minie2 = pe2_pv2;
144  }
145  else minie2 = maxie2 = pe2_pv1;
147  if (fabs(_gt.get_x(minie1) - _gt.get_x(minie2)) > std::numeric_limits<Scalar>::epsilon())
148  return _gt.get_x(minie1) < _gt.get_x(minie2);
149  else if (fabs(_gt.get_y(minie1) - _gt.get_y(minie2)) > std::numeric_limits<Scalar>::epsilon())
150  return _gt.get_y(minie1) < _gt.get_y(minie2);
151  else if (fabs(_gt.get_z(minie1) - _gt.get_z(minie2)) > std::numeric_limits<Scalar>::epsilon())
152  return _gt.get_z(minie1) < _gt.get_z(minie2);
153  else if (fabs(_gt.get_x(maxie1) - _gt.get_x(maxie2)) > std::numeric_limits<Scalar>::epsilon())
154  return _gt.get_x(maxie1) < _gt.get_x(maxie2);
155  else if (fabs(_gt.get_y(maxie1) - _gt.get_y(maxie2)) > std::numeric_limits<Scalar>::epsilon())
156  return _gt.get_y(maxie1) < _gt.get_y(maxie2);
157  else if (fabs(_gt.get_z(maxie1) - _gt.get_z(maxie2)) > std::numeric_limits<Scalar>::epsilon())
158  return _gt.get_z(maxie1) < _gt.get_z(maxie2);
159  else
160  {
161  auto e1_v1 = in_edges(source(e1, _g),_g),
162  e1_v2 = in_edges(target(e1, _g),_g),
163  e2_v1 = in_edges(source(e2, _g),_g),
164  e2_v2 = in_edges(target(e2, _g),_g);
165 
166  auto e1_v1_deg = std::distance(e1_v1.first, e1_v1.second),
167  e1_v2_deg = std::distance(e1_v2.first, e1_v2.second),
168  e2_v1_deg = std::distance(e2_v1.first, e2_v1.second),
169  e2_v2_deg = std::distance(e2_v2.first, e2_v2.second);
170  if( minie1_is_pe1_pv1 )
171  {
172  if( minie2_is_pe2_pv1 )
173  {
174  if( e1_v1_deg!= e2_v1_deg)
175  return e1_v1_deg < e2_v1_deg;
176  }
177  else
178  {
179  if( e1_v1_deg!= e2_v2_deg)
180  return e1_v1_deg < e2_v2_deg;
181  }
182  }
183  else
184  {
185  if( minie2_is_pe2_pv1 )
186  {
187  if( e1_v2_deg!= e2_v1_deg)
188  return e1_v2_deg < e2_v1_deg;
189  }
190  else
191  {
192  if( e1_v2_deg!= e2_v2_deg)
193  return e1_v2_deg < e2_v2_deg;
194  }
195  }
196 
197  if( !minie1_is_pe1_pv1 )
198  {
199  if( !minie2_is_pe2_pv1 )
200  {
201  if( e1_v1_deg!= e2_v1_deg)
202  return e1_v1_deg < e2_v1_deg;
203  }
204  else
205  {
206  if( e1_v1_deg!= e2_v2_deg)
207  return e1_v1_deg < e2_v2_deg;
208  }
209  }
210  else
211  {
212  if( !minie2_is_pe2_pv1 )
213  {
214  if( e1_v2_deg!= e2_v1_deg)
215  return e1_v2_deg < e2_v1_deg;
216  }
217  else
218  {
219  if( e1_v2_deg!= e2_v2_deg)
220  return e1_v2_deg < e2_v2_deg;
221  }
222  }
223  }
224 
225  return false; // can be an issue
226  }
227  };
229  template <typename Graph,
230  typename PointMap,
231  typename EdgeWeightMap = typename FEVV::Edge_pmap_traits<Graph,
233  >::pmap_type,
234  typename GeometryTraits = FEVV::Geometry_traits<Graph> >
235  static
236  Edge_comparator<Graph, PointMap, EdgeWeightMap, GeometryTraits>
237  get_edge_comparator(const Graph& g, const PointMap& pm) { return Edge_comparator<Graph, PointMap, EdgeWeightMap, GeometryTraits>(g, pm); }
238 } // namespace Container
239 } // namespace FEVV
240 
FEVV::Comparator::Edge_comparator::Edge_comparator
Edge_comparator(const Graph &g, const PointMap &pm, const GeometryTraits &gt)
Definition: Edge_comparators.hpp:46
FEVV::Comparator::Edge_comparator::Edge_comparator
Edge_comparator(const Graph &g, const PointMap &pm, const EdgeWeightMap &ew)
Definition: Edge_comparators.hpp:47
FEVV::Comparator::Edge_comparator::Point
GeometryTraits::Point Point
Definition: Edge_comparators.hpp:38
FEVV::Edge_pmap_traits
Definition: properties.h:345
FEVV::Comparator::Edge_comparator::Edge_comparator
Edge_comparator(const Edge_comparator &other)
Definition: Edge_comparators.hpp:49
FEVV::Comparator::Edge_comparator::_gt
const GeometryTraits _gt
Definition: Edge_comparators.hpp:43
FEVV::Comparator::Edge_comparator::Edge_comparator
Edge_comparator(const Graph &g, const PointMap &pm)
Definition: Edge_comparators.hpp:45
FEVV::Geometry_traits
Refer to Geometry_traits_documentation_dummy for further documentation on provided types and algorith...
Definition: Geometry_traits.h:162
boost
Definition: Graph_properties_aif.h:48
Point
AIFMesh::Point Point
Definition: Graph_properties_aif.h:21
FEVV::Comparator::get_edge_comparator
static Edge_comparator< Graph, PointMap, EdgeWeightMap, GeometryTraits > get_edge_comparator(const Graph &g, const PointMap &pm)
Definition: Edge_comparators.hpp:237
FEVV::Comparator::Edge_comparator::_pm
const PointMap & _pm
Definition: Edge_comparators.hpp:41
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::Edge_comparator::Scalar
GeometryTraits::Scalar Scalar
Definition: Edge_comparators.hpp:37
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::Comparator::Edge_comparator::_g
const Graph & _g
Definition: Edge_comparators.hpp:40
FEVV::Comparator::Edge_comparator::edge_descriptor
GraphTraits::edge_descriptor edge_descriptor
Definition: Edge_comparators.hpp:36
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::Comparator::Edge_comparator::Edge_comparator
Edge_comparator(const Graph &g, const PointMap &pm, const EdgeWeightMap &ew, const GeometryTraits &gt)
Definition: Edge_comparators.hpp:48
FEVV::Comparator::Edge_comparator
Definition: Edge_comparators.hpp:32
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
FEVV::Comparator::Edge_comparator::GraphTraits
boost::graph_traits< Graph > GraphTraits
Definition: Edge_comparators.hpp:34
Geometry_traits.h
FEVV::Comparator::Edge_comparator::_ew
EdgeWeightMap _ew
Definition: Edge_comparators.hpp:42
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
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::Edge_comparator::operator()
bool operator()(edge_descriptor e1, edge_descriptor e2)
Definition: Edge_comparators.hpp:50
FEVV::Comparator::Edge_comparator::vertex_descriptor
GraphTraits::vertex_descriptor vertex_descriptor
Definition: Edge_comparators.hpp:35
epsilon
const float epsilon
Definition: core.h:51