Cleaned up; replaced 'typedef' with 'using'; replaced CGAL::Timer with std::chrono

This commit is contained in:
Efi Fogel 2024-01-29 19:32:02 +02:00
parent 0bf75c9062
commit 1c7cdad3f0
3 changed files with 97 additions and 155 deletions

View File

@ -1,81 +1,63 @@
//! \file examples/Envelope_3/ex_envelope_planes.cpp //! \file examples/Envelope_3/ex_envelope_planes.cpp
// Constructing the lower and the upper envelope of a set of planes. // Constructing the lower and the upper envelope of a set of planes.
#include <iostream>
#include <list>
#include <CGAL/Exact_rational.h> #include <CGAL/Exact_rational.h>
#include <CGAL/Cartesian.h> #include <CGAL/Cartesian.h>
#include <CGAL/Env_plane_traits_3.h> #include <CGAL/Env_plane_traits_3.h>
#include <CGAL/envelope_3.h> #include <CGAL/envelope_3.h>
#include <iostream>
#include <list>
typedef CGAL::Exact_rational Number_type;
typedef CGAL::Cartesian<Number_type> Kernel;
typedef Kernel::Plane_3 Plane_3;
typedef CGAL::Env_plane_traits_3<Kernel> Traits_3;
typedef Traits_3::Surface_3 Surface_3;
typedef CGAL::Envelope_diagram_2<Traits_3> Envelope_diagram_2;
using Number_type = CGAL::Exact_rational;
using Kernel = CGAL::Cartesian<Number_type>;
using Plane_3 = Kernel::Plane_3;
using Traits_3 = CGAL::Env_plane_traits_3<Kernel>;
using Surface_3 = Traits_3::Surface_3;
using Envelope_diagram_2 = CGAL::Envelope_diagram_2<Traits_3>;
/* Auxiliary function - print the features of the given envelope diagram. */ /* Auxiliary function - print the features of the given envelope diagram. */
void print_diagram (const Envelope_diagram_2& diag) void print_diagram(const Envelope_diagram_2& diag) {
{
// Go over all arrangement faces. // Go over all arrangement faces.
Envelope_diagram_2::Face_const_iterator fit; for (auto fit = diag.faces_begin(); fit != diag.faces_end(); ++fit) {
Envelope_diagram_2::Ccb_halfedge_const_circulator ccb;
Envelope_diagram_2::Surface_const_iterator sit;
for (fit = diag.faces_begin(); fit != diag.faces_end(); ++fit)
{
// Print the face boundary. // Print the face boundary.
// Print the vertices along the outer boundary of the face. // Print the vertices along the outer boundary of the face.
ccb = fit->outer_ccb(); auto ccb = fit->outer_ccb();
std::cout << "[Face] "; std::cout << "[Face] ";
do do if (!ccb->is_fictitious()) std::cout << '(' << ccb->curve() << ") ";
{ while (++ccb != fit->outer_ccb());
if(!ccb->is_fictitious())
std::cout << '(' << ccb->curve() << ") ";
++ccb;
} while (ccb != fit->outer_ccb());
// Print the planes that induce the envelope on this face. // Print the planes that induce the envelope on this face.
std::cout << "--> " << fit->number_of_surfaces() std::cout << "--> " << fit->number_of_surfaces() << " planes:";
<< " planes:";
for (sit = fit->surfaces_begin(); sit != fit->surfaces_end(); ++sit) for (auto sit = fit->surfaces_begin(); sit != fit->surfaces_end(); ++sit)
std::cout << ' ' << sit->plane(); std::cout << ' ' << sit->plane();
std::cout << std::endl; std::cout << std::endl;
} }
return;
} }
/* The main program: */ /* The main program: */
int main () int main() {
{
// Construct the input planes. // Construct the input planes.
std::list<Surface_3> planes; std::list<Surface_3> planes;
planes.push_back (Surface_3(Plane_3(0, -1, 1, 0))); planes.push_back(Surface_3(Plane_3(0, -1, 1, 0)));
planes.push_back (Surface_3(Plane_3(-1, 0, 1, 0))); planes.push_back(Surface_3(Plane_3(-1, 0, 1, 0)));
planes.push_back (Surface_3(Plane_3(0, 1 , 1, 0))); planes.push_back(Surface_3(Plane_3(0, 1 , 1, 0)));
planes.push_back (Surface_3(Plane_3(1, 0, 1, 0))); planes.push_back(Surface_3(Plane_3(1, 0, 1, 0)));
// Compute and print the minimization diagram. // Compute and print the minimization diagram.
Envelope_diagram_2 min_diag; Envelope_diagram_2 min_diag;
CGAL::lower_envelope_3(planes.begin(), planes.end(), min_diag);
CGAL::lower_envelope_3 (planes.begin(), planes.end(), min_diag);
std::cout << std::endl << "The minimization diagram:" << std::endl; std::cout << std::endl << "The minimization diagram:" << std::endl;
print_diagram (min_diag); print_diagram(min_diag);
// Compute and print the maximization diagram. // Compute and print the maximization diagram.
Envelope_diagram_2 max_diag; Envelope_diagram_2 max_diag;
CGAL::upper_envelope_3(planes.begin(), planes.end(), max_diag);
CGAL::upper_envelope_3 (planes.begin(), planes.end(), max_diag);
std::cout << std::endl << "The maximization diagram:" << std::endl; std::cout << std::endl << "The maximization diagram:" << std::endl;
print_diagram (max_diag); print_diagram (max_diag);
return (0); return 0;
} }

