MEPP2 Project
helloworld_filter.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 
15 
21 template< typename HalfedgeGraph,
22  typename PointMap,
23  typename VertexColorMap,
24  typename VertexNormalMap,
25  typename GeometryTraits = FEVV::Geometry_traits< HalfedgeGraph > >
26 void
27 helloworld_filter(const HalfedgeGraph &g,
28  PointMap &pm,
29  VertexColorMap &v_cm,
30  VertexNormalMap &v_nm,
31  const GeometryTraits &gt)
32 {
33  typedef boost::graph_traits< HalfedgeGraph > GraphTraits;
34  typedef typename GraphTraits::vertex_iterator vertex_iterator;
35  //typedef typename GraphTraits::face_descriptor face_descriptor;
36  typedef typename GraphTraits::face_iterator face_iterator;
37  typedef typename boost::property_traits< PointMap >::value_type Point;
38  typedef typename boost::property_traits< VertexColorMap >::value_type Color;
39  typedef typename boost::property_traits< VertexNormalMap >::value_type Normal;
40 
41  // notes:
42  // - a property map stores a single property value for each
43  // vertex/halfedge/face it is related to ;
44  // - the property map content can only be accessed with a
45  // vertex/halfedge/face identifier (called a 'descriptor') ;
46  // - in order to display the whole property map content one must loop
47  // over all vertices/halfedges/faces
48 
49  // loop over vertices
50  int counter = 0;
51  auto iterator_pair = vertices(g);
52  // vertices() returns a vertex_iterator pair ;
53  // the same for faces(g) and edges(g)
54  vertex_iterator vi = iterator_pair.first;
55  vertex_iterator vi_end = iterator_pair.second;
56  for(; vi != vi_end; ++vi)
57  {
58  counter++;
59  std::cout << "processing vertex #" << counter << std::endl;
60 
61  // read property map data
62  Point p = get(pm, *vi); // gt.get_x(p), gt.get_y(p), gt.get_z(p)
63  Color c = get(v_cm, *vi); // c[0], c[1], c[2]
64  Normal n = get(v_nm, *vi); // n[0], n[1], n[2]
65 
66  // write property map data
67  Point newpoint(gt.get_x(p) + 1, gt.get_y(p) + 2, gt.get_z(p) + 1);
68  put(pm, *vi, newpoint);
69  Color newcolor(c[0]/2.0, c[1]/2.0, c[2]/2.0);
70  put(v_cm, *vi, newcolor);
71  Normal newnormal(n[0]/2.0, n[1]/2.0, n[2]/2.0);
72  put(v_nm, *vi, newnormal);
73  }
74 
75  // create and populate a filter-specific property map related to faces
76 
77  // create a property map
78  typename FEVV::Face_pmap< HalfedgeGraph, float > my_property_map;
79  my_property_map = FEVV::make_face_property_map< HalfedgeGraph, float >(g);
80 
81  // populate the property map
82  // loop over the faces
83  auto face_iterator_pair = faces(g);
84  face_iterator fi = face_iterator_pair.first;
85  face_iterator fi_end = face_iterator_pair.second;
86  for(; fi != fi_end; ++fi)
87  {
88  static float value = 42.1f;
89  put(my_property_map, *fi, value);
90  value += 1.0f;
91  }
92 
93  // display the property map
94  // loop over the faces
95  counter = 0;
96  fi = face_iterator_pair.first;
97  for(; fi != fi_end; ++fi)
98  {
99  counter++;
100  float value = get(my_property_map, *fi);
101  std::cout << "my_property_map[face#" << counter << "] = " << value
102  << std::endl;
103  }
104 }
105 
106 // Helper function to simplify (syntactic sugar) the call to helloworld_filter
107 template< typename HalfedgeGraph,
108  typename PointMap,
109  typename VertexColorMap,
110  typename VertexNormalMap,
111  typename GeometryTraits = FEVV::Geometry_traits< HalfedgeGraph > >
112 void
113 helloworld_filter(const HalfedgeGraph &g,
114  PointMap &pm,
115  VertexColorMap &v_cm,
116  VertexNormalMap &v_nm)
117 
118 {
119  GeometryTraits gt(g);
120  helloworld_filter(g, pm, v_cm, v_nm, gt);
121 }
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::Geometry_traits< HalfedgeGraph >
Point
AIFMesh::Point Point
Definition: Graph_properties_aif.h:21
FEVV::Face_pmap
typename Face_pmap_traits< MeshT, ValueT >::pmap_type Face_pmap
Definition: properties.h:610
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
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
Geometry_traits.h
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
properties.h
FEVV::DataStructures::AIF::AIFPoint
Definition: AIFProperties.h:31
FEVV::DataStructures::AIF::put
void put(const typename FEVV::DataStructures::AIF::PropertyMap< ValueT > &pm, KeyT k, const ValueT &v)
Specialization of put(pmap, key, value) for AIF.
Definition: Graph_properties_aif.h:214