mirror of https://github.com/CGAL/cgal
Update ToS2 examples
This commit is contained in:
parent
618b83b00a
commit
57148ce564
|
|
@ -1,6 +1,3 @@
|
|||
# Created by the script cgal_create_cmake_script
|
||||
# This is the CMake script for compiling a CGAL application.
|
||||
|
||||
cmake_minimum_required(VERSION 3.1...3.15)
|
||||
|
||||
project( Triangulation_on_sphere_2_Examples )
|
||||
|
|
@ -10,9 +7,10 @@ find_package(CGAL REQUIRED COMPONENTS Core)
|
|||
if ( CGAL_FOUND )
|
||||
|
||||
create_single_source_cgal_program( "triang_on_sphere.cpp" )
|
||||
create_single_source_cgal_program( "triang_on_sphere_range.cpp" )
|
||||
create_single_source_cgal_program( "triang_on_sphere_dual.cpp" )
|
||||
create_single_source_cgal_program( "triang_on_sphere_exact.cpp" )
|
||||
create_single_source_cgal_program( "triang_on_sphere_proj.cpp" )
|
||||
create_single_source_cgal_program( "triang_on_sphere_range.cpp" )
|
||||
create_single_source_cgal_program( "triang_on_sphere_geo.cpp" )
|
||||
|
||||
else()
|
||||
|
|
|
|||
|
|
@ -1,43 +1,44 @@
|
|||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
|
||||
#include <CGAL/Delaunay_triangulation_on_sphere_2.h>
|
||||
#include <CGAL/Delaunay_triangulation_on_sphere_traits_2.h>
|
||||
#include <CGAL/Delaunay_triangulation_on_sphere_2.h>
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
|
||||
|
||||
typedef CGAL::Delaunay_triangulation_on_sphere_traits_2<K> Traits;
|
||||
typedef CGAL::Delaunay_triangulation_on_sphere_2<Traits> DToS2;
|
||||
|
||||
typedef Traits::Point_3 Point;
|
||||
typedef Traits::Point_3 Point_3;
|
||||
|
||||
int main()
|
||||
int main(int, char**)
|
||||
{
|
||||
std::vector<Point> points;
|
||||
std::vector<Point_3> points;
|
||||
points.emplace_back( 2, 1, 1);
|
||||
points.emplace_back(-2, 1, 1); // not on the sphere
|
||||
points.emplace_back( 0, 1, 1);
|
||||
points.emplace_back( 1, 2, 1);
|
||||
points.emplace_back( 0, 1, 1); // duplicate
|
||||
points.emplace_back( 0, 1, 1); // duplicate of #3
|
||||
points.emplace_back( 1, 0, 1);
|
||||
points.emplace_back( 1, 1, 2);
|
||||
|
||||
Traits traits(Point(1, 1, 1));
|
||||
Traits traits(Point_3(1, 1, 1), 1); // sphere center on (1,1,1), with radius 1
|
||||
DToS2 dtos(traits);
|
||||
|
||||
for(const Point& pt : points)
|
||||
for(const Point_3& pt : points)
|
||||
{
|
||||
std::cout << "Inserting: " << pt
|
||||
<< " at distance: " << CGAL::squared_distance(pt, traits.center())
|
||||
<< " from center, is on sphere? " << traits.is_on_sphere(pt) << std::endl;
|
||||
std::cout << "Inserting (" << pt
|
||||
<< ") at squared distance " << CGAL::squared_distance(pt, traits.center())
|
||||
<< " from the center of the sphere; is it on there sphere? "
|
||||
<< (traits.is_on_sphere(pt) ? "yes" : "no") << std::endl;
|
||||
dtos.insert(pt);
|
||||
|
||||
std::cout << "dimension: " << dtos.dimension() << std::endl;
|
||||
std::cout << dtos.number_of_vertices() << " nv" << std::endl;
|
||||
std::cout << dtos.number_of_faces() << " nf" << std::endl;
|
||||
std::cout << dtos.number_of_ghost_faces() << " gf" << std::endl;
|
||||
std::cout << "After insertion, the dimension of the triangulation is: " << dtos.dimension() << "\n";
|
||||
std::cout << "It has:\n";
|
||||
std::cout << dtos.number_of_vertices() << " vertices\n";
|
||||
std::cout << dtos.number_of_edges() << " edges\n";
|
||||
std::cout << dtos.number_of_faces() << " solid faces\n";
|
||||
std::cout << dtos.number_of_ghost_faces() << " ghost faces\n" << std::endl;
|
||||
}
|
||||
|
||||
std::ofstream out("result.off");
|
||||
out.precision(17);
|
||||
CGAL::write_OFF(out, dtos);
|
||||
CGAL::write_OFF("result.off", dtos, CGAL::parameters::stream_precision(17));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,51 +7,62 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
typedef CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt K;
|
||||
template <typename Kernel>
|
||||
void create_triangulation(const char* filename)
|
||||
{
|
||||
typedef typename Kernel::FT FT;
|
||||
|
||||
// The kernel below cannot represent perfectly all points of the sphere
|
||||
// and thus a separation mecanism is needed to ensure that no points are hidden
|
||||
typedef CGAL::Projection_on_sphere_traits_3<Kernel> Traits;
|
||||
typedef CGAL::Delaunay_triangulation_on_sphere_2<Traits> DToS2;
|
||||
|
||||
// typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
|
||||
typedef typename Traits::Point_3 Point_3;
|
||||
|
||||
typedef K::FT FT;
|
||||
typedef K::Point_3 Point;
|
||||
std::cout << "\n-- Constructing triangulation with Kernel: " << typeid(Kernel).name() << " --" << std::endl;
|
||||
|
||||
typedef CGAL::Projection_on_sphere_traits_3<K> Traits;
|
||||
typedef CGAL::Delaunay_triangulation_on_sphere_2<Traits> DToS2;
|
||||
std::vector<Point_3> points;
|
||||
double x, y, z;
|
||||
|
||||
std::ifstream in(filename);
|
||||
if(!in)
|
||||
{
|
||||
std::cerr << "Invalid input file: " << filename << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
while(in >> x >> y >> z)
|
||||
points.emplace_back(x, y, z);
|
||||
|
||||
// Add an extra point that would be too close to 'p' with a basic kernel such as CGAL::EPICK,
|
||||
const Point_3& p = points.back();
|
||||
const FT tiny = 100 * std::numeric_limits<double>::epsilon();
|
||||
points.emplace_back(p.x() + tiny, p.y() - tiny, p.z() + tiny);
|
||||
|
||||
std::cout << "Adding point " << points.back() << "\nvery close to " << p << std::endl;
|
||||
std::cout << "Squared distance between points " << CGAL::squared_distance(points.back(), p) << std::endl;
|
||||
std::cout << points.size() << " points in input" << std::endl;
|
||||
|
||||
Traits traits(Point_3(0, 0, 0), 100);
|
||||
DToS2 dtos(points.begin(), points.end(), traits);
|
||||
|
||||
std::cout << dtos.number_of_vertices() << " vertices" << std::endl;
|
||||
std::cout << dtos.number_of_faces() << " faces" << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::cout.precision(17);
|
||||
|
||||
const char* filename = (argc > 1) ? argv[1] : "data/poste_france.data";
|
||||
// This kernel CAN represent exactly all points of the sphere
|
||||
typedef CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt EPECK_w_SQRT;
|
||||
|
||||
int n;
|
||||
std::vector<Point> points;
|
||||
double x, y, z;
|
||||
// This kernel CANNOT represent exactly all points of the sphere
|
||||
// and thus a separation mecanism is needed to ensure that no points are hidden
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel EPICK;
|
||||
|
||||
std::ifstream in(filename);
|
||||
in >> n;
|
||||
while(in >> x >> y >> z)
|
||||
points.emplace_back(x, y, z);
|
||||
const char* filename = (argc > 1) ? argv[1] : "data/poste_france.xyz";
|
||||
|
||||
// Add an extra point that would be too close to 'p' with a basic kernel such as CGAL::EPICK,
|
||||
const Point& p = points.back();
|
||||
const FT tiny = std::numeric_limits<double>::min();
|
||||
Point p_bis(p.x() + tiny, p.y() - tiny, p.z() + tiny);
|
||||
create_triangulation<EPICK>(filename);
|
||||
create_triangulation<EPECK_w_SQRT>(filename);
|
||||
|
||||
points.push_back(p_bis);
|
||||
|
||||
std::cout << points.size() << " points in input" << std::endl;
|
||||
|
||||
Traits traits(Point(0, 0, 0), 100);
|
||||
DToS2 dtos(points.begin(), points.end(), traits);
|
||||
|
||||
std::cout << dtos.number_of_vertices() << " nv" << std::endl;
|
||||
std::cout << dtos.number_of_faces() << " nf" << std::endl;
|
||||
std::cout << dtos.number_of_ghost_faces() << " gf" << std::endl;
|
||||
|
||||
std::ofstream out("result.off");
|
||||
out.precision(17);
|
||||
CGAL::write_OFF(out, dtos);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
|
||||
#include <CGAL/Delaunay_triangulation_on_sphere_2.h>
|
||||
#include <CGAL/Geographical_coordinates_traits_2.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
|
||||
|
||||
typedef CGAL::Geographical_coordinates_traits_2<K> Traits;
|
||||
typedef CGAL::Delaunay_triangulation_on_sphere_2<Traits> DToS2;
|
||||
|
||||
typedef Traits::Point_3 Point_3;
|
||||
typedef Traits::Point_on_sphere_2 Point;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::cout.precision(17);
|
||||
|
||||
const char* filename = (argc > 1) ? argv[1] : "data/poste_france.xyz";
|
||||
|
||||
Traits traits(Point_3(0, 0, 0), 100);
|
||||
|
||||
|
||||
std::ifstream in(filename);
|
||||
if(!in)
|
||||
{
|
||||
std::cerr << "Invalid input file: " << filename << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
typename Traits::Construct_point_on_sphere_2 cps2 = traits.construct_point_on_sphere_2_object();
|
||||
|
||||
std::vector<Point> points;
|
||||
double x, y, z;
|
||||
|
||||
while(in >> x >> y >> z)
|
||||
{
|
||||
Point_3 cp(x, y, z);
|
||||
Point ps = cps2(cp);
|
||||
std::cout << "Cartesian point: " << cp << " Coordinates on the sphere: " << ps << std::endl;
|
||||
points.push_back(ps);
|
||||
}
|
||||
|
||||
std::cout << points.size() << " points in input" << std::endl;
|
||||
|
||||
DToS2 dtos(points.begin(), points.end(), traits);
|
||||
|
||||
std::cout << dtos.number_of_vertices() << " vertices" << std::endl;
|
||||
std::cout << dtos.number_of_faces() << " solid faces" << std::endl;
|
||||
std::cout << dtos.number_of_ghost_faces() << " ghost faces" << std::endl;
|
||||
|
||||
CGAL::write_OFF("result.off", dtos, CGAL::parameters::stream_precision(17));
|
||||
}
|
||||
|
|
@ -5,36 +5,40 @@
|
|||
|
||||
#include <boost/iterator/transform_iterator.hpp>
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
|
||||
|
||||
typedef CGAL::Projection_on_sphere_traits_3<K> Projection_traits;
|
||||
typedef CGAL::Delaunay_triangulation_on_sphere_2<Projection_traits> Projected_DToS2;
|
||||
typedef CGAL::Projection_on_sphere_traits_3<K> Traits;
|
||||
typedef CGAL::Delaunay_triangulation_on_sphere_2<Traits> DToS2;
|
||||
|
||||
int main()
|
||||
typedef Traits::Point_3 Point_3;
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
std::vector<K::Point_3> points;
|
||||
points.push_back(K::Point_3( 3, 1, 1));
|
||||
points.push_back(K::Point_3(-8, 1, 1));
|
||||
points.push_back(K::Point_3( 1, 2, 1));
|
||||
points.push_back(K::Point_3( 1, -2, 1));
|
||||
points.push_back(K::Point_3( 1, 1, 10));
|
||||
std::vector<Point_3> points;
|
||||
points.emplace_back( 3, 1, 1);
|
||||
points.emplace_back(-8, 1, 1);
|
||||
points.emplace_back( 1, 2, 1);
|
||||
points.emplace_back( 1, -2, 1);
|
||||
points.emplace_back( 1, 1, 10);
|
||||
|
||||
Projection_traits traits(K::Point_3(1,1,1));
|
||||
Projected_DToS2 dtos(traits);
|
||||
Traits traits(Point_3(1,1,1)); // radius is 1 by default
|
||||
DToS2 dtos(traits);
|
||||
|
||||
Projection_traits::Construct_point_on_sphere_2 cst =
|
||||
traits.construct_point_on_sphere_2_object();
|
||||
Traits::Construct_point_on_sphere_2 cst = traits.construct_point_on_sphere_2_object();
|
||||
|
||||
for(const auto& pt : points)
|
||||
{
|
||||
std::cout << "----- Inserting: " << pt
|
||||
<< " at distance: " << CGAL::squared_distance(pt, traits.center())
|
||||
<< " from center" << std::endl;
|
||||
std::cout << "----- Inserting (" << pt
|
||||
<< ") at squared distance " << CGAL::squared_distance(pt, traits.center())
|
||||
<< " from the center of the sphere" << std::endl;
|
||||
dtos.insert(cst(pt));
|
||||
|
||||
std::cout << "dimension: " << dtos.dimension() << std::endl;
|
||||
std::cout << dtos.number_of_vertices() << " nv" << std::endl;
|
||||
std::cout << dtos.number_of_faces() << " nf" << std::endl;
|
||||
std::cout << dtos.number_of_ghost_faces() << " gf" << std::endl;
|
||||
std::cout << "The triangulation now has dimension: " << dtos.dimension() << " and\n";
|
||||
std::cout << dtos.number_of_vertices() << " vertices" << std::endl;
|
||||
std::cout << dtos.number_of_edges() << " edges" << std::endl;
|
||||
std::cout << dtos.number_of_faces() << " solid faces" << std::endl;
|
||||
std::cout << dtos.number_of_ghost_faces() << " ghost faces" << std::endl;
|
||||
}
|
||||
|
||||
CGAL::write_OFF("result.off", dtos, CGAL::parameters::stream_precision(17));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
|
|||
typedef CGAL::Projection_on_sphere_traits_3<K> Traits;
|
||||
typedef CGAL::Delaunay_triangulation_on_sphere_2<Traits> DToS2;
|
||||
|
||||
typedef Traits::Point_3 Point;
|
||||
typedef DToS2::Point_3 Point;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
|
@ -19,12 +19,16 @@ int main(int argc, char** argv)
|
|||
|
||||
const char* filename = (argc > 1) ? argv[1] : "data/radar.xyz";
|
||||
|
||||
int n;
|
||||
std::vector<Point> points;
|
||||
double x, y, z;
|
||||
|
||||
std::ifstream in(filename);
|
||||
in >> n;
|
||||
if(!in)
|
||||
{
|
||||
std::cerr << "Invalid input file: " << filename << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
while(in >> x >> y >> z)
|
||||
points.emplace_back(x, y, z);
|
||||
|
||||
|
|
@ -33,11 +37,8 @@ int main(int argc, char** argv)
|
|||
Traits traits(Point(0, 0, 0), 100);
|
||||
DToS2 dtos(points.begin(), points.end(), traits);
|
||||
|
||||
std::cout << dtos.number_of_vertices() << " nv" << std::endl;
|
||||
std::cout << dtos.number_of_faces() << " nf" << std::endl;
|
||||
std::cout << dtos.number_of_ghost_faces() << " gf" << std::endl;
|
||||
std::cout << dtos.number_of_vertices() << " vertices" << std::endl;
|
||||
std::cout << dtos.number_of_faces() << " solid faces" << std::endl;
|
||||
|
||||
std::ofstream out("result.off");
|
||||
out.precision(17);
|
||||
CGAL::write_OFF(out, dtos);
|
||||
CGAL::write_OFF("result.off", dtos, CGAL::parameters::stream_precision(17));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue