MEPP2 Project
calculate_face_tangent.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 
19 namespace FEVV {
20 namespace Operators {
21 
36 template< typename HalfedgeGraph,
37  typename PointMap,
38  typename Vector,
39  typename VertexTangentMap >
40 void
42  typename boost::graph_traits< HalfedgeGraph >::face_descriptor f,
43  const HalfedgeGraph &g,
44  const PointMap &pm,
45  const Vector &uv1,
46  const Vector &uv2,
47  const Vector &uv3,
48  VertexTangentMap &vtm)
49 {
51  using halfedge_descriptor =
52  typename boost::graph_traits< HalfedgeGraph >::halfedge_descriptor;
53  using vertex_descriptor =
55 
56  // RM: basic test with nth vertices polygons, *this may not work properly!*
57  // It may be needed to have only triangles for this to work (though
58  // unlikely, as long as we recover the plane basis)
59  // -> After having tested multiple meshes, some having 5+ vertices per
60  // face, it is less & less likely that this has an impact.
61 
62  /*
63 
64  *------* V2
65  | /|
66  | / |
67  | / |
68  | / |
69  | / |
70  |/ |
71  *------* V3
72  V1
73 
74  Any halfedge is fine, but assuming for example we're getting halfedge (named
75  H) V2 -> V1, then points are as such:
76  - V1 is the target of H
77  - V2 is the source of H
78  - V3 is the target of the next halfedge from H
79 
80  Actually, we don't care much about which points we get, as long as
81  there are 3 of them linked to each other to deduce a plane from it
82 
83  */
84 
85  halfedge_descriptor half_edge = halfedge(f, g);
86  const vertex_descriptor vert1 = target(half_edge, g); // V1
87  const vertex_descriptor vert2 = source(half_edge, g); // V2
88  const vertex_descriptor vert3 = target(next(half_edge, g), g); // V3
89 
90  // RM: get positions & texcoords from vertex descriptors
91  const Point pos1 = get(pm, vert1);
92  const Point pos2 = get(pm, vert2);
93  const Point pos3 = get(pm, vert3);
94 
95  const Vector tan =
96  Operators::calculate_triangle_tangent(pos1, pos2, pos3, uv1, uv2, uv3);
97 
98  const halfedge_descriptor first_he = half_edge;
99  do
100  {
101  const vertex_descriptor vert = source(half_edge, g);
102 
103  const Vector new_tan = get(vtm, vert) + tan;
104  put(vtm, vert, new_tan);
105 
106  half_edge = next(half_edge, g);
107  } while(half_edge != first_he);
108 }
109 
110 } // namespace Operators
111 } // namespace FEVV
FEVV::DataStructures::AIF::next
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor next(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the next halfedge around its face.
Definition: Graph_traits_aif.h:599
Vector
AIFMesh::Vector Vector
Definition: Graph_properties_aif.h:22
FEVV::Geometry_traits
Refer to Geometry_traits_documentation_dummy for further documentation on provided types and algorith...
Definition: Geometry_traits.h:162
FEVV::DataStructures::AIF::source
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor source(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor e, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the source vertex of e.
Definition: Graph_traits_aif.h:387
FEVV::get
FEVV::PCLPointCloudPointMap::value_type get(const FEVV::PCLPointCloudPointMap &pm, FEVV::PCLPointCloudPointMap::key_type key)
Specialization of get(point_map, key) for PCLPointCloud.
Definition: Graph_properties_pcl_point_cloud.h:117
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
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::target
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor target(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor e, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the target vertex of e.
Definition: Graph_traits_aif.h:400
tangents.hpp
Geometry_traits.h
FEVV::DataStructures::AIF::AIFVector
Definition: AIFProperties.h:173
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
FEVV::put
void put(FEVV::PCLPointCloudPointMap &pm, FEVV::PCLPointCloudPointMap::key_type key, const FEVV::PCLPointCloudPointMap::value_type &value)
Specialization of put(point_map, key, value) for PCLPointCloud.
Definition: Graph_properties_pcl_point_cloud.h:126
FEVV::Operators::calculate_triangle_tangent
Vector calculate_triangle_tangent(const Point &pt1, const Point &pt2, const Point &pt3, const Vector &uv1, const Vector &uv2, const Vector &uv3)
Calculate the actual face tangent from three connected vertices' positions & texture coordinates.
Definition: tangents.hpp:33
FEVV::Operators::calculate_face_tangent
void calculate_face_tangent(typename boost::graph_traits< HalfedgeGraph >::face_descriptor f, const HalfedgeGraph &g, const PointMap &pm, const Vector &uv1, const Vector &uv2, const Vector &uv3, VertexTangentMap &vtm)
Calculate a face tangent, then accumulate its value on every vertices it contains to average them; fi...
Definition: calculate_face_tangent.hpp:41
FEVV::DataStructures::AIF::AIFPoint
Definition: AIFProperties.h:31