#include <CGAL/Simple_cartesian.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_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 K::Point_3 Point_3;
typedef K::Vector_3 Vector_3;
typedef std::pair<Point_3, Vector_3> Pwn;
struct Weight_map
{
typedef Pwn key_type;
typedef typename K::FT value_type;
typedef value_type reference;
typedef boost::readable_property_map_tag category;
typedef Weight_map Self;
friend reference get(const Self&, const key_type&) { return value_type(1); }
};
namespace params = CGAL::parameters;
int main(int argc, const char** argv)
{
std::vector<Pwn> pwns1, pwns2;
.normal_map(Normal_map())))
{
std::cerr << "Error: cannot read file " << fname1 << std::endl;
return EXIT_FAILURE;
}
CGAL::parameters::point_map(Point_map())
.normal_map(Normal_map())))
{
std::cerr << "Error: cannot read file " << fname2 << std::endl;
return EXIT_FAILURE;
}
std::vector<ICP_config> point_set_1_filters;
point_set_1_filters.push_back( ICP_config { "MinDistDataPointsFilter" , { {"minDist", "0.5" }} } );
point_set_1_filters.push_back( ICP_config { "RandomSamplingDataPointsFilter", { {"prob" , "0.05"}} } );
std::vector<ICP_config> point_set_2_filters;
point_set_2_filters.push_back( ICP_config { "MinDistDataPointsFilter" , { {"minDist", "0.5" }} } );
point_set_2_filters.push_back( ICP_config { "RandomSamplingDataPointsFilter", { {"prob" , "0.05"}} } );
ICP_config matcher { "KDTreeMatcher", { {"knn", "1"}, {"epsilon", "3.16"} } };
std::vector<ICP_config> outlier_filters;
outlier_filters.push_back( ICP_config { "TrimmedDistOutlierFilter", { {"ratio", "0.75" }} } );
outlier_filters.push_back( ICP_config { "GenericDescriptorOutlierFilter", { {"descName", "weights" }} } );
ICP_config error_minimizer { "PointToPointErrorMinimizer", { } };
std::vector<ICP_config> transformation_checkers;
transformation_checkers.push_back( ICP_config { "CounterTransformationChecker", { {"maxIterationCount", "150" }} } );
transformation_checkers.push_back( ICP_config { "DifferentialTransformationChecker", { {"minDiffRotErr" , "0.001" },
{"minDiffTransErr", "0.01" },
{"smoothLength" , "4" } }
} );
ICP_config inspector { "NullInspector", { } };
ICP_config logger { "FileLogger", { } };
std::pair<K::Aff_transformation_3, bool> res =
(pwns1, pwns2,
params::point_map(Point_map()).normal_map(Normal_map()).scalar_map(Weight_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()).scalar_map(Weight_map())
.point_set_filters(point_set_2_filters)
.transformation(identity_transform)
);
bool converged = false;
do
{
converged =
(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)
);
if (converged)
std::cerr << "Success" << std::endl;
else
std::cerr << "Did not converge, try again" << std::endl;
}
while (!converged);
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;
}