From 39a4ad853451f48eea97543cd0bc72c8e4f8d966 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 24 May 2016 16:13:33 +0200 Subject: [PATCH] Makes the parameters for the meshing of gray images editable by the user. --- .../Plugins/Mesh_3/Mesh_3_plugin.cpp | 14 +- .../Mesh_3/Mesh_3_plugin_cgal_code.cpp | 100 +++++++++---- .../Plugins/Mesh_3/Mesh_3_plugin_cgal_code.h | 5 +- .../Plugins/Mesh_3/Meshing_dialog.ui | 140 +++++++++++++----- ...hedron_demo_mesh_3_labeled_mesh_domain_3.h | 9 +- 5 files changed, 201 insertions(+), 67 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_plugin.cpp index 116a3b72604..d52974cd567 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_plugin.cpp @@ -269,6 +269,12 @@ void Mesh_3_plugin::mesh_3() // ----------------------------------- // Get values // ----------------------------------- + if(image_item && image_item->isGray()) + ui.groupBox_3->setVisible(true); + else + ui.groupBox_3->setVisible(false); + + int i = dialog.exec(); if( i == QDialog::Rejected ) { return; } @@ -280,6 +286,9 @@ void Mesh_3_plugin::mesh_3() const double tet_sizing = !ui.noTetSizing->isChecked() ? 0 : ui.tetSizing->value(); const bool protect_features = ui.protect->isChecked(); const int manifold = ui.manifoldCheckBox->isChecked() ? 1 : 0; + const float iso_value = !ui.groupBox_3->isVisible() ? 0 : ui.iso_value_spinBox->value(); + const float value_outside = !ui.groupBox_3->isVisible() ? 0 : ui.value_outside_spinBox->value(); + const float inside_is_less = !ui.groupBox_3->isVisible() ? false : ui.inside_is_less_checkBox->isChecked(); QApplication::setOverrideCursor(Qt::WaitCursor); @@ -352,7 +361,10 @@ void Mesh_3_plugin::mesh_3() protect_features, manifold, scene, - image_item->isGray()); + image_item->isGray(), + iso_value, + value_outside, + inside_is_less); } #endif 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 6c0f4923057..4c302f03e45 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 @@ -115,8 +115,11 @@ Meshing_thread* cgal_code_mesh_3(const Implicit_function_interface* pfunction, #ifdef CGAL_MESH_3_DEMO_ACTIVATE_SEGMENTED_IMAGES #include typedef CGAL::Gray_image_mesh_domain_3 > > Gray_image_domain1; -typedef CGAL::Polyhedron_demo_labeled_mesh_domain_3 Gray_image_domain; -typedef CGAL::Mesh_domain_with_polyline_features_3 Gray_Image_mesh_domain; +typedef CGAL::Gray_image_mesh_domain_3 > > Gray_image_domain2; +typedef CGAL::Polyhedron_demo_labeled_mesh_domain_3 Gray_image_less_domain; +typedef CGAL::Mesh_domain_with_polyline_features_3 Gray_Image_mesh_less_domain; +typedef CGAL::Polyhedron_demo_labeled_mesh_domain_3 Gray_image_more_domain; +typedef CGAL::Mesh_domain_with_polyline_features_3 Gray_Image_mesh_more_domain; Meshing_thread* cgal_code_mesh_3(const Image* pImage, const Polylines_container& polylines, @@ -128,7 +131,10 @@ Meshing_thread* cgal_code_mesh_3(const Image* pImage, bool protect_features, const int manifold, CGAL::Three::Scene_interface* scene, - bool is_gray) + bool is_gray, + float iso_value, + float value_outside, + bool inside_is_less) { if (NULL == pImage) { return NULL; } @@ -167,36 +173,70 @@ Meshing_thread* cgal_code_mesh_3(const Image* pImage, } else { - Gray_Image_mesh_domain* p_domain = new Gray_Image_mesh_domain(*pImage, std::bind1st(std::less(), 3), 0); + if(inside_is_less) + { + Gray_Image_mesh_less_domain* p_domain = new Gray_Image_mesh_less_domain(*pImage, std::bind1st(std::less(), iso_value), value_outside); + if(protect_features && polylines.empty()){ + std::vector > polylines_on_bbox; + CGAL::polylines_to_protect(*pImage, polylines_on_bbox); + p_domain->add_features(polylines_on_bbox.begin(), polylines_on_bbox.end()); + } + if(! polylines.empty()){ + // Insert edge in domain + p_domain->add_features(polylines.begin(), polylines.end()); + protect_features = true; // so that it will be passed in make_mesh_3 + } + CGAL::Timer timer; + timer.start(); + Scene_c3t3_item* p_new_item = new Scene_c3t3_item; + p_new_item->setScene(scene); - if(protect_features && polylines.empty()){ - std::vector > polylines_on_bbox; - CGAL::polylines_to_protect(*pImage, polylines_on_bbox); - p_domain->add_features(polylines_on_bbox.begin(), polylines_on_bbox.end()); + Mesh_parameters param; + param.protect_features = protect_features; + param.facet_angle = facet_angle; + param.facet_sizing = facet_sizing; + param.facet_approx = facet_approx; + param.tet_sizing = tet_sizing; + param.tet_shape = tet_shape; + param.manifold = manifold; + + typedef ::Mesh_function Mesh_function; + Mesh_function* p_mesh_function = new Mesh_function(p_new_item->c3t3(), + p_domain, param); + return new Meshing_thread(p_mesh_function, p_new_item); } - if(! polylines.empty()){ - // Insert edge in domain - p_domain->add_features(polylines.begin(), polylines.end()); - protect_features = true; // so that it will be passed in make_mesh_3 + else + { + Gray_Image_mesh_more_domain*p_domain = new Gray_Image_mesh_more_domain(*pImage, std::bind1st(std::greater(), iso_value), value_outside); + if(protect_features && polylines.empty()){ + std::vector > polylines_on_bbox; + CGAL::polylines_to_protect(*pImage, polylines_on_bbox); + p_domain->add_features(polylines_on_bbox.begin(), polylines_on_bbox.end()); + } + if(! polylines.empty()){ + // Insert edge in domain + p_domain->add_features(polylines.begin(), polylines.end()); + protect_features = true; // so that it will be passed in make_mesh_3 + } + CGAL::Timer timer; + timer.start(); + Scene_c3t3_item* p_new_item = new Scene_c3t3_item; + p_new_item->setScene(scene); + + Mesh_parameters param; + param.protect_features = protect_features; + param.facet_angle = facet_angle; + param.facet_sizing = facet_sizing; + param.facet_approx = facet_approx; + param.tet_sizing = tet_sizing; + param.tet_shape = tet_shape; + param.manifold = manifold; + + typedef ::Mesh_function Mesh_function; + Mesh_function* p_mesh_function = new Mesh_function(p_new_item->c3t3(), + p_domain, param); + return new Meshing_thread(p_mesh_function, p_new_item); } - CGAL::Timer timer; - timer.start(); - Scene_c3t3_item* p_new_item = new Scene_c3t3_item; - p_new_item->setScene(scene); - - Mesh_parameters param; - param.protect_features = protect_features; - param.facet_angle = facet_angle; - param.facet_sizing = facet_sizing; - param.facet_approx = facet_approx; - param.tet_sizing = tet_sizing; - param.tet_shape = tet_shape; - param.manifold = manifold; - - typedef ::Mesh_function Mesh_function; - Mesh_function* p_mesh_function = new Mesh_function(p_new_item->c3t3(), - p_domain, param); - return new Meshing_thread(p_mesh_function, p_new_item); } } diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_plugin_cgal_code.h b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_plugin_cgal_code.h index ac35a09fdd9..1d9576abffc 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_plugin_cgal_code.h +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Mesh_3_plugin_cgal_code.h @@ -52,5 +52,8 @@ Meshing_thread* cgal_code_mesh_3(const CGAL::Image_3* pImage, bool protect_features, const int manifold, CGAL::Three::Scene_interface* scene, - bool is_gray = false); + bool is_gray = false, + float iso_value = 3.f, + float value_outside = 0.f, + bool inside_is_less = true); #endif diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Meshing_dialog.ui b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Meshing_dialog.ui index 965a4eb0dbf..39a4c09e3a0 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Meshing_dialog.ui +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Meshing_dialog.ui @@ -10,7 +10,7 @@ 0 0 473 - 482 + 637 @@ -254,17 +254,46 @@ Volume - - - + + + + + Enable/Disable parameter + - &Tetrahedron max. size + - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + true - - tetSizing + + + + + + Enable/Disable parameter + + + + + + true + + + + + + + + 110 + 0 + + + + 1.000000000000000 + + + 3.000000000000000 @@ -298,45 +327,90 @@ p, li { white-space: pre-wrap; } + + + + &Tetrahedron max. size + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + tetSizing + + + + + + + + + + Gray Images + + + + + + + 0 + 0 + + + + Qt::RightToLeft + + + + + + true + + + - - - - 110 - 0 - - - - 1.000000000000000 - + 3.000000000000000 - - - - Enable/Disable parameter + + + + + + + Qt::LeftToRight - + Value outside: - - true + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - Enable/Disable parameter + + + + Qt::LeftToRight - + Iso value: - - true + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Value "inside" is less that iso value: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Polyhedron_demo_mesh_3_labeled_mesh_domain_3.h b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Polyhedron_demo_mesh_3_labeled_mesh_domain_3.h index 8f77b42b0b7..13cae651a50 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Polyhedron_demo_mesh_3_labeled_mesh_domain_3.h +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Polyhedron_demo_mesh_3_labeled_mesh_domain_3.h @@ -85,7 +85,7 @@ public: p_rng) {} - ///Constructor for the Gray-level Images + ///Constructors for the Gray-level Images Polyhedron_demo_labeled_mesh_domain_3( const Image& img, const std::binder1st > iso_value = std::bind1st(std::less(), 3), @@ -93,7 +93,12 @@ public: : Base(img, iso_value) {} - + Polyhedron_demo_labeled_mesh_domain_3( + const Image& img, + const std::binder1st > iso_value = std::bind1st(std::greater(), 3), + const float value_outside = 0) + : Base(img, iso_value) + {} /** * Returns the index to be stored in a vertex lying on the surface identified