]> Creatis software - bbtk.git/blob - kernel/doc/bbtkPackageDevelopersGuide/bbtkPackageDevelopersGuide.tex
the latex \def made in config.tex where not taken into account by tth (does tth parse...
[bbtk.git] / kernel / doc / bbtkPackageDevelopersGuide / bbtkPackageDevelopersGuide.tex
1 % ==========================================
2 \documentclass[11pt,final,a4paper]{article}
3 \input{config.tex}
4
5
6 \def\todo{\scriptsize\fbox{\bf TODO !!}\normalsize}
7 \def\x{\bm{x}}
8 \def\BBTK{{\xspace}The {\bf Black Box Toolkit} }
9 \def\bbtk{{\xspace}$\texttt{bbtk}$ }
10 \def\bbi{{\xspace}$\texttt{bbi}$ }
11 \def\bbStudio{{\xspace}$\texttt{bbStudio}$ }
12 \def\bbfy{{\xspace}$\texttt{bbfy}$ }
13 \def\bbdoc{{\xspace}$\texttt{bbdoc}$ }
14 \def\bbCreatePackage{{\xspace}$\texttt{bbCreatePackage}$ }
15
16 \def\bb{{\xspace}$\texttt{bb}$ }
17 %\def\bbp{{\xspace}$\texttt{bbp}$\xspace}
18
19 \def\cmake{{\xspace}$\texttt{cmake}$ }
20
21 \def\C{{\xspace}$\texttt{C}$ }
22 \def\CPP{{\xspace}$\texttt{C++}$ }
23
24 \def\xml{{\xspace}$\texttt{xml}$ }
25
26 \def\itk{{\xspace}$\texttt{itk}$ }
27 \def\vtk{{\xspace}$\texttt{vtk}$ }
28 \def\gdcm{{\xspace}$\texttt{gdcm}$ }
29 \def\gsmis{{\xspace}$\texttt{gsmis}$ }
30 \def\wx{{\xspace}$\texttt{wxWidgets}$ }
31
32 \def\lin{{\xspace}\textit{Linux} }
33 \def\win{{\xspace}\textit{Windows} }
34
35 % the same macros with no space at the end
36
37 \def\BBTKns{{\xspace}The {\bf Black Box Toolkit}}
38 \def\bbtkns{{\xspace}$\texttt{bbtk}$}
39 \def\bbins{{\xspace}$\texttt{bbi}$}
40 \def\bbfyns{{\xspace}$\texttt{bbfy}$}
41 \def\bbdocns{{\xspace}$\texttt{bbdoc}$}
42 \def\bbCreatePackagens{{\xspace}$\texttt{bbCreatePackage}$}
43
44 \def\bbns{{\xspace}$\texttt{bb}$}
45 %\def\bbp{{\xspace}$\texttt{bbp}$\xspace}
46
47 \def\cmakens{{\xspace}$\texttt{cmake}$}
48
49 \def\Cns{{\xspace}$\texttt{C}$}
50 \def\CPPns{{\xspace}$\texttt{C++}$}
51
52 \def\xmlns{{\xspace}$\texttt{xml}$}
53
54 \def\itkns{{\xspace}$\texttt{itk}$}
55 \def\vtkns{{\xspace}$\texttt{vtk}$}
56 \def\gdcmns{{\xspace}$\texttt{gdcm}$}
57 \def\gsmisns{{\xspace}$\texttt{gsmis}$}
58 \def\wxns{{\xspace}$\texttt{wxWidgets}$}
59
60 \def\linns{{\xspace}\textit{Linux}}
61 \def\winns{{\xspace}\textit{Windows}}
62
63
64 \begin{document}
65 \title{The Black Box Toolkit\\Package Developers' Guide}
66 \date{\today}
67 \author{Laurent Guigues}
68 \maketitle
69 % ==========================================
70 \tableofcontents
71 % ==========================================
72
73 \listoftables
74
75 \listoffigures
76
77 % ==========================================
78 %\section*{Abstract}
79 % ==========================================
80 \newpage
81 % ==========================================
82 % ==========================================
83 \vspace{0.5cm}\hrule
84 %\section{Creating your own black boxes}
85 %\label{bbp}
86 % ==========================================
87
88 % ==========================================
89 \section{Steps in the creation of new black boxes}
90 % ==========================================
91 Any black box must be included in a \bbtk package, 
92 that is in a particular shared library which can be loaded 
93 dynamically by \bbtk (hence applications which use \bbtk, 
94 such as the interpreter \bbi). 
95
96 \begin{enumerate}
97 \item \textbf{Create a new package. }
98 Before defining any black box you  
99 have to create a package, or more precisely  
100 the files which will allow you to generate the package 
101 (compile and link the shared library) and may be install it. 
102  \texttt{bbStudio} does it for you.
103  
104
105 Two cases occur :
106 \begin{itemize}
107 \item The black boxes you want to create are based on 
108 a processing code (\CPP classes or \C functions) which 
109 is in an existing project handled by \cmake
110 and you want the new package to be part of your existing project. 
111 You will have to create your new package into the source tree of your 
112 project. 
113 \item You do not have an already existing project (you want 
114 to create the new boxes from scratch) or you want/are imposed  
115 that the existing project remain external to the package project.
116 You will have to create your new package in a new location and 
117 may be include/link against existing libraries. 
118 \end{itemize}
119
120 \item \textbf{Describe your new box. }
121 You can do it either :
122 \begin{itemize}
123 \item In \CPP code. You will have to write the class for 
124 your box, mostly using \bbtk macros.  
125 \item In \xml code. 
126 When configuring your project with \cmake, 
127 the utility \bbfy will then generate the corresponding \CPP code. 
128 \end{itemize}
129
130 \end{enumerate}
131
132 % ==========================================
133 \section{Creating a new black box package}
134 % ==========================================
135
136 Run \texttt{bbStudio}.
137
138 You''l get something like in fig. \ref{bb-Studio}
139
140 \begin{figure}[!ht]
141 \caption{\label{bb-Studio} bbStudio}
142 \begin{center}
143 \includegraphics[width=0.6\textwidth]{bbStudio.png}
144 \end{center}
145 \end{figure}
146
147 Use the option \texttt{Create package} of the menu \texttt{Tools}.
148
149 You will be asked to choose the directory where you want to create the package,
150 then you'll get something like in fig. \ref{bbCreatePackage}. 
151
152
153 \begin{figure}[!ht]
154 \caption{\label{bbCreatePackage} Create Package}
155 \begin{center}
156 \includegraphics[width=0.6\textwidth]{bbCreatePackage.png}
157 \end{center}
158 \end{figure}
159
160
161 That will creates the directory structure and the \texttt{cmake} 
162 files necessary to build the project.
163
164 You must then decide the name of your new package. 
165 This name will be used to load the package in \texttt{bbi}.
166 Fill up the form like in fig. \ref{bbFillUpPackageForm}.
167
168
169 \begin{figure}[!ht]
170 \caption{\label{bbFillUpPackageForm} Fill up the form}
171 \begin{center}
172 \includegraphics[width=0.6\textwidth]{bbFillUpPackageForm.png}
173 \end{center}
174 \end{figure} 
175
176 Edit the file \texttt{MyPackage/CMakeLists.txt} to customize your package
177
178
179 the file tree obtained is :
180
181 \begin{verbatim}
182 >tree  myPackageFolder
183 myPackageFolder
184 `-- MyPackage
185     |-- CMakeLists.txt
186     |-- Configure.cmake
187     |-- PackageConfig.cmake.in
188     |-- README.txt
189     |-- UsePackage.cmake.in
190     |-- bbs
191     |   |-- CMakeLists.txt
192     |   |-- appli
193     |   |   `-- README.txt
194     |   `-- boxes
195     |       `-- README.txt
196     |-- data
197     |   `-- CMakeLists.txt
198     |-- doc
199     |   |-- CMakeLists.txt
200     |   |-- bbdoc
201     |   |   |-- CMakeLists.txt
202     |   |   `-- header.html.in
203     |   `-- doxygen
204     |       |-- CMakeLists.txt
205     |       |-- DoxyMainPage.txt.in
206     |       `-- Doxyfile.txt.in
207     `-- src
208         `-- CMakeLists.txt
209         
210 9 directories, 16 files
211 \end{verbatim}
212
213 The directory \texttt{MyPackage} is the directory of your new package, 
214 in which you will create the files describing your black boxes.
215 But first, you have to customize your new package, by editing the file 
216 \texttt{CMakeLists.txt} in the \texttt{MyPackage} directory.
217 This file contains :
218
219 \begin{file}{MyPackage/CMakeLists.txt}
220 \small
221 \begin{verbatim}
222 #===========================================================================
223 # CMAKE SETTINGS FOR BUILDING A BBTK PACKAGE
224 #===========================================================================
225
226 #===========================================================================
227 # THE NAME OF THE BBTK PACKAGE
228 SET(BBTK_PACKAGE_NAME MyPackage)
229 #===========================================================================
230
231 #===========================================================================
232 # IF IT IS A STANDALONE PROJECT UNCOMMENT NEXT LINE TO DECLARE YOUR PROJECT
233 # PROJECT(bb${BBTK_PACKAGE_NAME})
234 #===========================================================================
235
236 #===========================================================================
237 # PACKAGE AUTHOR
238 # !!! NO COMMA ALLOWED !!!
239 SET(${BBTK_PACKAGE_NAME}_AUTHOR "myself")
240 #===========================================================================
241
242 #===========================================================================
243 # PACKAGE DESCRIPTION
244 SET(${BBTK_PACKAGE_NAME}_DESCRIPTION "The kinkiest stuff you ve ever seen.")
245 #===========================================================================
246
247 #===========================================================================
248 # PACKAGE VERSION NUMBER 
249 SET(${BBTK_PACKAGE_NAME}_MAJOR_VERSION 1)
250 SET(${BBTK_PACKAGE_NAME}_MINOR_VERSION 0)
251 SET(${BBTK_PACKAGE_NAME}_BUILD_VERSION 0)
252 #===========================================================================
253
254 #===========================================================================
255 # UNCOMMENT EACH LIBRARY NEEDED (WILL BE FOUND AND USED AUTOMATICALLY)
256 # SET(${BBTK_PACKAGE_NAME}_USE_VTK  ON)
257 # SET(${BBTK_PACKAGE_NAME}_USE_ITK  ON)
258 # SET(${BBTK_PACKAGE_NAME}_USE_GDCM ON)
259 # SET(${BBTK_PACKAGE_NAME}_USE_GSMIS ON)
260 # SET(${BBTK_PACKAGE_NAME}_USE_WXWIDGETS ON)
261 #===========================================================================
262
263 #===========================================================================
264 # LIST HERE THE OTHER bbtk PACKAGES NEEDED
265 # (WILL BE FOUND AND USED AUTOMATICALLY)
266 SET(${BBTK_PACKAGE_NAME}_USE_PACKAGES 
267   # std
268   # wx
269   # itk
270   # vtk
271   # ...
272   )
273 #===========================================================================
274
275 #===========================================================================
276 # THE SOURCES OF THE PACKAGE
277 # EITHER UNCOMMENT NEXT LINE TO COMPILE ALL .cxx OF THE src DIRECTORY :
278 SET(${BBTK_PACKAGE_NAME}_COMPILE_ALL_CXX ON)
279 # ... OR LIST THE FILES TO COMPILE MANUALLY :
280 #SET(${BBTK_PACKAGE_NAME}_SOURCES
281 # LIST HERE THE FILES TO COMPILE TO BUILD THE LIB
282 # E.G. TO COMPILE "toto.cxx" ADD "toto" (NO EXTENSION)
283 # THE PATH MUST BE RELATIVE TO THE src FOLDER
284 #    )
285 #===========================================================================
286
287 #===========================================================================
288 # THE xml SOURCES OF THE PACKAGE
289 # EITHER UNCOMMENT NEXT LINE TO bbfy ALL .xml OF THE src DIRECTORY :
290 SET(${BBTK_PACKAGE_NAME}_COMPILE_ALL_XML ON)
291 # ... OR LIST THE FILES TO COMPILE MANUALLY :
292 #SET(${BBTK_PACKAGE_NAME}_XML_SOURCES
293 # LIST HERE THE FILES TO bbfy TO BUILD THE LIB
294 # E.G. TO bbfy "toto.xml" ADD "toto" (NO EXTENSION)
295 # THE PATH MUST BE RELATIVE TO THE src FOLDER
296 #    )
297 #===========================================================================
298
299 #===========================================================================
300 # THE SCRIPT-DEFINED BOXES OF THE PACKAGE (bbs)
301 # EITHER UNCOMMENT NEXT LINE TO INCLUDE ALL .bbs OF THE bbs/boxes DIRECTORY :
302 SET(${BBTK_PACKAGE_NAME}_INCLUDE_ALL_BBS_BOXES ON)
303 # ... OR LIST THE FILES TO INCLUDE MANUALLY :
304 # SET(${BBTK_PACKAGE_NAME}_BBS_BOXES
305 # LIST HERE THE bbs FILES TO INCLUDE 
306 # E.G. TO INCLUDE "boxes/bbtoto.bbs" ADD "boxes/bbtoto" (NO EXTENSION)
307 # !! THE PATH MUST BE RELATIVE TO THE bbs FOLDER !!
308 #)
309 #===========================================================================
310
311 #===========================================================================
312 # THE SCRIPT-DEFINED APPLICATIONS OF THE PACKAGE (bbs)
313 # EITHER UNCOMMENT NEXT LINE TO INCLUDE ALL .bbs OF THE bbs/appli DIRECTORY :
314 SET(${BBTK_PACKAGE_NAME}_INCLUDE_ALL_BBS_APPLI ON)
315 # ... OR LIST THE FILES TO INCLUDE MANUALLY :
316 # SET(${BBTK_PACKAGE_NAME}_BBS_APPLI
317 # LIST HERE THE bbs FILES TO INCLUDE 
318 # E.G. TO INCLUDE "appli/testToto.bbs" ADD "appli/testToto" (NO EXTENSION)
319 # !! THE PATH MUST BE RELATIVE TO THE bbs FOLDER !!
320 #)
321 #===========================================================================
322
323 #===========================================================================
324 SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS
325   # LIST HERE YOUR ADDITIONAL INCLUDE DIRECTORIES 
326   # EXCEPT :
327   #  - src
328   #  - bbtk dirs
329   #  - automatically handled libraries or packages : wx, vtk... (see above)
330   #  - the dirs automatically set by other libraries found by FIND_PACKAGE
331   )
332 #===========================================================================
333
334 #===========================================================================
335 SET(${BBTK_PACKAGE_NAME}_LIBS 
336   # LIST HERE THE ADDITIONAL LIBS TO LINK AGAINST
337   # EXCEPT : the same libs than for INCLUDE_DIRS 
338   )
339 #===========================================================================
340
341 #===========================================================================
342 # IF NEEDED : UNCOMMENT NEXT LINE 
343 # AND LIST ADDITIONNAL DIRECTORIES 
344 # IN WHICH TO LOOK FOR LIBRARIES TO LINK AGAINST
345 # LINK_DIRECTORIES()
346 #===========================================================================
347
348 #===========================================================================
349 # SET TO TRUE TO HAVE INFORMATION ON LIBRARIES FOUND DURING CMAKE CONFIGURE
350 SET(FIND_PACKAGE_VERBOSE TRUE)
351 #===========================================================================
352
353 #===========================================================================
354 # END OF USER SECTION
355 #===========================================================================
356
357 #===========================================================================
358 # Include configuration script
359 INCLUDE(Configure.cmake)
360 #===========================================================================
361
362 #===========================================================================
363 # EOF
364 #===========================================================================
365
366 \end{verbatim}
367 \end{file}
368
369 The comments in the file should be easily understandable !
370 You have to customize the lines which are enclosed 
371 between dashed comment lines.
372 In these sections, you can see some of the informations you supplied in previous step:
373 \begin{itemize}
374   \item The \textbf{name} of your package. This will be the name used to load it in \bbi. The shared library however will be called \texttt{bb}name hence on 
375     \lin the object file will be called \texttt{libbb}name\texttt{.so} 
376     and on \win it  will be called \texttt{bb}name\texttt{.dll}.
377   \item The \textbf{author(s)} of the package. Preferably provide e-mail adresses.
378   \item A \textbf{description} of the package, which will appear in the help of your package or in its html documentation automatically generated by \bbdoc.  
379 \end{itemize}
380
381 In these sections, you can set :
382 \begin{itemize}
383
384 \item The \textbf{libraries used} by the package : \vtk, \itk, \gdcm, \gsmis, \wx. The mecanisms to find these libraries, their sources and to link against them are automatically handled by the \cmake files installed by \bbCreatePackage. You just have to uncomment a line to use one of these libraries.
385
386 \item A \textbf{description} of the package, which will appear in the help of your package or in its html documentation automatically generated by \bbdoc.
387 \item The \textbf{version} of the package.
388 \item The \textbf{\xml sources} of the package : you can list each input \xml file explicitly or tell \cmake to include in the project \emph{all} the \xml files of the directory. 
389 \item The \textbf{\CPP sources} of the package : you can list each input \CPP file explicitly or tell \cmake to include in the project all the \CPP files of the directory.
390 \item \textbf{Additional include directories}. Set it if your package needs to include source files which are not in the package directory, typically if it depends on another library which is not one the libraries automatically handled (\vtk, \itk...).
391 \item \textbf{Additional libraries} to link against. Set it if your package needs to link against another library which is not one the libraries automatically handled (\vtk, \itk...).
392 \end{itemize}
393
394 Of course, this is only a framework and you can add any other \cmake commands
395 in the file.
396
397 % ==========================================
398 \section{Creating a new box}
399 % ==========================================
400
401 % ==========================================
402 \subsection{Principles}
403 % ==========================================
404
405 \subsubsection{\texttt{C++} or \texttt{XML} ?}
406 There are two ways to create a new black box in an existing package :
407 \begin{itemize}
408 \item Write an \xml description file which will be automatically 
409 translated in \CPP by the \bbfy application (recommanded).
410 \item Write the \CPP code of the box using \bbtk macros.
411 \end{itemize}
412
413 \subsubsection{From which \bbtk class inherit ?}
414
415 Apart from this choice of the description langage to use, 
416 there is an important choice to do concerning the implementation of the box. 
417 In \CPP, a black box is nothing but a class which has the standard 
418 interface of all black boxes : what's its name ? inputs ? outputs ? and so on. 
419
420
421 The abstract description of this interface is done in the class 
422 \texttt{bbtk::BlackBox} and is implemented in its child classes : 
423 \texttt{bbtk::AtomicBlackBox} and \texttt{bbtk::WxBlackBox} 
424 \footnote{all the classes of the \bbtk library are in a \emph{namespace} 
425 called \texttt{bbtk} 
426 and the \CPP header of a class called \texttt{NameOfAClass} is 
427 in the file called \texttt{bbtkNameOfAClass.h}}.
428 To create a new black box, you have to inherit one of these two  
429 concrete classes in order to inherit the black box interface and a 
430 particular implementation of this interface. 
431 If your black box is a \emph{Widget} black box, 
432 that is a black box which has (or is) 
433 a piece of a graphical interface based on the \wx library,
434 then it must inherit the class \texttt{bbtk::WxBlackBox}. 
435
436 Concretely, a \texttt{bbtk::WxBlackBox} is associated to
437 a \texttt{wxWindow} and must be able to return a pointer to it. 
438 If your black box is not a widget black box 
439 (that is : doesn't returns a pointer to a \emph{Widget}),
440  it must inherit from \texttt{bbtk::AtomicBlackBox}.
441
442 \subsubsection{Inherit or encapsulate ?}
443
444 Now, your black box will do something (hopefully !). 
445 When you decide to write a new black box, 
446 you should be in one of these three cases :
447 \begin{enumerate}
448 \item You already have a \texttt{C}-like function which 
449 does the processing that you wish to 'blackboxify'
450 \item You already have a \CPP class which 
451 does the processing that you wish to 'blackboxify'
452 \item You start from scratch without any existing code
453 \end{enumerate}
454
455 The idea of \BBTK is to embed processing codes into 
456 \CPP objects which have a standard and generic interface - 
457 namely black boxes - to be able to chain arbitrary 
458 processes afterwards. 
459
460 In \CPP, in order to embed an existing processing \emph{class}  
461 into a standard interface you only have two possibilities :
462 \begin{enumerate}
463 \item {\bf Inherit} the existing processing class 
464 \emph{and} the interface class (e.g. \texttt{bbtk::AtomicBlackBox}).
465 In this case you have to :
466 \begin{enumerate}
467 \item make the link between the inputs and outputs of the black box 
468 and the interface of the inherited class
469 \item call the processing 
470 method of the inherited class in the processing method of the black box.
471 \end{enumerate}
472 \item {\bf Encapsulate} the existing processing class 
473 in a class inherited from 
474 the interface class (e.g. \texttt{bbtk::AtomicBlackBox}).
475 In this case you have to :
476 \begin{enumerate}
477 \item declare it as a member of the black box, 
478 \item instantiate it at the right time 
479 (either in the constructor or in the processing method of the black box)
480 \item in the processing method of the black box : 
481 \begin{enumerate}
482 \item set the inputs of the member procesing class with the inputs of the black box, 
483 \item call the processing method of the encapsulated class  
484 \item set the ouputs of the black box with the outputs of the encapsulated 
485 class.
486 \end{enumerate}
487 \end{enumerate}
488 \end{enumerate}
489
490 If you wish to 'blackboxify' a C-like \emph{function}, 
491 you do not have the choice, you can only use the second mechanism, 
492 namely encapsulation.
493
494 Obviously, the inheritance mechanism is more powerfull 
495 and - when it is possible to use it - it demands less effort 
496 because, as we will see, in \bbtk you can directly 
497 link the accessors to the input and output data of the box 
498 to the accessors of the inherited processing class, 
499 as well as the procesing method of the black box 
500 to the processing method of the inherited processing class, 
501 very much like a callback mechanism.
502
503 \subsubsection{How to generate a Black Box skeleton}
504
505 Run \texttt{bbStudio}, choose \texttt{Tools} in the menu bar, option
506 \texttt{Create Black Box}.
507 You will be shown something like in fig. \ref{bbCreateBlackbox} :
508
509 \begin{figure}[!ht]
510 \caption{\label{bbCreateBlackbox}Create Black Box}
511 \begin{center}
512 \includegraphics[width=0.6\textwidth]{bbCreateBackbox.png}
513 \end{center}
514 \end{figure}
515
516
517 \subsubsection{Informations to provide}
518
519 Finally, to create a new black box, you will have to give :
520 \begin{enumerate}
521   \item The {\bf name} of the box
522   \item The {\bf package} to which the box belongs (can we do it automatically ? LG : think about it) 
523   \item The {\bf author}(s) of the box
524   \item A {\bf description} of the box
525
526  \item Its {\bf type}, either 
527    \begin{enumerate} 
528      \item  a standard one (\texttt{std-template})
529      \item a VTK Polydata Algorithm based box (\texttt{VTK\_PolydataAlgorithm-template}),    
530      \item  a VTK Image Algorithm based box (\texttt{VTK\_ImageaAlgorithm-template}),
531      \item  if it uses the wxWidget Library (\texttt{widget-template})
532    \end{enumerate}
533    
534   \item The output format of the file, either a C++ file or an XML file.
535
536   %\item $[$Optional$]$ The additional {\bf include files} which are necessary for the code to compile (classes or functions declarations ...)  
537   %\item $[$Optional$]$ The other {\bf parent(s)} of the box (which must be known hence their header included)
538   %\item $[$Optional$]$ The {\bf namespace} to which the box belongs
539   %\item The box {\bf inputs} and {\bf outputs}, and for each one :
540   %\begin{enumerate}
541   %\item Its {\bf name} : the string which will identify the input or output
542   %\item Its {\bf type} : any \CPP type, either a basic type or a user defined type (class ...) but which must be known, hence the necessary files must be included.  
543   %\item Its {\bf help} : a string describing the input / output 
544   %\end{enumerate}
545 %\item Its {\bf processing} code, which can be a simple callback or an arbitrary complex code
546 \end{enumerate}
547
548 WARNING:
549 Under Linux, for reasons we shall not discuss here, you'll get an error message :
550
551  \texttt{No such file or directory}
552  
553 Have a look at the console, you'll see a shell command (whose syntax is OK although there is is a lot of
554 quotes),something like :
555
556  \texttt{ "/usr/local/bin/bbCreateBlackBox"  "/home/jpr/Desktop/essai" MyPackage
557  myVtkPolydataBlackBox VTK-PolyDataAlgorithm C++  'author1, author2'  'myVtkPolydataBlackBox description'}
558
559  Just copy the command, and run it manually.
560
561 \subsubsection{Input and output accessors}
562
563 When you encapsulate a processing class or a C function 
564 or when you write down a black box from scratch, 
565 you must access the inputs and outputs of the black box, 
566 in order to interface it manually with your processing method 
567 or simply write your processing code 
568 (there are other cases in which you also need to access the 
569 inputs and outputs, we will talk about them later). 
570
571 The only thing you must know about the \CPP code generated 
572 from your \xml or your \CPP macro-based description 
573 is that when you declare an input 
574 or an output of a black box then 
575 two \emph{accessors} for this input or output are generated : 
576 one to \emph{get} the value of the input or output and 
577 one to \emph{set} it. 
578 These accessors have normalized names : 
579
580 \begin{itemize} 
581 \item The declaration of an {\bf input} called \texttt{NAME} and 
582 of type \texttt{TYPE} generates the two accessors
583 \footnote{For the sake of simplicity, the parameters and return value are 
584 shown here as if they were all passed by value. 
585 However the actual code can use references. 
586 The same way, the issue of const or non const methods is eluded here. 
587 Different cases occur in practice.}: 
588 \begin{itemize} 
589 \item \texttt{void bbSetInput<NAME>(<TYPE>);} 
590 \item \texttt{<TYPE> bbGetInput<NAME>();} 
591 \end{itemize}
592 \item The declaration of an {\bf output} called \texttt{NAME} and  
593 of type \texttt{TYPE} generates the two accessors:
594 \begin{itemize} 
595 \item \texttt{void bbSetOutput<NAME>(<TYPE>);} 
596 \item \texttt{<TYPE> bbGetOutput<NAME>();} 
597 \end{itemize}
598 \end{itemize}
599
600 For example, declaring an input called \texttt{Image} 
601 would generate the two accessors \texttt{bbSetInputImage} and 
602 \texttt{bbGetInputImage}. 
603
604 Note that 
605 \begin{itemize}
606 \item All \bbtk methods are prefixed by \texttt{bb} 
607 to avoid conflicts with potential inherited methods. 
608 \item An input and an output can have the same name (e.g. 'Image').
609 No conflict between accessors occur (e.g. 
610 four distinct accessors are created : 
611 \texttt{bbSetInputImage}, 
612 \texttt{bbGetInputImage}, 
613 \texttt{bbSetOutputImage} and 
614 \texttt{bbGetOutputImage}).
615 \end{itemize}
616
617 % ==========================================
618 \subsection{\texttt{XML} description of a box}
619 % ==========================================
620
621 % ==========================================
622 \subsubsection{General \texttt{xml} tags}
623 % ==========================================
624
625 Let us examine the \texttt{xml} file 
626 describing the \texttt{Add} box of the \texttt{std} package :
627
628 \begin{file}{\texttt{packages/std/src/bbAdd.xml}}
629 \small
630 \begin{verbatim}
631 <?xml version="1.0" encoding="iso-8859-1"?>
632
633 <blackbox name="Add">
634
635   <author>laurent.guigues@creatis.insa-lyon.fr </author>
636   <description>Adds its inputs                 </description>
637   <category>math                               </category>
638
639   <input name="In1"  type="double" description="First number to add"/>
640   <input name="In2"  type="double" description="Second number to add"/>
641   <output name="Out" type="double" description="Result"/>
642
643   <process><PRE>
644     bbSetOutputOut( bbGetInputIn1() + bbGetInputIn2() );
645   </PRE></process>
646   
647   <constructor><PRE>
648     bbSetInputIn1(0);
649     bbSetInputIn2(0);
650     bbSetOutputOut(0);
651   </PRE></constructor>    
652
653 </blackbox>
654 \end{verbatim}
655 \end{file}
656
657 The tags and their role are easily understandable.
658
659 As the box is not a widget, we inherit implicitely from 
660 \texttt{bbtk::AtomicBlackBox}.
661
662
663 The only part of the file which needs a bit of explaination is 
664 the body of the \texttt{process} tag, which describes the 
665 actual code to execute in the box. 
666 This code must be enclosed in a \texttt{<PRE></PRE>} tag 
667 to tell the \xml parser not to interpret it as \xml instructions. 
668 This is necessary to be able to use any symbol, 
669 like the \texttt{<} and \texttt{>} which have a 
670 special meaning in \xml. 
671 In the case of the \texttt{Add} box, the process code 
672 is very simple : remember that 
673 \texttt{bbGetInputIn1()} is the 
674 accessor to the input \texttt{In1} declared above and 
675 \texttt{bbGetInputIn2()} is the 
676 accessor to the input \texttt{In2};  
677 the code simply adds the values of the two inputs 
678 and sets the output \texttt{Out} with the resulting value.
679
680 To describe your own black boxes in \xml code, 
681 you must modify the xml file generated in previous step : 
682
683 \begin{enumerate}
684   \item Complete the description and author tags if you feel like.
685   \item add the \texttt{\#include} directives to be put in the generated \texttt{.h} file
686   \item Create your inputs and outputs
687   \item Fill in the process tag
688   \item Fill in the constructor tag
689   \item Fill in the copyconstructor tag
690   \item Fill in the destructor tag
691   \item Pray
692 \end{enumerate}
693
694
695 % ==========================================
696 \subsubsection{Specific \texttt{xml} tags for \texttt{itk::ImageToImageFilter} classes bbfication}
697 % ==========================================
698
699 % ==========================================
700 \subsubsection{Specific \texttt{xml} tags for \texttt{vtkImageAlgorithm} classes bbfication}
701 % ==========================================
702 \begin{verbatim}
703
704 <blackbox name="..." type="VTK\_ImageAlgorithm">
705
706 <vtkparent>the vtk ImageAlgorithm class it inherits from</vtkparent>
707 <input  name="..."  type="double"        special="vtk parameter" description="..."/>
708 <input name="..."   type="vtkImageData*" special="vtk output"    description="..."/>
709
710 <output  name="..." type="double"        special="vtk parameter" description="..."/>
711 <output name="..."  type="vtkImageData*" special="vtk output"    description="..."/>
712 \end{verbatim}
713 % ==========================================
714 \subsubsection{Specific \texttt{xml} tags for \texttt{vtkPolyDataAlgorithm} classes bbfication}
715 % ==========================================
716 \begin{verbatim}
717 <blackbox name="..." type="VTK\_PolyDataAlgorithm">
718
719 <vtkparent>the vtk Polydata class it inherits from</vtkparent>
720 <input  name="..."  type="double"       special="vtk parameter" description="..."/>
721 <input  name="..."  type="vtkPolyData*" special="vtk output"    description="..."/>
722
723 <output  name="..." type="double"       special="vtk parameter" description="..."/>
724 <output name="..."  type="vtkPolyData*" special="vtk output"    description="..."/>
725
726 \end{verbatim}
727 % ==========================================
728 \subsubsection{\bbfy \texttt{xml} tags reference}
729 % ==========================================
730
731   
732 % ==========================================
733 \begin{table}[!ht]
734 \caption{\label{xml_tags}
735 \bbfy \texttt{xml} tags reference}
736 \small
737 \begin{tabular}{|lcllm{6cm}|}
738 \hline
739 Tag & Attributes & Condition & Multiplicity & Description
740  \\ \hline
741
742 \texttt{<blackbox>} & \texttt{name} & - & 1 & The name of the box \\ \hline
743                 & \texttt{type} & - & 1 & The type of the box. In: 
744         \{\texttt{standard} (default), 
745 \texttt{ITK\_ImageToImageFilter},
746 \texttt{VTK\_ImageAlgorithm},
747 \texttt{VTK\_PolyDataAlgorithm}\} \\\hline
748 & \texttt{generic} & a) & 0-1 &
749 Generate the generic filter (see text)\\ \hline 
750
751 \texttt{<description>} & - & - & 0-n &  The description of the box. Multiple occurrence are concatenated \\\hline 
752 \texttt{<author>} & - & - & 0-n &  The author of the box. Multiple occurrence are concatenated \\\hline 
753 \texttt{<category>} & - & - & 0-1 &  The box category (if more than one, they are separated with commas) see Tab \ref{categories}\\\hline 
754 \texttt{<parentblackbox>} & - & - & 1 &  The parent black box of the box.
755 In: \{\texttt{bbtk::BlackBox, bbtk::WxBlackBox, bbtk::WxContainerBlackBox}\}\\\hline 
756 \texttt{<package>} & - & - & 1 &  The package of the box \\\hline 
757 \texttt{<namespace>} & - & - & 0-1 &  The namespace of the box. 
758 Use \texttt{bbPACKAGE}, where \texttt{PACKAGE} is the name of the package\\\hline 
759 \texttt{<include>} & - & - & 0-n & Additionnal file to include 
760 (generates : \texttt{\#include 'value'})\\\hline 
761
762 \texttt{<template>} & - & - & 0-n &  Template parameter of the box. The template parameter list is generated in the order of appearance of the tag. \\\hline 
763
764 \texttt{<itkparent>} &  - & a) &  1 & The parent itk class (with namespace) \\\hline
765
766 \texttt{<vtkparent>} &  - & b) &  1 & The parent vtk class \\\hline
767
768 \texttt{<input>} & \texttt{name} & - & 1 &  The name of the input \\\hline 
769          & \texttt{type} & - & 1 &  The type of the input \\\hline 
770          & \texttt{special} & - & 0-1 & In: \{\texttt{``itk input'', 
771 ``vtk input'', ``itk parameter'', ``vtk parameter''}\} (see below).\\\hline 
772          & \texttt{generic\_type} & c) & 0-1 & The ``generic'' type of the input (see text). \\\hline 
773 \texttt{<output>} & \texttt{name} & - & 1 &  The name of the output \\\hline 
774          & \texttt{type} & - & 1 &  The type of the output \\\hline 
775          & \texttt{special} & - & 0-1 & In: \{\texttt{``itk output'', 
776 ``vtk output''}\} (see below).\\\hline
777          & \texttt{generic\_type} & c) & 0-1 & The ``generic'' type  of the output (see text).\\\hline  
778          & \texttt{nature} & c) & 0-1 & The ``nature'' of the output (used for automatic GUI generation).\\\hline 
779
780 \texttt{<process>} & - & - & 0-1 & The code of the processing method of the box. Must be put between clear tags : \texttt{<PRE></PRE>} \\\hline 
781 \texttt{<constructor>} & - & - & 0-1 & The code of the user Constructor of the box (may contains default initialisations). Must be put between clear tags : \texttt{<PRE></PRE>} \\\hline 
782 \texttt{<copyconstructor>} & - & - & 0-1 & The code of the user Copy Constructor of the box . Must be put between clear tags : \texttt{<PRE></PRE>} \\\hline
783 \texttt{<destructor>} & - & - & 0-1 & The code of the user Destructor of the box. Must be put between clear tags : \texttt{<PRE></PRE>} \\\hline
784  \end{tabular}
785  \end{table}
786 % ==========================================
787 \begin{table}[!ht]
788 \caption{\label{xml_tags}
789 \bbfy \texttt{xml} tags conditions}
790 \small
791 \begin{tabular}{|ll|}
792 \hline
793 a) & \texttt{<blackbox type == ''ITK\_ImageToImageFilter''>} \\ \hline
794 b) & \texttt{<blackbox type == ''VTK\_ImageAlgorithm'' or ''VTK\_PolyDataAlgorithm''>} \\ \hline
795 c) & \texttt{<blackbox type == ''ITK\_ImageToImageFilter''>} and 
796      \texttt{<blackbox generic>} is present. \\ \hline
797 \end{tabular}
798 \end{table}
799
800 \begin{table}[!ht]
801 \caption{\label{basic_parent}}
802 \bbfy \texttt{Basic box parent}
803 \small
804 \begin{tabular}{|ll|}
805 \hline
806 \texttt{bbtk::WxBlackBox}b) & If the blackbox associated to
807 a \texttt{wxWindow} and is be able to return a pointer to it.... \\ \hline
808 \texttt{bbtk::AtomicBlackBox} & Any other blackbox that doesn't return a pointer to a \texttt{wxWindow}
809
810 \end{tabular}
811 \end{table}
812
813
814
815
816 % ==========================================
817 \begin{table}[!ht]
818 \caption{\label{categories}
819 \bbfy \texttt{Black Box} categories}
820 \small
821 \begin{tabular}{|ll|}
822 \hline
823  \texttt{Categ name}     & : Meaning                                          \\ \hline \\ \hline
824  \texttt{adaptor}        & : Adaptor box                                      \\ \hline
825  \texttt{application}    & : Final application, end user intended             \\ \hline
826  \texttt{atomic box}     & : System category.
827                Automatically assigned to Atomic Black Boxes (c++ defined)     \\ \hline
828  \texttt{complex box}    & : System category.
829                Automatically assigned to Complex Black Boxes (script defined) \\ \hline  
830  \texttt{command line}   & : Script which defines a command line application (no embedded GUI, but command line imput parameters) \\ \hline
831  \texttt{demo}           & : Demonstration                             \\ \hline
832  \texttt{devel}          & : Developer tool (bbCreatePackage.bbs, ...) \\ \hline
833  \texttt{dicom}          & : DICOM aware box \\ \hline 
834  \texttt{example}        & : Example script showing a box use-case      \\ \hline
835  \texttt{filter}         & : Image processing box                       \\ \hline
836  \texttt{image}          & : Image processing related box               \\ \hline
837  \texttt{interaction}    & :                                            \\ \hline
838  \texttt{math}           & : Mathematical operations\\ \hline
839  \texttt{mesh}           & : Mesh processing related box \\ \hline
840  \texttt{misc}           & : A box that cannot be put in other category ! \\ \hline
841  \texttt{read/write}     & : Box that read or write data from or to disk  \\ \hline
842  \texttt{viewer}         & : Box which displays some data \\ \hline
843  \texttt{widget}         & : Piece of graphical interface  \\ \hline 
844  
845  \texttt{3D object creator} & : Sophisticated 3D widget  \\ \hline  
846  \texttt{toolsbbtk}         & : Component of bbStudio    \\ \hline  
847 \end{tabular}
848 \end{table}
849
850
851 % ==========================================
852 \begin{table}[!ht]
853 \caption{\label{kinds}
854 \bbfy \texttt{Black Box} kinds}
855 \small
856 \begin{tabular}{|ll|}
857 \hline
858  \texttt{Kind}     &  Use as :     \\ \hline \\ \hline
859  \texttt{ADAPTOR} & \\ \hline
860  \texttt{DEFAULT\_ADAPTOR} & \\ \hline 
861  \texttt{WIDGET\_ADAPTOR} & \\ \hline 
862  \texttt{DEFAULT\_WIDGET\_ADAPTOR} & \\ \hline
863  \texttt{GUI} & \\ \hline 
864  \texttt{DEFAULT\_GUI} & \\ \hline 
865  \texttt{ALL} & If kind='ALL' then sets the level for all kinds\\ \hline  
866 \end{tabular}
867 \end{table}
868
869
870 % ==========================================
871 \begin{table}[!ht]
872 \caption{\label{nature}
873 \bbfy \texttt{nature}}
874 \small
875 \begin{tabular}{|ll|}
876 \hline
877  \texttt{Nature}     &   : used for    \\ \hline \\ \hline
878  
879  \texttt{file name} & Poping up a File Selector\\ \hline
880  \texttt{directory name} & Poping up a Directory Selector\\ \hline 
881  \texttt{file extension} & \\ \hline  
882  \texttt{colour} & Poping up a Colour Selector\\ \hline 
883  \texttt{pixel type} & \\ \hline 
884  \texttt{image dimension} & \\ \hline
885  \texttt{image index} & \\ \hline 
886  \texttt{image size} & \\ \hline 
887  \texttt{voxel size} & \\ \hline  
888 \end{tabular}
889 \end{table}
890
891 % ==========================================
892 \subsection{\CPP description of a box}
893 % ==========================================
894
895 Almost everything is performed usig macros.
896
897 For a quick start, the best you have to do is to run \texttt{bbStudio}, then in the menu \texttt{Tools}, choose the item
898  \texttt{Create blackbox}, click on \texttt{C++}, and have a look to the generated files.
899  
900 % ==========================================
901 \subsubsection{\texttt{.h} description of a box}
902 % ========================================== 
903  \begin{itemize}
904     \item  \texttt{namespace} : your package name.
905     \item \texttt{class} : the name of your box
906     \item \texttt{public inheritance} : 
907       \begin{itemize}
908          \item{bbtk::WxBlackBox}
909             Your Black Box is intended to return a wxWidget, able to be included into an other one (you choosed
910             \texttt{widget-template} for \texttt{Type of the blackbox} )
911          \item{bbtk::AtomicBlackBox}
912             Your Black box is any processig box (std, ITK or VTK based)
913          \item{any processing class} (ITK, VTK, ...) your box inherits.  
914       \end{itemize}      
915     \item \texttt{BBTK\_BLACK\_BOX\_INTERFACE} : (yourBoxName, the list of the classes it inherits from, VTK Parent -if any-).
916     Yes, we know it's redundant with previous point... That's why we allow you to describe your class in xml format!
917     \item \texttt{bbUserConstructor} declaration of your own callback function, that will be called in the box constructor method
918     \item \texttt{bbUserCopyConstructor} declaration of your own callback function, that will be called in the box copy constructor method 
919     \item \texttt{bbUserDestructor} declaration of your own callback function, that will be called in the box destructor method
920     \item \texttt{BBTK\_DECLARE\_INPUT} : input parameter name (as it will appear to the users of your black box),
921                                         C++ type of the parameter (e.g. double, std::string, vtkImageData*, ...) 
922     \item \texttt{BBTK\_DECLARE\_OUTPUT} : output parameter name (as it will appear to the users of your black box),
923                                         C++ type of the parameter (e.g. double, std::string, vtkImageData*, ...
924     \item \texttt{BBTK\_DECLARE\_VTK\_INPUT}  Declares a vtkAlgorithm-inherited AtomicBlackBox input
925     \item \texttt{BBTK\_DECLARE\_VTK\_OUTPUT} Declares a vtkAlgorithm-inherited AtomicBlackBox output                                                                                   
926     \item \texttt{BBTK\_DECLARE\_VTK\_PARAM} Declares an AtomicBlackBox input corresponding to an inherited vtk parameter 
927      (you know, the ones that are declared by vtkSetMacro/vtkGetMacro). Its name must be the same than the vtk parameter name                           
928     \item \texttt{BBTK\_DECLARE\_VTK\_IMAGE\_ALGORITHM\_INPUT}     Declares a vtkImageAlgorithm-inherited    AtomicBlackBox input
929     \item \texttt{BBTK\_DECLARE\_VTK\_POLY\_DATA\_ALGORITHM\_INPUT} Declares a vtkPolyDataAlgorithm-inherited AtomicBlackBox input                                      
930     \item \texttt{BBTK\_PROCESS}   Defines the default bbUserProcess method for vtk inherited black boxes (actually : calls vtkParent::Update)
931                                                                                
932     \item \texttt{BBTK\_BEGIN\_DESCRIBE\_BLACK\_BOX}  : 
933     (yourBoxName,  \texttt{bbtk::WxBlackBox} or \texttt{bbtk::AtomicBlackBox} depending on what you
934     black box inherits from).
935     Yes, we know it's redundant with public inheritance ... That's why we allow you to describe your class in xml format! 
936     All the following items will be used in the Help interface; describe them carefully (i.e. in a Human understandable way!).
937     \item \texttt{BBTK\_NAME} : the name of your box 
938     \item \texttt{BBTK\_AUTHOR} : author name (better you put e-mail adress)
939     \item \texttt{BBTK\_DESCRIPTION} : brief description of what does the box
940     \item \texttt{BBTK\_CATEGORY} :box category  (see table \ref{categories})
941     \item \texttt{BBTK\_INPUT} for each one of the input parameters, you have to supply : 
942        \begin{itemize}
943          \item The current Blackbox name.
944          \item The parameter name
945          \item A brief description of what the parameter is used for.
946          \item The C++ type of the parameter (e.g. double, std::string, vtkImageData*, ...) 
947          \item The nature of the parameter (see table \ref{nature}) if you wish  your box may be used by automatic GUI generator.
948          Supply an empty string ("") if you don't care.          
949        \end{itemize}
950     \item \texttt{ BBTK\_OUTPUT} for each one of the output parameters, you have to supply :
951        \begin{itemize}
952          \item The current Blackbox name.
953          \item The parameter name
954          \item A brief description of what the parameter is used for.
955          \item The C++ type of the parameter (e.g. double, std::string, vtkImageData*, ...) 
956        \end{itemize} 
957     \item \texttt{BBTK\_END\_DESCRIBE\_BLACK\_BOX} : means the torture is (almost) over.        
958  \end{itemize}
959 % ==========================================
960 \subsubsection{\texttt{.cxx} description of a box}
961 % ========================================== 
962  \begin{itemize}
963     \item  \texttt{BBTK\_ADD\_BLACK\_BOX\_TO\_PACKAGE} : (Package name, Blackbox name)
964     \item  \texttt{BBTK\_BLACK\_BOX\_IMPLEMENTATION} : (Blackbox name, Blackbox basic parent \\ (bbtk::AtomicBlackBox/ bbtk::WxBlackBox)see :\label{basic_parent}
965     \item  \texttt{Process} :definition of your own callback function, that will be called in the box  method. \\ At least, you'll write here the default initialisation of the outputs
966     \item  \texttt{UserConstructor} :  definition of your own callback function, that will be called in the box constructor method. \\
967                                        At least, you'll write here the default initialisation of the inputs (to avoid unpredictable behaviour if user forgets to
968                                        Set/Connect any Input).  
969     \item  \texttt{UserCopyConstructor} : definition of your own callback function, that will be called in the box copy constructor method
970     \item  \texttt{UserDestructor} :  definition of your own callback function, that will be called in the box destructor method      
971  \end{itemize}
972  
973  
974  
975  %\bibliography{all}
976
977
978
979 %\section{Conclusion}
980 \end{document}
981