From 13b9f6b254141fdc4e445d197dc8db45f601df4e Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Wed, 15 Oct 2014 18:17:38 +0200 Subject: [PATCH] Code reorganization + function to generate points on n-spheres --- .../test_tangential_complex.cpp | 132 ++------------- .../test/Tangential_complex/test_utilities.h | 152 ++++++++++++++++++ 2 files changed, 168 insertions(+), 116 deletions(-) create mode 100644 Tangential_complex/test/Tangential_complex/test_utilities.h diff --git a/Tangential_complex/test/Tangential_complex/test_tangential_complex.cpp b/Tangential_complex/test/Tangential_complex/test_tangential_complex.cpp index 5817608f200..1123f9a81f6 100644 --- a/Tangential_complex/test/Tangential_complex/test_tangential_complex.cpp +++ b/Tangential_complex/test/Tangential_complex/test_tangential_complex.cpp @@ -6,9 +6,10 @@ # define TBB_USE_THREADING_TOOL #endif +#include "test_utilities.h" + #include #include -#include #include #include #include @@ -21,121 +22,15 @@ #endif #ifdef _DEBUG - const int NUM_POINTS = 6; + const int NUM_POINTS = 50; #else - const int NUM_POINTS = 50000; + const int NUM_POINTS = 500; #endif -template -std::vector generate_points_on_plane() -{ - typedef typename CGAL::Kernel_traits::type Kernel; - typedef typename Kernel::FT FT; - CGAL::Random rng; - std::vector points; - points.reserve(NUM_POINTS); - for (int i = 0 ; i != NUM_POINTS ; ++i) - { - FT x = rng.get_double(0, 5); - FT y = rng.get_double(0, 5); - points.push_back(Kernel().construct_point_d_object()(x, y, 0)); - } - return points; -} - -template -std::vector generate_points_on_sphere(double radius) -{ - CGAL::Random_points_on_sphere_3 generator(radius); - std::vector points; - points.reserve(NUM_POINTS); - for (int i = 0 ; i != NUM_POINTS ; ++i) - points.push_back(*generator++); - return points; -} - -// a = big radius, b = small radius -template -std::vector generate_points_on_klein_bottle_3D( - double a, double b, bool uniform = false) -{ - typedef typename CGAL::Kernel_traits::type Kernel; - typedef typename Kernel::FT FT; - CGAL::Random rng; - - // if uniform - int num_lines = (int)sqrt(NUM_POINTS); - int num_cols = NUM_POINTS/num_lines + 1; - - std::vector points; - points.reserve(NUM_POINTS); - for (int i = 0 ; i != NUM_POINTS ; ++i) - { - FT u, v; - if (uniform) - { - int k1 = i / num_lines; - int k2 = i % num_lines; - u = 6.2832 * k1 / num_lines; - v = 6.2832 * k2 / num_lines; - } - else - { - u = rng.get_double(0, 6.2832); - v = rng.get_double(0, 6.2832); - } - double tmp = cos(u/2)*sin(v) - sin(u/2)*sin(2.*v); - points.push_back(Kernel().construct_point_d_object()( - (a + b*tmp)*cos(u), - (a + b*tmp)*sin(u), - b*(sin(u/2)*sin(v) + cos(u/2)*sin(2.*v)))); - } - return points; -} - -// a = big radius, b = small radius -template -std::vector generate_points_on_klein_bottle_4D( - double a, double b, bool uniform = false) -{ - typedef typename CGAL::Kernel_traits::type Kernel; - typedef typename Kernel::FT FT; - CGAL::Random rng; - - // if uniform - int num_lines = (int)sqrt(NUM_POINTS); - int num_cols = NUM_POINTS/num_lines + 1; - - std::vector points; - points.reserve(NUM_POINTS); - for (int i = 0 ; i != NUM_POINTS ; ++i) - { - FT u, v; - if (uniform) - { - int k1 = i / num_lines; - int k2 = i % num_lines; - u = 6.2832 * k1 / num_lines; - v = 6.2832 * k2 / num_lines; - } - else - { - u = rng.get_double(0, 6.2832); - v = rng.get_double(0, 6.2832); - } - points.push_back(Kernel().construct_point_d_object()( - (a + b*cos(v))*cos(u), - (a + b*cos(v))*sin(u), - b*sin(v)*cos(u/2), - b*sin(v)*sin(u/2))); - } - return points; -} - int main() { - const int INTRINSIC_DIMENSION = 2; - const int AMBIENT_DIMENSION = 4; + const int INTRINSIC_DIMENSION = 4; + const int AMBIENT_DIMENSION = 5; typedef CGAL::Epick_d > Kernel; typedef Kernel::Point_d Point; @@ -158,10 +53,11 @@ int main() CGAL::default_random = CGAL::Random(i); std::cerr << "Random seed = " << i << std::endl; - //std::vector points = generate_points_on_plane(); - //std::vector points = generate_points_on_sphere(3.0); - //std::vector points = generate_points_on_klein_bottle_3D(4., 3.); - std::vector points = generate_points_on_klein_bottle_4D(4., 3.); + //std::vector points = generate_points_on_plane(NUM_POINTS); + //std::vector points = generate_points_on_sphere_3(NUM_POINTS, 3.0); + std::vector points = generate_points_on_sphere_d(NUM_POINTS, AMBIENT_DIMENSION, 3.0); + //std::vector points = generate_points_on_klein_bottle_3D(NUM_POINTS, 4., 3.); + //std::vector points = generate_points_on_klein_bottle_4D(NUM_POINTS, 4., 3.); CGAL::Tangential_complex< Kernel, @@ -179,7 +75,11 @@ int main() output_filename << "data/test_tc_" << INTRINSIC_DIMENSION << "_in_R" << AMBIENT_DIMENSION << ".off"; std::ofstream off_stream(output_filename.str()); - tc.export_to_off(off_stream, true, &incorrect_simplices, true); + if (INTRINSIC_DIMENSION <= 3) + tc.export_to_off(off_stream, true, &incorrect_simplices, true); + else + tc.number_of_inconsistent_simplices(); + double export_time = t.elapsed(); t.reset(); std::cerr << std::endl diff --git a/Tangential_complex/test/Tangential_complex/test_utilities.h b/Tangential_complex/test/Tangential_complex/test_utilities.h new file mode 100644 index 00000000000..6391fe1da6f --- /dev/null +++ b/Tangential_complex/test/Tangential_complex/test_utilities.h @@ -0,0 +1,152 @@ +// Copyright (c) 2014 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Clement Jamin +// +//****************************************************************************** +// File Description : +// +//****************************************************************************** + +#ifndef CGAL_TC_TEST_TEST_UTILITIES_H +#define CGAL_TC_TEST_TEST_UTILITIES_H + +#include +#include +#include + +template +std::vector generate_points_on_plane(std::size_t num_points) +{ + typedef typename CGAL::Kernel_traits::type Kernel; + typedef typename Kernel::FT FT; + CGAL::Random rng; + std::vector points; + points.reserve(NUM_POINTS); + for (int i = 0 ; i != NUM_POINTS ; ++i) + { + FT x = rng.get_double(0, 5); + FT y = rng.get_double(0, 5); + points.push_back(Kernel().construct_point_d_object()(x, y, 0)); + } + return points; +} + +template +std::vector generate_points_on_sphere_3( + std::size_t num_points, double radius) +{ + CGAL::Random_points_on_sphere_3 generator(radius); + std::vector points; + points.reserve(NUM_POINTS); + for (int i = 0 ; i != NUM_POINTS ; ++i) + points.push_back(*generator++); + return points; +} + +template +std::vector generate_points_on_sphere_d( + std::size_t num_points, int dim, double radius) +{ + CGAL::Random_points_on_sphere_d generator(dim, radius); + std::vector points; + points.reserve(NUM_POINTS); + for (int i = 0 ; i != NUM_POINTS ; ++i) + points.push_back(*generator++); + return points; +} + +// a = big radius, b = small radius +template +std::vector generate_points_on_klein_bottle_3D( + std::size_t num_points, double a, double b, bool uniform = false) +{ + typedef typename CGAL::Kernel_traits::type Kernel; + typedef typename Kernel::FT FT; + CGAL::Random rng; + + // if uniform + int num_lines = (int)sqrt(NUM_POINTS); + int num_cols = NUM_POINTS/num_lines + 1; + + std::vector points; + points.reserve(NUM_POINTS); + for (int i = 0 ; i != NUM_POINTS ; ++i) + { + FT u, v; + if (uniform) + { + int k1 = i / num_lines; + int k2 = i % num_lines; + u = 6.2832 * k1 / num_lines; + v = 6.2832 * k2 / num_lines; + } + else + { + u = rng.get_double(0, 6.2832); + v = rng.get_double(0, 6.2832); + } + double tmp = cos(u/2)*sin(v) - sin(u/2)*sin(2.*v); + points.push_back(Kernel().construct_point_d_object()( + (a + b*tmp)*cos(u), + (a + b*tmp)*sin(u), + b*(sin(u/2)*sin(v) + cos(u/2)*sin(2.*v)))); + } + return points; +} + +// a = big radius, b = small radius +template +std::vector generate_points_on_klein_bottle_4D( + std::size_t num_points, double a, double b, bool uniform = false) +{ + typedef typename CGAL::Kernel_traits::type Kernel; + typedef typename Kernel::FT FT; + CGAL::Random rng; + + // if uniform + int num_lines = (int)sqrt(NUM_POINTS); + int num_cols = NUM_POINTS/num_lines + 1; + + std::vector points; + points.reserve(NUM_POINTS); + for (int i = 0 ; i != NUM_POINTS ; ++i) + { + FT u, v; + if (uniform) + { + int k1 = i / num_lines; + int k2 = i % num_lines; + u = 6.2832 * k1 / num_lines; + v = 6.2832 * k2 / num_lines; + } + else + { + u = rng.get_double(0, 6.2832); + v = rng.get_double(0, 6.2832); + } + points.push_back(Kernel().construct_point_d_object()( + (a + b*cos(v))*cos(u) + rng.get_double(0, 0.01), + (a + b*cos(v))*sin(u) + rng.get_double(0, 0.01), + b*sin(v)*cos(u/2) + rng.get_double(0, 0.01), + b*sin(v)*sin(u/2) + rng.get_double(0, 0.01)) ); + } + return points; +} + +#endif // CGAL_MESH_3_TEST_TEST_UTILITIES_H