Hi Will,
I think your suggestion regarding output makes perfect sense. Regarding 3MF, note that there is a library: https://lib3mf.readthedocs.io/en/master/ that may greatly accelerate things for those comfortable in C++.
It would be very convenient if vtkPolyData was able to export/import homogenous meshes as an array of vertices and an array of faces, i.e. a connectivity matrix. I was able to extract this information from an instance of vtkSurfaceNets3D (SN) to numpy arrays, but it seems both slow and clumsy:
Off = SN.GetOutput().GetPolys().GetOffsetsArray()
Conn = SN.GetOutput().GetPolys().GetConnectivityArray()
Faces = np.empty([Off.GetNumberOfTuples()-1,3],dtype='int32')
for row in range(Off.GetNumberOfTuples()-1):
off = int(Off.GetTuple(row)[0])
for col in range(3):
Faces[row,col] = int(Conn.GetTuple(off+col)[0])
Verts = numpy_support.vtk_to_numpy(SN.GetOutput().GetPoints().GetData())
BoundaryLabels = np.array(SN.GetOutput().GetCellData().GetArray("BoundaryLabels"))
Iterating over tuples to extract the connectivity data seems to be the slow step. Any advice on how to accelerate is welcome. The numpy convenience functions included with the python wrappers do not seem to work with the vtkTypeInt64Array that one gets with .GetConnectivityArray().
I did have another question regarding vtkSurfaceNets. As you pointed out, the algorithm passes through just once, no matter how many labels are selected for output. So I thought that cycling through labels as show here:
SN.SetOutputStyleToSelected()
SN.InitializeSelectedLabelsList()
for i in range(1,numclasses,1):
print('Extracting SurfaceNet for '+keys.Label[I])
if i>1:
SN.DeleteSelectedLabel(i-1)
SN.AddSelectedLabel(i)
SN.Modified()
SN.Update()
stlWriter.SetInputData(SN.GetOutput())
stlWriter.SetFileTypeToBinary()
stlWriter.SetFileName('/path/to/file'+keys.Label[i]+'.stl')
stlWriter.Write()
would not require re-calculating everything. But that is what seems to be happening:
2023-04-26 07:26:34.132 (1599.634s) [ 13BF1E9] vtkSurfaceNets3D.cxx:2334 INFO| Executing Surface Nets 3D
2023-04-26 07:26:45.679 (1611.180s) [ 13BF1E9] vtkSurfaceNets3D.cxx:2408 INFO| Extracted: 29666048 points, 29749004 quads
2023-04-26 07:26:45.686 (1611.188s) [ 13BF1E9] vtkSurfaceNets3D.cxx:1828 INFO| Smoothing output
2023-04-26 07:26:45.754 (1611.255s) [ 13BF1E9]vtkConstrainedSmoothing:460 INFO| Executing constrained smoothing filter
2023-04-26 07:26:54.562 (1620.063s) [ 13BF1E9] vtkSurfaceNets3D.cxx:2044 INFO| Transforming output mesh type to: 1
2023-04-26 07:26:55.650 (1621.151s) [ 13BF1E9] vtkSurfaceNets3D.cxx:2459 INFO| Triangulated to produce: 59498008 triangles
2023-04-26 07:26:56.407 (1621.908s) [ 13BF1E9] vtkSurfaceNets3D.cxx:2472 INFO| Selected: 5609800 cells
2023-04-26 07:26:59.466 (1624.967s) [ 13BF1E9] vtkSurfaceNets3D.cxx:2334 INFO| Executing Surface Nets 3D
2023-04-26 07:27:10.887 (1636.389s) [ 13BF1E9] vtkSurfaceNets3D.cxx:2408 INFO| Extracted: 29666048 points, 29749004 quads
2023-04-26 07:27:10.894 (1636.395s) [ 13BF1E9] vtkSurfaceNets3D.cxx:1828 INFO| Smoothing output
2023-04-26 07:27:10.976 (1636.477s) [ 13BF1E9]vtkConstrainedSmoothing:460 INFO| Executing constrained smoothing filter
2023-04-26 07:27:19.734 (1645.235s) [ 13BF1E9] vtkSurfaceNets3D.cxx:2044 INFO| Transforming output mesh type to: 1
2023-04-26 07:27:20.769 (1646.270s) [ 13BF1E9] vtkSurfaceNets3D.cxx:2459 INFO| Triangulated to produce: 59498008 triangles
2023-04-26 07:27:21.188 (1646.689s) [ 13BF1E9] vtkSurfaceNets3D.cxx:2472 INFO| Selected: 8748100 cells
2023-04-26 07:27:23.611 (1649.112s) [ 13BF1E9] vtkSurfaceNets3D.cxx:2334 INFO| Executing Surface Nets 3D
2023-04-26 07:27:33.439 (1658.940s) [ 13BF1E9] vtkSurfaceNets3D.cxx:2408 INFO| Extracted: 29666048 points, 29749004 quads
2023-04-26 07:27:33.443 (1658.944s) [ 13BF1E9] vtkSurfaceNets3D.cxx:1828 INFO| Smoothing output
2023-04-26 07:27:33.476 (1658.977s) [ 13BF1E9]vtkConstrainedSmoothing:460 INFO| Executing constrained smoothing filter
2023-04-26 07:27:41.872 (1667.373s) [ 13BF1E9] vtkSurfaceNets3D.cxx:2044 INFO| Transforming output mesh type to: 1
2023-04-26 07:27:42.829 (1668.330s) [ 13BF1E9] vtkSurfaceNets3D.cxx:2459 INFO| Triangulated to produce: 59498008 triangles
2023-04-26 07:27:43.146 (1668.647s) [ 13BF1E9] vtkSurfaceNets3D.cxx:2472 INFO| Selected: 2958346 cells
I am still new to this entire pipeline thinking in VTK, so any pointers as to why this may be happening is welcome.