Problem with crossing tubes

Hi everyone!

I want to make a tube model with MarkupsToModel Module but I have 2 segments pretty close each other:

If I look to Red Slice, it shows something strange:

I´ve clipped the tube model with Green Slice Plane and this is the result:

Is there any way to fix it to get just a solid model? I´ve tried Surface Toolbox but I can´t get a solid model.

Thanks in advance!

This is a solid model. Every surface mesh will look empty inside if you cut them.

The model is self-intersecting, which may cause problems. There is no universal solution for this, but if you describe you high-level goals (what you would like to model with these curves, for what clinical application) then we can suggest specific solutions.

Of course, I put some fiducials over a bone model and make a tube model to be cutted with the bone. Sometimes direction changes are very closed and I have this kind of problem. As you can imagine, the cut operation is failed.
I send the model to segmentation and make a “fill holes” and export it again as model, but it is a time consuming workflow…

What is the clinical application? Would you like to simulate superficial grinding of the bone? Or you would like to cut out a surface patch of the bone? Or you would like to create a 3D és surgical guide?

It is for surgical guides. I want to cut the tube with the bone surface.

Probably the simplest is to use the Segment Editor for this. You can draw tubes directly on the 3D view using Paint effect by enabling “Edit in 3D view” option.

There are of course many other options, depending on exactly what kind of surgical guides you want to create. See for example the sophisticated module for automatic surgical guide generation for mandible reconstruction by @mau_igna_06 that uses a combination of markups and Segment Editor and Combine models module.

If you can draw a sketch of how you would like your surgical guide to look like then we can give more specific advice.

1 Like

Segment Editor, in my hands, used to have a low resolutions outputs for most input CT´s or a need to 2x-3x oversampling with logaritmic increase of memory and computations loads. What I look for is to manage this issue with models because resolution outputs are, again in my hands, better.
I think it should be intersting for many other porposes to add any kind of tool to Surfafe ToolBox to fix the intersecting faces problem in models, even for imported ones…
Looking for bibliography about it, I´ve found this paper:
https://doi.org/10.1016/j.gmod.2014.09.002
It should be possible to develop something like this with vtk? Try to forgive my ignorance, please.

Thanks again

In most cases, you can use the segment editor to get accurate anatomical surfaces without significant increase in memory size. You can crop the volume to minimal size and resample with isotropic spacing, which typically does not increase the volume size. You only need to apply further oversampling in rare cases: if you want to segment thin anatomical membranes, which are not visible in the image, just the user knows they are there.

Once you have the anatomical surface, you can use that to create a surgical guide by converting it to a shell (using Hollow effect) and crop it to the region that will be surgically exposed; and then combine it with CAD models or cut tool guidance holes or slots into it using “Combine models” module. This approach is implemented in a fully automated way in BoneReconstructionPlanner extension that I referenced above.

You are much better off avoiding generating invalid meshes than trying to fix them later. However, if you want to use a mesh fixing algorithm then you can.

The mesh fixing algorithm that you have found has a reference paper that collected 177 citations in 11 years, which is not much. This may suggest that the method does not work well and/or it may just reflect that people are reluctant to try it because of the very restrictive license (GPL license + no commercial use is explicitly prohibited). This license makes it impossible to integrate it into other libraries, such as VTK. However, you can give it a try using PyVista, which is a Pythonic interface for VTK with a few small additions, such as this pymeshfix package.

1 Like

PyMeshFix looks the way I´m looking for:
With pymeshfix.clean_from_file(“inputFile”,“outputFile”) I can get a model file to import like this:


I tried also this code:

import pymeshfix as mf
import pyvista as pv
model = getNode(“Model”)
pd = model.GetPolyData()
mesh = pv.PolyData(pd)
meshfix = mf.MeshFix(mesh)
meshfix.repair()
repaired = meshfix.mesh

But I can´t update model polidata with the repaired mesh because it is a Polydata not a vtkPolyData.
How can I do it?

Thanks

If you cannot get the vtkPolyData from that pyvista Polydata object then you can write it to a file and read that file into Slicer.

1 Like

Hi @lassoan,
I use pymeshfix in script with no problem but if I add “import pymeshfix” to a scripted module, Python interactor send me constinously this kind of error:

Input port 0 of algorithm vtkTubeFilter(0000017C8ADE3EF0) has 0 connections but is not optional.

Import lines in modules:

try:
  import pymeshfix
except ModuleNotFoundError as e:
  #if slicer.util.confirmOkCancelDisplay("This module requires 'pymeshfix' Python package. Click OK to install it now."):
  slicer.util.pip_install("pymeshfix")
  import pymeshfix

Any idea why is it?
Thanks in advance…

It means that a VTK tube filter is used somewhere and its input is not set. If you don’t create such a tube filter then you can probably ignore this error for now.

Recently, I had meet the same problem. And the clinical application is to make tube structure more realistic, e.g. pulmonary bronchi, artery-vein. Segmentation(lots of manual and CT quaility effects) from CT was hard to reconstuct smooth and tube-like structure mesh used for measures, so i try to use vtkTubeFilter to fit the mesh, but the bronchi and artery-vein has many bifurcation, then two tube mesh has self-intersecting in the bifurcation. Is there any way to solve this? Or is there other way to simulate a mesh to a smooth tube-like mesh?

Hi, I can’t use pymeshfix to merge two self-intersection mesh to one like yours, can you provide the src stl file for me to test if there some problen in my pymeshfix?

If you have trouble fixing up the tube filter output then you can use the curve as input of a vtkImplicitModeler. That filter is guaranteed to produce a solid tube.

1 Like

i see the examples of vtkImplicitModeler, it seems the tube simulation of tube-like structure, e.g. vessel and bronchi. But i didn’t find more examples about the function, can it produce the different tube with different distance between the line? How to implement this effects?

If you need varying radius then your can apply a tube filter with a smaller radius (subtracting a constant value) and then inflate it with the implicit modeler (using the value that was subtracted as distance value). If the radius varies in a large range then you may need to append multiple tubes (smaller tubes using the same centerline) to make sure large-diameter tube sections are filled by the implicit modeler.

Thanks for your quick apply. Before this, i using tube filter with various radius and increase a sphere(blue) to fit tube-like structure(red).

. But the problem described in the post occurs, the self-intersection tube looks very ugly and abnoraml. So next i will try the method you seggested with vtkImplicitModeler. Hope to solve the problem and get smooth tube simulation to the origin mesh(red).

Implicit modeler fixes the self-intersections. You need to balance between resolution of the internal labelmap resolution of the implicit modeler and accuracy of the output. If you have a model with a large bounding box and you want very high accuracy (e.g., you have very thin vessels) then the internal labelmap will be very large (many voxels) so you may need dozens of GB of memory and computation will be very slow.

If this issue prevents you from getting the model you need, then there is one more approach you can try: use vtkbool library. It is available in Slicer Preview Releases via Combine Models module, in Sandbox extension. You can combine sphere-terminated tube segments using mesh Boolean operators. It is of course many magnitudes slower than a simple tube filter, so you might want to detect sharp bends and only use Boolean operations there, and use simple tube filter elsewhere.

Okay, Thanks! I will try the method you suggented. BTW, i think this is a great good in mesh simulation in medical domain to solve the resolution and manual segmentation error in CT. Is there any feature development work about this?