From f6cd69aa7b315b10302b6e042450e86aaaf9e870 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 19 Dec 2011 06:38:04 +0000 Subject: [PATCH] Add an example to build voronoi_2. --- .gitattributes | 1 + .../Linear_cell_complex/CMakeLists.txt | 6 + .../Linear_cell_complex/voronoi_2.cpp | 114 ++++++++++++++++++ .../CGAL/Linear_cell_complex_constructors.h | 101 ++++++++++++++++ 4 files changed, 222 insertions(+) create mode 100644 Linear_cell_complex/examples/Linear_cell_complex/voronoi_2.cpp diff --git a/.gitattributes b/.gitattributes index 89984985f1e..5dd79c5cd02 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2036,6 +2036,7 @@ Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_viewer_vt Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_with_colored_vertices.cpp -text Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_4.cpp -text Linear_cell_complex/examples/Linear_cell_complex/plane_graph_to_lcc_2.cpp -text +Linear_cell_complex/examples/Linear_cell_complex/voronoi_2.cpp -text Linear_cell_complex/examples/Linear_cell_complex/voronoi_3.cpp -text Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h -text Linear_cell_complex/include/CGAL/Linear_cell_complex.h -text diff --git a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt index 03076670ce8..931b3b1ad54 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt @@ -45,6 +45,12 @@ if ( CGAL_FOUND ) #include("CMakeLCCViewerQt.inc") #include("CMakeLCCViewerVtk.inc") + add_executable(voronoi_2 voronoi_2.cpp) + target_link_libraries(voronoi_2 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES}) +# And if you use a viewer, you have to link with the corresponding lib. + target_link_libraries(voronoi_2 ${MAP_VIEWER_LIBRARIES_QT}) + #target_link_libraries(voronoi_3 ${MAP_VIEWER_LIBRARIES_VTK}) + add_executable(voronoi_3 voronoi_3.cpp) target_link_libraries(voronoi_3 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES}) # And if you use a viewer, you have to link with the corresponding lib. diff --git a/Linear_cell_complex/examples/Linear_cell_complex/voronoi_2.cpp b/Linear_cell_complex/examples/Linear_cell_complex/voronoi_2.cpp new file mode 100644 index 00000000000..8e27bc00b3e --- /dev/null +++ b/Linear_cell_complex/examples/Linear_cell_complex/voronoi_2.cpp @@ -0,0 +1,114 @@ +#include +#include +#include +#include +#include +#include + +/* If you want to use a viewer, you can use one of the following file + * depending if you use vtk or qglviewer. */ +#ifdef CGAL_LCC_USE_QT +//#include "linear_cell_complex_3_viewer_qt.h" +#endif + +typedef CGAL::Linear_cell_complex<2> LCC_2; +typedef LCC_2::Dart_handle Dart_handle; +typedef LCC_2::Point Point; + +typedef CGAL::Delaunay_triangulation_2 Triangulation; + +// Function used to display the voronoi diagram. +void display_voronoi(LCC_2& alcc, Dart_handle adart) +{ + // We remove all the faces containing one dart of the infinite faces + std::stack toremove; + int mark_toremove=alcc.get_new_mark(); + + // We cannot view the infinite face since it does not have + // a correct geometry. For that we have to remove the infinite face. + toremove.push(adart); + CGAL::mark_cell(alcc, adart, mark_toremove); + + // Plus all the faces sharing an edge with it. + for (LCC_2::Dart_of_cell_range<2>::iterator + it=alcc.darts_of_cell<2>(adart).begin(), + itend=alcc.darts_of_cell<2>(adart).end(); it!=itend; ++it) + { + if ( !alcc.is_marked(it->beta(2), mark_toremove) ) + { + CGAL::mark_cell(alcc, it->beta(2), mark_toremove); + toremove.push(it->beta(2)); + } + } + + while( !toremove.empty() ) + { + CGAL::remove_cell(alcc, toremove.top()); + toremove.pop(); + } + +#ifdef CGAL_LCC_USE_VIEWER + // display_lcc(alcc); +#endif // CGAL_LCC_USE_VIEWER +} + +int main(int narg, char** argv) +{ + if (narg>1 && (!strcmp(argv[1],"-h") || !strcmp(argv[1],"-?")) ) + { + std::cout<<"Usage : voronoi_2 filename"< begin(iFile), end; + T.insert(begin, end); + assert(T.is_valid(false)); + + // 2) Convert the triangulation into a 2D lcc. + LCC_2 lcc; + Dart_handle dh= + CGAL::import_from_triangulation_2(lcc, T); + + std::cout<<"Delaunay triangulation :"<