View File

@ -5,47 +5,44 @@
#ifndef CGAL_USE_CORE #ifndef CGAL_USE_CORE
#include <iostream> #include <iostream>
int main() int main() {
{
std::cout << "Sorry, this example needs CORE ..." << std::endl; std::cout << "Sorry, this example needs CORE ..." << std::endl;
return 0; return 0;
} }
#else #else
#include <iostream>
#include <list>
#include <chrono>
#include <CGAL/Cartesian.h> #include <CGAL/Cartesian.h>
#include <CGAL/CORE_algebraic_number_traits.h> #include <CGAL/CORE_algebraic_number_traits.h>
#include <CGAL/Arr_conic_traits_2.h> #include <CGAL/Arr_conic_traits_2.h>
#include <CGAL/Env_sphere_traits_3.h> #include <CGAL/Env_sphere_traits_3.h>
#include <CGAL/envelope_3.h> #include <CGAL/envelope_3.h>
#include <CGAL/Timer.h>
#include <iostream>
#include <list>
typedef CGAL::CORE_algebraic_number_traits Nt_traits; using Nt_traits = CGAL::CORE_algebraic_number_traits;
typedef Nt_traits::Rational Rational; using Rational = Nt_traits::Rational;
typedef Nt_traits::Algebraic Algebraic; using Algebraic = Nt_traits::Algebraic;
typedef CGAL::Cartesian<Rational> Rat_kernel; using Rat_kernel = CGAL::Cartesian<Rational>;
typedef Rat_kernel::Point_3 Rat_point_3; using Rat_point_3 = Rat_kernel::Point_3;
typedef CGAL::Cartesian<Algebraic> Alg_kernel; using Alg_kernel = CGAL::Cartesian<Algebraic>;
typedef CGAL::Arr_conic_traits_2<Rat_kernel, Alg_kernel, Nt_traits> using Conic_traits_2 =
Conic_traits_2; CGAL::Arr_conic_traits_2<Rat_kernel, Alg_kernel, Nt_traits>;
typedef CGAL::Env_sphere_traits_3<Conic_traits_2> Traits_3; using Traits_3 = CGAL::Env_sphere_traits_3<Conic_traits_2>;
typedef Traits_3::Surface_3 Sphere_3; using Sphere_3 = Traits_3::Surface_3;
typedef CGAL::Envelope_diagram_2<Traits_3> Envelope_diagram_2; using Envelope_diagram_2 = CGAL::Envelope_diagram_2<Traits_3>;
int main(int argc, char **argv) int main(int argc, char* argv[]) {
{
// Get the name of the input file from the command line, or use the default // Get the name of the input file from the command line, or use the default
// fan_grids.dat file if no command-line parameters are given. // fan_grids.dat file if no command-line parameters are given.
const char * filename = (argc > 1) ? argv[1] : "spheres.dat"; const char* filename = (argc > 1) ? argv[1] : "spheres.dat";
// Open the input file. // Open the input file.
std::ifstream in_file(filename); std::ifstream in_file(filename);
if (! in_file.is_open()) {
if (! in_file.is_open())
{
std::cerr << "Failed to open " << filename << " ..." << std::endl; std::cerr << "Failed to open " << filename << " ..." << std::endl;
return 1; return 1;
} }
@ -57,37 +54,28 @@ int main(int argc, char **argv)
// <x_2> <y_2> <x_2> <R_2> // center and squared radious of sphere #2. // <x_2> <y_2> <x_2> <R_2> // center and squared radious of sphere #2.
// : : : : // : : : :
// <x_n> <y_n> <x_n> <R_n> // center and squared radious of sphere #n. // <x_n> <y_n> <x_n> <R_n> // center and squared radious of sphere #n.
int n = 0; int n = 0;
std::list<Sphere_3> spheres; std::list<Sphere_3> spheres;
int x = 0, y = 0, z = 0, sqr_r = 0; int x = 0, y = 0, z = 0, sqr_r = 0;
int i;
in_file >> n; in_file >> n;
for (i = 0; i < n; ++i) for (int i = 0; i < n; ++i) {
{
in_file >> x >> y >> z >> sqr_r; in_file >> x >> y >> z >> sqr_r;
spheres.push_back(Sphere_3(Rat_point_3(x, y, z), Rational(sqr_r))); spheres.push_back(Sphere_3(Rat_point_3(x, y, z), Rational(sqr_r)));
} }
in_file.close(); in_file.close();
std::cout << "Constructing the lower envelope of " << n << " spheres.\n";
// Compute the lower envelope. // Compute the lower envelope.
Envelope_diagram_2 min_diag; Envelope_diagram_2 min_diag;
CGAL::Timer timer; auto start = std::chrono::system_clock::now();
std::cout << "Constructing the lower envelope of "
<< n << " spheres." << std::endl;
timer.start();
CGAL::lower_envelope_3(spheres.begin(), spheres.end(), min_diag); CGAL::lower_envelope_3(spheres.begin(), spheres.end(), min_diag);
timer.stop(); std::chrono::duration<double> secs = std::chrono::system_clock::now() - start;
// Print the dimensions of the minimization diagram. // Print the dimensions of the minimization diagram.
std::cout << "V = " << min_diag.number_of_vertices() std::cout << "V = " << min_diag.number_of_vertices()
<< ", E = " << min_diag.number_of_edges() << ", E = " << min_diag.number_of_edges()
<< ", F = " << min_diag.number_of_faces() << std::endl; << ", F = " << min_diag.number_of_faces() << std::endl;
std::cout << "Construction took " << secs.count() << " seconds.\n";
std::cout << "Construction took " << timer.time()
<< " seconds." << std::endl;
return 0; return 0;
} }

