This is an archival dump of old wiki content --- see scipy.org for current material.
Please see http://scipy-cookbook.readthedocs.org/

Attachment 'Vis_quad.py'

Download

   1 #!/usr/bin/env python
   2 """
   3 This example demonstrates the use of the contour filter, and the use of
   4 the vtkSampleFunction to generate a volume of data samples from an
   5 implicit function.
   6 
   7 Conversion of VisQuad.py of the VTK example to tvtk
   8 (and some additions).
   9 """
  10 
  11 from enthought.tvtk.api import tvtk
  12 
  13 # General form for a quadric to create an elliptical data field.
  14 quadric = tvtk.Quadric(coefficients=(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0))
  15 
  16 # Sample implicit function over a specified x-y-z range.
  17 # (here it defaults to -1,1 in the x,y,z directions).
  18 sample = tvtk.SampleFunction(implicit_function=quadric,
  19                              sample_dimensions=(30, 30, 30))
  20 
  21 # Create five surfaces F(x,y,z) = constant between range specified:
  22 contours = tvtk.ContourFilter(input=sample.output)
  23 contours.generate_values(5, 0.0, 1.2)
  24 
  25 contMapper = tvtk.PolyDataMapper(input=contours.output, scalar_range=(0.0, 1.2))
  26 contActor = tvtk.Actor(mapper=contMapper)
  27 
  28 # outline around the data.
  29 outline = tvtk.OutlineFilter(input=sample.output)
  30 outlineMapper = tvtk.PolyDataMapper(input=outline.output)
  31 outlineActor = tvtk.Actor(mapper=outlineMapper)
  32 outlineActor.property.color=(0, 0, 0)
  33 
  34 # The usual rendering stuff.
  35 ren = tvtk.Renderer(background=(0.95, 0.95, 1.0))
  36 renWin = tvtk.RenderWindow()
  37 renWin.add_renderer(ren)
  38 iren = tvtk.RenderWindowInteractor(render_window=renWin)
  39 ren.add_actor(contActor)
  40 ren.add_actor(outlineActor)
  41 
  42 # some nice view:
  43 ren.active_camera.elevation(10)
  44 
  45 iren.initialize()
  46 renWin.render()
  47 
  48 # save scene as png:
  49 renderLarge = tvtk.RenderLargeImage(input=ren, magnification=1)
  50 writer = tvtk.PNGWriter(input=renderLarge.output, file_name="vis_quad.png")
  51 writer.write()
  52 
  53 # interactive part starts here:
  54 iren.start()

New Attachment

File to upload
Rename to
Overwrite existing attachment of same name

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.