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