Subject Viewer¶
This module implements high level data viewers. They handle all VTK, and data access operations. They are made of data managers which specialize on handling specific data types. They maintain its state, and specially important, support changing subject or coordinate systems while keeping the other parameters constant. In this way it is possible to compare two subjects.
These viewers are designed to be used as widgets it Qt applications. For that matter specific Widget wrappers exist for each of them. This wrappers can send PyQt signals on certain events, like picking the screen.
Full Viewers¶
These classes combine different data managers to create integrated visualizations.
-
class
SubjectViewer
(render_window_interactor, reader, widget)[source]¶ A general viewer to show data on a particular subject
It provides access to
- Images
- fMRI Contours
- Segmentation reconstruction models
- Surface parcellations
- Tractographies
- Tracula Bundles
-
change_current_space
(*args, **kwargs)[source]¶ Changes the current coordinate system
Parameters: new_space (str) – New coordinate system
-
change_subject
(new_subject)[source]¶ Changes the subject associated to the viewer
Parameters: new_subject – new subject id
-
contours
¶ Access to
FmriContours
-
get_camera_parameters
()[source]¶ Gets current camera parameters
- Returs:
- focal_point, position, view_up
-
image
¶ Access to
ImageManager
-
models
¶ Access to
ModelManager
-
print_camera
()[source]¶ Logs information about the current camera position
Data is send to the current logger with info level
-
reset_camera
(position)[source]¶ resets the current camera to standard locations.
Parameters: position (int) – - 0: initial 3d view
- 1: left
- 2: right
- 3: front
- 4: back
- 5: top
- 6: bottom
-
set_contours_visibility
(*args, **kwargs)[source]¶ Toggle visibility of fMRI contours
Parameters: visible (bool) – If True
contours will show, ifFalse
contours will be hidden,
-
set_fmri_contours_image
(*args, **kwargs)[source]¶ Sets the image to use for calculating fMRI contours
Parameters:
-
surface
¶ Access to
SurfaceManager
-
tractography
¶ Access to
TractographyManager
-
tracula
¶ Access to
TraculaManager
-
class
fMRI_viewer
(render_window_interactor, reader, widget)[source]¶ A viewer for visualizaing fMRI data. It displays
- Images
- fMRI contours
-
change_contrast
(*args, **kwargs)[source]¶ Change contrast
Parameters: new_contrast (int) – Index of new contrast (starting at 1)
-
change_orientation
(orientation_index)[source]¶ Changes the orientation of the Image Plane Widget
Parameters: orientation_index (int) – 0 for x, 1 for y and 2 for z
-
change_paradigm
(*args, **kwargs)[source]¶ Change fMRI paradigm
Parameters: new_pdgm (str) – Must be one of the available fMRI paradigms
-
change_subject
(*args, **kwargs)[source]¶ Change subject associated to the plane
Parameters: new_subj – Id of new subject
-
contours
¶ Access to FmriContours
-
get_camera_parameters
()[source]¶ Gets current camera parameters
- Returs:
- focal_point, position, view_up
-
image
¶ Access to ImageManager
-
reset_camera
(*args, **kwargs)[source]¶ resets the current camera to standard locations.
Parameters: position (int) – - 0: initial 3d view
- 1: left
- 2: right
- 3: front
- 4: back
- 5: top
- 6: bottom
-
set_contour_opacity
(*args, **kwargs)[source]¶ Opacity for displaying the contours
Parameters: value (int) – A number from 0 to 100; where 0 is invisible and 100 is opaque
-
set_contour_value
(*args, **kwargs)[source]¶ Set value for the fMRI contours
Parameters: value (float) – The iso-contours will be calculated at this value
-
set_contour_visibility
(*args, **kwargs)[source]¶ Set visibility of contours
Parameters: value (bool) – If True
show the contours, otherwise hide them
-
class
OrthogonalPlanesViewer
(render_window_interactor, reader, widget)[source]¶ A viewer with three orthogonal planes
It provides access to
- Images
- Surfaces
- A sphere
-
change_image_modality
(*args, **kwargs)[source]¶ Change image modality in all planes
See
ImageManager.change_image_modality()
Parameters:
-
change_space
(*args, **kwargs)[source]¶ Changes the current coordinate system
Parameters: new_space (str) – New coordinate system
-
change_subject
(*args, **kwargs)[source]¶ Changes the subject associated to the viewer
Parameters: new_subject – new subject id
-
cortex
¶ Access to the surface manager
-
current_position
()[source]¶ Last picked position, either on the planes or on the surface
Returns: Coordinates of the last picked position
-
finish_initializing
()[source]¶ Finish viewer initialization, only call this after calling “show” on the widget or its parents
-
get_camera_parameters
()[source]¶ Gets current camera parameters
Returns: focal_point, position, view_up
-
get_current_slice
()[source]¶ Get current slices of all planes
Returns: A tuple with the current slice of each plane (x,y,z)
-
get_number_of_slices
()[source]¶ Get number of slices in each plane
Returns: A tuple with the image dimension
-
image_planes
¶ Access to the image planes array
-
sphere
¶ Access to the sphere
-
x_image
¶ Access to the image manager perpendicular to x
-
y_image
¶ Access to the image manager perpendicular to y
-
z_image
¶ Access to the image manager perpendicular to z
-
class
MeasurerViewer
(render_window_interactor, reader, widget)[source]¶ A viewer that allows the user to measure the distance between two points on images using a vtkMeasureWidget
-
change_image_modality
(*args, **kwargs)[source]¶ Change image modality in all planes
See
ImageManager.change_image_modality()
Parameters:
-
change_space
(*args, **kwargs)[source]¶ Changes the current coordinate system
Parameters: new_space (str) – New coordinate system
-
change_subject
(*args, **kwargs)[source]¶ Changes the subject associated to the viewer
Parameters: new_subject – new subject id
-
distance
¶ Current distance measured by the measure widget
-
finish_initializing
()[source]¶ Finish viewer initialization, only call this after calling “show” on the widget or its parents
-
get_camera_parameters
()[source]¶ Gets current camera parameters
Returns: focal_point, position, view_up
-
get_current_slice
()[source]¶ Get current slices of all planes
Returns: A tuple with the current slice of each plane (x,y,z)
-
get_number_of_slices
()[source]¶ Get number of slices in each plane
Returns: A tuple with the image dimension
-
image_planes
¶ Access to the image planes array
-
point1
¶ Get coordinates of first measure point
-
point2
¶ Get coordinates of second measure point
-
set_measure_axis
(*args, **kwargs)[source]¶ Set the measure plane to be perpendicular to the axis
Parameters: axis_str (str) – “axial”, “sagital” or “coronal”
-
set_slice_coords
(*args, **kwargs)[source]¶ Move the measure plane perpendicularly
Parameters: coords (float) – New position across the axis perpendicular to the measure plane
-
x_image
¶ Access to the image manager perpendicular to x
-
y_image
¶ Access to the image manager perpendicular to y
-
z_image
¶ Access to the image manager perpendicular to z
-
Data Managers¶
Managing the visualization state is simplified by the data managers, which focus on specific data types.
-
class
ImageManager
(reader, ren, widget, interactor, initial_subj=None, initial_space='subject', picker=None)[source]¶ Controls an ImagePlaneWidget
-
change_image_modality
(*args, **kwargs)[source]¶ Changes the modality of the current image;
In the case of fMRI modality should be fMRI and paradigm the name of the paradigm
Parameters: - image_class (str) – New image class, may be one of
["image","label","dti","fmri"]
- image_name (str) – New image modality name. Use
None
if image_class is"dti"
, otherwise it should be inside the index of the given class. In case of FMRI the paradigm should be entered here Seeget()
- force_reload (bool) – if True, forces the plane to reload the image if it appears to be the same as before
- contrast (int) – contrast to show in case image_class is
"fmri"
- image_class (str) – New image class, may be one of
-
change_image_orientation
(*args, **kwargs)[source]¶ Changes the orientation of the current image
Parameters: orientation (int) – 0 for X, 1 for Y and 2 for Z
-
change_space
(*args, **kwargs)[source]¶ Change current coordinate system
new_space (str) : new coordinate system, see
get()
-
change_subject
(*args, **kwargs)[source]¶ Change subject associated to the plane
Parameters: new_subject – Id of new subject
-
get_current_image_slice
()[source]¶ Get the index of the actual slice
Returns: The index of the current slice
-
get_number_of_image_slices
()[source]¶ Gets the number of slices in the current orientation
Returns: The number of available slicer for the current image and orientation
-
image_plane_widget
¶ Get the vtkImagePlaneWidget
-
set_image_level
(*args, **kwargs)[source]¶ Changes level value
Parameters: new_level (float) – New level value
-
set_image_slice
(*args, **kwargs)[source]¶ Sets the image slice
Parameters: new_slice (int) – Number of the desired slice
-
-
class
ModelManager
(reader, ren, initial_subj=None, initial_space='subject')[source]¶ A manager for segmented structure models
-
get_opacity
()[source]¶ Gets actual opacity
Returns: An integer from 0 to 100 indicating the current opacity percentage
-
get_scalar_metrics
(metric_name)[source]¶ Get an scalar metric from the current models
Parameters: metric_name (str) – May be
volume
: Total volume occupied by all modelsarea
: Sum of superficial areas of all modelsfa_inside
: Mean value of FA inside the current modelsmd_inside
: Mean value of MD inside the current modelsnfibers
: Number of fibers that cross any of the current modelslfibers
: Mean length of fibers that cross any of the current modelsfa-fibers
: Mean FA of fibers that cross any of the current models
Returns: Scalar value or nan
if there was an error
-
reload_models
(*args, **kwargs)[source]¶ Reloads all models
Parameters: - subj – Code for new subject, if
None
the subject is not changed - space (str) – new coordinate system, if
None
the coordinates are not changed
- subj – Code for new subject, if
-
set_color
(*args, **kwargs)[source]¶ Sets the color for displaying the models
Parameters: float_rgb_color (tuple) – An rgb value, if None
the freesurfer lookuptable is used
-
-
class
TractographyManager
(reader, ren, initial_subj=None, initial_space='subject')[source]¶ A manager for tractography data
-
add_from_database
(*args, **kwargs)[source]¶ Add a bundle from the database
See
braviz.readAndFilter.bundles_db
Parameters: b_id (int) – Bundle id in the database
-
change_color
(*args, **kwargs)[source]¶ Sets the coloring scheme for the rendered data.
Parameters: new_color (str) – New coloring scheme, the following values are accepted
bundle
: A different color for each bundleorient
: Color tractography based on local orientationrand
: A different color for each linefa_p
: Use FA values at each point and a lookuptablefa_l
: Use mean fa of each line and a lookuptablemd_p
: Use MD values at each point and a lookuptablemd_l
: Use mean MD of each line and a lookuptablelength
: Use length of each line and a lookuptableaparc
: Use the aparc label at each point and the freesurfer lookuptablewmparc
: Use the wmparc label at each point and the freesurfer lookuptable
-
get_bundle_colors
()[source]¶ Get a set of colors for coloring each active bundle in a different color
Returns: A color palette with length equal to the number of active bundles
-
get_polydata
(b_id)[source]¶ Gets the polydata object associated to a database bundle.
The current subject, coordinate system and scalars are maintained
Parameters: b_id (int) – Bundle database id Returns: vtkPolyData from the requested bundle
-
get_scalar_from_db
(scalar, bid)[source]¶ Gets an scalar metric from an active database bundle
Parameters: Returns: Scalar value or
nan
if there was an error
-
get_scalar_from_structs
(scalar)[source]¶ Gets an scalar metric from the active checkpoints bundle
see
set_bundle_from_checkpoints()
Parameters: scalar (str) – Scalar metric, available options are:
number
: Number of linesmean_length
: Mean length of linesmean_fa
: Mean FA of the bundlemean_md
: Mean MD of the bundle
Returns: Scalar value or nan
if there was an error
-
get_show_color_bar
()[source]¶ Status of the color bar
Returns: True
if the color bar is active,False
otherwise
-
hide_checkpoints_bundle
(*args, **kwargs)[source]¶ Hide the checkpoints bundle created with
set_bundle_from_checkpoints()
-
hide_database_tract
(*args, **kwargs)[source]¶ Hides a bundle previously added from the database
Parameters: bid (int) – Bundle database id
-
set_active_db_tracts
(*args, **kwargs)[source]¶ Selects active database tracts
Parameters: new_set (list) – List of database ids
-
set_bundle_from_checkpoints
(*args, **kwargs)[source]¶ Creates a fiber bundle based on a list of structures
Parameters:
-
set_current_space
(*args, **kwargs)[source]¶ Set current coordinate system
new_space (str) : new coordinate system, see
get()
-
set_opacity
(*args, **kwargs)[source]¶ Sets opacity for the displayed bundles
Parameters: float_opacity (float) – From 0 to 1; where 0 is transparent and 1 is opaque
-
-
class
TraculaManager
(reader, ren, initial_subj=None, initial_space='subject')[source]¶ A data manager for Tracula bundles
-
active_bundles
¶ Gets the set of active bundles
Returns: A frozenSet of currently active bundles
-
reload_bundles
(*args, **kwargs)[source]¶ Reloads all bundles
Parameters: - subj – Code for new subject, if
None
the subject is not changed - space (str) – new coordinate system, if
None
the coordinates are not changed
- subj – Code for new subject, if
-
-
class
SurfaceManager
(reader, ren, iren, initial_subj=None, initial_space='subject', picker=None, persistent_cone=False)[source]¶ A data manager for freesurfer sufaces parcelations
-
get_last_picked_pos
()[source]¶ Coordinates of the last picked position
Returns: A tuple with the coordinates of the last pickedposition
-
pick_cone_actor
¶ Access to the pick cone actor
-
set_opacity
(*args, **kwargs)[source]¶ Opacity for displaying the surfaces
Parameters: int_opacity (int) – A number from 0 to 100; where 0 is invisible and 100 is opaque
-
set_scalars
(*args, **kwargs)[source]¶ Sets the current scalars to use for the surfaces
Parameters: scalars (str) – See braviz.readAndFilter.base_reader.BaseReader.get()
for options
-
set_space
(*args, **kwargs)[source]¶ Change current coordinate system
new_space (str) : new coordinate system, see
get()
-
set_subject
(*args, **kwargs)[source]¶ Change subject associated to the manager
Parameters: new_subject – Id of new subject
-
set_surface
(*args, **kwargs)[source]¶ Sets the current surface to display at both hemispheres
Parameters: surface (str) – See braviz.readAndFilter.base_reader.BaseReader.get()
for options
-
-
class
SphereProp
(ren)[source]¶ An sphere that can be added to any viewer to represent regions of interest
-
set_opacity
(opac_int)[source]¶ Opacity of the sphere
Parameters: opac_int (int) – A number from 0 to 100; where 0 is invisible and 100 is opaque
-
-
class
FmriContours
(ren)[source]¶ Display contours calculated over an fMRI statistic map.
-
actor
¶ Get the contours actor
-
set_image
(img)[source]¶ Sets the statistical map
Parameters: img (vtkImageData) – Data used for contours generation
-
set_lut
(lut)[source]¶ Sets a lookup table for showing the contours
Notice the contour will always have the same vale, and therefore the same color. However the lut will reflect the changes in the contour value.
Parameters: lut (vtkScalarsToColors) – Table to generate contour color based on its value
-
PyQt Widgets¶
These classes wrap the viewers so that they can be connected into Qt applications, in theory such classes could be built for other graphical interface libraries.
-
class
QSubjectViewerWidget
(reader, parent)[source]¶ A Qt Widget that wraps
SubjectViewer
and lets it connect naturally to Qt Applications-
slice_change_handle
(new_slice)[source]¶ Emits a signal when the current image slice is changed on the vtkWidget
-
subject_viewer
¶ Access to the underlying
SubjectViewer
-
-
class
QOrthogonalPlanesWidget
(reader, parent)[source]¶ A Qt Widget that wraps
OrthogonalPlanesViewer
and lets it connect naturally to Qt Applications-
orthogonal_viewer
¶ Access to the underlying class:OrthogonalPlanesViewer
-
-
class
QMeasurerWidget
(reader, parent)[source]¶ A Qt Widget that wraps
MeasurerViewer
and lets it connect naturally to Qt Applications-
distance_changed_handle
(distance)[source]¶ Emits a signal the measured distance is changed in the vtkWidget
-
orthogonal_viewer
¶ Access to the underlying class:MeasurerViewer
-
Utilities¶
-
do_and_render
(f)[source]¶ Wraps drawing methods, adding an optional call to Render at the end.
It adds the skip_render kwarg argument, which if True will avoid the call to Render. This is useful to avoid repeated call renders when performing several draw operations.
requires the class to have the renderer accessible as self.ren
Parameters: f (function) – Function that changes vtk scene
-
class
FilterArrows
(parent=None, other_keys=())[source]¶ A Qt event filter to prevent the main vtk widget from swallowing certain keys. By default this are the arrows, but additional keys can be added in the constructor.
-
class
AdditionalCursors
(ren)[source]¶ An additional set of cursors to use when those included in vtkImageWidget are not flexible enough
-
get_coords
()[source]¶ Voxel coordinates of last picked position
Returns: Coordinates of last picked position in voxels
-
get_position
()[source]¶ Current position of the cursors
Returns: Coordinates of the last picked position (in mm)
-
set_image
(img)[source]¶ Image to use as reference for the cursors
Parameters: img (vtkImageData) – The cursors will stick to this image
-