[vtkusers] camera follower in 3D
Miroslav Drahos
mdrahos at aurisrobotics.com
Fri Mar 25 21:50:14 EDT 2016
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>
Cc: 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160326/57343f79/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: follow1.png
Type: image/png
Size: 7559 bytes
Desc: follow1.png
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160326/57343f79/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: follow2.png
Type: image/png
Size: 9139 bytes
Desc: follow2.png
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160326/57343f79/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: follow3.png
Type: image/png
Size: 8807 bytes
Desc: follow3.png
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160326/57343f79/attachment-0005.png>
More information about the vtkusers
mailing list