Skip to content
Snippets Groups Projects
Commit 294f6a8b authored by Paul McCarthy's avatar Paul McCarthy
Browse files

More updates to GLImageObject display resolution calculation, as it

was still not ideal in many situations. Hopefully this approach will
prove to be a good one.
parent 12ac1e17
No related branches found
No related tags found
No related merge requests found
......@@ -380,23 +380,36 @@ class GLImageObject(GLObject):
``GLImageObject``.
"""
image = self.image
opts = self.displayOpts
res = opts.resolution
if opts.transform in ('id', 'pixdim'):
pixdim = np.array(image.pixdim[:3])
steps = [res, res, res] / pixdim
steps = np.maximum(steps, [1, 1, 1])
res = image.shape[:3] / steps
return np.array(res.round(), dtype=np.uint32)
else:
lo, hi = map(np.array, self.getDisplayBounds())
maxres = int(round(((hi - lo) / res).max()))
return [maxres] * 3
import nibabel as nib
image = self.image
opts = self.displayOpts
res = opts.resolution
# Figure out a good display resolution
# along each voxel dimension
pixdim = np.array(image.pixdim[:3])
steps = [res, res, res] / pixdim
steps = np.maximum(steps, [1, 1, 1])
res = image.shape[:3] / steps
# Make sure the pixel
# resolutions are integers
res = np.array(res.round(), dtype=np.uint32)
# Figure out an approximate
# correspondence between the
# voxel axes and the display
# coordinate system axes.
xform = opts.getTransform('id', 'display')
axes = nib.orientations.aff2axcodes(
xform, ((0, 0), (1, 1), (2, 2)))
# Re-order the voxel resolutions
# in the display space
res = [res[axes[0]], res[axes[1]], res[axes[2]]]
return res
def generateVertices(self, zpos, xform):
......
......@@ -183,6 +183,9 @@ class GLVolume(globject.GLImageObject):
fslgl.glvolume_funcs.updateShaderState(self)
self.onUpdate()
def update(*a):
self.onUpdate()
def imageUpdate(*a):
volume = opts.volume
resolution = opts.resolution
......@@ -207,6 +210,7 @@ class GLVolume(globject.GLImageObject):
opts .addListener('volume', lName, imageUpdate, weak=False)
opts .addListener('resolution', lName, imageUpdate, weak=False)
opts .addListener('interpolation', lName, imageUpdate, weak=False)
opts .addListener('transform', lName, update, weak=False)
if opts.getParent() is not None:
opts.addSyncChangeListener(
......@@ -237,6 +241,7 @@ class GLVolume(globject.GLImageObject):
opts .removeListener( 'volume', lName)
opts .removeListener( 'resolution', lName)
opts .removeListener( 'interpolation', lName)
opts .removeListener( 'transform', lName)
if opts.getParent() is not None:
opts.removeSyncChangeListener('volume', lName)
opts.removeSyncChangeListener('resolution', lName)
......
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