// ============================================================================ // // Copyright (c) 1997 The CGAL Consortium // // This software and related documentation is part of an INTERNAL release // of the Computational Geometry Algorithms Library (CGAL). It is not // intended for general use. // // ---------------------------------------------------------------------------- // // release : $CGAL_Revision: $ // release_date : $CGAL_Date: $ // // file : point_generators_3.h // chapter : $CGAL_Chapter: Geometric Object Generators $ // package : $CGAL_Package: Generator 2.12 (28 Jul 1999) $ // revision : $Revision$ // revision_date : $Date$ // author(s) : Lutz Kettner // // coordinator : INRIA, Sophia Antipolis // // 3D Point Generators // ============================================================================ #ifndef CGAL_POINT_GENERATORS_3_H #define CGAL_POINT_GENERATORS_3_H 1 #include #include #include CGAL_BEGIN_NAMESPACE template < class P, class Creator = Creator_uniform_3::Kernel::RT,P> > class Random_points_in_sphere_3 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_in_sphere_3 This; Random_points_in_sphere_3( double r = 1, Random& rnd = default_random) // g is an input iterator creating points of type `P' uniformly // distributed in the open sphere with radius r, i.e. |`*g'| < r . // Three random numbers are needed from `rnd' for each point. : Random_generator_base

( r, rnd) { generate_point(); } This& operator++() { generate_point(); return *this; } This operator++(int) { This tmp = *this; ++(*this); return tmp; } }; template < class P, class Creator > void Random_points_in_sphere_3:: generate_point() { typedef typename Creator::argument_type T; do { Creator creator; this->d_item = creator( T(this->d_range * ( 2 * this->_rnd.get_double() - 1.0)), T(this->d_range * ( 2 * this->_rnd.get_double() - 1.0)), T(this->d_range * ( 2 * this->_rnd.get_double() - 1.0))); } while (CGAL::to_double(this->d_item.x() * this->d_item.x() + this->d_item.y() * this->d_item.y() + this->d_item.z() * this->d_item.z()) >= this->d_range * this->d_range); } template < class P, class Creator = Creator_uniform_3::Kernel::RT,P> > class Random_points_on_sphere_3 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_on_sphere_3 This; Random_points_on_sphere_3( double r = 1, Random& rnd = default_random) // g is an input iterator creating points of type `P' uniformly // distributed on the circle with radius r, i.e. |`*g'| == r . A // single random number is needed from `rnd' for each point. : Random_generator_base

( r, rnd) { generate_point(); } This& operator++() { generate_point(); return *this; } This operator++(int) { This tmp = *this; ++(*this); return tmp; } }; template < class P, class Creator > void Random_points_on_sphere_3:: generate_point() { typedef typename Creator::argument_type T; double alpha = this->_rnd.get_double() * 2.0 * CGAL_PI; double z = 2 * this->_rnd.get_double() - 1.0; double r = std::sqrt( 1 - z * z); Creator creator; this->d_item = creator( T(this->d_range * r * CGAL_CLIB_STD::cos(alpha)), T(this->d_range * r * CGAL_CLIB_STD::sin(alpha)), T(this->d_range * z)); } template < class P, class Creator = Creator_uniform_3::Kernel::RT,P> > class Random_points_in_cube_3 : public Random_generator_base

{ void generate_point(); public: typedef Random_points_in_cube_3 This; Random_points_in_cube_3( double a = 1, Random& rnd = default_random) : Random_generator_base

( a, rnd) { generate_point(); } This& operator++() { generate_point(); return *this; } This operator++(int) { This tmp = *this; ++(*this); return tmp; } }; template < class P, class Creator > void Random_points_in_cube_3:: generate_point() { typedef typename Creator::argument_type T; Creator creator; this->d_item = creator( T(this->d_range * ( 2 * this->_rnd.get_double() - 1.0)), T(this->d_range * ( 2 * this->_rnd.get_double() - 1.0)), T(this->d_range * ( 2 * this->_rnd.get_double() - 1.0))); } template OutputIterator points_on_cube_grid_3( double a, std::size_t n, OutputIterator o, Creator creator) { if (n == 0) return o; int m = int(CGAL_CLIB_STD::ceil( std::sqrt(std::sqrt(static_cast(n))))); while (m*m*m < int(n)) m++; double base = -a; // Left and bottom boundary. double step = 2*a/(m-1); int j = 0; int k = 0; double px = base; double py = base; double pz = base; *o++ = creator( px, py, pz); for (std::size_t i = 1; i < n; i++) { j++; if ( j == m) { k++; if ( k == m) { py = base; px = base; pz = pz + step; k = 0; } else { px = base; py = py + step; } j = 0; } else { px = px + step; } *o++ = creator( px, py, pz); } return o; } template OutputIterator points_on_cube_grid_3( double a, std::size_t n, OutputIterator o) { typedef std::iterator_traits ITraits; typedef typename ITraits::value_type P; return points_on_square_grid_3(a, n, o, Creator_uniform_3::Kernel::RT,P>()); } CGAL_END_NAMESPACE #endif // CGAL_POINT_GENERATORS_3_H // // EOF //