Graphical User Interface¶
Overview¶
Internal Structure¶
medtool consists of a graphical user interface and a series of underlying application software (so called scripts) that manipulate existing data or create new data. The flowchart below shows how medtool’s graphical user interface (GUI) performs tasks through the use of scripts and how data is read or stored.
A user interacts with the medtool GUI by inserting data and running scripts. These scripts read data, modify them, and writes them to a data storage device. The medtool GUI do not hold big data, it only safes the script names including the applied parameters.
GUI Structure¶
After starting medtool a user interface appears:
It consist of several parts:
Script Browser: This holds a list of all created scripts.
Script Parameters: The parameters of the active script in the script browser are shown in this area.
Script Output / Run Settings: After launching a script, the standard output and standard error are written to the Script Output area. The second tab (Run Settings) allows to modify run parameters like working directories, etc.
Viewer / Editor / Spreadsheet / Directory Manager: This area contains a simple midplane Viewer, a lightweight Editor, a simple Spreadsheet application, and a Directory Manager.
During a typical medtool GUI during a run looks like this:
Several scripts are visible in the Script Browser. Colored flags indicate the run status. Parameters for the active scripts are shown in the Script Parameters tab. In the Viewer area three mid-planes are visible. The Script Output area shows the standard output of the currently running script. The status bar at the bottom indicates that a job is running (red dot) and the green bar shows the progress.
Since medtool 4.4, it has been possible to adapt the user interface via a user level selector. This makes it easier for new users in particular to start using the “Simple” or “Standard” levels. Advanced users still have the option to view all script options at the “Expert” level.
More detailed descriptions are given in the section User Level.
Scripts Basics¶
A script with default parameters is loaded by clicking on the corresponding menu e.g. Image, Mesh, Material, Boundary, Solve, Post, Analyze, Publish, Fabricate or Extras menu (for details see Scripts section below). Which menu entries are visible depend on the licenced modules. All other menus (File, Edit, Run, View, Help) are medtool specific and will be described in detail in the following sections.
To load a script (see figure above) following steps have to be done:
Click on a menu entry (e.g Extras - File - Modifier 1)
Insert an application name or keep the default name (here
paf_
). For the first character only letters (A-Z, a-z) or underlines_
are allowed. The following characters may also include numbers (0-9) or-
. All other characters or blanks are forbidden. The script names have to be unique. The default script name is simple the name of the source code file plus an_
at the end.After clicking
OK
the new script will appear in the Script Browser and the corresponding script parameters will show up in the Script Parameters area.
Technically speaking an instance of the script is created. If the script is loaded again it has to get a different Script Browser name because it may hold different data for each parameter .
Note
- For extensive projects with many scripts:
number the script with
_01
,_02
…gives a brief hint on the script behavior e.g.
segment
,3D_mesh
keep the script name e.g.,
mic
,hma
,an informative script name is e.g.:
_01_segment_mic
create a folder with the same name to create new files e.g.:
01_segment_mic
Info Text¶
Use the “Info Text” script form the “Extras” menu to document and group scripts. The scripts have to
start with a __
(double) or ___
(triple) underline character.
These underlines has two effects:
The scripts names are colored differently in the Script Browser (better overview) and
all scripts between two Info Text scripts can be easily checked and unchecked by clicking on the check button of an Info Text script.
Script Entry Types¶
After loading a script all options (required and optional) appear in the Script Parameters area (see figure).
Explanations of the red numbers of the above picture:
Is a required entry. It has no check box on the upper left corner and is always active. This parameter must be provided otherwise the script stops with an error.
This is an optional entry which is activated. Click on 4 to activate it. It means this script argument IS not passed to the script during the call.
This is an optional entry which is not deactivated. It means this script option value IS NOT passed to the script during the call.
Toggle this button to activate/deactivate this option (e.g. here
-drange
).Clicking on the “help” symbol to show the help of this option in the Script Output area.
Clicking on the option text (e.g.
-sep
) replaces the value inside the entry by the default value.This is a line edit input area. If more than one parameter are given they must be separated by a
;
(semi-colon). In this case the extended input are (see 8) is opened automatically. Both fields (7 and 8) are synchronized.Extended input area to show all parameters as a list. See also 7.
Number of “o” next to the labels indicates how many entries (see 4)) are activated within this tab.
Many different entry types are available:
input file entries
input file edit entries
output file entries
directory entries
line entries
split entries
combo box entries
radio entries
color entries
table entry
The dpScriptTemplate.py
file shows all these different types.
Query Replace Parameters¶
The Replace Parameter option in the Edit Menu allows to query and replace these script entries i.e. the parameters.
It is a simple string replace which can be applied on
the active script
checked scripts
all scripts
(see Run Menu for explanations) as well as
active arguments (checked entries)
all arguments
which are described above.
Database¶
xml Files¶
After the creation of the script instance the parameter values appear in the Script Parameters area. Several different entry types are implemented (file, combo, radio, … entries). All entries have a line edit with data in it which can be edited. The data are interpreted and passed to the scripts as strings.
Internally medtool creates based on these line edit entries an XML database which looks for this example like:
<!DOCTYPE MedToolXML>
<MedToolXML cpu="1" writeonly="no" resfile="" workdir="Z:/testing" exefile="" paramfile="">
<paf_ script="paf" active="yes">
<modulName>
<description>Parameter File Generator</description>
</modulName>
<in>
<description>Input File Name</description>
<type>fileEntryInEdit</type>
<value>testIn.dat</value>
<default>testIn.dat</default>
<optional>no</optional>
<active>yes</active>
<info>txt:dat:inp:*</info>
<menu>Common</menu>
</in>
<par>
<description>Parameter File Name</description>
<type>fileEntryIn</type>
<value>test.par</value>
<default>test.par</default>
<optional>no</optional>
<active>yes</active>
<info>txt:dat:par</info>
<menu>Common</menu>
</par>
<out>
<description>OutFile Name</description>
<type>entry</type>
<value>$outfile</value>
<default>$outfile</default>
<optional>no</optional>
<active>yes</active>
<info>1</info>
<menu>Common</menu>
</out>
</paf_>
</MedToolXML>
This XML file can be saved and loaded via the File Menu. It is a meta data file without any heavy data in it like, for example, medical images. This file can be edited by hand if it is damaged. But only experience users should edit this file manually. In the worst case, medtool can not open the file after editing.
The name of the database appears in the GUI in the upper left corner. If the database
is not saved it says untitled.xml
.
Auto Save¶
If the database is saved once, e.g. as myMedtool.xml
, medtool will save the state
every minute in a file e.g. as myMedtool.xml.bak
. I case of a medtool crash, rename
this file e.g. to myMedtoolRecover.xml
and load it to get the last state. The
.xml.bak
files can be deleted if not needed anymore.
Update¶
Script options, default values, etc are changing. Usually only options are added but
not deleted. In order to be able to use new options, an old database needs to be
updated. This is done via File Menu - Update. First save or re-name your old
database file. Next call the update function of medtool and save the new database
.xml
file and test the new file if it is working correctly.
Advanced Run Options¶
Both Parameter Study and Parameter Study Batch run optoins are advanced medtool features and will be explained in more detail below.
Parameter Study¶
A typical script call can e.g. look like:
python circleArea.py -rad 12.3 -out /usr/work/Res1.txt
There is nothing wrong but if one likes to investigate the influence of the -rad
option
(the radius) than the parameter and script need to be re-run again and again. It would be more
convenient to use a generic variable for -rad
. This functionality is implemented in
medtool and called parameter study.
The basic idea behind parameter study is to use a generic run string i.e.:
python circleArea.py -rad $radius -out $dir$filename
where $radius
, $dir
, and $filename
are variables which start with $
in medtool .
The values these variables are supplied by a parameter file which is given in Run Settings tab. In this way medtool recognizes where to read the quantities. The content of such a file may look like:
$radius $dir $filename
12.3 /usr/work/ Res1.txt
19.7 /usr/stor/ Res2.txt
For this example, medtool would send the following run strings to the system:
python circleArea.py -rad 12.3 -out /usr/work/Res1.txt
python circleArea.py -rad 19.7 -out /usr/stor/Res2.txt
To set-up a parameter study by using medtool , following steps should be done. First a script is loaded and the script is executed in a regular way:
This means a user:
inserts a value for a parameter (e.g. 12.3),
clicks the Run Active or Run Checked button, and
checks the output area to see if the run was successful.
To be able run a parameter studies some pre-steps are necessary as shown in the figure:
One has to:
create a parameter file (e.g. with Spreadsheet in medtool ),
sets this file in the Run Settings - Parameter File option,
replaces the value by the parameter (e.g.
$radius
instead of 12.3). This replacement can also be done by the Query Replace Parameters functionality.
Now the script can be run as parameter study by:
clicking the Run Parameter Study button.
Finally, the output area should be checked where two successful run outputs are visible.
Internally medtool does a simple replacement of the $radius
string
by 12.3
, 19.7
. Thus,
more parameters can be appear in one entry including other characters (e.g.
$dir$file.png
) .but the names have to be unique in sense of a query/replace operation. For example
$radius
and$radius2
would be problematic because$radius
is part of$radius2
! Simply change in this case$radius
to$radius1
and the replacement works correctly.
Parameter Study Batch¶
The above described Run Parameter Study function in medtool is very helpful when you have to process many data sets. The option does not require special skills but is limited to one CPU on your server. If you want to run a parameter study in parallel, you can generate batch files and start them manually. This is called the Run Parameter Batch function.
Note
An additional license is necessary to activate this option.
The following steps are necessary for this:
set up an Run Parameter Study as described in Parameter Study.
Change your entries to parameters,
create a parameter file, and
select the parameter file in the Run Settings tab
as shown here:
edit the Run Batch Settings Panel:
Choose a batch file name. In windows the extension ‘.bat’ will be added automatically.
Choose the number of CPUs you like to use.
as shown here:
now the batch script can be creating by clicking the Run Parameter Batch button (F4) and two batch scripts are created.
to run these scripts open a terminal under the Run menu, click Open Python Terminal.
This
opens a terminal,
activates the current medtool python version,
sets all enviroment variables, and
changes to the working directory.
For example, the
dir
command (Windows) orls
command (Linux) shows the content of the current working directory.two batch scripts are created
circleArea_batch_1.bat
andcircleArea_batch_2.bat
because we have chosen two CPUs. Looking into one of the files using the Editor shows"C:/Program Files/medtool47/Python39/python.exe" "C:/myWorkingDir/circleArea_gui.py" -rad "12.3"
This shows the start of a medtool Python script with one parameter.
Start this batch script by typing
circleArea_batch_1.bat
in the terminal:(Python39) C:\myWorkingDir> circleArea_batch_1.bat
We see the same output as in the medtool GUI
S T A R T circleClass V_07.01.2014 - D. H. Pahr ... get / compute area Area = 475.291 E N D E D SUCCESSFULLY in TOT : 0.0 sec
open a second terminal and start
circleArea_batch_2.bat
. Now two medtool scripts run in parallel.
Note
If you do not run a “Parameter Study” but like to use this functionality, simply select a dummy parameter file and choose only one CPU.
If you run job in parallel, every job needs memory. Check that you are not running out of memory during a run. Otherwise the job gets very slown.
Do not use another Python version, because of the binary compatibility. Furthermore, all environment variables need to be set manually, which is tricky.
When medtool is closed, all terminals are also closed.
Own Python Scripts¶
There are three possibilities to use own Python scripts together with medtool libraries:
use medtool Plugins:
Pro: full medtool GUI support (options)
Con: medtool plugin must be written.
use
python_medtool
via the Extras - User Script Runner script (see examples, Grid Data Scripting).
Pro: no Plugin needs to be written
Con: no GUI for parameters.
use the Run - Open Python Terminal function to start the script in a terminal with activated medtool python (see Parameter Study Batch)
Pro: full freedom to start a Python scripts with or without medtool libraries.
Con: only for experiences users, limited to modules includes in the medtool distribution.
Useful Tools¶
User Level¶
As of medtool 4.4, it has been possible to adapt the user interface via a user level selector. There are three levels: Simple, Standard and Expert. Changing the user level has the following effects:
Script options are shown or hidden and
GUI areas and buttons are shown or hidden.
The following pictures show the three levels: Simple, Standard and Expert.
Simple
Standard
Expert
Which level should be chosen depends on the experience of the user.
Simple: A user who uses medtool for the first time. The GUI shows default options and functions that allow you to work through simple examples.
Standard: A user who uses medtool for daily work and also carries out parameter studies. Existing scripts are usually used and hardly changed.
Expert: A very experienced user who wants to have all medtool functions visible. This mode was the default for older medtool versions.
If you change the user mode from e.g. Expert on Standard and has activated an Expert function in one of the scripts, the following error appears:
This function prevents active options from being hidden. The user levels can only be changed if the corresponding option has been deactivated.
Script Output¶
Every script is producing output in form of text and (most properly other data). The text in the script ouput tells the user that a script is started, informs about the current task and finishing status. This output should be always checked. Therefore, medtool shows the Script Output tab automatically.
In the figure above a few more things are important:
The text produced by the script. In case of plugins the user should write meaningful messages to
stdout
. This output is written in this area during a medtool run.The progress bar is useful in case of long parameter runs. The “big green dot” means nothing is running, medtool is ready for a new run. When it become red, a process (script) is running. It is not possible to run more than one job at the time.
Click this button to delete the text inside the output area. This is done automatically before a run starts.
Save the output to a text file. This can be used as logging informations.
Search for strings in the output area. For examples, to look for WARNINGS.
Find the next appearance of the string given in 5).
Viewer¶
Note
If the options shown here are not visible, change the User Level to Expert.
medtool is not design to work on data interactively. Many other tools are available for such tasks depending on the type of data. For example:
medical imaging data: 3D slicer (http://www.slicer.org/), ImageJ (http://imagej.nih.gov/ij/)
point & cell data: Paraview (http://www.paraview.org/)
Finite Element data: Solver specific pre- and post processors (Abaqus Viewer, HyperView, … )
The idea is to quickly view midplane or projected data (like X-rays), to get important information about the data, and to select points or regions interactively. The image viewer in medtool was design to give such a quick insight. It shows three orthogonal planes of an image. After medtool startup the mid-planes and coordinate definitions are shown. The point 0,0 is always at the upper left corner.
On the left hand side a panel appears which allows to set viewing options, gives image informations and shows different data.
The data files for the viewer are generate with the Image - Processor script (see figure below, annotation 1 and 2) to generate three orthogonal mid-plane files (3) or three orthogonally projected planes (4), which are simulated X-rays.
This options write four files
anyName-XM.png -> x midplane
anyName-YM.png -> y midplane
anyName-ZM.png -> z midplane
anyName-IM.csv -> info file
“anyName” is an abitrary name (e.g. ‘test’) and the extension -XM
, -YM
, -ZM
, -IM
for midplanes
or -XP
, -YP
, -ZP
, -iP
for projected planes are automically appended.
To open a file using * open * in the viewer. Only one of these three files has to be
selected. The remaining images are automatically recognized and loaded.
Note
All mid-planes are loaded automatically after running a script in medtool .
Image Info & ROI Options¶
3D Image Info: Shows or hides the 3D Image Info tab. Inside the tab the most
important meta data are shown. These data are read from the *-IM.csv
or *-IP.csv
file. Maybe older medtool (4.2 and before) do not write out these files. Thus, not
all fields may be filled with values.
2D Image Info: Allows to pick points, lines, or polylines via the mouse. Click outside of the mid-planes to delete the selection.
The fields contain the following information:
Voxel Id i;j;k
: The global i,j,k voxel id of the picked voxel. Depending on the mid-plane, one of these values is always half of the voxel data size in this direction.
Voxel Id List i;j;..
: The local picked i,j values. These values are the i,j values of the corresponding 2D images. Depending on the mid-plane they are the global j,z (XM), i,k (YM), or i,j (ZM) values. This list can be copied to the Analyze - DXA script (din
option) or previously defined values can be pasted from elsewhere to define a new ROI.
Gray Value
: The picked gray value which is computed based on theGray Value Range
. If no range is given the default the image range is 0..255. A list of gray-values can be picked and displayed.
Position [mm]
: The physical position of the picked point. TheOffset
is taken into account.
Length [mm]
: The physical length between the last two picked points (length of a line).
ROI Selection: Allows to select cubical regions of interest (ROIs).
Features are:
The sliders (1) allow to change the bounding boxes manually in X, Y, Z.
The buttons on the right side of the sliders (2) allow to reset the ranges to min/max values.
BBOX i;j;k;di;dj;dk
: This entry shows the bounding box (ROI) by giving the start voxel ids i,j,k and the size of the ROI di;dj;dk - both are numbers of voxels. This list can be copied to the Image - Processor script (cut
option) in order to crop this region from a model or values can be pasted from elsewhere to define a new ROI.The button on the right side of the entry (3) allows to define the ROI based on a picked
Voxel Id List i;j;..
. Pick first a few points on a mid-plane and than click this button. It used the min/max picked i,j values as new bounding box. The third bounding box values are unchanged.
Editor¶
The editor is a simple lightweight editor with some basic syntax highlighting for Abaqus input files, python files, and text files which are used by medtool. Very big files (e.g. Abaqus) should be loaded with an editor with text folding.
The editor can also be used to edit parameter files (tools underlines in red).
Spreadsheet¶
The spreadsheet allows a quick generation of parameter run files in CSV format. These files can also be created by tools like Excel. It has some commenting functionality which allow to comment lines in and out. This is especially useful for parameter runs.
The spreadsheet stores data in CSV format using ;
as seperator:
$filename;$thres;$cutX;$cutY;
patient1.mhd;4563;345;567;
patient2.mhd;4436;332;545;
patient3.mhd;4765;366;567;
This format is the required file format for the medtool parameter file.
Directory Manager¶
The directory manager is designed to help the user to manage the Project Folder Structure of a medtool project.
It has following functionalities:
Create a single directory under the selected directory
Delete a directory. Because of the permanent deletion this function requires an empty directory.
Rename a directory.
Create a directory structure (Project Folder Structure ). A sub-window opens if this button is clicked (see left window):
A predefined structure can be generated. Individual folders can be toggled to ON or OFF. New folders can be added e.g. by inserting:
newFolder1;newFolder2;newFolder3
inside the empty text edit and click Add (result is shown in right figure).
Go to the home directory.
Go to the current working directory.
Project Folder Structure¶
The Directory Manager is able to generate such structure automatically. A few more words are given on this important topic. A workflow manager like medtool is able to produce a huge amount of data which should be organized to be able to re-use them. A suggested folder structure for an image to model project could look like:
The main project folder is splitter into subfolders starting with A, B, C etc. The way of indicating the folders is always similar i.e. in every project folder A contains original scans (uCT, QCT, …), B contains edited gray-scale images (cropped, scaled, …), C holds registered images, in D are segmented images (masked, thresholed,..), E holds meshes (surface, solid), F contains material mappings, G boundary conditions, H finite element models, K documents, and Z always contains the medtool XML and parameter files (par, txt, xls). Inside each folder the subfolders are numbered by 01, 02, 03 etc. The scripts in the corresponding medtool file also include this name e.g. mic_calib_01. In this way someone who has never worked with the data knows immediately where one can find what. The medtool script and parameter files in the Z folder gives exactly the order and parameters for the individual operations to modify or generate data.
Quick Directory Creation¶
Sometimes when you create a script, you want to create a folder with the same name. If the script and folder names are identical, you can immediately see which script writes data to which location. This can be realized in medtool with a few clicks.
Select a working directory where you like to create you folder
Click on the script which contains the folder name
Create a new folder/directory by clicking the button in the Directory Manager
A message box pops-up which shows the script name (with out
_
underline) as suggestion for the new folder name.
After you click OK
, a new folder is created within the working directory.
Toogle Working Directory¶
When opening a file in medtool, it often happens that very long file names are displayed, which affects the clarity.
You can switch very quickly between the long and an abbreviation ie.
to the .\
which is known as current directory in Linux). The
current directory is the working directory (see Run Settings) in medtool.
Simply click the Right mouse button (not the left) and a pop up window appears.
Select the Toogle Working Directory options and you see after that
This allows switching (toogle) between the short and long directory path versions.
Plugins¶
medtool offers two ways to run self-written scripts with the shipped Python version and all medtool modules:
Python Scripts or
medtool plugins.
Python scripts are simply executed with the Extras - User Script Runner.
A Python script is programmed using a text editor and given in the -exe
option of this script, e.g.:
> python_medtool script.py -value 10
python_medtool
is recognized by the User Script Runner and replaced by the
shipped Python version. Furthermore, internal enviroment variables are set such that
medtool libraries can be used.
A much more comfortable option to run user scripts are medtool plugins which are described below.
Write a Plugin¶
All medtool scripts are plugins which can be written in any programming language. medtool has to get 2 informations from the script to be able to integrate it accordingly:
The information about the script parameters (entry type, name, default value, …)
The help information of the script - simply a text string.
The script parameters are obtained from the script by calling it
with the -gui
option. This option has to be implemented by the user.
Such a gui string has the following style:
# entry arg description default opt info"
guiInit = \
"*modulName 'Template Script' \n"\
+"*fileEntryIn -inf 'Input File Name' testIn.dat no txt;dat \n"\
+"*fileEntryInEdit -ine 'Input/Edit File Name' test.txt yes txt;TXT \n"\
+"*fileEntryOut -out 'Output File Name' testOut.txt yes txt;dat \n"\
...
In this example a fileEntryIn
is created named Input File Name
which has a
default value testIn.dat
and is not optional.
The help information is return by a script by calling it with -help
.
In case of Python, the most elegant way is to return simply the doc string.
To make live easy for new users a fully run-able script template is provided with medtool . It can be simply opened via File Menu -View Script Template.
This shown script is a python template script and can be saved, modified, etc. All possible GUI entries are presented. It can be used to add it as plugin to medtool , can be used to try out the plugin option or to use it as a starting point for the development of a new medtool plugin script. For this task please following the instructions in the template file.
Adding a Plugin¶
A prevously create user plugin can be easily added by the user to medtool . The plugin manager is opened via the File Menu - Add Plugin option.
Required values are:
Menu Name: The name of the script which will appear inside the medtool menu. If two names are given which are separated by
:
than a sub-menu is created.Browser Name: An abbreviated name which should appear as default value for a script instance during creation.
Script Name: The name and location of the script on the PC (full path to the script).
Language: The script language. Usually
python
.Exec
means an executable which is called without any command e.g. compiled C++ or Fortran files.User
means that a user defined call of the script is provided via an-exe
option inside the script. This is usually needed forabaqus python
scripts.Insert Before: The insert location of the script in an existing plug-in menu.
After clicking Apply
an XML file (plugin.xml
) is generated in the
user home directory inside a directory named .medtool
. medtool
has to be restarted in order to recognize the new plug-in.
During a medtool start-up it loads the plugin.xml
file and creates the Plugins menu
inside medtool .
The Plugin Source (see Figure above) can be viewed and edited by hand. The icon at the very right of the Manage section opens this file with an editor. Plug-in deletion and moving can be done by hand. Simply select and/or delete/move the corresponding text in this file:
After including the plug-in medtool shows the following menu entry:
and Script Browser entry after loading the script with the default name:
If no plugins are added there is no Plugins menu.