Quantcast

CGAL Problem when generating mesh (make_mesh_3) from segmented 3d image

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

CGAL Problem when generating mesh (make_mesh_3) from segmented 3d image

gori23
Hi all,

I hope somebody can help me with my problem(s)

I am trying to extract the surfaces of the domains from a segmented 3d image. So my input is a 3d voxel image (e.g. the liver_gallbladder inr image). Then my plan was to run make_mesh_3 and to extract the surfaces.

I've ran into the following problems:
Somehow it only works when I open the inr file from a folder, like in the examples on the CGAL manual pages:
  // Loads image
  CGAL::Image_3 image;
  image.read("data/liver.inr.gz");

I tried to generate the Image_3 by myself using sth like this
_image* im = ::_initImage();
im->vectMode = VM_SCALAR;
im->xdim = xdim;
im->ydim = ydim;
im->zdim = zdim;
im->vdim = 1;
im->vx = vxSize.x();
im->vy = vxSize.y();
im->vz = vxSize.z();
im->endianness = ::_getEndianness();
im->wdim = sizeof(uint8_t);
im->wordKind = WK_FIXED;
im->sign = SGN_SIGNED;
im->data = volumearray;

(volumearray a pointer to the data array)
However, using my code the program gets stuck in make_mesh_3 without further output or termination.

The second problem occurs later at the stage where I want to extract the surface of the domains. So my aim is to get the CGAL tetrahedrization, to throw away the tetrahedra and to keep only the surface triangles.
I tried different approaches (e.g. to loop through all facets, getting the facets surface patch index (C3t3::Surface_patch_index sp = c3t3.surface_patch_index(f);) and generating my surface mesh from these vertices/triangles.
However, the result seems wrong/incomplete. In general it seems ok (as in it resembles the surface of a domain), but there are holes in the mesh, missing walls between domains and different domains have vertices/triangles that dont match their neighbours (intersecting triangles).

Maybe somebody can give me a hint here on how to extract the information.
If something is not clear or you need more of my code, let me know.

Cheers,
gori23

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CGAL Problem when generating mesh (make_mesh_3) from segmented 3d image

Padraig O Conbhui
Hi gori23,

One approach I took for this was to iterate through the facets, find the cell it belonged to (facet_handle->first), and the subdomain id (cell_handle->subdomain_id() maybe or c3t3.subdomain_id(cell_handle)) then find the adjacent cell tr3.mirror_facet(facet_handle).first) and again the subdomain id. Check the subdomain index of the two cells, and if they differ, the facet is on an interface.

I was just doing this to get stats on the surface meshes, so I wasn't worried about connectivity etc, so I have no idea about that.

Regards,
Paddy

On Mon, Nov 23, 2015 at 2:02 PM, gori23 <[hidden email]> wrote:
Hi all,

I hope somebody can help me with my problem(s)

I am trying to extract the surfaces of the domains from a segmented 3d
image. So my input is a 3d voxel image (e.g. the liver_gallbladder inr
image). Then my plan was to run make_mesh_3 and to extract the surfaces.

I've ran into the following problems:
Somehow it only works when I open the inr file from a folder, like in the
examples on the CGAL manual pages:
  // Loads image
  CGAL::Image_3 image;
  image.read("data/liver.inr.gz");

I tried to generate the Image_3 by myself using sth like this
_image* im = ::_initImage();
im->vectMode = VM_SCALAR;
im->xdim = xdim;
im->ydim = ydim;
im->zdim = zdim;
im->vdim = 1;
im->vx = vxSize.x();
im->vy = vxSize.y();
im->vz = vxSize.z();
im->endianness = ::_getEndianness();
im->wdim = sizeof(uint8_t);
im->wordKind = WK_FIXED;
im->sign = SGN_SIGNED;
im->data = volumearray;

(volumearray a pointer to the data array)
However, using my code the program gets stuck in make_mesh_3 without further
output or termination.

