Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: A lightweight UI for medical visualizations based on VTK-Python #1111

Closed
wants to merge 119 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
fde2fad
Renderer.add support multiple actors
MarcCote Jul 23, 2016
db15f08
Add CustomInteractorStyle
MarcCote Jul 23, 2016
71654d4
Update viz_advanced.py
MarcCote Jul 23, 2016
5e5c8e4
Improved CustomInteractorStyle
MarcCote Jul 24, 2016
a4e0273
Added record and play function to ShowManager
MarcCote Aug 26, 2016
65df2d0
Improved testing of widgets using event recording.
MarcCote Aug 26, 2016
0d64614
Push recorded interactor for testing button and slider widget
MarcCote Aug 26, 2016
f6b3355
BF: should stop the occasional segmentation fault we had when closing…
MarcCote Sep 16, 2016
2f297fd
Renamed record and play methods in ShowManager
MarcCote Sep 16, 2016
4b072ed
Compressed recorded events files.
MarcCote Oct 14, 2016
f7da9b7
Added coverage for VTK
MarcCote Oct 14, 2016
b528d48
RF+TST
MarcCote Oct 15, 2016
d07299e
BF in interactor tests
MarcCote Oct 15, 2016
1102be7
BF: on mouse move events notify props only once.
MarcCote Oct 15, 2016
865b9a8
PEP + addressed @Garyfallidis's comments
MarcCote Oct 15, 2016
0e0a18e
Trying to make mouse evebts work properly on Travis with Xvfb
MarcCote Oct 16, 2016
fef605a
Still trying to make mouse events work properly on Travis with Xvfb
MarcCote Oct 16, 2016
09d4617
Still trying to make mouse events work properly on Travis with Xvfb
MarcCote Oct 16, 2016
9d9f0f3
Changed recording
MarcCote Oct 16, 2016
dd642de
Resort to not test MouseWheel events
MarcCote Oct 16, 2016
6e6f557
Added a class Event that contains information about the occuring VTK …
MarcCote Oct 16, 2016
24d572e
Resort to not test MouseWheel events
MarcCote Oct 16, 2016
5eb74b3
RF: Refactored how the abort flag is set. Made it work on VTK 5.8 :-)
MarcCote Oct 16, 2016
9660375
A button to move a cube
ranveeraggarwal May 21, 2016
b2239e5
Button as a function
ranveeraggarwal May 23, 2016
e662fed
Made CustomInteractorStyle subclass vtkInteractorStyleTrackballCamera
MarcCote May 23, 2016
41d0b14
Button is now a 2D overlay
ranveeraggarwal May 25, 2016
993c570
vtkPropPicker needs to use GetViewProp for Actors2D or GetActor2D
Garyfallidis May 25, 2016
54b868f
Alternative use with GetActor2D is added as a comment
Garyfallidis May 25, 2016
a1271a4
Fixed observer bug
ranveeraggarwal May 25, 2016
b8bae30
Button click has higher preference than 3D object click
ranveeraggarwal May 26, 2016
4e846e1
Added lmb callback
ranveeraggarwal May 26, 2016
45d3cec
Button is a class
ranveeraggarwal May 28, 2016
d1f4be3
A more generic button class
ranveeraggarwal May 28, 2016
198086b
Fixed button class
ranveeraggarwal May 29, 2016
2e5ba1e
A dictionary of items instead of list
ranveeraggarwal May 30, 2016
527ed1e
Partially implemented text box
ranveeraggarwal Jun 2, 2016
6456a86
Add/remove character
ranveeraggarwal Jun 2, 2016
6bcaa1c
Textbox partially implemented
ranveeraggarwal Jun 3, 2016
63d7e01
Fixed font
ranveeraggarwal Jun 4, 2016
667f9fb
Removed default vtk key press events
ranveeraggarwal Jun 5, 2016
9c0f1d1
Dynamic text update implmented
ranveeraggarwal Jun 5, 2016
027b3f3
Multiline textbox
ranveeraggarwal Jun 5, 2016
812b521
Fixed textbox issues
ranveeraggarwal Jun 7, 2016
feba423
Introduced carat in textbox
ranveeraggarwal Jun 14, 2016
6b865e4
Caret fixed; textbox complete
ranveeraggarwal Jun 15, 2016
edfe4e9
Redesigned textbox
ranveeraggarwal Jun 17, 2016
ed2d247
Fixed backspace bug in textbox
ranveeraggarwal Jun 17, 2016
5976d08
Textbox fully completed; fixed all bugs discussed
ranveeraggarwal Jun 18, 2016
0485ce4
Textbox: Caret changed from | to _
ranveeraggarwal Jun 21, 2016
f270770
Slider: Basic slider Functionality
ranveeraggarwal Jun 23, 2016
5f40d0f
Slider: Clickable slider completed
ranveeraggarwal Jun 23, 2016
39c6b91
Slider: Slider text is now a UI element
ranveeraggarwal Jun 23, 2016
fb3af48
Support Python 2
MarcCote Jun 23, 2016
4c7fa44
UI: Adding one UI component will now add all its subcomponents to the…
ranveeraggarwal Jun 24, 2016
b31ab82
Slider: Dragging implemted but with a bug
ranveeraggarwal Jun 26, 2016
c7d515b
Slider: Still no fix
ranveeraggarwal Jun 30, 2016
1b99260
Slider: Added render to callback
ranveeraggarwal Jul 5, 2016
2cc1802
Slider: Text rendering issue fixed
ranveeraggarwal Jul 6, 2016
795b30b
Slider: Completely working now
ranveeraggarwal Jul 6, 2016
4e092b1
Circular Slider: Implemented
ranveeraggarwal Jul 7, 2016
7f8a632
Slider: Fixed order
ranveeraggarwal Jul 7, 2016
aa314d4
InteractorStyle: Fixed Bug
ranveeraggarwal Jul 7, 2016
c909162
Demo of vtkFollower for orbital menu
MarcCote Jul 7, 2016
a052a3c
Improved example on how to make a vtkAssembly that follows the camera.
MarcCote Jul 7, 2016
f02a7d4
Refactoring: separating 2D components
ranveeraggarwal Jul 9, 2016
c2d872c
Follower Menu: Initialised
ranveeraggarwal Jul 10, 2016
b8c36b6
Initialised follower menu
ranveeraggarwal Jul 13, 2016
991891a
Follower Menu: Without Transformation
ranveeraggarwal Jul 14, 2016
01db66c
Test picking element from a vtkAssembly
MarcCote Jul 14, 2016
56d1613
Follower Menu: Implemented a basic menu
ranveeraggarwal Jul 21, 2016
0fe57e2
Follower Menu: Added Buttons instead of cubes
ranveeraggarwal Jul 21, 2016
1ae5408
Follower Menu: Mixed UI Elements
ranveeraggarwal Jul 21, 2016
d8ec02e
Follower Menu: Fixed centers
ranveeraggarwal Jul 21, 2016
9b4d9f9
Follower Menu: Added Text
ranveeraggarwal Jul 21, 2016
dd15fb9
Follower Menu: Added Text with callback
ranveeraggarwal Jul 21, 2016
d7c5473
Use the new CustomInteractorStyle
MarcCote Jul 24, 2016
da6bb4a
Follower menu: fixed
ranveeraggarwal Jul 28, 2016
0f6e2a4
Textured a 2D rectangle
ranveeraggarwal Jul 28, 2016
5f69818
Added documentation and added a fix for followers
ranveeraggarwal Jul 28, 2016
eae509e
Follower menu: Compliant with new interactorStyle
ranveeraggarwal Jul 28, 2016
006d995
Follower Slider: Partial fix
ranveeraggarwal Jul 28, 2016
3fd0ea4
Panel: Implementation Initiated
ranveeraggarwal Aug 3, 2016
b8ed21e
Panel: Fixed text rendering for line slider
ranveeraggarwal Aug 3, 2016
9215b4a
Panel: Modified existing 2D elements to fit in with panel
ranveeraggarwal Aug 4, 2016
f6a0df3
Added documentation to gui.py
ranveeraggarwal Aug 4, 2016
16783c8
Documentation update for gui.py and gui_2d.py
ranveeraggarwal Aug 4, 2016
90e93ac
Added documentation for 2D GUI
ranveeraggarwal Aug 4, 2016
8d9b2ea
Fixed 1. 2D Button Set_Center 2. Docstrings
ranveeraggarwal Aug 5, 2016
a8a42b3
Panel: Now movable. All the elements move toether on click and drag.
ranveeraggarwal Aug 8, 2016
8185b5b
Added alignment features; ToDo: need to store slider states
ranveeraggarwal Aug 9, 2016
ee67c64
Panel Movement: LineSlider state fixed
ranveeraggarwal Aug 9, 2016
2ff103d
Panel Movement: Everything works
ranveeraggarwal Aug 9, 2016
48fed3f
Dragging panel doesn't move the 3D environment.
MarcCote Aug 10, 2016
d8623ac
Filedialog: Added filemenu layout and font background
ranveeraggarwal Aug 17, 2016
2880fa4
FileDialog: Modifications in the way it works and added a callback
ranveeraggarwal Aug 17, 2016
cbcf88e
Filedialog: Folder changing works
ranveeraggarwal Aug 18, 2016
0a7d1cd
FileSelect: Mostly done; 1/5 components of filesave menu built
ranveeraggarwal Aug 18, 2016
7d94428
FileSelect: Enhancements, fixed bugs
ranveeraggarwal Aug 18, 2016
7bd11e0
FileMenu: progress
ranveeraggarwal Aug 18, 2016
9ab1ae4
FileSaveDialog: Inter-Object interaction working
ranveeraggarwal Aug 18, 2016
79b8d20
FileDialog: Added working buttons
ranveeraggarwal Aug 18, 2016
8d36e80
FileDialog: Fixed Textbox
ranveeraggarwal Aug 18, 2016
b2c2efa
Removed SetBackground
ranveeraggarwal Aug 18, 2016
09d8571
Removed SetBackground1
ranveeraggarwal Aug 18, 2016
d497acf
FileDialog: Fixed bug - filename persistence
ranveeraggarwal Aug 18, 2016
31bf48c
Hide empty text actors
MarcCote Aug 18, 2016
3d19a5f
FileDialog: Fixed TextBox Bug; FileDialog is Almost Complete
ranveeraggarwal Aug 19, 2016
3c2083a
WIP Refactoring
ranveeraggarwal Aug 21, 2016
7df8feb
Slider Refactoring: Complete. Panel is now a recursive function; we c…
ranveeraggarwal Aug 21, 2016
0de0386
All UI elements refactored to use the new add_to_renderer function; a…
ranveeraggarwal Aug 21, 2016
2103eb3
Added filedialog scrolling
ranveeraggarwal Aug 22, 2016
b5bfb05
Fixed print; filedialog completed
ranveeraggarwal Aug 22, 2016
f2095ea
FileDialog: Fixed scroll bug
ranveeraggarwal Aug 22, 2016
809910b
Modded GUI
ranveeraggarwal Aug 29, 2016
178e6f1
GUI: Added docstrings wherever required; refactored code.
ranveeraggarwal Aug 30, 2016
c9855ed
Adapt UI component to use the improved CustomInteractorStyle
MarcCote Oct 17, 2016
e1c24ba
WIP: Adding new interactorStyle to gui_follower
ranveeraggarwal Nov 1, 2016
cf3b0a5
WIP: Adding new interactorStyle to gui_follower commit 2
ranveeraggarwal Nov 1, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -29,3 +29,5 @@ __config__.py
.coverage
.buildbot.patch
.eggs/

