From bca99f4a1833a9186e8dfa4cfc1957f03d9ae3c7 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Tue, 27 Sep 2022 16:17:25 +0200 Subject: [PATCH] add detect_features named parameter for create_labeled_image_mesh_domain_with_features todo : move it to create_labeled_image_mesh_domain and remove create_labeled_image_mesh_domain_with_features as soon as PR on named parameters is merged --- BGL/include/CGAL/boost/parameter.h | 1 + ...sh_3D_image_with_detection_of_features.cpp | 6 +- Mesh_3/include/CGAL/Implicit_mesh_domain_3.h | 1 + .../CGAL/Labeled_image_mesh_domain_3.h | 1 + Mesh_3/include/CGAL/Labeled_mesh_domain_3.h | 16 +++- .../CGAL/Mesh_3/Null_subdomain_index.h | 25 ++++++ .../CGAL/Mesh_3/detect_features_in_image.h | 13 ++++ .../Mesh_3/detect_features_on_image_bbox.h | 76 +++++++++++++++++++ .../CGAL/Mesh_3/polylines_to_protect.h | 7 +- .../Mesh_3/Mesh_3_plugin_cgal_code.cpp | 5 +- 10 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 Mesh_3/include/CGAL/Mesh_3/Null_subdomain_index.h create mode 100644 Mesh_3/include/CGAL/Mesh_3/detect_features_on_image_bbox.h diff --git a/BGL/include/CGAL/boost/parameter.h b/BGL/include/CGAL/boost/parameter.h index 14ab09b0474..4356ce2de19 100644 --- a/BGL/include/CGAL/boost/parameter.h +++ b/BGL/include/CGAL/boost/parameter.h @@ -114,6 +114,7 @@ BOOST_PARAMETER_NAME( (weights, tag) weights_) BOOST_PARAMETER_NAME( (p_rng, tag ) p_rng_) BOOST_PARAMETER_NAME( (null_subdomain_index, tag ) null_subdomain_index_) BOOST_PARAMETER_NAME( (construct_surface_patch_index, tag ) construct_surface_patch_index_) +BOOST_PARAMETER_NAME( (detect_features, tag ) detect_features_) // First used in BOOST_PARAMETER_NAME( (image, tag ) image_) diff --git a/Mesh_3/examples/Mesh_3/mesh_3D_image_with_detection_of_features.cpp b/Mesh_3/examples/Mesh_3/mesh_3D_image_with_detection_of_features.cpp index 0b0a7ffa2a6..55c3f44abb2 100644 --- a/Mesh_3/examples/Mesh_3/mesh_3D_image_with_detection_of_features.cpp +++ b/Mesh_3/examples/Mesh_3/mesh_3D_image_with_detection_of_features.cpp @@ -13,6 +13,9 @@ #include #include +#include + + typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef CGAL::Labeled_mesh_domain_3 Image_domain; typedef CGAL::Mesh_domain_with_polyline_features_3 Mesh_domain; @@ -47,7 +50,8 @@ int main(int argc, char* argv[]) /// [Domain creation] Mesh_domain domain - = Mesh_domain::create_labeled_image_mesh_domain_with_features(image); + = Mesh_domain::create_labeled_image_mesh_domain_with_features(image, + detect_features = CGAL::Mesh_3::Detect_features_in_image()); /// [Domain creation] CGAL::Bbox_3 bbox = domain.bbox(); diff --git a/Mesh_3/include/CGAL/Implicit_mesh_domain_3.h b/Mesh_3/include/CGAL/Implicit_mesh_domain_3.h index 3b969f95e8d..3b5bd6b2b50 100644 --- a/Mesh_3/include/CGAL/Implicit_mesh_domain_3.h +++ b/Mesh_3/include/CGAL/Implicit_mesh_domain_3.h @@ -24,6 +24,7 @@ #include #include +#include #include namespace CGAL { diff --git a/Mesh_3/include/CGAL/Labeled_image_mesh_domain_3.h b/Mesh_3/include/CGAL/Labeled_image_mesh_domain_3.h index 31ffaee34c8..9ac0525ee14 100644 --- a/Mesh_3/include/CGAL/Labeled_image_mesh_domain_3.h +++ b/Mesh_3/include/CGAL/Labeled_image_mesh_domain_3.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include diff --git a/Mesh_3/include/CGAL/Labeled_mesh_domain_3.h b/Mesh_3/include/CGAL/Labeled_mesh_domain_3.h index 6210e35410d..e7820dd2c72 100644 --- a/Mesh_3/include/CGAL/Labeled_mesh_domain_3.h +++ b/Mesh_3/include/CGAL/Labeled_mesh_domain_3.h @@ -55,7 +55,7 @@ #endif #include -#include //needs Null_subdomain_index +#include namespace CGAL { namespace Mesh_3 { @@ -126,6 +126,17 @@ namespace internal { } }; + template + void detect_features(const CGAL::Image_3& image, + Mesh_domain& domain, + DetectFunctor functor) + { + if (boost::is_same::value) + return; + else + return functor(image, domain); + } + } // end namespace CGAL::Mesh_3::internal } // end namespace CGAL::Mesh_3 @@ -485,6 +496,7 @@ CGAL_IGNORE_BOOST_PARAMETER_NAME_WARNINGS (image_values_to_subdomain_indices_, *, Null_functor()) (null_subdomain_index_, *, Null_functor()) (construct_surface_patch_index_, *, Null_functor()) + (detect_features_, *, Null_functor()) ) ) { @@ -497,7 +509,7 @@ CGAL_IGNORE_BOOST_PARAMETER_NAME_WARNINGS p::null_subdomain_index = null_subdomain_index_, p::construct_surface_patch_index = construct_surface_patch_index_); - CGAL::Mesh_3::detect_features_in_image(image_, domain); + CGAL::Mesh_3::internal::detect_features(image_, domain, detect_features_); return domain; } diff --git a/Mesh_3/include/CGAL/Mesh_3/Null_subdomain_index.h b/Mesh_3/include/CGAL/Mesh_3/Null_subdomain_index.h new file mode 100644 index 00000000000..1da8351bff4 --- /dev/null +++ b/Mesh_3/include/CGAL/Mesh_3/Null_subdomain_index.h @@ -0,0 +1,25 @@ +// Copyright (c) 2015 GeometryFactory +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Laurent Rineau + +#ifndef CGAL_INTERNAL_MESH_3_INTERNAL_NULL_SUBDOMAIN_INDEX +#define CGAL_INTERNAL_MESH_3_INTERNAL_NULL_SUBDOMAIN_INDEX + +#include + +namespace CGAL { + struct Null_subdomain_index { + template + bool operator()(const T& x) const { return 0 == x; } + }; +} + +#endif //CGAL_INTERNAL_MESH_3_INTERNAL_NULL_SUBDOMAIN_INDEX diff --git a/Mesh_3/include/CGAL/Mesh_3/detect_features_in_image.h b/Mesh_3/include/CGAL/Mesh_3/detect_features_in_image.h index 99036defb52..7632eda29c4 100644 --- a/Mesh_3/include/CGAL/Mesh_3/detect_features_in_image.h +++ b/Mesh_3/include/CGAL/Mesh_3/detect_features_in_image.h @@ -41,6 +41,8 @@ namespace CGAL { namespace Mesh_3 { +namespace internal +{ // Protect the intersection of the object with the box of the image, // by declaring 1D-features. Note that `CGAL::polylines_to_protect` is @@ -245,6 +247,17 @@ bool detect_features_in_image(const CGAL::Image_3& image, Mesh_domain& domain) return false; } +}// namespace internal + +struct Detect_features_in_image +{ + template + void operator()(const CGAL::Image_3& image, Mesh_domain& domain) + { + internal::detect_features_in_image(image, domain); + } +}; + }//end namespace Mesh_3 }//end namespace CGAL diff --git a/Mesh_3/include/CGAL/Mesh_3/detect_features_on_image_bbox.h b/Mesh_3/include/CGAL/Mesh_3/detect_features_on_image_bbox.h new file mode 100644 index 00000000000..47993791ef6 --- /dev/null +++ b/Mesh_3/include/CGAL/Mesh_3/detect_features_on_image_bbox.h @@ -0,0 +1,76 @@ +// Copyright (c) 2022 GeometryFactory (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Laurent Rineau, Jane Tournois +// +//****************************************************************************** +// +//****************************************************************************** + +#ifndef CGAL_MESH_3_DETECT_FEATURES_ON_IMAGE_BBOX_H +#define CGAL_MESH_3_DETECT_FEATURES_ON_IMAGE_BBOX_H + +#include + +#include + +#include + + +namespace CGAL +{ +namespace Mesh_3 +{ +namespace internal +{ +template +void detect_features_on_bbox_with_know_word_type(const CGAL::Image_3& image, + Mesh_domain& domain) +{ + using Gt = typename Mesh_domain::R; + using Point_3 = typename Gt::Point_3; + using Polyline_type = std::vector; + using Polylines = std::vector; + + Polylines polylines_on_bbox; + CGAL::polylines_to_protect(image, polylines_on_bbox); + + domain.add_features(polylines_on_bbox.begin(), polylines_on_bbox.end()); + +} + +template +void detect_features_on_bbox(const CGAL::Image_3& image, Mesh_domain& domain) +{ + CGAL_IMAGE_IO_CASE(image.image(), + return detect_features_on_bbox_with_know_word_type(image, domain) + ); + CGAL_error_msg("This place should never be reached, because it would mean " + "the image word type is a type that is not handled by " + "CGAL_ImageIO."); +} + +}// namespace internal + +struct Detect_features_on_image_bbox +{ + template + void operator()(const CGAL::Image_3& image, Mesh_domain& domain) + { + internal::detect_features_on_bbox(image, domain); + } +}; + + +}//end namespace Mesh_3 +}//end namespace CGAL + + +#endif //CGAL_MESH_3_DETECT_FEATURES_ON_IMAGE_BBOX_H diff --git a/Mesh_3/include/CGAL/Mesh_3/polylines_to_protect.h b/Mesh_3/include/CGAL/Mesh_3/polylines_to_protect.h index dbffdb4c547..86471b3030e 100644 --- a/Mesh_3/include/CGAL/Mesh_3/polylines_to_protect.h +++ b/Mesh_3/include/CGAL/Mesh_3/polylines_to_protect.h @@ -36,12 +36,7 @@ #include #include -namespace CGAL { - struct Null_subdomain_index { - template - bool operator()(const T& x) const { return 0 == x; } - }; -} +#include namespace CGAL { namespace Mesh_3 { diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_plugin_cgal_code.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_plugin_cgal_code.cpp index 583fef72bad..f9dd8f2e9e9 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_plugin_cgal_code.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_plugin_cgal_code.cpp @@ -13,6 +13,8 @@ #include "Mesh_function.h" #include "Facet_extra_criterion.h" +#include + using namespace CGAL::Three; @@ -369,7 +371,8 @@ Meshing_thread* cgal_code_mesh_3(const Image* pImage, (p::image = *pImage, p::relative_error_bound = 1e-6, p::construct_surface_patch_index = - [](int i, int j) { return (i * 1000 + j); } + [](int i, int j) { return (i * 1000 + j); }, + p::detect_features = CGAL::Mesh_3::Detect_features_in_image() ) ); }