MEPP2 Project
copy_point_cloud.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 
16 
17 #include <iostream>
18 #include <type_traits> // for std::remove_reference
19 
20 
21 namespace FEVV {
22 namespace Filters {
23 
24 
28 template< typename PointCloudS,
29  typename PointCloudT >
30 using PCVertexToVertexMap = std::map<
33 
34 
41 template< typename PointCloudS,
42  typename PointCloudT >
44 {
46 
48  {
49  m_v2v = _v2v;
50  return *this;
51  }
52 
53  V2VMap *m_v2v = nullptr;
54 };
55 
56 
71 template< typename PointCloudS,
72  typename PointCloudT,
73  typename Parameters,
74  typename GeometryTraitsS,
75  typename GeometryTraitsT >
76 void
77 copy_point_cloud(const PointCloudS &pc_s,
78  const PMapsContainer &pmaps_s,
79  PointCloudT &pc_t,
80  PMapsContainer &pmaps_t,
81  const Parameters &params,
82  const GeometryTraitsS &gt_s,
83  const GeometryTraitsT &/*gt_t*/)
84 {
85  // target types
86  typedef typename GeometryTraitsT::Scalar TScalar;
87  typedef typename GeometryTraitsT::Point TPoint;
88  typedef typename GeometryTraitsT::Vector TVector;
89  typedef decltype(make_property_map(FEVV::vertex_color, pc_t)) TColorMap;
90  typedef typename TColorMap::value_type TColor;
91  // note: we need the Color type because it is not a Vector with all
92  // datastructures ; the easiest way to define the Color type is
93  // "the type that is stored in the Color map", hence the declaration
94  // above
95 
96  // detect which standard properties are used by source
97  bool use_vertex_normal = has_map(pmaps_s, vertex_normal);
98  bool use_vertex_color = has_map(pmaps_s, vertex_color);
99 
100  // retrieve point maps
101  auto s_point_pm = get(boost::vertex_point, pc_s);
102  auto t_point_pm = get(boost::vertex_point, pc_t);
103 
104  // create needed property maps in target
105  if(use_vertex_normal)
106  {
107  auto vn_pm = make_property_map(FEVV::vertex_normal, pc_t);
108  put_property_map(FEVV::vertex_normal, pc_t, pmaps_t, vn_pm);
109  }
110  if(use_vertex_color)
111  {
112  auto vc_pm = make_property_map(FEVV::vertex_color, pc_t);
113  put_property_map(FEVV::vertex_color, pc_t, pmaps_t, vc_pm);
114  }
115 
116  // reset v2v map
117  if(params.m_v2v)
118  params.m_v2v->clear();
119 
120  // copy geometry and properties
121  auto iterator_pair = vertices(pc_s);
122  auto s_vi = iterator_pair.first;
123  auto s_vi_end = iterator_pair.second;
124  for(; s_vi != s_vi_end; ++s_vi)
125  {
126  // create new vertex in target
127  auto v = add_vertex(pc_t);
128 
129  // copy geometry
130  auto s_point = get(s_point_pm, *s_vi);
131  auto x = gt_s.get_x(s_point);
132  auto y = gt_s.get_y(s_point);
133  auto z = gt_s.get_z(s_point);
134  put(t_point_pm, v, TPoint(static_cast< TScalar >(x),
135  static_cast< TScalar >(y),
136  static_cast< TScalar >(z)));
137 
138  // copy properties
139  if(use_vertex_normal)
140  {
141  // vertex normal
142  auto source_pm = get_property_map(FEVV::vertex_normal, pc_s, pmaps_s);
143  auto target_pm = get_property_map(FEVV::vertex_normal, pc_t, pmaps_t);
144  auto normal = get(source_pm, *s_vi);
145  put(target_pm, v, TVector(static_cast< TScalar >(normal[0]),
146  static_cast< TScalar >(normal[1]),
147  static_cast< TScalar >(normal[2])));
148  }
149 
150  if(use_vertex_color)
151  {
152  // vertex color
153  auto source_pm = get_property_map(FEVV::vertex_color, pc_s, pmaps_s);
154  auto target_pm = get_property_map(FEVV::vertex_color, pc_t, pmaps_t);
155  auto color = get(source_pm, *s_vi);
156 
157  TColor t_color;
158  typedef typename std::remove_reference< decltype(t_color[0]) >::type
159  TColorValueType;
160 
161  put(target_pm,
162  v,
163  TColor(FEVV::Math::convert_color_value< TColorValueType >(color[0]),
164  FEVV::Math::convert_color_value< TColorValueType >(color[1]),
165  FEVV::Math::convert_color_value< TColorValueType >(color[2])));
166  }
167 
168  // populate v2v map
169  if(params.m_v2v)
170  (*params.m_v2v)[*s_vi] = v;
171  }
172 
173  // display some information
174 
175  std::cout << "copy_point_cloud(): input point_cloud has "
176  << size_of_vertices(pc_s) << " vertices, "
177  << std::endl;
178  std::cout << "copy_point_cloud(): input point_cloud has property maps: [";
179  for(auto &name: list_property_maps(pmaps_s))
180  std::cout << " " << name;
181  std::cout << " ]" << std::endl;
182 
183  std::cout << "copy_point_cloud(): output point_cloud has "
184  << size_of_vertices(pc_t) << " vertices, "
185  << std::endl;
186  std::cout << "copy_point_cloud(): output point_cloud has property maps: [";
187  for(auto &name: list_property_maps(pmaps_t))
188  std::cout << " " << name;
189  std::cout << " ]" << std::endl;
190 }
191 
192 
204 template< typename PointCloudS,
205  typename PointCloudT,
206  typename Parameters,
207  typename GeometryTraitsS = FEVV::Geometry_traits< PointCloudS >,
208  typename GeometryTraitsT = FEVV::Geometry_traits< PointCloudT > >
209 void
210 copy_point_cloud(const PointCloudS &pc_s,
211  const PMapsContainer &pmap_s,
212  PointCloudT &pc_t,
213  PMapsContainer &pmap_t,
214  const Parameters &params =
216 {
217  GeometryTraitsS gt_s(pc_s);
218  GeometryTraitsT gt_t(pc_t);
219  copy_point_cloud(pc_s, pmap_s, pc_t, pmap_t, params, gt_s, gt_t);
220 }
221 
222 
223 } // namespace Filters
224 } // namespace FEVV
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::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
Vector
AIFMesh::Vector Vector
Definition: Graph_properties_aif.h:22
FEVV::get_property_map
PMap_traits< PropertyT, MeshT >::pmap_type get_property_map(PropertyT p, const MeshT &, const PMapsContainer &pmaps)
Definition: properties.h:646
color_conversion.hpp
FEVV::has_map
bool has_map(const PMapsContainer &pmaps, const std::string &map_name)
(refer to Property Maps API)
Definition: properties.h:103
FEVV::Geometry_traits
Refer to Geometry_traits_documentation_dummy for further documentation on provided types and algorith...
Definition: Geometry_traits.h:162
Point
AIFMesh::Point Point
Definition: Graph_properties_aif.h:21
FEVV::Filters::CopyPCParameters
Definition: copy_point_cloud.hpp:44
FEVV::PMapsContainer
std::map< std::string, boost::any > PMapsContainer
Definition: properties.h:99
FEVV::Filters::CopyPCParameters::V2VMap
PCVertexToVertexMap< PointCloudS, PointCloudT > V2VMap
Definition: copy_point_cloud.hpp:45
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::Filters::CopyPCParameters::v2v
CopyPCParameters & v2v(V2VMap *_v2v)
Definition: copy_point_cloud.hpp:47
FEVV::Filters::copy_point_cloud
void copy_point_cloud(const PointCloudS &pc_s, const PMapsContainer &pmaps_s, PointCloudT &pc_t, PMapsContainer &pmaps_t, const Parameters &params, const GeometryTraitsS &gt_s, const GeometryTraitsT &)
Copy a source point cloud into a target point cloud. Copy standard properties too.
Definition: copy_point_cloud.hpp:77
FEVV::vertex_color
@ vertex_color
Definition: properties.h:47
FEVV::list_property_maps
std::vector< std::string > list_property_maps(const PMapsContainer &pmaps)
Definition: properties.h:708
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
FEVV::Filters::CopyPCParameters::m_v2v
V2VMap * m_v2v
Definition: copy_point_cloud.hpp:53
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
FEVV::Filters::PCVertexToVertexMap
std::map< typename boost::graph_traits< PointCloudS >::vertex_descriptor, typename boost::graph_traits< PointCloudT >::vertex_descriptor > PCVertexToVertexMap
Definition: copy_point_cloud.hpp:32
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
properties.h
FEVV::vertex_normal
@ vertex_normal
Definition: properties.h:35
FEVV::Filters::Parameters
Parameters contains the compression parameters except the stopping criteria.
Definition: Parameters.h:46
FEVV::size_of_vertices
boost::graph_traits< MeshT >::vertices_size_type size_of_vertices(const MeshT &g)
Real current number of vertices of the mesh. Generic version.
Definition: Graph_traits_extension.h:29
FEVV::make_property_map
PMap_traits< PropertyT, MeshT >::pmap_type make_property_map(PropertyT, const MeshT &m)
Definition: properties.h:630