Triangulating a Surface Mesh

Goal:

  • Triangulate a Surface Mesh (vtk unstructured grid) for FEM

Approach:

  • Load .vtk surface mesh in 3DSlicer
  • Convert Model to Segmentation Node
  • Use Segment Mesher + Cleaver Extension to create volumetric mesh
  • Triangulate further with Cleaver
  • Export as .vtk

Difficulties:

  • I right-click my imported .vtk surface mesh node and select “Convert Model to Segmentation Node”. A segmentation node is then created within the subject hierarchy.

  • I then go into Segment Mesher and have my segmentation node selected as the Input Segmentation, and Cleaver as the Meshing Method. When I click Apply an error occurs.
    cap2
    Questions:

  • Did I forget any steps between converting my model to segmentation node and using Segment Mesher? Within the segmentation editor I see empty segmentation

asdasd

So I then clicked Segmentations and then Add Segment to create this, selecting Closed Surface and Fractional Labelmap:

I am just confused if I can segment before creating a volumetric mesh, and I never see any segmentations show up in my render(not sure if they are supposed to)…

Thanks for reporting this. Which Slicer version did you use? Could you try with latest Slicer Preview Release?

This is in version 4.10.2

So this is not an error on my part (this is my first time using Slicer)?
(Also some additional info that might be helpful: that .vtk model is literally just a vtk Tetrahedron)

I have now also tried Preview 4.11.0 and have exactly the same issue. No segments are visible at all.

If there is anything else I can do to solve this please let me know.

I’ve tested this with latest Slicer Preview Release and it worked well. Probably the issue is how you define the segmentation geometry (origin, spacing, axis directions, and extents of the grid where the model is sampled on). Normally you start from the image and then segmentation geometry is already defined, but if you load a model then some generic geometry is created by default, which may not be ideal for meshing, because its extents just as large as the input model and for meshing it is good to have some margin at the boundaries.

First, I would recommend to follow steps of the tutorial to confirm that there are no software issues.

If everything works well the tutorial data then try with your data: load the model as segmentation, define an ROI node (available on the toolbar) that is slightly larger than your model, and use that to define segment geometry (button next to master volume selector in Segment Editor module). If any step is not clear then let me know and I’ll add a few screenshots to make it more clear. You can also upload your model to dropbox/onedrive and post the link here so that I can show how that particular object can be meshed.

1 Like

Thank you for the response, it has helped me get a couple of steps closer.

Here is what I see after I load the model, convert to segmentation, create ROI node, and then use the ROI to define the segment geo (it is now generating a master volume, though Slicer says that the volume is out of frame in the bottom views):

When I then run Segment Mesher on the segmentation I get the same error as before, but a Label Map Volume is created (when I enable view of it nothing seems to show up except its name in the bottom views):

Ignoring Segment Mesher and going straight to using Cleaver Test Mesher extensions, I can run the mesher on my segmentation master volume without error but nothing seems to change at all…

(At one point I was able to get the sides of the cube to render in the bottom views but I cannot recreate it again)

I would appreciate any form of clarification of the steps to go from a simple model(surface mesh) to Cleaver’s output.

I’ve updated the extension so that padding can be automatically added (you don’t need to create a ROI) and made creation of internal labelmap representation more robust. With the update extension you should be able to just load the mesh file as segmentation then go to Segment Mesher module, select an output model, and click Apply.

The updated extension will be available in the Extension manager from Tuesday or you can update SegmentMesher.py file in your installed extension with the new version.

1 Like

Thank you so much for taking the time to update the extension, but unfortunately I get the same error as before.

How I Updated:

C:\Users\MyName\AppData\Roaming\NA-MIC\Extensions-28257\SegmentMesher\lib\Slicer-4.10\qt-scripted-modules

to update SegmentMesher.py. (note: this is the extension folder for my current Slicer version, I deleted the one that was for my preview build I had yesterday)

I have also tried:

  • Deleting the compiled .pyc file right after updating the .py (having Slicer generate an updated .pyc at run-time)
  • Completely reinstalling the extension then updating it once again

Let me know if there are any other small details that will help clarify the issue.

