From ecfc04d4519cb4fa4f646a1586a27c085c1d3df6 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Fri, 12 Jun 2015 17:29:25 +0200 Subject: [PATCH] Fix more compilation errors on GCC --- .../Point_set_shape_detection_3/generators.h | 46 +++++++++++-------- .../test_cylinders_parameters.cpp | 18 ++++---- .../test_plane_connected_component.cpp | 11 ++--- .../test_plane_parameters.cpp | 17 +++---- 4 files changed, 49 insertions(+), 43 deletions(-) diff --git a/Point_set_shape_detection_3/test/Point_set_shape_detection_3/generators.h b/Point_set_shape_detection_3/test/Point_set_shape_detection_3/generators.h index eeb9823b4ef..efa91c3a1bd 100644 --- a/Point_set_shape_detection_3/test/Point_set_shape_detection_3/generators.h +++ b/Point_set_shape_detection_3/test/Point_set_shape_detection_3/generators.h @@ -3,22 +3,23 @@ #include #include +#include #include #include -template -FT random_float(FT min, FT max) { +template +fl_t random_float(fl_t min, fl_t max) { static CGAL::Random rand; - return FT(rand.get_double(min, max)); + return fl_t(rand.get_double(min, max)); } template typename CGAL::Vector_3 random_normal() { CGAL::Vector_3 n; do { - n = CGAL::Vector_3(random_float(-1.0, 1.0), - random_float(-1.0, 1.0), - random_float(-1.0, 1.0)); + n = CGAL::Vector_3(random_float(-1.0, 1.0), + random_float(-1.0, 1.0), + random_float(-1.0, 1.0)); } while (n.squared_length() < 0.001); n = n * 1.0 / (CGAL::sqrt(n.squared_length())); @@ -31,9 +32,9 @@ typename CGAL::Point_3 random_point_in(const CGAL::Bbox_3& bbox) { typedef typename K::FT FT; - FT x = random_float(bbox.xmin(), bbox.xmax()); - FT y = random_float(bbox.ymin(), bbox.ymax()); - FT z = random_float(bbox.zmin(), bbox.zmax()); + FT x = random_float(bbox.xmin(), bbox.xmax()); + FT y = random_float(bbox.ymin(), bbox.ymax()); + FT z = random_float(bbox.zmin(), bbox.zmax()); return typename CGAL::Point_3(x, y, z); } @@ -77,9 +78,10 @@ void sampleCylinderInBox(const std::size_t num_points, const typename K::FT length, OutputIterator points) { // Sample shape for (size_t i = 0 ; i < num_points ; ++i) { - CGAL::Vector_3 normal(random_float(-1., 1.), - random_float(-1., 1.), - random_float(-1., 1.)); + CGAL::Vector_3 normal( + random_float(-1., 1.), + random_float(-1., 1.), + random_float(-1., 1.)); normal = normal - ((normal * axis) * axis); if (normal.squared_length() < 0.0001) { i--; @@ -87,7 +89,7 @@ void sampleCylinderInBox(const std::size_t num_points, } normal = normal * (1.0 / sqrt(normal.squared_length())); - typename K::FT l = random_float(-length, length); + typename K::FT l = random_float(-length, length); CGAL::Point_3 p = center + axis * l + radius * normal; *points = CGAL::Point_with_normal_3(p, normal); @@ -102,8 +104,8 @@ void sampleRandomCylinderInBox(const std::size_t num_points, OutputIterator points) { // Generate random parameters axis = random_normal(); - radius = random_float(0.5, 5.); - typename K::FT length = random_float(0.2, 10.); + radius = random_float(0.5, 5.); + typename K::FT length = random_float(0.2, 10.); // Find random center point placed on the plane through // the origin with 'axis' as normal. @@ -112,7 +114,7 @@ void sampleRandomCylinderInBox(const std::size_t num_points, v = v * 1.0 / CGAL::sqrt(v.squared_length()); u = CGAL::cross_product(v, axis); - center = CGAL::ORIGIN + random_float(-5., 5.) * u + random_float(-5., 5.) * v; + center = CGAL::ORIGIN + random_float(-5., 5.) * u + random_float(-5., 5.) * v; sampleCylinderInBox(num_points, bbox, center, axis, radius, length, points); } @@ -121,6 +123,8 @@ template void generatePointsOnCone(const std::size_t num_points, typename CGAL::Point_3 const& apex, typename CGAL::Vector_3 const& axis, typename K::FT angle, typename K::FT s, typename K::FT e, OutputIterator points) { typedef typename K::FT FT; + typedef typename CGAL::Vector_3 Vector; + assert(s < e); FT radiusGrow = std::tan(angle); axis = axis * 1.0 / (CGAL::sqrt(axis.squared_length())); @@ -191,8 +195,8 @@ void sampleRandomParallelogramInBox(const std::size_t num_points, const CGAL::Bb v = p[2] - p[0]; for (std::size_t i = 0;i < num_points; ++i) { - double s = random_float(0., 1.); - double t = random_float(0., 1.); + double s = random_float(0., 1.); + double t = random_float(0., 1.); *points = CGAL::Point_with_normal_3(p[0] + s * u + t * v, normal); ++points; @@ -200,8 +204,12 @@ void sampleRandomParallelogramInBox(const std::size_t num_points, const CGAL::Bb } template -void generatePointsOnTorus(const std::size_t num_points, typename CGAL::Point_3 const& center, typename CGAL::Vector_3 const& axis, typename K::FT majorRadius, typename K::FT minorRadius, OutputIterator points) +void generatePointsOnTorus(const std::size_t num_points, CGAL::Point_3 const& center, CGAL::Vector_3 const& axis, typename K::FT majorRadius, typename K::FT minorRadius, OutputIterator points) { + typedef typename K::FT FT; + typedef CGAL::Point_3 Point; + typedef CGAL::Vector_3 Vector; + size_t i = 0; axis = axis / CGAL::sqrt(axis.squared_length()); diff --git a/Point_set_shape_detection_3/test/Point_set_shape_detection_3/test_cylinders_parameters.cpp b/Point_set_shape_detection_3/test/Point_set_shape_detection_3/test_cylinders_parameters.cpp index 9feb1211bbd..7a244b30fa7 100644 --- a/Point_set_shape_detection_3/test/Point_set_shape_detection_3/test_cylinders_parameters.cpp +++ b/Point_set_shape_detection_3/test/Point_set_shape_detection_3/test_cylinders_parameters.cpp @@ -19,11 +19,11 @@ bool test_cylinder_parameters() { typedef typename CGAL::Identity_property_map Point_map; typedef typename CGAL::Normal_of_point_with_normal_pmap Normal_map; - typedef CGAL::Shape_detection_3::Efficient_RANSAC_traits Traits; + typedef CGAL::Shape_detection_3::Efficient_RANSAC_traits< + K, Pwn_vector, Point_map, Normal_map> Traits; - typedef CGAL::Shape_detection_3::Efficient_RANSAC Efficient_ransac; - typedef CGAL::Shape_detection_3::Cylinder Cylinder; + typedef CGAL::Shape_detection_3::Efficient_RANSAC Efficient_ransac; + typedef CGAL::Shape_detection_3::Cylinder Cylinder; std::size_t success = 0; @@ -32,7 +32,7 @@ bool test_cylinder_parameters() { Pwn_vector points; // generate random points on random cylinder - typename K::FT radius = (FT)0; // radius will be randomly generated by sampleRandomCylinderInBox + typename K::FT radius = 0; // radius will be randomly generated by sampleRandomCylinderInBox Vector axis; Point center; CGAL::Bbox_3 bbox(-10, -10, -10, 10, 10, 10); @@ -54,7 +54,7 @@ bool test_cylinder_parameters() { // Set cluster epsilon to a high value as just the parameters of // the extracted primitives are to be tested. - Efficient_ransac::Parameters parameters; + typename Efficient_ransac::Parameters parameters; parameters.probability = 0.05f; parameters.min_points = ptsCount/10; parameters.epsilon = 0.002f; @@ -66,7 +66,7 @@ bool test_cylinder_parameters() { return false; } - Efficient_ransac::Shape_range shapes = ransac.shapes(); + typename Efficient_ransac::Shape_range shapes = ransac.shapes(); // check: unique shape detected if (shapes.size() != 1) @@ -108,11 +108,11 @@ int main() { bool success = true; std::cout << "test_cylinder_parameters> "; - if (!test_cylinder_parameters>()) + if (!test_cylinder_parameters >()) success = false; std::cout << "test_cylinder_parameters> "; - if (!test_cylinder_parameters>()) + if (!test_cylinder_parameters >()) success = false; std::cout << "test_cylinder_parameters "; diff --git a/Point_set_shape_detection_3/test/Point_set_shape_detection_3/test_plane_connected_component.cpp b/Point_set_shape_detection_3/test/Point_set_shape_detection_3/test_plane_connected_component.cpp index 58058343ebf..51b982bf192 100644 --- a/Point_set_shape_detection_3/test/Point_set_shape_detection_3/test_plane_connected_component.cpp +++ b/Point_set_shape_detection_3/test/Point_set_shape_detection_3/test_plane_connected_component.cpp @@ -31,12 +31,9 @@ bool test_plane_connected_component() { for (std::size_t i = 0;i> "; - if (!test_plane_connected_component>()) + if (!test_plane_connected_component >()) success = false; std::cout << "test_plane_connected_component> "; - if (!test_plane_connected_component>()) + if (!test_plane_connected_component >()) success = false; std::cout << "test_plane_connected_component "; diff --git a/Point_set_shape_detection_3/test/Point_set_shape_detection_3/test_plane_parameters.cpp b/Point_set_shape_detection_3/test/Point_set_shape_detection_3/test_plane_parameters.cpp index 68205249db3..c089e605569 100644 --- a/Point_set_shape_detection_3/test/Point_set_shape_detection_3/test_plane_parameters.cpp +++ b/Point_set_shape_detection_3/test/Point_set_shape_detection_3/test_plane_parameters.cpp @@ -12,6 +12,7 @@ const int ptsCount = 1000; template bool test_plane_parameters() { + typedef typename K::FT FT; typedef typename CGAL::Point_with_normal_3 Pwn; typedef typename CGAL::Point_3 Point; typedef typename CGAL::Vector_3 Vector; @@ -30,7 +31,7 @@ bool test_plane_parameters() { for (std::size_t i = 0;iplane_normal(); - const K::FT sign = (phi < 0) ? -1.0f : 1.0f; + const FT phi = normal * pl->plane_normal(); + const FT sign = (phi < 0) ? -1.0f : 1.0f; - const K::FT dist2 = (CGAL::Plane_3(*pl)).d(); + const FT dist2 = (CGAL::Plane_3(*pl)).d(); if (abs(phi) < 0.98 || abs(dist2 - sign * dist) > 0.02) continue; @@ -98,11 +99,11 @@ int main() { bool success = true; std::cout << "test_plane_parameters> "; - if (!test_plane_parameters>()) + if (!test_plane_parameters >()) success = false; std::cout << "test_plane_parameters> "; - if (!test_plane_parameters>()) + if (!test_plane_parameters >()) success = false; std::cout << "test_plane_parameters ";