Setting renderer camera causing center of rotation to change

Hey all,

I’m having an issue where I need to zoom my visual out on startup so it’s not so large, but after doing so,
the center of rotation of my object changes. Does anyone have any idea why this happens or what a potential fix could be?

        self.vtkWidget = QVTKRenderWindowInteractor(self.uic.openGLViewer)
        self.vtkWidget.setGeometry(0, 0, 481, 341)
        self.ren = vtkRenderer()
        camera = vtkCamera()
        camera.SetPosition(0, 0, 200)
        self.ren.SetActiveCamera(camera)
        #self.ren.GetActiveCamera().SetPosition(0, 0, 5)
        self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()

@cam, is there a reason you’re setting a new camera on the renderer? By default, the renderer makes a camera for you. All you should have to do is call ResetCamera on the renderer. And to zoom out the visual just call ren.getActiveCamera().Zoom() or ren.getActiveCamera().Dolly() after the initial ResetCamera and before the first Render.

There is no particular reason I did that. I am very new to VTK and trying to figure everything out still.

        self.vtkWidget = QVTKRenderWindowInteractor(self.uic.openGLViewer)
        self.vtkWidget.setGeometry(0, 0, 481, 341)
        self.ren = vtkRenderer()
        self.ren.ResetCamera()
        self.ren.GetActiveCamera().Zoom(2)
        self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()

I have made the following modification and I am still having the issue where the STL object is off center.

Make sure you call ResetCamera after adding the actor to the renderer. In essence, the reset camera call is figuring out the frustum bounds based on all the actors present in the viewport.

1 Like

This works perfectly! Here is the code for the sake of completion:

 self.vtkWidget = QVTKRenderWindowInteractor(self.uic.openGLViewer)
        self.vtkWidget.setGeometry(0, 0, 481, 341)
        self.ren = vtkRenderer()
        self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()

        reader = vtkSTLReader()
        reader.SetFileName(filename)

        # Create a mapper
        mapper = vtkPolyDataMapper()
        mapper.SetInputConnection(reader.GetOutputPort())

        # Create an actor
        actor = vtkActor()
        actor.SetMapper(mapper)

        self.ren.AddActor(actor)
        self.ren.ResetCamera()
        self.ren.GetActiveCamera().Zoom(0.8)