From d82cdbcff157f2e79882f3d986aaf4d4bd365274 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 5 Oct 2018 17:02:38 +0200 Subject: [PATCH 1/4] Mesh_3: Allow `Subdomain_index` to be `short` ... That forced me to modify the `Index` of domains with features. --- Mesh_3/include/CGAL/Mesh_3/io_signature.h | 40 +++++++++++++ .../Mesh_domain_with_polyline_features_3.h | 56 +++++++++++++++---- .../CGAL/internal/Mesh_3/indices_management.h | 24 +++++++- .../test_domain_with_polyline_features.cpp | 1 + .../test_meshing_polyhedron_with_features.cpp | 7 ++- .../Polygon_mesh_processing/detect_features.h | 10 ++-- 6 files changed, 120 insertions(+), 18 deletions(-) diff --git a/Mesh_3/include/CGAL/Mesh_3/io_signature.h b/Mesh_3/include/CGAL/Mesh_3/io_signature.h index 1dda061e14b..c5dfd9dd25a 100644 --- a/Mesh_3/include/CGAL/Mesh_3/io_signature.h +++ b/Mesh_3/include/CGAL/Mesh_3/io_signature.h @@ -109,6 +109,46 @@ struct Get_io_signature } }; +template <> +struct Get_io_signature +{ + std::string operator()() { + return "c"; + } +}; + +template <> +struct Get_io_signature +{ + std::string operator()() { + return "uc"; + } +}; + +template <> +struct Get_io_signature +{ + std::string operator()() { + return "sc"; + } +}; + +template <> +struct Get_io_signature +{ + std::string operator()() { + return "s"; + } +}; + +template <> +struct Get_io_signature +{ + std::string operator()() { + return "us"; + } +}; + template <> struct Get_io_signature { diff --git a/Mesh_3/include/CGAL/Mesh_domain_with_polyline_features_3.h b/Mesh_3/include/CGAL/Mesh_domain_with_polyline_features_3.h index 5fc0fcc48df..eb9dfd83520 100644 --- a/Mesh_3/include/CGAL/Mesh_domain_with_polyline_features_3.h +++ b/Mesh_3/include/CGAL/Mesh_domain_with_polyline_features_3.h @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -546,15 +547,19 @@ class Mesh_domain_with_polyline_features_3 public: /// \name Types /// @{ - typedef typename MeshDomain_3::Index Index; + typedef typename MeshDomain_3::Surface_patch_index Surface_patch_index; + typedef typename MeshDomain_3::Subdomain_index Subdomain_index; + typedef int Curve_index; + typedef int Corner_index; - typedef typename MeshDomain_3::Surface_patch_index - Surface_patch_index; + typedef typename Mesh_3::internal::Index_generator_with_features< + typename MeshDomain_3::Subdomain_index, + Surface_patch_index, + Curve_index, + Corner_index>::type Index; - typedef int Curve_index; - typedef int Corner_index; - typedef CGAL::Tag_true Has_features; - typedef typename MeshDomain_3::R::FT FT; + typedef CGAL::Tag_true Has_features; + typedef typename MeshDomain_3::R::FT FT; /// @} #ifndef DOXYGEN_RUNNING @@ -777,18 +782,47 @@ public: const Point_3& c1, const Point_3& c2, const FT sq_r1, const FT sq_r2) const; + + /** + * Returns the index to be stored in a vertex lying on the surface identified + * by \c index. + */ + Index index_from_surface_patch_index(const Surface_patch_index& index) const + { return Index(index); } + + /** + * Returns the index to be stored in a vertex lying in the subdomain + * identified by \c index. + */ + Index index_from_subdomain_index(const Subdomain_index& index) const + { return Index(index); } + /// Returns an `Index` from a `Curve_index` Index index_from_curve_index(const Curve_index& index) const { return Index(index); } - /// Returns a `Curve_index` from an `Index` - Curve_index curve_index(const Index& index) const - { return boost::get(index); } - /// Returns an `Index` from a `Corner_index` Index index_from_corner_index(const Corner_index& index) const { return Index(index); } + /** + * Returns the \c Surface_patch_index of the surface patch + * where lies a vertex with dimension 2 and index \c index. + */ + Surface_patch_index surface_patch_index(const Index& index) const + { return boost::get(index); } + + /** + * Returns the index of the subdomain containing a vertex + * with dimension 3 and index \c index. + */ + Subdomain_index subdomain_index(const Index& index) const + { return boost::get(index); } + + /// Returns a `Curve_index` from an `Index` + Curve_index curve_index(const Index& index) const + { return boost::get(index); } + /// Returns a `Corner_index` from an `Index` Corner_index corner_index(const Index& index) const { return boost::get(index); } diff --git a/Mesh_3/include/CGAL/internal/Mesh_3/indices_management.h b/Mesh_3/include/CGAL/internal/Mesh_3/indices_management.h index 4bd0e7be97f..62cbed028f1 100644 --- a/Mesh_3/include/CGAL/internal/Mesh_3/indices_management.h +++ b/Mesh_3/include/CGAL/internal/Mesh_3/indices_management.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -48,7 +49,7 @@ template < typename Subdomain_index, typename Surface_patch_index > struct Index_generator { typedef boost::variant Index; - typedef Index type; + typedef Index type; }; template < typename T > @@ -58,6 +59,27 @@ struct Index_generator typedef Index type; }; +template < typename Subdomain_index, + typename Surface_patch_index, + typename Curves_index, + typename Corner_index> +struct Index_generator_with_features +{ + typedef boost::mpl::set4 Set; + typedef typename boost::make_variant_over::type Index; + typedef Index type; +}; + +template < typename T> +struct Index_generator_with_features +{ + typedef T Index; + typedef Index type; +}; + template const T& get_index(const Boost_variant& x, typename boost::disable_if >::type * = 0) diff --git a/Mesh_3/test/Mesh_3/test_domain_with_polyline_features.cpp b/Mesh_3/test/Mesh_3/test_domain_with_polyline_features.cpp index 5123829ce97..d5b480e8d10 100644 --- a/Mesh_3/test/Mesh_3/test_domain_with_polyline_features.cpp +++ b/Mesh_3/test/Mesh_3/test_domain_with_polyline_features.cpp @@ -38,6 +38,7 @@ struct Dummy_domain typedef typename K::FT FT; typedef int Index; typedef int Surface_patch_index; + typedef unsigned short Subdomain_index; }; typedef Dummy_domain Smooth_domain; diff --git a/Mesh_3/test/Mesh_3/test_meshing_polyhedron_with_features.cpp b/Mesh_3/test/Mesh_3/test_meshing_polyhedron_with_features.cpp index d69b475b3ad..9697ac33b19 100644 --- a/Mesh_3/test/Mesh_3/test_meshing_polyhedron_with_features.cpp +++ b/Mesh_3/test/Mesh_3/test_meshing_polyhedron_with_features.cpp @@ -39,8 +39,11 @@ struct Polyhedron_with_features_tester : public Tester void operator()() const { typedef CGAL::Mesh_3::Robust_intersection_traits_3 Gt; - typedef typename CGAL::Mesh_polyhedron_3::type Polyhedron; - typedef CGAL::Polyhedral_mesh_domain_with_features_3 Mesh_domain; + typedef typename CGAL::Mesh_polyhedron_3::type Polyhedron; + typedef CGAL::Polyhedral_mesh_domain_with_features_3 Mesh_domain; typedef typename CGAL::Mesh_triangulation_3< Mesh_domain, diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/detect_features.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/detect_features.h index 330e348277b..5e0394a876d 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/detect_features.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/detect_features.h @@ -97,14 +97,16 @@ template typename PatchIdMapWrapper::value_type get(PatchIdMapWrapper& map, Handle_type h) { - return get(map.map, h) - map.offset; + typedef typename PatchIdMapWrapper::value_type value_type; + return value_type(get(map.map, h) - map.offset); } template void put(PatchIdMapWrapper& map, Handle_type h, typename PatchIdMapWrapper::value_type pid) { - put(map.map, h, pid + map.offset); + typedef typename PatchIdMapWrapper::value_type value_type; + put(map.map, h, value_type(pid + map.offset)); } @@ -127,14 +129,14 @@ template typename PatchIdMapWrapper >::value_type get(PatchIdMapWrapper >& map, Handle_type h) { - return get(map.map, h).first - map.offset; + return Int(get(map.map, h).first - map.offset); } template void put(PatchIdMapWrapper >& map, Handle_type h, typename PatchIdMapWrapper >::value_type pid) { - put(map.map, h, std::pair(pid+map.offset, 0)); + put(map.map, h, std::pair(Int(pid+map.offset), 0)); } template Date: Mon, 8 Oct 2018 09:50:03 +0200 Subject: [PATCH 2/4] Add `-ftemplate-backtrace-limit=0` to CXX flags That should allow to debug more efficiently compilation issues with templates --- .travis/build_package.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/build_package.sh b/.travis/build_package.sh index f1faf434ddd..d9afbe224b7 100755 --- a/.travis/build_package.sh +++ b/.travis/build_package.sh @@ -2,7 +2,7 @@ set -e [ -n "$CGAL_DEBUG_TRAVIS" ] && set -x -CXX_FLAGS="-DCGAL_NDEBUG" +CXX_FLAGS="-DCGAL_NDEBUG -ftemplate-backtrace-limit=0" function build_examples { mkdir -p build-travis From afde694d639733be64872f1ea7fe89ca0336ff75 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Mon, 8 Oct 2018 12:50:08 +0200 Subject: [PATCH 3/4] As far as I know, the `CMAKE_BUILD_TYPE` is empty. --- .travis/build_package.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis/build_package.sh b/.travis/build_package.sh index d9afbe224b7..c47cd822c21 100755 --- a/.travis/build_package.sh +++ b/.travis/build_package.sh @@ -7,7 +7,7 @@ CXX_FLAGS="-DCGAL_NDEBUG -ftemplate-backtrace-limit=0" function build_examples { mkdir -p build-travis cd build-travis - cmake -DCGAL_DIR="/usr/local/lib/cmake/CGAL" -DCMAKE_CXX_FLAGS_RELEASE="${CXX_FLAGS}" .. + cmake -DCGAL_DIR="/usr/local/lib/cmake/CGAL" -DCMAKE_CXX_FLAGS="${CXX_FLAGS}" .. make -j2 } @@ -45,7 +45,7 @@ function build_demo { QGLVIEWERROOT=$PWD/qglviewer export QGLVIEWERROOT fi - cmake -DCGAL_DIR="/usr/local/lib/cmake/CGAL" -DQt5_DIR="/opt/qt55/lib/cmake/Qt5" -DQt5Svg_DIR="/opt/qt55/lib/cmake/Qt5Svg" -DQt5OpenGL_DIR="/opt/qt55/lib/cmake/Qt5OpenGL" -DCGAL_DONT_OVERRIDE_CMAKE_FLAGS:BOOL=ON -DCMAKE_CXX_FLAGS_RELEASE="${CXX_FLAGS} ${EXTRA_CXX_FLAGS}" .. + cmake -DCGAL_DIR="/usr/local/lib/cmake/CGAL" -DQt5_DIR="/opt/qt55/lib/cmake/Qt5" -DQt5Svg_DIR="/opt/qt55/lib/cmake/Qt5Svg" -DQt5OpenGL_DIR="/opt/qt55/lib/cmake/Qt5OpenGL" -DCGAL_DONT_OVERRIDE_CMAKE_FLAGS:BOOL=ON -DCMAKE_CXX_FLAGS="${CXX_FLAGS} ${EXTRA_CXX_FLAGS}" .. make -j2 } old_IFS=$IFS From d50e70eee8ccaa1c8ba2b99b5b25d7473180d6d5 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Mon, 8 Oct 2018 14:53:48 +0200 Subject: [PATCH 4/4] boost::make_variant_over cannot be trusted! Use my own naive implementation, with ugly meta-programming, instead of using `boost::make_variant_over` and `boost::mpl::set`. --- .../CGAL/internal/Mesh_3/indices_management.h | 60 +++++++++++++++++-- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/Mesh_3/include/CGAL/internal/Mesh_3/indices_management.h b/Mesh_3/include/CGAL/internal/Mesh_3/indices_management.h index 62cbed028f1..b10f55e321b 100644 --- a/Mesh_3/include/CGAL/internal/Mesh_3/indices_management.h +++ b/Mesh_3/include/CGAL/internal/Mesh_3/indices_management.h @@ -33,7 +33,6 @@ #include #include #include -#include #include #include @@ -59,17 +58,66 @@ struct Index_generator typedef Index type; }; +// Nasty meta-programming to get a boost::variant of four types that +// may not be all different. +template struct seq1 { + typedef T0 type; +}; +template struct seq2 { + typedef boost::variant type; +}; +template struct seq3 { + typedef boost::variant type; +}; +template struct seq4 { + typedef boost::variant type; +}; + +template struct insert; +template struct insert, U> { + typedef seq2 type; +}; +template struct insert, V> { + typedef seq3 type; +}; +template +struct insert, W> { + typedef seq4 type; +}; +template struct insert, T> { + typedef seq1 type; +}; +template struct insert, T> { + typedef seq2 type; +}; +template struct insert, U> { + typedef seq2 type; +}; +template struct insert, T> { + typedef seq3 type; +}; +template struct insert, U> { + typedef seq3 type; +}; +template struct insert, V> { + typedef seq3 type; +}; + template < typename Subdomain_index, typename Surface_patch_index, typename Curves_index, typename Corner_index> struct Index_generator_with_features { - typedef boost::mpl::set4 Set; - typedef typename boost::make_variant_over::type Index; + typedef typename insert< + typename insert< + typename insert, + Surface_patch_index + >::type, + Curves_index + >::type, + Corner_index>::type seq; + typedef typename seq::type Index; typedef Index type; };