Have you downloaded the file from github - https://github.com/lassoan/SlicerSegmentMesher/blob/master/SegmentMesher/SegmentMesher.py? Do you have self.addLog('Failed to create binary labelmap representation') in line 512?

My file does contain the proper 512. I was just copying the raw code over before, but now I have actually replaced the file and the error persists:

Mesh generation using Cleaver is started in working directory: C:/Users/MeName/AppData/Local/Temp/Slicer/SegmentMesher/20200218_102026_202
Error: 'NoneType' object has no attribute 'GetColorNode'

I have quadruple checked everything as well. I load in the .vtk as a Model, create the segmentation node, and then run Segment Mesher on the seg node (selecting my model as the output model and cleaver as the method (I also have cleaver extension installed)).

Could you attach the log file? (I’m particularly interested in which line number the error occurs and also what additional module paths are defined)

“Error: ‘NoneType’ object has no attribute ‘GetColorNode’” error is used to be logged when for some reason export of segmentation to labelmap failed. But now that error is detected before, in line 512, so I suspect that there may be two versions of the same module included in the “additional module paths”.

If that’s not the issue then maybe it is something related to the input mesh. For that, it would be great if you could test with some other data set (for example, I’ve tested with this prostate gland STL file) and report what you find.

Here is the full error log, I was unaware that it showed more than the small console within the extension’s gui. (your link seems to be a file path from your computer, and does not work)

I guess this means that my model is causing an issue, but as I stated before it is simply a large cube from vtk that I write to a .vtk file using vtkUnstructuredGridWriter.

Sorry, fixed.

Only a tiny fraction of the full log is visible in the screenshot. Please use menu: Help / Report a bug to get log as text. If it’s too long then upload the text to somewhere and post the link here. Thank you!

I see that much as "Failed to import model ‘testCube’ to segmentation. So, the segmentation is probably empty, which explain why do you have this error. Is testCube a surface mesh (vtkPolyData) or already a volumetric mesh (vtkUnstructuredGrid)? It should be a vtkPolyData. We could easily get a surface mesh from a volumetric mesh (just need to apply vtkGeometryFilter), but this has never come up before.

I have now also tried the prostate model, but it too causes an error. One big difference between it and my model is that right when I create the segmentation node it automaticaly creates a segmentation within the node; my model did not do this…


Here is the log from my model:

