MEPP2 Project
stencil.h
Go to the documentation of this file.
1 // Copyright (c) 2012-2022 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 
12 #pragma once
13 
14 #include <boost/graph/graph_traits.hpp>
15 #include <boost/graph/properties.hpp>
16 #include <CGAL/boost/graph/iterator.h>
17 
18 namespace FEVV {
19 namespace Filters {
20 template< typename HalfedgeGraph,
21  typename vertex_descriptor =
23  typename halfedge_descriptor = typename boost::graph_traits<
24  HalfedgeGraph >::halfedge_descriptor >
25 
26 void
27 forbid_vertex(HalfedgeGraph &g,
29  std::set< halfedge_descriptor > &forbidden_edges)
30 {
31  boost::iterator_range<
32  CGAL::Halfedge_around_target_iterator< HalfedgeGraph > >
33  iterator_range = CGAL::halfedges_around_target(v, g);
34  for(auto h_v : iterator_range)
35  {
36  forbidden_edges.insert(h_v);
37  forbidden_edges.insert(opposite(h_v, g));
38  }
39 }
40 
41 template< typename HalfedgeGraph,
42  typename vertex_descriptor =
44  typename halfedge_descriptor = typename boost::graph_traits<
45  HalfedgeGraph >::halfedge_descriptor >
46 void
47 find_vertices_to_forbid(HalfedgeGraph &g,
49  std::set< vertex_descriptor > &forbidden_vertices)
50 {
51  boost::iterator_range<
52  CGAL::Halfedge_around_target_iterator< HalfedgeGraph > >
53  iterator_range = CGAL::halfedges_around_target(v, g);
54  forbidden_vertices.insert(v);
55  for(auto h_v : iterator_range)
56  {
57  vertex_descriptor src_h = source(h_v, g);
58  forbidden_vertices.insert(src_h);
59  }
60 }
61 
62 
63 template< typename HalfedgeGraph,
64  typename vertex_descriptor =
66  typename halfedge_descriptor = typename boost::graph_traits<
67  HalfedgeGraph >::halfedge_descriptor >
68 void
69 forbid_edges(HalfedgeGraph &g,
71  std::set< halfedge_descriptor > &forbidden_edges)
72 {
73  std::set< vertex_descriptor > forbidden_vertices;
74  // include all adjacent vertices to v in forbidden_vertices
75  find_vertices_to_forbid(g, v, forbidden_vertices);
76 
77  // include all halfedges incident to a vertex in forbidden_vertices
78  // in forbidden_edges
79  for(const vertex_descriptor &ver : forbidden_vertices)
80  {
81  forbid_vertex(g, ver, forbidden_edges);
82  }
83 }
84 
85 template< typename HalfedgeGraph,
86  typename vertex_descriptor =
88  typename halfedge_descriptor = typename boost::graph_traits<
89  HalfedgeGraph >::halfedge_descriptor >
90 void
91 compute_simple_stencil(HalfedgeGraph &g,
93  std::set< halfedge_descriptor > &forbidden_edges,
94  std::vector< halfedge_descriptor > &edges_to_color)
95 {
96  boost::iterator_range<
97  CGAL::Halfedge_around_target_iterator< HalfedgeGraph > >
98  iterator_range = CGAL::halfedges_around_target(v, g);
99  for(auto h_v : iterator_range)
100  {
101  forbidden_edges.insert(h_v);
102  forbidden_edges.insert(opposite(h_v, g));
103 
104  edges_to_color.push_back(h_v);
105  edges_to_color.push_back(opposite(h_v, g));
106 
107  halfedge_descriptor next_h = next(opposite(h_v, g), g);
108 
109  forbidden_edges.insert(next_h);
110  halfedge_descriptor opp_next_h = opposite(next_h, g);
111  forbidden_edges.insert(opp_next_h);
112  edges_to_color.push_back(next_h);
113  edges_to_color.push_back(opp_next_h);
114 
115 
116  if(!CGAL::is_border(opp_next_h, g) &&
117  !CGAL::is_border(next_h, g)) // second verification might be overkill
118  {
119 
120 
121  forbidden_edges.insert(next(opp_next_h, g));
122  vertex_descriptor vv = target(opp_next_h, g);
123  boost::iterator_range<
124  CGAL::Halfedge_around_target_iterator< HalfedgeGraph > >
125  iterator_range2 = CGAL::halfedges_around_target(vv, g);
126  for(auto h_v2 : iterator_range2)
127  {
128  forbidden_edges.insert(h_v2);
129  forbidden_edges.insert(opposite(h_v2, g));
130  }
131  forbidden_edges.insert(opposite(next(opp_next_h, g), g));
132 
133  edges_to_color.push_back(next(opp_next_h, g));
134  edges_to_color.push_back(opposite(next(opp_next_h, g), g));
135 
136  forbidden_edges.insert(next(next(opp_next_h, g), g));
137  forbidden_edges.insert(opposite(next(next(opp_next_h, g), g), g));
138 
139  edges_to_color.push_back(next(next(opp_next_h, g), g));
140  edges_to_color.push_back(opposite(next(next(opp_next_h, g), g), g));
141  }
142  }
143 }
144 
145 } // namespace Filters
146 } // namespace FEVV
FEVV::DataStructures::AIF::next
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor next(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the next halfedge around its face.
Definition: Graph_traits_aif.h:599
FEVV::Filters::find_vertices_to_forbid
void find_vertices_to_forbid(HalfedgeGraph &g, vertex_descriptor v, std::set< vertex_descriptor > &forbidden_vertices)
Definition: stencil.h:47
FEVV::DataStructures::AIF::opposite
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor opposite(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the halfedge with source and target swapped.
Definition: Graph_traits_aif.h:625
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
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::Filters::forbid_vertex
void forbid_vertex(HalfedgeGraph &g, vertex_descriptor v, std::set< halfedge_descriptor > &forbidden_edges)
Definition: stencil.h:27
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::Filters::compute_simple_stencil
void compute_simple_stencil(HalfedgeGraph &g, vertex_descriptor v, std::set< halfedge_descriptor > &forbidden_edges, std::vector< halfedge_descriptor > &edges_to_color)
Definition: stencil.h:91
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
FEVV::Filters::forbid_edges
void forbid_edges(HalfedgeGraph &g, vertex_descriptor v, std::set< halfedge_descriptor > &forbidden_edges)
Definition: stencil.h:69