MEPP2 Project
helloworld_main.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 
16 
23 template< typename MeshT >
24 int
25 helloworld_main(int argc, const char **argv)
26 {
27  if(argc != 2)
28  {
29  std::cout << "Apply a dummy filter to the input mesh." << std::endl;
30  std::cout << "Usage: " << argv[0] << " input_mesh_filename" << std::endl;
31  std::cout << "Example: " << argv[0]
32  << " ../Testing/Data/CubeNonTriangleFaces.off" << std::endl;
33  return EXIT_FAILURE;
34  }
35 
36  // input and output files
37  std::string input_file_path = argv[1];
38  std::string output_file_path = "helloWorldFilter.output.obj";
39 
40  // read mesh from file
41  MeshT m;
42  FEVV::PMapsContainer pmaps_bag;
43  FEVV::Filters::read_mesh(input_file_path, m, pmaps_bag);
44 
45  // Note: the property maps must be extracted from the
46  // property maps bag, and explicitely passed as
47  // parameters to the filter, in order to make
48  // clear what property is used by the filter
49 
50  // retrieve or create vertex-color property map
51  using VertexColorMap =
53  VertexColorMap v_cm;
54  if(has_map(pmaps_bag, FEVV::vertex_color))
55  {
56  std::cout << "use existing vertex-color map" << std::endl;
57  v_cm = get_property_map(FEVV::vertex_color, m, pmaps_bag);
58  }
59  else
60  {
61  std::cout << "create vertex-color map" << std::endl;
63  // store property map in property maps bag
64  put_property_map(FEVV::vertex_color, m, pmaps_bag, v_cm);
65  }
66 
67  // retrieve or create vertex-normal property map
68  using VertexNormalMap =
70  VertexNormalMap v_nm;
71  if(has_map(pmaps_bag, FEVV::vertex_normal))
72  {
73  std::cout << "use existing vertex-normal map" << std::endl;
74  v_nm = get_property_map(FEVV::vertex_normal, m, pmaps_bag);
75  }
76  else
77  {
78  std::cout << "create vertex-normal map" << std::endl;
80  // store property map in property maps bag
81  put_property_map(FEVV::vertex_normal, m, pmaps_bag, v_nm);
82  }
83 
84  // retrieve point property map (aka geometry)
85  auto pm = get(boost::vertex_point, m);
86 
87  // apply filter
88  helloworld_filter(m, pm, v_cm, v_nm);
89 
90  // write mesh to file
91  FEVV::Filters::write_mesh(output_file_path, m, pmaps_bag);
92 
93  return 0;
94 }
FEVV::put_property_map
void put_property_map(PropertyT p, const MeshT &, PMapsContainer &pmaps, const typename PMap_traits< PropertyT, MeshT >::pmap_type &pmap)
Definition: properties.h:664
FEVV::get_property_map
PMap_traits< PropertyT, MeshT >::pmap_type get_property_map(PropertyT p, const MeshT &, const PMapsContainer &pmaps)
Definition: properties.h:646
FEVV::has_map
bool has_map(const PMapsContainer &pmaps, const std::string &map_name)
(refer to Property Maps API)
Definition: properties.h:103
generic_reader.hpp
FEVV::PMapsContainer
std::map< std::string, boost::any > PMapsContainer
Definition: properties.h:99
helloworld_filter
void helloworld_filter(const HalfedgeGraph &g, PointMap &pm, VertexColorMap &v_cm, VertexNormalMap &v_nm, const GeometryTraits &gt)
Refer here for a detailed presentation of that filter example, what it does and how to use it.
Definition: helloworld_filter.hpp:27
FEVV::Filters::read_mesh
void read_mesh(const std::string &filename, FEVV::CGALPointSet &g, PMapsContainer &pmaps, bool=false)
Load mesh from file.
Definition: cgal_point_set_reader.hpp:110
FEVV::vertex_color
@ vertex_color
Definition: properties.h:47
FEVV::Filters::write_mesh
void write_mesh(const std::string &filename, FEVV::CGALPointSet &g, PMapsContainer &pmaps)
Write mesh to file.
Definition: cgal_point_set_writer.hpp:42
generic_writer.hpp
boost::get
boost::property_map< FEVV::DataStructures::AIF::AIFMesh, boost::vertex_index_t >::const_type get(const boost::vertex_index_t &, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the vertex index property map of the mesh.
Definition: Graph_properties_aif.h:108
FEVV::DataStructures::AIF::AIFMesh
This class represents an AIF structure. AIF structure can deal with both manifold and non-manifold su...
Definition: AIFMesh.hpp:47
helloworld_filter.hpp
FEVV::_PMap_traits
Definition: properties.h:376
helloworld_main
int helloworld_main(int argc, const char **argv)
A mesh type templated main(argc, argv) function that.
Definition: helloworld_main.hpp:25
FEVV::vertex_normal
@ vertex_normal
Definition: properties.h:35
FEVV::make_property_map
PMap_traits< PropertyT, MeshT >::pmap_type make_property_map(PropertyT, const MeshT &m)
Definition: properties.h:630