\documentclass{article}
\usepackage{cite}
\usepackage{latexsym}
\usepackage{wrapfig}
\usepackage{eso-pic,graphicx}

%% Header Logo
\newcommand{\mylogo}{\includegraphics[scale=0.2]{images/ritk.pdf}}
\usepackage{scrpage2}
\pagestyle{scrheadings}
\clearscrheadfoot
\chead{\headmark}
\cfoot[\pagemark]{\pagemark}
\ohead[\mylogo]{\mylogo}
\ihead[\today]{\today}

\begin{document}

\title{RITK Plugin Tutorial}
\author{Jakob Wasza, Sebastian Bauer, Sven Haase}
\date{October 2011}
\maketitle


%ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
\begin{wrapfigure}{r}{0.5\textwidth}
	\vspace{-20pt}
	\begin{center}
		\includegraphics[scale=0.6]{images/PluginArchitecture.pdf}
	\end{center}
	\vspace{-20pt}
	\caption{The Plugin Architecture.}
	\vspace{-10pt}
	\label{fig_pluginArchitecture}
\end{wrapfigure}
%ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

\section{Why do I need a plugin?}
As described in the RITK paper \cite{RITK2011}, the RITK is split up into several parts, that are called plugins. At the beginning there must be a plugin to provide the measured data (\textit{Source Plugin}), in the middle one can add plugins to manipulate this data (\textit{Filter Plugins}) and at the end there should be at least one plugin that represents the application layer of your program (\textit{Application Plugin}). (see Fig.~\ref{fig_pluginArchitecture})

\section{Where is the plugin creator?}
The plugin creator is integrated into the RITK application. Therefore, you can find it either in the source code in the module \textit{ritkCore}, if you want to modify the creator itself anything or, in the case you just want to use it and create your own plugin, you will find the plugin creator in the menu of RITK under "Plugins" $\rightarrow$ "Plugin Creator".

\section{What plugin do I need?}
If you want to acquire data from a 3-D sensor that is not yet supported by RITK then you will need a \textit{Source Plugin}. This kind of plugin is placed at the beginning of a RITK pipeline and provides the data for all downstream plugins of the current pipeline.\\
If you want to manipulate any data read from a file or acquired by 3-D sensor and provided by an already implemented \textit{Source Plugin} then you might need a \textit{Filter Plugin}. This kind of plugin is placed anywhere between a source plugin and an application plugin and can preprocess any payload delivered by the previous plugin. \textit{Filter Plugins} are optional and not needed to a complete RITK pipeline.\\
If you just want to present the data in a special way or evaluate the data at the end of the RITK pipeline then you will need an \textit{Application Plugin}. This kind of plugin is placed at the end of the RITK plugin. It provides the GUI and shows data that was acquired and preprocessed by the pipeline.

\section{How do I create my own plugin?}
After opening the plugin creator, a dialog should pop up (Fig.~\ref{fig_pluginCreator}) that gives you all the options needed to create your own plugin. At first you have to define the type of your plugin. Afterwards, you have to name your plugin (note: the extension \textit{plugin} is added to your name automatically) and give a short description. Both of these information will be shown in the plugin manager, when RITK is launched. Although RITK itself is open source developers may also differentiate between open source and closed source plugins. This will have an influence where the sources are created. The last option offers the opportunity to select the RITK modules and external libraries you want to link against.\\
After creating the plugin, RITK will create a folder in your RITKPlugins source directory named after your plugin and add this plugin to the CMake file. Now you just have to regenerate the \textit{RITKPlugins} solution with CMake and your new plugin will be ready (note: MSVC is able of detecting modifications of CMake files and does this automatically).

\section{Where do I write my code?}
The created plugin sources are very basic and have no functionality but can be compiled and used straight forward. If you want to add additional GUI elements into your widgets please be aware of the different thread contexts. Therefore, we is recommend to use the signal-slot-system of QT.
\subsection{Source Plugin}
What additional functions you want to add to your source plugin depends on the 3-D sensor and its interface. At least the function \textit{GenerateOutputInformation()} of \textit{MySourcePluginSourcePluginRImageSource.cxx} must be modified with the correct intrinsic parameters needed to calculate the 3-D data afterwards. Furthermore the same class includes the function \textit{GenerateRImage()} where you have to acquire the data from your sensor and set it as an output of the current plugin. Additionally, one can modify the data before providing it to the pipeline in the file \textit{MySourcePluginSourcePlugin.cxx} in the function \textit{RequestFrame}. If you want to add some additional payload to the current RImage (e.g. the skeleton of the Kinect) you can do this by implementing a new RImage and include this new RImage into your plugin.
\subsection{Filter Plugin}
In most cases you want to filter the range values of your input. Therefore the class \textit{MyFilterPluginImageFilter} was created that represents a wrapper class for an itk image filter. In the function \textit{ThreadedGenerateData()} of this class you can implement your filter algorithm. If you want to filter other values as well (e.g. RGB or WorldCoords) then you can implement those procedures into the \textit{DoFiltering()} function of \textit{MyFilterPluginRImageFilter.txx}.
\subsection{Application Plugin}
The generated plugin just includes a visualization widget. If you want to add processing algorithms before representing the data, you will need to do this in the \textit{ProcessEvent(ritk::Event::Pointer EventP)} function of \textit{MyApplicationPluginPlugin.cxx}. For any additional help please take a look at existing application plugins.

\section{How can I load my plugin in RITK?}
First of all, you don't have to modify RITK itself in any way to get your plugin loaded. After building the \textit{INSTALL} project ot \textit{RITKPlugins} your plugin is automatically loaded and added to the plugin manager. The plugin manager can either be called from the menu "Plugins" $\rightarrow$ "Plugin Manager" or by using the shortcut "Ctrl+M". The dialogue should look like Fig.~\ref{fig_pluginManager} and provides the functionality to start or stop any plugin loaded.\\
Furthermore, you can find a plugin configuration file in your RITK binary directory in the folder "PluginConfigs". This functionality is not yet fully supported, but allows you to load a prepared pipeline to safe you time for loading plugins and parameter adjustment. During the startup of RITK the "default.xml" is loaded. If you want to have additional configuration files, you can load them from the menu "Plugins" $\rightarrow$ "Load Plugin Configuration".


%ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
\begin{figure}[b]
\begin{center}
\includegraphics[scale=0.6]{images/PluginCreator.jpg} %% update because of name
\end{center}
\caption{The Plugin Creator of RITK (future version).}
\label{fig_pluginCreator}
\end{figure}
%ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

%ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
\begin{figure}[b]
\begin{center}
\includegraphics[scale=0.5]{images/PluginManager.jpg}
\end{center}
\caption{The Plugin Manager of RITK.}
\label{fig_pluginManager}
\end{figure}
%ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

\bibliographystyle{alpha}

\bibliography{Tutorial}

\end{document}