MEPP2 Project
copy_graph.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 
18 
19 #include <map>
20 
21 
22 namespace FEVV {
23 namespace Filters {
24 
25 
29 template< typename BoostGraphS,
30  typename BoostGraphT >
31 using VertexToVertexMap = std::map<
34 
35 
39 template< typename FaceGraphS,
40  typename FaceGraphT >
41 using FaceToFaceMap = std::map<
42  typename boost::graph_traits< FaceGraphS >::face_descriptor,
43  typename boost::graph_traits< FaceGraphT >::face_descriptor >;
44 
45 
52 template< typename FaceGraphS,
53  typename FaceGraphT >
55 {
58 
60  {
61  m_v2v = _v2v;
62  return *this;
63  }
64 
66  {
67  m_f2f = _f2f;
68  return *this;
69  }
70 
71  V2VMap *m_v2v = nullptr;
72  F2FMap *m_f2f = nullptr;
73 };
74 
75 
90 template< typename FaceListGraphS,
91  typename FaceListGraphT,
92  typename Parameters,
93  typename GeometryTraitsS,
94  typename GeometryTraitsT >
95 void
96 copy_graph(const FaceListGraphS &g_s,
97  const PMapsContainer &pmaps_s,
98  FaceListGraphT &g_t,
99  PMapsContainer &pmaps_t,
100  const Parameters &params,
101  const GeometryTraitsS &gt_s,
102  const GeometryTraitsT &gt_t)
103 {
104  // build the vector representation of the source mesh
105 
106  // TODO-elo templatize this 4 types ? Extract them from the mesh type ?
107  typedef double coordP_type; // position coordinate type
108  typedef double coordN_type; // normal coordinate type
109  typedef float coordC_type; // color coordinate type
110  typedef float coordT_type; // texture coordinate type
111  typedef size_t index_type;
112 
113  FEVV::Types::MVR< coordP_type,
114  coordN_type,
115  coordT_type,
116  coordC_type,
117  index_type > mvr;
118 
119  mesh_to_vector_representation(g_s, pmaps_s, mvr, gt_s);
120 
121  // build the target mesh from the vector representation
122 
123  unsigned int duplicated_vertices_nbr = 0;
126  bool use_corner_texture_coord = has_map(pmaps_s, halfedge_texcoord);
127 
129 
131  pmaps_t,
132  duplicated_vertices_nbr,
133  mvr,
134  mfv_params.vd_target(&vd_target)
135  .fd_target(&fd_target)
137  use_corner_texture_coord),
138  gt_t);
139 
140  // populate v2v and f2f maps if provided
141 
142  // populate v2v map
143  if(params.m_v2v)
144  {
145  // reset v2v map
146  params.m_v2v->clear();
147 
148  // ensure there are as many source vertices than target vertices
149  if(size_of_vertices(g_s) == vd_target.size())
150  {
151  // loop over source mesh vertices
152  auto v_iter_pair = vertices(g_s);
153  auto vi = v_iter_pair.first;
154  auto vi_end = v_iter_pair.second;
155  size_t i = 0;
156  for(; vi != vi_end; ++vi)
157  {
158  // source vertices and vd_target are in the same order
159  (*params.m_v2v)[*vi] = vd_target[i];
160  i++;
161  }
162  }
163  else
164  {
165  std::cout << "copy_graph(): WARNING unable to build v2v map because "
166  " source and target have not the same number of vertices."
167  << std::endl;
168  }
169  }
170 
171  // populate f2f map
172  if(params.m_f2f)
173  {
174  // reset f2f map
175  params.m_f2f->clear();
176 
177  // ensure there are as many source faces than target faces
178  if(size_of_faces(g_s) == fd_target.size())
179  {
180  // loop over source mesh faces
181  auto f_iter_pair = faces(g_s);
182  auto fi = f_iter_pair.first;
183  auto fi_end = f_iter_pair.second;
184  size_t i = 0;
185  for(; fi != fi_end; ++fi)
186  {
187  // source faces and fd_target are in the same order
188  (*params.m_f2f)[*fi] = fd_target[i];
189  i++;
190  }
191  }
192  else
193  {
194  std::cout << "copy_graph(): WARNING unable to build f2f map because "
195  " source and target have not the same number of faces."
196  << std::endl;
197  }
198  }
199 
200  // display some information
201 
202  std::cout << "copy_graph(): input mesh has "
203  << size_of_vertices(g_s) << " vertices, "
204  << size_of_edges(g_s) << " edges, "
205  << size_of_faces(g_s) << " faces."
206  << std::endl;
207  std::cout << "copy_graph(): input mesh has property maps: [";
208  for(auto &name: list_property_maps(pmaps_s))
209  std::cout << " " << name;
210  std::cout << " ]" << std::endl;
211 
212  std::cout << "copy_graph(): output mesh has "
213  << size_of_vertices(g_t) << " vertices, "
214  << size_of_edges(g_t) << " edges, "
215  << size_of_faces(g_t) << " faces."
216  << std::endl;
217  if(duplicated_vertices_nbr > 0)
218  {
219  std::cout << "copy_graph(): "
220  << duplicated_vertices_nbr << " vertices were duplicated."
221  << std::endl;
222  }
223  std::cout << "copy_graph(): output mesh has property maps: [";
224  for(auto &name: list_property_maps(pmaps_t))
225  std::cout << " " << name;
226  std::cout << " ]" << std::endl;
227 }
228 
229 
241 template< typename FaceListGraphS,
242  typename FaceListGraphT,
243  typename Parameters =
244  CopyGraphParameters< FaceListGraphS, FaceListGraphT >,
245  typename GeometryTraitsS = FEVV::Geometry_traits< FaceListGraphS >,
246  typename GeometryTraitsT = FEVV::Geometry_traits< FaceListGraphT > >
247 void
248 copy_graph(const FaceListGraphS &g_s,
249  const PMapsContainer &pmap_s,
250  FaceListGraphT &g_t,
251  PMapsContainer &pmap_t,
252  const Parameters &params =
254 {
255  GeometryTraitsS gt_s(g_s);
256  GeometryTraitsT gt_t(g_t);
257  copy_graph(g_s, pmap_s, g_t, pmap_t, params, gt_s, gt_t);
258 }
259 
260 
273 template< typename FaceListGraphS,
274  typename FaceListGraphT,
275  typename Parameters,
276  typename GeometryTraitsS,
277  typename GeometryTraitsT >
278 void
279 copy_graph(const FaceListGraphS &g_s,
280  FaceListGraphT &g_t,
281  const Parameters &params,
282  const GeometryTraitsS &gt_s,
283  const GeometryTraitsT &gt_t)
284 {
285  PMapsContainer pmaps_s; // empty bag
286  PMapsContainer pmaps_t; // empty bag
287 
288  copy_graph(g_s, pmaps_s, g_t, pmaps_t, params, gt_s, gt_t);
289 }
290 
291 
301 template< typename FaceListGraphS,
302  typename FaceListGraphT,
303  typename Parameters =
304  CopyGraphParameters< FaceListGraphS, FaceListGraphT >,
305  typename GeometryTraitsS = FEVV::Geometry_traits< FaceListGraphS >,
306  typename GeometryTraitsT = FEVV::Geometry_traits< FaceListGraphT > >
307 void
308 copy_graph(const FaceListGraphS &g_s,
309  FaceListGraphT &g_t,
310  const Parameters &params =
312 {
313  GeometryTraitsS gt_s(g_s);
314  GeometryTraitsT gt_t(g_t);
315  copy_graph(g_s, g_t, params, gt_s, gt_t);
316 }
317 
318 
319 } // namespace Filters
320 } // namespace FEVV
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::Filters::VertexToVertexMap
std::map< typename boost::graph_traits< BoostGraphS >::vertex_descriptor, typename boost::graph_traits< BoostGraphT >::vertex_descriptor > VertexToVertexMap
Definition: copy_graph.hpp:33
FEVV::Types::MVR
Definition: Mesh_vector_representation.h:32
FEVV::Filters::MeshFromVectorReprParameters::use_corner_texcoord
MeshFromVectorReprParameters & use_corner_texcoord(bool _use_corner_texcoord)
Definition: mesh_from_vector_representation.hpp:96
FEVV::Filters::copy_graph
void copy_graph(const FEVV::CGALPointSet &pc_s, const FEVV::PMapsContainer &pmaps_s, PointCloudT &pc_t, FEVV::PMapsContainer &pmaps_t, const Parameters &params, const GeometryTraitsS &gt_s, const GeometryTraitsT &gt_t)
Overloading of copy_graph() for CGAL Point Set copy from.
Definition: copy_graph_cgal_point_set.hpp:43
mesh_to_vector_representation.hpp
FEVV::Filters::CopyGraphParameters::v2v
CopyGraphParameters & v2v(V2VMap *_v2v)
Definition: copy_graph.hpp:59
FEVV::has_map
bool has_map(const PMapsContainer &pmaps, const std::string &map_name)
(refer to Property Maps API)
Definition: properties.h:103
FEVV::Filters::mesh_from_vector_representation
void mesh_from_vector_representation(HalfedgeGraph &g, FEVV::PMapsContainer &pmaps, unsigned int &dup_v_nbr, FEVV::Types::MVR< coordP_type, coordN_type, coordT_type, coordC_type, index_type > &mvr, MeshFromVectorReprParameters< HalfedgeGraph > const &params, const GeometryTraits &)
Build the mesh from the given vector representation.
Definition: mesh_from_vector_representation.hpp:142
FEVV::Geometry_traits
Refer to Geometry_traits_documentation_dummy for further documentation on provided types and algorith...
Definition: Geometry_traits.h:162
FEVV::Filters::CopyGraphParameters::F2FMap
FaceToFaceMap< FaceGraphS, FaceGraphT > F2FMap
Definition: copy_graph.hpp:57
FEVV::Filters::CopyGraphParameters
Definition: copy_graph.hpp:55
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::PMapsContainer
std::map< std::string, boost::any > PMapsContainer
Definition: properties.h:99
FEVV::Filters::MeshFromVectorReprParameters
Definition: mesh_from_vector_representation.hpp:92
FEVV::Filters::CopyGraphParameters::f2f
CopyGraphParameters & f2f(F2FMap *_f2f)
Definition: copy_graph.hpp:65
FEVV::Filters::MeshFromVectorReprParameters::vd_target
MeshFromVectorReprParameters & vd_target(VDVect *_vd_target)
Definition: mesh_from_vector_representation.hpp:103
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::Filters::FaceDescVect
std::vector< typename boost::graph_traits< FaceGraph >::face_descriptor > FaceDescVect
Definition: mesh_from_vector_representation.hpp:80
FEVV::list_property_maps
std::vector< std::string > list_property_maps(const PMapsContainer &pmaps)
Definition: properties.h:708
mesh_from_vector_representation.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::Filters::mesh_to_vector_representation
void mesh_to_vector_representation(const FaceListGraph &g, const FEVV::PMapsContainer &pmaps, FEVV::Types::MVR< coordP_type, coordN_type, coordT_type, coordC_type, index_type > &mvr, const GeometryTraits &)
Build the vector representation of the mesh.
Definition: mesh_to_vector_representation.hpp:44
FEVV::Filters::FaceToFaceMap
std::map< typename boost::graph_traits< FaceGraphS >::face_descriptor, typename boost::graph_traits< FaceGraphT >::face_descriptor > FaceToFaceMap
Definition: copy_graph.hpp:43
FEVV::Filters::CopyGraphParameters::m_f2f
F2FMap * m_f2f
Definition: copy_graph.hpp:72
FEVV::Filters::CopyGraphParameters::m_v2v
V2VMap * m_v2v
Definition: copy_graph.hpp:71
properties.h
FEVV::halfedge_texcoord
@ halfedge_texcoord
Definition: properties.h:69
FEVV::Filters::VertDescVect
std::vector< typename boost::graph_traits< BoostGraph >::vertex_descriptor > VertDescVect
Definition: mesh_from_vector_representation.hpp:72
FEVV::Filters::Parameters
Parameters contains the compression parameters except the stopping criteria.
Definition: Parameters.h:46
FEVV::Filters::CopyGraphParameters::V2VMap
VertexToVertexMap< FaceGraphS, FaceGraphT > V2VMap
Definition: copy_graph.hpp:56
Mesh_vector_representation.h
FEVV::size_of_vertices
boost::graph_traits< MeshT >::vertices_size_type size_of_vertices(const MeshT &g)
Real current number of vertices of the mesh. Generic version.
Definition: Graph_traits_extension.h:29
FEVV::Filters::MeshFromVectorReprParameters::fd_target
MeshFromVectorReprParameters & fd_target(FDVect *_fd_target)
Definition: mesh_from_vector_representation.hpp:109