[vtkusers] Create many instances of vtkContourWidget

Marcos Saito de Paula marcosaito at gmail.com
Fri Aug 31 17:57:54 EDT 2018

Hi everyone,

I'm new to vtk and have been playing with it for some days now.

Is it possible to create many instances of vtkContourWidget, letting the
user draw lines and manipulate the nodes?

I've done it already, but it seems I'm not doing it right.

Here is the code:

import vtk
def main():

    # Create a renderer, render window, and interactor
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()

    Interactor = vtk.vtkRenderWindowInteractor()

    style = vtk.vtkInteractorStyleTerrain()

    Interactor.AddObserver("KeyPressEvent", keyPressEvent)

    # Render and interact
def keyPressEvent(obj, event):

    key = obj.GetKeySym()

    if key == 'n':
        contourRep = vtk.vtkOrientedGlyphContourRepresentation()

        contourWidget = vtk.vtkContourWidget()




It almost works fine this way, the problem is that, when I want to close
the application window, I have to click the button to close the window many
times. And I have to click one time for each vtkContourWidget created.

It seems that each time I call the function keyPressEvent and create a
vtkContourWidget, the obj.Start() (that is the same of Interactor.Start())
line instantiates kind of another instance of the application?

I've also tried contourWidget.SetEnabled() (with obj.Start() commented
out), and it works to create new instances of vtkContourWidget, but when I
try to close the app window, the app freezes.

With both obj.Start() and contourWidget.SetEnabled() on the code, I can
create many instances, but each time I create a new instance, the previous
one disappears.

I think this topic here (
https://www.vtk.org/pipermail/vtk-developers/2008-April/020587.html) may
have the solution, but I don't know how to implement it.

I've posted the same question here:

Thanks in advance,

Marcos Saito de Paula
São Paulo - SP, Brazil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180831/ac8ee134/attachment.html>

More information about the vtkusers mailing list