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