.idea/
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -37,6 +37,7 @@ matrix:
- python: 2.7
sudo: true # This is set to true for apt-get
env:
- COVERAGE=1
- VTK=1
- VTK_VER="python-vtk"
- LIBGL_ALWAYS_INDIRECT=y
Expand Down
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions dipy/testing/decorators.py
Expand Up @@ -60,12 +60,12 @@ def xvfb_it(my_test):
# When we use verbose testing we want the name:
fname = my_test.__name__

def test_with_xvfb():
def test_with_xvfb(*args, **kwargs):
if use_xvfb:
from xvfbwrapper import Xvfb
display = Xvfb(width=1920, height=1080)
display.start()
my_test()
my_test(*args, **kwargs)
if use_xvfb:
display.stop()
# Plant it back in and return the new function:
Expand Down
214 changes: 214 additions & 0 deletions dipy/viz/gui.py
@@ -0,0 +1,214 @@
from dipy.viz.interactor import CustomInteractorStyle

from dipy.utils.optpkg import optional_package

# Allow import, but disable doctests if we don't have vtk.
vtk, have_vtk, setup_module = optional_package('vtk')

if have_vtk:
version = vtk.vtkVersion.GetVTKSourceVersion().split(' ')[-1]
major_version = vtk.vtkVersion.GetVTKMajorVersion()
else:
vtkInteractorStyleUser = object


