MEPP2 Project
test_normalize_vector_map.inl
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 
13 
14 #include <iostream>
15 #include <cmath>
16 
17 #undef NEAR
18 #define NEAR(val1, val2, epsilon) (fabs((val1)-(val2)) <= (epsilon))
19 
20 #undef NDEBUG // enable assert in release mode
21  // must be the last include to avoid side effect
22 #include <cassert>
23 
24 
25 template< typename MeshT >
26 int
28 {
29  typedef FEVV::Geometry_traits< MeshT > GeometryTraits;
30  typedef typename GeometryTraits::Vector Vector;
31 
32  MeshT m;
33  GeometryTraits gt(m);
34 
35  float eps = 1e-5f;
36 
37  // test vertex vector map normalization
38 
39  {
40  auto v1 = add_vertex(m);
41  auto v2 = add_vertex(m);
42 
43  auto vn_pm = make_property_map(FEVV::vertex_normal, m);
44  put(vn_pm, v1, Vector(2.0f, 3.0f, 4.0f));
45  put(vn_pm, v2, Vector(3.0f, 4.0f, 2.0f));
46 
48 
49  auto vec1 = get(vn_pm, v1);
50  std::cout << "v vec1 = " << vec1[0] << " " << vec1[1] << " " << vec1[2]
51  << std::endl;
52  assert(NEAR(vec1[0], 0.371391f, eps));
53  assert(NEAR(vec1[1], 0.557086f, eps));
54  assert(NEAR(vec1[2], 0.742781f, eps));
55 
56  auto vec2 = get(vn_pm, v2);
57  std::cout << "v vec2 = " << vec2[0] << " " << vec2[1] << " " << vec2[2]
58  << std::endl;
59  assert(NEAR(vec2[0], 0.557086f, eps));
60  assert(NEAR(vec2[1], 0.742781f, eps));
61  assert(NEAR(vec2[2], 0.371391f, eps));
62  }
63 
64  // test face vector map normalization
65 
66  {
67  auto f1 = add_face(m);
68  auto f2 = add_face(m);
69 
70  auto fn_pm = make_property_map(FEVV::face_normal, m);
71  put(fn_pm, f1, Vector(4.0f, 2.0f, 3.0f));
72  put(fn_pm, f2, Vector(2.0f, 3.0f, 4.0f));
73 
75 
76  auto vec1 = get(fn_pm, f1);
77  std::cout << "f vec1 = " << vec1[0] << " " << vec1[1] << " " << vec1[2]
78  << std::endl;
79  assert(NEAR(vec1[0], 0.742781f, eps));
80  assert(NEAR(vec1[1], 0.371391f, eps));
81  assert(NEAR(vec1[2], 0.557086f, eps));
82 
83  auto vec2 = get(fn_pm, f2);
84  std::cout << "f vec2 = " << vec2[0] << " " << vec2[1] << " " << vec2[2]
85  << std::endl;
86  assert(NEAR(vec2[0], 0.371391f, eps));
87  assert(NEAR(vec2[1], 0.557086f, eps));
88  assert(NEAR(vec2[2], 0.742781f, eps));
89  }
90 
91  // test halfedge vector map normalization
92 
93  {
94  auto e1 = add_edge(m);
95  auto h1 = halfedge(e1, m);
96  auto h2 = opposite(h1, m);
97 
99  put(hn_pm, h1, Vector(3.0f, 4.0f, 2.0f));
100  put(hn_pm, h2, Vector(4.0f, 2.0f, 3.0f));
101 
103 
104  auto vec1 = get(hn_pm, h1);
105  std::cout << "h vec1 = " << vec1[0] << " " << vec1[1] << " " << vec1[2]
106  << std::endl;
107  assert(NEAR(vec1[0], 0.557086f, eps));
108  assert(NEAR(vec1[1], 0.742781f, eps));
109  assert(NEAR(vec1[2], 0.371391f, eps));
110 
111  auto vec2 = get(hn_pm, h2);
112  std::cout << "h vec2 = " << vec2[0] << " " << vec2[1] << " " << vec2[2]
113  << std::endl;
114  assert(NEAR(vec2[0], 0.742781f, eps));
115  assert(NEAR(vec2[1], 0.371391f, eps));
116  assert(NEAR(vec2[2], 0.557086f, eps));
117  }
118 
119  return 0;
120 }
Vector
AIFMesh::Vector Vector
Definition: Graph_properties_aif.h:22
FEVV::Filters::normalize_vector_map_vertices
void normalize_vector_map_vertices(const HalfedgeGraph &g, PropertyMap &prop_map)
Normalize each vector of the vertex property map.
Definition: normalize_vector_map.h:55
FEVV::Filters::normalize_vector_map_faces
void normalize_vector_map_faces(const HalfedgeGraph &g, PropertyMap &prop_map)
Normalize each vector of the face property map.
Definition: normalize_vector_map.h:75
FEVV::Filters::normalize_vector_map_halfedges
void normalize_vector_map_halfedges(const HalfedgeGraph &g, PropertyMap &prop_map)
Normalize each vector of the halfedge property map.
Definition: normalize_vector_map.h:115
FEVV::DataStructures::AIF::add_face
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::face_descriptor add_face(FEVV::DataStructures::AIF::AIFMesh &sm)
Adds a new face to the graph without initializing the connectivity.
Definition: Graph_traits_aif.h:1056
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
NEAR
#define NEAR(val1, val2, epsilon)
Definition: test_normalize_vector_map.inl:18
test_normalize_vector_map
int test_normalize_vector_map(void)
Definition: test_normalize_vector_map.inl:27
normalize_vector_map.h
FEVV::DataStructures::AIF::add_edge
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor add_edge(FEVV::DataStructures::AIF::AIFMesh &sm)
Adds two opposite halfedges to the graph without initializing the connectivity.
Definition: Graph_traits_aif.h:827
FEVV::halfedge_normal
@ halfedge_normal
Definition: properties.h:65
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::add_vertex
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor add_vertex(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_property_type vp, FEVV::DataStructures::AIF::AIFMesh &sm)
Definition: Graph_properties_aif.h:263
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
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
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
FEVV::face_normal
@ face_normal
Definition: properties.h:77