Subject: CGAL users discussion list
List archive
- From: Ramón Casero Cañas <>
- To:
- Subject: Re: [cgal-discuss] Surface mesh from a labelled image
- Date: Mon, 30 Sep 2013 23:10:50 +0100
Replying to myself, I had got confused, as the CGAL::Labeled_image_mesh_domain_3 is for volumetric meshes, not surfaces meshes.
In the end, I managed to make it work following the example more closely, with a CGAL::Gray_level_image_3 and CGAL::Implicit_surface_3.
The code is here in case it's useful for somebody else (it's a Matlab MEX wrapper around CGAL::make_surface_mesh)
Cheers,
Ramon.
On 24 September 2013 12:01, Ramón Casero Cañas <> wrote:
Dear all,I'm trying to mesh a segmentation (labelled image). So far I've been trying with the "3D Surface Mesh Generation" package.I haven't found an example for this online, so I'm trying to adapt "Example 48.3.2 Meshing Isosurfaces Defined as Gray Levels in 3D Images" to labelled images, but I'm shooting a bit in the dark.As my image lives in Matlab memory, I have written a function to get the pointer and metainformation into a CGAL _image struct.// get Matlab image pointer and metadata in CGAL format_image *im = matlabImport->ReadCgalImageFromMatlab(inIM);Otherwise, I'm trying to stick to the example, replacing the gray image by a labelled image, but I'm doing something wrong. The parts of my code that are relevant to CGAL are:/* CGAL headers */#include <CGAL/Surface_mesh_default_triangulation_3.h>#include <CGAL/Surface_mesh_default_criteria_3.h>#include <CGAL/Complex_2_in_triangulation_3.h>#include <CGAL/IO/Complex_2_in_triangulation_3_file_writer.h>#include <CGAL/make_surface_mesh.h>//#include <CGAL/Gray_level_image_3.h>#include <CGAL/Labeled_image_mesh_domain_3.h>#include <CGAL/Implicit_surface_3.h>#include <CGAL/ImageIO.h>#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>// default triangulation for Surface_meshertypedef CGAL::Surface_mesh_default_triangulation_3 Tr;// c2t3typedef CGAL::Complex_2_in_triangulation_3<Tr> C2t3;// labelled imagetypedef Tr::Geom_traits GT;//typedef CGAL::Gray_level_image_3<GT::FT, GT::Point_3> Gray_level_image;typedef CGAL::Exact_predicates_inexact_constructions_kernel K;typedef CGAL::Labeled_image_mesh_domain_3<CGAL::Image_3, K> Mesh_domain;typedef CGAL::Implicit_surface_3<GT, Mesh_domain> Surface_3;void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {// some Matlab stuff...// get Matlab image pointer and metadata in CGAL format_image *im = matlabImport->ReadCgalImageFromMatlab(inIM);// Carefully choosen bounding sphere: the center must be inside the// surface defined by 'image' and the radius must be high enough so that// the sphere actually bounds the whole image.GT::Point_3 bounding_sphere_center(2.0, 2.0, 2.0);GT::FT bounding_sphere_squared_radius = 5.0*5.0*5.0;GT::Sphere_3 bounding_sphere(bounding_sphere_center,bounding_sphere_squared_radius);// say that the input image is a labeled segmentation that is going// to be meshedMesh_domain domain(im);// definition of the surface, with 10^-5 as relative precisionSurface_3 surface(domain, bounding_sphere, 1e-5);Tr tr; // 3D-Delaunay triangulationC2t3 c2t3 (tr); // 2D-complex in 3D-Delaunay triangulation// Mesh criteriaCGAL::Surface_mesh_default_criteria_3<Tr> criteria(30.,5.,5.);// MeshingCGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Manifold_tag());// Outputstd::ofstream medit_file("/tmp/out.mesh");c2t3.output_to_medit(medit_file);}But I get a compilation error in lineSurface_3 surface(domain, bounding_sphere, 1e-5);/home/rcasero/Documents/gerardus/cpp/src/third-party/CGAL-4.2/include/CGAL/Labeled_image_mesh_domain_3.h: In function ‘void mexFunction(int, mxArray**, int, const mxArray**)’:/home/rcasero/Documents/gerardus/cpp/src/third-party/CGAL-4.2/include/CGAL/Labeled_image_mesh_domain_3.h:79: error: ‘CGAL::Labeled_image_mesh_domain_3<Image, BGT, Wrapper>::Labeled_image_mesh_domain_3(const CGAL::Labeled_image_mesh_domain_3<Image, BGT, CGAL::Mesh_3::Image_to_labeled_function_wrapper<Image, BGT, unsigned char, int, true> >&) [with Image = CGAL::Image_3, BGT = CGAL::Epick, Wrapper = CGAL::Mesh_3::Image_to_labeled_function_wrapper<CGAL::Image_3, CGAL::Epick, unsigned char, int, true>]’ is private/home/rcasero/Documents/gerardus/matlab/CgalToolbox/CgalMeshSegmentation.cpp:92: error: within this context/home/rcasero/Documents/gerardus/matlab/CgalToolbox/CgalMeshSegmentation.cpp:92: error: initializing argument 1 of ‘CGAL::Implicit_surface_3<GT, Function_>::Implicit_surface_3(Function_, typename GT::Sphere_3, typename GT::FT, GT) [with GT = CGAL::Robust_circumcenter_traits_3<CGAL::Epick>, Function_ = CGAL::Labeled_image_mesh_domain_3<CGAL::Image_3, CGAL::Epick, CGAL::Mesh_3::Image_to_labeled_function_wrapper<CGAL::Image_3, CGAL::Epick, unsigned char, int, true> >]’/home/rcasero/Documents/gerardus/matlab/CgalToolbox/CgalMeshSegmentation.cpp:108: error: ‘class C2t3’ has no member named ‘output_to_medit’[...other errors edited out...]
As I'm not too sure of what I'm doing, any examples or indications on how to tackle this would be welcome.Best regards,Ramon.--
Dr. Ramón Casero Cañas
Oxford e-Research Centre (OeRC)
University of Oxford
7 Keble Rd
Oxford OX1 3QG
tlf +44 (0) 1865 610739
web http://www.cs.ox.ac.uk/people/Ramon.CaseroCanas
photos http://www.flickr.com/photos/rcasero/
Dr. Ramón Casero Cañas
Oxford e-Research Centre (OeRC)
University of Oxford
7 Keble Rd
Oxford OX1 3QG
tlf +44 (0) 1865 610739
web http://www.cs.ox.ac.uk/people/Ramon.CaseroCanas
photos http://www.flickr.com/photos/rcasero/
- Re: [cgal-discuss] Surface mesh from a labelled image, Ramón Casero Cañas, 10/01/2013
- Re: [cgal-discuss] Surface mesh from a labelled image, Laurent Rineau (CGAL/GeometryFactory), 10/01/2013
Archive powered by MHonArc 2.6.18.