[DEBUG][Qt] 18.02.2020 10:51:29 [] (unknown:0) - Session start time …: 2020-02-18 10:51:29
[DEBUG][Qt] 18.02.2020 10:51:29 [] (unknown:0) - Slicer version …: 4.10.2 (revision 28257) win-amd64 - installed release
[DEBUG][Qt] 18.02.2020 10:51:29 [] (unknown:0) - Operating system …: Windows / Personal / (Build 9200) - 64-bit
[DEBUG][Qt] 18.02.2020 10:51:29 [] (unknown:0) - Memory …: 16119 MB physical, 18551 MB virtual
[DEBUG][Qt] 18.02.2020 10:51:29 [] (unknown:0) - CPU …: GenuineIntel , 12 cores, 12 logical processors
[DEBUG][Qt] 18.02.2020 10:51:29 [] (unknown:0) - VTK configuration …: OpenGL2 rendering, TBB threading
[DEBUG][Qt] 18.02.2020 10:51:29 [] (unknown:0) - Developer mode enabled …: no
[DEBUG][Qt] 18.02.2020 10:51:29 [] (unknown:0) - Prefer executable CLI …: yes
[DEBUG][Qt] 18.02.2020 10:51:29 [] (unknown:0) - Additional module paths …: C:/Users/thefl/AppData/Roaming/NA-MIC/Extensions-28257/CleaverExtension/lib/Slicer-4.10/cli-modules, C:/Users/thefl/AppData/Roaming/NA-MIC/Extensions-28257/SegmentMesher/lib/Slicer-4.10/qt-scripted-modules
[DEBUG][Python] 18.02.2020 10:51:30 [Python] (C:\Program Files\Slicer 4.10.2\lib\Slicer-4.10\qt-scripted-modules\SubjectHierarchyPlugins\AbstractScriptedSubjectHierarchyPlugin.py:36) - Scripted subject hierarchy plugin registered: Annotations
[DEBUG][Python] 18.02.2020 10:51:31 [Python] (C:\Program Files\Slicer 4.10.2\lib\Slicer-4.10\qt-scripted-modules\SubjectHierarchyPlugins\AbstractScriptedSubjectHierarchyPlugin.py:36) - Scripted subject hierarchy plugin registered: SegmentEditor
[DEBUG][Python] 18.02.2020 10:51:31 [Python] (C:\Program Files\Slicer 4.10.2\lib\Slicer-4.10\qt-scripted-modules\SubjectHierarchyPlugins\AbstractScriptedSubjectHierarchyPlugin.py:36) - Scripted subject hierarchy plugin registered: SegmentStatistics
[DEBUG][Qt] 18.02.2020 10:51:31 [] (unknown:0) - Switch to module: “Data”
[DEBUG][Qt] 18.02.2020 10:52:04 [] (unknown:0) - “Model” Reader has successfully read the file “C:/Users/thefl/Downloads/testCube.vtk” “[0.00s]”
[ERROR][VTK] 18.02.2020 10:52:09 [vtkMRMLSegmentationNode (000001FFF5205210)] (D:\D\S\Slicer-4102\Modules\Loadable\Segmentations\Logic\vtkSlicerSegmentationsModuleLogic.cxx:1171) - ImportModelToSegmentationNode: Invalid model node
[CRITICAL][Qt] 18.02.2020 10:52:09 [] (unknown:0) - void __cdecl qSlicerSubjectHierarchySegmentationsPlugin::convertModelToSegmentation(void) : Failed to import model ’ testCube ’ to segmentation ’ testCube-segmentation ’
[DEBUG][Qt] 18.02.2020 10:52:12 [] (unknown:0) - Switch to module: “SegmentMesher”
[INFO][Python] 18.02.2020 10:52:13 [Python] (C:/Users/thefl/AppData/Roaming/NA-MIC/Extensions-28257/SegmentMesher/lib/Slicer-4.10/qt-scripted-modules/SegmentMesher.py:361) - Mesh generation using Cleaver is started in working directory: C:/Users/thefl/AppData/Local/Temp/Slicer/SegmentMesher/20200218_105213_730
[INFO][Stream] 18.02.2020 10:52:13 [] (unknown:0) - CLEAVER
[INFO][Stream] 18.02.2020 10:52:13 [] (unknown:0) - Mesh generation using Cleaver is started in working directory: C:/Users/thefl/AppData/Local/Temp/Slicer/SegmentMesher/20200218_105213_730
[ERROR][VTK] 18.02.2020 10:52:13 [vtkOrientedImageData (000001FFF51417E0)] (D:\D\S\Slicer-4102\Libs\vtkSegmentationCore\vtkSegmentationConverter.cxx:214) - DeserializeImageGeometry: Failed to de-serialize geometry string
[ERROR][VTK] 18.02.2020 10:52:13 [vtkMRMLSegmentationNode (000001FFF5205210)] (D:\D\S\Slicer-4102\Libs\MRML\Core\vtkMRMLSegmentationNode.cxx:527) - GenerateMergedLabelmap: Segmentation does not contain binary labelmap representation
[ERROR][VTK] 18.02.2020 10:52:13 [vtkMRMLSegmentationNode (000001FFF5205210)] (D:\D\S\Slicer-4102\Modules\Loadable\Segmentations\Logic\vtkSlicerSegmentationsModuleLogic.cxx:1021) - ExportSegmentsToLabelmapNode: Failed to generate merged labelmap
[WARNING][VTK] 18.02.2020 10:52:13 [] (unknown:0) - Generic Warning: In D:\D\S\Slicer-4102\Libs\MRML\Core\vtkDataFileFormatHelper.cxx, line 237
vtkDataFileFormatHelper::GetFileExtensionFromFormatString: please update deprecated extension-only format specifier to ‘File format name (.ext)’ format! Current format string: .nrrd
[ERROR][VTK] 18.02.2020 10:52:13 [vtkITKImageWriter (000001FFF4E805E0)] (D:\D\S\Slicer-4102\Libs\vtkITK\vtkITKImageWriter.cxx:514) - Can only export 1 or 3 component images, current image has 0 components
[ERROR][VTK] 18.02.2020 10:52:13 [vtkMRMLVolumeArchetypeStorageNode (000001FFF2F28CA0)] (D:\D\S\Slicer-4102\Libs\MRML\Core\vtkMRMLVolumeArchetypeStorageNode.cxx:866) - UpdateFileList: the archetype file ‘inputLabelmap.nrrd’ wasn’t written out when writing ‘C:/Users/thefl/AppData/Local/Temp/Slicer/SegmentMesher/20200218_105213_730/TempWriteinputLabelmap/inputLabelmap.nrrd’ in ‘C:/Users/thefl/AppData/Local/Temp/Slicer/SegmentMesher/20200218_105213_730/TempWriteinputLabelmap’. Only those 0 file(s) have been written: . Old name is ‘C:/Users/thefl/AppData/Local/Temp/Slicer/SegmentMesher/20200218_105213_730\inputLabelmap.nrrd’.
[WARNING][VTK] 18.02.2020 10:52:13 [] (unknown:0) - Generic Warning: In D:\D\S\Slicer-4102\Libs\MRML\Core\vtkDataFileFormatHelper.cxx, line 237
vtkDataFileFormatHelper::GetFileExtensionFromFormatString: please update deprecated extension-only format specifier to ‘File format name (.ext)’ format! Current format string: .nrrd
[ERROR][VTK] 18.02.2020 10:52:13 [vtkITKImageWriter (000001FFF4E80ED0)] (D:\D\S\Slicer-4102\Libs\vtkITK\vtkITKImageWriter.cxx:514) - Can only export 1 or 3 component images, current image has 0 components
[INFO][Stream] 18.02.2020 10:52:13 [] (unknown:0) - ‘NoneType’ object has no attribute ‘GetColorNode’
[CRITICAL][Stream] 18.02.2020 10:52:13 [] (unknown:0) - Traceback (most recent call last):
[CRITICAL][Stream] 18.02.2020 10:52:13 [] (unknown:0) - File “C:/Users/thefl/AppData/Roaming/NA-MIC/Extensions-28257/SegmentMesher/lib/Slicer-4.10/qt-scripted-modules/SegmentMesher.py”, line 296, in onApplyButton
[CRITICAL][Stream] 18.02.2020 10:52:13 [] (unknown:0) - self.cleaverPaddingPercentSpinBox.value * 0.01)
[CRITICAL][Stream] 18.02.2020 10:52:13 [] (unknown:0) - File “C:/Users/thefl/AppData/Roaming/NA-MIC/Extensions-28257/SegmentMesher/lib/Slicer-4.10/qt-scripted-modules/SegmentMesher.py”, line 548, in createMeshFromSegmentationCleaver
[CRITICAL][Stream] 18.02.2020 10:52:13 [] (unknown:0) - colorTableNode = labelmapVolumeNode.GetDisplayNode().GetColorNode()
[CRITICAL][Stream] 18.02.2020 10:52:13 [] (unknown:0) - AttributeError: ‘NoneType’ object has no attribute ‘GetColorNode’


