MEPP2 Project
collapse_edge.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 <CGAL/boost/graph/iterator.h>
15 
16 #include <CGAL/boost/graph/Euler_operations.h> // for add_face(vr,g)
17 
20 
21 #include <algorithm> // std::swap
22 #include <cassert>
23 
24 namespace FEVV {
25 namespace Operators {
26 
27 
29 
43 template< typename MutableFaceIncidentGraph >
44 void
45 collapse_edge_keep_source(MutableFaceIncidentGraph &g,
46  typename boost::graph_traits<
47  MutableFaceIncidentGraph >::
48  edge_descriptor &e)
49 {
50  typedef boost::graph_traits< MutableFaceIncidentGraph > GraphTraits;
51  typedef typename GraphTraits::edge_descriptor edge_descriptor;
53  if (e == GraphTraits::null_edge())
54  return;
55 
56  auto pair_e_bool = edge(source(e, g), target(e, g), g);
57  if(!pair_e_bool.second)
58  return;
60  edge_descriptor retrieved_edge = pair_e_bool.first;
61 
63  typedef typename GraphTraits::face_descriptor face_descriptor;
65  // REMOVE INCIDENT TRIANGULAR FACES
67  // 1 remove retrieved_edge from all its incident faces
68  std::vector< face_descriptor > faces_to_remove;
69  auto faces_range_pair = in_edges(e, g); // get incident faces
70  auto iter_f = faces_range_pair.first;
71  for(; iter_f != faces_range_pair.second; ++iter_f)
72  {
74  *iter_f, retrieved_edge); // remove edge retrieved_edge from face *iterF
75  if(degree(*iter_f, g) < 3)
76  faces_to_remove.push_back(*iter_f);
77  }
79  // 2 remove all faces that must be removed from mesh
80  typename std::vector< face_descriptor >::iterator it(faces_to_remove.begin()),
81  ite(faces_to_remove.end());
82  for(; it != ite; ++it)
83  remove_face(*it, g);
84  faces_to_remove.clear();
86  // REMOVE THE EDGE AND MERGE ITS TWO VERTICES
88  // 3 remove retrieved_edge
89  vertex_descriptor t = target(retrieved_edge, g);
90  vertex_descriptor s = source(retrieved_edge, g);
91 
92  remove_edge(retrieved_edge, g);
94  // cannot handle multiple incident similar edges (assumed by Florian Caillaud
95  // => easier encoding for mesh compression)
98  // cannot handle multiple incident similar faces (assumed by Florian Caillaud
99  // => easier encoding for mesh compression) Else a particular attention would
100  // be needed to distinguish between similar faces added intentionaly (or read
101  // from file) against those obtained via the edge collapse that must be
102  // resolved
106  // 4 merge retrieved_edge' vertices (source and target): the source is kept!
107 
108  // all incident edges of target vertex are put onto source vertex
109  auto src_incident_edges_range = in_edges(t, g);
110  auto iter_e = src_incident_edges_range.first;
111  for(; iter_e != src_incident_edges_range.second; ++iter_e)
112  {
113  AIFHelpers::add_vertex(*iter_e, s, AIFHelpers::vertex_position(*iter_e, t));
114  }
116  // merge the 2 vertices
117  // for each incident edge of the target vertex t
118  // if that edge was not incident to source vertex s, add it to s
119  // else add current edge to a list of edges to be removed from mesh
120  // replace this edge to be removed by the similar edge incident to s
121  // remove all edges in the list of edges to be removed
122  std::vector< edge_descriptor > edges_to_remove;
123  src_incident_edges_range = in_edges(t, g);
124  iter_e = src_incident_edges_range.first;
125  for(; iter_e != src_incident_edges_range.second; ++iter_e)
126  {
127  edge_descriptor edge = AIFHelpers::common_edge(
128  (*iter_e)->get_first_vertex(), (*iter_e)->get_second_vertex());
129  if(edge == AIFHelpers::null_edge())
130  AIFHelpers::add_edge(s, *iter_e);
131  else
132  {
133  edges_to_remove.push_back(*iter_e);
135  }
136  }
138  typename std::vector< edge_descriptor >::iterator it_e(
139  edges_to_remove.begin()),
140  it_ee(edges_to_remove.end());
141  for(; it_e != it_ee; ++it_e)
142  {
143  // AIFHelpers::add_vertex(*itE, t, AIFHelpers::vertex_position(*itE, s)); //
144  // to unsure that t is correctly updated during the next removal
145  remove_edge(*it_e, g); // REDUNDANT EDGES ARE REMOVED (can also remove t
146  // vertex if above ligne is uncommented)
147  }
148  edges_to_remove.clear();
152  // 5 unsure that the incident faces of s does not contain t vertex as incident
153  // vertex
154  // then remove similar faces
157  // facesRange = AIFHelpers::incident_faces(s);
158  // std::cout << "nb incident faces = " << facesRange.size() << std::endl;
161  // 6 remove t vertex
162  remove_vertex(t, g);
163 }
164 
165 
179 template< typename MutableFaceIncidentGraph >
180 void collapse_edge_keep_target(MutableFaceIncidentGraph &g,
181  typename boost::graph_traits<
182  MutableFaceIncidentGraph >::
183  edge_descriptor &e)
184 {
185  typedef boost::graph_traits< MutableFaceIncidentGraph > GraphTraits;
186  typedef typename GraphTraits::edge_descriptor edge_descriptor;
187 
188  auto pair_e_bool = edge(target(e, g), source(e, g), g);
189  if(pair_e_bool.second)
190  {
191  edge_descriptor retrieved_edge = pair_e_bool.first;
192  collapse_edge_keep_source(g, retrieved_edge);
193  }
194 }
195 
196 } // namespace Operators
197 } // namespace FEVV
FEVV::DataStructures::AIF::AIFTopologyHelpers::common_edge
static edge_descriptor common_edge(vertex_descriptor vertex1, vertex_descriptor vertex2)
Definition: AIFTopologyHelpers.h:458
FEVV::DataStructures::AIF::remove_vertex
void remove_vertex(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor v, FEVV::DataStructures::AIF::AIFMesh &sm)
Removes v from the mesh.
Definition: Graph_traits_aif.h:728
FEVV::Operators::collapse_edge_keep_source
void collapse_edge_keep_source(MutableFaceIncidentGraph &g, typename boost::graph_traits< MutableFaceIncidentGraph >::edge_descriptor &e)
Collapse an edge of the graph. The edge to collapse is given as a non-oriented edge....
Definition: collapse_edge.hpp:45
FEVV::DataStructures::AIF::degree
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::degree_size_type degree(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor u, const FEVV::DataStructures::AIF::AIFMesh &)
Definition: Graph_traits_aif.h:548
FEVV::Operators::resolve_similar_incident_faces
static void resolve_similar_incident_faces(typename boost::graph_traits< MutableFaceIncidentGraph >::vertex_descriptor v_to_keep, MutableFaceIncidentGraph &g, bool take_into_account_face_rientation=false)
Remove/resolve similar faces for all incident faces of v_to_keep vertex.
Definition: similarity.hpp:150
FEVV::DataStructures::AIF::remove_edge
void remove_edge(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor e, FEVV::DataStructures::AIF::AIFMesh &sm)
Remove edge e.
Definition: Graph_traits_aif.h:858
FEVV::DataStructures::AIF::AIFTopologyHelpers::vertex_position
static vertex_pos vertex_position(edge_descriptor edge, vertex_descriptor vertex)
Definition: AIFTopologyHelpers.h:1252
FEVV::DataStructures::AIF::AIFTopologyHelpers::null_edge
static edge_descriptor null_edge()
Definition: AIFTopologyHelpers.h:113
FEVV::DataStructures::AIF::AIFTopologyHelpers::add_edge
static edge_descriptor add_edge(ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:2772
FEVV::Operators::AIFHelpers
FEVV::DataStructures::AIF::AIFTopologyHelpers AIFHelpers
Definition: collapse_edge.hpp:28
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::DataStructures::AIF::remove_out_edge
void remove_out_edge(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::face_descriptor f, typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor e)
Definition: Graph_traits_aif.h:1042
FEVV::DataStructures::AIF::edge
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor edge(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the edge corresponding to h and opposite(h).
Definition: Graph_traits_aif.h:345
FEVV::Operators::collapse_edge_keep_target
void collapse_edge_keep_target(MutableFaceIncidentGraph &g, typename boost::graph_traits< MutableFaceIncidentGraph >::edge_descriptor &e)
Collapse an edge of the graph. The edge to collapse is given as a non-oriented edge....
Definition: collapse_edge.hpp:180
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
AIFMesh.hpp
FEVV::Operators::merge_similar_edges
static void merge_similar_edges(typename boost::graph_traits< MutableFaceIncidentGraph >::edge_descriptor e_to_keep, typename boost::graph_traits< MutableFaceIncidentGraph >::edge_descriptor e_to_remove, MutableFaceIncidentGraph &g)
For all faces incident to e_to_remove, if e_to_keep and e_to_remove were similar/parallel edges then ...
Definition: similarity.hpp:69
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::Operators::contains_similar_incident_edges
static bool contains_similar_incident_edges(const typename boost::graph_traits< FaceIncidentGraph >::vertex_descriptor v_to_keep, const FaceIncidentGraph &g)
Function determining if a pair of similar/parallel edges exists among the incident edges of vertex v_...
Definition: topology_predicates.hpp:62
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::Operators::resolve_similar_incident_edges
static void resolve_similar_incident_edges(typename boost::graph_traits< MutableFaceIncidentGraph >::vertex_descriptor v_to_keep, MutableFaceIncidentGraph &g)
Remove/resolve similar/parallel edges for all incident edges of v_to_keep vertex.
Definition: similarity.hpp:102
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
FEVV::DataStructures::AIF::AIFTopologyHelpers
This class is an helper class associated to the AIFMesh structure. AIFTopologyHelpers implements all ...
Definition: AIFTopologyHelpers.h:57
FEVV::DataStructures::AIF::AIFTopologyHelpers::clear_vertex
static void clear_vertex(vertex_descriptor vertex)
Definition: AIFTopologyHelpers.h:2946
similarity.hpp
FEVV::DataStructures::AIF::AIFTopologyHelpers::add_vertex
static vertex_descriptor add_vertex(ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:2709
FEVV::DataStructures::AIF::remove_face
void remove_face(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::face_descriptor f, FEVV::DataStructures::AIF::AIFMesh &sm)
Removes f from the mesh.
Definition: Graph_traits_aif.h:971