class UI(object):
""" An umbrella class for all UI elements.

While adding UI elements to the renderer, we need to go over all the
sub-elements that come with it and add those to the renderer too.
There are several features that are common to all the UI elements:
- ui_param : This is an attribute that can be passed to the UI object
by the interactor. Thanks to Python's dynamic type-setting
this parameter can be anything.
- ui_list : This is used when there are more than one UI elements inside
a UI element. Inside the renderer, they're all iterated and added.
- parent_UI: This is useful of there is a parent UI element and its reference
needs to be passed down to the child.

"""
def __init__(self):
self.ui_param = None
self.ui_list = list()

self.parent_UI = None
self._callbacks = []

def get_actors(self):
""" Returns the actors that compose this UI component. """
msg = "Subclasses of UI must implement `get_actors(self)`."
raise NotImplementedError(msg)

def add_to_renderer(self, ren):
""" Allows UI objects to add their own props to the renderer.

Parameters
----------
ren : renderer
"""
ren.add(*self.get_actors())

# Get a hold on the current interactor style.
iren = ren.GetRenderWindow().GetInteractor().GetInteractorStyle()

for callback in self._callbacks:
if not isinstance(iren, CustomInteractorStyle):
msg = ("The ShowManager requires `CustomInteractorStyle` in"
" order to use callbacks.")
raise TypeError(msg)

