<?xml version="1.0" encoding="UTF-8"?>
<!--
    This file is a test input file for ActionStateMachine.
    The ASM here is very simple:
    - Open an image with the Open Action
    - Name it openedImage
    - Apply a manual threshol on this image
           	- with low threshold to arbitrary set to 58
           	- with high threshold arbitrary set to 153
    - Name the output image resampledImage
    - Save this output image in the same directory as the input image.
-->
<scxml      xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
            xmlns='http://camitk.imag.fr/3/smallScxml'
            xmlns:camitk='http://camitk.imag.fr/3/asm'
            xsi:schemaLocation='http://camitk.imag.fr/3/smallScxml ../resources/smallScxml.xsd'
            applicationName="Simple Image Filter"
            initial="Initialize"
>
    <state id="Initialize">
        <onentry>
            <camitk:onState>
                <camitk:description>
<![CDATA[
This Action State Machine performs a very simple image processing pipeline:<br/>
<ul>
    <li>Open an image with the Open Action</li>
    <li>Name the output image openedImage</li>
    <li>Apply a manual threshold on this image</li>
    <ul>
        <li>with low threshold to arbitrary set to 58</li>
        <li>with high threshold arbitrary set to 153</li>
    </ul>
    <li>Name the output image resampledImage</li>
    <li>Save this output image in the same directory as the input image.</li>
    <li>Quit the application</li>
]]>
                </camitk:description>                
                <camitk:action>
                    <camitk:name>Set Path To Test Data</camitk:name>
                </camitk:action>
            </camitk:onState>
        </onentry>
        <transition event="Next" target="Image Open" applyAction="true"/>
    </state>
    
    <state id="Image Open">
        <onentry>
            <camitk:onState>
                <camitk:description>Open a new volume image and display it.</camitk:description>
                <camitk:action>
                    <camitk:name>Open File</camitk:name>
                    <camitk:parameters>
                        <camitk:parameter name="File Name" type="QString" value="brain.mha"/>
                    </camitk:parameters>
                    <camitk:outputs>
                        <camitk:component type="ImageComponent" name="openedImage"/>
                    </camitk:outputs>
                </camitk:action>
            </camitk:onState>
        </onentry>
        <transition event="Quit" target="Bye" applyAction="false"/>
        <transition event="Next" target="Image Display" applyAction="true" />
    </state>

    <state id="Image Display">
        <onentry>
            <camitk:onState>
                <camitk:description>
<![CDATA[
Please check that this image is the right image.
]]>
                </camitk:description>
                <camitk:altDescription previousStatus="ABORTED ERROR">
<![CDATA[
<font color='#ff0000'>
    The image has not been opened correctly. <br/>
    Please retry to open an image.
</font>
]]>
                </camitk:altDescription>
            </camitk:onState>
        </onentry>
        <transition event="Back" target="Image Open">
            <camitk:onTransition>
                <camitk:close>
                    <camitk:component type="ImageComponent" name="openedImage"/>                
                </camitk:close>
            </camitk:onTransition>
        </transition>
        <transition event="Next" target="Image Resampling" disable="ABORTED ERROR"/>
    </state>
    
    <state id="Image Resampling">
        <onentry>
            <camitk:onState>
                <camitk:description>Resample Image</camitk:description>
                <camitk:action>
                    <camitk:name>Resample</camitk:name>
                    <camitk:parameters>
                        <camitk:parameter type="int" value="90" name="New Image X Dimension"/>
                        <camitk:parameter type="int" value="100" name="New Image Y Dimension"/>
                        <camitk:parameter type="int" value="90" name="New Image Z Dimension"/>
                        <camitk:parameter type="int" value="0" name="New Image Scalar Type"/>  <!-- enum #0 = SAME_AS_INPUT -->
                    </camitk:parameters>
                    <camitk:inputs>
                        <camitk:component type="ImageComponent"  name="openedImage"/>
                    </camitk:inputs>
                    <camitk:outputs>
                        <camitk:component type="ImageComponent" name="resampledImage"/>
                    </camitk:outputs>
                </camitk:action>
            </camitk:onState>
        </onentry>
        <transition event="Back" target="Image Display"	applyAction="false"/>
        <transition event="Next" target="Save Image" applyAction="true"/>
    </state>

    <state id="Save Image">
        <onentry>
            <camitk:onState>
                <camitk:description>Save the threshold image</camitk:description>
                <camitk:action>
                    <camitk:name>Save</camitk:name>
                    <camitk:inputs>
                         <camitk:component type="ImageComponent" name="resampledImage"  suffix=".mha"/>
                    </camitk:inputs>
                </camitk:action>
            </camitk:onState>
        </onentry>
        <transition event="Back" target="Image Resampling" applyAction="false">
            <camitk:onTransition>
                <camitk:close>
                    <camitk:component type="ImageComponent" name="resampledImage"/>
                </camitk:close>
            </camitk:onTransition>
        </transition>		
        <transition event="Next" target="Bye"/>
    </state>

    <state id="Bye" final="true">
        <onentry>
            <camitk:onState>
                <camitk:description>
<![CDATA[
<b><i> Congratulations ! </i></b><br/>
<i>Press <b>Quit</b> to quit the application or <b>Back to the Beginning</b> to
to re-run the application from the beginning.
]]>
                </camitk:description>
            </camitk:onState>
        </onentry>
        <transition event="Back to the Beginning" target="Initialize">
            <camitk:onTransition>
                <camitk:close>
                    <camitk:component type="ImageComponent" name="openedImage"/>
                    <camitk:component type="ImageComponent" name="resampledImage"/>
                </camitk:close>
            </camitk:onTransition>
        </transition>
    </state>
</scxml>
