Merge remote-tracking branch 'necip/gsoc2019-pointmatcher_icp_wrapper-necipfazil' into gsoc2019-pointmatcher_icp_wrapper-necipfazil

This commit is contained in:
Simon Giraudot
2020-03-05 15:58:17 +01:00
34 changed files with 2972 additions and 9 deletions
@@ -78,6 +78,34 @@ if ( CGAL_FOUND )
create_single_source_cgal_program( "jet_smoothing_example.cpp" )
create_single_source_cgal_program( "normal_estimation.cpp" )
create_single_source_cgal_program( "edges_example.cpp" )
# Executables that require libpointmatcher
find_package(libpointmatcher QUIET)
if (libpointmatcher_FOUND)
create_single_source_cgal_program( "registration_with_pointmatcher.cpp" )
CGAL_target_use_pointmatcher(registration_with_pointmatcher)
else()
message(STATUS "NOTICE : the registration_with_pointmatcher test requires libpointmatcher and will not be compiled.")
endif()
# Executables that require OpenGR
find_package(OpenGR QUIET)
if (OpenGR_FOUND)
create_single_source_cgal_program( "registration_with_OpenGR.cpp" )
CGAL_target_use_OpenGR(registration_with_OpenGR)
else()
message(STATUS "NOTICE : registration_with_OpenGR requires OpenGR, and will not be compiled.")
endif()
# Executables that require both libpointmatcher and OpenGR
if (libpointmatcher_FOUND AND OpenGR_FOUND)
create_single_source_cgal_program( "registration_with_opengr_pointmatcher_pipeline.cpp" )
CGAL_target_use_OpenGR(registration_with_opengr_pointmatcher_pipeline)
CGAL_target_use_pointmatcher(registration_with_opengr_pointmatcher_pipeline)
else()
message(STATUS "NOTICE : registration_with_opengr_pointmatcher_pipeline requires libpointmatcher and OpenGR, and will not be compiled.")
endif()
else()
message(STATUS "NOTICE: Some of the executables in this directory need Eigen 3.1 (or greater) and will not be compiled.")
@@ -0,0 +1,87 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/IO/read_ply_points.h>
#include <CGAL/IO/write_ply_points.h>
#include <CGAL/property_map.h>
#include <CGAL/OpenGR/compute_registration_transformation.h>
#include <CGAL/OpenGR/register_point_sets.h>
#include <fstream>
#include <iostream>
#include <utility>
typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_3 Point_3;
typedef K::Vector_3 Vector_3;
typedef std::pair<Point_3, Vector_3> Pwn;
typedef CGAL::First_of_pair_property_map<Pwn> Point_map;
typedef CGAL::Second_of_pair_property_map<Pwn> 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<Pwn> 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<Pwn>()).
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();
// EITHER call the registration method Super4PCS from OpenGR to get the transformation to apply to pwns2
// std::pair<K::Aff_transformation_3, double> res =
CGAL::OpenGR::compute_registration_transformation(pwns1, pwns2,
params::point_map(Point_map())
.normal_map(Normal_map())
.number_of_samples(200)
.maximum_running_time(60)
.accuracy(0.01),
params::point_map(Point_map())
.normal_map(Normal_map()));
// OR call the registration method Super4PCS from OpenGR and apply the transformation to pwn2
double score =
CGAL::OpenGR::register_point_sets(pwns1, pwns2,
params::point_map(Point_map())
.normal_map(Normal_map())
.number_of_samples(200)
.maximum_running_time(60)
.accuracy(0.01),
params::point_map(Point_map())
.normal_map(Normal_map()));
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 << "Registration score: " << score << ".\n"
<< "Transformed version of " << fname2
<< " written to pwn2_aligned.ply.\n";
return EXIT_SUCCESS;
}
@@ -0,0 +1,88 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/IO/read_ply_points.h>
#include <CGAL/IO/write_ply_points.h>
#include <CGAL/property_map.h>
#include <CGAL/Aff_transformation_3.h>
#include <CGAL/pointmatcher/register_point_sets.h>
#include <CGAL/OpenGR/compute_registration_transformation.h>
#include <fstream>
#include <iostream>
#include <utility>
#include <vector>
typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_3 Point_3;
typedef K::Vector_3 Vector_3;
typedef std::pair<Point_3, Vector_3> Pwn;
typedef CGAL::First_of_pair_property_map<Pwn> Point_map;
typedef CGAL::Second_of_pair_property_map<Pwn> 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<Pwn> 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<Pwn>()).
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::cerr << "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::cerr << "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, and apply the transformation to pwns2
// bool converged =
CGAL::pointmatcher::register_point_sets
(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::cerr << "Transformed version of " << fname2
<< " written to pwn2_aligned.ply.\n";
return EXIT_SUCCESS;
}
@@ -0,0 +1,150 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/IO/read_ply_points.h>
#include <CGAL/IO/write_ply_points.h>
#include <CGAL/property_map.h>
#include <CGAL/Aff_transformation_3.h>
#include <CGAL/aff_transformation_tags.h>
#include <CGAL/pointmatcher/compute_registration_transformation.h>
#include <CGAL/pointmatcher/register_point_sets.h>
#include <fstream>
#include <iostream>
#include <utility>
#include <vector>
typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_3 Point_3;
typedef K::Vector_3 Vector_3;
typedef std::pair<Point_3, Vector_3> Pwn;
typedef CGAL::First_of_pair_property_map<Pwn> Point_map;
typedef CGAL::Second_of_pair_property_map<Pwn> 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<Pwn> 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<Pwn>()).
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();
//
// Prepare ICP config
//
using CGAL::pointmatcher::ICP_config;
// Possible config modules/components: https://libpointmatcher.readthedocs.io/en/latest/Configuration/#configuration-of-an-icp-chain
// See documentation of optional named parameters for CGAL PM ICP configuration / pointmatcher config module mapping
// Prepare point set 1 filters (PM::ReferenceDataPointsFilters)
std::vector<ICP_config> point_set_1_filters;
point_set_1_filters.push_back( ICP_config { /*.name=*/"MinDistDataPointsFilter" , /*.params=*/{ {"minDist", "0.5" }} } );
point_set_1_filters.push_back( ICP_config { /*.name=*/"RandomSamplingDataPointsFilter", /*.params=*/{ {"prob" , "0.05"}} } );
// Prepare point set 2 filters (PM::ReadingDataPointsFilters)
std::vector<ICP_config> point_set_2_filters;
point_set_2_filters.push_back( ICP_config { /*.name=*/"MinDistDataPointsFilter" , /*.params=*/{ {"minDist", "0.5" }} } );
point_set_2_filters.push_back( ICP_config { /*.name=*/"RandomSamplingDataPointsFilter", /*.params=*/{ {"prob" , "0.05"}} } );
// Prepare matcher function
ICP_config matcher { /*.name=*/"KDTreeMatcher", /*.params=*/{ {"knn", "1"}, {"epsilon", "3.16"} } };
// Prepare outlier filters
std::vector<ICP_config> outlier_filters;
outlier_filters.push_back( ICP_config { /*.name=*/"TrimmedDistOutlierFilter", /*.params=*/{ {"ratio", "0.75" }} } );
// Prepare error minimizer
ICP_config error_minimizer { /*.name=*/"PointToPointErrorMinimizer"};
// Prepare transformation checker
std::vector<ICP_config> transformation_checkers;
transformation_checkers.push_back( ICP_config { /*.name=*/"CounterTransformationChecker", /*.params=*/{ {"maxIterationCount", "150" }} } );
transformation_checkers.push_back( ICP_config { /*.name=*/"DifferentialTransformationChecker", /*.params=*/{ {"minDiffRotErr" , "0.001" },
{"minDiffTransErr", "0.01" },
{"smoothLength" , "4" } }
} );
// Prepare inspector
ICP_config inspector { /*.name=*/"NullInspector" };
// Prepare logger
ICP_config logger { /*.name=*/"FileLogger" };
const K::Aff_transformation_3 identity_transform = K::Aff_transformation_3(CGAL::Identity_transformation());
// EITHER call the ICP registration method pointmatcher to get the transformation to apply to pwns2
std::pair<K::Aff_transformation_3, bool> res =
CGAL::pointmatcher::compute_registration_transformation
(pwns1, pwns2,
params::point_map(Point_map()).normal_map(Normal_map())
.point_set_filters(point_set_1_filters)
.matcher(matcher)
.outlier_filters(outlier_filters)
.error_minimizer(error_minimizer)
.transformation_checkers(transformation_checkers)
.inspector(inspector)
.logger(logger),
params::point_map(Point_map()).normal_map(Normal_map())
.point_set_filters(point_set_2_filters)
.transformation(identity_transform) /* initial transform for pwns2.
* default value is already identity transform.
* a proper initial transform could be given, for example,
* a transform returned from a coarse registration algorithm.
* */
);
// OR call the ICP registration method from pointmatcher and apply the transformation to pwn2
bool converged =
CGAL::pointmatcher::register_point_sets
(pwns1, pwns2,
params::point_map(Point_map()).normal_map(Normal_map())
.point_set_filters(point_set_1_filters)
.matcher(matcher)
.outlier_filters(outlier_filters)
.error_minimizer(error_minimizer)
.transformation_checkers(transformation_checkers)
.inspector(inspector)
.logger(logger),
params::point_map(Point_map()).normal_map(Normal_map())
.point_set_filters(point_set_2_filters)
.transformation(res.first) /* pass the above computed transformation as initial transformation.
* as a result, the registration will require less iterations to converge.
* */
);
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;
}