[vtkusers] Re: Re: 3D Axes For User Orientation...

Andrea Gavana andrea.gavana at polymtl.ca
Wed Jul 14 16:24:16 EDT 2004


Hello NG,

      thanks for all your kind suggestions, now this part of my code work as a 
dream... tomorrow I will try the modification proposed by Nick Hu, but I am 
satisfied of the results.

Thanks a lot for your help!

Andrea.

Selon Nick Hu <nhu at sten.sunnybrook.utoronto.ca>:

> Hi Andrea,
> 
> I made some changes to your python code, and now it looks right. But I don't
> know too much detail about the "layer" stuff in the vtkRendererWindow, so I
> don't know the cause of the previous pronlem.
> 
> The code:
> import vtkpython
> import Numeric
> 
> cone = vtkpython.vtkConeSource()
> coneMapper = vtkpython.vtkPolyDataMapper()
> coneMapper.SetInput(cone.GetOutput())
> coneActor = vtkpython.vtkActor()
> coneActor.SetMapper(coneMapper)
> 
> camAxes = vtkpython.vtkCamera()
> camAxes.ParallelProjectionOn()
> 
> renAxes = vtkpython.vtkRenderer()
> renAxes.InteractiveOff()
> renAxes.SetActiveCamera(camAxes)
> renAxes.SetViewport(0, 0, 0.25, 0.25)
> #renAxes.SetLayer(0)
> 
> def SyncCameras(renderer, event_string):
> 
>     cam = ren.GetActiveCamera()
>     camAxes.SetViewUp(cam.GetViewUp())
>     proj = cam.GetDirectionOfProjection()
>     x, y, z = cam.GetDirectionOfProjection()
> 
>     # figure out the distance away from 0 0 0
>     # if the renderer resets the camera to optimally inlcude all props
>     # composing the orientation marker
> 
>     bnds = renAxes.ComputeVisiblePropBounds()
>     x0, x1, y0, y1, z0, z1 = renAxes.ComputeVisiblePropBounds()
>     renAxes.ResetCamera(x0, x1, y0, y1, z0, z1)
>     pos = camAxes.GetPosition()
>     px, py, pz = camAxes.GetPosition()
>     d = Numeric.sqrt(px*px + py*py + pz*pz)
>     dproj = Numeric.sqrt(x*x + y*y + z*z)
> 
>     # reset the camera back along the unit vector of the
>     # direction of projection using our optimal distance
>     camAxes.SetFocalPoint(0,0,0)
>     camAxes.SetPosition(-d*x/dproj, -d*y/dproj, -d*z/dproj)
>     renAxes.ResetCameraClippingRange()
> 
> 
> 
> ren = vtkpython.vtkRenderer()
> ren.AddActor(coneActor)
> #renAxes.SetLayer(1)
> ren.AddObserver("StartEvent", SyncCameras)
> 
> renWin = vtkpython.vtkRenderWindow()
> #renWin.SetNumberOfLayers(2)
> 
> #renWin.AddRenderer(renAxes)
> renWin.SetSize(600,600)
> renWin.AddRenderer(ren)
> renWin.AddRenderer(renAxes)
> iren = vtkpython.vtkRenderWindowInteractor()
> iren.SetRenderWindow(renWin)
> 
> ## The corner axes
> xAxis = vtkpython.vtkArrowSource()
> xAxisMapper = vtkpython.vtkPolyDataMapper()
> xAxisMapper.SetInput(xAxis.GetOutput())
> xAxisActor = vtkpython.vtkActor()
> xAxisActor.SetMapper(xAxisMapper)
> xAxisActor.GetProperty().SetColor(1,0,0)
> 
> yAxis = vtkpython.vtkArrowSource()
> yAxisMapper = vtkpython.vtkPolyDataMapper()
> yAxisMapper.SetInput(yAxis.GetOutput())
> yAxisActor = vtkpython.vtkActor()
> yAxisActor.SetMapper(yAxisMapper)
> yAxisActor.GetProperty().SetColor(1,1,0)
> yAxisActor.RotateZ(90)
> 
> zAxis = vtkpython.vtkArrowSource()
> zAxisMapper = vtkpython.vtkPolyDataMapper()
> zAxisMapper.SetInput(zAxis.GetOutput())
> zAxisActor = vtkpython.vtkActor()
> zAxisActor.SetMapper(zAxisMapper)
> zAxisActor.GetProperty().SetColor(0,1,0)
> zAxisActor.RotateY(-90)
> 
> xLabel = vtkpython.vtkCaptionActor2D()
> xLabel.SetCaption("X")
> xLabel.SetAttachmentPoint(1,0,0)
> xLabel.LeaderOff()
> xLabel.BorderOff()
> xLabel.SetPosition(0,0)
> 
> yLabel = vtkpython.vtkCaptionActor2D()
> yLabel.SetCaption("Y")
> yLabel.SetAttachmentPoint(0,1,0)
> yLabel.LeaderOff()
> yLabel.BorderOff()
> yLabel.SetPosition(0,0)
> 
> zLabel = vtkpython.vtkCaptionActor2D()
> zLabel.SetCaption("Z")
> zLabel.SetAttachmentPoint(0,0,1)
> zLabel.LeaderOff()
> zLabel.BorderOff()
> zLabel.SetPosition(0,0)
> 
> Axes3D = vtkpython.vtkPropAssembly()
> Axes3D.AddPart(xAxisActor)
> Axes3D.AddPart(yAxisActor)
> Axes3D.AddPart(zAxisActor)
> Axes3D.AddPart(xLabel)
> Axes3D.AddPart(yLabel)
> Axes3D.AddPart(zLabel)
> 
> renAxes.AddActor(Axes3D)
> 
> iren.Initialize()
> iren.Start()
> 
> 
> 
> Nick
> >
> > 2) By translating (I hope correctly) the code from Goodwin Lawlor found at
> this
> > url:
> >
> > http://www.bioengineering-research.com/vtk/axes_example2.tcl
> >
> > I was able to create the orientation axes at the bottom left of the VTK
> window,
> > but I'm facing some strange behaviors. When I rotate the main Actor (a
> Cone, in
> > my example), I get a sequence of superimposing images that represent all
> the
> > rotation I have done on my cone. I can not explain it clearly, I've tried
> to
> > attach an image but the vtkuser server told me that it was too big, so I
> posted
> > an image explining what I said at this url:
> >
> > http://xoomer.virgilio.it/infinity77/vtkproblem.jpg
> >
> > It's a strange behavior, I don't know why it happens...
> >
> > I post here my python code, if someone has comments on this, please let me
> > know... probably I have done something wrong in traslating it from tcl...
> >
> > Thank you for every suggestion.
> >
> > Andrea.
> >
> > # BEGIN PYTHON CODE
> >
> > import vtkpython
> > import Numeric
> >
> > cone = vtkpython.vtkConeSource()
> > coneMapper = vtkpython.vtkPolyDataMapper()
> > coneMapper.SetInput(cone.GetOutput())
> > coneActor = vtkpython.vtkActor()
> > coneActor.SetMapper(coneMapper)
> >
> > camAxes = vtkpython.vtkCamera()
> > camAxes.ParallelProjectionOn()
> >
> > renAxes = vtkpython.vtkRenderer()
> > renAxes.InteractiveOff()
> > renAxes.SetActiveCamera(camAxes)
> > renAxes.SetViewport(0, 0, 0.25, 0.25)
> > renAxes.SetLayer(1)
> >
> > def SyncCameras(renderer, event_string):
> >
> >     cam = ren.GetActiveCamera()
> >     camAxes.SetViewUp(cam.GetViewUp())
> >     proj = cam.GetDirectionOfProjection()
> >     x, y, z = cam.GetDirectionOfProjection()
> >
> >     # figure out the distance away from 0 0 0
> >     # if the renderer resets the camera to optimally inlcude all props
> >     # composing the orientation marker
> >
> >     bnds = renAxes.ComputeVisiblePropBounds()
> >     x0, x1, y0, y1, z0, z1 = renAxes.ComputeVisiblePropBounds()
> >     renAxes.ResetCamera(x0, x1, y0, y1, z0, z1)
> >     pos = camAxes.GetPosition()
> >     px, py, pz = camAxes.GetPosition()
> >     d = Numeric.sqrt(px*px + py*py + pz*pz)
> >     dproj = Numeric.sqrt(x*x + y*y + z*z)
> >
> >     # reset the camera back along the unit vector of the
> >     # direction of projection using our optimal distance
> >     camAxes.SetFocalPoint(0,0,0)
> >     camAxes.SetPosition(-d*x/dproj, -d*y/dproj, -d*z/dproj)
> >     renAxes.ResetCameraClippingRange()
> >
> >
> > ren = vtkpython.vtkRenderer()
> > ren.AddActor(coneActor)
> >
> > ren.AddObserver("StartEvent", SyncCameras)
> >
> > renWin = vtkpython.vtkRenderWindow()
> > renWin.SetNumberOfLayers(2)
> > renWin.AddRenderer(renAxes)
> > renWin.SetSize(600,600)
> > renWin.AddRenderer(ren)
> > iren = vtkpython.vtkRenderWindowInteractor()
> > iren.SetRenderWindow(renWin)
> >
> > ## The corner axes
> > xAxis = vtkpython.vtkArrowSource()
> > xAxisMapper = vtkpython.vtkPolyDataMapper()
> > xAxisMapper.SetInput(xAxis.GetOutput())
> > xAxisActor = vtkpython.vtkActor()
> > xAxisActor.SetMapper(xAxisMapper)
> > xAxisActor.GetProperty().SetColor(1,0,0)
> >
> > yAxis = vtkpython.vtkArrowSource()
> > yAxisMapper = vtkpython.vtkPolyDataMapper()
> > yAxisMapper.SetInput(yAxis.GetOutput())
> > yAxisActor = vtkpython.vtkActor()
> > yAxisActor.SetMapper(yAxisMapper)
> > yAxisActor.GetProperty().SetColor(1,1,0)
> > yAxisActor.RotateZ(90)
> >
> > zAxis = vtkpython.vtkArrowSource()
> > zAxisMapper = vtkpython.vtkPolyDataMapper()
> > zAxisMapper.SetInput(zAxis.GetOutput())
> > zAxisActor = vtkpython.vtkActor()
> > zAxisActor.SetMapper(zAxisMapper)
> > zAxisActor.GetProperty().SetColor(0,1,0)
> > zAxisActor.RotateY(-90)
> >
> > xLabel = vtkpython.vtkCaptionActor2D()
> > xLabel.SetCaption("X")
> > xLabel.SetAttachmentPoint(1,0,0)
> > xLabel.LeaderOff()
> > xLabel.BorderOff()
> > xLabel.SetPosition(0,0)
> >
> > yLabel = vtkpython.vtkCaptionActor2D()
> > yLabel.SetCaption("Y")
> > yLabel.SetAttachmentPoint(0,1,0)
> > yLabel.LeaderOff()
> > yLabel.BorderOff()
> > yLabel.SetPosition(0,0)
> >
> > zLabel = vtkpython.vtkCaptionActor2D()
> > zLabel.SetCaption("Z")
> > zLabel.SetAttachmentPoint(0,0,1)
> > zLabel.LeaderOff()
> > zLabel.BorderOff()
> > zLabel.SetPosition(0,0)
> >
> > Axes3D = vtkpython.vtkPropAssembly()
> > Axes3D.AddPart(xAxisActor)
> > Axes3D.AddPart(yAxisActor)
> > Axes3D.AddPart(zAxisActor)
> > Axes3D.AddPart(xLabel)
> > Axes3D.AddPart(yLabel)
> > Axes3D.AddPart(zLabel)
> >
> > renAxes.AddActor(Axes3D)
> >
> > iren.Initialize()
> > iren.Start()
> >
> > # END PYTHON CODE
> >
> 
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at:
> <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> 






More information about the vtkusers mailing list