The second problem occurs later at the stage where I want to extract the
surface of the domains. So my aim is to get the CGAL tetrahedrization, to
throw away the tetrahedra and to keep only the surface triangles.
I tried different approaches (e.g. to loop through all facets, getting the
facets surface patch index (C3t3::Surface_patch_index sp =
c3t3.surface_patch_index(f);) and generating my surface mesh from these
vertices/triangles.
However, the result seems wrong/incomplete. In general it seems ok (as in it
resembles the surface of a domain), but there are holes in the mesh, missing
walls between domains and different domains have vertices/triangles that
dont match their neighbours (intersecting triangles).

Maybe somebody can give me a hint here on how to extract the information.
If something is not clear or you need more of my code, let me know.

Cheers,
gori23





--
View this message in context: http://cgal-discuss.949826.n4.nabble.com/CGAL-Problem-when-generating-mesh-make-mesh-3-from-segmented-3d-image-tp4661387.html
Sent from the cgal-discuss mailing list archive at Nabble.com.

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CGAL Problem when generating mesh (make_mesh_3) from segmented 3d image

gori23
Hi Padraig,

Thanks for your reply.
It actually pointed me towards the right solution. Here is what I do now:

for (Tr::All_facets_iterator it=t.all_facets_begin(); it != t.all_facets_end(); ++it) // loop through facets
{
  Tr::Facet f(*it);
  C3t3::Surface_patch_index sp = c3t3.surface_patch_index(f);

// now sp.first/second contain information to which domains the facets belongs (on both sides)

// now get the vertices of the facet and add the triangle to the belonging cells
...
}

This generally works well, however occasionally I get malformed regions, where there is 1 or 2 triangles too many, so that the domain cant be closed proplerly. Another problem is that the orientation of the triangles seems to be random. is there a way to get oriented tris from CGAL?
And finally I haven't solved the first problem (of the inital posting) yet, I can only open 3d data from files.

Thanks a lot.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CGAL Problem when generating mesh (make_mesh_3) from segmented 3d image

gori23
Hi,

I recently came back to this project (which I didn't continue due to above problem).

I now also tried the example code of the random_labeled_image.
(http://doc.cgal.org/latest/Mesh_3/Mesh_3_2random_labeled_image_8h-example.html)

But whatever setting or method I'm using to create or fill the Image_3 object my program always gets stuck (it doesn't get past this line) at make_mesh_3.

To give you a bit more code:

  // here I tried to create an empty image, but as written above I tried many different things to get an Image_3 object, empty or filled
  _image* image11 = _createImage(dim, dim, dim, 1, 1.f, 1.f, 1.f, 1, WK_FIXED, SGN_UNSIGNED);
  unsigned char* ptr = (unsigned char*)(image11->data);
  std::fill(ptr, ptr+dim*dim*dim, '\0');
  CGAL::Image_3 im11(image11);

  // set it as domain
  Mesh_domain domain(im11);

  // create the mesh
  cout << "now make mesh" << endl;
  C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria, no_perturb(), no_exude(), odt());
  cout << "CGAL mesh" << endl;


There is one thing that works (and only this). image.read(filename), with the liver_gallbladder sample file.
However, files generated by random_labelled_image again have that problem and get stuck

Maybe somebody has another idea on what to try? What is so special about the liver_gallbladder file?


Best Regards
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CGAL Problem when generating mesh (make_mesh_3) from segmented 3d image

gori23
Hi all,

I solved above problem with loading the Image_3 data

The trick was changing the size parameter in createImage to 2 bytes
_image* image11 = _createImage(dim, dim, dim, 1, 1.f, 1.f, 1.f, 2, WK_FIXED, SGN_UNSIGNED);

I now sucessfully generated tetrahedral meshes with different domains. I am struggling with extracting just the surface triangles of the domains

this is briefly what I am doing right now after generating the mesh:

    for (Complex_Cell_Iterator it = c3t3.cells_in_complex_begin(); it != c3t3.cells_in_complex_end(); ++it)
    {

      const Tr::Cell c(*it);
      const C3t3::Vertex_handle i1 = c.vertex(0);
      const C3t3::Vertex_handle i2 = c.vertex(1);
      const C3t3::Vertex_handle i3 = c.vertex(2);
      const C3t3::Vertex_handle i4 = c.vertex(3);

     //v1-4 are 3d points with the coordinates of the vertices i1-4
     // addTri adds an opriented triangle to my mesh structure

      if(c.is_facet_on_surface(f4.second)) addTri(v1, v2, v3);
      if(c.is_facet_on_surface(f3.second)) addTri(v1, v2, v4);
      if(c.is_facet_on_surface(f1.second)) addTri(v4, v2, v3);
      if(c.is_facet_on_surface(f2.second)) addTri(v1, v4, v3);
}

now when I run above code without the if(c.is_facet_on_surface) conditions (and simply add all triangles) I get the tetrahedras, already nicely oriented. I had assumed by just getting the surface it also would be oriented, but it isn't like that, the orientations seem to be random.

Is there a better way to extract the surface mesh in a oriented way?

Cheers,
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CGAL Problem when generating mesh (make_mesh_3) from segmented 3d image

Sebastien Loriot (GeometryFactory)
You can try boundary_to_off()
http://doc.cgal.org/latest/Mesh_3/classCGAL_1_1Mesh__complex__3__in__triangulation__3.html#af1d55be1242c37384224de9b235057cd

Sebastien


On 01/19/2017 04:44 PM, gori23 wrote:

> Hi all,
>
> I solved above problem with loading the Image_3 data
>
> The trick was changing the size parameter in createImage to 2 bytes
> _image* image11 = _createImage(dim, dim, dim, 1, 1.f, 1.f, 1.f, 2, WK_FIXED,
> SGN_UNSIGNED);
>
> I now sucessfully generated tetrahedral meshes with different domains. I am
> struggling with extracting just the surface triangles of the domains
>
> this is briefly what I am doing right now after generating the mesh:
>
>     for (Complex_Cell_Iterator it = c3t3.cells_in_complex_begin(); it !=
> c3t3.cells_in_complex_end(); ++it)
>     {
>
>       const Tr::Cell c(*it);
>       const C3t3::Vertex_handle i1 = c.vertex(0);
>       const C3t3::Vertex_handle i2 = c.vertex(1);
>       const C3t3::Vertex_handle i3 = c.vertex(2);
>       const C3t3::Vertex_handle i4 = c.vertex(3);
>
>      //v1-4 are 3d points with the coordinates of the vertices i1-4
>      // addTri adds an opriented triangle to my mesh structure
>
>       if(c.is_facet_on_surface(f4.second)) addTri(v1, v2, v3);
>       if(c.is_facet_on_surface(f3.second)) addTri(v1, v2, v4);
>       if(c.is_facet_on_surface(f1.second)) addTri(v4, v2, v3);
>       if(c.is_facet_on_surface(f2.second)) addTri(v1, v4, v3);
> }
>
> now when I run above code without the if(c.is_facet_on_surface) conditions
> (and simply add all triangles) I get the tetrahedras, already nicely
> oriented. I had assumed by just getting the surface it also would be
> oriented, but it isn't like that, the orientations seem to be random.
>
> Is there a better way to extract the surface mesh in a oriented way?
>
> Cheers,
>
>
>
>
> --
> View this message in context: http://cgal-discuss.949826.n4.nabble.com/CGAL-Problem-when-generating-mesh-make-mesh-3-from-segmented-3d-image-tp4661387p4662475.html
> Sent from the cgal-discuss mailing list archive at Nabble.com.
>


--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss


Loading...