[Tuto05Mesher] Create a mesh from an image

The fifth tutorial explains how to use several objects in an application. This application provides an action to create a mesh from an image mask.

../../_images/tuto05Mesher.png

Prerequisites

Before reading this tutorial, you should have seen:

Structure

Properties.cmake

This file describes the project information and requirements:

set( NAME Tuto05Mesher )
set( VERSION 0.1 )
set( TYPE APP )
set( DEPENDENCIES  )
set( REQUIREMENTS
    dataReg
    servicesReg
    gui
    guiQt
    ioVTK
    visuVTKQt
    uiIO
    vtkSimpleNegato
    vtkSimpleMesh
    opVTKMesh # provides services to generate a mesh from an image.
    launcher
    appXml
)

bundleParam(appXml PARAM_LIST config PARAM_VALUES MesherConfig)

Note

The Properties.cmake file of the application is used by CMake to compile the application but also to generate the profile.xml: the file used to launch the application.

plugin.xml

This file is in the rc/ directory of the application. It defines the services to run.

<plugin id="Tuto05Mesher" version="@PROJECT_VERSION@">

    <requirement id="dataReg" />
    <requirement id="servicesReg" />
    <requirement id="visuVTKQt" />

    <extension implements="::fwServices::registry::AppConfig">
        <id>MesherConfig</id>
        <config>

            <!-- Mesh object associated to the uid 'myMesh' -->
            <object uid="myMesh" type="::fwData::Mesh" />

            <!-- Image object associated to the key 'myImage' -->
            <object uid="myImage" type="::fwData::Image" />

            <!-- Frame & View -->

            <service uid="myFrame" type="::gui::frame::SDefaultFrame">
                <gui>
                    <frame>
                        <name>Mesher</name>
                        <icon>Tuto05Mesher-0.1/tuto.ico</icon>
                        <minSize width="800" height="600" />
                    </frame>
                    <menuBar />
                </gui>
                <registry>
                    <menuBar sid="myMenuBar" start="yes" />
                    <view sid="myDefaultView" start="yes" />
                </registry>
            </service>

            <!--
                Default view service:
                The type '::fwGui::LineLayoutManager' represents a layout where the view are aligned
                horizontally or vertically (set orientation value 'horizontal' or 'vertical').
                It is possible to add a 'proportion' attribute for the <view> to defined the proportion
                used by the view compared to the others.
            -->
            <service uid="myDefaultView" type="::gui::view::SDefaultView">
                <gui>
                    <layout type="::fwGui::LineLayoutManager">
                        <orientation value="horizontal" />
                        <view caption="Image view" />
                        <view caption="Mesh view" />
                    </layout>
                </gui>
                <registry>
                    <view sid="RenderingImage" start="yes" />
                    <view sid="RenderingMesh" start="yes" />
                </registry>
            </service>

            <!-- Menu Bar, Menus & Actions -->

            <service uid="myMenuBar" type="::gui::aspect::SDefaultMenuBar">
                <gui>
                    <layout>
                        <menu name="File" />
                        <menu name="Mesher" />
                    </layout>
                </gui>
                <registry>
                    <menu sid="menuFile" start="yes" />
                    <menu sid="menuMesher" start="yes" />
                </registry>
            </service>

            <service uid="menuFile" type="::gui::aspect::SDefaultMenu">
                <gui>
                    <layout>
                        <menuItem name="Open image file" shortcut="Ctrl+O" />
                        <menuItem name="Save image" />
                        <separator />
                        <menuItem name="Open mesh file" shortcut="Ctrl+M" />
                        <menuItem name="Save mesh" />
                        <separator />
                        <menuItem name="Quit" specialAction="QUIT" shortcut="Ctrl+Q" />
                    </layout>
                </gui>
                <registry>
                    <menuItem sid="actionOpenImageFile" start="yes" />
                    <menuItem sid="actionSaveImageFile" start="yes" />
                    <menuItem sid="actionOpenMeshFile" start="yes" />
                    <menuItem sid="actionSaveMeshFile" start="yes" />
                    <menuItem sid="actionQuit" start="yes" />
                </registry>
            </service>

            <service uid="menuMesher" type="::gui::aspect::SDefaultMenu">
                <gui>
                    <layout>
                        <menuItem name="Compute Mesh (VTK)" />
                    </layout>
                </gui>
                <registry>
                    <menuItem sid="actionCreateVTKMesh" start="yes" />
                </registry>
            </service>

            <service uid="actionQuit" type="::gui::action::SQuit" />

            <service uid="actionOpenImageFile" type="::gui::action::SStarter">
                <start uid="readerPathImageFile" />
            </service>

            <service uid="actionSaveImageFile" type="::gui::action::SStarter">
                <start uid="writerImageFile" />
            </service>

            <service uid="actionOpenMeshFile" type="::gui::action::SStarter">
                <start uid="readerPathMeshFile" />
            </service>

            <service uid="actionSaveMeshFile" type="::gui::action::SStarter">
                <start uid="writerMeshFile" />
            </service>

            <service uid="actionCreateVTKMesh" type="::opVTKMesh::action::SMeshCreation">
                <in key="image" uid="myImage" />
                <inout key="mesh" uid="myMesh" />
                <percentReduction value="0" />
            </service>

            <!-- Add a shortcut in the application (key "v") -->
            <service uid="ActionShortcut" type="::guiQt::SSignalShortcut">
                <config shortcut="v" sid="myDefaultView" />
            </service>

            <!--
                Services associated to the Image data :
                Visualization, reading and writing service creation.
            -->
            <service uid="RenderingImage" type="::vtkSimpleNegato::SRenderer" autoConnect="yes" >
                <in key="image" uid="myImage" />
            </service>

            <service uid="readerPathImageFile" type="::uiIO::editor::SIOSelector">
                <inout key="data" uid="myImage" />
                <type mode="reader" />
            </service>

            <service uid="writerImageFile" type="::uiIO::editor::SIOSelector">
                <inout key="data" uid="myImage" />
                <type mode="writer" />
            </service>

            <!--
                Services associated to the Mesh data :
                Visualization, reading and writing service creation.
            -->
            <service uid="RenderingMesh" type="::vtkSimpleMesh::SRenderer" autoConnect="yes" >
                <in key="mesh" uid="myMesh" />
            </service>

            <service uid="readerPathMeshFile" type="::uiIO::editor::SIOSelector">
                <inout key="data" uid="myMesh" />
                <type mode="reader" />
            </service>

            <service uid="writerMeshFile" type="::uiIO::editor::SIOSelector">
                <inout key="data" uid="myMesh" />
                <type mode="writer" />
            </service>

            <!-- Connect the shortcut "v" to the update slot of 'actionCreateVTKMesh'-->
            <connect>
                <signal>ActionShortcut/activated</signal>
                <slot>actionCreateVTKMesh/update</slot>
            </connect>

            <start uid="myFrame" />
            <start uid="ActionShortcut" />

        </config>
    </extension>
</plugin>

Run

To run the application, you must call the following line into the install or build directory:

bin/fwlauncher share/Tuto05Mesher_0-1/profile.xml