View File

@ -1,110 +1,82 @@
//! \file examples/Envelope_3/ex_envelope_triangles.cpp //! \file examples/Envelope_3/ex_envelope_triangles.cpp
// Constructing the lower and the upper envelope of a set of triangles. // Constructing the lower and the upper envelope of a set of triangles.
#include <iostream>
#include <list>
#include <CGAL/Exact_rational.h> #include <CGAL/Exact_rational.h>
#include <CGAL/Cartesian.h> #include <CGAL/Cartesian.h>
#include <CGAL/Env_triangle_traits_3.h> #include <CGAL/Env_triangle_traits_3.h>
#include <CGAL/Env_surface_data_traits_3.h> #include <CGAL/Env_surface_data_traits_3.h>
#include <CGAL/envelope_3.h> #include <CGAL/envelope_3.h>
#include <iostream>
#include <list>
typedef CGAL::Exact_rational Number_type; using Number_type = CGAL::Exact_rational;
typedef CGAL::Cartesian<Number_type> Kernel; using Kernel = CGAL::Cartesian<Number_type>;
typedef CGAL::Env_triangle_traits_3<Kernel> Traits_3; using Traits_3 = CGAL::Env_triangle_traits_3<Kernel>;
typedef Kernel::Point_3 Point_3; using Point_3 = Kernel::Point_3;
typedef Traits_3::Surface_3 Triangle_3; using Triangle_3 = Traits_3::Surface_3;
typedef CGAL::Env_surface_data_traits_3<Traits_3, char> Data_traits_3; using Data_traits_3 = CGAL::Env_surface_data_traits_3<Traits_3, char>;
typedef Data_traits_3::Surface_3 Data_triangle_3; using Data_triangle_3 = Data_traits_3::Surface_3;
typedef CGAL::Envelope_diagram_2<Data_traits_3> Envelope_diagram_2; using Envelope_diagram_2 = CGAL::Envelope_diagram_2<Data_traits_3>;
/* Auxiliary function - print the features of the given envelope diagram. */ /* Auxiliary function - print the features of the given envelope diagram. */
void print_diagram (const Envelope_diagram_2& diag) void print_diagram(const Envelope_diagram_2& diag) {
{
// Go over all arrangement faces. // Go over all arrangement faces.
Envelope_diagram_2::Face_const_iterator fit; for (auto fit = diag.faces_begin(); fit != diag.faces_end(); ++fit) {
Envelope_diagram_2::Ccb_halfedge_const_circulator ccb;
Envelope_diagram_2::Surface_const_iterator sit;
for (fit = diag.faces_begin(); fit != diag.faces_end(); ++fit)
{
// Print the face boundary. // Print the face boundary.
if (fit->is_unbounded()) if (fit->is_unbounded()) std::cout << "[Unbounded face]";
{ else {
std::cout << "[Unbounded face]";
}
else
{
// Print the vertices along the outer boundary of the face. // Print the vertices along the outer boundary of the face.
ccb = fit->outer_ccb(); auto ccb = fit->outer_ccb();
std::cout << "[Face] "; std::cout << "[Face] ";
do do std::cout << '(' << ccb->target()->point() << ") ";
{ while (++ccb != fit->outer_ccb());
std::cout << '(' << ccb->target()->point() << ") ";
++ccb;
} while (ccb != fit->outer_ccb());
} }
// Print the labels of the triangles that induce the envelope on this face. // Print the labels of the triangles that induce the envelope on this face.
std::cout << "--> " << fit->number_of_surfaces() std::cout << "--> " << fit->number_of_surfaces() << " triangles:";
<< " triangles:";
for (sit = fit->surfaces_begin(); sit != fit->surfaces_end(); ++sit) for (auto sit = fit->surfaces_begin(); sit != fit->surfaces_end(); ++sit)
std::cout << ' ' << sit->data(); std::cout << ' ' << sit->data();
std::cout << std::endl; std::cout << std::endl;
} }
// Go over all arrangement edges. // Go over all arrangement edges.
Envelope_diagram_2::Edge_const_iterator eit; Envelope_diagram_2::Edge_const_iterator eit;
for (eit = diag.edges_begin(); eit != diag.edges_end(); ++eit) for (auto eit = diag.edges_begin(); eit != diag.edges_end(); ++eit) {
{
// Print the labels of the triangles that induce the envelope on this edge. // Print the labels of the triangles that induce the envelope on this edge.
std::cout << "[Edge] (" << eit->source()->point() std::cout << "[Edge] (" << eit->source()->point()
<< ") (" << eit->target()->point() << ") (" << eit->target()->point()
<< ") --> " << eit->number_of_surfaces() << ") --> " << eit->number_of_surfaces()
<< " triangles:"; << " triangles:";
for (sit = eit->surfaces_begin(); sit != eit->surfaces_end(); ++sit) for (auto sit = eit->surfaces_begin(); sit != eit->surfaces_end(); ++sit)
std::cout << ' ' << sit->data(); std::cout << ' ' << sit->data();
std::cout << std::endl; std::cout << std::endl;
} }
return;
} }
/* The main program: */ /* The main program: */
int main () int main() {
{
// Construct the input triangles, makred A and B. // Construct the input triangles, makred A and B.
std::list<Data_triangle_3> triangles; std::list<Data_triangle_3> triangles;
auto t1 = Triangle_3(Point_3 (0, 0, 0), Point_3 (0, 6, 0), Point_3 (5, 3, 4));
triangles.push_back (Data_triangle_3 (Triangle_3 (Point_3 (0, 0, 0), triangles.push_back(Data_triangle_3(t1, 'A'));
Point_3 (0, 6, 0), auto t2 = Triangle_3(Point_3 (6, 0, 0), Point_3 (6, 6, 0), Point_3 (1, 3, 4));
Point_3 (5, 3, 4)), triangles.push_back(Data_triangle_3(t2, 'B'));
'A'));
triangles.push_back (Data_triangle_3 (Triangle_3 (Point_3 (6, 0, 0),
Point_3 (6, 6, 0),
Point_3 (1, 3, 4)),
'B'));
// Compute and print the minimization diagram. // Compute and print the minimization diagram.
Envelope_diagram_2 min_diag; Envelope_diagram_2 min_diag;
CGAL::lower_envelope_3(triangles.begin(), triangles.end(), min_diag);
CGAL::lower_envelope_3 (triangles.begin(), triangles.end(),
min_diag);
std::cout << std::endl << "The minimization diagram:" << std::endl; std::cout << std::endl << "The minimization diagram:" << std::endl;
print_diagram (min_diag); print_diagram(min_diag);
// Compute and print the maximization diagram. // Compute and print the maximization diagram.
Envelope_diagram_2 max_diag; Envelope_diagram_2 max_diag;
CGAL::upper_envelope_3 (triangles.begin(), triangles.end(), max_diag);
CGAL::upper_envelope_3 (triangles.begin(), triangles.end(),
max_diag);
std::cout << std::endl << "The maximization diagram:" << std::endl; std::cout << std::endl << "The maximization diagram:" << std::endl;
print_diagram (max_diag); print_diagram (max_diag);
return (0); return 0;
} }