[vtkusers] How can I get a combination of Glyph3D and Follower?
Day, Robert
Robert.Day at health.wa.gov.au
Sun Nov 20 22:32:21 EST 2005
Thanks for this suggestion Sylvain,
I have taken some time to implement it, because it doesn't seem to work and I thought it should.
I have tried C++, python and tcl, and in each case the glyphs do not face the camera individually but move as a block which seems to move rapidly in and out along the Z axis.
In thinking about this I was led to my eventual solution and the reason for this behaviour. Followers appear to rotate about their own actor origin to face the camera. My points are a long way from (0,0,0). Within the vtkFollower the geometry (ie the glyph) was placed at (x,y,z), but the rotations were all occurring about (0,0,0); in this case the World origin.
The solution was to generate a single glyph at (0,0,0) and copy instances of that in to the vtkFollower, then use the SetPosition() method of vtkFollower to put each glyph instance at the appropriate point.
My problem now is to get each disk to be filled white with a dark circle around the edge, but I assume a texture will sort that out fairly easily.
Thanks to everyone who helped.
Rob.
Example solution:
#!/usr/bin/env python
rPoints = vtk.vtkPolyDataReader()
rPoints.SetFileName(FILE_ROOT + "/asisLeft.vtk")
pts = vtk.vtkPolyData()
pts = rPoints.GetOutput()
pts.Update()
# Create graphics stuff
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
style = vtk.vtkInteractorStyleTrackballCamera()
iren.SetInteractorStyle(style)
# Make a disk with a filled centre
C = vtk.vtkDiskSource()
C.SetInnerRadius(0)
C.SetOuterRadius(3)
C.SetCircumferentialResolution(10)
C.SetRadialResolution(1)
# create a cloud of followers, one for each point
P = vtk.vtkPoints()
P = pts.GetPoints()
npts = P.GetNumberOfPoints()
for i in range(npts):
# version with no glyphers at all
polyDataMapper = vtk.vtkPolyDataMapper()
polyDataMapper.SetInput(C.GetOutput())
follower = vtk.vtkFollower()
follower.SetMapper(polyDataMapper)
follower.SetCamera(ren.GetActiveCamera())
follower.SetPosition(P.GetPoint(i)) # this is the important bit
ren.AddActor(follower)
ren.GetActiveCamera().ParallelProjectionOn()
ren.ResetCameraClippingRange()
renWin.SetSize(300, 300)
iren.Initialize()
renWin.Render()
iren.Start()
> -----Original Message-----
> From: Sylvain Jaume [mailto:sylvain.jaume at kitware.com]
> Sent: Tuesday, 8 November 2005 9:20 PM
> To: Day, Robert
> Cc: vtkusers at vtk.org
> Subject: Re: [vtkusers] How can I get a combination of Glyph3D and
> Follower?
>
>
> Hi Rob,
>
> You could execute the pipeline for every landmark point:
>
> double *point;
> vtkPoints *newPoints;
> vtkPolyData *newPolyData;
> vtkGlyph3D *glyph3D;
> vtkPolyDataMapper *polyDataMapper;
> vtkFollower *follower;
> vtkSphereSource *sphereSource = vtkSphereSource::New();
> vtkRenderer *renderer = vtkRenderer::New();
>
> for (int i=0; i<numPoints; i++ )
> {
> point = landmarkPolyData->GetPoint(i);
>
> newPoints = vtkPoints::New();
> newPoints->InsertNextPoint(point);
>
> newPolyData = vtkPolyData::New();
> newPolyData->SetPoints(newPoints);
> newPoints->Delete();
>
> glyph3D = vtkGlyph3D::New();
> glyph3D->SetInput(newPolyData);
> newPolyData->Delete();
>
> polyDataMapper = vtkPolyDataMapper::New();
> polyDataMapper->SetInput(glyph3D->GetOutput());
> glyph3D->Delete();
>
> follower = vtkFollower::New();
> follower->SetMapper(polyDataMapper);
> polyDataMapper->Delete();
>
> renderer->AddActor(follower);
> follower->Delete();
> }
>
> vtkRenderWindow *renderWindow = vtkRenderWindow::New();
> renderWindow->AddRender(renderer);
> renderer->Delete();
> renderWindow->Render();
>
> Cheers,
> Sylvain
>
> Day, Robert wrote:
>
> >Hi Sylvain,
> >
> >Yes I did, as it was the obvious thing to do. That makes my
> point cloud rotate (around its centre ?) as a whole to follow
> the camera, moving the glyphs away from where they are supposed to be.
> >
> >What I need is for each glyph to rotate around its centre so
> that they face the camera but keep their proper positions.
> >
> >Rob.
> >
> >
> >
> >>-----Original Message-----
> >>From: Sylvain Jaume [mailto:sylvain.jaume at kitware.com]
> >>Sent: Tuesday, 8 November 2005 8:04 PM
> >>To: Day, Robert
> >>Cc: vtkusers at vtk.org
> >>Subject: Re: [vtkusers] How can I get a combination of Glyph3D and
> >>Follower?
> >>
> >>
> >>Hi Rob,
> >>
> >>Have you tried vtkGlyph3D -> vtkPolyDataMapper -> vtkFollower ?
> >>
> >>Cheers,
> >>Sylvain
> >>
> >>
> >>
> ><snip>
> >_______________________________________________
> >This is the private VTK discussion list.
> >Please keep messages on-topic. Check the FAQ at:
http://www.vtk.org/Wiki/VTK_FAQ
>Follow this link to subscribe/unsubscribe:
>http://www.vtk.org/mailman/listinfo/vtkusers
>
>
>
More information about the vtkusers
mailing list