]> Creatis software - bbtk.git/blob - kernel/doc/bbtkPackageDevelopersGuide/bbtkPackageDevelopersGuide.tex
#3202 BBTK Feature New Normal - fast algorithm for ImageBoundaries box
[bbtk.git] / kernel / doc / bbtkPackageDevelopersGuide / bbtkPackageDevelopersGuide.tex
1 % # ---------------------------------------------------------------------
2 % #
3 % # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 % #                        pour la SantÈ)
5 % # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 % # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 % # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 % #
9 % #  This software is governed by the CeCILL-B license under French law and
10 % #  abiding by the rules of distribution of free software. You can  use,
11 % #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 % #  license as circulated by CEA, CNRS and INRIA at the following URL
13 % #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 % #  or in the file LICENSE.txt.
15 % #
16 % #  As a counterpart to the access to the source code and  rights to copy,
17 % #  modify and redistribute granted by the license, users are provided only
18 % #  with a limited warranty  and the software's author,  the holder of the
19 % #  economic rights,  and the successive licensors  have only  limited
20 % #  liability.
21 % #
22 % #  The fact that you are presently reading this means that you have had
23 % #  knowledge of the CeCILL-B license and that you accept its terms.
24 % # ------------------------------------------------------------------------ */
25 %
26
27
28
29 % ==========================================
30 \documentclass[11pt,final,a4paper]{article}
31 \input config.tex
32 \begin{document}
33 \bbtkGuide[Package Developers' Guide]
34 \newpage
35 % ==========================================
36
37
38
39
40 % ==========================================
41 \section{Introduction}
42 % ==========================================
43
44 This guide describes how to 
45 create new \bbtk packages and black boxes. 
46 How to use them is described in \bbtk Users' guide. 
47
48 Any black box must be included in a \bbtk package, 
49 that is in a particular shared library that can be loaded 
50 dynamically by \bbtkns, either in \CPP code or in \bbs scripts 
51 with the commands \texttt{include} or \texttt{load}.
52 The steps to create new boxes are thus:
53
54 \begin{enumerate}
55         \item \textbf{Create a new package. }
56         This process (see section \ref{CreatePackage}), consists of two steps:
57         \begin{enumerate}
58                 \item Generation of the project structure by use of \bbCreatePackage utility that creates both the
59                  directories tree (for sources, documentation, etc.) and configuration files (particularly \texttt{CMakelists}). See section
60                  \ref{sec:bbCreatePackage-files}.
61                 \item Customization of the \texttt{CMakelists}. See section \ref{RootCMakeLists}.
62         \end{enumerate}
63         \item \textbf{Describe your new box.} This is explained in section \ref{CreateBlackBox}.
64         You can do it either:
65         \begin{itemize}
66                 \item In \xml code. You will mainly have to customize an \xml skeleton automatically generated by \bbCreateBlackBox utility.
67                 See section \ref{sec:XML-box}.
68                 When configuring your project with \cmakens, 
69                 the utility \bbfy will then automatically generate the corresponding \CPP code. 
70                 \item In \CPP code. You will have to write the class for 
71                 your box, mostly using \bbtk macros. See section \ref{sec:CPP-box}. 
72         \end{itemize}
73         \item \textbf{Configure your project with \cmakens.} See section \ref{sec:CMake}.
74         \item \textbf{Compile your project.} See section \ref{sec:compile}.
75         \item \textbf{Plug the new package} if you use  \bbStudio See section \ref{sec:plugin}.
76 \end{enumerate}
77
78 % ==========================================
79 \section{Creating a new package}
80 \label{CreatePackage}
81 % ==========================================
82
83 % ==========================================
84 \subsection{Creating the file tree}
85 \label{sec:bbCreatePackage-files}
86 % ==========================================
87 Before defining any black box you  
88 have to create a package, or more precisely  
89 the source files that will allow you to generate the package 
90 (compile and link the shared library) and maybe install it. 
91 The \bbtk command-line application \bbCreatePackage 
92 allows to create the basic file architecture 
93 to start the development of a new black box package.
94 Type \bbCreatePackage in a console to get its usage:
95 \begin{verbatim}
96 bbCreatePackage <package-path> <package-name> [author] [description]
97 \end{verbatim}
98
99 In \bbStudio you can run this application via a graphical interface, by use of the menu \texttt{Tools $>$ Create Package}. 
100 In both cases (using the command-line tool or \bbStudio interface), 
101 you have to choose: 
102
103 \begin{itemize}
104 \item The {\bf directory} of your new package. 
105 Two cases occur:
106 \begin{itemize}
107 \item The black boxes you want to create are based on 
108 a processing code (\CPP classes or \C functions), which 
109 is in an existing project handled by \cmake
110 and you want the new package to be part of your existing project. 
111 You will have to create your new package within the source tree of your 
112 project and add a \texttt{ADD_SUBDIRECTORY} command in the \texttt{CMakeLists.txt} 
113 file of the parent directory of your package.
114 \item You do not have an already existing project (you want 
115 to create the new boxes from scratch) or you want/are imposed  
116 that the existing project remain external to the package project.
117 You will have to create your new package in a new location and 
118 maybe include/link against existing libraries. 
119 \end{itemize}
120
121 \item The {\bf name} of your new package. 
122 This name will be used to load the package in \CPP and \bbs scripts.
123 \end{itemize}
124
125 You must also provide the \texttt{author} list 
126 and a \texttt{description} which will be used for your package documentation.
127
128 After running \bbCreatePackage or clicking 'Run' in \bbStudio interface 
129 you should get a file structure like this (Linux users can verify it with the \texttt{tree} command):
130 \begin{verbatim}
131     NEW_PACKAGE
132     |-- CMakeLists.txt
133     |-- Configure.cmake
134     |-- PackageConfig.cmake.in
135     |-- README.txt
136     |-- UsePackage.cmake.in
137     |-- bbs
138     |   |-- CMakeLists.txt
139     |   |-- appli
140     |   |   `-- README.txt
141     |   `-- boxes
142     |       `-- README.txt
143     |-- data
144     |   `-- CMakeLists.txt
145     |-- doc
146     |   |-- CMakeLists.txt
147     |   |-- bbdoc
148     |   |   |-- CMakeLists.txt
149     |   |   `-- header.html.in
150     |   `-- doxygen
151     |       |-- CMakeLists.txt
152     |       |-- DoxyMainPage.txt.in
153     |       `-- Doxyfile.txt.in
154     `-- src
155         `-- CMakeLists.txt
156 \end{verbatim}
157
158 You can then:
159 \begin{itemize}
160 \item Edit the root \texttt{CMakeLists.txt} file to customize your package build settings (see section \ref{RootCMakeLists})
161
162 \item Put your \CPP/\xml boxes sources in '\texttt{src}' subdirectory (see section \ref{CreateBlackBox}).
163  
164   Please use the convention: If the name of your package is \texttt{Pack} and the name of your box is \texttt{Box} then name the source files \texttt{bbPackBox.\{h;cxx;xml\}}. Note that this is automatically done when using the \bbCreateBlackBox utility.
165
166 \item Put your script-defined boxes (complex boxes) in '\texttt{bbs/boxes}' subdirectory. 
167
168   Please use the convention: If the name of your box is '\texttt{Box}' then call the file '\texttt{bbBox.bbs}' to let others know that the script defines a complex black box type.
169
170 \item Put your script-defined applications in '\texttt{bbs/appli}' subdirectory. 
171
172   Please use the convention: Do {\bf not} prefix '\texttt{bb}' to the files.
173
174 \item Put your data in '\texttt{data}' subdirectory. 
175 Any data put there will be installed and accessible in your scripts. The box 
176 \texttt{std::PrependPackageDataPath} provides the package data path.
177
178
179 \item Customize the header of your package \texttt{html} doc. To do so, you have to edit the file '\texttt{doc/bbdoc/header.html.in}' either with an \texttt{html} editor or by use of a text editor (directly editing the \texttt{html} code). You can include images or links to other \texttt{html} pages. The images and pages must be put in the folder '\texttt{doc/bbdoc}' and will be properly installed. The same way, you can link to these images or pages in your boxes descriptions without giving any path. If you create subdirs for your material then you have to install the materials yourself by editing the \texttt{CMakeLists.txt} and links must use paths relative to '\texttt{doc/bbdoc}'.
180
181 \item Customize the main page of your \texttt{doxygen} doc. To do so, you have to edit the file '\texttt{doc/doxygen/DoxyMainPage.txt.in}'.
182 \end{itemize}
183
184 \subsection{Configuring the root \texttt{CMakeLists.txt}}
185 \label{RootCMakeLists}
186
187 \texttt{CMake} is a family of tools designed to build, test and package software (\url{http://www.cmake.org/}). It is used to control the software compilation process using platform- and compiler-independent configuration files. \texttt{CMake} generates native makefiles and workspaces that can be used in the compiler environment of your choice. To do this, each branch of your project directory tree contains an appropriate \texttt{CMakeLists.txt} file. These files have been filled-up, so as to minimize your effort. Normally, you only have to edit the file \texttt{CMakeLists.txt} in the package root directory, in order to configure your new package build settings.
188 The listing of this file is given below. Hopefully, the comments in the file are easy to understand!
189
190 \begin{file}{CMakeLists.txt}
191 \small
192 \begin{verbatim}
193 #==========================================================================
194 # CMAKE SETTINGS FOR BUILDING A BBTK PACKAGE
195 #==========================================================================
196
197 #==========================================================================
198 # THE NAME OF THE BBTK PACKAGE
199 SET(BBTK_PACKAGE_NAME MyPackage)
200 #==========================================================================
201
202 #==========================================================================
203 # IF IT IS A STANDALONE PROJECT UNCOMMENT NEXT LINE TO DECLARE YOUR PROJECT
204 # PROJECT(bb${BBTK_PACKAGE_NAME})
205 #==========================================================================
206
207 #==========================================================================
208 # PACKAGE AUTHOR
209 # !!! NO COMMA ALLOWED !!!
210 SET(${BBTK_PACKAGE_NAME}_AUTHOR "myself")
211 #==========================================================================
212
213 #==========================================================================
214 # PACKAGE DESCRIPTION
215 SET(${BBTK_PACKAGE_NAME}_DESCRIPTION "My super package does nothing yet")
216 #==========================================================================
217
218 #==========================================================================
219 # PACKAGE VERSION NUMBER 
220 SET(${BBTK_PACKAGE_NAME}_MAJOR_VERSION 1)
221 SET(${BBTK_PACKAGE_NAME}_MINOR_VERSION 0)
222 SET(${BBTK_PACKAGE_NAME}_BUILD_VERSION 0)
223 #==========================================================================
224
225 #==========================================================================
226 # UNCOMMENT EACH LIBRARY NEEDED (WILL BE FOUND AND USED AUTOMATICALLY)
227 # SET(${BBTK_PACKAGE_NAME}_USE_VTK  ON)
228 # SET(${BBTK_PACKAGE_NAME}_USE_ITK  ON)
229 # SET(${BBTK_PACKAGE_NAME}_USE_GDCM ON)
230 # SET(${BBTK_PACKAGE_NAME}_USE_GSMIS ON)
231 # SET(${BBTK_PACKAGE_NAME}_USE_WXWIDGETS ON)
232 #==========================================================================
233
234 #==========================================================================
235 # LIST HERE THE OTHER bbtk PACKAGES NEEDED
236 # (WILL BE FOUND AND USED AUTOMATICALLY)
237 SET(${BBTK_PACKAGE_NAME}_USE_PACKAGES 
238   # std
239   # wx
240   # itk
241   # vtk
242   # ...
243   )
244 #==========================================================================
245
246 #==========================================================================
247 # THE SOURCES OF THE PACKAGE
248 # EITHER UNCOMMENT NEXT LINE TO COMPILE ALL .cxx OF THE src DIRECTORY :
249 SET(${BBTK_PACKAGE_NAME}_COMPILE_ALL_CXX ON)
250 # ... OR LIST THE FILES TO COMPILE MANUALLY :
251 #SET(${BBTK_PACKAGE_NAME}_SOURCES
252 # LIST HERE THE FILES TO COMPILE TO BUILD THE LIB
253 # E.G. TO COMPILE "toto.cxx" ADD "toto" (NO EXTENSION)
254 # THE PATH MUST BE RELATIVE TO THE src FOLDER
255 #    )
256 #==========================================================================
257
258 #==========================================================================
259 # THE xml SOURCES OF THE PACKAGE
260 # EITHER UNCOMMENT NEXT LINE TO bbfy ALL .xml OF THE src DIRECTORY :
261 SET(${BBTK_PACKAGE_NAME}_COMPILE_ALL_XML ON)
262 # ... OR LIST THE FILES TO COMPILE MANUALLY :
263 #SET(${BBTK_PACKAGE_NAME}_XML_SOURCES
264 # LIST HERE THE FILES TO bbfy TO BUILD THE LIB
265 # E.G. TO bbfy "toto.xml" ADD "toto" (NO EXTENSION)
266 # THE PATH MUST BE RELATIVE TO THE src FOLDER
267 #    )
268 #==========================================================================
269
270 #==========================================================================
271 # THE SCRIPT-DEFINED BOXES OF THE PACKAGE (bbs)
272 # EITHER UNCOMMENT NEXT LINE TO INCLUDE ALL .bbs OF THE bbs/boxes DIRECTORY:
273 SET(${BBTK_PACKAGE_NAME}_INCLUDE_ALL_BBS_BOXES ON)
274 # ... OR LIST THE FILES TO INCLUDE MANUALLY :
275 # SET(${BBTK_PACKAGE_NAME}_BBS_BOXES
276 # LIST HERE THE bbs FILES TO INCLUDE 
277 # E.G. TO INCLUDE "boxes/bbtoto.bbs" ADD "boxes/bbtoto" (NO EXTENSION)
278 # !! THE PATH MUST BE RELATIVE TO THE bbs FOLDER !!
279 #)
280 #==========================================================================
281
282 #==========================================================================
283 # THE SCRIPT-DEFINED APPLICATIONS OF THE PACKAGE (bbs)
284 # EITHER UNCOMMENT NEXT LINE TO INCLUDE ALL .bbs OF THE bbs/appli DIRECTORY:
285 SET(${BBTK_PACKAGE_NAME}_INCLUDE_ALL_BBS_APPLI ON)
286 # ... OR LIST THE FILES TO INCLUDE MANUALLY :
287 # SET(${BBTK_PACKAGE_NAME}_BBS_APPLI
288 # LIST HERE THE bbs FILES TO INCLUDE 
289 # E.G. TO INCLUDE "appli/testToto.bbs" ADD "appli/testToto" (NO EXTENSION)
290 # !! THE PATH MUST BE RELATIVE TO THE bbs FOLDER !!
291 #)
292 #==========================================================================
293
294 #==========================================================================
295 SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS
296   # LIST HERE YOUR ADDITIONAL INCLUDE DIRECTORIES 
297   # EXCEPT :
298   #  - src
299   #  - bbtk dirs
300   #  - automatically handled libraries or packages: wx, vtk... (see above)
301   #  - the dirs automatically set by other libraries found by FIND_PACKAGE
302   )
303 #==========================================================================
304
305 #==========================================================================
306 SET(${BBTK_PACKAGE_NAME}_LIBS 
307   # LIST HERE THE ADDITIONAL LIBS TO LINK AGAINST
308   # EXCEPT : the same libs than for INCLUDE_DIRS 
309   )
310 #==========================================================================
311
312 #==========================================================================
313 # IF NEEDED : UNCOMMENT NEXT LINE 
314 # AND LIST ADDITIONNAL DIRECTORIES 
315 # IN WHICH TO LOOK FOR LIBRARIES TO LINK AGAINST
316 # LINK_DIRECTORIES()
317 #==========================================================================
318
319 #==========================================================================
320 # SET TO TRUE TO HAVE INFORMATION ON LIBRARIES FOUND DURING CMAKE CONFIGURE
321 SET(FIND_PACKAGE_VERBOSE TRUE)
322 #==========================================================================
323
324 #==========================================================================
325 # END OF USER SECTION
326 #==========================================================================
327
328 #==========================================================================
329 # Include configuration script
330 INCLUDE(Configure.cmake)
331 #==========================================================================
332
333 #==========================================================================
334 # EOF
335 #==========================================================================
336
337 \end{verbatim}
338 \end{file}
339
340 You can see in the file some of the informations you supplied  when running the  \bbCreatePackage utility:
341 \begin{itemize}
342   \item The \textbf{name} of your package. This will be the name used to load it in \bbins. The shared library however will be called \texttt{bb}name hence on 
343     \lin the object file will be called \texttt{libbb}name\texttt{.so} 
344     and on \win it  will be called \texttt{bb}name\texttt{.dll}.
345   \item The \textbf{author(s)} of the package. Preferably provide e-mail addresses.
346   \item A \textbf{description} of the package, which will appear in the help of your package or in its html documentation automatically generated by \bbtkns.  
347 \end{itemize}
348
349 You can additionally set:
350 \begin{itemize}
351 \item The \textbf{version} of the package.
352
353 \item The \textbf{libraries} that will be used by the package. The mechanisms to find these libraries, their sources and to link against them are automatically handled by the \cmake files installed by \bbCreatePackagens. You just have to uncomment a line to use one of these libraries: \vtkns, \itkns, \gdcmns, \gsmisns, \wxns.
354 \item The \textbf{core \bbtk packages} that will be used by the package as \CPP libraries
355 (if you need to use the black boxes of these packages in your \CPP code, 
356 i.e. include some header and link with the library). 
357 The mechanisms to find these libraries, 
358 their sources and to link against them are automatically handled 
359 by the \cmake files installed by \bbCreatePackagens. 
360 You just have to uncomment a line to use one of these libraries.
361
362 \item The \textbf{\CPP sources} of the package: you can list each input \CPP 
363 file explicitly or tell \cmake to include in the project all the \CPP files 
364 of the 'src' directory (default). To do this, you have to comment/uncomment appropriate lines in the file. Be careful with lines containing the opening and closing parentheses.
365
366 \item The \textbf{\xml sources} of the package: you can list each input \xml
367 file explicitly or tell \cmake to include in the project all the \xml files 
368 of the 'src' directory (default). Here you also have to be careful when commenting/uncommenting lines with opening and closing parentheses.
369
370 \item The \textbf{boxes \bbs sources} of the package: you can list each 
371 input \bbs
372 file explicitly or tell \cmake to include in the project \emph{all} 
373 the \bbs files of the 'bbs/boxes' directory (default, recommended). Here you also have to be careful when commenting/uncommenting lines with opening and closing parentheses.
374
375 \item The \textbf{appli \bbs sources} of the package: 
376 you can list each input \bbs
377 file explicitly or tell \cmake to include in the project \emph{all} 
378 the \bbs files of the 'bbs/appli' directory (default, recommended). Here you also have to be careful when commenting/uncommenting lines with opening and closing parentheses.
379
380 \item \textbf{Additional include directories}. Set it if your package needs to include source files that are not in the package directory, typically if it depends on another library that is not one of the libraries automatically handled (\vtkns, \itkns...) and that you did not find with the 
381 \texttt{FIND\_PACKAGE} mechanism of \cmakens.
382
383 \item \textbf{Additional libraries} to link against. Set it if your package needs to link against another library that is not one of the libraries automatically handled (\vtkns, \itkns...) and that you did not find with the 
384 \texttt{FIND\_PACKAGE} mechanism of \cmakens.
385
386 \item \textbf{Additional link directories} in which to find libraries not 
387 automatically handled and that you did not find with the 
388 \texttt{FIND\_PACKAGE} mechanism of \cmakens. 
389
390 \end{itemize}
391
392 Of course, this is only a framework and you can add any other \cmake commands
393 in the file.
394
395 % ==========================================
396 \section{Creating a new box}
397 \label{CreateBlackBox}
398 % ==========================================
399
400 % ==========================================
401 \subsection{Principles}
402 % ==========================================
403
404 % ==========================================
405 \subsubsection{\texttt{C++} or \texttt{XML}?}
406 % ==========================================
407 There are two ways to create a new black box in an existing package:
408 \begin{itemize}
409 \item Write an \xml description file that will be automatically 
410 translated into \CPP by the \bbfy application during build (recommended).
411 \item Write the \CPP code of the box using \bbtk macros.
412 \end{itemize}
413
414 % ==========================================
415 \subsubsection{From which \bbtk class inherit?}
416 % ==========================================
417
418 Apart from the choice of the description language to be used, 
419 there is an important choice to make concerning the implementation of the box. 
420 In \CPPns, a black box is nothing but a class that has the standard 
421 interface of all black boxes, giving access to its name, inputs, outputs, and so on. 
422
423 The abstract description of this interface is done in the class 
424 \texttt{bbtk::BlackBox} of the \bbtk library 
425 and is implemented in its children classes: 
426 \texttt{bbtk::AtomicBlackBox} and \texttt{bbtk::WxBlackBox} 
427 \footnote{all the classes of the \bbtk library are in a \emph{namespace} 
428 called \texttt{bbtk} 
429 and the \CPP header of a class called \texttt{NameOfAClass} is 
430 in the file called \texttt{bbtkNameOfAClass.h}}.
431
432 To create a new black box, you have to inherit from one of these two  
433 actual classes in order to inherit the black box interface and a 
434 particular implementation of this interface. 
435
436 If your black box is a \emph{Widget} black box, 
437 that is a black box that has (or is) 
438 a piece of a graphical interface based on the \wx library,
439 then it must inherit from the class \texttt{bbtk::WxBlackBox}. 
440
441 Concretely, a \texttt{bbtk::WxBlackBox} is associated to 
442 a \texttt{wxWindow} and must be able to return a pointer to it. 
443 If your black box is not a widget black box 
444 (that is: does not return a pointer to a \texttt{wxWindow}),
445  it must inherit from \texttt{bbtk::AtomicBlackBox}.
446  
447 NOTE: \emph{modal dialogs} 
448 that are created and destroyed at the end of the process 
449 method of the box are NOT \texttt{WxBlackBoxes}: 
450 they do not return a \texttt{wxWindow}, 
451 see the code of \texttt{wx::FileSelector} for example.
452
453 % ==========================================
454 \subsubsection{Inherit or encapsulate?}
455 % ==========================================
456
457 Now, your black box will do something (hopefully!). 
458 When you decide to write a new black box, 
459 you should be in one of these three cases :
460 \begin{enumerate}
461 \item You already have a \texttt{C}-like function that 
462 does the processing and that you wish to 'blackboxify' ('bbfy' in short).
463 \item You already have a \CPP class that 
464 does the processing and that you wish to 'bbfy'
465 \item You start from scratch without any existing code
466 \end{enumerate}
467
468 The idea of \BBTK is to embed processing codes into 
469 \CPP objects that have a standard and generic interface - 
470 namely black boxes - to be able to chain arbitrary 
471 processes afterwards. 
472
473 In \CPPns, in order to embed an existing processing \emph{class}  
474 into a standard interface you only have two possibilities:
475 \begin{enumerate}
476 \item {\bf Inherit} from the interface class (e.g. \texttt{bbtk::AtomicBlackBox})
477 \emph{and} from the existing processing class.
478 In this case you have to:
479 \begin{enumerate}
480 \item make the link between the inputs and outputs of the black box 
481 and the interface of the inherited class
482 \item call the processing 
483 method of the inherited class in the processing method of the black box.
484 \end{enumerate}
485 \item {\bf Encapsulate} the existing processing class 
486 in a class inherited from 
487 the interface class (e.g. \texttt{bbtk::AtomicBlackBox}).
488 In this case you have to:
489 \begin{enumerate}
490 \item declare an instance of the processing class 
491 as a member of the black box, 
492 \item instantiate it at the right time 
493 (either in the constructor or in the processing method of the black box)
494 \item in the processing method of the black box : 
495 \begin{enumerate}
496 \item set the inputs of the member processing class with the inputs of the black box, 
497 \item call the processing method of the encapsulated class  
498 \item set the ouputs of the black box with the outputs of the encapsulated 
499 class.
500 \end{enumerate}
501 \end{enumerate}
502 \end{enumerate}
503
504 If you wish to 'bbfy' a C-like \emph{function}, 
505 you do not have the choice, you can only use the second mechanism, 
506 namely encapsulation.
507
508 Obviously, the inheritance mechanism is more powerful 
509 and - when it is possible to use it - it demands less effort. 
510 Indeed, as we will see, in \bbtk you can directly 
511 link the accessors to the input and output data of the box 
512 to the accessors of the inherited processing class, 
513 as well as the processing method of the black box 
514 to the processing method of the inherited processing class, 
515 very much like a callback mechanism.
516 %\itk and \vtk classes 
517
518 % ==========================================
519 \subsubsection{Input and output accessors}
520 % ==========================================
521
522 When you encapsulate a processing class or a C function 
523 or when you write down a black box from scratch, 
524 you must access the inputs and outputs of the black box, 
525 in order to interface it manually with your processing method 
526 or simply write your processing code 
527 (there are other cases in which you also need to access the 
528 inputs and outputs, we will talk about them later). 
529
530 The only thing you must know about the \CPP code generated 
531 from your \xml or your \CPP macro-based description 
532 is that when you declare an input 
533 or an output of a black box then 
534 two \emph{accessors} for this input or output are generated : 
535 one to \emph{get} the value of the input or output and 
536 one to \emph{set} it. 
537 These accessors have normalized names: 
538
539 \begin{itemize} 
540 \item The declaration of an {\bf input} called \texttt{NAME} and 
541 of type \texttt{TYPE} generates the two accessors
542 \footnote{For the sake of simplicity, the parameters and return value are 
543 shown here as if they were all passed by value. 
544 However the actual code can use references. 
545 The same way, the issue of const or non const methods is eluded here. 
546 Different cases occur in practice.}: 
547 \begin{itemize} 
548 \item \texttt{void bbSetInput<NAME>(<TYPE>);} 
549 \item \texttt{<TYPE> bbGetInput<NAME>();} 
550 \end{itemize}
551 \item The declaration of an {\bf output} called \texttt{NAME} and  
552 of type \texttt{TYPE} generates the two accessors:
553 \begin{itemize} 
554 \item \texttt{void bbSetOutput<NAME>(<TYPE>);} 
555 \item \texttt{<TYPE> bbGetOutput<NAME>();} 
556 \end{itemize}
557 \end{itemize}
558
559 For example, declaring an input called \texttt{Image} 
560 would generate the two accessors \texttt{bbSetInputImage} and 
561 \texttt{bbGetInputImage}. 
562
563 Note that:
564 \begin{itemize}
565 \item All \bbtk methods are prefixed by \texttt{bb} 
566 to avoid conflicts with potential inherited methods. 
567 \item An input and an output can have the same name (e.g. 'Image') and no conflict between accessors occurs, since
568 four distinct accessors are created, as follows: 
569 \texttt{bbSetInputImage}, 
570 \texttt{bbGetInputImage}, 
571 \texttt{bbSetOutputImage}, 
572 \texttt{bbGetOutputImage}.
573 \end{itemize}
574
575
576 % ==========================================
577 \subsection{Generate the black box skeleton}
578 % ==========================================
579
580 The command line application \bbCreateBlackBox 
581 allows to create a skeleton \CPP or \xml files for a new black box. 
582 It has a rather complex usage, 
583 we recommend you use the graphical interface to it 
584 which is accessible with \bbStudio menu \texttt{Tools $>$ Create black box}.
585 You will first be prompted to choose the location for the new black box, which should be the \texttt{src} directory of your package sources tree.
586 Then the actual interface will appear, which looks like in fig. \ref{bbCreateBlackBox}.
587
588 \begin{figure}[!ht]
589 \caption{\label{bbCreateBlackBox}Create Black Box interface}
590 \begin{center}
591 \includegraphics[width=0.6\textwidth]{bbCreateBackBox.png}
592 \end{center}
593 \end{figure}
594
595 You will have to give:
596 \begin{enumerate}
597   \item The {\bf name} of the box.
598   \item The {\bf package} to which the box belongs. Caution! You may not make a mistake, otherwise you will be unable to carry out the final build of your project.
599   \item The {\bf author}(s) of the box.
600   \item A {\bf description} of the box.
601
602  \item Its {\bf type}, which is one of the following: 
603    \begin{enumerate} 
604      \item  \emph{Basic}, has no particular Input/Output, inherits from \texttt{AtomicBlackBox};
605      \item  \emph{Widget}, has an output \texttt{Widget}, type \texttt{wxWindow*}, inherits from \texttt{WxBlackBox};
606      \item \emph{VTK PolyDataAlgorithm}, has standard vtk Inputs/Outputs, inherits from \texttt{AtomicBlackBox} and from \texttt{vtkPolyDataAlgorithm};
607      \item \emph{VTK ImageAlgorithm}, has standard vtk Inputs/Outputs, inherits from \texttt{AtomicBlackBox} and from \texttt{vtkImageAlgorithm}.
608
609    \end{enumerate}
610    
611   \item The output format of the file, either a C++ file or an XML file.
612 \end{enumerate}
613
614 % ==========================================
615 \subsection{\texttt{XML} description of a box}
616 \label{sec:XML-box}
617 % ==========================================
618
619 % ==========================================
620 \subsubsection{General \texttt{xml} tags}
621 % ==========================================
622
623 Let us examine the \texttt{xml} file 
624 describing the \texttt{Add} box of the \texttt{std} package:
625
626 \begin{file}{\texttt{packages/std/src/bbAdd.xml}}
627 \small
628 \begin{verbatim}
629 <?xml version="1.0" encoding="iso-8859-1"?>
630
631 <blackbox name="Add">
632
633   <author>laurent.guigues@creatis.insa-lyon.fr </author>
634   <description>Adds its inputs                 </description>
635   <category>math                               </category>
636
637   <input name="In1"  type="double" description="First number to add"/>
638   <input name="In2"  type="double" description="Second number to add"/>
639   <output name="Out" type="double" description="Result"/>
640
641   <process><PRE>
642     bbSetOutputOut( bbGetInputIn1() + bbGetInputIn2() );
643   </PRE></process>
644   
645   <constructor><PRE>
646     bbSetInputIn1(0);
647     bbSetInputIn2(0);
648     bbSetOutputOut(0);
649   </PRE></constructor>    
650
651 </blackbox>
652 \end{verbatim}
653 \end{file}
654
655 As the box is not a widget, it implicitly inherits from 
656 \texttt{bbtk::AtomicBlackBox} (the default).
657
658 The tags and their role are (hopefully) easily understandable.
659 The only part of the file, which needs a bit of explanation, is 
660 the body of the \texttt{process} tag, which describes the 
661 actual code to execute in the box. 
662 This code must be enclosed in a \texttt{<PRE></PRE>} tag 
663 to tell the \xml parser not to interpret it as \xml instructions. 
664 Thus we will be able to use such symbols as \texttt{<} and \texttt{>}, which have a 
665 special meaning in \xmlns. 
666
667 In the case of the \texttt{Add} box, the process code 
668 is very simple. Remember that 
669 \texttt{bbGetInputIn1()} and 
670 \texttt{bbGetInputIn2()} respectively are the 
671 accessors to the inputs \texttt{In1} and \texttt{In2} declared above;  
672 the code simply adds the values of the two inputs 
673 and sets the output \texttt{Out} with the resulting value.
674
675 Note that the afore cited code of the \texttt{Add} box was cleaned so as to only contain the necessary lines.
676 The actual \xml file generated by \bbCreateBlackBox utility is more complete. 
677 It contains many comments to guide you, it already includes the informations you provided when running the \bbCreateBlackBoxns, and it looks like this:
678
679 \begin{file}{\texttt{MyPackage/bbMyPackageMyBox.xml}}
680 \small
681 \begin{verbatim}
682 <!--=======================================================================
683    STARTS THE DESCRIPTION OF THE BLACK BOX -->
684 <blackbox name="MyBox">
685 <!--====================================================================-->
686
687   <!--=====================================================================
688     THE BOX DOCUMENTATION -->
689
690   <author>myself</author>
691   <description>no idea of what it can do</description>
692   <category>__CATEGORY__</category>
693   <!--==================================================================-->
694
695   <!--=====================================================================
696     #include directives to be put in the .h generated
697     There must be one tag per file to include
698     Here we include the standard header iostream.h -->
699   <include><PRE>iostream</PRE></include>
700   <!--==================================================================-->
701
702   <!--=====================================================================
703     INPUTS/OUTPUTS DECLARATION -->
704   <!-- Declares an input with name 'In', type 'double' 
705       and description 'First input' -->
706
707   <input name="In" type="double" description="First input"/>
708   
709   <!-- Declares an output with name 'Out', type 'double' 
710       and description 'First output' -->
711   <output name="Out" type="double" description="First output"/>
712   <!--==================================================================-->
713
714   <!--=====================================================================
715     THE PROCESSING METHOD BODY :
716     Here simply copies the value of the input 'In' to the output 'Out'
717     And prints out the value
718     INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
719       void bbSet{Input|Output}NAME(const TYPE&)
720       const TYPE& bbGet{Input|Output}NAME() const 
721     Where :
722     * NAME is the name of the input/output
723       (the one provided in the attribute 'name' of the tag 'input')
724     * TYPE is the C++ type of the input/output
725       (the one provided in the attribute 'type' of the tag 'input')     -->
726
727   <process>
728   <PRE>
729     bbSetOutputOut( bbGetInputIn() );
730     std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
731   </PRE>
732   </process>
733   <!--==================================================================-->
734
735   <!--=====================================================================
736     CONSTRUCTORS / DESTRUCTORS (OPTIONAL) 
737     THE CONSTRUCTION METHOD BODY :
738     Here initializes the input 'In' to 0
739     This is also where you should allocate the output pointers -->
740   <constructor>
741   <PRE>
742     bbSetInputIn(0);
743   </PRE>
744   </constructor>
745
746   <!-- THE COPY-CONSTRUCTION METHOD BODY :
747     Here does nothing 
748     But this is where you should allocate the output pointers if any
749     and copy the pointed values (to avoid bug caused by multiple refs)  -->
750   <copyconstructor>
751   <PRE>
752   </PRE>
753   </copyconstructor>
754
755   <!-- THE DESTRUCTION METHOD BODY :
756     Here does nothing 
757     but this is where you should desallocate the output pointers if any -->
758   <destructor>
759   <PRE>
760   </PRE>
761   </destructor>
762   <!--==================================================================-->
763
764 <!--====================================================================-->
765 <!-- END OF BLACK BOX DESCRIPTION -->
766 </blackbox>
767 <!--====================================================================-->
768 <!--====================================================================-->
769 <!--====================================================================-->
770 <!--====================================================================-->
771 \end{verbatim}
772 \end{file}
773
774 To describe your own black box in \xml code, 
775 you have to modify this \xml file as follows: 
776
777 \begin{enumerate}
778   \item Complete the category, description and author tags if you feel like.
779   \item Add the \texttt{\#include} directives to be put in the generated \texttt{.h} file (the example given in the \xml file includes the standard \texttt{iostream} header; depending on the actual file to be included, you will have to put or omit the \texttt{.h} extension).
780   \item Create your inputs and outputs
781   \item Fill in the process tag
782   \item Fill in the constructor tag
783   \item Fill in the copyconstructor tag
784   \item Fill in the destructor tag
785 \end{enumerate}
786
787
788
789 % ==========================================
790 \subsubsection{Writing new widget boxes in \xml}
791 % ==========================================
792 See the example \texttt{packages/wx/src/bbwxOutputText.xml}
793
794 \begin{file}{\texttt{packages/wx/src/bbwxOutputText.xml}}
795 \small
796 \begin{verbatim}
797 <blackbox name="OutputText" widget>
798
799   <author>laurent.guigues at creatis.insa-lyon.fr</author>
800   <description>Text zone to be inserted into a window (wxStaticText)
801                                                              </description>
802   <category></category>
803
804   <input name="Title" type="std::string" 
805                                  description="Title prefixed to the text"/>
806   <input name="In" type="std::string" description="Text"/>
807
808   <createwidget><PRE>
809    bbSetOutputWidget( new wxStaticText ( bbGetWxParent() , -1 , _T("") ) );
810    Process();
811   </PRE></createwidget>
812  
813   <process><PRE>
814    std::string msg;
815     if (bbGetInputTitle()!="")
816       {
817         msg = bbGetInputTitle()+": " + bbGetInputIn();
818       }  
819     else 
820       {
821         msg = bbGetInputIn();
822       }
823    ((wxStaticText*)bbGetOutputWidget())->SetLabel( bbtk::std2wx( msg ) ); 
824   </PRE></process>
825   
826   <constructor><PRE> 
827     bbSetInputIn("");
828     bbSetInputTitle("");
829   </PRE></constructor>    
830
831 </blackbox>
832 \end{verbatim}
833 \end{file}
834
835 Explanations:
836 \begin{itemize}
837         \item The attribute \texttt{widget} of the \texttt{blackbox} tag instructs 
838                 \bbfy that the box inherits from \texttt{bbtk::WxBlackBox}.
839         \item An output called \texttt{'Widget'} of type \texttt{wxWindow*} is 
840                 automatically declared (you do not have to do it).
841         \item The tag \texttt{createwidget} provides the body of the method which creates the widget. 
842                 At the end of this method the output \texttt{'Widget'} must 
843                 have been set with the newly created \texttt{wxWindow}. 
844                 Here we create a new \texttt{wxStaticText}.
845                 The parent of the widget to create MUST BE the one provided by the method 
846                 \texttt{bbGetWxParent()} which returns a \texttt{wxWindow*}. 
847                 To update the static text after creation we simply call the \texttt{Process} 
848                 method.
849         \item The body of the \texttt{process} method simply concatenates the 
850                 input \texttt{'Title'} (if non empty) and the input \texttt{'In'} and 
851                 updates the \texttt{wxStaticText}. 
852                 Remark that to get it, we use the \texttt{bbGetOutputWidget()} method 
853                 which returns a \texttt{wxWindow*} which we cast into a 
854                 \texttt{wxStaticText*} to use its specific method \texttt{SetLabel}.
855 \end{itemize}
856
857 More complex examples can be found in the \texttt{package/wx/src} folder.
858
859 % ==========================================
860 \subsubsection{Specific \texttt{xml} tags for \texttt{vtkImageAlgorithm} classes bbfication by inheritance}
861 \label{sec:Specific-VTK}
862 % ==========================================
863 To 'bbfy' \texttt{vtkImageAlgorithm} classes such as \texttt{vtkImageAnisotropicDiffusion3D},  
864 we recommend you the use of \xmlns. You can have a look at the examples 
865 in the \vtk core package 'src' folder. 
866 The bbfication mechanism is inheritance. In the \xml file you have to add:
867
868 \begin{itemize}
869 \item the attribute \texttt{type="VTK\_ImageAlgorithm"} 
870         to the \texttt{blackbox} tag:
871         \begin{verbatim}
872                 <blackbox name="..." type="VTK_ImageAlgorithm">
873         \end{verbatim}
874
875 \item the tag \texttt{vtkparent} which gives the \vtk parent of the box, e.g.:
876         \begin{verbatim}
877                 <vtkparent> vtkImageAnisotropicDiffusion3D </vtkparent>
878         \end{verbatim}
879
880 \item an \texttt{include} tag to include the appropriate \vtk parent header, such as:
881         \begin{verbatim}
882                 <include> vtkImageAnisotropicDiffusion3D.h </include> 
883         \end{verbatim}
884 \end{itemize}
885
886 The \vtk algorithm inputs/ouputs are wrapped directly using the 
887 \texttt{special} attributes of the \texttt{input} and \texttt{output} tags. 
888 A typical example is:
889 \begin{verbatim}
890 <input name="In"   type="vtkImageData*" special="vtk input" 
891        description="Input image"/>
892 <output name="Out"  type="vtkImageData*" special="vtk output"    
893         description="Output image"/>
894 \end{verbatim}
895 In this example, the attribute \texttt{special="vtk input"} of the input 'In' definition 
896 directly connects it to the input of the vtk object the box inherits. 
897 No additional code is needed, the vtk object will directly receive 
898 the value of this input. 
899 The same mechanism holds for the output.
900
901 Similarly, the attribute \texttt{special="vtk parameter"} of the \texttt{input} tag permits to directly 
902 wrap the parameters of the vtk object, which are declared using 
903 \texttt{vtkSetMacro} and \texttt{vtkGetMacro}, e.g.:
904 \begin{verbatim}
905 <input name="DiffusionThreshold" type="double" special="vtk parameter" 
906         description="Difference threshold that stops diffusion"/>
907 \end{verbatim}
908 Here, the attribute \texttt{special="vtk parameter"} 
909 of the input \texttt{DiffusionThreshold} instructs \bbfy to call the \texttt{SetDiffusionThreshold} and 
910 \texttt{GetDiffusionThreshold} 
911 methods of the \vtk parent, when needed. 
912
913 {\bf NOTE:} 
914 For this mechanism to work, 
915 the name of the \bbtk input MUST be the same as the name 
916 of the \vtk parent parameter. 
917
918 No \texttt{process} method has to be given, 
919 \bbfy generates a process body for you, which simply calls the 
920 \texttt{Update()} method of the \vtk parent.
921
922 {\bf NOTE:}
923 You can write your own \texttt{process} code which will overload 
924 the default. Don't forget to call \texttt{Update()}. 
925 See \texttt{packages/vtk/src/bbvtkConeSource.xml} for an example.
926
927 % ==========================================
928 \subsubsection{Specific \texttt{xml} tags for \texttt{vtkPolyDataAlgorithm} classes bbfication by inheritance}
929 % ==========================================
930 To bbfy \texttt{vtkPolyDataAlgorithm} classes such as \texttt{vtkConeSource},  
931 we also recommend the use of \xml (you can have a look at the examples 
932 in the \vtk core package 'src' folder). 
933 The bbfication mechanism is inheritance. 
934 You have to use the same \xml tags and attributes as for wrapping a 
935 \texttt{vtkImageAlgorithm} (see above): 
936
937 \begin{verbatim}
938 <blackbox name="..." type="VTK_PolyDataAlgorithm">
939
940 <vtkparent>the vtk Polydata class it inherits from</vtkparent>
941 <input  name="..."  type="vtkPolyData*" special="vtk input"    
942         description="..."/>
943 <output name="..."  type="vtkPolyData*" special="vtk output"    
944         description="..."/>
945 <input  name="..."  type="double"       special="vtk parameter" 
946         description="..."/>
947 \end{verbatim}
948
949 % ==========================================
950 \subsubsection{Specific \texttt{xml} tags for \texttt{itk::ImageToImageFilter} classes bbfication by inheritance}
951 \label{sec:Specific-ITK}
952 % ==========================================
953
954 to be written...
955
956 \newpage
957
958 % ==========================================
959 \subsubsection{\bbfy \texttt{xml} tags reference}
960 % ==========================================
961
962 % See tables \ref{xml_tags}, \ref{xml_tags2}
963 % ==========================================
964 \begin{table}[!ht]
965 \caption{\label{xml_tags}
966 \bbfy \texttt{xml} tags reference (part 1). \emph{'Cond' stands for 'Condition' (see Tab.\ref{xml_tags-conditions}), while 'Mult' stands for 'Multiplicity'}}
967 \small
968 \begin{tabular}{|lcllm{5.7cm}|}
969 \hline
970 Tag & Attributes & Cond & Mult & Description \\ \hline
971
972 \texttt{<blackbox>} & \texttt{name} & - & 1 & The name of the box \\ \cline{5-5}
973                 & \texttt{type} & - & 1 & The type of the box, belongs to: 
974                 
975                                                         \{\texttt{standard} (default), 
976         
977                                                         \texttt{ITK\_ImageToImageFilter},
978                                                         \texttt{VTK\_ImageAlgorithm},
979                                                         \texttt{VTK\_PolyDataAlgorithm}\} \\ \cline{5-5}
980                 & \texttt{generic} & a) & 0-1 & Generate the generic filter (see text)\\ \cline{5-5} 
981                 & \texttt{widget} & - & 1 & If present then the box inherits from \texttt{WxBlackBox}, otherwise it inherits from  \texttt{AtomicBlackBox} \\ \hline 
982 \texttt{<description>} & - & - & 0-n &  The description of the box. Multiple occurrences are concatenated \\ \hline 
983 \texttt{<author>} & - & - & 0-n &  The author of the box. Multiple occurrences are concatenated \\ \hline 
984 \texttt{<category>} & - & - & 0-1 &  Categories the box belongs to (see Tab.~\ref{categories}), separated by semi-colons \\ \hline 
985 \texttt{<namespace>} & - & - & 0-1 &  The namespace of the box, use \texttt{bb\emph{PACKAGE}}, where \texttt{\emph{PACKAGE}} is the name of the package\\ \hline 
986 \texttt{<include>} & - & - & 0-n & Additional file to include, generates \texttt{\#include \emph{filename}}\\ \hline 
987 \texttt{<itkparent>} &  - & a) &  1 & The parent \itk class (with namespace) \\ \hline
988 \texttt{<vtkparent>} &  - & b) &  1 & The parent \vtk class \\ \hline
989 \texttt{<input>} & \texttt{name} & - & 1 &  The name of the input \\ \cline{5-5} 
990          & \texttt{type} & - & 1 &  The type of the input \\ \cline{5-5} 
991          & \texttt{special} & - & 0-1 & Directly wraps either of the following: \{\texttt{vtk input, vtk parameter, itk input, itk parameter}\}, see sections \ref{sec:Specific-VTK} and \ref{sec:Specific-ITK}.\\ \cline{5-5} 
992          & \texttt{generic\_type} & c) & 0-1 & The ``generic'' type of the input (see text). \\ \hline 
993  \texttt{<output>} & \texttt{name} & - & 1 &  The name of the output \\ \cline{5-5} 
994          & \texttt{type} & - & 1 &  The type of the output \\ \cline{5-5} 
995          & \texttt{special} & - & 0-1 & Directly wraps either of the following: \{\texttt{itk output, vtk output}\}, see sections \ref{sec:Specific-VTK} and \ref{sec:Specific-ITK}.\\ \cline{5-5}
996          & \texttt{generic\_type} & c) & 0-1 & The ``generic'' type  of the output (see text).\\ \cline{5-5}  
997          & \texttt{nature} & c) & 0-1 & The ``nature'' of the output (used for automatic GUI generation).\\\hline 
998 \end{tabular}
999 \end{table}
1000
1001 \begin{table}[!ht]
1002 \caption{\label{xml_tags2}
1003 \bbfy \texttt{xml} tags reference (part 2). \emph{'Cond' stands for 'Condition' (see Tab.\ref{xml_tags-conditions}), while 'Mult' stands for 'Multiplicity'}}
1004 \small
1005 \begin{tabular}{|lcllm{5.5cm}|}
1006 \hline
1007 Tag & Attributes & Cond & Mult & Description\\ \hline
1008 \texttt{<template>} & - & - & 0-n &  Template parameter of the box. The template parameter list is generated in the order of appearance of the tag. \\ \hline 
1009 \texttt{<process>} & - & - & 0-1 & The code of the processing method of the box. Must be put between clear tags: \texttt{<PRE></PRE>} \\ \hline 
1010 \texttt{<createwidget>} & - & d) & 0-1 & The code of the widget creation method of the box. Must be put between clear tags: \texttt{<PRE></PRE>} \\ \hline 
1011 \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 
1012 \texttt{<copyconstructor>} & - & - & 0-1 & The code of the user Copy Constructor of the box. Must be put between clear tags: \texttt{<PRE></PRE>} \\ \hline
1013 \texttt{<destructor>} & - & - & 0-1 & The code of the user Destructor of the box. Must be put between clear tags: \texttt{<PRE></PRE>} \\ \hline
1014 \end{tabular}
1015 \end{table}
1016  
1017 %\newpage
1018  
1019 % ==========================================
1020 \begin{table}[!ht]
1021 \caption{\label{xml_tags-conditions}
1022 \bbfy \texttt{xml} tags conditions}
1023 \begin{centering}
1024 \small
1025 \begin{tabular}{|ll|}
1026 \hline
1027 a) & \texttt{<blackbox type == 'ITK\_ImageToImageFilter'>} \\ \hline
1028 b) & \texttt{<blackbox type == 'VTK\_ImageAlgorithm'} \texttt{or 'VTK\_PolyDataAlgorithm'>} \\ \hline
1029 c) & \texttt{<blackbox type == 'ITK\_ImageToImageFilter'>} \\
1030 \multicolumn{2}{|r|}{and \texttt{<blackbox generic>} is present.} \\ \hline
1031 d) & \texttt{<blackbox widget>} is present \\ \hline
1032 \end{tabular}
1033
1034 \end{centering}
1035 \end{table}
1036
1037 %\begin{table}[!ht]
1038 %\caption{\label{basic_parent}}
1039 %\bbfy \texttt{Basic box parent}
1040 %\small
1041 %\begin{tabular}{|ll|}
1042 %\hline
1043 %\texttt{bbtk::WxBlackBox}b) & If the blackbox associated to
1044 %a \texttt{wxWindow} and is be able to return a pointer to it.... \\ \hline
1045 %\texttt{bbtk::AtomicBlackBox} & Any other blackbox that doesn't return a pointer to a \texttt{wxWindow}%
1046 %\end{tabular}
1047 %\end{table}
1048
1049
1050
1051
1052 % ==========================================
1053 \begin{table}[!ht]
1054 \caption{\label{categories} \texttt{Black Box} categories}
1055 \small
1056 \begin{tabular}{|p{4cm}p{8cm}|}
1057 \hline
1058  \texttt{Category name}     & : Meaning                                          \\ \hline 
1059 & \\ \hline
1060  \texttt{adaptor}        & : Adaptor box                                      \\ \hline
1061  \texttt{application}    & : Final application, end user intended             \\ \hline
1062  \texttt{atomic box}     & : System category.
1063                Automatically assigned to (\CPP defined) Atomic Black Boxes     \\ \hline
1064  \texttt{complex box}    & : System category.
1065                Automatically assigned to (script defined) Complex Black Boxes \\ \hline  
1066  \texttt{command line}   & : Script that defines an application without embedded GUI, but with command-line input parameters) \\ \hline
1067  \texttt{demo}           & : Demonstration                             \\ \hline
1068  %\texttt{devel}          & : Developer tool (bbCreatePackage.bbs, ...) \\ \hline
1069  \texttt{dicom}          & : DICOM aware box \\ \hline 
1070  \texttt{example}        & : Example script showing a box use-case      \\ \hline
1071  \texttt{filter}         & : Filtering box                       \\ \hline
1072  \texttt{image}          & : Image processing related box               \\ \hline
1073 % \texttt{interaction}    & :                                            \\ \hline
1074  \texttt{math}           & : Mathematical operations\\ \hline
1075  \texttt{mesh}           & : Mesh processing related box \\ \hline
1076  \texttt{misc}           & : A box that cannot be put in other category ! \\ \hline
1077  \texttt{read/write}     & : Box that read or write data from or to disk  \\ \hline
1078  \texttt{viewer}         & : Box which displays some data \\ \hline
1079  \texttt{widget}         & : Piece of graphical interface  \\ \hline 
1080  
1081  \texttt{3D object creator} & : Sophisticated 3D widget  \\ \hline  
1082  \texttt{toolsbbtk}         & : \bbtk development tools such as \\
1083                                                                                                                 & GUICreatePackage, GUICreateBlackBox, etc.   \\ \hline  
1084 \end{tabular}
1085 \end{table}
1086
1087
1088 % ==========================================
1089 \begin{table}[!ht]
1090 \caption{\label{kinds}\texttt{Black box} kinds. The notion of 'kind' corresponds to special black boxes that are automatically added to the user-defined pipeline} 
1091 \small
1092 \begin{tabular}{|p{4cm}p{8cm}|}
1093 \hline
1094  \texttt{Kind}     &   Description    \\ \hline & \\ \hline
1095  \texttt{ADAPTOR} & black box that carries out a type-conversion (cast), so that a connection between an output and an input can be properly made \\ \hline
1096  \texttt{DEFAULT\_ADAPTOR} & indicates the preferred one, if several boxes can carry out the same type-conversion\\ \hline 
1097  \texttt{GUI} & black box usable by the \texttt{newgui} command that tries to automatically assign a graphical interface according to the input types\\ \hline 
1098  \texttt{DEFAULT\_GUI} & indicates the preferred one, if several boxes can provide the expected features\\ \hline 
1099 \end{tabular}
1100 \end{table}
1101
1102
1103 % ==========================================
1104 \begin{table}[!ht]
1105 \caption{\label{nature}Input/output \texttt{natures}}
1106 \small
1107 \begin{tabular}{|p{4cm}p{8cm}|}
1108 \hline
1109  \texttt{Nature}     &   : Associated \texttt{DEFAULT\_GUI} box   \\ \hline 
1110 & \\ \hline
1111
1112  \texttt{'file name'} & \texttt{wx::FileSelector}\\ \hline
1113  \texttt{'directory name'} & \texttt{wx::DirectorySelector}\\ \hline 
1114 % \texttt{'file extension'} & \\ \hline  
1115  \texttt{'colour'} & \texttt{wx::ColourSelector}\\ \hline 
1116 % \texttt{pixel type} & \\ \hline 
1117 % \texttt{image dimension} & \\ \hline
1118 % \texttt{image index} & \\ \hline 
1119 % \texttt{image size} & \\ \hline 
1120 % \texttt{voxel size} & \\ \hline  
1121 \end{tabular}
1122 \end{table}
1123
1124 %\newpage 
1125
1126
1127 % ==========================================
1128 \subsection{\CPP description of a box}
1129 \label{sec:CPP-box}
1130 % ==========================================
1131
1132 Almost everything is performed using macros.
1133
1134 For a quick start, the best you have to do is to run \texttt{bbStudio}, then in the menu \texttt{Tools}, choose the item
1135  \texttt{Create black box}, click on \texttt{C++}, and have a look to the generated files, or have a look at the source files of \bbtk core packages.
1136  
1137 % ==========================================
1138 \subsubsection{Black box basic header file (.h)}
1139 % ========================================== 
1140
1141 Let's have a look at the file \texttt{packages/std/bbstdMakeFileName.h}
1142
1143 \begin{file}{\texttt{packages/std/bbstdMakeFileName.h}}
1144 \small
1145 \begin{verbatim}
1146 #ifndef __bbstdMakeFileName_h_INCLUDED__
1147 #define __bbstdMakeFileName_h_INCLUDED__
1148
1149 #include "bbtkAtomicBlackBox.h"
1150
1151 namespace bbstd
1152 {
1153   class MakeFileName : public bbtk::AtomicBlackBox
1154   {
1155     BBTK_BLACK_BOX_INTERFACE(MakeFileName,bbtk::AtomicBlackBox);
1156     BBTK_DECLARE_INPUT(Directory, std::string);
1157     BBTK_DECLARE_INPUT(File,      std::string);
1158     BBTK_DECLARE_INPUT(Extent,    std::string);
1159     BBTK_DECLARE_OUTPUT(Out,      std::string);
1160     BBTK_PROCESS(DoProcess);
1161     void DoProcess();
1162   protected:
1163     virtual void bbUserConstructor();
1164   };
1165
1166   BBTK_BEGIN_DESCRIBE_BLACK_BOX(MakeFileName,bbtk::AtomicBlackBox);
1167   BBTK_NAME("MakeFileName");
1168   BBTK_AUTHOR("jpr@creatis.insa-lyon.fr");
1169   BBTK_CATEGORY("misc");
1170   BBTK_DESCRIPTION("Makes a kosher file name");
1171   BBTK_INPUT(MakeFileName,Directory,"Directory Name",std::string,
1172              "directory name");
1173   BBTK_INPUT(MakeFileName,File,     "File Name",     std::string,
1174              "file name");
1175   BBTK_INPUT(MakeFileName,Extent,   "Extention",     std::string,
1176              "file extension");
1177   
1178   BBTK_OUTPUT(MakeFileName,Out,"Full File Name",std::string,"file name");
1179   BBTK_END_DESCRIBE_BLACK_BOX(MakeFileName);
1180
1181 }
1182 // EO namespace bbstd
1183
1184 #endif //  __bbstdMakeFileName_h_INCLUDED__
1185 \end{verbatim}
1186 \end{file}
1187
1188 It includes \texttt{bbtkAtomicBlackBox.h}.
1189 The box class is \texttt{MakeFileName}.
1190 It inherits \texttt{bbtk::AtomicBlackBox}.
1191 It is in the \texttt{bbstd} namespace : 
1192 each box of a given package, say PACK, must be inserted into 
1193 the namespace \texttt{bbPACK}.
1194
1195 The macro \texttt{BBTK\_BLACK\_BOX\_INTERFACE} 
1196 declares the interface of the class: constructor, destructor,
1197 standard methods (e.g. New), etc. 
1198 The following macros then declare inputs and outputs of the box, 
1199 with their types.
1200 The macro \texttt{BBTK\_PROCESS} then declares which method to call 
1201 when processing the box (the process callback).
1202 The callback itself is declared just below.
1203
1204 The line \texttt{virtual void bbUserConstructor();} then 
1205 overloads the virtual method \texttt{bbUserConstructor} 
1206 which is used to perform specific things at construction time.
1207 You can also overload \texttt{bbUserCopyConstructor} 
1208 and \texttt{bbUserDestructor} with the same signature.
1209 The black box interface macros are summarized in table 
1210 \ref{CPPInterfaceBasicMacros}.
1211
1212 % ==========================================
1213 \begin{table}[!ht]
1214 \caption{\label{CPPInterfaceBasicMacros}Black box interface \CPP macros}
1215 \begin{tabular}{p{\textwidth}}\hline
1216     \\ \small \texttt{BBTK\_BLACK\_BOX\_INTERFACE(BOX\_NAME,BBTK\_PARENT)}:
1217     Yes, we know the \bbtk parent is redundant with the inheritance list... That's why we allow you to describe your class in \xml format!
1218      \\ \small \texttt{BBTK\_VTK\_BLACK\_BOX\_INTERFACE(CLASS,BBTK\_PARENT,VTK\_PARENT) }: Black box interface for \vtk object inherited boxes
1219         \dots
1220     \\ \small \texttt{BBTK\_ITK\_BLACK\_BOX\_INTERFACE(CLASS,BBTK\_PARENT,ITK\_PARENT) }: Black box interface for \itk object inherited boxes
1221         \dots
1222     \\ \small \texttt{BBTK\_DECLARE\_INPUT (NAME,TYPE) }: Declares an input of the box, with \texttt{NAME}: the input name (as it will appear to the users of your black box) and \texttt{TYPE}: \CPP type of the input (e.g. double, std::string, vtkImageData*, ...).
1223   \\ \small \texttt{BBTK\_DECLARE\_INHERITED\_INPUT(NAME,TYPE,GETMETHOD,SETMETHOD)}: Declares an input of the box which wraps the \texttt{GETMETHOD / SETMETHOD} accessors
1224     \\ \small \texttt{BBTK\_DECLARE\_VTK\_INPUT(NAME,TYPE)}:
1225          Declares a vtk object-inherited input
1226    \\ \small \texttt{BBTK\_DECLARE\_VTK\_IMAGE\_ALGORITHM\_INPUT(NAME,TYPE)}:    Declares a vtkImageAlgorithm-inherited input 
1227     \\ \small \texttt{BBTK\_DECLARE\_VTK\_POLY\_DATA\_ALGORITHM\_INPUT(NAME,TYPE)}: Declares a vtkPolyDataAlgorithm-inherited input  
1228     \\ \small \texttt{BBTK\_DECLARE\_ITK\_INPUT (NAME,TYPE)}:
1229          Declares a itk object-inherited input
1230   \\ \small \texttt{BBTK\_DECLARE\_OUTPUT (NAME,TYPE) }:
1231         Declares an output of the box 
1232   \\ \small \texttt{BBTK\_DECLARE\_INHERITED\_OUTPUT(NAME,TYPE,GETMETHOD,SETMETHOD)}:
1233     Declares an output of the box which wraps the \texttt{GETMETHOD / SETMETHOD} accessors
1234     \\ \small \texttt{BBTK\_DECLARE\_VTK\_OUTPUT(NAME,TYPE)}:
1235         Declares a vtk object-inherited output    
1236      \\ \small \texttt{BBTK\_DECLARE\_ITK\_OUTPUT(NAME,TYPE)}:
1237          Declares a itk object-inherited output
1238    \\ \small \texttt{BBTK\_DECLARE\_VTK\_PARAM(VTK\_PARENT,NAME,TYPE)}:
1239  Declares an input corresponding to an inherited vtk parameter 
1240      (you know, the ones that are declared by vtkSetMacro/vtkGetMacro). Its name must be the same than the vtk parameter name.  
1241     \\ \small \texttt{BBTK\_DECLARE\_ITK\_PARAM(NAME,TYPE)}:
1242  Declares an input corresponding to an inherited itk parameter 
1243     \\ \small \texttt{BBTK\_PROCESS(METHOD\_NAME)}:
1244         Defines the method to call when the box is processed. 
1245     \\ \small \texttt{BBTK\_VTK\_PROCESS}:                                                      Defines AND implements the default processing method for vtk 
1246         inherited black boxes (calls \texttt{vtkParent::Update})
1247   \\ \small \texttt{BBTK\_ITK\_PROCESS}:                                                        Defines AND implements the default processing method for itk 
1248         inherited black boxes (calls \texttt{itkParent::Update})
1249 \\ 
1250 \hline\end{tabular}
1251
1252 \end{table}
1253 %================================================
1254
1255 After the black box class declaration 
1256 then comes a zone in which you describe your black box, 
1257 between the macros \texttt{BBTK\_BEGIN\_DESCRIBE\_BLACK\_BOX} 
1258 and \\ \texttt{BBTK\_END\_DESCRIBE\_BLACK\_BOX}.
1259
1260 The macro \texttt{BBTK\_BEGIN\_DESCRIBE\_BLACK\_BOX} 
1261 actually starts the declaration of another class, 
1262 called \texttt{\textless BOXNAME \textgreater Descriptor} 
1263 (in our case \texttt{MakeFileNameDescriptor}).
1264 The descriptor of a black box :
1265 \begin{itemize}
1266 \item has only one instance, which is stored in the package
1267 \item provides information about the box type (author, description, ...) 
1268 which is used for documentation.
1269 \item provides information about the box I/Os, mainly their types
1270 (uses RTTI : \texttt{std::type\_info} ).
1271 \item is responsible for creating new instances of the box it describes.
1272 \end{itemize}
1273
1274 As you can see, 
1275 the macros which are between \texttt{BBTK\_BEGIN\_DESCRIBE\_BLACK\_BOX} 
1276 and \texttt{BBTK\_END\_DESCRIBE\_BLACK\_BOX} 
1277 provide the box name (the string), 
1278 its authors, description, category, 
1279 the descriptions of its inputs and outputs.
1280 Black box descriptor related 
1281 are described in table \ref{CPPDescriptorBasicMacros}.
1282
1283 % ==========================================
1284 \begin{table}[!ht]
1285 \caption{\label{CPPDescriptorBasicMacros}Black box descriptor \CPP macros}
1286 \begin{tabular}{p{\textwidth}}\hline
1287     \\ \small \texttt{BBTK\_BEGIN\_DESCRIBE\_BLACK\_BOX(BOX\_NAME,BBTK\_PARENT) } : 
1288     Yes, we know it's redundant with public inheritance ... That's why we allow you to describe your class in xml format! 
1289     All the following items will be used in the Help interface; describe them carefully (i.e. in a Human understandable way!).
1290   \\ \small \texttt{BBTK\_ADAPTOR}: Declares that the box is an adaptor
1291   \\ \small \texttt{BBTK\_DEFAULT\_ADAPTOR}: Declares that the box is the default adaptor for its I/O types
1292    \\ \small \texttt{BBTK\_NAME(STRING)}: The name of your box 
1293     \\ \small \texttt{BBTK\_AUTHOR(STRING)}: The author(s) (better you put e-mail adresses)
1294     \\ \small \texttt{BBTK\_DESCRIPTION(STRING)}: Brief description of what does the box
1295     \\ \small \texttt{BBTK\_CATEGORY(STRING)}: Box categories, semicolon separated  (see table \ref{categories})
1296     \\ \small \texttt{BBTK\_INPUT(BOX\_NAME,INPUT\_NAME,DESCRIPTION,CPP\_TYPE,INPUT\_NATURE)} 
1297        \begin{itemize}
1298          \item \texttt{BOX\_NAME}: The current black box name.
1299          \item \texttt{INPUT\_NAME}: The input name
1300          \item \texttt{DESCRIPTION} (string): A brief description of what the parameter is used for.
1301          \item \texttt{CPP\_TYPE}: The \CPP type of the input (e.g. double, std::string, vtkImageData*, ...) 
1302          \item \texttt{INPUT\_NATURE}: The 'nature' of the parameter (see table \ref{nature}) if you wish your box may be used by automatic GUI generator.
1303          Supply an empty string ("") if you don't care.          
1304        \end{itemize}
1305     \\ \small\texttt{BBTK\_OUTPUT(BOX\_NAME,OUTPUT\_NAME,DESCRIPTION,CPP\_TYPE)}: The same
1306      \\ \small \texttt{BBTK\_END\_DESCRIBE\_BLACK\_BOX(BOX\_NAME)} 
1307  \\ \hline\end{tabular}
1308 \end{table}
1309
1310 % ==========================================
1311 \subsubsection{Black box basic implementation file (.cxx)}
1312 % ========================================== 
1313
1314 Now let's have a look at the file \texttt{packages/std/bbstdMakeFileName.cxx}
1315
1316 \begin{file}{\texttt{packages/std/bbstdMakeFileName.cxx}}
1317 \small
1318 \begin{verbatim}
1319 #include "bbstdMakeFileName.h"
1320 #include "bbstdPackage.h"
1321
1322 namespace bbstd
1323 {
1324
1325   BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,MakeFileName);
1326   BBTK_BLACK_BOX_IMPLEMENTATION(MakeFileName,bbtk::AtomicBlackBox);
1327   
1328   void MakeFileName::bbUserConstructor()
1329   {
1330     bbSetInputDirectory("");
1331     bbSetInputFile("");
1332     bbSetInputExtent("");
1333   }
1334   
1335   void MakeFileName::DoProcess()
1336   {
1337     ...
1338   }
1339 }
1340 // EO namespace bbstd
1341 \end{verbatim}
1342 \end{file}
1343
1344 The first line includes the header file.
1345 The second one includes the \texttt{std} package header file.
1346 This file is automatically generated during cmake configuration :
1347 for a package named \texttt{\textless PACK \textgreater}, \cmake
1348 creates the files \texttt{bb\textless PACK \textgreater Package.h} 
1349 and \texttt{bb\textless PACK \textgreater Package.cxx}.
1350 The header is to be included in any box implementation file and 
1351 the second one is compiled in the package library.
1352
1353 The macro \texttt{BBTK\_ADD\_BLACK\_BOX\_TO\_PACKAGE} 
1354 then registers the box \texttt{MakeFileName} into the package \texttt{std}.
1355
1356 The macro \texttt{BBTK\_BLACK\_BOX\_IMPLEMENTATION} is the 
1357 mirror macro of the macro \texttt{BBTK\_BLACK\_BOX\_INTERFACE} that 
1358 was used in the header : it implements the methods declared in the header.
1359
1360 We then need to write the body of \texttt{bbUserConstrutor} 
1361 and of the processing callback (here \texttt{DoProcess}).
1362
1363 That's all we need for a 'basic' black box.
1364 The implementation related macros are summarized in table \ref{CPPImplementationBasicMacros}.
1365
1366 % ==========================================
1367 \begin{table}[!ht]
1368 \caption{\label{CPPImplementationBasicMacros}Black box implementation \CPP macros}
1369 \begin{tabular}{p{\textwidth}}\hline
1370     \\ \small \texttt{BBTK\_ADD\_BLACK\_BOX\_TO\_PACKAGE(PACKAGE\_NAME,BOX\_NAME)}
1371    \\ \small  \texttt{BBTK\_BLACK\_BOX\_IMPLEMENTATION(BOX\_NAME,BBTK\_PARENT)}
1372 \\ \hline
1373 \end{tabular}
1374 \end{table}
1375  
1376 % ==========================================
1377 \subsubsection{Widget black boxes \CPP macros}
1378 % ==========================================
1379
1380 See the example of \texttt{package/wx/src/bbwxLayoutLine.h\textbar cxx}.
1381 The only differences with a non-widget black box are :
1382 \begin{itemize}
1383 \item The header must include \texttt{bbtkWxBlackBox.h} and \\ 
1384 the class must inherit \texttt{bbtk::WxBlackBox}.
1385 \item The black box interface must declare the widget creation callback 
1386 with the macro \texttt{BBTK\_CREATE\_WIDGET(CALLBACK)}. 
1387 The callback must be declared in the interface and implemented. 
1388 \item You can overload the method \texttt{void bbUserOnShow()} which 
1389 is called just after the \texttt{wxWindow} has been shown, e.g. 
1390 to refresh its content. Note that \texttt{Layout} widget \emph{MUST}
1391 overload this method and call \texttt{bbUserOnShowWidget(INPUT\_NAME)} 
1392 for all inputs which correspond to an 'embedded' window
1393 (the 'Widget1' ... 'WidgetN' inputs, 
1394 see \texttt{package/wx/src/bbwxLayoutLine.cxx})
1395 \end{itemize}
1396
1397 % ==========================================
1398 \subsubsection{VTK black boxes \CPP macros}
1399 % ==========================================
1400
1401 See the example of \texttt{package/wx/src/bbvtkMarchingCubes.h\textbar cxx}.
1402 The macros are summarized in table \ref{CPPInterfaceBasicMacros}.
1403
1404 % ==========================================
1405 \subsubsection{Template black boxes \CPP macros}
1406 % ==========================================
1407
1408 You can write down black box classes \emph{templates}. 
1409 However, only \emph{actual} classes, that is instanciated templates, 
1410 can be inserted into a package.
1411
1412 The files \texttt{package/std/src/bbstdStringTo.h\textbar cxx} 
1413 provide an example of a class template with one template parameter. 
1414
1415 The files \texttt{package/std/src/bbstdCast.h\textbar cxx} 
1416 provide an example of a class template with two template parameters. 
1417
1418 Class templates related macros are summarized in table \ref{CPPTemplateMacros}.
1419 % ==========================================
1420 \begin{table}[!ht]
1421 \caption{\label{CPPTemplateMacros}Black box templates-related \CPP macros}
1422 \begin{tabular}{p{\textwidth}}\hline
1423 % \begin{itemize}
1424     \\  \small\texttt{BBTK\_TEMPLATE\_BLACK\_BOX\_INTERFACE(BOX\_NAME,BBTK\_PARENT, TEMPLATE\_PARAMETER)}
1425     \\  \small\texttt{BBTK\_TEMPLATE2\_BLACK\_BOX\_INTERFACE(BOX\_NAME,BBTK\_PARENT, TEMPLATE\_PARAMETER\_1, TEMPLATE\_PARAMETER\_2)}
1426     \\  \small\texttt{BBTK\_BEGIN\_DESCRIBE\_TEMPLATE\_BLACK\_BOX(BOX\_NAME,BBTK\_PARENT)}: Note that in the descriptor, the template parameter name is \texttt{T}
1427 \\ \small\texttt{BBTK\_BEGIN\_DESCRIBE\_TEMPLATE2\_BLACK\_BOX(BOX\_NAME,BBTK\_PARENT)}: Note that in the descriptor, the template parameters names are \texttt{T1} and \texttt{T2}
1428     \\ \small\texttt{BBTK\_END\_DESCRIBE\_TEMPLATE\_BLACK\_BOX(BOX\_NAME)}
1429    \\ \small\texttt{BBTK\_END\_DESCRIBE\_TEMPLATE2\_BLACK\_BOX(BOX\_NAME)}
1430      \\ \small\texttt{BBTK\_TEMPLATE\_INPUT(BOX\_NAME,INPUT\_NAME,DESCRIPTION,CPP\_TYPE, INPUT\_NATURE)}: Same than for non-templates, except that the \texttt{CPP\_TYPE} can be the template parameter.
1431     \\ \small\texttt{BBTK\_TEMPLATE2\_INPUT(BOX\_NAME,INPUT\_NAME,DESCRIPTION,CPP\_TYPE, INPUT\_NATURE)}: Same remark
1432  \\\small \texttt{BBTK\_TEMPLATE\_OUTPUT(BOX\_NAME,OUTPUT\_NAME,DESCRIPTION,CPP\_TYPE)}: Same remark 
1433  \\ \small\texttt{BBTK\_TEMPLATE2\_OUTPUT(BOX\_NAME,OUTPUT\_NAME,DESCRIPTION,CPP\_TYPE)}: Same remark 
1434  \\ \small\texttt{BBTK\_BLACK\_BOX\_TEMPLATE\_IMPLEMENTATION(BOX\_NAME,BBTK\_PARENT)}
1435  \\ \small\texttt{BBTK\_BLACK\_BOX\_TEMPLATE2\_IMPLEMENTATION(BOX\_NAME,BBTK\_PARENT)}
1436  \\ \small\texttt{BBTK\_ADD\_TEMPLATE\_BLACK\_BOX\_TO\_PACKAGE(PACKAGE\_NAME,BOX\_NAME, TEMPLATE\_PARAMETER\_VALUE)}: Adds the black box template instanciated on a certain value of its template parameter to the package. You can put as many such lines with different template parameter values as you want (see e.g. \texttt{package/std/src/bbstdStringTo.cxx})
1437  \\ \small\texttt{BBTK\_ADD\_TEMPLATE2\_BLACK\_BOX\_TO\_PACKAGE(PACKAGE\_NAME,BOX\_NAME, TEMPLATE\_PARAMETER\_1\_VALUE, TEMPLATE\_PARAMETER\_2\_VALUE)}:
1438 The same for two template parameters (see  e.g. \texttt{package/std/src/bbstdCast.cxx})
1439 \\
1440 %\end{itemize}
1441 \\ \hline
1442 \end{tabular}
1443 \end{table}
1444
1445
1446 {\bf IMPORTANT NOTE ON TEMPLATE BLACK BOXES NAMES:}
1447
1448 Two different boxes registered in a package must have two different names. 
1449 Hence when using black box classes templates, 
1450 one must give different names to two instanciations of the template on 
1451 two different types. 
1452 This is typically done with inserting the template parameter type name in the 
1453 black box class name.
1454 An example is provided in \texttt{package/std/src/bbstdStringTo.h}: 
1455
1456 \begin{verbatim}
1457   BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(ToString,bbtk::AtomicBlackBox);
1458   BBTK_NAME(bbtk::HumanTypeName<T>()+"ToString");
1459    ... 
1460   BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(ToString);
1461 \end{verbatim}
1462
1463 To get the string corresponding to the name of a \CPP type
1464 (here the template parameter \texttt{T})
1465 one must use the template \bbtk function \texttt{bbtk::HumanTypeName<T>()}
1466 \footnote{\texttt{HumanTypeName} returns a human readable type name, 
1467 without special chars such as \texttt{::} or \textless. For example the 
1468 human readable type name of \texttt{std::vector\textless std::string \textgreater} is \texttt{VectorOfString}. The 'inhuman' type name is given 
1469 by the function \texttt{bbtk::TypeName<T>()}.}.
1470 It is then concatenated to the name \texttt{ToString}.
1471 This thus gives the name \texttt{IntToString} to the black box \texttt{ToString\textless int \textgreater}, 
1472 \texttt{DoubleToString} to the black box \texttt{ToString\textless double \textgreater}, etc.
1473
1474 You can also use \texttt{bbtk::HumanTypeName<T>()} 
1475 in the macro \texttt{BBTK\_DESCRIPTION}, like for example: 
1476 \begin{verbatim}
1477   BBTK_DESCRIPTION("Converts a "+bbtk::HumanTypeName<T>()+" ("
1478                    +bbtk::TypeName<T>()+") into a string");
1479 \end{verbatim}
1480
1481
1482 % ==========================================
1483 \subsubsection{ITK black boxes \CPP macros}
1484 % ==========================================
1485
1486 It is a special case of black box templates with also 
1487 special macros for \itk object inherited black boxes. 
1488
1489 See the example of \texttt{package/wx/src/bbitkBinaryThresholdImageFilter.h\textbar cxx}, 
1490 the tables \ref{CPPInterfaceBasicMacros} and \ref{CPPTemplateMacros}.
1491
1492 Note that 
1493 there is also a mechanism for making 
1494 ``generic'' untemplatized itk black boxes.
1495 See the example in the file above.
1496
1497 % ==========================================
1498 \section{Configure your project with \cmakens.} 
1499 \label{sec:CMake}
1500 % ==========================================
1501 You have to run the \texttt{CMakeSetup} application with your project root directory as location of the sources (this can be done by dragging the icon of the \texttt{CmakeLists.txt} file toward the icon of \texttt{CMakeSetup}). You will have to indicate a location for the binaries, which must be different from the location of the sources. You are likely to encounter some warnings about the compiler version, which you (generally) can ignore. Be careful however with various options, the default state of which is \texttt{OFF}, e.g.: at the very beginning, you will have to put \texttt{ON} the attribute \texttt{BUILD\_BBTK\_PACKAGE\_\emph{your\_package\_name}}. Click on 'Configure' as long as new elements appear or remain in red, then click on 'OK'. \cmake will generate an entire directory tree, with the workspace file (e.g. \texttt{bb\emph{your\_package\_name}.sln} for Microsoft Visual Studio) in the root directory. Note that the tree includes a \texttt{src} directory where the \CPP code of the package is automatically generated.
1502
1503 % ==========================================
1504 \section{Compile your project.}
1505 \label{sec:compile}
1506 % ==========================================
1507 Open the workspace file generated by \texttt{CMakeSetup} (e.g. \texttt{bb\emph{your\_package\_name}.sln} for Microsoft Visual Studio), select either the appropriate project to be built, or \texttt{ALL\_BUILD} if applies. Build it in RelWithDebInfo configuration, which corresponds to the configuration in which the bbtk libraries provided by the installer were compiled. The first step of the \texttt{build} process is the generation of \CPP code from \xml files. Note that these new \texttt{.cxx} and \texttt{.h} files are put into the \texttt{src} subdirectory of the directory tree containing the binaries and {\bf not} of the one containing the sources. Indeed, the 'sources' directory tree is intended to contain actual source files, that are to be saved (e.g. with CVS), while the 'binaries' directory tree is intended to contain all the files generated either by \cmake or by the \texttt{build} process.
1508
1509 % ==========================================
1510 \section{Plug the new package.}
1511 \label{sec:plugin}
1512 % ==========================================
1513 If you want to use the new package with \bbStudio you can plug it dynamically. Use the menu
1514 \texttt{Tools > Plug package}. You will be prompted to indicate the package directory. Browse the root of the 'binaries' directory tree (the one generated by \cmakens).
1515 The plug-in mechanism actually consists in automatic adding of appropriate paths into the configuration file.
1516
1517 \end{document}
1518