Wait for cli command MatLabBridge

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Wait for cli command MatLabBridge

lui8errador
Hello all,

I'm trying to run a matlab module (with matlab bridge) in my module Python.
My problem is that I need the output of the matlab module to continue my
process in python. I tried to use the IsBusy() method, also the
getStatusString as it is explained here:
http://slicer-devel.65872.n3.nabble.com/Regarding-batch-processing-of-data-using-python-evalpython-execpython-td2328846.html

My problem is that when I use state.IsBusy() or state.GetStatusString !=
'Completed', 3DSlicer stops and I cannot continue. Does anyone can take a
look on the code? The navigation module is my matlab module that has a
linear transform as output.

    T = slicer.vtkMRMLLinearTransformNode()
    T.SetName('T')
    slicer.mrmlScene.AddNode(T)
    fidNode=slicer.vtkMRMLMarkupsFiducialNode()
    slicer.mrmlScene.AddNode(fidNode)
    displayNode = slicer.vtkMRMLMarkupsDisplayNode()
    slicer.mrmlScene.AddNode(displayNode)
    fidNode.SetAndObserveDisplayNodeID(displayNode.GetID())

    parameters={};
    parameters['transform2']=T
    tool_pos = slicer.modules.*navigation*
    state = slicer.cli.run(tool_pos, None, parameters)

    *while state.IsBusy():* #If I don't make this loop the matrix is not
updated
      print state.GetStatusString()

    fst_coor = T.GetMatrixTransformToParent().GetElement(0,3)     # Is 0
because it is not updated
    snd_coor = T.GetMatrixTransformToParent().GetElement(1,3)   # Is 0
because it is not updated
    trd_coor = T.GetMatrixTransformToParent().GetElement(2,3)     # Is 0
because it is not updated

    fidNode.AddFiducial(fst_coor,snd_coor,trd_coor)



--
View this message in context: http://slicer-devel.65872.n3.nabble.com/Wait-for-cli-command-MatLabBridge-tp4038017.html
Sent from the slicer-devel mailing list archive at Nabble.com.
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Wait for cli command MatLabBridge

Steve Pieper-2

On Tue, Feb 14, 2017 at 9:12 AM, lui8errador <[hidden email]> wrote:
Hello all,

I'm trying to run a matlab module (with matlab bridge) in my module Python.
My problem is that I need the output of the matlab module to continue my
process in python. I tried to use the IsBusy() method, also the
getStatusString as it is explained here:
http://slicer-devel.65872.n3.nabble.com/Regarding-batch-processing-of-data-using-python-evalpython-execpython-td2328846.html

My problem is that when I use state.IsBusy() or state.GetStatusString !=
'Completed', 3DSlicer stops and I cannot continue. Does anyone can take a
look on the code? The navigation module is my matlab module that has a
linear transform as output.

    T = slicer.vtkMRMLLinearTransformNode()
    T.SetName('T')
    slicer.mrmlScene.AddNode(T)
    fidNode=slicer.vtkMRMLMarkupsFiducialNode()
    slicer.mrmlScene.AddNode(fidNode)
    displayNode = slicer.vtkMRMLMarkupsDisplayNode()
    slicer.mrmlScene.AddNode(displayNode)
    fidNode.SetAndObserveDisplayNodeID(displayNode.GetID())

    parameters={};
    parameters['transform2']=T
    tool_pos = slicer.modules.*navigation*
    state = slicer.cli.run(tool_pos, None, parameters)

    *while state.IsBusy():* #If I don't make this loop the matrix is not
updated
      print state.GetStatusString()

    fst_coor = T.GetMatrixTransformToParent().GetElement(0,3)     # Is 0
because it is not updated
    snd_coor = T.GetMatrixTransformToParent().GetElement(1,3)   # Is 0
because it is not updated
    trd_coor = T.GetMatrixTransformToParent().GetElement(2,3)     # Is 0
because it is not updated

    fidNode.AddFiducial(fst_coor,snd_coor,trd_coor)



--
View this message in context: http://slicer-devel.65872.n3.nabble.com/Wait-for-cli-command-MatLabBridge-tp4038017.html
Sent from the slicer-devel mailing list archive at Nabble.com.
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ


_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Wait for cli command MatLabBridge

lasso2
In reply to this post by lui8errador
Would you like to block Slicer until yet get a response?

If yes, then call your Matlab module with wait_for_completion=True
(https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#Running_a_CLI_from_Python)

If you want Slicer to keep running then use wait_for_completion=False and set up a timer to check for completion once in every second or so, using qt.QTimer.

Andras


-----Original Message-----
From: slicer-devel [mailto:[hidden email]] On Behalf Of lui8errador
Sent: February 14, 2017 9:12
To: SPL Slicer Devel <[hidden email]>
Subject: [slicer-devel] Wait for cli command MatLabBridge

Hello all,

I'm trying to run a matlab module (with matlab bridge) in my module Python.
My problem is that I need the output of the matlab module to continue my process in python. I tried to use the IsBusy() method, also the getStatusString as it is explained here:
http://slicer-devel.65872.n3.nabble.com/Regarding-batch-processing-of-data-using-python-evalpython-execpython-td2328846.html

My problem is that when I use state.IsBusy() or state.GetStatusString != 'Completed', 3DSlicer stops and I cannot continue. Does anyone can take a look on the code? The navigation module is my matlab module that has a linear transform as output.

    T = slicer.vtkMRMLLinearTransformNode()
    T.SetName('T')
    slicer.mrmlScene.AddNode(T)
    fidNode=slicer.vtkMRMLMarkupsFiducialNode()
    slicer.mrmlScene.AddNode(fidNode)
    displayNode = slicer.vtkMRMLMarkupsDisplayNode()
    slicer.mrmlScene.AddNode(displayNode)
    fidNode.SetAndObserveDisplayNodeID(displayNode.GetID())

    parameters={};
    parameters['transform2']=T
    tool_pos = slicer.modules.*navigation*
    state = slicer.cli.run(tool_pos, None, parameters)

    *while state.IsBusy():* #If I don't make this loop the matrix is not updated
      print state.GetStatusString()

    fst_coor = T.GetMatrixTransformToParent().GetElement(0,3)     # Is 0
because it is not updated
    snd_coor = T.GetMatrixTransformToParent().GetElement(1,3)   # Is 0
because it is not updated
    trd_coor = T.GetMatrixTransformToParent().GetElement(2,3)     # Is 0
because it is not updated

    fidNode.AddFiducial(fst_coor,snd_coor,trd_coor)



--
View this message in context: http://slicer-devel.65872.n3.nabble.com/Wait-for-cli-command-MatLabBridge-tp4038017.html
Sent from the slicer-devel mailing list archive at Nabble.com.
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