Skip to content

Commit

Permalink
Merge pull request #853 from grlee77/viz_py3
Browse files Browse the repository at this point in the history
miscellaneous Python 3 compatibility problem fixes in fvtk
  • Loading branch information
Garyfallidis committed Feb 1, 2016
2 parents 6fecc49 + da72700 commit 2355db4
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
4 changes: 2 additions & 2 deletions dipy/viz/actor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# from __future__ import division, print_function, absolute_import
from __future__ import division, print_function, absolute_import

import numpy as np

Expand Down Expand Up @@ -157,7 +157,7 @@ def display_extent(self, x1, x2, y1, y2, z1, z2):

def display(self, x=None, y=None, z=None):
if x is None and y is None and z is None:
self.display_extent(ex1, ex2, ey1, ey2, ez2/2, ez2/2)
self.display_extent(ex1, ex2, ey1, ey2, ez2//2, ez2//2)
if x is not None:
self.display_extent(x, x, ey1, ey2, ez1, ez2)
if y is not None:
Expand Down
9 changes: 9 additions & 0 deletions dipy/viz/fvtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
show, record, snapshot)
from dipy.viz.actor import line, streamtube, slicer, axes

try:
from vtk import vtkVolumeTextureMapper2D
have_vtk_texture_mapper2D = True
except:
have_vtk_texture_mapper2D = False


def dots(points, color=(1, 0, 0), opacity=1, dot_size=5):
""" Create one or more 3d points
Expand Down Expand Up @@ -479,6 +485,9 @@ def volume(vol, voxsz=(1.0, 1.0, 1.0), affine=None, center_origin=1,
colormap[i, 0], colormap[i, 1], colormap[i, 2], colormap[i, 3])

if(maptype == 0):
if not have_vtk_texture_mapper2D:
raise ValueError("VolumeTextureMapper2D is not available in your "
"version of VTK")

property = vtk.vtkVolumeProperty()
property.SetColor(color)
Expand Down
2 changes: 2 additions & 0 deletions dipy/viz/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
colors, have_vtk_colors, _ = optional_package('vtk.util.colors')
numpy_support, have_ns, _ = optional_package('vtk.util.numpy_support')
_, have_imread, _ = optional_package('Image')
if not have_imread:
_, have_imread, _ = optional_package('PIL')

if have_vtk:
version = vtk.vtkVersion.GetVTKSourceVersion().split(' ')[-1]
Expand Down
33 changes: 19 additions & 14 deletions doc/examples/introduction_to_basic_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,18 @@

# Prepare the display objects.
color = line_colors(streamlines)
streamlines_actor = fvtk.line(streamlines, line_colors(streamlines))

# Create the 3d display.
r = fvtk.ren()
fvtk.add(r, streamlines_actor)
if fvtk.have_vtk:
streamlines_actor = fvtk.line(streamlines, line_colors(streamlines))

# Save still images for this static example. Or for interactivity use fvtk.show
fvtk.record(r, n_frames=1, out_path='deterministic.png',
size=(800, 800))
# Create the 3d display.
r = fvtk.ren()
fvtk.add(r, streamlines_actor)

# Save still images for this static example. Or for interactivity use
# fvtk.show
fvtk.record(r, n_frames=1, out_path='deterministic.png',
size=(800, 800))

"""
.. figure:: deterministic.png
Expand Down Expand Up @@ -189,15 +192,17 @@

# Prepare the display objects.
color = line_colors(streamlines)
streamlines_actor = fvtk.line(streamlines, line_colors(streamlines))

# Create the 3d display.
r = fvtk.ren()
fvtk.add(r, streamlines_actor)
if fvtk.have_vtk:
streamlines_actor = fvtk.line(streamlines, line_colors(streamlines))

# Create the 3d display.
r = fvtk.ren()
fvtk.add(r, streamlines_actor)

# Save still images for this static example.
fvtk.record(r, n_frames=1, out_path='probabilistic.png',
size=(800, 800))
# Save still images for this static example.
fvtk.record(r, n_frames=1, out_path='probabilistic.png',
size=(800, 800))

"""
.. figure:: probabilistic.png
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/reconst_dsid.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
In this example we will show with simulated data how this method's ODF performs
against standard DSI ODF and a ground truth multi tensor ODF.
"""

import numpy as np
from dipy.sims.voxel import multi_tensor, multi_tensor_odf
from dipy.data import get_data, get_sphere
from dipy.core.gradients import gradient_table
Expand Down
3 changes: 2 additions & 1 deletion doc/examples/viz_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Here we present an example for visualizing slices from 3D images.
"""
from __future__ import division

import os
import nibabel as nib
Expand Down Expand Up @@ -73,7 +74,7 @@
plane.
"""

slice_actor2.display(slice_actor2.shape[0]/2, None, None)
slice_actor2.display(slice_actor2.shape[0]//2, None, None)

renderer.add(slice_actor2)

Expand Down
4 changes: 2 additions & 2 deletions doc/examples/viz_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
which will change the opacity of these tubes and c) move the streamtubes using
a slider.
"""

from __future__ import print_function
import numpy as np
from dipy.viz import window, actor, widget
from dipy.data import fetch_viz_icons, read_viz_icons
Expand Down Expand Up @@ -99,7 +99,7 @@ def move_lines(obj, event):


def text_clicked(obj, event):
print "Awesome!"
print("Awesome!")

text = widget.text(show_manager.iren, show_manager.ren,
message="Powered by DIPY",
Expand Down

0 comments on commit 2355db4

Please sign in to comment.