Here is the prostate model’s log:

[DEBUG][Qt] 18.02.2020 10:55:15 [] (unknown:0) - Session start time …: 2020-02-18 10:55:15
[DEBUG][Qt] 18.02.2020 10:55:15 [] (unknown:0) - Slicer version …: 4.10.2 (revision 28257) win-amd64 - installed release
[DEBUG][Qt] 18.02.2020 10:55:15 [] (unknown:0) - Operating system …: Windows / Personal / (Build 9200) - 64-bit
[DEBUG][Qt] 18.02.2020 10:55:15 [] (unknown:0) - Memory …: 16119 MB physical, 18551 MB virtual
[DEBUG][Qt] 18.02.2020 10:55:15 [] (unknown:0) - CPU …: GenuineIntel , 12 cores, 12 logical processors
[DEBUG][Qt] 18.02.2020 10:55:15 [] (unknown:0) - VTK configuration …: OpenGL2 rendering, TBB threading
[DEBUG][Qt] 18.02.2020 10:55:15 [] (unknown:0) - Developer mode enabled …: no
[DEBUG][Qt] 18.02.2020 10:55:15 [] (unknown:0) - Prefer executable CLI …: yes
[DEBUG][Qt] 18.02.2020 10:55:15 [] (unknown:0) - Additional module paths …: C:/Users/thefl/AppData/Roaming/NA-MIC/Extensions-28257/CleaverExtension/lib/Slicer-4.10/cli-modules, C:/Users/thefl/AppData/Roaming/NA-MIC/Extensions-28257/SegmentMesher/lib/Slicer-4.10/qt-scripted-modules
[DEBUG][Python] 18.02.2020 10:55:17 [Python] (C:\Program Files\Slicer 4.10.2\lib\Slicer-4.10\qt-scripted-modules\SubjectHierarchyPlugins\AbstractScriptedSubjectHierarchyPlugin.py:36) - Scripted subject hierarchy plugin registered: Annotations
[DEBUG][Python] 18.02.2020 10:55:17 [Python] (C:\Program Files\Slicer 4.10.2\lib\Slicer-4.10\qt-scripted-modules\SubjectHierarchyPlugins\AbstractScriptedSubjectHierarchyPlugin.py:36) - Scripted subject hierarchy plugin registered: SegmentEditor
[DEBUG][Python] 18.02.2020 10:55:17 [Python] (C:\Program Files\Slicer 4.10.2\lib\Slicer-4.10\qt-scripted-modules\SubjectHierarchyPlugins\AbstractScriptedSubjectHierarchyPlugin.py:36) - Scripted subject hierarchy plugin registered: SegmentStatistics
[DEBUG][Qt] 18.02.2020 10:55:17 [] (unknown:0) - Switch to module: “Data”
[DEBUG][Qt] 18.02.2020 10:55:29 [] (unknown:0) - “Model” Reader has successfully read the file “C:/Users/thefl/Downloads/ProstateMeanShape2.stl” “[0.07s]”
[INFO][VTK] 18.02.2020 10:55:31 [vtkClosedSurfaceToBinaryLabelmapConversionRule (00000279C06AAB10)] (D:\D\S\Slicer-4102\Libs\vtkSegmentationCore\vtkClosedSurfaceToBinaryLabelmapConversionRule.cxx:251) - CalculateOutputGeometry: No image geometry specified, default geometry is calculated (0.165357492443735;0;0;41.1088981628418;0;0.165357492443735;0;52.828800201416;0;0;0.165357492443735;18.8999996185303;0;0;0;1;0;322;0;221;0;219;)
[DEBUG][Qt] 18.02.2020 10:55:41 [] (unknown:0) - Switch to module: “SegmentMesher”
[INFO][Python] 18.02.2020 10:55:48 [Python] (C:/Users/thefl/AppData/Roaming/NA-MIC/Extensions-28257/SegmentMesher/lib/Slicer-4.10/qt-scripted-modules/SegmentMesher.py:361) - Mesh generation using Cleaver is started in working directory: C:/Users/thefl/AppData/Local/Temp/Slicer/SegmentMesher/20200218_105548_245
[INFO][Stream] 18.02.2020 10:55:48 [] (unknown:0) - CLEAVER
[INFO][Stream] 18.02.2020 10:55:48 [] (unknown:0) - Mesh generation using Cleaver is started in working directory: C:/Users/thefl/AppData/Local/Temp/Slicer/SegmentMesher/20200218_105548_245
[DEBUG][Python] 18.02.2020 10:55:48 [Python] (C:/Users/thefl/AppData/Roaming/NA-MIC/Extensions-28257/SegmentMesher/lib/Slicer-4.10/qt-scripted-modules/SegmentMesher.py:375) - Attempt to find executable at: C:\Users\thefl\AppData\Roaming\NA-MIC\Extensions-28257\SegmentMesher\lib\Slicer-4.10\cleaver-cli.exe
[INFO][Python] 18.02.2020 10:55:48 [Python] (C:/Users/thefl/AppData/Roaming/NA-MIC/Extensions-28257/SegmentMesher/lib/Slicer-4.10/qt-scripted-modules/SegmentMesher.py:361) - Generating volumetric mesh…
[WARNING][VTK] 18.02.2020 10:55:48 [] (unknown:0) - Generic Warning: In D:\D\S\Slicer-4102\Libs\MRML\Core\vtkDataFileFormatHelper.cxx, line 237
vtkDataFileFormatHelper::GetFileExtensionFromFormatString: please update deprecated extension-only format specifier to ‘File format name (.ext)’ format! Current format string: .nrrd
[INFO][Stream] 18.02.2020 10:55:48 [] (unknown:0) - Generating volumetric mesh…
[INFO][Python] 18.02.2020 10:55:48 [Python] (C:/Users/thefl/AppData/Roaming/NA-MIC/Extensions-28257/SegmentMesher/lib/Slicer-4.10/qt-scripted-modules/SegmentMesher.py:448) - Generate mesh using: C:\Users\thefl\AppData\Roaming\NA-MIC\Extensions-28257\SegmentMesher\lib\Slicer-4.10\cleaver-cli.exe: [’–input_files’, u’C:/Users/thefl/AppData/Local/Temp/Slicer/SegmentMesher/20200218_105548_245\inputLabelmap.nrrd’, ‘–segmentation’, ‘–output_path’, u’C:/Users/thefl/AppData/Local/Temp/Slicer/SegmentMesher/20200218_105548_245/’, ‘–output_format’, ‘vtkUSG’, ‘–fix_tet_windup’, ‘–strip_exterior’, ‘–verbose’, ‘–scale’, ‘0.2’, ‘–multiplier’, ‘2’, ‘–grading’, ‘5’]
[INFO][Stream] 18.02.2020 10:55:48 [] (unknown:0) - Generate mesh using: C:\Users\thefl\AppData\Roaming\NA-MIC\Extensions-28257\SegmentMesher\lib\Slicer-4.10\cleaver-cli.exe: [’–input_files’, u’C:/Users/thefl/AppData/Local/Temp/Slicer/SegmentMesher/20200218_105548_245\inputLabelmap.nrrd’, ‘–segmentation’, ‘–output_path’, u’C:/Users/thefl/AppData/Local/Temp/Slicer/SegmentMesher/20200218_105548_245/’, ‘–output_format’, ‘vtkUSG’, ‘–fix_tet_windup’, ‘–strip_exterior’, ‘–verbose’, ‘–scale’, ‘0.2’, ‘–multiplier’, ‘2’, ‘–grading’, ‘5’]
[INFO][Stream] 18.02.2020 10:56:16 [] (unknown:0) - ‘NoneType’ object has no attribute ‘GetType’
[CRITICAL][Stream] 18.02.2020 10:56:16 [] (unknown:0) - Traceback (most recent call last):
[CRITICAL][Stream] 18.02.2020 10:56:16 [] (unknown:0) - File “C:/Users/thefl/AppData/Roaming/NA-MIC/Extensions-28257/SegmentMesher/lib/Slicer-4.10/qt-scripted-modules/SegmentMesher.py”, line 296, in onApplyButton
[CRITICAL][Stream] 18.02.2020 10:56:16 [] (unknown:0) - self.cleaverPaddingPercentSpinBox.value * 0.01)
[CRITICAL][Stream] 18.02.2020 10:56:16 [] (unknown:0) - File “C:/Users/thefl/AppData/Roaming/NA-MIC/Extensions-28257/SegmentMesher/lib/Slicer-4.10/qt-scripted-modules/SegmentMesher.py”, line 625, in createMeshFromSegmentationCleaver
[CRITICAL][Stream] 18.02.2020 10:56:16 [] (unknown:0) - if currentColorNode.GetType() == currentColorNode.User and currentColorNode.IsA(“vtkMRMLColorTableNode”):
[CRITICAL][Stream] 18.02.2020 10:56:16 [] (unknown:0) - AttributeError: ‘NoneType’ object has no attribute ‘GetType’

