<s> import os , sys <EOL> import unittest <EOL> from __main__ import vtk , qt , ctk , slicer <EOL> from slicer . ScriptedLoadableModule import * <EOL> import logging <EOL> try : <EOL> from CIP . logic . SlicerUtil import SlicerUtil <EOL> except Exception as ex : <EOL> currentpath = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> path = os . path . normpath ( currentpath + '<STR_LIT>' ) <EOL> if not os . path . exists ( path ) : <EOL> path = os . path . normpath ( currentpath + '<STR_LIT>' ) <EOL> sys . path . append ( path ) <EOL> print ( "<STR_LIT>" + path ) <EOL> from CIP . logic . SlicerUtil import SlicerUtil <EOL> from CIP . logic import Util <EOL> from CIP . ui import CaseReportsWidget <EOL> class CIP_PAARatio ( ScriptedLoadableModule ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent ) : <EOL> ScriptedLoadableModule . __init__ ( self , parent ) <EOL> self . parent . title = "<STR_LIT>" <EOL> self . parent . categories = SlicerUtil . CIP_ModulesCategory <EOL> self . parent . dependencies = [ SlicerUtil . CIP_ModuleName ] <EOL> self . parent . contributors = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . parent . helpText = """<STR_LIT>""" <EOL> self . parent . acknowledgementText = SlicerUtil . ACIL_AcknowledgementText <EOL> class CIP_PAARatioWidget ( ScriptedLoadableModuleWidget ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def moduleName ( self ) : <EOL> return "<STR_LIT>" <EOL> def __init__ ( self , parent ) : <EOL> ScriptedLoadableModuleWidget . __init__ ( self , parent ) <EOL> from functools import partial <EOL> def __onNodeAddedObserver__ ( self , caller , eventId , callData ) : <EOL> """<STR_LIT>""" <EOL> if callData . GetClassName ( ) == '<STR_LIT>' and slicer . util . mainWindow ( ) . moduleSelector ( ) . selectedModule == self . moduleName : <EOL> self . volumeSelector . setCurrentNode ( callData ) <EOL> self . __onNodeAddedObserver__ = partial ( __onNodeAddedObserver__ , self ) <EOL> self . __onNodeAddedObserver__ . CallDataType = vtk . VTK_OBJECT <EOL> def setup ( self ) : <EOL> """<STR_LIT>""" <EOL> ScriptedLoadableModuleWidget . setup ( self ) <EOL> self . logic = CIP_PAARatioLogic ( ) <EOL> mainAreaCollapsibleButton = ctk . ctkCollapsibleButton ( ) <EOL> mainAreaCollapsibleButton . text = "<STR_LIT>" <EOL> self . layout . addWidget ( mainAreaCollapsibleButton ) <EOL> self . mainAreaLayout = qt . QGridLayout ( mainAreaCollapsibleButton ) <EOL> self . label = qt . QLabel ( "<STR_LIT>" ) <EOL> self . label . setStyleSheet ( "<STR_LIT>" ) <EOL> self . mainAreaLayout . addWidget ( self . label , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . volumeSelector = slicer . qMRMLNodeComboBox ( ) <EOL> self . volumeSelector . nodeTypes = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . volumeSelector . selectNodeUponCreation = True <EOL> self . volumeSelector . autoFillBackground = True <EOL> self . volumeSelector . addEnabled = True <EOL> self . volumeSelector . noneEnabled = False <EOL> self . volumeSelector . removeEnabled = False <EOL> self . volumeSelector . showHidden = False <EOL> self . volumeSelector . showChildNodeTypes = False <EOL> self . volumeSelector . setMRMLScene ( slicer . mrmlScene ) <EOL> self . volumeSelector . setStyleSheet ( "<STR_LIT>" ) <EOL> self . mainAreaLayout . addWidget ( self . volumeSelector , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> self . placeDefaultRulersButton = ctk . ctkPushButton ( ) <EOL> self . placeDefaultRulersButton . text = "<STR_LIT>" <EOL> self . placeDefaultRulersButton . setIcon ( qt . QIcon ( "<STR_LIT>" . format ( SlicerUtil . CIP_ICON_DIR ) ) ) <EOL> self . placeDefaultRulersButton . setIconSize ( qt . QSize ( <NUM_LIT:20> , <NUM_LIT:20> ) ) <EOL> self . placeDefaultRulersButton . setStyleSheet ( "<STR_LIT>" ) <EOL> self . mainAreaLayout . addWidget ( self . placeDefaultRulersButton , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . structuresGroupbox = qt . QGroupBox ( "<STR_LIT>" ) <EOL> self . groupboxLayout = qt . QVBoxLayout ( ) <EOL> self . structuresGroupbox . setLayout ( self . groupboxLayout ) <EOL> self . mainAreaLayout . addWidget ( self . structuresGroupbox , <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> self . structuresButtonGroup = qt . QButtonGroup ( ) <EOL> btn = qt . QRadioButton ( "<STR_LIT>" ) <EOL> btn . checked = True <EOL> self . structuresButtonGroup . addButton ( btn , <NUM_LIT:0> ) <EOL> self . groupboxLayout . addWidget ( btn ) <EOL> btn = qt . QRadioButton ( "<STR_LIT>" ) <EOL> self . structuresButtonGroup . addButton ( btn , <NUM_LIT:1> ) <EOL> self . groupboxLayout . addWidget ( btn ) <EOL> btn = qt . QRadioButton ( "<STR_LIT>" ) <EOL> self . structuresButtonGroup . addButton ( btn , <NUM_LIT:2> ) <EOL> self . groupboxLayout . addWidget ( btn ) <EOL> self . buttonsToolboxFrame = qt . QFrame ( ) <EOL> self . buttonsToolboxLayout = qt . QGridLayout ( ) <EOL> self . buttonsToolboxFrame . setLayout ( self . buttonsToolboxLayout ) <EOL> self . mainAreaLayout . addWidget ( self . buttonsToolboxFrame , <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> self . placeRulersButton = ctk . ctkPushButton ( ) <EOL> self . placeRulersButton . text = "<STR_LIT>" <EOL> self . placeRulersButton . toolTip = "<STR_LIT>" <EOL> self . placeRulersButton . setIcon ( qt . QIcon ( "<STR_LIT>" . format ( SlicerUtil . CIP_ICON_DIR ) ) ) <EOL> self . placeRulersButton . setIconSize ( qt . QSize ( <NUM_LIT:20> , <NUM_LIT:20> ) ) <EOL> self . placeRulersButton . setFixedWidth ( <NUM_LIT> ) <EOL> self . placeRulersButton . setStyleSheet ( "<STR_LIT>" ) <EOL> self . buttonsToolboxLayout . addWidget ( self . placeRulersButton , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . moveUpButton = ctk . ctkPushButton ( ) <EOL> self . moveUpButton . text = "<STR_LIT>" <EOL> self . moveUpButton . toolTip = "<STR_LIT>" <EOL> self . moveUpButton . setIcon ( qt . QIcon ( "<STR_LIT>" . format ( SlicerUtil . CIP_ICON_DIR ) ) ) <EOL> self . moveUpButton . setIconSize ( qt . QSize ( <NUM_LIT:20> , <NUM_LIT:20> ) ) <EOL> self . moveUpButton . setFixedWidth ( <NUM_LIT> ) <EOL> self . buttonsToolboxLayout . addWidget ( self . moveUpButton , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> self . moveDownButton = ctk . ctkPushButton ( ) <EOL> self . moveDownButton . text = "<STR_LIT>" <EOL> self . moveDownButton . toolTip = "<STR_LIT>" <EOL> self . moveDownButton . setIcon ( qt . QIcon ( "<STR_LIT>" . format ( SlicerUtil . CIP_ICON_DIR ) ) ) <EOL> self . moveDownButton . setIconSize ( qt . QSize ( <NUM_LIT:20> , <NUM_LIT:20> ) ) <EOL> self . moveDownButton . setFixedWidth ( <NUM_LIT> ) <EOL> self . buttonsToolboxLayout . addWidget ( self . moveDownButton , <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> self . removeButton = ctk . ctkPushButton ( ) <EOL> self . removeButton . text = "<STR_LIT>" <EOL> self . removeButton . toolTip = "<STR_LIT>" <EOL> self . removeButton . setIcon ( qt . QIcon ( "<STR_LIT>" . format ( SlicerUtil . CIP_ICON_DIR ) ) ) <EOL> self . removeButton . setIconSize ( qt . QSize ( <NUM_LIT:20> , <NUM_LIT:20> ) ) <EOL> self . buttonsToolboxLayout . addWidget ( self . removeButton , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> self . textboxesFrame = qt . QFrame ( ) <EOL> self . textboxesLayout = qt . QFormLayout ( ) <EOL> self . textboxesFrame . setLayout ( self . textboxesLayout ) <EOL> self . textboxesFrame . setFixedWidth ( <NUM_LIT> ) <EOL> self . mainAreaLayout . addWidget ( self . textboxesFrame , <NUM_LIT:3> , <NUM_LIT:0> ) <EOL> self . paTextBox = qt . QLineEdit ( ) <EOL> self . paTextBox . setReadOnly ( True ) <EOL> self . textboxesLayout . addRow ( "<STR_LIT>" , self . paTextBox ) <EOL> self . aortaTextBox = qt . QLineEdit ( ) <EOL> self . aortaTextBox . setReadOnly ( True ) <EOL> self . textboxesLayout . addRow ( "<STR_LIT>" , self . aortaTextBox ) <EOL> self . ratioTextBox = qt . QLineEdit ( ) <EOL> self . ratioTextBox . setReadOnly ( True ) <EOL> self . textboxesLayout . addRow ( "<STR_LIT>" , self . ratioTextBox ) <EOL> self . reportsCollapsibleButton = ctk . ctkCollapsibleButton ( ) <EOL> self . reportsCollapsibleButton . text = "<STR_LIT>" <EOL> self . layout . addWidget ( self . reportsCollapsibleButton ) <EOL> self . reportsLayout = qt . QHBoxLayout ( self . reportsCollapsibleButton ) <EOL> self . storedColumnNames = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . reportsWidget = CaseReportsWidget ( "<STR_LIT>" , columnNames = self . storedColumnNames , parentWidget = self . reportsCollapsibleButton ) <EOL> self . reportsWidget . setup ( ) <EOL> self . switchToRedView ( ) <EOL> if SlicerUtil . isSlicerACILLoaded ( ) : <EOL> caseNavigatorAreaCollapsibleButton = ctk . ctkCollapsibleButton ( ) <EOL> caseNavigatorAreaCollapsibleButton . text = "<STR_LIT>" <EOL> self . layout . addWidget ( caseNavigatorAreaCollapsibleButton , <NUM_LIT> ) <EOL> from ACIL . ui import CaseNavigatorWidget <EOL> self . caseNavigatorWidget = CaseNavigatorWidget ( self . moduleName , caseNavigatorAreaCollapsibleButton ) <EOL> self . caseNavigatorWidget . setup ( ) <EOL> self . layout . addStretch ( ) <EOL> self . observers = [ ] <EOL> self . __addSceneObservables__ ( ) <EOL> self . volumeSelector . connect ( '<STR_LIT>' , self . onVolumeSelectorChanged ) <EOL> self . placeDefaultRulersButton . connect ( '<STR_LIT>' , self . oPlaceDefaultRulersClicked ) <EOL> self . placeRulersButton . connect ( '<STR_LIT>' , self . onPlaceRulersClicked ) <EOL> self . moveUpButton . connect ( '<STR_LIT>' , self . onMoveUpRulerClicked ) <EOL> self . moveDownButton . connect ( '<STR_LIT>' , self . onMoveDownRulerClicked ) <EOL> self . removeButton . connect ( '<STR_LIT>' , self . onRemoveRulerClicked ) <EOL> self . reportsWidget . addObservable ( self . reportsWidget . EVENT_SAVE_BUTTON_CLICKED , self . onSaveReport ) <EOL> def enter ( self ) : <EOL> """<STR_LIT>""" <EOL> volumeId = self . volumeSelector . currentNodeId <EOL> if volumeId : <EOL> SlicerUtil . setActiveVolumeId ( volumeId ) <EOL> def exit ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def cleanup ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def jumpToTemptativeSlice ( self , volumeId ) : <EOL> """<STR_LIT>""" <EOL> aorta1 , aorta2 , pa1 , pa2 = self . logic . getDefaultCoords ( volumeId ) <EOL> self . moveRedWindowToSlice ( aorta1 [ <NUM_LIT:2> ] ) <EOL> def placeDefaultRulers ( self , volumeId ) : <EOL> """<STR_LIT>""" <EOL> if not volumeId : <EOL> return <EOL> self . logic . hideAllRulers ( ) <EOL> self . logic . removeRulers ( volumeId ) <EOL> self . logic . createDefaultRulers ( volumeId , self . onRulerUpdated ) <EOL> self . structuresButtonGroup . buttons ( ) [ <NUM_LIT:0> ] . setChecked ( True ) <EOL> self . jumpToTemptativeSlice ( volumeId ) <EOL> self . placeRuler ( ) <EOL> self . logic . currentVolumesLoaded . add ( volumeId ) <EOL> redSliceNode = slicer . util . getFirstNodeByClassByName ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> factor = <NUM_LIT:0.5> <EOL> newFOVx = redSliceNode . GetFieldOfView ( ) [ <NUM_LIT:0> ] * factor <EOL> newFOVy = redSliceNode . GetFieldOfView ( ) [ <NUM_LIT:1> ] * factor <EOL> newFOVz = redSliceNode . GetFieldOfView ( ) [ <NUM_LIT:2> ] <EOL> redSliceNode . SetFieldOfView ( newFOVx , newFOVy , newFOVz ) <EOL> redSliceNode . SetXYZOrigin ( <NUM_LIT:0> , <NUM_LIT:50> , <NUM_LIT:0> ) <EOL> redSliceNode . UpdateMatrices ( ) <EOL> def placeRuler ( self ) : <EOL> """<STR_LIT>""" <EOL> volumeId = self . volumeSelector . currentNodeId <EOL> if volumeId == '<STR_LIT>' : <EOL> self . showUnselectedVolumeWarningMessage ( ) <EOL> return <EOL> selectedStructure = self . getCurrentSelectedStructure ( ) <EOL> if selectedStructure == self . logic . NONE : <EOL> qt . QMessageBox . warning ( slicer . util . mainWindow ( ) , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> return <EOL> currentSlice = self . getCurrentRedWindowSlice ( ) <EOL> if selectedStructure == self . logic . BOTH : <EOL> structures = [ self . logic . PA , self . logic . AORTA ] <EOL> else : <EOL> structures = [ selectedStructure ] <EOL> for structure in structures : <EOL> self . logic . placeRulerInSlice ( volumeId , structure , currentSlice , self . onRulerUpdated ) <EOL> self . refreshTextboxes ( ) <EOL> def getCurrentSelectedStructure ( self ) : <EOL> """<STR_LIT>""" <EOL> selectedStructureText = self . structuresButtonGroup . checkedButton ( ) . text <EOL> if selectedStructureText == "<STR_LIT>" : return self . logic . AORTA <EOL> elif selectedStructureText == "<STR_LIT>" : return self . logic . PA <EOL> elif selectedStructureText == "<STR_LIT>" : return self . logic . BOTH <EOL> return self . logic . NONE <EOL> def stepSlice ( self , offset ) : <EOL> """<STR_LIT>""" <EOL> volumeId = self . volumeSelector . currentNodeId <EOL> if volumeId == '<STR_LIT>' : <EOL> self . showUnselectedVolumeWarningMessage ( ) <EOL> return <EOL> selectedStructure = self . getCurrentSelectedStructure ( ) <EOL> if selectedStructure == self . logic . NONE : <EOL> self . showUnselectedStructureWarningMessage ( ) <EOL> return <EOL> if selectedStructure == self . logic . BOTH : <EOL> self . logic . stepSlice ( volumeId , self . logic . AORTA , offset ) <EOL> newSlice = self . logic . stepSlice ( volumeId , self . logic . PA , offset ) <EOL> else : <EOL> newSlice = self . logic . stepSlice ( volumeId , selectedStructure , offset ) <EOL> self . moveRedWindowToSlice ( newSlice ) <EOL> def removeRulers ( self ) : <EOL> """<STR_LIT>""" <EOL> self . logic . removeRulers ( self . volumeSelector . currentNodeId ) <EOL> self . refreshTextboxes ( reset = True ) <EOL> def getCurrentRedWindowSlice ( self ) : <EOL> """<STR_LIT>""" <EOL> redNodeSliceNode = slicer . app . layoutManager ( ) . sliceWidget ( '<STR_LIT>' ) . sliceLogic ( ) . GetSliceNode ( ) <EOL> return redNodeSliceNode . GetSliceOffset ( ) <EOL> def moveRedWindowToSlice ( self , newSlice ) : <EOL> """<STR_LIT>""" <EOL> redNodeSliceNode = slicer . app . layoutManager ( ) . sliceWidget ( '<STR_LIT>' ) . sliceLogic ( ) . GetSliceNode ( ) <EOL> redNodeSliceNode . JumpSlice ( <NUM_LIT:0> , <NUM_LIT:0> , newSlice ) <EOL> def refreshTextboxes ( self , reset = False ) : <EOL> """<STR_LIT>""" <EOL> self . aortaTextBox . setText ( "<STR_LIT:0>" ) <EOL> self . paTextBox . setText ( "<STR_LIT:0>" ) <EOL> self . ratioTextBox . setText ( "<STR_LIT:0>" ) <EOL> self . ratioTextBox . setStyleSheet ( "<STR_LIT>" ) ; <EOL> volumeId = self . volumeSelector . currentNodeId <EOL> if volumeId not in self . logic . currentVolumesLoaded : <EOL> return <EOL> if volumeId : <EOL> self . logic . changeColor ( volumeId , self . logic . defaultColor ) <EOL> aorta = None <EOL> pa = None <EOL> if not reset : <EOL> rulerAorta , newAorta = self . logic . getRulerNodeForVolumeAndStructure ( self . volumeSelector . currentNodeId , <EOL> self . logic . AORTA , createIfNotExist = False ) <EOL> rulerPA , newPA = self . logic . getRulerNodeForVolumeAndStructure ( self . volumeSelector . currentNodeId , <EOL> self . logic . PA , createIfNotExist = False ) <EOL> if rulerAorta : <EOL> aorta = rulerAorta . GetDistanceMeasurement ( ) <EOL> self . aortaTextBox . setText ( str ( aorta ) ) <EOL> if rulerPA : <EOL> pa = rulerPA . GetDistanceMeasurement ( ) <EOL> self . paTextBox . setText ( str ( pa ) ) <EOL> if aorta is not None and aorta != <NUM_LIT:0> : <EOL> try : <EOL> ratio = pa / aorta <EOL> self . ratioTextBox . setText ( str ( ratio ) ) <EOL> if ratio > <NUM_LIT:1> : <EOL> self . ratioTextBox . setStyleSheet ( "<STR_LIT>" ) ; <EOL> self . logic . changeColor ( volumeId , self . logic . defaultWarningColor ) <EOL> except Exception : <EOL> Util . print_last_exception ( ) <EOL> def showUnselectedVolumeWarningMessage ( self ) : <EOL> qt . QMessageBox . warning ( slicer . util . mainWindow ( ) , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def showUnselectedStructureWarningMessage ( self ) : <EOL> qt . QMessageBox . warning ( slicer . util . mainWindow ( ) , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def switchToRedView ( self ) : <EOL> """<STR_LIT>""" <EOL> layoutManager = slicer . app . layoutManager ( ) <EOL> layoutManager . setLayout ( <NUM_LIT:6> ) <EOL> def __addSceneObservables__ ( self ) : <EOL> self . observers . append ( slicer . mrmlScene . AddObserver ( slicer . vtkMRMLScene . NodeAddedEvent , self . __onNodeAddedObserver__ ) ) <EOL> self . observers . append ( slicer . mrmlScene . AddObserver ( slicer . vtkMRMLScene . EndCloseEvent , self . __onSceneClosed__ ) ) <EOL> def __removeSceneObservables ( self ) : <EOL> for observer in self . observers : <EOL> slicer . mrmlScene . RemoveObserver ( observer ) <EOL> self . observers . remove ( observer ) <EOL> def onVolumeSelectorChanged ( self , node ) : <EOL> self . refreshTextboxes ( ) <EOL> def onStructureClicked ( self , button ) : <EOL> fiducialsNode = self . getFiducialsNode ( self . volumeSelector . currentNodeId ) <EOL> if fiducialsNode is not None : <EOL> self . __addRuler__ ( button . text , self . volumeSelector . currentNodeId ) <EOL> markupsLogic = slicer . modules . markups . logic ( ) <EOL> markupsLogic . SetActiveListID ( fiducialsNode ) <EOL> applicationLogic = slicer . app . applicationLogic ( ) <EOL> selectionNode = applicationLogic . GetSelectionNode ( ) <EOL> selectionNode . SetReferenceActivePlaceNodeClassName ( "<STR_LIT>" ) <EOL> interactionNode = applicationLogic . GetInteractionNode ( ) <EOL> interactionNode . SwitchToSinglePlaceMode ( ) <EOL> def oPlaceDefaultRulersClicked ( self ) : <EOL> volumeId = self . volumeSelector . currentNodeId <EOL> if volumeId == '<STR_LIT>' : <EOL> self . showUnselectedVolumeWarningMessage ( ) <EOL> return <EOL> self . placeDefaultRulers ( volumeId ) <EOL> def onRulerUpdated ( self , node , event ) : <EOL> self . refreshTextboxes ( ) <EOL> def onPlaceRulersClicked ( self ) : <EOL> self . placeRuler ( ) <EOL> def onMoveUpRulerClicked ( self ) : <EOL> self . stepSlice ( <NUM_LIT:1> ) <EOL> def onMoveDownRulerClicked ( self ) : <EOL> self . stepSlice ( - <NUM_LIT:1> ) <EOL> def onRemoveRulerClicked ( self ) : <EOL> if ( qt . QMessageBox . question ( slicer . util . mainWindow ( ) , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> qt . QMessageBox . Yes | qt . QMessageBox . No ) ) == qt . QMessageBox . Yes : <EOL> self . logic . removeRulers ( self . volumeSelector . currentNodeId ) <EOL> self . refreshTextboxes ( ) <EOL> def onSaveReport ( self ) : <EOL> """<STR_LIT>""" <EOL> volumeId = self . volumeSelector . currentNodeId <EOL> if volumeId : <EOL> caseName = slicer . mrmlScene . GetNodeByID ( volumeId ) . GetName ( ) <EOL> coords = [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> pa1 = pa2 = a1 = a2 = None <EOL> rulerNode , newNode = self . logic . getRulerNodeForVolumeAndStructure ( volumeId , self . logic . PA , createIfNotExist = False ) <EOL> if rulerNode : <EOL> rulerNode . GetPositionWorldCoordinates1 ( coords ) <EOL> pa1 = list ( coords ) <EOL> rulerNode . GetPositionWorldCoordinates2 ( coords ) <EOL> pa2 = list ( coords ) <EOL> rulerNode , newNode = self . logic . getRulerNodeForVolumeAndStructure ( volumeId , self . logic . AORTA , createIfNotExist = False ) <EOL> if rulerNode : <EOL> rulerNode . GetPositionWorldCoordinates1 ( coords ) <EOL> a1 = list ( coords ) <EOL> rulerNode . GetPositionWorldCoordinates2 ( coords ) <EOL> a2 = list ( coords ) <EOL> self . reportsWidget . saveCurrentValues ( <EOL> caseId = caseName , <EOL> paDiameter_mm = self . paTextBox . text , <EOL> aortaDiameter_mm = self . aortaTextBox . text , <EOL> pa1r = pa1 [ <NUM_LIT:0> ] if pa1 is not None else '<STR_LIT>' , <EOL> pa1a = pa1 [ <NUM_LIT:1> ] if pa1 is not None else '<STR_LIT>' , <EOL> pa1s = pa1 [ <NUM_LIT:2> ] if pa1 is not None else '<STR_LIT>' , <EOL> pa2r = pa2 [ <NUM_LIT:0> ] if pa2 is not None else '<STR_LIT>' , <EOL> pa2a = pa2 [ <NUM_LIT:1> ] if pa2 is not None else '<STR_LIT>' , <EOL> pa2s = pa2 [ <NUM_LIT:2> ] if pa2 is not None else '<STR_LIT>' , <EOL> a1r = a1 [ <NUM_LIT:0> ] if a1 is not None else '<STR_LIT>' , <EOL> a1a = a1 [ <NUM_LIT:1> ] if a1 is not None else '<STR_LIT>' , <EOL> a1s = a1 [ <NUM_LIT:2> ] if a1 is not None else '<STR_LIT>' , <EOL> a2r = a2 [ <NUM_LIT:0> ] if a2 is not None else '<STR_LIT>' , <EOL> a2a = a2 [ <NUM_LIT:1> ] if a2 is not None else '<STR_LIT>' , <EOL> a2s = a2 [ <NUM_LIT:2> ] if a2 is not None else '<STR_LIT>' <EOL> ) <EOL> qt . QMessageBox . information ( slicer . util . mainWindow ( ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __onSceneClosed__ ( self , arg1 , arg2 ) : <EOL> """<STR_LIT>""" <EOL> self . logic . currentVolumesLoaded . clear ( ) <EOL> class CIP_PAARatioLogic ( ScriptedLoadableModuleLogic ) : <EOL> """<STR_LIT>""" <EOL> NONE = <NUM_LIT:0> <EOL> AORTA = <NUM_LIT:1> <EOL> PA = <NUM_LIT:2> <EOL> BOTH = <NUM_LIT:3> <EOL> SLICEFACTOR = <NUM_LIT> <EOL> defaultAorta1 = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> ] <EOL> defaultAorta2 = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> ] <EOL> defaultPA1 = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> ] <EOL> defaultPA2 = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> ] <EOL> defaultColor = [ <NUM_LIT:0.5> , <NUM_LIT:0.5> , <NUM_LIT:1> ] <EOL> defaultWarningColor = [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> def __init__ ( self ) : <EOL> self . currentVolumesLoaded = set ( ) <EOL> def getRootAnnotationsNode ( self ) : <EOL> """<STR_LIT>""" <EOL> return SlicerUtil . getRootAnnotationsNode ( ) <EOL> def getRulersListNode ( self , volumeId , createIfNotExist = True ) : <EOL> """<STR_LIT>""" <EOL> nodeName = volumeId + '<STR_LIT>' <EOL> rulersNode = slicer . util . getNode ( nodeName ) <EOL> if rulersNode is None and createIfNotExist : <EOL> annotationsLogic = slicer . modules . annotations . logic ( ) <EOL> rootHierarchyNode = self . getRootAnnotationsNode ( ) <EOL> annotationsLogic . SetActiveHierarchyNodeID ( rootHierarchyNode . GetID ( ) ) <EOL> annotationsLogic . AddHierarchy ( ) <EOL> n = rootHierarchyNode . GetNumberOfChildrenNodes ( ) <EOL> rulersNode = rootHierarchyNode . GetNthChildNode ( n - <NUM_LIT:1> ) <EOL> rulersNode . SetName ( nodeName ) <EOL> logging . debug ( "<STR_LIT>" + nodeName + "<STR_LIT>" ) <EOL> return rulersNode <EOL> def getRulerNodeForVolumeAndStructure ( self , volumeId , structureId , createIfNotExist = True , callbackWhenRulerModified = None ) : <EOL> """<STR_LIT>""" <EOL> isNewNode = False <EOL> if structureId == <NUM_LIT:0> : <EOL> return None , isNewNode <EOL> if structureId == self . AORTA : <EOL> nodeName = "<STR_LIT:A>" <EOL> elif structureId == self . PA : <EOL> nodeName = "<STR_LIT>" <EOL> rulersListNode = self . getRulersListNode ( volumeId , createIfNotExist = createIfNotExist ) <EOL> node = None <EOL> if rulersListNode : <EOL> for i in range ( rulersListNode . GetNumberOfChildrenNodes ( ) ) : <EOL> nodeWrapper = rulersListNode . GetNthChildNode ( i ) <EOL> col = vtk . vtkCollection ( ) <EOL> nodeWrapper . GetChildrenDisplayableNodes ( col ) <EOL> rulerNode = col . GetItemAsObject ( <NUM_LIT:0> ) <EOL> if rulerNode . GetName ( ) == nodeName : <EOL> node = rulerNode <EOL> break <EOL> if node is None and createIfNotExist : <EOL> annotationsLogic = slicer . modules . annotations . logic ( ) <EOL> annotationsLogic . SetActiveHierarchyNodeID ( rulersListNode . GetID ( ) ) <EOL> node = slicer . mrmlScene . CreateNodeByClass ( '<STR_LIT>' ) <EOL> node . SetName ( nodeName ) <EOL> self . __changeColor__ ( node , self . defaultColor ) <EOL> slicer . mrmlScene . AddNode ( node ) <EOL> isNewNode = True <EOL> node . AddObserver ( vtk . vtkCommand . ModifiedEvent , callbackWhenRulerModified ) <EOL> logging . debug ( "<STR_LIT>" + nodeName + "<STR_LIT>" + volumeId ) <EOL> return node , isNewNode <EOL> def hideAllRulers ( self ) : <EOL> """<STR_LIT>""" <EOL> for volume in self . currentVolumesLoaded : <EOL> rulersNode = self . getRulersListNode ( volume , False ) <EOL> if rulersNode : <EOL> print ( "<STR_LIT>" + rulersNode . GetID ( ) ) <EOL> def __changeColor__ ( self , node , color ) : <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> n = node . GetNthDisplayNode ( i ) <EOL> if n : <EOL> n . SetColor ( color ) <EOL> slicer . app . layoutManager ( ) . sliceWidget ( "<STR_LIT>" ) . sliceView ( ) . mrmlSliceNode ( ) . Modified ( ) <EOL> def changeColor ( self , volumeId , color ) : <EOL> """<STR_LIT>""" <EOL> for structureId in [ self . PA , self . AORTA ] : <EOL> node , new = self . getRulerNodeForVolumeAndStructure ( volumeId , structureId , createIfNotExist = False ) <EOL> if node : <EOL> self . __changeColor__ ( node , color ) <EOL> def createDefaultRulers ( self , volumeId , callbackWhenRulerModified ) : <EOL> """<STR_LIT>""" <EOL> aorta1 , aorta2 , pa1 , pa2 = self . getDefaultCoords ( volumeId ) <EOL> rulerNodeAorta , newNodeAorta = self . getRulerNodeForVolumeAndStructure ( volumeId , self . AORTA , <EOL> createIfNotExist = True , callbackWhenRulerModified = callbackWhenRulerModified ) <EOL> rulerNodeAorta . SetPositionWorldCoordinates1 ( aorta1 ) <EOL> rulerNodeAorta . SetPositionWorldCoordinates2 ( aorta2 ) <EOL> rulerNodePA , newNodePA = self . getRulerNodeForVolumeAndStructure ( volumeId , self . PA , <EOL> createIfNotExist = True , callbackWhenRulerModified = callbackWhenRulerModified ) <EOL> rulerNodePA . SetPositionWorldCoordinates1 ( pa1 ) <EOL> rulerNodePA . SetPositionWorldCoordinates2 ( pa2 ) <EOL> return rulerNodeAorta , newNodeAorta , rulerNodePA , newNodePA <EOL> def stepSlice ( self , volumeId , structureId , sliceStep ) : <EOL> """<STR_LIT>""" <EOL> rulerNode , newNode = self . getRulerNodeForVolumeAndStructure ( volumeId , structureId , createIfNotExist = False ) <EOL> if not rulerNode : <EOL> return False <EOL> coords = [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> rulerNode . GetPositionWorldCoordinates1 ( coords ) <EOL> rastoijk = vtk . vtkMatrix4x4 ( ) <EOL> ijktoras = vtk . vtkMatrix4x4 ( ) <EOL> scalarVolumeNode = slicer . mrmlScene . GetNodeByID ( volumeId ) <EOL> scalarVolumeNode . GetRASToIJKMatrix ( rastoijk ) <EOL> scalarVolumeNode . GetIJKToRASMatrix ( ijktoras ) <EOL> ijkCoords = list ( rastoijk . MultiplyPoint ( coords ) ) <EOL> ijkCoords [ <NUM_LIT:2> ] += sliceStep <EOL> newSlice = ijktoras . MultiplyPoint ( ijkCoords ) [ <NUM_LIT:2> ] <EOL> self . _placeRulerInSlice_ ( rulerNode , structureId , volumeId , newSlice ) <EOL> return newSlice <EOL> def placeRulerInSlice ( self , volumeId , structureId , newSlice , callbackWhenUpdated = None ) : <EOL> """<STR_LIT>""" <EOL> rulerNode , newNode = self . getRulerNodeForVolumeAndStructure ( volumeId , structureId , createIfNotExist = True ) <EOL> self . currentVolumesLoaded . add ( volumeId ) <EOL> self . _placeRulerInSlice_ ( rulerNode , structureId , volumeId , newSlice ) <EOL> def _placeRulerInSlice_ ( self , rulerNode , structureId , volumeId , newSlice ) : <EOL> """<STR_LIT>""" <EOL> coords1 = [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> coords2 = [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> rulerNode . GetPositionWorldCoordinates1 ( coords1 ) <EOL> rulerNode . GetPositionWorldCoordinates2 ( coords2 ) <EOL> coords1 [ <NUM_LIT:2> ] = coords2 [ <NUM_LIT:2> ] = newSlice <EOL> if coords1 [ <NUM_LIT:0> ] == <NUM_LIT:0> and coords1 [ <NUM_LIT:1> ] == <NUM_LIT:0> : <EOL> defaultCoords = self . getDefaultCoords ( volumeId ) <EOL> if structureId == self . AORTA : <EOL> coords1 [ <NUM_LIT:0> ] = defaultCoords [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> coords1 [ <NUM_LIT:1> ] = defaultCoords [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> coords2 [ <NUM_LIT:0> ] = defaultCoords [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> coords2 [ <NUM_LIT:1> ] = defaultCoords [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> elif structureId == self . PA : <EOL> coords1 [ <NUM_LIT:0> ] = defaultCoords [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] <EOL> coords1 [ <NUM_LIT:1> ] = defaultCoords [ <NUM_LIT:2> ] [ <NUM_LIT:1> ] <EOL> coords2 [ <NUM_LIT:0> ] = defaultCoords [ <NUM_LIT:3> ] [ <NUM_LIT:0> ] <EOL> coords2 [ <NUM_LIT:1> ] = defaultCoords [ <NUM_LIT:3> ] [ <NUM_LIT:1> ] <EOL> rulerNode . SetPositionWorldCoordinates1 ( coords1 ) <EOL> rulerNode . SetPositionWorldCoordinates2 ( coords2 ) <EOL> def getDefaultCoords ( self , volumeId ) : <EOL> """<STR_LIT>""" <EOL> volume = slicer . mrmlScene . GetNodeByID ( volumeId ) <EOL> rasBounds = [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> volume . GetRASBounds ( rasBounds ) <EOL> ijk = self . RAStoIJK ( volume , [ <NUM_LIT:0> , <NUM_LIT:0> , rasBounds [ <NUM_LIT:5> ] ] ) <EOL> slice = int ( ijk [ <NUM_LIT:2> ] * self . SLICEFACTOR ) <EOL> aorta1 = list ( self . defaultAorta1 ) <EOL> aorta1 [ <NUM_LIT:2> ] = slice <EOL> aorta1 = self . IJKtoRAS ( volume , aorta1 ) <EOL> aorta2 = list ( self . defaultAorta2 ) <EOL> aorta2 [ <NUM_LIT:2> ] = slice <EOL> aorta2 = self . IJKtoRAS ( volume , aorta2 ) <EOL> pa1 = list ( self . defaultPA1 ) <EOL> pa1 [ <NUM_LIT:2> ] = slice <EOL> pa1 = self . IJKtoRAS ( volume , pa1 ) <EOL> pa2 = list ( self . defaultPA2 ) <EOL> pa2 [ <NUM_LIT:2> ] = slice <EOL> pa2 = self . IJKtoRAS ( volume , pa2 ) <EOL> return aorta1 , aorta2 , pa1 , pa2 <EOL> def removeRulers ( self , volumeId ) : <EOL> """<STR_LIT>""" <EOL> rulersListNode = self . getRulersListNode ( volumeId , createIfNotExist = False ) <EOL> if rulersListNode : <EOL> rulersListNode . RemoveAllChildrenNodes ( ) <EOL> slicer . mrmlScene . RemoveNode ( rulersListNode ) <EOL> def RAStoIJK ( self , volumeNode , rasCoords ) : <EOL> """<STR_LIT>""" <EOL> rastoijk = vtk . vtkMatrix4x4 ( ) <EOL> volumeNode . GetRASToIJKMatrix ( rastoijk ) <EOL> rasCoords . append ( <NUM_LIT:1> ) <EOL> return list ( rastoijk . MultiplyPoint ( rasCoords ) ) <EOL> def IJKtoRAS ( self , volumeNode , ijkCoords ) : <EOL> """<STR_LIT>""" <EOL> ijktoras = vtk . vtkMatrix4x4 ( ) <EOL> volumeNode . GetIJKToRASMatrix ( ijktoras ) <EOL> ijkCoords . append ( <NUM_LIT:1> ) <EOL> return list ( ijktoras . MultiplyPoint ( ijkCoords ) ) <EOL> class CIP_PAARatioTest ( ScriptedLoadableModuleTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> slicer . mrmlScene . Clear ( <NUM_LIT:0> ) <EOL> def runTest ( self ) : <EOL> """<STR_LIT>""" <EOL> self . setUp ( ) <EOL> self . test_CIP_PAARatio_PrintMessage ( ) <EOL> def test_CIP_PAARatio_PrintMessage ( self ) : <EOL> self . delayDisplay ( "<STR_LIT>" ) <EOL> logic = CIP_PAARatioLogic ( ) <EOL> volume = slicer . util . loadVolume ( '<STR_LIT>' , returnNode = True ) <EOL> self . assertTrue ( volume [ <NUM_LIT:0> ] ) <EOL> volumeId = volume [ <NUM_LIT:1> ] . GetID ( ) <EOL> logic . createDefaultRulers ( volumeId ) <EOL> ruler = logic . getRulerNodeForVolumeAndStructure ( volumeId , logic . AORTA , createIfNotExist = False ) <EOL> self . assertFalse ( ruler [ <NUM_LIT:0> ] is None ) <EOL> self . delayDisplay ( '<STR_LIT>' ) </s>
