DEMOSTRACION

**//__DEMOSTRACION__//**

**Este es un ejemplo de un cubo que se utilizara en la presentacion:**

# import vtk python module import vtk # create polygonal cube geometry #  here a procedural source object is used, #  a source can also be, e.g., a file reader cube = vtk.vtkCubeSource cube.SetBounds(-1,1,-1,1,-1,1)
 * 1) File: cube.py

# map to graphics library #  a mapper is the interface between the visualization pipeline #  and the graphics model mapper = vtk.vtkPolyDataMapper mapper.SetInput(cube.GetOutput); # connect source and mapper

# an actor represent what we see in the scene, # it coordinates the geometry, its properties, and its transformation aCube = vtk.vtkActor aCube.SetMapper(mapper); aCube.GetProperty.SetColor(0,1,0); # cube color green # a renderer and render window ren1 = vtk.vtkRenderer renWin = vtk.vtkRenderWindow renWin.AddRenderer(ren1);

# an interactor iren = vtk.vtkRenderWindowInteractor iren.SetRenderWindow(renWin);

# add the actor to the scene ren1.AddActor(aCube); ren1.SetBackground(1,1,1); # Background color white

# render an image (lights and cameras are created automatically) renWin.Render;

# begin mouse interaction iren.Start;

__Se mira asi:__

Este segundo ejemplo es una esfera pero para este se crea un archivo .VTK antes: # vtk DataFile Version 2.0 A polygonal sphere with point scalars and vectors and cell scalars ASCII // ASCII, could have been BINARY DATASET POLYDATA // POLYDATA, could have been something else

POINTS 938 float // 938 xyz coordinates, polydata must have points... 0 -1 0   0.207912 -0.978148 0    ...

POLYGONS 470 2350 // 470 polygons and 2350 entries in the array 4 0 2 3 1        // the line 4 0 2 3 1 means a     4 2 4 5 3         // quadraliteral (4) with vertices at points ...              // 0, 2, 3, and 1. 4 0 2 3 1 is five digits => // 470x5 = 2350

POINT_DATA 938 // here follows the data specified at the 938 points SCALARS my_scalars float 1 // first scalar values... LOOKUP_TABLE default // choose default or specify an own lut 0 0 0 0.04 ...

VECTORS my_vectors float // ...then vector values 0.168204 -0.978148 0.122207   0.0642482 -0.978148 0.197736

CELL_DATA 470 // here follows the data specified at the 470 cells SCALARS cell_scalars float 1 // only scalars for the cells LOOKUP_TABLE default 0.000730178 0.000300185 7.9128e-05 ...

//Y despues se utiliza el script de python://
 * 1) File: sphere1.py

# import python module import vtk

# our data source, a PolyDataReader reader = vtk.vtkPolyDataReader reader.SetFileName("sphere.vtk") reader.Update # by calling Update we read the file

# find the range of the point scalars a,b = reader.GetOutput.GetPointData.GetScalars.GetRange nm = reader.GetOutput.GetPointData.GetScalars.GetName

# show how to print a string in python, it is similar to C-style sprintf print "Range of %s: %4.2f-%4.2f" %(nm,a,b)

# transfer function (lookup table) for mapping point scalar data # to colors (parent class is vtkScalarsToColors) lut = vtk.vtkColorTransferFunction lut.AddRGBPoint(a,        0.0, 0.0, 1.0) lut.AddRGBPoint(a+(b-a)/4, 0.0, 0.5, 0.5) lut.AddRGBPoint(a+(b-a)/2, 0.0, 1.0, 0.0) lut.AddRGBPoint(b-(b-a)/4, 0.5, 0.5, 0.0) lut.AddRGBPoint(b,        1.0, 0.0, 0.0)

# the mapper that will use the lookup table mapper = vtk.vtkPolyDataMapper mapper.SetLookupTable(lut) mapper.SetScalarRange(a,b) mapper.SetInput(reader.GetOutput) # connection # important! tell which data you want to use # here we use the point data mapper.SetScalarModeToUsePointData

# the actor myActor = vtk.vtkActor myActor.SetMapper( mapper )

# a colorbar to display the colormap scalarBar = vtk.vtkScalarBarActor scalarBar.SetLookupTable( mapper.GetLookupTable ) scalarBar.SetTitle("Point scalar value") scalarBar.SetOrientationToHorizontal scalarBar.GetLabelTextProperty.SetColor(0,0,1) scalarBar.GetTitleTextProperty.SetColor(0,0,1)

# position it in window coord = scalarBar.GetPositionCoordinate coord.SetCoordinateSystemToNormalizedViewport coord.SetValue(0.1,0.05) scalarBar.SetWidth(.8) scalarBar.SetHeight(.15)

# renderer and render window ren = vtk.vtkRenderer ren.SetBackground(1, 1, 1) renWin = vtk.vtkRenderWindow renWin.SetSize(512, 512) renWin.AddRenderer( ren )

# render window interactor iren = vtk.vtkRenderWindowInteractor iren.SetRenderWindow( renWin )

# add the actors to the renderer ren.AddActor( myActor ) ren.AddActor( scalarBar )

# render renWin.Render

# initialize and start the interactor iren.Initialize iren.Start

Y se mira asi:

Existe un tercer ejemplo que se mira de esta forma:



Para ver los ejemplos en linea dirigase a esta pagina:

http://www.it.uu.se/edu/course/homepage/avgrafik/vt06/ComputerExercises/vtkexamples.shtml

Grupo No. 4