Set Pivot value to the model

How can i set pivot point to 3D model, normal segment exportation model pivot is far away from the actual model,it should be center of the model.

Model is exported in the original patient coordinate system. You can change the position of a model by applying a transform to the node (in Transforms module, create a linear transform, apply to the model or segmentation, and adjust sliders; or enable Display / Interaction / Visible in 3D view and drag-and-drop the box in 3D view).

If you just want to be able to easily view the model you can also center the view with the button in the controller bar:

https://www.slicer.org/wiki/Documentation/4.8/SlicerApplication/MainApplicationGUI#3D_Viewer

Yeah that make sense , it comes from patient coordinate system. i’m using scriptable module to process it though batch file, but do we have any code to adjust pivot to the center of the model, or we have to adjust it manually.

You can easily access and modify model points using numpy. For example you can “re-center” a model using this code snippet:

# Get point coordinates from model
modelNode = getNode('Segment_2')
points = arrayFromModelPoints(modelNode)

# Compute new coordinates and update them in-place
import numpy as np
centroid = np.mean(points, 0)
points[:] = points[:] - centroid

# Indicate that point modifications are completed and trigger re-render
modelNode.GetPolyData().GetPoints().GetData().Modified()
modelNode.GetDisplayNode().Modified()

Traceback:
‘MRMLCorePython.vtkMRMLScalarVolumeNode’ object has no attribute ‘GetPolyData’

Try with latest nightly version of Slicer. There has been a related fix recently.

i have updated my slicer to latest Nightly build, so now what i’m doing is to get the poly data i think model is necessary.
so i’m exporting segmentation to modelHirarchy > using above code with the segment to set it at the center > importing this model hierarchy to segmentation . using this i can able to set and export model successfully to center of the pivot point.

now the issue is in python interactor it is working fine , but when i try to run that code using my scriptable module app stop working error comes up and app crashes ,

i think this code is causing the problem slicer.modules.segmentations.logic().ExportAllSegmentsToModelHierarchy(segmentationNode,modelNode)

Could you please copy-paste the complete script here? The modelNode variable name indicates that you might try to export into a model node instead of a model hierarchy node (see http://apidocs.slicer.org/master/classvtkSlicerSegmentationsModuleLogic.html#afce3df1cc98a515ecf29cb190b12d66f).

Note that you can also export directly to files using ExportSegmentsClosedSurfaceRepresentationToFiles() method.

I’m having the same problem. Using this script or other similar code, they all return an AttributeError, like these:
**1 -> ** Traceback (most recent call last):
File “”, line 1, in
File “/home/vivian/Sources/Slicer/Slicer-SuperBuild-Debug/Slicer-build/bin/Python/slicer/util.py”, line 1273, in arrayFromModelPoints
pointData = modelNode.GetPolyData().GetPoints().GetData()
AttributeError: ‘MRMLCorePython.vtkMRMLScalarVolumeNode’ object has no attribute ‘GetPolyData’

**2 -> ** >>> n=getNode(‘T1’)

n
(MRMLCorePython.vtkMRMLScalarVolumeNode)0x7f070983cca8

nD=n.getDisplayNode()
Traceback (most recent call last):
File “”, line 1, in
AttributeError: ‘MRMLCorePython.vtkMRMLScalarVolumeNode’ object has no attribute ‘getDisplayNode’

The version of Slicer is 4.13, from the nightly build

The script above is for model nodes, which is not directly applicable to a volume node. Anyway, probably this is not needed anymore. If you want to rotate a node then you can now do it easily using GUI:

If you want to align nodes then I would recommend to use semi-automatic registration.

Actually, I’m trying to use the python interactor, but it doesn’t seen to work. I’m following the script from the " Slicer Programming tutorial" from the T1.nrrd image, and the following script:

n = getNote(‘T1’)
nD = n.getDisplayNode()
nD.InterpolateOff()

The first line works, but running the second line, this is what returns:

Traceback (most recent call last):
File “”, line 1, in
AttributeError: ‘MRMLCorePython.vtkMRMLScalarVolumeNode’ object has no attribute ‘getDisplayNode’

Sorry, yes, that’s a typo in the tutorial - it should be GetDisplayNode.

There’s an updated version of the tutorial linked from here, with the typo fixed: https://docs.google.com/document/d/1WJFxbZrCCOGLi6_lqKrI5lfxwfdwP01Wkv-5YDBXq4g/edit