How to fix 3D data viewing angle setting

Hello,
I always get a lot of help.

I have one question for you.

I am using VTK 8.9 Version and I am developing a program with Visual Studio 2015 MFC (C++).
And I’m showing 3D data in Picture Control.

I want to see the same View point every time I load a PLY file.
When using the function below, you can use the left mouse button to view the same point of view for rotated 3D data.

However, I couldn’t find a way to view the same point of view for 3D data that was zoomed/shifted using the mouse wheel button.

Could you tell me how to solve it?

vtkRenderer
.SetPosition
.SetFocalPoint
.SetViewUp
.SetParallelScale
.ResetCamera
.Render

ex)
2023-05-22 17 00 35

Best regards

Hello,

If I understand well, you want to know which parameter you should save/load to keep the same zoom.

I see you’re saving/loading the “ParallelScale” parameter. If your camera is using the “ParallelProjection”, then you should already be able to achieve what you want. Otherwise, when you’re not using parallel projection, the information you’re looking for is the “ViewAngle”.

You can augment your function with vtkCamera::SetViewAngle(double) and vtkCamera::GetViewAngle(). By the way, you’re talking about functions from vtkRenderer which actually are in vtkCamera. Maybe in your VTK version those were exposed, I didn’t find this information. I guess if it was the case that the view angle should also have been exposed.

Correct me if I’m wrong!
Best regards

Hello Charly Bollinger,

Thanks for your answer.
I didn’t get the result I wanted.

To explain it in more detail

  1. I made a simple program to load a PLY file into a Picture Control with mouse events added to it.

  2. And the mouse event (wheel, left button) changes the point of view of the 3D data,
    I want to see the changed point of view when I reload the PLY file.

  3. However, I’m having trouble fixing the 3D data point zoomed in/out with the mouse wheel.

Hello,

I understood your need, but I’m not sure to understand what you’ve already got. Are you already saving information about last time you loaded it? If yes, is it made of the example code you provided? And what is currently working: everything except the zoom info?
Last but not least, can you confirm that the functions you’re using (e.g SetPosition, SetFocalPoint,…) are from vtkRenderer?And if yes, is there some View Angle function?

I hope I can help with those informations. Thanks

Best regards

Hello,

One possible way to address that is by:

  1. Subclassing vtkInteractorStyleTrackballCamera and overriding its event handlers:
  1. Attaching the custom event handler class to your rendering pipeline by doing (in the body of your MFC widget class, for example):
(...)

    // Customize event handling through a subclass of vtkInteractorStyleTrackballCamera.
    m_myInteractor = vtkSmartPointer<v3dMouseInteractor>::New();
    m_myInteractor->SetDefaultRenderer(m_renderer);
    m_vtkwidget->renderWindow()->GetInteractor()->SetInteractorStyle( m_myInteractor );

    // Set callback for any event
    vtkSmartPointer<vtkCallbackCommand> callBackCommand = vtkSmartPointer<vtkCallbackCommand>::New();
    callBackCommand->SetCallback( rendererCallback );
    callBackCommand->SetClientData((void*)this); //the pointer to your MFC widget, for example
    m_renderer->AddObserver( vtkCommand::AnyEvent , callBackCommand );   // m_renderer is the vtkRenderer object.

(...)

My renderCallback() was coded for Qt, so you need to translate it to whatever MFC equivalents are:

/*static*/ void View3DWidget::rendererCallback(vtkObject *caller,
                                                 unsigned long vtkNotUsed(QWidget::event),
                                                 void *arg,
                                                 void *vtkNotUsed(whatIsThis))
{
    QVTKOpenGLNativeWidget *qvtkOGLwidget;  // must point to the same object as View3DWidget's _vtkwidget.
    qvtkOGLwidget = static_cast<QVTKOpenGLNativeWidget*>(arg);
    if( ! qvtkOGLwidget ){
        Application::instance()->logWarn("View3DWidget::rendererCallback(): arg is not a QVTKOpenGLWidget.  Check View3DWidget::_vtkwidget's class.");
    } else {
        // Place vtkRenderer event handling code here.
    }
}

complete code: gammaray/viewer3d at master · PauloCarvalhoRJ/gammaray · GitHub.

I hope this helps,

PC