MEPP2 Project
test_point_cloud_normal_wpca.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 
15 
16 #include <string>
17 
21  template< typename PointCloud >
22 int test_point_cloud_normal_wpca(int argc, const char **argv)
23 {
24  if (argc != 6 && argc != 7)
25  {
26  std::cout<<std::endl;
27  printf("./normal_estimation [input pointcloud] [output_pointcloud.ply] [number of neighbors] [noise] [curvature] [OPTIONNAL:reference_file]\n");
28  printf("Estimated noise (m),\n \t example : 0.0001 \n");
29  printf("Min tolerated curvature radius (m) \n \t example for curved objects = 0.1 \n \t for intersecting planes = 10000000000\n");
30  printf("It is recommended to scale the objects (for diagonal to be 1) to better parameterize the min tolerated curvature radius\n");
31 
32  std::cout << "Examples: \n"
33  << argv[0] << " casting.xyz casting.curvature.ply 10 0 0.01 casting.curvature.ref.ply\n"
34  << std::endl;
35  return EXIT_FAILURE;
36  }
37  else
38  {
39  // display parameters summary
40  std::cout << "\nParameters summary:" << std::endl;
41  std::cout<<std::endl;
42  for (int i = 1 ; i<argc; i++)
43  std::cout<<argv[i]<<" ";
44  std::cout<<std::endl<<std::endl;
45  }
46 
47  // input and output files
48  std::string input_file_path = argv[1];
49  std::string output_file_path = argv[2];
50 
51  // read mesh from file
52  PointCloud cloud;
53  FEVV::PMapsContainer pmaps_bag;
54  FEVV::Filters::read_mesh(input_file_path, cloud, pmaps_bag);
55 
56  // Note: the property maps must be extracted from the
57  // property maps bag, and explicitely passed as
58  // parameters to the filter, in order to make
59  // clear what property is used by the filter
60 
61  // retrieve or create vertex-normal property map
62  using VertexNormalMap =
64  VertexNormalMap v_nm;
65  if(has_map(pmaps_bag, FEVV::vertex_normal))
66  {
67  std::cout << "use existing vertex-normal map" << std::endl;
68  v_nm = get_property_map(FEVV::vertex_normal, cloud, pmaps_bag);
69  }
70  else
71  {
72  std::cout << "create vertex-normal map" << std::endl;
74  // store property map in property maps bag
75  put_property_map(FEVV::vertex_normal, cloud, pmaps_bag, v_nm);
76  }
77 
78  // retrieve point property map (aka geometry)
79  auto pm = get(boost::vertex_point, cloud);
80 
81  // apply filter
82  int n_neigh = static_cast<int>(atoi(argv[3]));
83  float noise = static_cast<float>(atof(argv[4])/sqrt(3));
84  noise = std::max(noise, 0.000001f);
85  float curvature = static_cast<float>(atof(argv[5]));
86  FEVV::Filters::compute_weighted_pca(cloud, pm, v_nm, n_neigh, noise, curvature);
87 
88  //std::string output_file_path = create_output_name(input_file_path, "weightedPCA", n_neigh, "pcd");
89 
90  // save the point cloud
91  std::cout << "saving point cloud with normals to " << output_file_path
92  << std::endl;
93  FEVV::Filters::write_mesh(output_file_path, cloud, pmaps_bag);
94 
95  // check output file
96  std::string reference_file_path;
97  if(argc == 7)
98  reference_file_path = argv[6];
99 
100  if(!reference_file_path.empty())
101  {
102  std::cout << "Comparing output file" << std::endl;
103  std::cout << " '" << output_file_path << "'" << std::endl;
104  std::cout << "with reference file" << std::endl;
105  std::cout << " '" << reference_file_path << "'" << std::endl;
106  std::cout << "..." << std::endl;
107 
108  // use text file comparator
109  if(!identical_text_based_files(output_file_path, reference_file_path))
110  {
111  std::cout << "Files are different!" << std::endl;
112  return EXIT_FAILURE;
113  }
114 
115  std::cout << "Files are identical." << std::endl;
116  }
117 
118  return 0;
119 }
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
FEVV::get_property_map
PMap_traits< PropertyT, MeshT >::pmap_type get_property_map(PropertyT p, const MeshT &, const PMapsContainer &pmaps)
Definition: properties.h:646
point_cloud_normal_wpca.hpp
FEVV::has_map
bool has_map(const PMapsContainer &pmaps, const std::string &map_name)
(refer to Property Maps API)
Definition: properties.h:103
utils_identical_text_based_files.hpp
FEVV::PMapsContainer
std::map< std::string, boost::any > PMapsContainer
Definition: properties.h:99
test_point_cloud_normal_wpca
int test_point_cloud_normal_wpca(int argc, const char **argv)
Generic test of Weighted PCA filter.
Definition: test_point_cloud_normal_wpca.inl:22
FEVV::Filters::compute_weighted_pca
void compute_weighted_pca(const PointCloud &pointCloud, const PointMap &pointMap, NormalMap &normalMap, int n_neight, float noise, float curvature, const GeometryTraits &gt)
Definition: point_cloud_normal_wpca.hpp:38
identical_text_based_files
bool identical_text_based_files(std::string filename_a, std::string filename_b, const std::vector< std::string > &skip=std::vector< std::string >())
Definition: utils_identical_text_based_files.hpp:27
FEVV::Filters::read_mesh
void read_mesh(const std::string &filename, FEVV::CGALPointSet &g, PMapsContainer &pmaps, bool=false)
Load mesh from file.
Definition: cgal_point_set_reader.hpp:110
FEVV::Filters::write_mesh
void write_mesh(const std::string &filename, FEVV::CGALPointSet &g, PMapsContainer &pmaps)
Write mesh to file.
Definition: cgal_point_set_writer.hpp:42
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::_PMap_traits
Definition: properties.h:376
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
curvature
void curvature(FEVV::DataStructures::AIF::AIFMesh *mesh)
Definition: test_curvature_filter_aif.cpp:26