Thank you. The two executions are completely different.

Your mesh cannot be imported into the segmentation. Can you upload it somewhere and send the download link?

In the second case, I was able to reproduce the problem based on the logs. It seems that in Segment mesher module, you have accidentally left the “Output model” as “ProstateMeanShape2” (the original input surface mesh). This was unexpected and this case was not handled properly, but I’ve fixed the logic now (the updated file is available at the same URL). I would recommend to load the mesh file directly as a segmentation node by choosing “Segmentation” in Add data dialog’s description column (then you would not need to convert the model node to segmentation node and end up with an extra model node in the scene that you don’t need).

1 Like

Thank you, I got the prostate model to work by directly loading it in as a mesh, and was able to play with Cleaver’s parameters without breaking anything.

In regards to my model, I never get the option to add it as a segment, only Model / Volume / Scalar Overlay.

My .vtk file: https://pastebin.com/zTvj9LE1

Your VTK file is already as volumetric mesh, and so it is already perfectly accurate and the simplest possible as is - there is nothing to do for the segment mesher.

If you want to have more elements then you can convert to tetrahedra and subdivide it as many times as needed, for example:

unstructuredGridNode = getNode('testCube')
unstructuredGridNode.GetDisplayNode().SetBackfaceCulling(False)
unstructuredGridNode.GetDisplayNode().EdgeVisibilityOn()

