vtkObjExporter- model down quality

I’m getting so down quality obj file,

  • when i try to get it using vtkObjexporter i get this output, …Capture2

Capture1

  • And same model when i export it using segmentation exporter in slicer UI in latest slicer 4.9

am i missing any parameter??

There should be no extra smoothing. Are you sure that the software that you use to view the exported file does not apply smoothing? How the model looks in ParaView?

How do you use vtkOBJExporter? What do you do exactly: what buttons you click / what code do you execute?

It would help a lot if you could go back to your post and edit it so that it is clear where sentences start and end, and which picture belongs to which sentence. Right now, it is not clear if you want to get the top or the bottom image.

ohh sorry for bad arrangement of images in post
I’m using windows MR viewer of windows 10 and 3D paint which comes default in windows 10.
I;m using same code which you have given for exporting stl file of segmentation, stl works perfect but i’m getting this weird output for obj.

Code:

/Segmentation
masterVolumeNode = getNode(‘Sft’)

/ Create segmentation
segmentationNode = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLSegmentationNode”)
segmentationNode.CreateDefaultDisplayNodes() # only needed for display
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(masterVolumeNode)
addedSegmentID = segmentationNode.GetSegmentation().AddEmptySegment(“skin”)

/ Create segment editor to get access to effects
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
segmentEditorNode = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLSegmentEditorNode”)
segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
segmentEditorWidget.setSegmentationNode(segmentationNode)
segmentEditorWidget.setMasterVolumeNode(masterVolumeNode)

/ Thresholding
segmentEditorWidget.setActiveEffectByName(“Threshold”)
effect = segmentEditorWidget.activeEffect()
effect.setParameter(“MinimumThreshold”,“300”)
effect.setParameter(“MaximumThreshold”,“5695”)
effect.self().onApply()

/ Smoothing
segmentEditorWidget.setActiveEffectByName(“Smoothing”)
effect = segmentEditorWidget.activeEffect()
effect.setParameter(“SmoothingMethod”, “MEDIAN”)
effect.setParameter(“KernelSizeMm”, 3)
effect.self().onApply()

/ Clean up
segmentEditorWidget = None
slicer.mrmlScene.RemoveNode(segmentEditorNode)
/ Make segmentation results visible in 3D
segmentationNode.CreateClosedSurfaceRepresentation()

/ Make sure surface mesh cells are consistently oriented
surfaceMesh = segmentationNode.GetClosedSurfaceRepresentation(addedSegmentID)
normals = vtk.vtkPolyDataNormals()
normals.AutoOrientNormalsOn()
normals.ConsistencyOn()
normals.SetInputData(surfaceMesh)
normals.Update()
surfaceMesh = normals.GetOutput()

/Write to OBJ file
lm = slicer.app.layoutManager()
tdv = lm.threeDWidget(0).threeDView()
rw = tdv.renderWindow()
Move renderer temporarily into another renderWindow
It will make the application crash, but it allows the scene export to complete successfully.
rw2 = vtk.vtkRenderWindow()
rw2.AddRenderer(rw.GetRenderers().GetFirstRenderer())
o = vtk.vtkOBJExporter()
o.SetFilePrefix(‘c:/Anand Work/test’)
o.SetRenderWindow(rw2)
o.Write()

and yes , in slicer 3d view it looks perfect

In recent nightly builds, export to file feature is built in - Save segmentation directly to STL or OBJ files. I would recommend to use that.

1 Like

Thanks , latest segmentation export works fine :slight_smile: