mirror of https://github.com/CGAL/cgal
connected component unit test for torus
some parameter and comment adjustments
This commit is contained in:
parent
529327b603
commit
086363af4f
|
|
@ -24,10 +24,12 @@ if ( CGAL_FOUND )
|
||||||
include_directories (BEFORE "../../include")
|
include_directories (BEFORE "../../include")
|
||||||
|
|
||||||
create_single_source_cgal_program( "test_cone_parameters.cpp" )
|
create_single_source_cgal_program( "test_cone_parameters.cpp" )
|
||||||
create_single_source_cgal_program( "test_cylinders_parameters.cpp" )
|
create_single_source_cgal_program( "test_cylinder_parameters.cpp" )
|
||||||
create_single_source_cgal_program( "test_plane_connected_component.cpp" )
|
create_single_source_cgal_program( "test_plane_connected_component.cpp" )
|
||||||
create_single_source_cgal_program( "test_plane_parameters.cpp" )
|
create_single_source_cgal_program( "test_plane_parameters.cpp" )
|
||||||
|
create_single_source_cgal_program( "test_sphere_connected_component.cpp" )
|
||||||
create_single_source_cgal_program( "test_sphere_parameters.cpp" )
|
create_single_source_cgal_program( "test_sphere_parameters.cpp" )
|
||||||
|
create_single_source_cgal_program( "test_torus_connected_component.cpp" )
|
||||||
create_single_source_cgal_program( "test_torus_parameters.cpp" )
|
create_single_source_cgal_program( "test_torus_parameters.cpp" )
|
||||||
|
|
||||||
else()
|
else()
|
||||||
|
|
|
||||||
|
|
@ -56,16 +56,17 @@ bool test_plane_connected_component() {
|
||||||
|
|
||||||
ransac.set_input(points);
|
ransac.set_input(points);
|
||||||
|
|
||||||
// For the first half the rounds chose a high cluster_epsilon to find one
|
// Same parameters as for the parameters unit tests, besides
|
||||||
// shape and for the second half choose a small cluster_epsilon to find
|
// the cluster_epsilon.
|
||||||
// four separated shapes.
|
|
||||||
|
|
||||||
typename Efficient_ransac::Parameters parameters;
|
typename Efficient_ransac::Parameters parameters;
|
||||||
parameters.probability = 0.05f;
|
parameters.probability = 0.05f;
|
||||||
parameters.min_points = 100;
|
parameters.min_points = 100;
|
||||||
parameters.epsilon = 0.002f;
|
parameters.epsilon = 0.002f;
|
||||||
parameters.normal_threshold = 0.9f;
|
parameters.normal_threshold = 0.9f;
|
||||||
|
|
||||||
|
// For the first half the rounds chose a high cluster_epsilon to find one
|
||||||
|
// shape and for the second half choose a small cluster_epsilon to find
|
||||||
|
// four separated shapes.
|
||||||
if (i < NB_ROUNDS/2)
|
if (i < NB_ROUNDS/2)
|
||||||
parameters.cluster_epsilon = 0.201f;
|
parameters.cluster_epsilon = 0.201f;
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -53,18 +53,21 @@ bool test_sphere_connected_component() {
|
||||||
|
|
||||||
ransac.set_input(points);
|
ransac.set_input(points);
|
||||||
|
|
||||||
// Set cluster epsilon to a high value as just the parameters of
|
// Same parameters as for the parameters unit tests, besides
|
||||||
// the extracted primitives are to be tested.
|
// the cluster_epsilon.
|
||||||
typename Efficient_ransac::Parameters parameters;
|
typename Efficient_ransac::Parameters parameters;
|
||||||
parameters.probability = 0.05f;
|
parameters.probability = 0.05f;
|
||||||
parameters.min_points = NB_POINTS/10;
|
parameters.min_points = NB_POINTS/10;
|
||||||
parameters.epsilon = 0.002f;
|
parameters.epsilon = 0.002f;
|
||||||
parameters.normal_threshold = 0.9f;
|
parameters.normal_threshold = 0.9f;
|
||||||
|
|
||||||
|
// The first half of rounds choose a high cluster_epsilon to get only
|
||||||
|
// a single shape and a lower cluster_epsilon for the second half
|
||||||
|
// to get two separated shapes.
|
||||||
if (i < NB_ROUNDS/2)
|
if (i < NB_ROUNDS/2)
|
||||||
parameters.cluster_epsilon = spacing * (K::FT) 1.21;
|
parameters.cluster_epsilon = spacing * (K::FT) 1.5;
|
||||||
else
|
else
|
||||||
parameters.cluster_epsilon = spacing / (K::FT) 2;
|
parameters.cluster_epsilon = spacing * (K::FT) 0.9;
|
||||||
|
|
||||||
if (!ransac.detect(parameters)) {
|
if (!ransac.detect(parameters)) {
|
||||||
std::cout << " aborted" << std::endl;
|
std::cout << " aborted" << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,119 @@
|
||||||
|
#include "generators.h"
|
||||||
|
|
||||||
|
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||||
|
#include <CGAL/Simple_cartesian.h>
|
||||||
|
|
||||||
|
#include <CGAL/Shape_detection_3.h>
|
||||||
|
#include <CGAL/Point_with_normal_3.h>
|
||||||
|
#include <CGAL/property_map.h>
|
||||||
|
|
||||||
|
|
||||||
|
template <class K>
|
||||||
|
bool test_torus_connected_component() {
|
||||||
|
const int NB_ROUNDS = 10;
|
||||||
|
const int NB_POINTS = 2000;
|
||||||
|
|
||||||
|
typedef typename K::FT FT;
|
||||||
|
typedef CGAL::Point_with_normal_3<K> Pwn;
|
||||||
|
typedef CGAL::Point_3<K> Point;
|
||||||
|
typedef CGAL::Vector_3<K> Vector;
|
||||||
|
typedef std::vector<Pwn> Pwn_vector;
|
||||||
|
typedef CGAL::Identity_property_map<Pwn> Point_map;
|
||||||
|
typedef CGAL::Normal_of_point_with_normal_pmap<K> Normal_map;
|
||||||
|
|
||||||
|
typedef CGAL::Shape_detection_3::Efficient_RANSAC_traits<
|
||||||
|
K, Pwn_vector, Point_map, Normal_map> Traits;
|
||||||
|
|
||||||
|
typedef CGAL::Shape_detection_3::Efficient_RANSAC<Traits> Efficient_ransac;
|
||||||
|
typedef CGAL::Shape_detection_3::Torus<Traits> Torus;
|
||||||
|
|
||||||
|
std::size_t success = 0;
|
||||||
|
|
||||||
|
for (std::size_t i = 0;i<NB_ROUNDS;i++) {
|
||||||
|
Pwn_vector points;
|
||||||
|
|
||||||
|
// generate random points on torus
|
||||||
|
CGAL::Bbox_3 bbox(-10, -10, -10, 10, 10, 10);
|
||||||
|
FT minor_radius = (FT) 0.7;
|
||||||
|
FT major_radius = (FT) 2.0;
|
||||||
|
Vector axis = random_normal<K>();
|
||||||
|
Point center = random_point_in<K>(bbox);
|
||||||
|
|
||||||
|
sample_torus(NB_POINTS, center, axis,
|
||||||
|
major_radius, minor_radius, std::back_inserter(points));
|
||||||
|
|
||||||
|
CGAL::Vector_3<K> n = random_normal<K>();
|
||||||
|
n = CGAL::cross_product(axis, n);
|
||||||
|
n = n * (FT) 1.0 / (CGAL::sqrt(n.squared_length()));
|
||||||
|
CGAL::Plane_3<K> pl(center, n);
|
||||||
|
|
||||||
|
FT spacing = (FT) 1;
|
||||||
|
|
||||||
|
filter_by_distance(pl, spacing * (K::FT) 0.5, points);
|
||||||
|
|
||||||
|
Efficient_ransac ransac;
|
||||||
|
|
||||||
|
ransac.template add_shape_factory<Torus>();
|
||||||
|
|
||||||
|
ransac.set_input(points);
|
||||||
|
|
||||||
|
// Same parameters as for the parameters unit tests, besides
|
||||||
|
// the cluster_epsilon.
|
||||||
|
typename Efficient_ransac::Parameters parameters;
|
||||||
|
parameters.probability = 0.05f;
|
||||||
|
parameters.min_points = NB_POINTS/10;
|
||||||
|
parameters.epsilon = 0.002f;
|
||||||
|
parameters.normal_threshold = 0.9f;
|
||||||
|
|
||||||
|
// The first half of rounds choose a high cluster_epsilon to get only
|
||||||
|
// a single shape and a lower cluster_epsilon for the second half
|
||||||
|
// to get two separated shapes.
|
||||||
|
if (i < NB_ROUNDS/2)
|
||||||
|
parameters.cluster_epsilon = spacing * (FT) 1.5;
|
||||||
|
else
|
||||||
|
parameters.cluster_epsilon = spacing * (FT) 0.9;
|
||||||
|
|
||||||
|
if (!ransac.detect(parameters)) {
|
||||||
|
std::cout << " aborted" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
typename Efficient_ransac::Shape_range shapes = ransac.shapes();
|
||||||
|
|
||||||
|
if (i < NB_ROUNDS/2 && shapes.size() != 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (i >= NB_ROUNDS/2 && shapes.size() != 2)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
success++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (success >= NB_ROUNDS * 0.8) {
|
||||||
|
std::cout << " succeeded" << std::endl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::cout << " failed" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
std::cout << "test_torus_connected_component<CGAL::Simple_cartesian<float>> ";
|
||||||
|
if (!test_torus_connected_component<CGAL::Simple_cartesian<float> >())
|
||||||
|
success = false;
|
||||||
|
|
||||||
|
std::cout << "test_torus_connected_component<CGAL::Simple_cartesian<double>> ";
|
||||||
|
if (!test_torus_connected_component<CGAL::Simple_cartesian<double> >())
|
||||||
|
success = false;
|
||||||
|
|
||||||
|
std::cout << "test_torus_connected_component<CGAL::Exact_predicates_inexact_constructions_kernel> ";
|
||||||
|
if (!test_torus_connected_component<CGAL::Exact_predicates_inexact_constructions_kernel>())
|
||||||
|
success = false;
|
||||||
|
|
||||||
|
return (success) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue