used std::array for point storage in the following examples of Bounding_volumes (1)min_annulus_d_fast_exact.cpp (2)min_annulus_d.cpp (3)min_ellipse_2.cpp (4)min_sphere_3.cpp (5)min_sphere_homogenous_3.cpp

This commit is contained in:
Anirudh Lakhanpal 2025-01-26 17:54:36 +05:30
parent 27c788d1d3
commit 057caa3d19
5 changed files with 18 additions and 17 deletions

View File

@ -6,6 +6,7 @@
#include <CGAL/Homogeneous.h> #include <CGAL/Homogeneous.h>
#include <iostream> #include <iostream>
#include <cassert> #include <cassert>
#include <array>
#ifdef CGAL_USE_GMP #ifdef CGAL_USE_GMP
#include <CGAL/Gmpzf.h> #include <CGAL/Gmpzf.h>
@ -25,10 +26,10 @@ typedef CGAL::Min_annulus_d<Traits> Min_annulus;
int main() int main()
{ {
// points on the squares [-1,1]^2 and [-2,2]^2 // points on the squares [-1,1]^2 and [-2,2]^2
Point P[8] = { Point(-1,-1), Point(-1,1), Point(1,-1), Point(1,1), std::array<Point, 8> P = { Point(-1,-1), Point(-1,1), Point(1,-1), Point(1,1),
Point(-2,-2), Point(-2,2), Point(2,-2), Point(2,2)}; Point(-2,-2), Point(-2,2), Point(2,-2), Point(2,2)};
Min_annulus ma(P, P+8); Min_annulus ma(P.begin(), P.end());
assert (ma.is_valid()); assert (ma.is_valid());
// get center of annulus // get center of annulus

View File

@ -11,7 +11,7 @@ typedef CGAL::Exact_integer ET;
#include <iostream> #include <iostream>
#include <cassert> #include <cassert>
#include <array>
// use an inexact kernel... // use an inexact kernel...
typedef CGAL::Homogeneous<double> K; typedef CGAL::Homogeneous<double> K;
typedef K::Point_2 Point; typedef K::Point_2 Point;
@ -24,10 +24,10 @@ typedef CGAL::Min_annulus_d<Traits> Min_annulus;
int main() int main()
{ {
// points on the squares [-1,1]^2 and [-2,2]^2 // points on the squares [-1,1]^2 and [-2,2]^2
Point P[8] = { Point(-1,-1), Point(-1,1), Point(1,-1), Point(1,1), std::array<Point, 8> P = { Point(-1,-1), Point(-1,1), Point(1,-1), Point(1,1),
Point(-2,-2), Point(-2,2), Point(2,-2), Point(2,2)}; Point(-2,-2), Point(-2,2), Point(2,-2), Point(2,2)};
Min_annulus ma(P, P+8); Min_annulus ma(P.begin(), P.end());
assert (ma.is_valid()); assert (ma.is_valid());
// get center of annulus // get center of annulus

View File

@ -4,7 +4,7 @@
#include <CGAL/Exact_rational.h> #include <CGAL/Exact_rational.h>
#include <cassert> #include <cassert>
#include <array>
typedef CGAL::Exact_rational NT; typedef CGAL::Exact_rational NT;
typedef CGAL::Cartesian<NT> K; typedef CGAL::Cartesian<NT> K;
typedef CGAL::Point_2<K> Point; typedef CGAL::Point_2<K> Point;
@ -16,20 +16,20 @@ int
main( int, char**) main( int, char**)
{ {
const int n = 200; const int n = 200;
Point P[n]; std::array<Point, n> P;
for ( int i = 0; i < n; ++i) for ( int i = 0; i < n; ++i)
P[ i] = Point( i % 2 ? i : -i , 0); P.at(i) = Point( i % 2 ? i : -i , 0);
// (0,0), (-1,0), (2,0), (-3,0) // (0,0), (-1,0), (2,0), (-3,0)
std::cout << "Computing ellipse (without randomization)..."; std::cout << "Computing ellipse (without randomization)...";
std::cout.flush(); std::cout.flush();
Min_ellipse me1( P, P+n, false); // very slow Min_ellipse me1( P.begin(), P.end(), false); // very slow
std::cout << "done." << std::endl; std::cout << "done." << std::endl;
std::cout << "Computing ellipse (with randomization)..."; std::cout << "Computing ellipse (with randomization)...";
std::cout.flush(); std::cout.flush();
Min_ellipse me2( P, P+n, true); // fast Min_ellipse me2( P.begin(), P.end(), true); // fast
std::cout << "done." << std::endl; std::cout << "done." << std::endl;
// because all input points are collinear, the ellipse is // because all input points are collinear, the ellipse is

View File

@ -5,7 +5,7 @@
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>
#include <array>
typedef CGAL::Simple_cartesian<double> K; typedef CGAL::Simple_cartesian<double> K;
typedef CGAL::Min_sphere_of_points_d_traits_3<K,double> Traits; typedef CGAL::Min_sphere_of_points_d_traits_3<K,double> Traits;
typedef CGAL::Min_sphere_of_spheres_d<Traits> Min_sphere; typedef CGAL::Min_sphere_of_spheres_d<Traits> Min_sphere;
@ -16,16 +16,16 @@ const int d = 3; // dimension of points
int main () int main ()
{ {
Point P[n]; // n points std::array<Point, n> P; // n points
CGAL::Random r; // random number generator CGAL::Random r; // random number generator
for (int i=0; i<n; ++i) { for (int i=0; i<n; ++i) {
for (int j = 0; j < d; ++j) { for (int j = 0; j < d; ++j) {
P[i] = Point(r.get_double(), r.get_double(), r.get_double()); // random point P.at(i) = Point(r.get_double(), r.get_double(), r.get_double()); // random point
} }
} }
Min_sphere ms(P, P+n); // smallest enclosing sphere Min_sphere ms(P.begin(), P.end()); // smallest enclosing sphere
Min_sphere::Cartesian_const_iterator ccib = ms.center_cartesian_begin(), ccie = ms.center_cartesian_end(); Min_sphere::Cartesian_const_iterator ccib = ms.center_cartesian_begin(), ccie = ms.center_cartesian_end();
std::cout << "center:"; std::cout << "center:";

View File

@ -16,14 +16,14 @@ int
main () main ()
{ {
const int n = 10; // number of points const int n = 10; // number of points
Point P[n]; // n points std::array<Point, n> P; // n points
CGAL::Random r; // random number generator CGAL::Random r; // random number generator
for (int i=0; i<n; ++i) { for (int i=0; i<n; ++i) {
P[i] = Point(r.get_int(0, 1000),r.get_int(0, 1000), r.get_int(0, 1000), 1 ); P.at(i) = Point(r.get_int(0, 1000),r.get_int(0, 1000), r.get_int(0, 1000), 1 );
} }
Min_sphere ms (P, P+n); // smallest enclosing sphere Min_sphere ms (P.begin(), P.end()); // smallest enclosing sphere
CGAL::IO::set_pretty_mode (std::cout); CGAL::IO::set_pretty_mode (std::cout);
std::cout << ms; // output the sphere std::cout << ms; // output the sphere