Will and all,
this looks absolutely fabulous! Dr. Frisken’s publication caught my eye, and I was very glad to discover that you have not only adopted SurfaceNets but also spent the time parallelizing it. Never having used VTK before, I was impressed that I was able to build VTK from source and even get it to run, using the python wrappers, in the course of a few hours - this speaks to your dedication to making it accessible much more than to my skills. We are currently working on a number (>200) of decently sized synchrotron µCT reconstructions of mouse mandibles (typical size ~1500x900x3500 voxels, 14-20 classes/labels/contour values). I managed to load one of our label matrices using vtkTIFFReader, and looking at https://gitlab.kitware.com/will.schroeder/surface-nets-testing/-/blob/main/RunSN.cxx I cobbled a Jupyter script together that actually worked, and was blindingly fast, too. Color me impressed.
But I seem to have exhausted my streak of getting things to work. Here are a few things that I would like to do, hoping that you might be able to point me in the right direction.
-
Extract the
BoundaryLabels
Array from the output, and parse it, for example to determine the surface areas of the various interfaces. I have a rough sense on how I might be able to extract the vertices and faces (connectivity) from thevtkPolyData
I can pull out via the.GetPolys()
method. But I can’t figure out how to get theBoundaryLabels
, and do not understand how these labels map onto the polys (in my case, triangles). Because I am less familiar with vtk, my instinct is to try and export to numpy arrays (and ultimately Matlab, where most of our current code lives). Any suggestions on how to do this are very welcome. -
One thing that we’d ultimately like to do is 3D print some of the models using a multi-material printer. For this, I was hoping to find a method more elegant and efficient than using
.SetOutputStyleToSelected()
,.InitializeSelectedLabelsList()
, andAddSelectedLabel(label)
and iterating over the label to save separate STLs. Any suggestions on how to transform the output into a format such as 3MF or a similar industry-standard format that supports multi-material printing would be greatly appreciated.
Thank you very much,
Derk
PS: And one more question. Using a very simple rendering pipeline on my Mac (OS X 12.6.3), I can generate beautiful windows and interact with the render. However, I cannot figure out how to close the window (the red button results in a spinning pizza) short of restarting the Python kernel. The keyboard commands I read about either do nothing or also result in Python becoming unresponsive. How do I get the renderer/interactor to stop? Here is my Jupyter script:
# set up tiff reader and import
reader = vtkTIFFReader()
reader.SetFileName('/path/to/SurfaceNetsTest.tiff')
reader.Update()
LabelMatrix = reader.GetOutput()
# vtkSurfaceNets3D class methods can be found here: https://vtk.org/doc/nightly/html/classvtkSurfaceNets3D.html#a51c2dd330853912b207b944831cc8d92
SN = vtkSurfaceNets3D()
# create instance of SurfaceNets3D
SN.SetInputData(LabelMatrix)
# this set the number of classes ander their values for (eventual) coloring, I think
SN.GenerateValues(14,0,13)
# the next two are parameters that we need to explore
SN.SetNumberOfIterations(25)
SN.SetConstraintScale(2)
SN.Modified()
SN.Update()
# create color lookup table
lut = vtkLookupTable()
lut.SetNumberOfColors(14);
lut.SetHueRange(0.667, 0.0);
lut.Build();
# create PolyDataMapper
pdm = vtkPolyDataMapper()
pdm.SetInputData(SN.GetOutput())
pdm.SetLookupTable(lut)
pdm.SetScalarRange(0,13)
pdm.SetColorModeToMapScalars()
# Create Actor
actor = vtkActor();
actor.SetMapper(pdm);
# Create Renderer
ren = vtkRenderer();
ren.AddActor(actor);
# Create Window
renWin = vtkRenderWindow();
renWin.SetSize(500,500);
renWin.AddRenderer(ren);
# Create Interactor
iren= vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# Render w/interactive controls
renWin.Render();
iren.Start();