Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] Surface mesh from a labelled image

Subject: CGAL users discussion list

List archive

[cgal-discuss] Surface mesh from a labelled image


Chronological Thread 
  • From: Ramón Casero Cañas <>
  • To:
  • Subject: [cgal-discuss] Surface mesh from a labelled image
  • Date: Tue, 24 Sep 2013 12:01:01 +0100

Dear all,

I'm trying to mesh a segmentation (labelled image). So far I've been trying with the "3D Surface Mesh Generation" package.

http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Surface_mesher/Chapter_main.html

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_mesher
typedef CGAL::Surface_mesh_default_triangulation_3 Tr;

// c2t3
typedef CGAL::Complex_2_in_triangulation_3<Tr> C2t3;

// labelled image
typedef 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 meshed
  Mesh_domain domain(im);

  // definition of the surface, with 10^-5 as relative precision
  Surface_3 surface(domain, bounding_sphere, 1e-5);

  Tr tr;            // 3D-Delaunay triangulation
  C2t3 c2t3 (tr);   // 2D-complex in 3D-Delaunay triangulation

  // Mesh criteria
  CGAL::Surface_mesh_default_criteria_3<Tr> criteria(30.,
                                                     5.,
                                                     5.);

  // Meshing
  CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Manifold_tag());

  // Output
  std::ofstream medit_file("/tmp/out.mesh");
  c2t3.output_to_medit(medit_file);

}


But I get a compilation error in line

Surface_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/


  • [cgal-discuss] Surface mesh from a labelled image, Ramón Casero Cañas, 09/24/2013

Archive powered by MHonArc 2.6.18.

Top of Page