3D object rotates when we are perform 3D center code in CPP

Actually I want to have 3D view by default in center.

TRY:1 Python

in the Script repository we are having this code.

# Center the 3D view on the scene¶
layoutManager = slicer.app.layoutManager()
threeDWidget = layoutManager.threeDWidget(0)
threeDView = threeDWidget.threeDView()
threeDView.resetFocalPoint()

But this is rotating 3D object when we are clicking (Eye button) visible - invisible from segment table.

TRY:2 Python

by pressing center 3D button programmatically.

# Center 3D View
slicer.app.layoutManager().threeDWidget(0).threeDController().BarWidget.CenterButton_Header.click()

This code by pressing center 3D button has solved the issue of rotation in python files.



TRY:1 Cpp

As we know segment table’s show 3D eye code is in the Cpp for that I have done.

//Center 3D View
      PythonQt::init();
      PythonQtObjectPtr openBrowserContext = PythonQt::self()->getMainModule();
      openBrowserContext.evalScript(QString(
        "from slicer.util import * \n"
        "mainWindow = slicer.util.mainWindow()\n"
        "print('Segment table visible button')\n"
        "slicer.app.layoutManager().threeDWidget(0).threeDController().BarWidget.CenterButton_Header.click()\n"));

This code makes 3D object in the center but when we are frequently pressing segment table’s eye button it rotates the 3D object in CW.

Can you please share any better approach for this issue.

Reason:

  • its very annoying to press center 3D button all the time. So that’s way when I am loading or showing 3D object it should come to center.

Thank you.

Thanks for the code snippets. They specify what code you have problem with, but it is not clear for me why you keep clicking the eye icons, why would you like to change the camera’s focal point, and why it causes problems for you.

Normaly you set the camera focal point to the center of the volume you have segmented and don’t change if after that programmatically.

Can you describe your workflow in a bit more detail? Is there anything special about it that makes it necessary to change the focal point frequently or you think that in general Slicer does not do a good job in setting the focal point?