From 150c9c95de1a4a48e8f41a03e0bb5d40e39a922c Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 12 Sep 2018 12:27:31 +0200 Subject: [PATCH] Add an example with a Polyhedron_3 --- .../doc/Heat_method_3/Heat_method_3.txt | 41 +++++++++++-------- Heat_method_3/doc/Heat_method_3/dependencies | 2 +- Heat_method_3/doc/Heat_method_3/examples.txt | 1 + .../examples/Heat_method_3/CMakeLists.txt | 1 + .../examples/Heat_method_3/heat_method.cpp | 7 +++- .../Heat_method_3/heat_method_polyhedron.cpp | 40 ++++++++++++++++++ .../heat_method_surface_mesh.cpp | 4 +- .../heat_method_surface_mesh_intrinsic.cpp | 4 +- .../CGAL/Heat_method_3/Heat_method_3.h | 2 +- 9 files changed, 78 insertions(+), 24 deletions(-) create mode 100644 Heat_method_3/examples/Heat_method_3/heat_method_polyhedron.cpp diff --git a/Heat_method_3/doc/Heat_method_3/Heat_method_3.txt b/Heat_method_3/doc/Heat_method_3/Heat_method_3.txt index 610e37bb745..436fbbdec9b 100644 --- a/Heat_method_3/doc/Heat_method_3/Heat_method_3.txt +++ b/Heat_method_3/doc/Heat_method_3/Heat_method_3.txt @@ -6,6 +6,10 @@ namespace CGAL { \cgalAutoToc \author Keenan Crane, Christina Vaz, Andreas Fabri +\image html octopus.png + +\section sec_HM_introduction Introduction + The Heat Method is an algorithm that solves the multiple-source shortest path problem by returning the geodesic distance for all vertices of a triangle mesh to the closest vertex in a given set of source vertices. @@ -17,12 +21,12 @@ The method works well on triangle meshes with.... For triangle meshes that do not fulfill these requirements, applying edge flips to obtain an Intrinsic Delaunay Triangulation also gives good results. -\cgalFigureBegin{landscape_meshes, landscape_meshes.png} +\cgalFigureBegin{landscape_meshes, landscape.jpg} Isolines placed on a mesh with and without iDT remeshing. \cgalFigureEnd -In the next section we give examples. Section \ref sec_HM_definitions presents -the mathematical background. The last section is about the \ref sec_HM_history. +In the next section we give some examples. Section \ref sec_HM_definitions presents +the mathematical theory of the Heat method. The last section is about the \ref sec_HM_history. Note that this package requires the third party \ref thirdpartyEigen library. This implementation is based on \cgalCite{cgal:cww-ghnac-13} and \cgalCite{cgal:fsbs-acidt-06} @@ -37,12 +41,20 @@ for the `Heat_method_3::Intrinsic_Delaunay_triangulation_3` class. \subsection HM_example_Free_function Using a Free Function -The first example calls a free function that computes the distances to a single source vertex. +The first example calls the free function `Heat_method_3::geodesic_distances_3()` +which computes for all vertices of a triangle mesh the distances to a single source vertex. + The distances are written into an internal property map of the surface mesh. -For a `Polyhedron_3` you can use a `std::map` passed to the function `make_assoc_property_map()`, instead. \cgalExample{Heat_method_3/heat_method.cpp} +For a `Polyhedron_3` you can either add a data field to the vertex type, or, as shown +in the following exampole create a `boost::unordered_map` and pass it to the function +`boost::make_assoc_property_map()` which generates a vertex distance property map. + +\cgalExample{Heat_method_3/heat_method_polyhedron.cpp} + + \subsection HM_example_Class Using the Heat Method Class The following example shows the heat method class. It can be used @@ -55,11 +67,11 @@ the distances to these two sources. \cgalExample{Heat_method_3/heat_method_surface_mesh.cpp} -\subsection HM_example_Intrinsic Using the Intrinsic Delaunay Triangulation +\subsection HM_example_Intrinsic Using the Intrinsic Delaunay Triangulation Class The following example shows the heat method on a triangle mesh using the intrinsic Delaunay triangulation algorithm. This should be done when the -triangles are very ..................... +triangles have small angles or ..................... \cgalExample{Heat_method_3/heat_method_surface_mesh_intrinsic.cpp} @@ -67,8 +79,8 @@ triangles are very ..................... \section sec_HM_definitions Theoretical Background -Section \ref Subsection_HM_Definitions_Intro gives an overview of the theory needed by the heat method. -Section \ref Subsection_HM_IDT_Definitions gives the background needed for the Intrinsic Delaunay Triangulation. +Section \ref Subsection_HM_Definitions_Intro gives an overview of the theory needed by the Heat method. +Section \ref Subsection_HM_IDT_Definitions gives the background needed for the Intrinsic Delaunay triangulation. \subsection Subsection_HM_Definitions_Intro The Heat Method Algorithm @@ -177,14 +189,11 @@ The algorithm is as follows: The new \f$(\tilde K, \tilde L)\f$ are then used in the Heat Method distance computation. + We already in the beginning gave an example where the intrinsic Delaunay triangulation improves the results. + The mesh was obtained by giving elevation to a 2D triangulation, which lead to elongated triangles. + + The situation is similar for any triangle mesh that has faces with very small angles as can be seen in the figures below. - The following figures demonstrate the difference between the heat method with and without intrinsic Delaunay remeshing. - \cgalFigureBegin{landscape_mesh, landscape2withoutidt.png} - Isolines placed on a mesh without iDT remeshing - \cgalFigureEnd - \cgalFigureBegin{landscape_mesh_idt, landscape2withidt.png} - Isolines placed on a mesh with iDT remeshing - \cgalFigureEnd \cgalFigureBegin{circle_box, red_circle_box_without_idt_bottom.png} Isolines placed on a mesh without iDT remeshing \cgalFigureEnd diff --git a/Heat_method_3/doc/Heat_method_3/dependencies b/Heat_method_3/doc/Heat_method_3/dependencies index 2eaa352e416..a0c9b69e5de 100644 --- a/Heat_method_3/doc/Heat_method_3/dependencies +++ b/Heat_method_3/doc/Heat_method_3/dependencies @@ -7,4 +7,4 @@ Stream_support Surface_mesh Solver_interface BGL -Polyhedron_3 +Polyhedron diff --git a/Heat_method_3/doc/Heat_method_3/examples.txt b/Heat_method_3/doc/Heat_method_3/examples.txt index 2c5759ced58..089f321e369 100644 --- a/Heat_method_3/doc/Heat_method_3/examples.txt +++ b/Heat_method_3/doc/Heat_method_3/examples.txt @@ -1,5 +1,6 @@ /*! \example Heat_method_3/heat_method.cpp +\example Heat_method_3/heat_method_polyhedron.cpp \example Heat_method_3/heat_method_surface_mesh.cpp \example Heat_method_3/heat_method_surface_mesh_intrinsic.cpp */ diff --git a/Heat_method_3/examples/Heat_method_3/CMakeLists.txt b/Heat_method_3/examples/Heat_method_3/CMakeLists.txt index 1003faa228e..2b6e1f2ebe6 100644 --- a/Heat_method_3/examples/Heat_method_3/CMakeLists.txt +++ b/Heat_method_3/examples/Heat_method_3/CMakeLists.txt @@ -54,5 +54,6 @@ include_directories( BEFORE include ) include( CGAL_CreateSingleSourceCGALProgram ) create_single_source_cgal_program( "heat_method.cpp" ) +create_single_source_cgal_program( "heat_method_polyhedron.cpp" ) create_single_source_cgal_program( "heat_method_surface_mesh.cpp" ) create_single_source_cgal_program( "heat_method_surface_mesh_intrinsic.cpp" ) diff --git a/Heat_method_3/examples/Heat_method_3/heat_method.cpp b/Heat_method_3/examples/Heat_method_3/heat_method.cpp index b41d1a9bcc4..821ed8e60ff 100644 --- a/Heat_method_3/examples/Heat_method_3/heat_method.cpp +++ b/Heat_method_3/examples/Heat_method_3/heat_method.cpp @@ -7,6 +7,8 @@ #include #include +#include + typedef CGAL::Simple_cartesian Kernel; typedef Kernel::Point_3 Point_3; typedef CGAL::Surface_mesh Surface_mesh; @@ -28,9 +30,10 @@ int main(int argc, char* argv[]) CGAL::Heat_method_3::geodesic_distances_3(sm, heat_intensity,source) ; - + std::cout << "Source vertex " << source << " at: " << sm.point(source) << std::endl; BOOST_FOREACH(vertex_descriptor vd , vertices(sm)){ - std::cout << vd << " is at distance " << get(heat_intensity, vd) << " from " << source << std::endl; + std::cout << vd << " ("<< sm.point(vd) << ")" + << " is at distance " << get(heat_intensity, vd) << std::endl; } return 0; diff --git a/Heat_method_3/examples/Heat_method_3/heat_method_polyhedron.cpp b/Heat_method_3/examples/Heat_method_3/heat_method_polyhedron.cpp new file mode 100644 index 00000000000..0e98ce212fb --- /dev/null +++ b/Heat_method_3/examples/Heat_method_3/heat_method_polyhedron.cpp @@ -0,0 +1,40 @@ +#include +#include +#include + +#include +#include +#include + +#include +#include + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point_3; +typedef CGAL::Polyhedron_3 Surface_mesh; + +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; + +int main(int argc, char* argv[]) +{ + //read in mesh + Surface_mesh sm; + const char* filename = (argc > 1) ? argv[1] : "./data/bunny.off"; + std::ifstream in(filename); + in >> sm; + + boost::unordered_map heat_intensity; + + vertex_descriptor source = *(vertices(sm).first); + + CGAL::Heat_method_3::geodesic_distances_3(sm, + boost::make_assoc_property_map(heat_intensity), + source) ; + + std::cout << "Source vertex at: " << source->point() << std::endl; + BOOST_FOREACH(vertex_descriptor vd , vertices(sm)){ + std::cout << vd->point() << " is at distance " << heat_intensity[vd] << std::endl; + } + + return 0; +} diff --git a/Heat_method_3/examples/Heat_method_3/heat_method_surface_mesh.cpp b/Heat_method_3/examples/Heat_method_3/heat_method_surface_mesh.cpp index c8cafb1d6c8..4da92d43b00 100644 --- a/Heat_method_3/examples/Heat_method_3/heat_method_surface_mesh.cpp +++ b/Heat_method_3/examples/Heat_method_3/heat_method_surface_mesh.cpp @@ -4,9 +4,10 @@ #include #include -#include #include +#include + typedef CGAL::Simple_cartesian Kernel; typedef Kernel::Point_3 Point_3; typedef CGAL::Surface_mesh Surface_mesh; @@ -47,7 +48,6 @@ int main(int argc, char* argv[]) } hm.add_source(far); hm.update(); - BOOST_FOREACH(vertex_descriptor vd , vertices(sm)){ std::cout << vd << " is at distance " << get(heat_intensity, vd) << std::endl; diff --git a/Heat_method_3/examples/Heat_method_3/heat_method_surface_mesh_intrinsic.cpp b/Heat_method_3/examples/Heat_method_3/heat_method_surface_mesh_intrinsic.cpp index 8bc40744624..ff9f68d1f2c 100644 --- a/Heat_method_3/examples/Heat_method_3/heat_method_surface_mesh_intrinsic.cpp +++ b/Heat_method_3/examples/Heat_method_3/heat_method_surface_mesh_intrinsic.cpp @@ -5,9 +5,9 @@ #include #include -#include #include -#include + +#include typedef CGAL::Simple_cartesian Kernel; typedef Kernel::Point_3 Point_3; diff --git a/Heat_method_3/include/CGAL/Heat_method_3/Heat_method_3.h b/Heat_method_3/include/CGAL/Heat_method_3/Heat_method_3.h index f85838c1c53..02748c2500b 100644 --- a/Heat_method_3/include/CGAL/Heat_method_3/Heat_method_3.h +++ b/Heat_method_3/include/CGAL/Heat_method_3/Heat_method_3.h @@ -288,7 +288,7 @@ private: { //currently just working with a single vertex in source set, add the first one for now Index i; - Matrix K(num_vertices(tm), 1); + Matrix K(static_cast(num_vertices(tm)), 1); if(sources.empty()) { i = 0; K.set_coef(i,0, 1, true);