[vtkusers] Looping help for iterations????Anyone

Shiva Bissoon sbissoo2 at hotmail.com
Tue Apr 10 14:48:54 EDT 2001


Hi all,
I have run into a problem with iterating and I was hoping someone would help 
me debug my program.
This program creates a simple cube with some particles in it.It is tedious 
and time consuming if I want to add 100 particles to place 100 actors,so, I 
tried having a loop so that I can loop through and add the actors but it 
doesn't seem to work.
I have shown how three particles would be added...using 
addactor2..addactor3..etc.
if someone can assist me I would be most grateful.

Shiva


#created on April 10th 2001, by Shiva Bissoon
#try and create an iteration for the particles.


catch {load vtktcl}

source vtkInt.tcl
source colors.tcl

#create a window and renderer
vtkRenderer ren1
vtkRenderWindow renWin
    renWin AddRenderer ren1
vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin

#to add a simple cube first
		#create a cube
			vtkCubeSource cuber
  			cuber SetXLength 3
  			cuber SetYLength 3
  			cuber SetZLength 3

		#create the mapper
			vtkPolyDataMapper mapper
  			mapper SetInput [cuber GetOutput]

		#create the actor
			vtkActor cube
			cube SetMapper mapper
			#[cube GetProperty] SetColor 0.8900 0.0900 0.0500
			 [cube GetProperty] SetOpacity 0.3


#creates some particles

		#define a Quadric definition
  			vtkQuadric quadric
   			quadric SetCoefficients .5 1 .2 0 .1 0 0 .2 0 0

		#define a sample function
			vtkSampleFunction sample
   			sample SetSampleDimensions 50 50 50
   			sample SetImplicitFunction quadric
   			#sample SetModelBounds 0 1 0 1 2 0
   			sample Update
   			sample Print

		#Create one elliptical surface F(x,y,z) = constant between range specified
  			vtkContourFilter contours
    			contours SetInput [sample GetOutput]
    			#contours GenerateValues 1 1.2 1.2

		#create the mapper
  			vtkPolyDataMapper contMapper
    			contMapper SetInput [contours GetOutput]
    			contMapper ScalarVisibilityOff

  			#vtkLODActor contourActor1
    			#contourActor1 SetMapper contMapper
			#[contourActor1 GetProperty] SetColor 1.0000 0.5490 0.0000
    			#contMapper SetScalarRange 0.0 1.2

	##create the actor--add iteration here!!!

#here is the test iteration
		vtkMath math

		for {set i 1} {$i < 4} {incr i} {

		   set $x [math Random -2 2]
		   set $y [math Random -1 1]
		   set $z [math Random -1 1]

  			vtkActor contActor$i
    			contActor$i SetMapper contMapper
    			contActor$i SetOrigin 1 10 0
			contActor$i SetPosition $x $y $z
    			#contActor SetPosition 0.3 .5  .5
    			[contActor GetProperty] SetColor 1 0 0
   			# contActor RotateX 10
		}
#it doesn't work.

		#add another actor
			vtkActor contActor2
    			contActor2 SetMapper contMapper
   		        contActor2 SetOrigin 1 10 0
   		        contActor2 SetPosition 0 .2  -.5
    			[contActor2 GetProperty] SetColor 0.2510 0.8784 0.8157
    			#turquoise
    			contActor RotateX 2
    			contActor RotateY 5

		#add a third actor
  			vtkActor contActor3
   		        contActor3 SetMapper contMapper
    			contActor3 SetOrigin 1 10 0
    			contActor3 SetPosition -.2 .25  .1
    			[contActor3 GetProperty] SetColor 1 0 1
   			 contActor RotateY 1




# add the actors and backgrd

  renWin SetSize 500 500
  #ren1 SetBackground 1.0000 0.8941 0.7098
  ren1 SetBackground 1 1 1
  ren1 AddActor contActor$i
  #ren1 AddActor outlineActor
  ren1 AddActor contActor2
  ren1 AddActor contActor3



#add the actor to the render window
ren1 AddActor cube

[ren1 GetActiveCamera] Azimuth 20
[ren1 GetActiveCamera] Elevation 10
[ren1 GetActiveCamera] Dolly 1.1
ren1 ResetCameraClippingRange


# enable user interface interactor
iren SetUserMethod {wm deiconify .vtkInteract}
iren Initialize
renWin Render


ren1 SetBackground 1.0000 0.9804 0.9804
renWin SetSize 300 300

# prevent the tk window from showing up then start the event loop
wm withdraw .



_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.





More information about the vtkusers mailing list