populse_mia.user_interface.data_viewer.anatomist_2.anasimpleviewer2¶
This the anasimpleviewer2 module, a module derived from pyanatomist’s anasimpleviewer module (brainvisa/anatomist-gpl/pyanatomist/python/anatomist/simpleviewer/ anasimpleviewer.py)
This module is a viewer for 2D/3D images, and is used in Mia.
Classes
|
AnaSimpleViewer is a simple viewer application and widget. |
|
Control for 3D navigation using the left mouse button. |
|
Control for volume rendering navigation using the middle mouse button. |
- class populse_mia.user_interface.data_viewer.anatomist_2.anasimpleviewer2.LeftSimple3DControl(prio=25, name='LeftSimple3DControl')[source]¶
Bases:
Simple2DControlControl for 3D navigation using the left mouse button.
This control is particularly useful for touch devices where rotation can be achieved by pressing and holding the left mouse button.
Contains:
Methods:
eventAutoSubscription: Auto-subscribes to mouse and keyboard events relevant for 3D controls.
- __init__(prio=25, name='LeftSimple3DControl')[source]¶
Initializes the LeftSimple3DControl instance.
- Parameters:
prio – (int) The priority level for the control (default is 25).
name – (str) The name of the control (default is “LeftSimple3DControl”).
- eventAutoSubscription(pool)[source]¶
Auto-subscribes to mouse and keyboard events relevant for 3D controls.
This method sets up event subscriptions for mouse button actions and keyboard shortcuts to control the trackball actions.
- Parameters:
pool – The event pool to which the subscriptions will be made.
- class populse_mia.user_interface.data_viewer.anatomist_2.anasimpleviewer2.VolRenderControl(prio=25, name='VolRenderControl')[source]¶
Bases:
LeftSimple3DControlControl for volume rendering navigation using the middle mouse button.
This control allows users to rotate the cut slice of the volume rendering by holding down the middle mouse button.
Contains:
Methods:
eventAutoSubscription: Auto-subscribes to mouse events for cut slice rotation.
- __init__(prio=25, name='VolRenderControl')[source]¶
Initializes the VolRenderControl instance.
- Parameters:
prio – (int) The priority level for the control (default is 25).
name – (str) The name of the control (default is “VolRenderControl”).
- eventAutoSubscription(pool)[source]¶
Auto-subscribes to mouse events for cut slice rotation.
This method overrides the base class behavior to subscribe to events triggered by the middle mouse button for controlling the track cut action.
- Parameters:
pool – The event pool to which the subscriptions will be made.
- class populse_mia.user_interface.data_viewer.anatomist_2.anasimpleviewer2.AnaSimpleViewer2(init_global_handlers=None)[source]¶
Bases:
QObjectAnaSimpleViewer is a simple viewer application and widget.
It can be used via the “anasimpleviewer.py” command or included as a library module in a custom widget.
The viewer contains an object list and four 3D views (anatomist windows). Objects loaded are added to all views and can be toggled using the “add” and “remove” buttons.
This class handles methods for menu/actions callbacks and utility functions for loading/viewing objects, as well as for removal and deletion.
Note
The class inherits from QObject but is not a QWidget. The widget can be accessed through the awidget attribute of the instance.
Additionally, some global Anatomist config variables may be set within AnaSimpleViewer, initiated optionally via the init_global_handlers method called by the constructor unless init_global_handlers is set to False.
Contains:
Methods:
_displayVolume: Displays a volume or Fusion2D object in all available windows.
addMesh: Adds a 2D mesh representation of a volume object to the viewer.
addNewView: Open a popup window displaying the given object.
addObject: Displays an object in all Anatomist windows based on its type.
addVolume: Displays a volume in all windows.
automaticRunning: Enables the automatic running of functional images.
changeConfig: Changes the configuration based on user settings.
changeIcon: Updates the icon of a list item to indicate its display status.
changeOpacity: Changes the opacity of the selected object based on the slider value.
changeRef: Changes the referential and reloads objects.
checkviews: Prevents closing the last opened view.
clickHandler: Callback for linked cursor.
closeAll: Closes all open Anatomist windows and cleans up resources.
colorBackgroundList: Colors the background of items in the ‘objectslist’ widget.
coordsChanged: Sets the cursor position in the 3D view based on the coordinates entered in the GUI fields.
createWindow: Opens a new window in the windows grid layout.
createTotalWindow: Creates windows that will contain the specified views.
deleteObjects: Deletes the specified objects from the scene.
deleteObjectsFromFiles: Deletes objects from the scene based on their filenames.
deleteTotalWindow: Clears all existing windows and fusions to prepare for a new display.
disableButtons: Disables the add and remove buttons based on the selected object’s display status.
dragEnterEvent: Handles the drag enter event to determine if the dragged data can be decoded.
dropEvent: Handles the drop event to load or register Anatomist objects.
editAdd: Display all objects currently selected in the list box.
editDelete: Deletes the currently selected objects from the scene and updates the object list.
editRemove: Removes the currently selected objects from the scene and updates the background color list.
enableVolumeRendering: Enables or disables volume rendering in 3D views.
fileOpen: Open a file browser dialog and load selected objects.
get_new_mesh2d_color: Retrieves a new color for a 2D mesh that has not been used yet.
getViewsToDisplay: Determines which views need to be displayed based on the state of the view buttons.
init_global_handlers: Set some global controls/settings in Anatomist application object.
initialize_components: Initializes the component attributes and user interface.
loadObject: Loads objects from the specified files and prepares them for display.
newDisplay: Performs a new display of windows, objects, and views.
newPalette: Sets the chosen color palette in the toolbar drop-down menu to the selected object.
objectLoaded: Handles the event when an object is loaded.
object_properties: Display the properties of selected objects in an Anatomist browser window.
open_anatomist_main_window: Opens the main Anatomist control window and adds GUI menus if available.
popup_objects: Displays a context menu for selected objects in the object list.
registerObject: Registers an object in the AnaSimpleViewer’s object list and displays it.
removeMesh: Removes the specified mesh and its associated object from the viewer.
removeObject: Remove an object from all views.
removeVolume: Hides a volume from the views.
selectedObjects: Retrieve objects currently selected in the list box.
setColorPalette: Checks color palette of a selected object.
setComboBox: Inserts a drop-down menu in the toolbar containing available color palettes.
setSlider: Inserts an opacity slider in the toolbar.
setup_anatomist: Registers the Anatomist controls and options.
setup_color_palette_and_slider: Sets up the color palette dropdown and opacity slider in the toolbar.
setup_gui_connections: Connects GUI actions to their respective callbacks.
startVolumeRendering: Enables volume rendering in 3D views.
stopVolumeRendering: Disables volume rendering and displays a slice instead.
updateRendering: Updates volume rendering based on the current cursor position.
updateVolumeValues: Updates the volume values displayed based on the cursor position.
viewReferential: Centers the view on the specified object and sets the referential.
- _global_handlers_initialized = False¶
- __init__(init_global_handlers=None)[source]¶
Initializes the AnaSimpleViewer2 instance.
- Parameters:
init_global_handlers – (bool) Determines if global handlers should be initialized (default is True).
- _displayVolume(obj, opts=None)[source]¶
Displays a volume or Fusion2D object in all available windows.
If volume rendering is enabled, 3D views will display a clipped volume rendering of the object.
- Parameters:
obj – (AObject) The volume or Fusion2D object to display.
opts – (dict) Additional options for rendering.
- addMesh(obj)[source]¶
Adds a 2D mesh representation of a volume object to the viewer.
This method creates a 2D mesh from the given object and assigns a unique color. It then displays the mesh in the appropriate 2D windows and the original object in the 3D windows.
- Parameters:
obj – The volume object from which to create the mesh.
- addNewView(obj)[source]¶
Open a popup window displaying the given object.
- Parameters:
obj – The object to display. The default view is axial but may be changed by the user.
- addObject(obj)[source]¶
Displays an object in all Anatomist windows based on its type.
- Parameters:
obj – The object to be displayed. Its objectType must be one of ‘VOLUME’, ‘SURFACE’, or ‘GRAPH’.
- addVolume(obj, opts=None)[source]¶
Displays a volume in all windows.
If multiple volumes are displayed, a Fusion2D will be created to wrap them all. If volume rendering is enabled, 3D views will display a clipped volume rendering of either the single volume (if only one is present) or the 2D fusion.
- Parameters:
obj – The volume object to be displayed.
opts – (dict) Additional options for rendering.
- automaticRunning(checked=False)[source]¶
Enables the automatic running of functional images.
The frame rate can be changed in preferences by the user.
- Parameters:
checked – (bool) Not used, but required to match the QAction.triggered signal.
- changeConfig(config)[source]¶
Changes the configuration based on user settings.
- Parameters:
config – (str) “neuro” or “radio”.
- changeIcon(item, index, icon_type=None)[source]¶
Updates the icon of a list item to indicate its display status.
Replaces the specified item in the ‘objectslist’ widget with a new item at the same row, using either a check icon (if displayed) or a blank icon.
- Parameters:
item – (QListWidgetItem) The item to update in the list widget.
index – (int) Index of the object in self.aobjects to retrieve its name.
icon_type – (str) Type of icon to use. Set to “check” for a checkmark; any other value results in a blank icon.
- changeOpacity(*_)[source]¶
Changes the opacity of the selected object based on the slider value.
Changes the mixing rate between objects when multiple ones are displayed.
- changeRef()[source]¶
Changes the referential and reloads objects.
ref : Boolean
0 : World coordinates
1 : Image referential
- checkviews()[source]¶
Prevents closing the last opened view.
This method checks how many view buttons are enabled. If only one view button is checked, it disables that button to prevent closing the last view. Otherwise, all buttons remain enabled.
- clickHandler(eventName, params)[source]¶
Callback for linked cursor.
In volume rendering mode, it syncs the VR slice to the linked cursor and updates the volume values view.
- Parameters:
eventName – (str) The name of the event (unused).
params – (dict) Parameters related to the event, including position and window.
- closeAll(close_ana=True)[source]¶
Closes all open Anatomist windows and cleans up resources.
- Parameters:
close_ana – (bool) If True, closes the Anatomist instance. Defaults to True.
- colorBackgroundList()[source]¶
Colors the background of items in the ‘objectslist’ widget based on whether their corresponding objects are currently displayed.
Also updates their icons using changeIcon.
If an object’s name is in displayedObjects, the background is set to green and the icon is updated to ‘check’.
Otherwise, the background is set to transparent and the default icon is used.
- coordsChanged()[source]¶
Sets the cursor position in the 3D view based on the coordinates entered in the GUI fields.
- createWindow(wintype='Axial')[source]¶
Opens a new window in the windows grid layout.
The new window will be set in MNI referential (except 3D for the moment, due to a problem with rendering volumes in direct reference) and assigned the custom control without menus/toolbars.
- Parameters:
wintype – (str) The type of window to create (“Axial”, “Sagittal”, “Coronal” or “3D”).
- createTotalWindow(views)[source]¶
Creates windows that will contain the specified views.
This method sets a predefined camera angle for the 3D view and checks the appropriate view buttons upon creation.
- Parameters:
views – (list[str]) A list of strings specifying the view types to create. Acceptable values include “axial”, “sagittal”, “coronal”, and “3D”.
- deleteObjects(objects_to_delete)[source]¶
Deletes the specified objects from the scene, the object list widget, and the internal object list.
- Parameters:
objects_to_delete – (list) A list of objects to be deleted.
- deleteObjectsFromFiles(files)[source]¶
Deletes objects from the scene based on their filenames.
- Parameters:
files – (list) Filenames corresponding to the objects to be deleted.
- deleteTotalWindow()[source]¶
Clears all existing windows and fusions to prepare for a new display.
This method removes all windows from the grid layout and clears the 2D fusion objects. It ensures that no residual elements affect the new display setup.
- disableButtons()[source]¶
Disables the add and remove buttons based on the selected object’s display status.
This method checks the currently displayed objects and the selected item in the objects list. It disables the add button if an item is selected and currently displayed, and enables the remove button. If no object is urrently displayed or selected, it enables the add button.
- dragEnterEvent(event)[source]¶
Handles the drag enter event to determine if the dragged data can be decoded.
Accepts the event if it contains a decodable object or URI; otherwise, rejects it.
- Parameters:
event – (QDragEnterEvent) The drag enter event instance.
- dropEvent(event)[source]¶
Handles the drop event to load or register Anatomist objects.
If the dropped content can be decoded as Anatomist objects or URIs, the method registers or adds them to the current view. If the object is already present, it is re-added. Otherwise, it is loaded or registered accordingly.
- Parameters:
event – (QDropEvent) The drop event containing the data to handle.
- editAdd(checked=False)[source]¶
Display all objects currently selected in the list box.
Retrieves the objects selected in the UI and adds each one to the display. Updates the background colors in the list to reflect the new display state.
- Parameters:
checked – (bool) Not used, but required to match the QAction.triggered signal.
- editDelete(checked=False)[source]¶
Deletes the currently selected objects from the scene and updates the object list.
- Parameters:
checked – (bool) Not used, but required to match the QAction.triggered signal.
- editRemove(checked=False)[source]¶
Removes the currently selected objects from the scene and updates the background color list.
- Parameters:
checked – (bool) Not used, but required to match the QAction.triggered signal.
- enableVolumeRendering(on)[source]¶
Enables or disables volume rendering in 3D views.
- Parameters:
on – (bool) True to enable volume rendering, False to disable.
- fileOpen(checked=False)[source]¶
Open a file browser dialog and load selected objects.
Displays a QFileDialog allowing the user to select multiple existing files. After selection, passes the files to the load_object method for processing.
- Parameters:
checked – (bool) Not used, but required to match the QAction.triggered signal.
- get_new_mesh2d_color()[source]¶
Retrieves a new color for a 2D mesh that has not been used yet.
This method checks the predefined list of colors and returns the first color that is not currently in use by any of the 2D meshes. If all colors have been used, it returns a color based on the total count of existing 2D meshes.
- Returns:
(tuple[float, float, float, float]) The RGBA color.
- getViewsToDisplay()[source]¶
Determines which views need to be displayed based on the state of the view buttons.
- Returns:
(list[str]) The views to be displayed. Possible values are “Axial”, “Sagittal”, “Coronal”, and “3D”.
- initialize_components(awin)[source]¶
Initializes the component attributes and user interface.
- Parameters:
awin – The main window widget.
- loadObject(files, config_changed=None)[source]¶
Loads objects from the specified files and prepares them for display.
This method displays only the first loaded object. Subsequent objects are added to the object list but not displayed. If an object has already been imported, a warning message is shown.
- Parameters:
files – (list[str]) A list of file names to load objects from.
config_changed – (bool) Indicates whether the configuration has changed. If True, the method will return early if an object has already been imported.
- newDisplay(checked=False)[source]¶
Performs a new display of windows, objects, and views.
This method checks the state of view buttons, deletes any existing windows and displayed objects, initializes new views based on the state of the view buttons, and adds existing objects to the new display.
- Parameters:
checked – (bool) Not used, but required to match the QAction.triggered signal.
- newPalette(*_)[source]¶
Sets the chosen color palette in the toolbar drop-down menu to the selected object.
- objectLoaded(obj, filename)[source]¶
Handles the event when an object is loaded.
This method registers the loaded object with the Anatomist application and manages processing execution state.
- Parameters:
obj – (AObject) The loaded object to be registered.
filename – (str) The name of the file from which the object was loaded (unused).
- object_properties(checked=False)[source]¶
Display the properties of selected objects in an Anatomist browser window.
If the browser does not exist, is null, or is not visible, a new one is created. Otherwise, the existing browser is cleared and updated with the current selection.
- Parameters:
checked – (bool) Not used, but required to connect properly to the QAction.triggered signal.
- open_anatomist_main_window(checked=False)[source]¶
Opens the main Anatomist control window and adds GUI menus if available.
- Parameters:
checked – (bool) Not used, but required to match the QAction.triggered signal.
- registerObject(obj, views=None)[source]¶
Registers an object in the AnaSimpleViewer’s object list and displays it.
- Parameters:
obj – The object to register and display.
views – (list[str]) A list of view types to create if windows do not already exist.
- removeMesh(obj)[source]¶
Removes the specified mesh and its associated object from the viewer.
This method locates the mesh associated with the provided object, removes both the object and its mesh from the displayed windows, and updates the internal structures accordingly.
- Parameters:
obj – The volume object whose mesh is to be removed.
- removeObject(obj)[source]¶
Remove an object from all views.
This method hides the specified object from all associated views and performs additional cleanup based on the object type.
- Parameters:
obj – The object to be removed from display.
- removeVolume(obj, opts=None)[source]¶
Hides a volume from the views.
This method removes the specified volume object from the display. If multiple volumes are associated with the Fusion2D, it updates the Fusion2D object accordingly. If volume rendering is enabled, it also handles the cleanup of the rendered objects.
- Parameters:
obj – The volume object to be removed.
opts – (dict) Additional options for rendering.
- selectedObjects()[source]¶
Retrieve objects currently selected in the list box.
Finds selected items in the UI list box on the upper left panel and returns the corresponding anatomical objects.
- Returns:
(list) List of anatomical objects that are currently selected in the UI. Empty list if no objects are selected.
- setColorPalette()[source]¶
Checks color palette of a selected object, displays it in the toolbar drop-down menu and adds it if it isn’t already stored in self.available_palettes.
If corresponding palette image exists it is added, otherwise only the name of the palette appears.
- setComboBox()[source]¶
Inserts a drop-down menu in the toolbar containing available color palettes.
The default color palettes are in self.available_palettes.
- setSlider()[source]¶
Inserts an opacity slider in the toolbar.
Minimum value is 0 and maximum value is 100.
- setup_anatomist(a)[source]¶
Registers the Anatomist controls and options.
- Parameters:
a – The Anatomist instance.
- setup_color_palette_and_slider()[source]¶
Sets up the color palette dropdown and opacity slider in the toolbar.
- setup_gui_connections(awin)[source]¶
Connects GUI actions to their respective callbacks.
- Parameters:
awin – (Qt.QWidget) The main window widget to connect actions to.
- updateRendering(win, a, pos)[source]¶
Updates volume rendering based on the current cursor position.
- Parameters:
win – The current window instance.
a – The Anatomist instance.
pos – The current cursor position.
- updateVolumeValues(win, a, pos)[source]¶
Updates the volume values displayed based on the cursor position.
Handles both 3D and 4D volumes robustly. Anatomist may provide 3D or 4D positions depending on the object type and context.
- Parameters:
win – The current window instance for transformations.
a – The Anatomist instance for transformation.
pos – The current position of the cursor.