MEPP2 Project
homogeneous_transform.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 #include <boost/graph/properties.hpp>
16 
17 #include <Eigen/Dense>
18 
19 namespace FEVV {
20 namespace Filters {
21 
22 
34 template< typename HalfedgeGraph,
35  typename PointMap,
36  typename GeometryTraits >
37 void
38 homogeneous_transform(const HalfedgeGraph &g,
39  PointMap &pm,
40  const Eigen::Matrix4d &mat,
41  const GeometryTraits &gt)
42 {
43  typedef boost::graph_traits< HalfedgeGraph > GraphTraits;
44  typedef typename GraphTraits::vertex_iterator vertex_iterator;
45  typedef typename boost::property_traits< PointMap >::value_type Point;
46 
47  auto iterator_pair = vertices(g);
48  vertex_iterator vi = iterator_pair.first;
49  vertex_iterator vi_end = iterator_pair.second;
50 
51  // loop over vertices
52  for(; vi != vi_end; ++vi)
53  {
54  // retrieve vertex coordinates
55  Point p = get(pm, *vi);
56  double x = gt.get_x(p);
57  double y = gt.get_y(p);
58  double z = gt.get_z(p);
59  Eigen::Vector4d v(x, y, z, 1);
60 
61  // compute transformed coordinates
62  // | s.xt | | tx | | x |
63  // | s.yt | = | R3x3 ty |.| y |
64  // | s.zt | | tz | | z |
65  // | s | | 0 0 0 1 | | 1 |
66  // with s = 1
67  Eigen::Vector4d vt = mat * v;
68  assert(vt(3) == 1);
69 
70  // update point property map
71  Point pt(vt(0), vt(1), vt(2));
72  put(pm, *vi, pt);
73  }
74 }
75 
76 
88 template< typename HalfedgeGraph,
89  typename PointMap,
90  typename GeometryTraits = FEVV::Geometry_traits< HalfedgeGraph > >
91 void
92 homogeneous_transform(const HalfedgeGraph &g,
93  PointMap &pm,
94  const Eigen::Matrix4d &mat)
95 {
96  GeometryTraits gt(g);
97  return homogeneous_transform< HalfedgeGraph,
98  PointMap,
99  GeometryTraits >(g, pm, mat, gt);
100 }
101 
102 
103 } // namespace Filters
104 } // namespace FEVV
105 
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::homogeneous_transform
void homogeneous_transform(const HalfedgeGraph &g, PointMap &pm, const Eigen::Matrix4d &mat, const GeometryTraits &gt)
Calculate the homogeneous transformation of the vertices coordinates using the provided 4x4 homogeneo...
Definition: homogeneous_transform.hpp:38
FEVV::Geometry_traits< HalfedgeGraph >
Point
AIFMesh::Point Point
Definition: Graph_properties_aif.h:21
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
Geometry_traits.h
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::DataStructures::AIF::AIFPoint
Definition: AIFProperties.h:31