Fix more compilation errors on GCC

This commit is contained in:
Clement Jamin 2015-06-12 17:29:25 +02:00
parent 1e39860061
commit ecfc04d451
4 changed files with 49 additions and 43 deletions

View File

@ -3,22 +3,23 @@
#include <CGAL/Random.h>
#include <CGAL/Point_with_normal_3.h>
#include <CGAL/Kernel/global_functions.h>
#include <string>
#include <fstream>
template <typename FT>
FT random_float(FT min, FT max) {
template <typename fl_t>
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 K>
typename CGAL::Vector_3<K> random_normal() {
CGAL::Vector_3<K> n;
do {
n = CGAL::Vector_3<K>(random_float<K>(-1.0, 1.0),
random_float<K>(-1.0, 1.0),
random_float<K>(-1.0, 1.0));
n = CGAL::Vector_3<K>(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<K> random_point_in(const CGAL::Bbox_3& bbox)
{
typedef typename K::FT FT;
FT x = random_float<K>(bbox.xmin(), bbox.xmax());
FT y = random_float<K>(bbox.ymin(), bbox.ymax());
FT z = random_float<K>(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<K>(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<K> normal(random_float<K>(-1., 1.),
random_float<K>(-1., 1.),
random_float<K>(-1., 1.));
CGAL::Vector_3<K> 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<K>(-length, length);
typename K::FT l = random_float(-length, length);
CGAL::Point_3<K> p = center + axis * l + radius * normal;
*points = CGAL::Point_with_normal_3<K>(p, normal);
@ -102,8 +104,8 @@ void sampleRandomCylinderInBox(const std::size_t num_points,
OutputIterator points) {
// Generate random parameters
axis = random_normal<K>();
radius = random_float<K>(0.5, 5.);
typename K::FT length = random_float<K>(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<K>(-5., 5.) * u + random_float<K>(-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 <typename K, typename OutputIterator>
void generatePointsOnCone(const std::size_t num_points, typename CGAL::Point_3<K> const& apex, typename CGAL::Vector_3<K> 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<K> 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<K>(0., 1.);
double t = random_float<K>(0., 1.);
double s = random_float(0., 1.);
double t = random_float(0., 1.);
*points = CGAL::Point_with_normal_3<K>(p[0] + s * u + t * v, normal);
++points;
@ -200,8 +204,12 @@ void sampleRandomParallelogramInBox(const std::size_t num_points, const CGAL::Bb
}
template <typename K, typename OutputIterator>
void generatePointsOnTorus(const std::size_t num_points, typename CGAL::Point_3<K> const& center, typename CGAL::Vector_3<K> const& axis, typename K::FT majorRadius, typename K::FT minorRadius, OutputIterator points)
void generatePointsOnTorus(const std::size_t num_points, CGAL::Point_3<K> const& center, CGAL::Vector_3<K> const& axis, typename K::FT majorRadius, typename K::FT minorRadius, OutputIterator points)
{
typedef typename K::FT FT;
typedef CGAL::Point_3<K> Point;
typedef CGAL::Vector_3<K> Vector;
size_t i = 0;
axis = axis / CGAL::sqrt(axis.squared_length());

View File

@ -19,11 +19,11 @@ bool test_cylinder_parameters() {
typedef typename CGAL::Identity_property_map<Pwn> Point_map;
typedef typename 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<
K, Pwn_vector, Point_map, Normal_map> Traits;
typedef CGAL::Shape_detection_3::Efficient_RANSAC<Traits> Efficient_ransac;
typedef CGAL::Shape_detection_3::Cylinder<Traits> Cylinder;
typedef CGAL::Shape_detection_3::Efficient_RANSAC<Traits> Efficient_ransac;
typedef CGAL::Shape_detection_3::Cylinder<Traits> 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<CGAL::Simple_cartesian<float>> ";
if (!test_cylinder_parameters<CGAL::Simple_cartesian<float>>())
if (!test_cylinder_parameters<CGAL::Simple_cartesian<float> >())
success = false;
std::cout << "test_cylinder_parameters<CGAL::Simple_cartesian<double>> ";
if (!test_cylinder_parameters<CGAL::Simple_cartesian<double>>())
if (!test_cylinder_parameters<CGAL::Simple_cartesian<double> >())
success = false;
std::cout << "test_cylinder_parameters<CGAL::Exact_predicates_inexact_constructions_kernel> ";

View File

@ -31,12 +31,9 @@ bool test_plane_connected_component() {
for (std::size_t i = 0;i<rounds;i++) {
Pwn_vector points;
K::FT dist = 0;
Vector normal;
CGAL::Bbox_3 bbox(-10, -10, -10, 10, 10, 10);
std::size_t index = 0;
// Sample 4 rectangles with 0.05 spacing between points
// and 0.2 spacing between rectangles.
Vector offset[] = {Vector(0, 0, 0), Vector(1.2, 0, 0),
@ -59,7 +56,7 @@ bool test_plane_connected_component() {
// shape and for the second half choose a small cluster_epsilon to find
// four separated shapes.
Efficient_ransac::Parameters parameters;
typename Efficient_ransac::Parameters parameters;
parameters.probability = 0.05f;
parameters.min_points = 100;
parameters.epsilon = 0.002f;
@ -75,7 +72,7 @@ bool test_plane_connected_component() {
return false;
}
Efficient_ransac::Shape_range shapes = ransac.shapes();
typename Efficient_ransac::Shape_range shapes = ransac.shapes();
if (i <= rounds/2 && shapes.size() != 1)
continue;
@ -101,11 +98,11 @@ int main() {
bool success = true;
std::cout << "test_plane_connected_component<CGAL::Simple_cartesian<float>> ";
if (!test_plane_connected_component<CGAL::Simple_cartesian<float>>())
if (!test_plane_connected_component<CGAL::Simple_cartesian<float> >())
success = false;
std::cout << "test_plane_connected_component<CGAL::Simple_cartesian<double>> ";
if (!test_plane_connected_component<CGAL::Simple_cartesian<double>>())
if (!test_plane_connected_component<CGAL::Simple_cartesian<double> >())
success = false;
std::cout << "test_plane_connected_component<CGAL::Exact_predicates_inexact_constructions_kernel> ";

View File

@ -12,6 +12,7 @@ const int ptsCount = 1000;
template <class K>
bool test_plane_parameters() {
typedef typename K::FT FT;
typedef typename CGAL::Point_with_normal_3<K> Pwn;
typedef typename CGAL::Point_3<K> Point;
typedef typename CGAL::Vector_3<K> Vector;
@ -30,7 +31,7 @@ bool test_plane_parameters() {
for (std::size_t i = 0;i<rounds;i++) {
Pwn_vector points;
K::FT dist = 0;
typename K::FT dist = 0;
Vector normal;
CGAL::Bbox_3 bbox(-10, -10, -10, 10, 10, 10);
@ -50,7 +51,7 @@ bool test_plane_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 = 100;
parameters.epsilon = 0.002f;
@ -62,7 +63,7 @@ bool test_plane_parameters() {
return false;
}
Efficient_ransac::Shape_range shapes = ransac.shapes();
typename Efficient_ransac::Shape_range shapes = ransac.shapes();
if (shapes.size() != 1)
continue;
@ -72,10 +73,10 @@ bool test_plane_parameters() {
if (!pl)
continue;
const K::FT phi = normal * pl->plane_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<K>(*pl)).d();
const FT dist2 = (CGAL::Plane_3<K>(*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<CGAL::Simple_cartesian<float>> ";
if (!test_plane_parameters<CGAL::Simple_cartesian<float>>())
if (!test_plane_parameters<CGAL::Simple_cartesian<float> >())
success = false;
std::cout << "test_plane_parameters<CGAL::Simple_cartesian<double>> ";
if (!test_plane_parameters<CGAL::Simple_cartesian<double>>())
if (!test_plane_parameters<CGAL::Simple_cartesian<double> >())
success = false;
std::cout << "test_plane_parameters<CGAL::Exact_predicates_inexact_constructions_kernel> ";