VolViewer Scripting in more detail: Difference between revisions

From BanghamLab
Jump to navigation Jump to search
No edit summary
No edit summary
 
(21 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[VolViewer#User Documentation|Back to VolViewer overview]]<br>
[[VolViewer#User Documentation|Back to VolViewer overview]]<br>
=VolViewer scripting and accessing VolViewer from Matlab=
===See also===
==VolViewer scripting==
[http://rico-coen.jic.ac.uk/LabGuide/index.php?title=MSR3_File_Specification MSR file specification] MSR file specification (MSR stands for ''Measure''.)  MSR files describe 3D objects and are used to pass data between the 3D BanghamLab toolboxes: VolViewer, GFtbox and AAMToolbox.<br>
A script is a limited form of program - a list of commands. In this case the commands ([http://dmbi.nbi.bbsrc.ac.uk/Index.php/VolViewerScriptsAPI see VolViewerScriptsAPI]) cover most of the operations that you would usually do interactively. On Windows, VolViewer is an exe file. It can either be launched by clicking its icon or from the command prompt using the command<br>
[http://dmbi.nbi.bbsrc.ac.uk/index.php/VolViewerScriptsAPI VolViewerScriptsAPI] The VolViewerScriptsAPI enables external applications, such as the AAMToolbox, to exploit VolViewer.
*[http://dmbi.nbi.bbsrc.ac.uk/index.php/VolViewerScriptsAPI#set_watchfile List of VolViewer commands]
*[[VolViewer commands by function|Table of VolViewer commands by function]]
*[[VolViewer msr file specification|VolViewer saves spatial data in msr files]]
 
=<span style="color: Navy">VolViewer scripting and accessing VolViewer from Matlab</span>=
==<span style="color: Navy">VolViewer scripting</span>==
A script is a limited form of program - a list of commands. In this case the commands (http://dmbi.nbi.bbsrc.ac.uk/index.php/VolViewerScriptsAPI see VolViewerScriptsAPI]) cover most of the operations that you would usually do interactively. On Windows, VolViewer is an exe file that can ''either'' be<br>
'''interactive''', i.e. launched by clicking its icon or from the command prompt using the command<br>
  VolViewer.exe
  VolViewer.exe
Normally VolViewer runs interactively this is how you would discover how best to filter and view an image stack. That done it is tedious to then repeat the operations on all stacks in a sequence. The alternative is to list the operations (commands) in a script file and tell VolViewer to follow the commands. To do this one launches VolViewer giving the name of a text file that contains the script. For example, if the script is contained in a file called '' 'myscript.txt' '' in the same path (directory) as VolViewer itself then VolViewer should be launched using the command<br>
''or'' '''scripted'''. In which case the operations (commands) are stored in a script file. In which case VolViewer is launched with<br>
VolViewer.exe open_script('myscript.txt')
VolViewer set_watchfile('file.txt')
VolViewer will open, execute the operations in '' 'myscript.txt' '' and close again with no further actions by the user (you).
where ''file.txt'' contains the commands. For example, if VolViewer is to be a viewing tool for an external program, e.g. a Matlab program, then the file.txt could contain<br>
The following is an example of  '' 'myscript.txt' ''. It opens an image called '' 'Anti_Flower 294 (gfp1+txr+vis)' '' in a directory called '' 'E:\VOLUME DATA''', filters it, save a projection and saves the processed stack. <br>
open_image_stack(0, 'E:\VOLUME DATA\ScanID1934_Leaf1\')
'' 'myscript.txt' '' contains
where ''ScanID1934_Leaf1'' is a directory containing a stack of images. VolViewer will automatically load and display these images as soon as it finds that the watchfile has been updated.<br><br>
  open_image_stack(0, 'E:\VOLUME DATA\Anti_Flower 294 (gfp1+txr+vis)\')
 
  compute_GPUfilter_AnisotropicDiffusion(0, 5.0, 0.1, 10)
[http://dmbi.nbi.bbsrc.ac.uk/index.php/VolViewerScriptsAPI#Examples Other examples]<br><br>
  save_projection('E:\VOLUME DATA\Projections\Anti_Flower 294 (gfp1+txr+vis).png')
 
  save_image_stack('E:\VOLUME DATA\Anti_Flower 294 (gfp1+txr+vis)\Filtered\')
It is '''not practical to script''' VolViewer using these commands manually. It is better to''' use VolViewer as a tool''' that is controlled through a library of commands in, for example, Matlab. Or, when running VolViewer on the server side of a server/client session where the user is interacting with VolViewer through a client web page.
==Matlab to Volviewer==
==<span style="color: Navy">Matlab to Volviewer</span>==
The DArT_Toolbox contains a [[VolViewer access from Matlab| library of functions]] for using and controlling VolViewer from Matlab.
===Accessing VolViewer from Matlab===
 
{| border="0" cellpadding="5" cellspacing="3"
|- valign="top"
|width="300pt"|There is a VolViewer Matlab class library: launching and controlling Volviewer for the display of 3D volume images (the display window has zoom, rotate, etc.). On computers with an appropriate graphics card and stereo display VolViewer can be used to display volume images and graphics objects from msr files.
|width="300pt"|[[Image:VolViewer_Monitor_Illustration.jpg|400px|right|VolViewer as a viewport for Matlab]]<br>VolViewer viewport without its usual menu-bars and under control of a Matlab program. It shows endogenous fluorescence signal from a young leaf that has been annotated with a series of points set on the mid point of trichomes and joined by lines. These points characterise the 3D shape of the leaf and are stored in an MSR text file.<br>To manipulate the view: left-click-drag '''rotate''', middle-click-drag '''translate''', right-click-drag '''zoom.''' <br><br>
This image was created using steps 2, 3, and 4 below.
|}
1) '''Install''' VolViewer
*For example, in 'C:\VolViewer_x64'. This is the '''PathToVolViewer'''.
2) '''Launch VolViewer''' from Matlab
*Temporary data files on paths are saved in '...\DArT_Toolshed\ToolBag\VolViewerAPI\CLASSFILES'<br>
This should mean that once VolViewer is installed on a computer - the system will remember where to find everything without having to respecify paths.<br>
  VO=VolViewer(1,'D:\VolViewer_x64','D:\VolViewer_x64')
creates a VolViewer object - which, because there is no semicolon at the end, is displayed as:
          PathToVolViewer: D:\VolViewer_x64
          PathToWatchFile: D:\VolViewer_x64
          WatchFileNumber:    1.00000
                      PathTo:
          imageFilenames:
              msrFilename:
              tfnFilename:
              slcFilename:
              vvrFilename:
              objFilename:
                Commands:
Notice that the paths have been filled in and that this is the first copy of VolViewer (WatchFileNumber is 1).<br>
3) '''Display an image''' stack in VolViewer
*The key step is to notify VolViewer where to find the images by putting a command into WatchFile1.txt. This is done automatically with the following
  VO=imshowVOL(VO, 'PathTo','D:\Shape_T1_only\Image_data\11to14DFS\1554')
In this case the image stack is in the directory 'D:\Shape_T1_only\Image_data\11to14DFS\1554'. Notice, that VOL has been updated
  >> VOL
          PathToVolViewer: D:\VolViewer_x64
          PathToWatchFile: D:\VolViewer_x64
          WatchFileNumber:    1.00000
          PathTo: D:\Shape_T1_only\Image_data\11to14DFS\1554
          imageFilenames:
              msrFilename:
              tfnFilename:
              slcFilename:
              vvrFilename:
              objFilename:
                Commands:
4) '''Display an MSR''' (results: points/lines/planes) file
*Put the command into WatchFile1.txt using
  VO=imshowVOL(VO,'PathTo','D:\Shape_T1_only\Image_data\11to14DFS\1554','msrFilename','1554_T1_Shape.msr')
To hide the image
  VO=commandsVOL(VO,'set_channels(0,0,0)');
To see the image again
  VO=commandsVOL(VO,'set_channels(1,1,1)');
To clear the MSR points/lines/planes
  VO=commandsVOL(VO,'set_clear_all_MSR()')

Latest revision as of 13:19, 11 April 2012

Back to VolViewer overview

See also

MSR file specification MSR file specification (MSR stands for Measure.) MSR files describe 3D objects and are used to pass data between the 3D BanghamLab toolboxes: VolViewer, GFtbox and AAMToolbox.
VolViewerScriptsAPI The VolViewerScriptsAPI enables external applications, such as the AAMToolbox, to exploit VolViewer.

VolViewer scripting and accessing VolViewer from Matlab

VolViewer scripting

A script is a limited form of program - a list of commands. In this case the commands (http://dmbi.nbi.bbsrc.ac.uk/index.php/VolViewerScriptsAPI see VolViewerScriptsAPI]) cover most of the operations that you would usually do interactively. On Windows, VolViewer is an exe file that can either be
interactive, i.e. launched by clicking its icon or from the command prompt using the command

VolViewer.exe

or scripted. In which case the operations (commands) are stored in a script file. In which case VolViewer is launched with

VolViewer set_watchfile('file.txt')

where file.txt contains the commands. For example, if VolViewer is to be a viewing tool for an external program, e.g. a Matlab program, then the file.txt could contain

open_image_stack(0, 'E:\VOLUME DATA\ScanID1934_Leaf1\')

where ScanID1934_Leaf1 is a directory containing a stack of images. VolViewer will automatically load and display these images as soon as it finds that the watchfile has been updated.

Other examples

It is not practical to script VolViewer using these commands manually. It is better to use VolViewer as a tool that is controlled through a library of commands in, for example, Matlab. Or, when running VolViewer on the server side of a server/client session where the user is interacting with VolViewer through a client web page.

Matlab to Volviewer

The DArT_Toolbox contains a library of functions for using and controlling VolViewer from Matlab.

Accessing VolViewer from Matlab

There is a VolViewer Matlab class library: launching and controlling Volviewer for the display of 3D volume images (the display window has zoom, rotate, etc.). On computers with an appropriate graphics card and stereo display VolViewer can be used to display volume images and graphics objects from msr files.
VolViewer as a viewport for Matlab

VolViewer viewport without its usual menu-bars and under control of a Matlab program. It shows endogenous fluorescence signal from a young leaf that has been annotated with a series of points set on the mid point of trichomes and joined by lines. These points characterise the 3D shape of the leaf and are stored in an MSR text file.
To manipulate the view: left-click-drag rotate, middle-click-drag translate, right-click-drag zoom.

This image was created using steps 2, 3, and 4 below.

1) Install VolViewer

  • For example, in 'C:\VolViewer_x64'. This is the PathToVolViewer.

2) Launch VolViewer from Matlab

  • Temporary data files on paths are saved in '...\DArT_Toolshed\ToolBag\VolViewerAPI\CLASSFILES'

This should mean that once VolViewer is installed on a computer - the system will remember where to find everything without having to respecify paths.

 VO=VolViewer(1,'D:\VolViewer_x64','D:\VolViewer_x64')

creates a VolViewer object - which, because there is no semicolon at the end, is displayed as:

         PathToVolViewer: D:\VolViewer_x64 
         PathToWatchFile: D:\VolViewer_x64 
         WatchFileNumber:    1.00000 
                     PathTo: 
          imageFilenames: 
             msrFilename: 
             tfnFilename: 
             slcFilename: 
             vvrFilename: 
             objFilename: 
                Commands: 

Notice that the paths have been filled in and that this is the first copy of VolViewer (WatchFileNumber is 1).
3) Display an image stack in VolViewer

  • The key step is to notify VolViewer where to find the images by putting a command into WatchFile1.txt. This is done automatically with the following
 VO=imshowVOL(VO, 'PathTo','D:\Shape_T1_only\Image_data\11to14DFS\1554')

In this case the image stack is in the directory 'D:\Shape_T1_only\Image_data\11to14DFS\1554'. Notice, that VOL has been updated

>> VOL
         PathToVolViewer: D:\VolViewer_x64 
         PathToWatchFile: D:\VolViewer_x64 
         WatchFileNumber:    1.00000 
         PathTo: D:\Shape_T1_only\Image_data\11to14DFS\1554 
          imageFilenames: 
             msrFilename: 
             tfnFilename: 
             slcFilename: 
             vvrFilename: 
             objFilename: 
                Commands: 

4) Display an MSR (results: points/lines/planes) file

  • Put the command into WatchFile1.txt using
 VO=imshowVOL(VO,'PathTo','D:\Shape_T1_only\Image_data\11to14DFS\1554','msrFilename','1554_T1_Shape.msr')

To hide the image

VO=commandsVOL(VO,'set_channels(0,0,0)');

To see the image again

VO=commandsVOL(VO,'set_channels(1,1,1)');

To clear the MSR points/lines/planes

VO=commandsVOL(VO,'set_clear_all_MSR()')