From 7bbbf35d1b73b9ca220a72c4bac5a25ab1e4f010 Mon Sep 17 00:00:00 2001 From: Sylvain Pion Date: Fri, 30 May 2003 09:20:20 +0000 Subject: [PATCH] - Add new example program : example_find_conflicts.C --- .../examples/Triangulation_3/README | 17 ++++-- .../Triangulation_3/example_find_conflicts.C | 61 +++++++++++++++++++ 2 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 Packages/Triangulation_3/examples/Triangulation_3/example_find_conflicts.C diff --git a/Packages/Triangulation_3/examples/Triangulation_3/README b/Packages/Triangulation_3/examples/Triangulation_3/README index 5a6ee2d4f94..c05beb866c0 100644 --- a/Packages/Triangulation_3/examples/Triangulation_3/README +++ b/Packages/Triangulation_3/examples/Triangulation_3/README @@ -1,5 +1,5 @@ -------- example_simple ------------------------------------------------- +------- example_simple --------------------------------------- This example shows the incremental construction of a 3D triangulation, the location of a point, and how to manipulate elementary operations @@ -8,23 +8,32 @@ CGAL for the Triangulation_3 class. -------------------------------------------------------------- -------- example_color ------------------------------------------------- +------- example_color ---------------------------------------- This example shows how the user can plug his own vertex base in a triangulation. -------------------------------------------------------------- -------- example_hierarchy ------------------------------------------------- +------- example_hierarchy ------------------------------------ This example shows the use of the hierarchy to speed up the construction of a Delaunay triangulation. -------------------------------------------------------------- -------- example_tds ------------------------------------------------- +------- example_tds ------------------------------------------ Shows how to construct a 3D triangulation data structure by inserting vertices. -------------------------------------------------------------- + +------- example_find_conflicts ------------------------------- + +Illustrates how the insertion process of points in a Delaunay +triangulation can be decomposed in order to give access to the +cells in conflict (those which would be destroyed by the insertion +of a point) prior to deciding to do the actual insertion or not. + +-------------------------------------------------------------- diff --git a/Packages/Triangulation_3/examples/Triangulation_3/example_find_conflicts.C b/Packages/Triangulation_3/examples/Triangulation_3/example_find_conflicts.C new file mode 100644 index 00000000000..61e847273ca --- /dev/null +++ b/Packages/Triangulation_3/examples/Triangulation_3/example_find_conflicts.C @@ -0,0 +1,61 @@ +// Triangulation_3/example_find_conflicts.C +#include +#include +#include +#include + +#include +#include + +struct K : CGAL::Filtered_kernel > {}; + +typedef CGAL::Delaunay_triangulation_3 Delaunay; +typedef Delaunay::Point Point; +typedef Delaunay::Cell_handle Cell_handle; +typedef Delaunay::Facet Facet; + +int main() +{ + Delaunay T; + CGAL::Random_points_in_sphere_3 rnd; + + // First, make sure the triangulation is 3D. + T.insert(Point(0,0,0)); + T.insert(Point(1,0,0)); + T.insert(Point(0,1,0)); + T.insert(Point(0,0,1)); + + assert(T.dimension() == 3); + + // Inserts 100 random points if and only if their insertion + // in the Delaunay tetrahedralization would conflict with + // an even number of cells. + for (int i = 0; i != 100; ++i) { + Point p = *rnd++; + + // Locate the point + Delaunay::Locate_type lt; + int li, lj; + Cell_handle c = T.locate(p, lt, li, lj); + if (lt == Delaunay::VERTEX) + continue; // Point already exists + + // Get the cells that conflict with p in a vector V, + // and a facet on the boundary of this hole in f. + std::vector V; + Facet f; + + T.find_conflicts(p, c, + CGAL::Oneset_iterator(f), // Get one boundary facet + std::back_inserter(V), // Conflict cells in V + CGAL::Emptyset_iterator()); // Drop internal facets + + if ((V.size() & 1) == 0) // Even number of conflict cells ? + T.insert_in_hole(p, V.begin(), V.end(), f.first, f.second); + } + + std::cout << "Final triangulation has " << T.number_of_vertices() + << " vertices." << std::endl; + + return 0; +}