[vtkusers] VTK Python Examples?

Dean N. Williams williams13 at llnl.gov
Fri Dec 6 11:25:58 EST 2002


Jose,

    Thank you for all you can do. I am finding it difficult to find the 
library calls in
    Python that are needed to display, adjust, etc. for Vtk. Examples 
are the best
    way for new users to learn, this is why I think it is important to 
have them.

    Again, thanks!

Best regards,
    Dean

>On Wednesday 04 December 2002 17:11, Prabhu Ramachandran wrote:
>  
>
>>Hi Dean,
>>
>>    
>>
>>>>>>>"DNW" == Dean N Williams <williams13 at llnl.gov> writes:
>>>>>>>              
>>>>>>>
>>    DNW>     Can you tell me if the all the Python examples that were
>>    DNW> included in Vtk 3.0 are now in Vtk 4.1.1?  (That is, the
>>    DNW> Vtk/Python test/example programs should be in the
>>    DNW> VTK/Graphics/Testing/Python directory.  In version 4.0, all
>>    DNW> the Python examples were not included.)
>>
>>Unfortunately no.  All the Tcl examples that you see are new ones.
>>Someone has to take the pains to either write new Python examples or
>>add upgraded versions of the older ones from 3.2 or atleast translate
>>all the existing VTK 4.x Tcl examples to Python.  I believe the
>>recommended approach with VTK 4.x is to write well documented examples
>>rather than simply use the older ones from 3.2.  This is going to take
>>some work.  I'm swamped with things to do so haven't volunteered for
>>the task.  I guess translating the existing VTK 4.x Tcl examples to
>>Python should not be too hard.  Any volunteers?
>>
>>    
>>
>
>I am not volunteering, just attaching a "translation" of TenEllip.tcl to 
>TenEllip.py.
>
>Comments welcome. If is is ok I will try to find time to do one or two such 
>translations a week. In Examples there are 103 .tcl files and in 
>*/Testing/Tcl I counted 346. If there are no more files it means that I will 
>have the job done in 4 to 8 years ;-)
>
>See you then!
>
>Regards 
>
>Ze Paulo
>
>
>  
>
>------------------------------------------------------------------------
>
>#!/usr/bin/env python
># create tensor ellipsoids
>
>from vtkpython import *
>
># Create the RenderWindow, Renderer and interactive renderer
>#
>ren1 = vtkRenderer()
>renWin = vtkRenderWindow()
>renWin.AddRenderer( ren1 )
>iren = vtkRenderWindowInteractor()
>iren.SetRenderWindow( renWin )
>
>#
># Create tensor ellipsoids
>#
>
># generate tensors
>ptLoad = vtkPointLoad()
>ptLoad.SetLoadValue( 100.0 )
>ptLoad.SetSampleDimensions( 6, 6, 6 )
>ptLoad.ComputeEffectiveStressOn()
>ptLoad.SetModelBounds( -10, 10, -10, 10, -10, 10 )
>
># extract plane of data
>plane = vtkImageDataGeometryFilter()
>plane.SetInput( ptLoad.GetOutput() )
>plane.SetExtent( 2, 2, 0, 99, 0, 99 )
>
># Generate ellipsoids
>sphere = vtkSphereSource()
>sphere.SetThetaResolution( 8 )
>sphere.SetPhiResolution( 8 )
>ellipsoids = vtkTensorGlyph()
>ellipsoids.SetInput( ptLoad.GetOutput() )
>ellipsoids.SetSource( sphere.GetOutput() )
>ellipsoids.SetScaleFactor( 10 )
>ellipsoids.ClampScalingOn()
>  
>ellipNormals = vtkPolyDataNormals()
>ellipNormals.SetInput( ellipsoids.GetOutput() )
>
># Map contour
>lut = vtkLogLookupTable()
>lut.SetHueRange( .6667, 0.0 )
>ellipMapper = vtkPolyDataMapper()
>ellipMapper.SetInput( ellipNormals.GetOutput() )
>ellipMapper.SetLookupTable( lut )
>plane.Update() #force update for scalar range
>ellipMapper.SetScalarRange( plane.GetOutput().GetScalarRange() )
>
>ellipActor = vtkActor()
>ellipActor.SetMapper( ellipMapper )
>#
># Create outline around data
>#
>outline = vtkOutlineFilter()
>outline.SetInput( ptLoad.GetOutput())
>
>outlineMapper = vtkPolyDataMapper()
>outlineMapper.SetInput( outline.GetOutput() )
>
>outlineActor = vtkActor()
>outlineActor.SetMapper( outlineMapper )
>outlineActor.GetProperty().SetColor( 0, 0, 0 )
>
>#
># Create cone indicating application of load
>#
>coneSrc = vtkConeSource()
>coneSrc.SetRadius( .5 )
>coneSrc.SetHeight( 2 )
>coneMap = vtkPolyDataMapper()
>coneMap.SetInput( coneSrc.GetOutput() )
>coneActor = vtkActor()
>coneActor.SetMapper( coneMap )
>coneActor.SetPosition( 0, 0, 11 )
>coneActor.RotateY( 90 )
>coneActor.GetProperty().SetColor( 1, 0, 0 )
>
>camera = vtkCamera()
>camera.SetFocalPoint( 0.113766, -1.13665, -1.01919 )
>camera.SetPosition( -29.4886, -63.1488, 26.5807 )
>camera.SetViewAngle( 24.4617 )
>camera.SetViewUp( 0.17138, 0.331163, 0.927879 )
>camera.SetClippingRange( 1, 100 )
>
>ren1.AddActor( ellipActor )
>ren1.AddActor( outlineActor )
>ren1.AddActor( coneActor )
>ren1.SetBackground( 1.0, 1.0, 1.0 )
>ren1.SetActiveCamera( camera )
>
>renWin.SetSize( 400, 400 )
>renWin.Render()
>
>iren.Initialize ()
>iren.Start()
>
>  
>





More information about the vtkusers mailing list