Skip to content
Snippets Groups Projects
Commit 1ff5b837 authored by Andrew Maclean's avatar Andrew Maclean
Browse files

Updated ContourWidget

parent 11ded159
No related branches found
No related tags found
2 merge requests!353Create VTK hyperlinks in one pass and remove #details from the link,!352Draft: Classes in python not in pythonic api 08
...@@ -8,6 +8,7 @@ import vtkmodules.vtkInteractionStyle ...@@ -8,6 +8,7 @@ import vtkmodules.vtkInteractionStyle
import vtkmodules.vtkRenderingOpenGL2 import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkCommonCore import ( from vtkmodules.vtkCommonCore import (
vtkCommand,
vtkPoints vtkPoints
) )
from vtkmodules.vtkCommonDataModel import ( from vtkmodules.vtkCommonDataModel import (
...@@ -16,7 +17,8 @@ from vtkmodules.vtkCommonDataModel import ( ...@@ -16,7 +17,8 @@ from vtkmodules.vtkCommonDataModel import (
) )
from vtkmodules.vtkInteractionWidgets import ( from vtkmodules.vtkInteractionWidgets import (
vtkContourWidget, vtkContourWidget,
vtkOrientedGlyphContourRepresentation vtkOrientedGlyphContourRepresentation,
vtkWidgetEvent
) )
from vtkmodules.vtkRenderingCore import ( from vtkmodules.vtkRenderingCore import (
vtkRenderWindow, vtkRenderWindow,
...@@ -25,11 +27,29 @@ from vtkmodules.vtkRenderingCore import ( ...@@ -25,11 +27,29 @@ from vtkmodules.vtkRenderingCore import (
) )
def get_program_parameters():
import argparse
description = 'Contour widget.'
epilogue = '''
The options -Shift or -Scale demonstrate how to override the left button press event.
If either of these are set, you cannot change the shape of the circle.
'''
parser = argparse.ArgumentParser(description=description, epilog=epilogue,
formatter_class=argparse.RawDescriptionHelpFormatter)
group = parser.add_mutually_exclusive_group()
group.add_argument('-Shift', action='store_true',
help='Pressing the left button on a point will shift the whole circle.')
group.add_argument('-Scale', action='store_true',
help='Pressing the left button on a point will scale the whole circle.')
return parser.parse_args()
def main(): def main():
colors = vtkNamedColors() colors = vtkNamedColors()
# colors.SetColor('bkg', [0.1, 0.2, 0.4, 1.0]) # colors.SetColor('bkg', [0.1, 0.2, 0.4, 1.0])
args = get_program_parameters()
# Create the RenderWindow, Renderer and both Actors # Create the RenderWindow, Renderer and both Actors
renderer = vtkRenderer(background=colors.GetColor3d('MidnightBlue')) renderer = vtkRenderer(background=colors.GetColor3d('MidnightBlue'))
render_window = vtkRenderWindow(size=(600, 600), window_name='ContourWidget') render_window = vtkRenderWindow(size=(600, 600), window_name='ContourWidget')
...@@ -45,6 +65,19 @@ def main(): ...@@ -45,6 +65,19 @@ def main():
contour_widget = vtkContourWidget(interactor=interactor, representation=contour_rep) contour_widget = vtkContourWidget(interactor=interactor, representation=contour_rep)
contour_widget.On() contour_widget.On()
if args.Shift:
contour_widget.event_translator.RemoveTranslation(
vtkCommand.LeftButtonPressEvent)
contour_widget.event_translator.SetTranslation(
vtkCommand.LeftButtonPressEvent,
vtkWidgetEvent.Translate)
if args.Scale:
contour_widget.event_translator.RemoveTranslation(
vtkCommand.LeftButtonPressEvent)
contour_widget.event_translator.SetTranslation(
vtkCommand.LeftButtonPressEvent,
vtkWidgetEvent.Scale)
# Generate a set of points arranged in a circle. # Generate a set of points arranged in a circle.
points = vtkPoints() points = vtkPoints()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment