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.
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.
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?
Subclassing vtkInteractorStyleTrackballCamera and overriding its event handlers:
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.
}
}