[vtkusers] R: R: vtk AddActor

Zampini Samuele samuele.zampini at epfl.ch
Wed Aug 26 03:31:17 EDT 2009


Thanks to all for help.

Anyway, I have one more question: when I try to use the RemoveActor (see the code below) it says me that the actor Cone1 is not a "global actor".

Now, I can agree this but I can not understand why, since I have already defined the actor pushig the button to open the cone 1 (and opening it)...

Any idea?

Thanks,

samuele










class VtkCones:

        def __init__(self, wTree):

		self.window = wTree.get_widget("hbox2")
		self.window.connect("destroy", gtk.mainquit)
		self.window.connect("delete_event", gtk.mainquit)


		self.vtkda = Canvas3D(None)
		self.vtkda.show()

		hbox = gtk.HBox(spacing=5)
		hbox.show()
		hbox.pack_start(self.vtkda)
    
		self.window.add(hbox)
    		self.window.set_size_request(400, 400)

		self.window.show()

		self.ren = vtk.vtkRenderer()
		self.ren.SetBackground(.5, .5, .5)

		self.vtkda.GetRenderWindow().AddRenderer(self.ren)



#This function will allow us to print 2 cones
	
	def open_vtk(self, widget):

                # Cone1
                cone1 = vtk.vtkConeSource()
                # Look at this: I chose a Height of 1 (let's say mm)
                # and to cut it (see [*1]) at 0.5 (the middle of the
                # height) I have to put the origin of the clip plane
                # at 0.0005, like if it is in m. I can not understand
                # why, but it works properly.
                cone1.SetHeight(1)
                cone1.SetRadius(0.5)
                cone1.SetResolution(150)

                # Map to graphics library
                cone1_map = vtk.vtkPolyDataMapper()
                cone1_map.SetInputConnection( cone1.GetOutputPort() )

                # Actor coordinates geometry, properties, transformation
                cone1_actor = vtk.vtkActor()
                cone1_actor.SetMapper( cone1_map )
                cone1_actor.SetPosition(0,3,0)
                cone1_actor.GetProperty().SetColor(1,0,0)  # cone1 is the
                # red one
                # Create a clipping plane to clip cone 1
                plane1 = vtk.vtkPlane()
                plane1.SetOrigin(0.0005,0.0,0.0)# [*1]
                plane1.SetNormal(-1.0,0.0,0.0)
                cone1_map.AddClippingPlane( plane1 )


		#  Cone2
		cone2 = vtk.vtkConeSource()
		cone2.SetHeight(1)
		cone2.SetRadius(0.5)
		cone2.SetResolution(150)
		
		# map to graphics library
		cone2_map = vtk.vtkPolyDataMapper()
		cone2_map.SetInput( cone2.GetOutput() )

		# actor coordinates geometry, properties, transfvaormation
		cone2_actor = vtk.vtkActor()
		cone2_actor.SetMapper(cone2_map)
		cone2_actor.SetPosition(0,3,0)
		# cone2_actor.RotateY(90)
		cone2_actor.RotateZ(180)
		cone2_actor.GetProperty().SetColor(0,0,0)#  cone2 is the
		#                                           black one
        
		# create a clipping plane to clip cone 2
		plane2 = vtk.vtkPlane()
		plane2.SetOrigin(0.0005,0.0,0.0)
		plane2.SetNormal(1.0,0.0,0.0)
		cone2_map.AddClippingPlane(plane2)

		# create axes
		axes = vtk.vtkAxes()
		axes.SetOrigin(0,0,0)
		axes_tubes = vtk.vtkTubeFilter()
		axes_tubes.SetInputConnection(axes.GetOutputPort())
		axes_tubes.SetRadius(axes.GetScaleFactor()/100.0);# questo comando
		#						    serve per cambiare
		#						    la dimensione degli
		#						    assi del SdR
		axes_tubes.SetNumberOfSides(3)
		axes_mapper = vtk.vtkPolyDataMapper()
		axes_mapper.SetInputConnection(axes_tubes.GetOutputPort())
		axes_actor = vtk.vtkActor()
		axes_actor.SetMapper(axes_mapper)


		'''self.ren = vtk.vtkRenderer()
		self.ren.SetBackground(.5, .5, .5)

		self.vtkda.GetRenderWindow().AddRenderer(self.ren) '''
		self.ren.AddActor(cone1_actor)
		self.ren.AddActor(cone2_actor)
		self.ren.AddActor(axes_actor)
		self.ren.ResetCamera()


# With this function we could print 1st cone

	def cone1(self, widget):

                # Cone1
                cone1 = vtk.vtkConeSource()
                # Look at this: I chose a Height of 1 (let's say mm)
                # and to cut it (see [*1]) at 0.5 (the middle of the
                # height) I have to put the origin of the clip plane
                # at 0.0005, like if it is in m. I can not understand
                # why, but it works properly.
                cone1.SetHeight(1)
                cone1.SetRadius(0.5)
                cone1.SetResolution(150)

                # Map to graphics library
                cone1_map = vtk.vtkPolyDataMapper()
                cone1_map.SetInputConnection( cone1.GetOutputPort() )

                # Actor coordinates geometry, properties, transformation
                cone1_actor = vtk.vtkActor()
                cone1_actor.SetMapper( cone1_map )
                cone1_actor.SetPosition(0,3,0)
                cone1_actor.GetProperty().SetColor(1,0,0)  # cone1 is the
		                                          # red one
                # Create a clipping plane to clip cone 1
                plane1 = vtk.vtkPlane()
                plane1.SetOrigin(0.0005,0.0,0.0)# [*1]
                plane1.SetNormal(-1.0,0.0,0.0)
                cone1_map.AddClippingPlane( plane1 )


		'''# create axes
		axes = vtk.vtkAxes()
		axes.SetOrigin(0,0,0)
		axes_tubes = vtk.vtkTubeFilter()
		axes_tubes.SetInputConnection(axes.GetOutputPort())
		axes_tubes.SetRadius(axes.GetScaleFactor()/100.0);# questo comando
		#						    serve per cambiare
		#						    la dimensione degli
		#						    assi del SdR
		axes_tubes.SetNumberOfSides(3)
		axes_mapper = vtk.vtkPolyDataMapper()
		axes_mapper.SetInputConnection(axes_tubes.GetOutputPort())
		axes_actor = vtk.vtkActor()
		axes_actor.SetMapper(axes_mapper)'''


		''' self.ren = vtk.vtkRenderer()
		self.ren.SetBackground(.5, .5, .5)

		self.vtkda.GetRenderWindow().AddRenderer(self.ren) '''
		self.ren.AddActor(cone1_actor)
		# ren.AddActor(axes_actor)
		self.ren.ResetCamera()


# With this function we could print 2nd cone

	def cone2(self, widget):

                # Cone2
		cone2 = vtk.vtkConeSource()
		cone2.SetHeight(1)
		cone2.SetRadius(0.5)
		cone2.SetResolution(150)
		
		# Map to graphics library
		cone2_map = vtk.vtkPolyDataMapper()
		cone2_map.SetInput( cone2.GetOutput() )

		# Actor coordinates geometry, properties, transfvaormation
		cone2_actor = vtk.vtkActor()
		cone2_actor.SetMapper(cone2_map)
		cone2_actor.SetPosition(0,3,0)
		# Cone_actor.RotateY(90)
		cone2_actor.RotateZ(180)
		cone2_actor.GetProperty().SetColor(0,0,0)#  cone2 is the
		#                                           black one
        
		# Create a clipping plane to clip cone 2
		plane2 = vtk.vtkPlane()
		plane2.SetOrigin(0.0005,0.0,0.0)
		plane2.SetNormal(1.0,0.0,0.0)
		cone2_map.AddClippingPlane(plane2)

		"""# create axes
		axes = vtk.vtkAxes()
		axes.SetOrigin(0,0,0)
		axes_tubes = vtk.vtkTubeFilter()
		axes_tubes.SetInputConnection(axes.GetOutputPort())
		axes_tubes.SetRadius(axes.GetScaleFactor()/100.0);# questo comando
		#						    serve per cambiare
		#						    la dimensione degli
		#						    assi del SdR
		axes_tubes.SetNumberOfSides(3)
		axes_mapper = vtk.vtkPolyDataMapper()
		axes_mapper.SetInputConnection(axes_tubes.GetOutputPort())
		axes_actor = vtk.vtkActor()
		axes_actor.SetMapper(axes_mapper)"""


		'''self.ren = vtk.vtkRenderer()
		self.ren.SetBackground(.5, .5, .5)

		self.vtkda.GetRenderWindow().AddRenderer(self.ren)'''
		self.ren.AddActor(cone2_actor)
		# ren.AddActor(axes_actor)
		self.ren.ResetCamera()


	def rem_cone1(self, widget):

                self.ren.RemoveActor(cone1_actor)
		self.ren.ResetCamera()


	def rem_cone2(self, widget):

                self.ren.RemoveActor(cone2_actor)
		self.ren.ResetCamera()




________________________________________
Da: Anka Kochanowska [anka at bic.mni.mcgill.ca]
Inviato: martedì 25 agosto 2009 19.10
A: Zampini Samuele
Cc: John Drescher; VTK
Oggetto: Re: [vtkusers] R:  vtk AddActor

Hi!
vtkActor class has SetVisibility(int) or VisibilityOff(), VisibilityOn()
functions.

You might want to read some documentation. For every class that you are
using in your code, you could see the members and the methods, and
sometimes and explanation in the documents provided on Kitware site.
Here is link to the latest documentation vtk 5.5. You may look at vtk
site  for earlier documentation.

http://www.vtk.org/doc/nightly/html/classes.html

Anka

Zampini Samuele wrote:
> thanks for answer.
>
> could you explain me how?
>
> thanks a lot,
>
> samuele
> ________________________________________
> Da: John Drescher [drescherjm at gmail.com]
> Inviato: martedì 25 agosto 2009 18.14
> A: Zampini Samuele; VTK
> Oggetto: Re: [vtkusers] vtk AddActor
>
> On Tue, Aug 25, 2009 at 12:07 PM, Zampini
> Samuele<samuele.zampini at epfl.ch> wrote:
>
>> Dear all,
>>
>> I wanna now if it is exist a feature that allow me to remove an actor instaed of adding it.
>>
>> I mean, if I succed in putting 2 cones together and I decided to remove one of them, how can I do?
>>
>>
>
> I think you can hide the actor without removing it.
>
> John
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



More information about the vtkusers mailing list