tetrahedralize=vtk.vtkDataSetTriangleFilter()
tetrahedralize.SetInputData(unstructuredGridNode.GetMesh())

subdivide=vtk.vtkSubdivideTetra()
subdivide.SetInputConnection(tetrahedralize.GetOutputPort())
subdivide.Update()

subdivide2=vtk.vtkSubdivideTetra()
subdivide2.SetInputData(subdivide.GetOutput())
subdivide2.Update()

unstructuredGridNode.SetAndObserveMesh(subdivide2.GetOutput())

If you want to use Segment Mesher module on a volumetric mesh grid then you have to convert it to labelmap or surface mesh first (using vtkResampleToImage or vtkGeometryFilter).

1 Like

Thank you for all of your help, but now I am completely confused… How did you know it was a volumetric mesh? In my perspective, all I do in VTK is define a surface using points and cells.

Typically, surfaces meshes are stored in vtkPolyData, while volumetric meshes are stored in vtkUnstructuredGrid. Your vtk file contained an unstructured grid, which suggested that it is a volumetric mesh, and the cell type = 12 confirmed that indeed your mesh had a single volumetric cell: a hexahedron.

# vtk DataFile Version 4.2
vtk output
ASCII
DATASET UNSTRUCTURED_GRID
POINTS 8 float
20 20 -20 -20 20 -20 -20 -20 -20
20 -20 -20 20 20 20 -20 20 20
-20 -20 20 20 -20 20
CELLS 1 9
8 0 1 2 3 4 5 6 7
 
