# vtkObjExporter- model down quality

**URL:** <https://discourse.slicer.org/t/vtkobjexporter-model-down-quality/2510>\
**Category:** Development\
**Created:** [April 4, 2018, 7:48am UTC](https://discourse.slicer.org/t/vtkobjexporter-model-down-quality/2510 "2018-04-04T07:48:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anandmulay3](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anandmulay3](https://discourse.slicer.org/u/anandmulay3)\
**Post date:** [April 4, 2018, 7:48am UTC](https://discourse.slicer.org/t/vtkobjexporter-model-down-quality/2510/1 "2018-04-04T07:48:02Z")

</div>

I’m getting so down quality obj file,

- when i try to get it using vtkObjexporter i get this output, … ![Capture2](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/8/08fd82e1e3d58bf60a2ec3a766a6b9a97282cb01.png)

![Capture1](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/6/c6848d82d04059674d635fd64d2e255c7ab0df8c.png)

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

am i missing any parameter??

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [April 4, 2018, 6:35pm UTC](https://discourse.slicer.org/t/vtkobjexporter-model-down-quality/2510/2 "2018-04-04T18:35:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anandmulay3](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anandmulay3](https://discourse.slicer.org/u/anandmulay3)\
**Post date:** [April 5, 2018, 6:46am UTC](https://discourse.slicer.org/t/vtkobjexporter-model-down-quality/2510/3 "2018-04-05T06:46:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [April 6, 2018, 12:31am UTC](https://discourse.slicer.org/t/vtkobjexporter-model-down-quality/2510/4 "2018-04-06T00:31:48Z")

</div>

In recent nightly builds, export to file feature is built in - [Save segmentation directly to STL or OBJ files](https://discourse.slicer.org/t/save-segmentation-directly-to-stl-or-obj-files/2428/2). I would recommend to use that.

---

<div class="post-metadata">

**Author:** ![anandmulay3](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anandmulay3](https://discourse.slicer.org/u/anandmulay3)\
**Post date:** [April 6, 2018, 8:18am UTC](https://discourse.slicer.org/t/vtkobjexporter-model-down-quality/2510/5 "2018-04-06T08:18:56Z")

</div>

Thanks , latest segmentation export works fine 🙂
