mirror of https://github.com/CGAL/cgal
add meshing of segmented images
This commit is contained in:
parent
8ad83f7597
commit
adf5c63fb2
|
|
@ -31,7 +31,7 @@
|
|||
#include <CGAL/Random.h>
|
||||
#include <CGAL/Labeled_mesh_domain_3.h>
|
||||
#include <CGAL/Mesh_3/Image_to_labeled_function_wrapper.h>
|
||||
|
||||
#include <CGAL/Bbox_3.h>
|
||||
|
||||
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() {}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,9 +44,7 @@ typedef CGAL::Triangle_accessor_3<Polyhedron, Kernel> 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<int,int>
|
||||
// The last `Tag_true` says the Patch_id type will be int, and not pair<int, int>
|
||||
|
||||
#ifdef CGAL_MESH_3_DEMO_ACTIVATE_SEGMENTED_IMAGES
|
||||
typedef CGAL::Labeled_image_mesh_domain_3<Image,Kernel> Image_domain;
|
||||
|
|
|
|||
|
|
@ -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 )
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef IMAGE_TYPE_H
|
||||
#define IMAGE_TYPE_H
|
||||
|
||||
#include <CGAL/Image_3.h>
|
||||
|
||||
typedef CGAL::Image_3 Image;
|
||||
|
||||
#endif // IMAGE_TYPE_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
|
||||
|
|
@ -27,6 +27,8 @@
|
|||
#define CGAL_POLYHEDRON_DEMO_LABELED_MESH_DOMAIN_3_H
|
||||
|
||||
#include <CGAL/Labeled_mesh_domain_3.h>
|
||||
#include <CGAL/Random.h>
|
||||
#include "Image_type.h"
|
||||
|
||||
#include <boost/type_traits.hpp>
|
||||
|
||||
|
|
@ -36,7 +38,7 @@ namespace CGAL {
|
|||
* \class Polyhedron_demo_labeled_mesh_domain_3
|
||||
* LabeledDomain must be a Labeled_mesh_domain_3
|
||||
*/
|
||||
template<class LabeledDomain>
|
||||
template<class LabeledDomain, class Image = CGAL::Image_3>
|
||||
class Polyhedron_demo_labeled_mesh_domain_3
|
||||
: public LabeledDomain
|
||||
{
|
||||
|
|
@ -64,14 +66,6 @@ public:
|
|||
typedef CGAL::cpp11::tuple<Point_3, Index, int> 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)
|
||||
{}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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_implicit_function_item*>(scene->item(index));
|
||||
#endif
|
||||
#ifdef CGAL_MESH_3_DEMO_ACTIVATE_SEGMENTED_IMAGES
|
||||
Scene_segmented_image_item* image_item =
|
||||
qobject_cast<Scene_segmented_image_item*>(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<Scene_c3t3_item*>(temp_item);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,18 @@
|
|||
#include "config_mesh_3.h"
|
||||
|
||||
#include <CGAL/AABB_intersections.h>
|
||||
#include <CGAL/AABB_tree.h>
|
||||
|
||||
#include <CGAL/Mesh_criteria_3.h>
|
||||
#include <CGAL/make_mesh_3.h>
|
||||
#include <CGAL/Bbox_3.h>
|
||||
|
||||
#include <Polyhedron_type.h>
|
||||
#include <C3t3_type.h>
|
||||
|
||||
#include <Scene_polyhedron_item.h>
|
||||
#include <Scene_polygon_soup_item.h>
|
||||
#include <Scene_c3t3_item.h>
|
||||
#include <Scene_item.h>
|
||||
|
||||
#include "Mesh_function.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include <CGAL/Timer.h>
|
||||
|
||||
|
|
@ -139,6 +134,67 @@ Scene_item* cgal_code_mesh_3(const Implicit_function_interface* pfunction,
|
|||
p_new_item->c3t3() = CGAL::make_mesh_3<C3t3>(*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<Image_mesh_domain> 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<C3t3>(*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"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
#define SCENE_SEGMENTED_IMAGE_ITEM_H
|
||||
|
||||
#include "Scene_item.h"
|
||||
#include <CGAL/Three/Scene_interface.h>
|
||||
#include "Image_type_fwd.h"
|
||||
#include "Scene_segmented_image_item_config.h"
|
||||
#include <CGAL/gl.h>
|
||||
|
|
@ -10,7 +9,10 @@
|
|||
#include <QOpenGLVertexArrayObject>
|
||||
#include <QOpenGLBuffer>
|
||||
#include <QOpenGLShaderProgram>
|
||||
|
||||
#include <CGAL/Three/Scene_interface.h>
|
||||
#include <CGAL/Three/Viewer_interface.h>
|
||||
|
||||
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<float> *vertices);
|
||||
public Q_SLOTS:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue