[vtkusers] R: Creating 2 solids in the same window

Zampini Samuele samuele.zampini at epfl.ch
Tue Aug 25 09:43:59 EDT 2009


Thanks John.
Sorry, I forgot the code.
Anyway, yes: I do have a actor in each source. But I think this is "cumpolsory" for what I am gonna do.
Anyway, I am not sure. If you could help, thanks a lot.

Samuele


=============================================================================================================================
#The following class is the class which allows us to "print the cones" where we want. We
#could print eiter 1 or 2 cones.

class VtkCones:

        def __init__(self, wTree):

                 #Set the Glade file
                 #self.gladefile = "gui.glade" 
       
                 #This is the command to open my GUI
                 #self.wTree = gtk.glade.XML(self.gladefile)
       
                 #Create our dictionay and connect it
                 #dic = { "on_open_cone_clicked" : self.open_vtk,
                 #       "on_open_cone_clicked" : self.vtkcones.open_vtk,
                 # "on_MainWindow_destroy" : gtk.main_quit }
               
                 #self.wTree.signal_autoconnect(dic)

                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()


# 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)


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

                self.vtkda.GetRenderWindow().AddRenderer(ren)
                ren.AddActor(cone1_actor)
                ren.AddActor(axes_actor)
                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)
                # 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)


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

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














________________________________________
Da: John Drescher [drescherjm at gmail.com]
Inviato: martedì 25 agosto 2009 15.41
A: Zampini Samuele; VTK
Oggetto: Re: [vtkusers] Creating 2 solids in the same window

On Tue, Aug 25, 2009 at 9:36 AM, Zampini Samuele<samuele.zampini at epfl.ch> wrote:
> Hi there,
>
> I would like to create a solid (let's say a cone) in a window after pushing a button. And I can do it. Now, the question is: if I wanna add another cone in THE SAME window, how can I do?
>
> I mean: the 2 events are linked to differen buttons. So, maybe, I wanna display the cone 1, the cone 2 or both of them.
>
> Could you help?
>
> With my codde (read below) 2 wrong things happen:
>
> 1. if I push the button for the cone one I see the con one (of course). Now, I wanna add the cone 2. I push the button and the cone 2 appears (but the 1st one disappears).
> 2. the second cone is frozen. I mean that I can not interact with it.
>

Do you have 1 actor per source?

John



More information about the vtkusers mailing list