iren.add_callback(*callback, args=[self])

def add_callback(self, prop, event_type, callback, priority=0):
""" Adds a callback to a specific event for this UI component.

Parameters
----------
prop : vtkProp
event_type : event code
callback : function
priority : int
"""
# Actually since we need an interactor style we will add the callback
# only when this UI component is added to the renderer.
self._callbacks.append((prop, event_type, callback, priority))

def set_center(self, position):
""" Sets the center of the UI component

Parameters
----------
position : (float, float)
"""
pass


class TextActor2D(vtk.vtkTextActor):
""" Inherits from the default vtkTextActor and helps setting the text.

Contains member functions for text formatting.
"""
def message(self, text):
""" Set message after initialization.

Parameters
----------
text : string

"""
self.SetInput(text)

def set_message(self, text):
""" Modify text message.

Parameters
----------
text : string
"""
self.SetInput(text)

def get_message(self):
""" Gets message from the text.

Returns
-------
message : string

"""
return self.GetInput()

def font_size(self, size):
""" Sets font size.

Parameters
----------
size : int
"""
self.GetTextProperty().SetFontSize(size)

def font_family(self, family='Arial'):
""" Sets font family.
Currently defaults to Ariel.
# TODO: Add other font families.

Parameters
----------
family : string
"""
self.GetTextProperty().SetFontFamilyToArial()

def justification(self, justification):
""" Justifies text.

Parameters
----------
justification : string
Possible values : left, right, center
"""
tprop = self.GetTextProperty()
if justification == 'left':
tprop.SetJustificationToLeft()
if justification == 'center':
tprop.SetJustificationToCentered()
if justification == 'right':
tprop.SetJustificationToRight()

def font_style(self, bold=False, italic=False, shadow=False):
""" Style font.

Parameters
----------
bold : bool
italic : bool
shadow : bool
"""
tprop = self.GetTextProperty()
if bold:
tprop.BoldOn()
else:
tprop.BoldOff()
if italic:
tprop.ItalicOn()
else:
tprop.ItalicOff()
if shadow:
tprop.ShadowOn()
else:
tprop.ShadowOff()

def color(self, color=(1, 0, 0)):
""" Set text color.

Parameters
----------
color : (float, float, float)
Values must be between 0-1
"""
self.GetTextProperty().SetColor(*color)

def set_position(self, position):
""" Set text actor position.

Parameters
----------
position : (float, float)
"""
self.SetDisplayPosition(*position)

def get_position(self):
""" Gets text actor position.

Returns
-------
position : (float, float)
"""
return self.GetDisplayPosition()

def set_center(self, position):
""" Set text actor position.

Parameters
----------
position : (float, float)
"""
self.SetPosition(position)