def setup(self): ScriptedLoadableModuleWidget.setup(self) self.logic = CNN_Image_ClassifierLogic() self.moduleDir = os.path.dirname( slicer.modules.collect_training_images.path) # Instantiate and connect widgets ... # # Parameters Area # parametersCollapsibleButton = ctk.ctkCollapsibleButton() parametersCollapsibleButton.text = "Parameters" self.layout.addWidget(parametersCollapsibleButton) # Layout within the dummy collapsible button parametersFormLayout = qt.QFormLayout(parametersCollapsibleButton) self.modelSelector = qt.QComboBox() self.modelSelector.addItems(["Select model"]) modelDirectoryContents = os.listdir( os.path.join(self.moduleDir, os.pardir, "Models")) modelNames = [ dir for dir in modelDirectoryContents if dir.find(".") == -1 and dir != "Dockerfile" ] self.modelSelector.addItems(["Create new model"]) self.modelSelector.addItems(modelNames) parametersFormLayout.addRow(self.modelSelector) # # Apply Button # self.applyButton = qt.QPushButton("Start") self.applyButton.toolTip = "Run the algorithm." self.applyButton.enabled = False parametersFormLayout.addRow(self.applyButton) ''' self.classifyAllFramesButton = qt.QPushButton("Classify all frames") self.classifyAllFramesButton.toolTip = "classify all frames in a sequence" parametersFormLayout.addRow(self.classifyAllFramesButton) ''' # # Object table # self.objectTable = qt.QTableWidget() self.objectTable.setColumnCount(3) self.objectTable.setHorizontalHeaderLabels( ["Name", "Found", "Confidence"]) parametersFormLayout.addRow(self.objectTable) # # Adjust Confidence Thresholds # confidenceThresholdsCollapsibleButton = ctk.ctkCollapsibleButton() confidenceThresholdsCollapsibleButton.text = "Confidence Thresholds" self.layout.addWidget(confidenceThresholdsCollapsibleButton) confidenceFormLayout = qt.QFormLayout( confidenceThresholdsCollapsibleButton) self.confidenceSlider = qt.QSlider(0x1) #horizontal slider self.confidenceSlider.setRange(0, 100) self.confidenceSlider.setTickInterval(5) self.confidenceSlider.setTickPosition(2) #Ticks appear below slider self.confidenceSlider.setSliderPosition(80) self.confidenceSlider.setToolTip( "Set the minimum degree of confidence that must be met for an object to be considered found" ) confidenceFormLayout.addRow("Confidence: ", self.confidenceSlider) self.confidenceLabel = qt.QLabel("80%") confidenceFormLayout.addRow(self.confidenceLabel) self.recordingPlayWidget = slicer.qMRMLSequenceBrowserPlayWidget() parametersFormLayout.addRow(self.recordingPlayWidget) self.recordingSeekWidget = slicer.qMRMLSequenceBrowserSeekWidget() parametersFormLayout.addRow(self.recordingSeekWidget) # connections self.applyButton.connect('clicked(bool)', self.onApplyButton) #self.classifyAllFramesButton.connect('clicked(bool)', self.onClassifyAllFramesClicked) self.modelSelector.connect('currentIndexChanged(int)', self.onModelSelected) self.confidenceSlider.connect('sliderMoved(int)', self.onConfidenceChanged) # Add vertical spacer self.layout.addStretch(1) # Refresh Apply button state self.onSelect() try: self.webcamReference = slicer.util.getNode('Webcam_Reference') except slicer.util.MRMLNodeNotFoundException: #if not self.webcamReference: imageSpacing = [0.2, 0.2, 0.2] imageData = vtk.vtkImageData() imageData.SetDimensions(640, 480, 1) imageData.AllocateScalars(vtk.VTK_UNSIGNED_CHAR, 1) thresholder = vtk.vtkImageThreshold() thresholder.SetInputData(imageData) thresholder.SetInValue(0) thresholder.SetOutValue(0) # Create volume node self.webcamReference = slicer.vtkMRMLVectorVolumeNode() self.webcamReference.SetName('Webcam_Reference') self.webcamReference.SetSpacing(imageSpacing) self.webcamReference.SetImageDataConnection( thresholder.GetOutputPort()) # Add volume to scene slicer.mrmlScene.AddNode(self.webcamReference) displayNode = slicer.vtkMRMLVectorVolumeDisplayNode() slicer.mrmlScene.AddNode(displayNode) self.webcamReference.SetAndObserveDisplayNodeID( displayNode.GetID()) self.webcamConnectorNode = self.createWebcamPlusConnector() self.webcamConnectorNode.Start() self.setupWebcamResliceDriver()
def setup(self): ScriptedLoadableModuleWidget.setup(self) # tracks the modified event observer on the currently # selected sequence browser node self.sequenceBrowserObserverRecord = None self.animatorActionsGUI = None self.logic = AnimatorLogic() # Instantiate and connect widgets ... # # Parameters Area # parametersCollapsibleButton = ctk.ctkCollapsibleButton() parametersCollapsibleButton.text = "Animation Parameters" self.layout.addWidget(parametersCollapsibleButton) # Layout within the dummy collapsible button parametersFormLayout = qt.QFormLayout(parametersCollapsibleButton) self.durationBox = ctk.ctkDoubleSpinBox() self.durationBox.suffix = " seconds" self.durationBox.decimals = 1 self.durationBox.minimum = 1 self.durationBox.value = 5 self.durationBox.toolTip = "Duration cannot be changed after animation created" parametersFormLayout.addRow("New animation duration", self.durationBox) # # animation selector # self.animationSelector = slicer.qMRMLNodeComboBox() self.animationSelector.nodeTypes = ["vtkMRMLScriptedModuleNode"] self.animationSelector.setNodeTypeLabel("Animation", "vtkMRMLScriptedModuleNode") self.animationSelector.selectNodeUponCreation = True self.animationSelector.addEnabled = True self.animationSelector.addAttribute("vtkMRMLScriptedModuleNode", "ModuleName", "Animation") self.animationSelector.baseName = "Animation" self.animationSelector.removeEnabled = True self.animationSelector.noneEnabled = True self.animationSelector.showHidden = True self.animationSelector.showChildNodeTypes = False self.animationSelector.setMRMLScene( slicer.mrmlScene ) self.animationSelector.setToolTip( "Pick the animation description." ) parametersFormLayout.addRow("Animation Node: ", self.animationSelector) self.sequencePlay = slicer.qMRMLSequenceBrowserPlayWidget() self.sequencePlay.setMRMLScene(slicer.mrmlScene) self.sequenceSeek = slicer.qMRMLSequenceBrowserSeekWidget() self.sequenceSeek.setMRMLScene(slicer.mrmlScene) parametersFormLayout.addRow(self.sequencePlay) parametersFormLayout.addRow(self.sequenceSeek) self.actionsMenuButton = qt.QPushButton("Add Action") self.actionsMenuButton.enabled = False self.actionsMenu = qt.QMenu() self.actionsMenuButton.setMenu(self.actionsMenu) for actionName in slicer.modules.animatorActionPlugins.keys(): qAction = qt.QAction(actionName, self.actionsMenu) qAction.connect('triggered()', lambda actionName=actionName: self.onAddAction(actionName)) self.actionsMenu.addAction(qAction) parametersFormLayout.addWidget(self.actionsMenuButton) # # Actions Area # self.actionsCollapsibleButton = ctk.ctkCollapsibleButton() self.actionsCollapsibleButton.text = "Actions" self.layout.addWidget(self.actionsCollapsibleButton) # Layout within the dummy collapsible button self.actionsFormLayout = qt.QFormLayout(self.actionsCollapsibleButton) # # Export Area # self.exportCollapsibleButton = ctk.ctkCollapsibleButton() self.exportCollapsibleButton.text = "Export" self.layout.addWidget(self.exportCollapsibleButton) self.exportCollapsibleButton.enabled = False self.exportFormLayout = qt.QFormLayout(self.exportCollapsibleButton) self.sizeSelector = qt.QComboBox() for size in self.sizes.keys(): self.sizeSelector.addItem(size) self.sizeSelector.currentText = self.defaultSize self.exportFormLayout.addRow("Animation size", self.sizeSelector) self.fileFormatSelector = qt.QComboBox() for format in self.fileFormats.keys(): self.fileFormatSelector.addItem(format) self.fileFormatSelector.currentText = self.defaultFileFormat self.exportFormLayout.addRow("Animation format", self.fileFormatSelector) self.outputFileButton = qt.QPushButton("Select a file...") self.exportFormLayout.addRow("Output file", self.outputFileButton) self.exportButton = qt.QPushButton("Export") self.exportButton.enabled = False self.exportFormLayout.addRow("", self.exportButton) # connections self.animationSelector.connect("currentNodeChanged(vtkMRMLNode*)", self.onSelect) self.outputFileButton.connect("clicked()", self.selectExportFile) self.exportButton.connect("clicked()", self.onExport) # Add vertical spacer self.layout.addStretch(1)
def setup(self): ScriptedLoadableModuleWidget.setup(self) # Instantiate and connect widgets ... self.pbucLogic = PointerBasedUSCalibrationLogic() # Have reference to an instance of the logic # # Tracked ultrasound playback toolbox # self.playToolBox = qt.QToolBox() self.layout.addWidget( self.playToolBox ) # # Real-time playback # self.realTimeFrame = qt.QFrame( self.playToolBox ) self.realTimeLayout = qt.QVBoxLayout( self.realTimeFrame ) self.connectorNodeSelector = slicer.qMRMLNodeComboBox() self.connectorNodeSelector.nodeTypes = [ "vtkMRMLIGTLConnectorNode" ] self.connectorNodeSelector.addEnabled = False self.connectorNodeSelector.removeEnabled = False self.connectorNodeSelector.noneEnabled = False self.connectorNodeSelector.showHidden = False self.connectorNodeSelector.showChildNodeTypes = False self.connectorNodeSelector.setMRMLScene( slicer.mrmlScene ) self.connectorNodeSelector.setToolTip( "Select the connector node for playback." ) self.realTimeLayout.addWidget( self.connectorNodeSelector ) self.freezeButton = qt.QPushButton( "Freeze" ) self.freezeButton.setToolTip( "Freeze the connection." ) self.realTimeLayout.addWidget( self.freezeButton ) # # Recorded sequence playback # self.sequenceFrame = qt.QFrame( self.playToolBox ) self.sequenceLayout = qt.QVBoxLayout( self.sequenceFrame ) self.sequenceBrowserNodeSelector = slicer.qMRMLNodeComboBox() self.sequenceBrowserNodeSelector.nodeTypes = [ "vtkMRMLSequenceBrowserNode" ] self.sequenceBrowserNodeSelector.addEnabled = False self.sequenceBrowserNodeSelector.removeEnabled = False self.sequenceBrowserNodeSelector.noneEnabled = False self.sequenceBrowserNodeSelector.showHidden = False self.sequenceBrowserNodeSelector.showChildNodeTypes = False self.sequenceBrowserNodeSelector.setMRMLScene( slicer.mrmlScene ) self.sequenceBrowserNodeSelector.setToolTip( "Select the sequence browser node for playback." ) self.sequenceLayout.addWidget( self.sequenceBrowserNodeSelector ) self.sequenceBrowserPlayWidget = slicer.qMRMLSequenceBrowserPlayWidget() # TODO: Somehow disable the recording button without changing sequences' recording states self.sequenceBrowserPlayWidget.setMRMLSequenceBrowserNode( self.sequenceBrowserNodeSelector.currentNode() ) self.sequenceLayout.addWidget( self.sequenceBrowserPlayWidget ) self.sequenceBrowserSeekWidget = slicer.qMRMLSequenceBrowserSeekWidget() self.sequenceBrowserSeekWidget.setMRMLSequenceBrowserNode( self.sequenceBrowserNodeSelector.currentNode() ) self.sequenceLayout.addWidget( self.sequenceBrowserSeekWidget ) # Add the playback modes to the tool box self.playToolBox.addItem( self.realTimeFrame, "Real-time" ) self.playToolBox.addItem( self.sequenceFrame, "Sequence" ) # # Points group box # self.pointGroupBox = qt.QGroupBox() self.pointGroupBox.setTitle( "Points" ) self.layout.addWidget( self.pointGroupBox ) # Layout within the group box self.pointGroupBoxLayout = qt.QHBoxLayout( self.pointGroupBox ) # Mark point self.markPointButton = qt.QPushButton( "Mark Point" ) self.markPointButton.setIcon( qt.QIcon( ":/Icons/MarkupsMouseModePlace.png" ) ) self.markPointButton.setToolTip( "Start placing a point on the ultrasound image." ) self.pointGroupBoxLayout.addWidget( self.markPointButton ) # Undo self.undoPointsButton = qt.QPushButton( "" ) self.undoPointsButton.setIcon( qt.QIcon( ":/Icons/Small/SlicerUndo.png" ) ) self.undoPointsButton.setSizePolicy( qt.QSizePolicy.Fixed, qt.QSizePolicy.Fixed ) self.undoPointsButton.setToolTip( "Remove the most recently placed point." ) self.pointGroupBoxLayout.addWidget( self.undoPointsButton ) # Reset self.resetPointsButton = qt.QPushButton( "" ) self.resetPointsButton.setIcon( qt.QApplication.style().standardIcon( qt.QStyle.SP_DialogResetButton ) ) self.resetPointsButton.setSizePolicy( qt.QSizePolicy.Fixed, qt.QSizePolicy.Fixed ) self.resetPointsButton.setToolTip( "Clear all points." ) self.pointGroupBoxLayout.addWidget( self.resetPointsButton ) # # Result label # self.calibrationResultLabel = qt.QLabel() self.calibrationResultLabel.setText( "No calibration parameters selected." ) self.calibrationResultLabel.setToolTip( "Output from the calibration." ) self.layout.addWidget( self.calibrationResultLabel ) # # Advanced area # self.advancedCollapsibleButton = ctk.ctkCollapsibleButton() self.advancedCollapsibleButton.setText( "Advanced" ) self.advancedCollapsibleButton.collapsed = True self.layout.addWidget( self.advancedCollapsibleButton ) # Layout within the collapsible button self.advancedLayout = qt.QFormLayout( self.advancedCollapsibleButton ) # Mark point self.applyButton = qt.QPushButton( "Apply" ) self.applyButton.setToolTip( "Apply the ImageToProbe transform to the ultrasound image." ) self.advancedLayout.addWidget( self.applyButton ) # # Results area # self.resultsCollapsibleButton = ctk.ctkCollapsibleButton() self.resultsCollapsibleButton.setText( "Results" ) self.resultsCollapsibleButton.collapsed = True self.advancedLayout.addWidget( self.resultsCollapsibleButton ) # Layout within the collapsible button self.resultsLayout = qt.QFormLayout( self.resultsCollapsibleButton ) # Results table self.resultsTable = qt.QTableWidget( self.resultsCollapsibleButton ) self.resultsTable.setColumnCount( self.RESULTS_NUM_INDICES ) self.resultsTable.setHorizontalHeaderLabels( [ "Image Points", "Probe Points", "Error", "Delete" ] ) self.resultsTable.horizontalHeader().setResizeMode( qt.QHeaderView.Stretch ) self.resultsTable.horizontalHeader().setResizeMode( self.RESULTS_DELETE_INDEX, qt.QHeaderView.Fixed ) self.resultsLayout.addRow( self.resultsTable ) # # Parameters area # self.parametersCollapsibleButton = ctk.ctkCollapsibleButton() self.parametersCollapsibleButton.setText( "Parameters" ) self.parametersCollapsibleButton.collapsed = True self.advancedLayout.addWidget( self.parametersCollapsibleButton ) # Layout within the collapsible button self.parametersLayout = qt.QVBoxLayout( self.parametersCollapsibleButton ) # Parameters node self.frwNodeSelector = slicer.qMRMLNodeComboBox() self.frwNodeSelector.nodeTypes = [ "vtkMRMLFiducialRegistrationWizardNode" ] self.frwNodeSelector.addEnabled = True self.frwNodeSelector.removeEnabled = True self.frwNodeSelector.noneEnabled = False self.frwNodeSelector.showHidden = False self.frwNodeSelector.showChildNodeTypes = False self.frwNodeSelector.baseName = "UltrasoundCalibration" self.frwNodeSelector.setMRMLScene( slicer.mrmlScene ) self.frwNodeSelector.setToolTip( "Select the ultrasound calibration parameters node." ) self.parametersLayout.addWidget( self.frwNodeSelector ) # # Input group box # self.inputGroupBox = qt.QGroupBox( self.parametersCollapsibleButton ) self.inputGroupBox.setTitle( "Input" ) self.parametersLayout.addWidget( self.inputGroupBox ) # Layout within the group box self.inputGroupBoxLayout = qt.QFormLayout( self.inputGroupBox ) # US image selector self.usImageNodeSelector = slicer.qMRMLNodeComboBox() self.usImageNodeSelector.nodeTypes = [ "vtkMRMLVolumeNode" ] self.usImageNodeSelector.addEnabled = False self.usImageNodeSelector.removeEnabled = False self.usImageNodeSelector.noneEnabled = True self.usImageNodeSelector.showHidden = False self.usImageNodeSelector.showChildNodeTypes = True self.usImageNodeSelector.setMRMLScene( slicer.mrmlScene ) self.usImageNodeSelector.setToolTip( "Select the ultrasound image node." ) self.inputGroupBoxLayout.addRow( "Ultrasound image ", self.usImageNodeSelector ) # StylusTipToProbe selector self.stylusTipToProbeNodeSelector = slicer.qMRMLNodeComboBox() self.stylusTipToProbeNodeSelector.nodeTypes = [ "vtkMRMLLinearTransformNode" ] self.stylusTipToProbeNodeSelector.addEnabled = False self.stylusTipToProbeNodeSelector.removeEnabled = False self.stylusTipToProbeNodeSelector.noneEnabled = True self.stylusTipToProbeNodeSelector.showHidden = False self.stylusTipToProbeNodeSelector.showChildNodeTypes = True self.stylusTipToProbeNodeSelector.setMRMLScene( slicer.mrmlScene ) self.stylusTipToProbeNodeSelector.setToolTip( "Select the StylusTipToProbe node (parent transforms will be applied)." ) self.inputGroupBoxLayout.addRow( "StylusTipToProbe ", self.stylusTipToProbeNodeSelector ) # # Output group box # self.outputGroupBox = qt.QGroupBox( self.parametersCollapsibleButton ) self.outputGroupBox.setTitle( "Output" ) self.parametersLayout.addWidget( self.outputGroupBox ) # Layout within the group box self.outputGroupBoxLayout = qt.QFormLayout( self.outputGroupBox ) # ImageToProbe selector self.imageToProbeNodeSelector = slicer.qMRMLNodeComboBox() self.imageToProbeNodeSelector.nodeTypes = [ "vtkMRMLLinearTransformNode" ] self.imageToProbeNodeSelector.addEnabled = True self.imageToProbeNodeSelector.removeEnabled = False self.imageToProbeNodeSelector.noneEnabled = True self.imageToProbeNodeSelector.renameEnabled = True self.imageToProbeNodeSelector.showHidden = False self.imageToProbeNodeSelector.showChildNodeTypes = True self.imageToProbeNodeSelector.setMRMLScene( slicer.mrmlScene ) self.imageToProbeNodeSelector.setToolTip( "Select the ImageToProbe output node (stores the result of the calibration)." ) self.outputGroupBoxLayout.addRow( "ImageToProbe ", self.imageToProbeNodeSelector ) # # Set up connections # self.freezeButton.connect( "clicked(bool)", self.onFreezeButtonClicked ) self.sequenceBrowserNodeSelector.connect( "currentNodeChanged(vtkMRMLNode*)", self.onSequenceBrowserNodeChanged ) self.frwNodeSelector.connect( "currentNodeChanged(vtkMRMLNode*)", self.onCalibrationNodeChanged ) self.usImageNodeSelector.connect( "currentNodeChanged(vtkMRMLNode*)", self.onUSImageNodeChanged ) self.stylusTipToProbeNodeSelector.connect( "currentNodeChanged(vtkMRMLNode*)", self.onStylusTipToProbeNodeChanged ) self.markPointButton.connect( "clicked(bool)", self.onMarkPointButtonClicked ) self.undoPointsButton.connect( "clicked(bool)", self.onUndoPointsButtonClicked ) self.resetPointsButton.connect( "clicked(bool)", self.onResetPointsButtonClicked ) self.imageToProbeNodeSelector.connect( "currentNodeChanged(vtkMRMLNode*)", self.onImageToProbeNodeChanged ) self.applyButton.connect( "clicked(bool)", self.onApplyOutputTransformToImageClicked ) # # Create a parameters node by default # defaultFRWNode = slicer.vtkMRMLFiducialRegistrationWizardNode() defaultFRWNode.SetName( "UltrasoundCalibration" ) defaultFRWNode.SetScene( slicer.mrmlScene ) slicer.mrmlScene.AddNode( defaultFRWNode ) self.frwNodeSelector.setCurrentNodeID( defaultFRWNode.GetID() ) # Add vertical spacer self.layout.addStretch(1)