MEPP2 Project
clean_topology.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 
17 
18 #include <vector>
19 
20 namespace FEVV {
21 namespace Filters {
22 
45  template<typename FaceGraph>
46  bool clean_topology(FaceGraph& g,
47  bool remove_isolated_vertices=true,
48  bool remove_isolated_edges=true,
49  bool remove_isolated_faces=false,
50  bool remove_similar_edges=true,
51  bool remove_similar_faces=true)
52  {
53  bool ret = false;
54  if(remove_isolated_faces)
55  {
56  std::vector< typename boost::graph_traits<FaceGraph>::face_descriptor > f_to_remove;
57  auto iterator_pair_f = faces(g);
58  auto fi = iterator_pair_f.first;
59  auto fi_end = iterator_pair_f.second;
60  for (; fi != fi_end; ++fi)
61  {
63  f_to_remove.push_back(*fi);
64  }
65  if (!f_to_remove.empty())
66  ret = true;
68  f_to_remove.begin(), f_to_remove.end(), g);
69  }
70  if(remove_isolated_edges)
71  {
72  std::vector< typename boost::graph_traits<FaceGraph>::edge_descriptor > e_to_remove;
73  auto iterator_pair_e = edges(g);
74  auto ei = iterator_pair_e.first;
75  auto ei_end = iterator_pair_e.second;
76  for (; ei != ei_end; ++ei)
77  {
79  e_to_remove.push_back(*ei);
80  }
81  if (!e_to_remove.empty())
82  ret = true;
84  e_to_remove.begin(), e_to_remove.end(), g);
85  }
86  if(remove_isolated_vertices)
87  {
89  auto iterator_pair_v = vertices(g);
90  auto vi = iterator_pair_v.first;
91  auto vi_end = iterator_pair_v.second;
92  for (; vi != vi_end; ++vi)
93  {
95  v_to_remove.push_back(*vi);
96  }
97  std::sort(v_to_remove.begin(),
98  v_to_remove.end(),
100  const typename boost::graph_traits<FaceGraph>::vertex_descriptor & v2) -> bool
101  {
102  return v1->GetIndex() > v2->GetIndex();
103  }); // to remove first vertices with higher index value
104  if (!v_to_remove.empty())
105  ret = true;
107  v_to_remove.begin(), v_to_remove.end(), g);
108  }
109  // remove similar faces and edges
110  size_t nb_e = size_of_edges(g), nb_f = size_of_faces(g);
111  if(remove_similar_faces)
113  if(remove_similar_edges)
115  if ((nb_e != size_of_edges(g)) || (nb_f != size_of_faces(g)))
116  ret = true;
117  return ret;
118  }
119 
120 } // namespace Filters
121 } // namespace FEVV
122 
FEVV::DataStructures::AIF::vertices
std::pair< typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_iterator, typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_iterator > vertices(const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the iterator range of the vertices of the mesh.
Definition: Graph_traits_aif.h:172
FEVV::DataStructures::AIF::AIFTopologyHelpers::remove_faces
static void remove_faces(InputIt first, InputIt last, MeshType &mesh)
Definition: AIFTopologyHelpers.h:3193
FEVV::DataStructures::AIF::AIFTopologyHelpers::is_isolated_edge
static bool is_isolated_edge(edge_descriptor edge)
Definition: AIFTopologyHelpers.h:995
FEVV::DataStructures::AIF::AIFTopologyHelpers::is_isolated_face
static bool is_isolated_face(face_descriptor face)
Definition: AIFTopologyHelpers.h:1511
FEVV::DataStructures::AIF::edges
std::pair< typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_iterator, typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_iterator > edges(const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the iterator range of the edges of the mesh.
Definition: Graph_traits_aif.h:238
FEVV::DataStructures::AIF::AIFTopologyHelpers::remove_edges
static void remove_edges(InputIt first, InputIt last, MeshType &mesh)
Definition: AIFTopologyHelpers.h:3067
FEVV::Filters::resolve_similar_edges
static void resolve_similar_edges(MutableFaceIncidentGraph &g)
Remove/resolve similar edges for the given mesh g.
Definition: resolve_similar_edges.hpp:29
FEVV::Filters::clean_topology
bool clean_topology(FaceGraph &g, bool remove_isolated_vertices=true, bool remove_isolated_edges=true, bool remove_isolated_faces=false, bool remove_similar_edges=true, bool remove_similar_faces=true)
Function use for cleaning the topology of mesh g. This can be seen as a preprocessing step for some g...
Definition: clean_topology.hpp:46
FEVV::size_of_edges
boost::graph_traits< MeshT >::edges_size_type size_of_edges(const MeshT &g)
Real current number of edges of the mesh. Generic version.
Definition: Graph_traits_extension.h:46
FEVV::Filters::resolve_similar_faces
static void resolve_similar_faces(MutableFaceIncidentGraph &g, bool take_into_account_face_rientation=false)
Remove/resolve similar faces for the given mesh g.
Definition: resolve_similar_faces.hpp:31
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::DataStructures::AIF::faces
std::pair< typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::face_iterator, typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::face_iterator > faces(const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns an iterator range over all faces of the mesh.
Definition: Graph_traits_aif.h:679
FEVV::DataStructures::AIF::AIFTopologyHelpers::is_isolated_vertex
static bool is_isolated_vertex(vertex_descriptor vertex)
Definition: AIFTopologyHelpers.h:159
resolve_similar_faces.hpp
resolve_similar_edges.hpp
FEVV::size_of_faces
boost::graph_traits< MeshT >::faces_size_type size_of_faces(const MeshT &g)
Real current number of faces of the mesh. Generic version.
Definition: Graph_traits_extension.h:80
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
FEVV::DataStructures::AIF::AIFTopologyHelpers::remove_vertices
static void remove_vertices(InputIt first, InputIt last, MeshType &mesh)
Definition: AIFTopologyHelpers.h:3000