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