Top, Left, Right, Bottom, Back View.

Hello,

ex) Top View
( CloudCompare

I programmed the code below to implement CloudCompare Top View.
But it looks like a Top View, but I don’t think it’s a perfect Top View.
( It seems to be tilted very slightly. )

Let me know what I made a mistake.

vtkCamera *m_vtkCamera;
m_vtkCamera = m_vtkRenderer->GetActiveCamera();
m_vtkCamera->SetFocalPoint(0, 0, 0);
m_vtkCamera->SetViewUp(0, 0, 0);
m_vtkCamera->SetPosition(0, 0, 1);

BR

Hi, Seram,

This is how I do “look at plane” (the 3 first button in your case):

void View3DWidget::onLookAtXY()
{
    //_renderer->ResetCamera();
    double *fp = _rendererMainScene->GetActiveCamera()->GetFocalPoint();
    double *p = _rendererMainScene->GetActiveCamera()->GetPosition();
    double dist
        = std::sqrt((p[0] - fp[0]) * (p[0] - fp[0]) + (p[1] - fp[1]) * (p[1] - fp[1])
                    + (p[2] - fp[2]) * (p[2] - fp[2]));
    _rendererMainScene->GetActiveCamera()->SetPosition(fp[0], fp[1], fp[2] + dist);
    _rendererMainScene->GetActiveCamera()->SetViewUp(0.0, 1.0, 0.0);
    // redraw the scene
    _vtkwidget->GetRenderWindow()->Render();
}

void View3DWidget::onLookAtXZ()
{
    double *fp = _rendererMainScene->GetActiveCamera()->GetFocalPoint();
    double *p = _rendererMainScene->GetActiveCamera()->GetPosition();
    double dist
        = std::sqrt((p[0] - fp[0]) * (p[0] - fp[0]) + (p[1] - fp[1]) * (p[1] - fp[1])
                    + (p[2] - fp[2]) * (p[2] - fp[2]));
    _rendererMainScene->GetActiveCamera()->SetPosition(fp[0], fp[1] - dist, fp[2]);
    _rendererMainScene->GetActiveCamera()->SetViewUp(0.0, 0.0, 1.0);
    // redraw the scene
    _vtkwidget->GetRenderWindow()->Render();
}

void View3DWidget::onLookAtYZ()
{
    double *fp = _rendererMainScene->GetActiveCamera()->GetFocalPoint();
    double *p = _rendererMainScene->GetActiveCamera()->GetPosition();
    double dist
        = std::sqrt((p[0] - fp[0]) * (p[0] - fp[0]) + (p[1] - fp[1]) * (p[1] - fp[1])
                    + (p[2] - fp[2]) * (p[2] - fp[2]));
    _rendererMainScene->GetActiveCamera()->SetPosition(fp[0] + dist, fp[1], fp[2]);
    _rendererMainScene->GetActiveCamera()->SetViewUp(0.0, 0.0, 1.0);
    // redraw the scene
    _vtkwidget->GetRenderWindow()->Render();
}

For the other 3 buttons, you need to swap the signs of the sums/diffs in the _rendererMainScene->GetActiveCamera()->SetPosition() calls (e.g. from fp[0] + dist to fp[0] - dist);

I hope this helps,

regards,

Paulo

1 Like

Hi Paulo

I tried applying the code, but it’s still slightly tilted.
Is there any way to look like CloudCompare?

BR
Seram

This looks more like the perspective of the camera rather than the camera position, you can set the projection to be parallel by adding:

m_vtkCamera->ParallelProjectionOn();

You can always toggle this option too.

Hi Fraseyboo

Thanks for the answer.
Thanks to that, the problem was solved.

BR
Seram