8
8
import numpy as np
9
9
10
10
from .optpkg import optional_package
11
+ from .orientations import aff2axcodes , axcodes2ornt
11
12
12
13
plt , _ , _ = optional_package ('matplotlib.pyplot' )
13
14
mpl_img , _ , _ = optional_package ('matplotlib.image' )
@@ -33,41 +34,40 @@ class OrthoSlicer3D(object):
33
34
>>> OrthoSlicer3D(data).show() # doctest: +SKIP
34
35
"""
35
36
# Skip doctest above b/c not all systems have mpl installed
36
- def __init__ (self , data , axes = None , aspect_ratio = ( 1 , 1 , 1 ), affine = None ,
37
- cmap = 'gray' , pcnt_range = (1. , 99. ), figsize = (8 , 8 )):
37
+ def __init__ (self , data , affine = None , axes = None , cmap = 'gray' ,
38
+ pcnt_range = (1. , 99. ), figsize = (8 , 8 )):
38
39
"""
39
40
Parameters
40
41
----------
41
42
data : ndarray
42
43
The data that will be displayed by the slicer. Should have 3+
43
44
dimensions.
44
- axes : tuple of mpl.Axes | None, optional
45
- 3 or 4 axes instances for the X, Y, Z slices plus volumes,
46
- or None (default).
47
- aspect_ratio : array-like, optional
48
- Stretch factors for X, Y, Z directions.
49
45
affine : array-like | None
50
46
Affine transform for the data. This is used to determine
51
47
how the data should be sliced for plotting into the X, Y,
52
- and Z view axes. If None, identity is assumed.
48
+ and Z view axes. If None, identity is assumed. The aspect
49
+ ratio of the data are inferred from the affine transform.
50
+ axes : tuple of mpl.Axes | None, optional
51
+ 3 or 4 axes instances for the X, Y, Z slices plus volumes,
52
+ or None (default).
53
53
cmap : str | instance of cmap, optional
54
54
String or cmap instance specifying colormap.
55
55
pcnt_range : array-like, optional
56
56
Percentile range over which to scale image for display.
57
57
figsize : tuple
58
58
Figure size (in inches) to use if axes are None.
59
59
"""
60
- ar = np .array (aspect_ratio , float )
61
- if ar .shape != (3 ,) or np .any (ar <= 0 ):
62
- raise ValueError ('aspect ratio must have exactly 3 elements >= 0' )
63
- aspect_ratio = dict (x = ar [0 ], y = ar [1 ], z = ar [2 ])
64
60
data = np .asanyarray (data )
65
61
if data .ndim < 3 :
66
62
raise ValueError ('data must have at least 3 dimensions' )
67
63
affine = np .array (affine , float ) if affine is not None else np .eye (4 )
68
64
if affine .ndim != 2 or affine .shape != (4 , 4 ):
69
65
raise ValueError ('affine must be a 4x4 matrix' )
70
- self ._affine = affine
66
+ self ._affine = affine .copy ()
67
+ self ._codes = axcodes2ornt (aff2axcodes (self ._affine )) # XXX USE FOR ORDERING
68
+ print (self ._codes )
69
+ self ._scalers = np .abs (self ._affine ).max (axis = 0 )[:3 ]
70
+ self ._inv_affine = np .linalg .inv (affine )
71
71
self ._volume_dims = data .shape [3 :]
72
72
self ._current_vol_data = data [:, :, :, 0 ] if data .ndim > 3 else data
73
73
self ._data = data
@@ -122,7 +122,7 @@ def __init__(self, data, axes=None, aspect_ratio=(1, 1, 1), affine=None,
122
122
123
123
# set up axis crosshairs
124
124
self ._crosshairs = dict ()
125
- for type_ , i_1 , i_2 in zip ('zyx ' , 'xxy ' , 'yzz ' ):
125
+ for type_ , i_1 , i_2 in zip ('xyz ' , 'yxx ' , 'zzy ' ):
126
126
ax , label = self ._axes [type_ ], labels [type_ ]
127
127
vert = ax .plot ([self ._idx [i_1 ]] * 2 ,
128
128
[- 0.5 , self ._sizes [i_2 ] - 0.5 ],
@@ -145,7 +145,7 @@ def __init__(self, data, axes=None, aspect_ratio=(1, 1, 1), affine=None,
145
145
horizontalalignment = anchor [0 ],
146
146
verticalalignment = anchor [1 ])
147
147
ax .axis (lims )
148
- ax .set_aspect (aspect_ratio [type_ ])
148
+ # ax.set_aspect(aspect_ratio[type_]) # XXX FIX
149
149
ax .patch .set_visible (False )
150
150
ax .set_frame_on (False )
151
151
ax .axes .get_yaxis ().set_visible (False )
@@ -206,7 +206,7 @@ def n_volumes(self):
206
206
"""Number of volumes in the data"""
207
207
return int (np .prod (self ._volume_dims ))
208
208
209
- def set_indices (self , x = None , y = None , z = None , v = None ):
209
+ def set_position (self , x = None , y = None , z = None , v = None ):
210
210
"""Set current displayed slice indices
211
211
212
212
Parameters
0 commit comments