From 84bf522352640fd8a04498edf39fd302c9bbd4ff Mon Sep 17 00:00:00 2001 From: Necip Yildiran Date: Sat, 20 Jul 2019 00:29:53 +0300 Subject: [PATCH] Added psp example: registration with opengr+pointmatcher pipeline --- ...tion_with_opengr_pointmatcher_pipeline.cpp | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 Point_set_processing_3/examples/Point_set_processing_3/registration_with_opengr_pointmatcher_pipeline.cpp diff --git a/Point_set_processing_3/examples/Point_set_processing_3/registration_with_opengr_pointmatcher_pipeline.cpp b/Point_set_processing_3/examples/Point_set_processing_3/registration_with_opengr_pointmatcher_pipeline.cpp new file mode 100644 index 00000000000..fa3802e4e2f --- /dev/null +++ b/Point_set_processing_3/examples/Point_set_processing_3/registration_with_opengr_pointmatcher_pipeline.cpp @@ -0,0 +1,92 @@ +// TODO: Copyright info +// TODO: Requires both OpenGR and PointMatcher wrappers. + +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian K; +typedef K::Point_3 Point_3; +typedef K::Vector_3 Vector_3; +typedef std::pair Pwn; +typedef CGAL::First_of_pair_property_map Point_map; +typedef CGAL::Second_of_pair_property_map Normal_map; + +namespace params = CGAL::parameters; + +int main(int argc, const char** argv) +{ + const char* fname1 = (argc>1)?argv[1]:"data/hippo1.ply"; + const char* fname2 = (argc>2)?argv[2]:"data/hippo2.ply"; + + std::vector pwns1, pwns2; + std::ifstream input(fname1); + if (!input || + !CGAL::read_ply_points(input, std::back_inserter(pwns1), + CGAL::parameters::point_map (CGAL::First_of_pair_property_map()). + normal_map (Normal_map()))) + { + std::cerr << "Error: cannot read file " << fname1 << std::endl; + return EXIT_FAILURE; + } + input.close(); + + input.open(fname2); + if (!input || + !CGAL::read_ply_points(input, std::back_inserter(pwns2), + CGAL::parameters::point_map (Point_map()). + normal_map (Normal_map()))) + { + std::cerr << "Error: cannot read file " << fname2 << std::endl; + return EXIT_FAILURE; + } + input.close(); + + std::cout << "Computing registration transformation using OpenGR Super4PCS.." << std::endl; + // First, compute registration transformation using OpenGR Super4PCS + K::Aff_transformation_3 res = + std::get<0>( // get first of pair, which is the transformation + CGAL::OpenGR::compute_registration_transformation + (pwns1, pwns2, + params::point_map(Point_map()).normal_map(Normal_map()), + params::point_map(Point_map()).normal_map(Normal_map())) + ); + + std::cout << "Computing registration transformation using PointMatcher ICP, " + << "taking transformation computed by OpenGR Super4PCS as initial transformation.." << std::endl; + // Then, compute registration transformation using PointMatcher ICP, taking transformation computed + // by OpenGR as initial transformation + res = + CGAL::pointmatcher::compute_registration_transformation + (pwns1, pwns2, + params::point_map(Point_map()).normal_map(Normal_map()), + params::point_map(Point_map()).normal_map(Normal_map()) + .transformation(res) + ); + + std::ofstream out("pwns2_aligned.ply"); + if (!out || + !CGAL::write_ply_points( + out, pwns2, + CGAL::parameters::point_map(Point_map()). + normal_map(Normal_map()))) + { + return EXIT_FAILURE; + } + + std::cout << "Transformed version of " << fname2 + << " written to pwn2_aligned.ply.\n"; + + return EXIT_SUCCESS; +} \ No newline at end of file