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 b95f47a8fd9..62eefd5afe6 100644 --- a/Mesh_3/include/CGAL/Labeled_image_mesh_domain_3.h +++ b/Mesh_3/include/CGAL/Labeled_image_mesh_domain_3.h @@ -31,7 +31,7 @@ #include #include #include - +#include namespace CGAL { @@ -64,6 +64,16 @@ public: p_rng) {} + Labeled_image_mesh_domain_3(const Image& image, + const CGAL::Bbox_3& bbox, + const FT& error_bound = FT(1e-3), + CGAL::Random* p_rng = NULL) + : Base(Wrapper(image), + bbox, + error_bound, + p_rng) + {} + /// Destructor virtual ~Labeled_image_mesh_domain_3() {} diff --git a/Polyhedron/demo/Polyhedron/C3t3_type.h b/Polyhedron/demo/Polyhedron/C3t3_type.h index 12b397dd7c3..7511d78e7c9 100644 --- a/Polyhedron/demo/Polyhedron/C3t3_type.h +++ b/Polyhedron/demo/Polyhedron/C3t3_type.h @@ -44,9 +44,7 @@ typedef CGAL::Triangle_accessor_3 T_accessor; typedef CGAL::Polyhedral_mesh_domain_with_features_3< Kernel, Polyhedron, T_accessor, CGAL::Tag_true> Polyhedral_mesh_domain; -// The last `Tag_true` says the Patch_id type will be int -// until now, in `Image_mesh_domain`, and `Function_mesh_domain`. -// Patch_id is pair +// The last `Tag_true` says the Patch_id type will be int, and not pair #ifdef CGAL_MESH_3_DEMO_ACTIVATE_SEGMENTED_IMAGES typedef CGAL::Labeled_image_mesh_domain_3 Image_domain; diff --git a/Polyhedron/demo/Polyhedron/CMakeLists.txt b/Polyhedron/demo/Polyhedron/CMakeLists.txt index cab872f0909..cdeab44d147 100644 --- a/Polyhedron/demo/Polyhedron/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/CMakeLists.txt @@ -294,7 +294,8 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) Polyhedron_demo_mesh_3_plugin_cgal_code.cpp Meshing_thread.cpp #Scene_c3t3_item.moc ${meshingUI_FILES}) target_link_libraries(mesh_3_plugin scene_polyhedron_item scene_polygon_soup_item - scene_implicit_function_item scene_c3t3_item ${QGLVIEWER_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}) + scene_implicit_function_item scene_segmented_image_item + scene_c3t3_item ${QGLVIEWER_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}) add_item(scene_segmented_image_item Scene_segmented_image_item.cpp) qt5_wrap_cpp( VOLUME_MOC_OUTFILES ${CMAKE_CURRENT_SOURCE_DIR}/Volume_plane_thread.h ) diff --git a/Polyhedron/demo/Polyhedron/Image_type.h b/Polyhedron/demo/Polyhedron/Image_type.h new file mode 100644 index 00000000000..69eb8262159 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/Image_type.h @@ -0,0 +1,8 @@ +#ifndef IMAGE_TYPE_H +#define IMAGE_TYPE_H + +#include + +typedef CGAL::Image_3 Image; + +#endif // IMAGE_TYPE_H diff --git a/Polyhedron/demo/Polyhedron/Image_type_fwd.h b/Polyhedron/demo/Polyhedron/Image_type_fwd.h new file mode 100644 index 00000000000..537f8b79bc8 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/Image_type_fwd.h @@ -0,0 +1,8 @@ +#ifndef IMAGE_TYPE_FWD_H +#define IMAGE_TYPE_FWD_H + +namespace CGAL { + class Image_3; +} + +#endif // IMAGE_TYPE_FWD_H diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_labeled_mesh_domain_3.h b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_labeled_mesh_domain_3.h index fa3495dd117..0c76a24d4c1 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_labeled_mesh_domain_3.h +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_labeled_mesh_domain_3.h @@ -27,6 +27,8 @@ #define CGAL_POLYHEDRON_DEMO_LABELED_MESH_DOMAIN_3_H #include +#include +#include "Image_type.h" #include @@ -36,7 +38,7 @@ namespace CGAL { * \class Polyhedron_demo_labeled_mesh_domain_3 * LabeledDomain must be a Labeled_mesh_domain_3 */ -template +template class Polyhedron_demo_labeled_mesh_domain_3 : public LabeledDomain { @@ -64,14 +66,6 @@ public: typedef CGAL::cpp11::tuple Intersection; //constructors - Polyhedron_demo_labeled_mesh_domain_3( - const typename Base::Fct& f, - const typename Base::Sphere_3& bounding_sphere, - const typename Base::FT& error_bound = FT(1e-3), - CGAL::Random* p_rng = NULL) - : Base(f, bounding_sphere, error_bound, p_rng) - {} - Polyhedron_demo_labeled_mesh_domain_3( const typename Base::Fct& f, const typename Base::Bbox_3& bbox, @@ -81,11 +75,10 @@ public: {} Polyhedron_demo_labeled_mesh_domain_3( - const typename Base::Fct& f, - const typename Base::Iso_cuboid_3& bbox, + const Image& img, const typename Base::FT& error_bound = FT(1e-3), CGAL::Random* p_rng = NULL) - : Base(f, bbox, error_bound, p_rng) + : Base(img, error_bound, p_rng) {} /** diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin.cpp index 27e2631954c..55534b553a2 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin.cpp @@ -21,6 +21,9 @@ #ifdef CGAL_MESH_3_DEMO_ACTIVATE_IMPLICIT_FUNCTIONS #include "Scene_implicit_function_item.h" #endif +#ifdef CGAL_MESH_3_DEMO_ACTIVATE_SEGMENTED_IMAGES +#include "Scene_segmented_image_item.h" +#endif #include "ui_Meshing_dialog.h" @@ -45,6 +48,16 @@ Scene_item* cgal_code_mesh_3(const Implicit_function_interface* pfunction, CGAL::Three::Scene_interface* scene); #endif +#ifdef CGAL_MESH_3_DEMO_ACTIVATE_SEGMENTED_IMAGES +Scene_item* cgal_code_mesh_3(const Image* pImage, + const double facet_angle, + const double facet_sizing, + const double facet_approx, + const double tet_sizing, + const double tet_shape, + CGAL::Three::Scene_interface* scene); +#endif + using namespace CGAL::Three; class Polyhedron_demo_mesh_3_plugin : public QObject, @@ -106,6 +119,10 @@ void Polyhedron_demo_mesh_3_plugin::mesh_3() Scene_implicit_function_item* function_item = qobject_cast(scene->item(index)); #endif +#ifdef CGAL_MESH_3_DEMO_ACTIVATE_SEGMENTED_IMAGES + Scene_segmented_image_item* image_item = + qobject_cast(scene->item(index)); +#endif Scene_item* item = NULL; bool features_protection_available = false; @@ -117,6 +134,9 @@ void Polyhedron_demo_mesh_3_plugin::mesh_3() #ifdef CGAL_MESH_3_DEMO_ACTIVATE_IMPLICIT_FUNCTIONS else if (NULL != function_item) { item = function_item; } #endif +#ifdef CGAL_MESH_3_DEMO_ACTIVATE_SEGMENTED_IMAGES + else if (NULL != image_item) { item = image_item; } +#endif if (NULL == item) { @@ -239,6 +259,25 @@ void Polyhedron_demo_mesh_3_plugin::mesh_3() scene); } #endif +#ifdef CGAL_MESH_3_DEMO_ACTIVATE_SEGMENTED_IMAGES + else if (NULL != image_item) + { + const Image* pImage = image_item->image(); + if (NULL == pImage) + { + QMessageBox::critical(mw, tr(""), tr("ERROR: no data in selected item")); + return; + } + + temp_item = cgal_code_mesh_3(pImage, + angle, + facet_sizing, + approx, + tet_sizing, + radius_edge, + scene); + } +#endif Scene_c3t3_item *result_item = qobject_cast(temp_item); diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin_cgal_code.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin_cgal_code.cpp index 869d45335f0..8274ce2ec32 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin_cgal_code.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin_cgal_code.cpp @@ -1,23 +1,18 @@ #include "config_mesh_3.h" -#include -#include - #include #include +#include #include #include -#include -#include #include #include #include "Mesh_function.h" #include -#include #include @@ -139,6 +134,67 @@ Scene_item* cgal_code_mesh_3(const Implicit_function_interface* pfunction, p_new_item->c3t3() = CGAL::make_mesh_3(*p_domain, criteria); p_new_item->set_scene(scene); + std::cerr << "done (" << timer.time() << " ms, " + << p_new_item->c3t3().triangulation().number_of_vertices() << " vertices)" + << std::endl; + + if (p_new_item->c3t3().triangulation().number_of_vertices() > 0) + { + const Scene_item::Bbox& bbox = p_new_item->bbox(); + p_new_item->setPosition((float)(bbox.xmin + bbox.xmax) / 2.f, + (float)(bbox.ymin + bbox.ymax) / 2.f, + (float)(bbox.zmin + bbox.zmax) / 2.f); + return p_new_item; + } + else { + delete p_new_item; + return 0; + } +} +#endif // CGAL_MESH_3_DEMO_ACTIVATE_IMPLICIT_FUNCTIONS + + +#ifdef CGAL_MESH_3_DEMO_ACTIVATE_SEGMENTED_IMAGES + +Scene_item* cgal_code_mesh_3(const Image* pImage, + const double facet_angle, + const double facet_sizing, + const double facet_approx, + const double tet_sizing, + const double tet_shape, + CGAL::Three::Scene_interface* scene) +{ + typedef Mesh_function Mesh_function; + + if (NULL == pImage) { return NULL; } + + Image_mesh_domain* p_domain + = new Image_mesh_domain(*pImage, 1e-6); + + Mesh_parameters param; + param.protect_features = false; + 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; + + Scene_c3t3_item* p_new_item = new Scene_c3t3_item(); + Mesh_function* p_mesh_function + = new Mesh_function(p_new_item->c3t3(), p_domain, param); + + // Set mesh criteria + Edge_criteria edge_criteria(facet_sizing); + Facet_criteria facet_criteria(facet_angle, facet_sizing, facet_approx); // angle, size, approximation + Cell_criteria cell_criteria(tet_shape, tet_sizing); // radius-edge ratio, size + Mesh_criteria criteria(edge_criteria, facet_criteria, cell_criteria); + + // return new Meshing_thread(p_mesh_function, p_new_item); + + CGAL::Timer timer; + p_new_item->c3t3() = CGAL::make_mesh_3(*p_domain, criteria); + p_new_item->set_scene(scene); + std::cerr << "done (" << timer.time() << " ms, " << p_new_item->c3t3().triangulation().number_of_vertices() << " vertices)" << std::endl; @@ -158,7 +214,7 @@ Scene_item* cgal_code_mesh_3(const Implicit_function_interface* pfunction, } -#endif // CGAL_MESH_3_DEMO_ACTIVATE_IMPLICIT_FUNCTIONS +#endif //CGAL_MESH_3_DEMO_ACTIVATE_SEGMENTED_IMAGES #include "Polyhedron_demo_mesh_3_plugin_cgal_code.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene_segmented_image_item.h b/Polyhedron/demo/Polyhedron/Scene_segmented_image_item.h index 7ceb462633f..56afe4f163b 100644 --- a/Polyhedron/demo/Polyhedron/Scene_segmented_image_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_segmented_image_item.h @@ -2,7 +2,6 @@ #define SCENE_SEGMENTED_IMAGE_ITEM_H #include "Scene_item.h" -#include #include "Image_type_fwd.h" #include "Scene_segmented_image_item_config.h" #include @@ -10,7 +9,10 @@ #include #include #include + +#include #include + typedef CGAL::Image_3 Image; using namespace CGAL::Three; class SCENE_SEGMENTED_IMAGE_ITEM_EXPORT Scene_segmented_image_item @@ -32,17 +34,20 @@ public: virtual bool supportsRenderingMode(RenderingMode m) const; // draw - virtual void direct_draw(Viewer_interface* viewer) const { draw(viewer); } - virtual void direct_draw_edges(Viewer_interface* viewer) const { draw_edges(viewer); } - virtual void draw(Viewer_interface*) const; - virtual void draw_edges(Viewer_interface* viewer) const { draw_gl(viewer); } + virtual void direct_draw(CGAL::Three::Viewer_interface* viewer) const + { draw(viewer); } + virtual void direct_draw_edges(CGAL::Three::Viewer_interface* viewer) const + { draw_edges(viewer); } + virtual void draw(CGAL::Three::Viewer_interface*) const; + virtual void draw_edges(CGAL::Three::Viewer_interface* viewer) const + { draw_gl(viewer); } virtual QString toolTip() const; const Image* image() const { return m_image; } private: - void draw_gl(Viewer_interface* viewer) const; + void draw_gl(CGAL::Three::Viewer_interface* viewer) const; void initialize_buffers(); GLint ibo_size() const; @@ -73,7 +78,7 @@ private: mutable QOpenGLVertexArrayObject vao[vaoSize]; mutable QOpenGLShaderProgram rendering_program; void draw_bbox(); - void attrib_buffers(Viewer_interface*) const; + void attrib_buffers(CGAL::Three::Viewer_interface*) const; void compile_shaders(); void draw_Bbox(Bbox bbox, std::vector *vertices); public Q_SLOTS: diff --git a/Polyhedron/demo/Polyhedron/config_mesh_3.h b/Polyhedron/demo/Polyhedron/config_mesh_3.h index 1a84684f444..4443b3b6368 100644 --- a/Polyhedron/demo/Polyhedron/config_mesh_3.h +++ b/Polyhedron/demo/Polyhedron/config_mesh_3.h @@ -34,8 +34,7 @@ //#define CGAL_MESH_3_DEMO_ACTIVATE_SHARP_FEATURES_IN_POLYHEDRAL_DOMAIN #ifndef CGAL_MESH_3_DEMO_ACTIVATE_SHARP_FEATURES_IN_POLYHEDRAL_DOMAIN # define CGAL_MESH_3_DEMO_ACTIVATE_IMPLICIT_FUNCTIONS -//# define CGAL_MESH_3_DEMO_ACTIVATE_SEGMENTED_IMAGES - +# define CGAL_MESH_3_DEMO_ACTIVATE_SEGMENTED_IMAGES #endif //#define CGAL_MESH_3_DEMO_DONT_COUNT_TETS_ADJACENT_TO_SHARP_FEATURES_FOR_HISTOGRAM