[vtkusers] Adding geometric solid in an existing window

Zampini Samuele samuele.zampini at epfl.ch
Tue Sep 1 04:19:26 EDT 2009


Hi there,

I have a problem with vtk.

I created a gui and when I press a button (let's say button 1) a cone appear in a window in my gui.

Then, when I press another button, I want that a cube will appear in the same window with the cone. How can I do that?

With my code (see below) I get the cube in a different window.

Could you help?

Thanks a lot,

samuele

======================================================================================================
The code is:

class VmtkInterface:

    def __init__(self, img, wTree, *args):
        
        self.subdir = img
	
	# setting window to widget: I don't want to create a new window,
	# but I want to use the same window I created in the file vtkcones.py
        # self.window = wTree.get_widget("hbox2")
	self.vtkWindow = vtkcones.vtkWindow(wTree)
	# self.vtkWindow.window = vtkcones.vtkWindow.window()
	
	self.vtkWindow.window.connect("destroy", gtk.mainquit)
	self.vtkWindow.window.connect("delete_event", gtk.mainquit)

	# defining new Canvas
        self.vtkda = vtkcones.Canvas3D(None)
	self.vtkda.show()

	# adding Canvas to gtk
	hbox = gtk.HBox(spacing=5)
	hbox.show()
	hbox.pack_start(self.vtkda)
    
	self.vtkWindow.window.add(hbox)
	self.vtkWindow.window.set_size_request(400, 400)

	self.vtkWindow.window.show()


	# defining new vmtkRenderer
        self.vmtkRenderer = vmtkrenderer.vmtkRenderer()
	# setting vtkRenderer in vmtkRenderer as a new one
	self.vmtkRenderer.Renderer = vtk.vtkRenderer()
	# just modify the background to see what we are changing
	self.vmtkRenderer.Renderer.SetBackground(.5, .5, .5)

	self.vtkda.GetRenderWindow().AddRenderer(self.vmtkRenderer.Renderer)

	# setting RenderWindow to the already existing one in vtkda 
	self.vmtkRenderer.RenderWindow = self.vtkda.GetRenderWindow() #vtkWindow.vtkda.GetRenderWindow()

	### 
	self.vmtkRenderer.RenderWindow.AddRenderer(self.vmtkRenderer.Renderer)
	self.vmtkRenderer.RenderWindow.SetSize(self.vmtkRenderer.WindowSize[0],self.vmtkRenderer.WindowSize[1])
	self.vmtkRenderer.RenderWindow.SetPointSmoothing(self.vmtkRenderer.PointSmoothing)
	self.vmtkRenderer.RenderWindow.SetLineSmoothing(self.vmtkRenderer.LineSmoothing)
	self.vmtkRenderer.RenderWindow.SetPolygonSmoothing(self.vmtkRenderer.PolygonSmoothing)
	
	self.vmtkRenderer.RenderWindowInteractor = vtk.vtkGenericRenderWindowInteractor()
	self.vmtkRenderer.RenderWindowInteractor.SetRenderWindow(self.vtkda.GetRenderWindow())
	self.vmtkRenderer.RenderWindowInteractor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
	self.vmtkRenderer.RenderWindow.SetInteractor(self.vmtkRenderer.RenderWindowInteractor)


More information about the vtkusers mailing list