3

I have a 3D vtk scene representing a point cloud, displayed through a QVTKWidget. vtk7.1, Qt5.8.

I want to be able to rotate the scene around specific coordinates, but I don't know how to proceed.

I like the trackball interaction. I just need to set the center, but I'm a bit lost in VTK api. I think I can do this by changing the rotation matrix : InvTranslation + Rotation + Translation should do the trick. I see two ways of doing it :

1)

  • Get the Rotation Matrix computed by VTK
  • Generate a new matrix
  • Apply the matrix.

2)

  • set a transform to vtk to apply before the process
  • set a transform to vtk to apply after the process

Am I in the right direction? If yes, how I can implement one of these solutions..?

Thank i advance,

Etienne.

eti_nne
  • 126
  • 1
  • 8

2 Answers2

2

Problem solved. The change of focale would also change the view. SO, I aplied a few geometric transform, and there it is.

// vtk Element /////////////////////////////////////////////////////////
vtkRenderWindowInteractor *rwi = widget->GetInteractor();
vtkRenderer *renderer = widget->GetRenderWindow()->GetRenderers()->GetFirstRenderer();
vtkCamera *camera = renderer->GetActiveCamera();

// Camera Parameters ///////////////////////////////////////////////////
double *focalPoint = camera->GetFocalPoint();
double *viewUp = camera->GetViewUp();
double *position = camera->GetPosition();
double axis[3];
axis[0] = -camera->GetViewTransformMatrix()->GetElement(0,0);
axis[1] = -camera->GetViewTransformMatrix()->GetElement(0,1);
axis[2] = -camera->GetViewTransformMatrix()->GetElement(0,2);

// Build The transformatio /////////////////////////////////////////////////
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
transform->Identity();

transform->Translate(d->center[0], d->center[1], d->center[2]);
transform->RotateWXYZ(rxf, viewUp); // Azimuth
transform->RotateWXYZ(ryf, axis);   // Elevation
transform->Translate(-d->center[0], -d->center[1], -d->center[2]);

double newPosition[3];
transform->TransformPoint(position,newPosition); // Transform Position
double newFocalPoint[3];
transform->TransformPoint(focalPoint, newFocalPoint); // Transform Focal Point

camera->SetPosition(newPosition);
camera->SetFocalPoint(newFocalPoint);

// Orhthogonalize View Up //////////////////////////////////////////////////
camera->OrthogonalizeViewUp();
renderer->ResetCameraClippingRange();

rwi->Render();
eti_nne
  • 126
  • 1
  • 8
  • 1
    was trying to avoid implementing the arcball camera rendering by just rotating the actor - but now that I found your solution, couldn't help but try it out. thanks! [python-vtk implementation shared via gist](https://gist.github.com/pangyuteng/facd430d0d9761fc67fff4ff2e5fffc3) – pangyuteng Feb 19 '18 at 00:34
0

You just have to change the focal point of your vtkCamera

vtkSmartPointer<vtkCamera> camera = 
   vtkSmartPointer<vtkCamera>::New();
camera->SetPosition(0, 0, 20);
camera->SetFocalPoint(0, 0, 10); // The center point is not 0, 0, 10
asdfasdf
  • 774
  • 11
  • 29
  • It could be a solution, but the change of focal also centered the view on the focal. I wanted to to fix the rotation center even when I move the camera around. – eti_nne Mar 31 '17 at 12:18