def storeSceneView(self,name,description=""):
    """  Store a scene view into the current scene.
    TODO: this might move to slicer.util
    """
    layoutManager = slicer.app.layoutManager()

    sceneViewNode = slicer.vtkMRMLSceneViewNode()
    view1 = layoutManager.threeDWidget(0).threeDView()

    w2i1 = vtk.vtkWindowToImageFilter()
    w2i1.SetInput(view1.renderWindow())

    w2i1.Update()
    image1 = w2i1.GetOutput()
    sceneViewNode.SetScreenShot(image1)
    sceneViewNode.UpdateStoredScene()
    slicer.mrmlScene.AddNode(sceneViewNode)

    sceneViewNode.SetName(name)
    sceneViewNode.SetSceneViewDescription(description)
    sceneViewNode.StoreScene()

    return sceneViewNode
Пример #2
0
    def storeSceneView(self, name, description=""):
        """  Store a scene view into the current scene.
    TODO: this might move to slicer.util
    """
        layoutManager = slicer.app.layoutManager()

        sceneViewNode = slicer.vtkMRMLSceneViewNode()
        view1 = layoutManager.threeDWidget(0).threeDView()

        w2i1 = vtk.vtkWindowToImageFilter()
        w2i1.SetInput(view1.renderWindow())

        w2i1.Update()
        image1 = w2i1.GetOutput()
        sceneViewNode.SetScreenShot(image1)
        sceneViewNode.UpdateStoredScene()
        slicer.mrmlScene.AddNode(sceneViewNode)

        sceneViewNode.SetName(name)
        sceneViewNode.SetSceneViewDescription(description)
        sceneViewNode.StoreScene()

        return sceneViewNode
  def test_AddStorableDataAfterSceneViewTest1(self):

    slicer.util.delayDisplay("Starting the test")

    #
    # add a fiducial
    #
    slicer.modules.markups.logic().AddFiducial()

    #
    # save a scene view
    #
    sv = slicer.mrmlScene.AddNode(slicer.vtkMRMLSceneViewNode())
    sv.StoreScene()

    #
    # add another storable node, a volume
    #
    slicer.util.delayDisplay("Adding a new storable node, after creating a scene view")
    import SampleData
    sampleDataLogic = SampleData.SampleDataLogic()
    mrHeadVolume = sampleDataLogic.downloadMRHead()
    mrHeadID = mrHeadVolume.GetID()

    #
    # restore the scene view
    #
    slicer.util.delayDisplay("Restoring the scene view")
    sv.RestoreScene()

    #
    # Is the new storable data still present?
    #
    restoredData = slicer.mrmlScene.GetNodeByID(mrHeadID)

    # for now, the non scene view storable data is removed
    self.assertIsNone( restoredData )
    slicer.util.delayDisplay('Success: extra storable node removed with scene view restore')


    #
    # add new storable again
    mrHeadVolume = sampleDataLogic.downloadMRHead()
    mrHeadID = mrHeadVolume.GetID()

    #
    # restore the scene view, but error on removing nodes
    #
    slicer.util.delayDisplay("Restoring the scene view with check for removed nodes")
    sv.RestoreScene(0)

    #
    # Is the new storable data still present?
    #
    restoredData = slicer.mrmlScene.GetNodeByID(mrHeadID)

    # in this case the non scene view storable data is kept' scene is not changed
    self.assertIsNotNone( restoredData )
    slicer.util.delayDisplay('Success: extra storable node NOT removed with scene view restore')

    print 'Scene error code = ' + str(slicer.mrmlScene.GetErrorCode())
    print '\t' + slicer.mrmlScene.GetErrorMessage()

    slicer.util.delayDisplay('Test passed!')
Пример #4
0
    def test_AddStorableDataAfterSceneViewTest1(self):

        slicer.util.delayDisplay("Starting the test")

        #
        # add a fiducial
        #
        slicer.modules.markups.logic().AddFiducial()

        #
        # save a scene view
        #
        sv = slicer.mrmlScene.AddNode(slicer.vtkMRMLSceneViewNode())
        sv.StoreScene()

        #
        # add another storable node, a volume
        #
        slicer.util.delayDisplay(
            "Adding a new storable node, after creating a scene view")
        import SampleData
        mrHeadVolume = SampleData.downloadSample("MRHead")
        mrHeadID = mrHeadVolume.GetID()

        #
        # restore the scene view
        #
        slicer.util.delayDisplay("Restoring the scene view")
        sv.RestoreScene()

        #
        # Is the new storable data still present?
        #
        restoredData = slicer.mrmlScene.GetNodeByID(mrHeadID)

        # for now, the non scene view storable data is removed
        self.assertIsNone(restoredData)
        slicer.util.delayDisplay(
            'Success: extra storable node removed with scene view restore')

        #
        # add new storable again
        mrHeadVolume = SampleData.downloadSample("MRHead")
        mrHeadID = mrHeadVolume.GetID()

        #
        # restore the scene view, but error on removing nodes
        #
        slicer.util.delayDisplay(
            "Restoring the scene view with check for removed nodes")
        sv.RestoreScene(0)

        #
        # Is the new storable data still present?
        #
        restoredData = slicer.mrmlScene.GetNodeByID(mrHeadID)

        # in this case the non scene view storable data is kept' scene is not changed
        self.assertIsNotNone(restoredData)
        slicer.util.delayDisplay(
            'Success: extra storable node NOT removed with scene view restore')

        print('Scene error code = ' + str(slicer.mrmlScene.GetErrorCode()))
        print('\t' + slicer.mrmlScene.GetErrorMessage())

        slicer.util.delayDisplay('Test passed!')
import slicer

fid = slicer.vtkMRMLAnnotationFiducialNode()
fid.SetScene(slicer.mrmlScene)
fid.CreateAnnotationTextDisplayNode()
fid.CreateAnnotationPointDisplayNode()

startCoords = [1.0, 2.0, 3.0]
fid.AddControlPoint(startCoords, 0, 1)

slicer.mrmlScene.AddNode(fid)
fid.GetFiducialCoordinates(startCoords)
print("Starting fiducial coordinates = ", startCoords)

sv = slicer.mrmlScene.AddNode(slicer.vtkMRMLSceneViewNode())

sv.StoreScene()

fid.SetFiducialCoordinates(11.1, 22.2, 33.3)
afterStoreSceneCoords = [0, 0, 0]
fid.GetFiducialCoordinates(afterStoreSceneCoords)
print("After storing the scene, set fiducial coords to ",
      afterStoreSceneCoords)

sv.RestoreScene()

fidAfterRestore = slicer.mrmlScene.GetNodeByID(
    "vtkMRMLAnnotationFiducialNode1")

coords = [0, 0, 0]