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