CELL_TYPES 1
12

We seem to use completely different terminologies - in the title you call your input data “surface mesh”, while I would say it is a volumetric mesh; you say “triangulating”, while I would say that triangulation is the trivial operation of subdividing meshes to triangles or tetrahedra (performed by vtkDataSetTriangleFilter) and probably you want to do adaptive remeshing.

Perhaps switching to a real data set will make it more clear what you would like to do and what is a good approach to achieve it.

My apolgoies for the confusion. To be clear, I only care about the surface and wish to triangulate/subdivide it in a controlled manner.

With this new understanding my plan is to go from vtkUnstructredGrid (volumetric) → vtkGeometryFilter → vtkPolyData(surface mesh) → 3DSlicer Segmentation → SegMesher(Cleaver).

I have successfully done this, but there are 2 difficulties I am having:

  • I cannot load my polydata in as a Segmentation directly, but when I load it in as a Model and then convert to segmentation it behaves fine, creating the segmentation automatically and working with SegMesher.
  • I cannot fully control the amount of subdivisions cleaver applies to my model. I have played with the parameters but cannot make Cleaver increase the amount of triangles/tetrahedra

cap
(as you can see there are only 2 triangles per surface, I would like to add many more and also set boundaries in which triangulation would increase in fineness as you aproach them)


My .vtk file to avoid any confusion:

# vtk DataFile Version 4.2
vtk output
ASCII
DATASET POLYDATA
POINTS 8 float
-20 20 20 20 20 20 20 20 -20 
-20 20 -20 20 -20 20 -20 -20 20 
-20 -20 -20 20 -20 -20 
POLYGONS 6 30
4 0 1 2 3 
4 4 5 6 7 
4 5 0 3 6 
4 1 4 7 2 
4 1 0 5 4 
4 7 6 3 2