MEPP2 Project
flip_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 <CGAL/boost/graph/internal/helpers.h> // set_border
14 #include <boost/graph/graph_traits.hpp>
15 #include <CGAL/boost/graph/iterator.h>
16 
17 #include <CGAL/boost/graph/Euler_operations.h> // for add_face(vr,g)
18 
19 #include <CGAL/boost/graph/helpers.h> // is_border + is_triangle_mesh
20 
21 #include <cassert>
22 
24 
25 namespace FEVV {
26 namespace Operators {
27 
40 template< typename MutableFaceGraph >
41 void
43  MutableFaceGraph &g,
44  typename boost::graph_traits< MutableFaceGraph >::halfedge_descriptor &h)
45 {
46  typedef FEVV::Geometry_traits< MutableFaceGraph > GeometryTraits;
47 
48  typedef boost::graph_traits< MutableFaceGraph > GraphTraits;
49  typedef typename GraphTraits::halfedge_descriptor halfedge_descriptor;
51  typedef typename GraphTraits::face_descriptor face_descriptor;
52  GeometryTraits gt(g);
53 
54  if(h == boost::graph_traits< MutableFaceGraph >::null_halfedge())
55  return;
56 
57  halfedge_descriptor opp_h = opposite(h, g);
58  // ensure the edge is incident to 2 triangles (only)
59  if(CGAL::is_border(h, g))
60  {
61  return;
62  }
63  else if(CGAL::is_border(opp_h, g))
64  {
65  return;
66  }
67  else
68  {
69  if(!CGAL::is_triangle(h, g) || !CGAL::is_triangle(opp_h, g))
70  return;
71  }
72 
73  // deal with vertex geometry
74  vertex_descriptor vs = source(h, g);
75  vertex_descriptor vt = target(h, g);
76 
77  typedef CGAL::Halfedge_around_face_iterator< MutableFaceGraph >
78  Halfedge_around_face_iterator;
79  vertex_descriptor midpoint_vertex;
80 
81  std::vector< vertex_descriptor > face_vertices;
82  // here we assume a 2_manifold context
83  vertex_descriptor opp_v1 = target(next(h, g), g);
84  vertex_descriptor opp_v2 = target(next(opp_h, g), g);
85 
86  halfedge_descriptor h1 = next(h, g), h2 = prev(h, g);
87  halfedge_descriptor h3 = next(opp_h, g), h4 = prev(opp_h, g);
88  remove_face(face(h, g), g);
89  CGAL::internal::set_border(h1, g);
90  CGAL::internal::set_border(h2, g);
91 
92  remove_face(face(opp_h, g), g);
93  CGAL::internal::set_border(h3, g);
94  CGAL::internal::set_border(h4, g);
95 
96  face_vertices.push_back(vs);
97  face_vertices.push_back(opp_v2);
98  face_vertices.push_back(opp_v1);
99  face_descriptor f1 = CGAL::Euler::add_face(face_vertices, g);
100  face_vertices.clear();
101  face_vertices.push_back(opp_v1);
102  face_vertices.push_back(opp_v2);
103  face_vertices.push_back(vt);
104  face_descriptor f2 = CGAL::Euler::add_face(face_vertices, g);
106  Halfedge_around_face_iterator hi, he;
107  //int cpt = 0;
108  for(boost::tie(hi, he) = CGAL::halfedges_around_face(halfedge(f1, g), g);
109  hi != he;
110  ++hi)
111  {
112  if(CGAL::is_border_edge(*hi, g))
113  {
114  // std::cout << "border!" << std::endl;
115  CGAL::internal::set_border(opposite(*hi, g), g);
116  }
117  }
118  for(boost::tie(hi, he) = CGAL::halfedges_around_face(halfedge(f2, g), g);
119  hi != he;
120  ++hi)
121  {
122  if(CGAL::is_border_edge(*hi, g))
123  {
124  // std::cout << "border!" << std::endl;
125  CGAL::internal::set_border(opposite(*hi, g), g);
126  }
127  }
128 }
129 
130 } // namespace Operators
131 } // namespace FEVV
CGAL::Euler::add_face
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::face_descriptor add_face(const VertexRange &vr, FEVV::DataStructures::AIF::AIFMesh &g)
Definition: Graph_traits_aif.h:1104
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::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::Geometry_traits
Refer to Geometry_traits_documentation_dummy for further documentation on provided types and algorith...
Definition: Geometry_traits.h:162
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::DataStructures::AIF::halfedge
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor halfedge(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor v, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns a halfedge with target v.
Definition: Graph_traits_aif.h:296
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::DataStructures::AIF::prev
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor prev(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the previous halfedge around its face.
Definition: Graph_traits_aif.h:612
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
FEVV::DataStructures::AIF::face
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::face_descriptor face(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the face incident to halfedge h.
Definition: Graph_traits_aif.h:664
FEVV::Operators::flip_edge
void flip_edge(MutableFaceGraph &g, typename boost::graph_traits< MutableFaceGraph >::halfedge_descriptor &h)
Flip an edge of the graph. The edge to flip is given as a halfedge.
Definition: flip_edge.hpp:42
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