[vtkusers] camera follower in 3D

Miroslav Drahos mdrahos at aurisrobotics.com
Fri Mar 25 22:58:46 EDT 2016


Rick,
I am not trying to trivialize your problem, and understand that things are much more complicated. I was just showing that vtkFollower works, and you may be able to use it to your advantage.
For example you could check the matrix that vtkFollower calculates against your matrix.
Or you could derive from vtkBoxRepresentation and replace all actors with followers. You will probably have to modify the interaction as well (i.e. override methods in vtkBoxWidget2).
Best,
Miro


From: Richard Frank [mailto:rickfrank at me.com]
Sent: Friday, March 25, 2016 7:01 PM
To: Miroslav Drahos <mdrahos at aurisrobotics.com>
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] camera follower in 3D

Ok I get that. But the clip planes and box widget? That's multiple actors embedded in the box widget / vtk box representation. It's much more complex. Anyways, let me put my small example together ( which uses ComputeMatrix() to get the basis vectors)  and maybe you can assist me figuring out why the box scales.....ill try to post something to Drop Box tomorrow.
What I'm trying to do is clip using the box widget always facing the camera ( cut planes ) while in addition allowing the use to resize the clip volume. Which means the center of rotation for the box has to be at the camera focal point....

Thanks for the quick help!

Rick


Sent from my iPad

On Mar 25, 2016, at 9:50 PM, Miroslav Drahos <mdrahos at aurisrobotics.com<mailto:mdrahos at aurisrobotics.com>> wrote:
Here, I typed this quickly to demonstrate. Adding a cone and cylinder, cylinder will be fixed in 3D space, and cone will be always facing the camera. Attached some shots on what it looks like.
HTH,
Miro

#include <vtkFollower.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkConeSource.h>
#include <vtkCylinderSource.h>
#include <vtkSmartPointer.h>

#define VTK_CREATE(type, name) vtkSmartPointer<type> name = vtkSmartPointer<type>::New();

int main()
{
    VTK_CREATE(vtkRenderWindow, rw);
    VTK_CREATE(vtkRenderer, ren);
    rw->AddRenderer(ren);

    VTK_CREATE(vtkConeSource, cone);
    VTK_CREATE(vtkPolyDataMapper, coneMapper);
   coneMapper->SetInputConnection(cone->GetOutputPort());
    VTK_CREATE(vtkFollower, coneFollower);
    coneFollower->SetMapper(coneMapper);
    // tilt the cone a bit so that we can see its orientation better
    coneFollower->RotateY(40);
    coneFollower->SetPosition(0, 3, 0);
    coneFollower->SetCamera(ren->GetActiveCamera());
    ren->AddViewProp(coneFollower);

    VTK_CREATE(vtkCylinderSource, cylinder);
    VTK_CREATE(vtkPolyDataMapper, cylinderMapper);
    cylinderMapper->SetInputConnection(cylinder->GetOutputPort());
    VTK_CREATE(vtkActor, cylinderActor);
    cylinderActor->SetMapper(cylinderMapper);
    ren->AddViewProp(cylinderActor);

    VTK_CREATE(vtkRenderWindowInteractor, iren);
    rw->SetInteractor(iren);

    ren->ResetCamera();
    rw->Render();
    iren->Start();

    return 0;
}



From: Richard Frank [mailto:rickfrank at me.com]
Sent: Friday, March 25, 2016 6:30 PM
To: Miroslav Drahos <mdrahos at aurisrobotics.com<mailto:mdrahos at aurisrobotics.com>>
Cc: vtkusers at vtk.org<mailto:vtkusers at vtk.org>
Subject: Re: [vtkusers] camera follower in 3D

Ok, I could never get it to work. But more specifically, I need the box/clip widget to stay perp to the camera. It is composed of many actors( which are private)

Rick Frank

On Mar 25, 2016, at 9:19 PM, Miroslav Drahos <mdrahos at aurisrobotics.com<mailto:mdrahos at aurisrobotics.com>> wrote:
Rick,
There is no such restriction for vtkFollower. It is a vtkActor, so can be used with a variety of different data sources, such as polydata. That’s the case for example with the oriented polygonal handle representation.
The transform that you are looking for is calculated in vtkFollower::ComputeMatrix().
Cheers,
Miro


From: Richard Frank [mailto:rickfrank at me.com]
Sent: Friday, March 25, 2016 5:57 PM
To: Miroslav Drahos <mdrahos at aurisrobotics.com<mailto:mdrahos at aurisrobotics.com>>
Cc: vtkusers at vtk.org<mailto:vtkusers at vtk.org>
Subject: Re: [vtkusers] camera follower in 3D

Thanks the problem I've had with VTK follower is that it seems dedicated to text- it puts text at the viewport z= 0 and doesn't seem to work for something at the camera focal point

Rick Frank

On Mar 25, 2016, at 7:49 PM, Miroslav Drahos <mdrahos at aurisrobotics.com<mailto:mdrahos at aurisrobotics.com>> wrote:
It uses vtkFollower (a subclass of vtkActor that always faces the camera). So make sure to check out vtkFollower as well.

Miro



From: Miroslav Drahos
Sent: Friday, March 25, 2016 4:45 PM
To: 'Richard Frank' <rickfrank at me.com<mailto:rickfrank at me.com>>; vtkusers at vtk.org<mailto:vtkusers at vtk.org>
Subject: RE: [vtkusers] camera follower in 3D

Rick,
Look at vtkOrientedPolygonalHandleRepresentation3D
 http://www.vtk.org/doc/nightly/html/classvtkOrientedPolygonalHandleRepresentation3D.html
It does exactly that – keeps the widget rep (polydata) in a fixed orientation with respect to camera.
HTH,
Miro


From: vtkusers [mailto:vtkusers-bounces at vtk.org] On Behalf Of Richard Frank
Sent: Friday, March 25, 2016 4:41 PM
To: vtkusers at vtk.org<mailto:vtkusers at vtk.org>
Subject: [vtkusers] camera follower in 3D


Hi,

Has anyone successfully created a widget or other object that stays facing the camera in 3D?

I've been trying to get the boxwidget to stay with one side facing the camera and I've come close - by computing a change of basis matrix after computing the camera position, direction of projection, etc. and creating a rotation matrix from the basis column vectors.

When I have the PlusX face of the box widget facing the camera, and move the camera with the trackball interactor, the face of the widget stays facing (seems like it is standing still) but the size/scale of the box gets smaller as I rotate by sliding the mouse from right to left.

It seems that I need to compensate for some scaling of the rotation matrix but I'm not sure exactly what. I'm putting together a small example if someone wants to take a look at it.

Thanks

Rick

<follow1.png>
<follow2.png>
<follow3.png>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160326/c0cf049b/attachment.html>


More information about the vtkusers mailing list