
TCL/TK Part 5: Using primitive geometric shapes and texturing
You can download the sphere.tcl
or just copy this code into a text doc with a tcl extention.
classvtkSphereSource reference link.
######################################################################## package require vtk #-------------------------------------------------------- # map to graphics library # actor coordinates geometry, properties, transformation #------------------------------------------------------- # create a window to render into # create an interactor # add the sphere # Render an image; since no lights/cameras specified, created automatically # prevent the tk window from showing up then start the event loop |
After you have copied code check that it works
Now let us add a cylinder.
Add this code under the sphere code
classvtkCylinderSource reference link.
#------------------------------------------------------- vtkTransform t1 vtkTransformPolyDataFilter f1 vtkDataSetMapper cylinderMap vtkActor cylinderActor #------------------------------------------------------- |
Now near the bottom of the original code you should
see a
ren1 AddActor sphereActor
below it add
ren1 AddActor cylinderActor
Now test it to see if it works if iot dont work here is file to show you what it looks like sphereCylinder.tcl
Now let's add a cone.
Add this code below the cylinder code
classvtkConeSource reference link.
#------------------------------------------------------- vtkConeSource cone vtkPolyDataMapper coneMapper coneMapper SetInput [cone GetOutput] vtkActor coneActor #------------------------------------------------------- |
Now add
ren1 AddActor coneActor
below ren1 AddActor cylinderActor
Check to see that it works if it does not work here is the file that it should look like sphereCylinderCone.tcl
Now lets add a cube
Add this code below the cone code
classvtkCubeSource reference link.
#------------------------------------------------------- vtkPolyDataMapper cubeMapper |
Now add
ren1 AddActor cubeActor
below ren1 AddActor coneActor
Check to see that it works if it does not work here is the file that it should look like sphereCylinderConeCube.tcl
Now let's texure a sphere
in this code you use the vtkTexturedSphereSource object instead of the vtkSphereSource
object
Here is the code or download sphereTexture.tcl
classvtkTextureMapToSphere reference link.
############################################################### # Create the RenderWindow, Renderer and both Actors renWin AddRenderer ren1 vtkTexturedSphereSource tss # load 2 differenttexture map vtkPNMReader pnmReader vtkTexture atext
# Add the actors to the renderer, set the background and size # render the image # prevent the tk window from showing up then start the event loop ############################################################### |
Now check to see if code works
In code I have imported 2 textures a vtkBMPReader and vtkPNMReader respectfully
bmpReader and pnmReader.
I have commented out the pnmReader I want you to uncomment it and comment
out the bmpReader
now check that it works.
Learn about VTK Class Hierarchy: http://www.vtk.org/doc/release/4.0/html/hierarchy.html
The site also has more explanation of all the objects and how to use them.
Homework
1) Create 3 diffrent pictures in each picture change position, color, and
resolution on the cube, sphere, cone, and cylinder.
2) Add a texture to the cylinder. Hint goto
http://www.vtk.org/doc/release/4.0/html/classvtkTextureMapToCylinder.html
for more info