1 % # ---------------------------------------------------------------------
3 % # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 % # ------------------------------------------------------------------------ */
29 % ==========================================
30 \documentclass[11pt,final,a4paper]{article}
33 \bbtkGuide[Package Developers' Guide]
35 % ==========================================
40 % ==========================================
41 \section{Introduction}
42 % ==========================================
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.
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:
55 \item \textbf{Create a new package. }
56 This process (see section \ref{CreatePackage}), consists of two steps:
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}.
63 \item \textbf{Describe your new box.} This is explained in section \ref{CreateBlackBox}.
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}.
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}.
78 % ==========================================
79 \section{Creating a new package}
81 % ==========================================
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:
96 bbCreatePackage <package-path> <package-name> [author] [description]
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),
104 \item The {\bf directory} of your new package.
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.
121 \item The {\bf name} of your new package.
122 This name will be used to load the package in \CPP and \bbs scripts.
125 You must also provide the \texttt{author} list
126 and a \texttt{description} which will be used for your package documentation.
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):
134 |-- PackageConfig.cmake.in
136 |-- UsePackage.cmake.in
148 | | |-- CMakeLists.txt
149 | | `-- header.html.in
152 | |-- DoxyMainPage.txt.in
153 | `-- Doxyfile.txt.in
160 \item Edit the root \texttt{CMakeLists.txt} file to customize your package build settings (see section \ref{RootCMakeLists})
162 \item Put your \CPP/\xml boxes sources in '\texttt{src}' subdirectory (see section \ref{CreateBlackBox}).
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.
166 \item Put your script-defined boxes (complex boxes) in '\texttt{bbs/boxes}' subdirectory.
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.
170 \item Put your script-defined applications in '\texttt{bbs/appli}' subdirectory.
172 Please use the convention: Do {\bf not} prefix '\texttt{bb}' to the files.
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.
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}'.
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}'.
184 \subsection{Configuring the root \texttt{CMakeLists.txt}}
185 \label{RootCMakeLists}
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!
190 \begin{file}{CMakeLists.txt}
193 #==========================================================================
194 # CMAKE SETTINGS FOR BUILDING A BBTK PACKAGE
195 #==========================================================================
197 #==========================================================================
198 # THE NAME OF THE BBTK PACKAGE
199 SET(BBTK_PACKAGE_NAME MyPackage)
200 #==========================================================================
202 #==========================================================================
203 # IF IT IS A STANDALONE PROJECT UNCOMMENT NEXT LINE TO DECLARE YOUR PROJECT
204 # PROJECT(bb${BBTK_PACKAGE_NAME})
205 #==========================================================================
207 #==========================================================================
209 # !!! NO COMMA ALLOWED !!!
210 SET(${BBTK_PACKAGE_NAME}_AUTHOR "myself")
211 #==========================================================================
213 #==========================================================================
214 # PACKAGE DESCRIPTION
215 SET(${BBTK_PACKAGE_NAME}_DESCRIPTION "My super package does nothing yet")
216 #==========================================================================
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 #==========================================================================
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 #==========================================================================
234 #==========================================================================
235 # LIST HERE THE OTHER bbtk PACKAGES NEEDED
236 # (WILL BE FOUND AND USED AUTOMATICALLY)
237 SET(${BBTK_PACKAGE_NAME}_USE_PACKAGES
244 #==========================================================================
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
256 #==========================================================================
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
268 #==========================================================================
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 !!
280 #==========================================================================
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 !!
292 #==========================================================================
294 #==========================================================================
295 SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS
296 # LIST HERE YOUR ADDITIONAL INCLUDE DIRECTORIES
300 # - automatically handled libraries or packages: wx, vtk... (see above)
301 # - the dirs automatically set by other libraries found by FIND_PACKAGE
303 #==========================================================================
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
310 #==========================================================================
312 #==========================================================================
313 # IF NEEDED : UNCOMMENT NEXT LINE
314 # AND LIST ADDITIONNAL DIRECTORIES
315 # IN WHICH TO LOOK FOR LIBRARIES TO LINK AGAINST
317 #==========================================================================
319 #==========================================================================
320 # SET TO TRUE TO HAVE INFORMATION ON LIBRARIES FOUND DURING CMAKE CONFIGURE
321 SET(FIND_PACKAGE_VERBOSE TRUE)
322 #==========================================================================
324 #==========================================================================
325 # END OF USER SECTION
326 #==========================================================================
328 #==========================================================================
329 # Include configuration script
330 INCLUDE(Configure.cmake)
331 #==========================================================================
333 #==========================================================================
335 #==========================================================================
340 You can see in the file some of the informations you supplied when running the \bbCreatePackage utility:
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.
349 You can additionally set:
351 \item The \textbf{version} of the package.
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.
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.
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.
370 \item The \textbf{boxes \bbs sources} of the package: you can list each
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.
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.
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.
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.
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.
392 Of course, this is only a framework and you can add any other \cmake commands
395 % ==========================================
396 \section{Creating a new box}
397 \label{CreateBlackBox}
398 % ==========================================
400 % ==========================================
401 \subsection{Principles}
402 % ==========================================
404 % ==========================================
405 \subsubsection{\texttt{C++} or \texttt{XML}?}
406 % ==========================================
407 There are two ways to create a new black box in an existing package:
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.
414 % ==========================================
415 \subsubsection{From which \bbtk class inherit?}
416 % ==========================================
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.
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}
429 and the \CPP header of a class called \texttt{NameOfAClass} is
430 in the file called \texttt{bbtkNameOfAClass.h}}.
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.
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}.
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}.
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.
453 % ==========================================
454 \subsubsection{Inherit or encapsulate?}
455 % ==========================================
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 :
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
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.
473 In \CPPns, in order to embed an existing processing \emph{class}
474 into a standard interface you only have two possibilities:
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:
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.
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:
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 :
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
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.
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
518 % ==========================================
519 \subsubsection{Input and output accessors}
520 % ==========================================
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).
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:
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.}:
548 \item \texttt{void bbSetInput<NAME>(<TYPE>);}
549 \item \texttt{<TYPE> bbGetInput<NAME>();}
551 \item The declaration of an {\bf output} called \texttt{NAME} and
552 of type \texttt{TYPE} generates the two accessors:
554 \item \texttt{void bbSetOutput<NAME>(<TYPE>);}
555 \item \texttt{<TYPE> bbGetOutput<NAME>();}
559 For example, declaring an input called \texttt{Image}
560 would generate the two accessors \texttt{bbSetInputImage} and
561 \texttt{bbGetInputImage}.
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}.
576 % ==========================================
577 \subsection{Generate the black box skeleton}
578 % ==========================================
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}.
589 \caption{\label{bbCreateBlackBox}Create Black Box interface}
591 \includegraphics[width=0.6\textwidth]{bbCreateBackBox.png}
595 You will have to give:
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.
602 \item Its {\bf type}, which is one of the following:
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}.
611 \item The output format of the file, either a C++ file or an XML file.
614 % ==========================================
615 \subsection{\texttt{XML} description of a box}
617 % ==========================================
619 % ==========================================
620 \subsubsection{General \texttt{xml} tags}
621 % ==========================================
623 Let us examine the \texttt{xml} file
624 describing the \texttt{Add} box of the \texttt{std} package:
626 \begin{file}{\texttt{packages/std/src/bbAdd.xml}}
629 <?xml version="1.0" encoding="iso-8859-1"?>
631 <blackbox name="Add">
633 <author>laurent.guigues@creatis.insa-lyon.fr </author>
634 <description>Adds its inputs </description>
635 <category>math </category>
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"/>
642 bbSetOutputOut( bbGetInputIn1() + bbGetInputIn2() );
655 As the box is not a widget, it implicitly inherits from
656 \texttt{bbtk::AtomicBlackBox} (the default).
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.
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.
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:
679 \begin{file}{\texttt{MyPackage/bbMyPackageMyBox.xml}}
682 <!--=======================================================================
683 STARTS THE DESCRIPTION OF THE BLACK BOX -->
684 <blackbox name="MyBox">
685 <!--====================================================================-->
687 <!--=====================================================================
688 THE BOX DOCUMENTATION -->
690 <author>myself</author>
691 <description>no idea of what it can do</description>
692 <category>__CATEGORY__</category>
693 <!--==================================================================-->
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 <!--==================================================================-->
702 <!--=====================================================================
703 INPUTS/OUTPUTS DECLARATION -->
704 <!-- Declares an input with name 'In', type 'double'
705 and description 'First input' -->
707 <input name="In" type="double" description="First input"/>
709 <!-- Declares an output with name 'Out', type 'double'
710 and description 'First output' -->
711 <output name="Out" type="double" description="First output"/>
712 <!--==================================================================-->
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
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') -->
729 bbSetOutputOut( bbGetInputIn() );
730 std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
733 <!--==================================================================-->
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 -->
746 <!-- THE COPY-CONSTRUCTION METHOD BODY :
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) -->
755 <!-- THE DESTRUCTION METHOD BODY :
757 but this is where you should desallocate the output pointers if any -->
762 <!--==================================================================-->
764 <!--====================================================================-->
765 <!-- END OF BLACK BOX DESCRIPTION -->
767 <!--====================================================================-->
768 <!--====================================================================-->
769 <!--====================================================================-->
770 <!--====================================================================-->
774 To describe your own black box in \xml code,
775 you have to modify this \xml file as follows:
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
789 % ==========================================
790 \subsubsection{Writing new widget boxes in \xml}
791 % ==========================================
792 See the example \texttt{packages/wx/src/bbwxOutputText.xml}
794 \begin{file}{\texttt{packages/wx/src/bbwxOutputText.xml}}
797 <blackbox name="OutputText" widget>
799 <author>laurent.guigues at creatis.insa-lyon.fr</author>
800 <description>Text zone to be inserted into a window (wxStaticText)
802 <category></category>
804 <input name="Title" type="std::string"
805 description="Title prefixed to the text"/>
806 <input name="In" type="std::string" description="Text"/>
809 bbSetOutputWidget( new wxStaticText ( bbGetWxParent() , -1 , _T("") ) );
811 </PRE></createwidget>
815 if (bbGetInputTitle()!="")
817 msg = bbGetInputTitle()+": " + bbGetInputIn();
821 msg = bbGetInputIn();
823 ((wxStaticText*)bbGetOutputWidget())->SetLabel( bbtk::std2wx( msg ) );
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}
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}.
857 More complex examples can be found in the \texttt{package/wx/src} folder.
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:
869 \item the attribute \texttt{type="VTK\_ImageAlgorithm"}
870 to the \texttt{blackbox} tag:
872 <blackbox name="..." type="VTK_ImageAlgorithm">
875 \item the tag \texttt{vtkparent} which gives the \vtk parent of the box, e.g.:
877 <vtkparent> vtkImageAnisotropicDiffusion3D </vtkparent>
880 \item an \texttt{include} tag to include the appropriate \vtk parent header, such as:
882 <include> vtkImageAnisotropicDiffusion3D.h </include>
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:
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"/>
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.
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.:
905 <input name="DiffusionThreshold" type="double" special="vtk parameter"
906 description="Difference threshold that stops diffusion"/>
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.
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.
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.
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.
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):
938 <blackbox name="..." type="VTK_PolyDataAlgorithm">
940 <vtkparent>the vtk Polydata class it inherits from</vtkparent>
941 <input name="..." type="vtkPolyData*" special="vtk input"
943 <output name="..." type="vtkPolyData*" special="vtk output"
945 <input name="..." type="double" special="vtk parameter"
949 % ==========================================
950 \subsubsection{Specific \texttt{xml} tags for \texttt{itk::ImageToImageFilter} classes bbfication by inheritance}
951 \label{sec:Specific-ITK}
952 % ==========================================
958 % ==========================================
959 \subsubsection{\bbfy \texttt{xml} tags reference}
960 % ==========================================
962 % See tables \ref{xml_tags}, \ref{xml_tags2}
963 % ==========================================
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'}}
968 \begin{tabular}{|lcllm{5.7cm}|}
970 Tag & Attributes & Cond & Mult & Description \\ \hline
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:
975 \{\texttt{standard} (default),
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
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'}}
1005 \begin{tabular}{|lcllm{5.5cm}|}
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
1019 % ==========================================
1021 \caption{\label{xml_tags-conditions}
1022 \bbfy \texttt{xml} tags conditions}
1025 \begin{tabular}{|ll|}
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
1038 %\caption{\label{basic_parent}}
1039 %\bbfy \texttt{Basic box parent}
1041 %\begin{tabular}{|ll|}
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}%
1052 % ==========================================
1054 \caption{\label{categories} \texttt{Black Box} categories}
1056 \begin{tabular}{|p{4cm}p{8cm}|}
1058 \texttt{Category name} & : Meaning \\ \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
1081 \texttt{3D object creator} & : Sophisticated 3D widget \\ \hline
1082 \texttt{toolsbbtk} & : \bbtk development tools such as \\
1083 & GUICreatePackage, GUICreateBlackBox, etc. \\ \hline
1088 % ==========================================
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}
1092 \begin{tabular}{|p{4cm}p{8cm}|}
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
1103 % ==========================================
1105 \caption{\label{nature}Input/output \texttt{natures}}
1107 \begin{tabular}{|p{4cm}p{8cm}|}
1109 \texttt{Nature} & : Associated \texttt{DEFAULT\_GUI} box \\ \hline
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
1127 % ==========================================
1128 \subsection{\CPP description of a box}
1130 % ==========================================
1132 Almost everything is performed using macros.
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.
1137 % ==========================================
1138 \subsubsection{Black box basic header file (.h)}
1139 % ==========================================
1141 Let's have a look at the file \texttt{packages/std/bbstdMakeFileName.h}
1143 \begin{file}{\texttt{packages/std/bbstdMakeFileName.h}}
1146 #ifndef __bbstdMakeFileName_h_INCLUDED__
1147 #define __bbstdMakeFileName_h_INCLUDED__
1149 #include "bbtkAtomicBlackBox.h"
1153 class MakeFileName : public bbtk::AtomicBlackBox
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);
1163 virtual void bbUserConstructor();
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,
1173 BBTK_INPUT(MakeFileName,File, "File Name", std::string,
1175 BBTK_INPUT(MakeFileName,Extent, "Extention", std::string,
1178 BBTK_OUTPUT(MakeFileName,Out,"Full File Name",std::string,"file name");
1179 BBTK_END_DESCRIBE_BLACK_BOX(MakeFileName);
1182 // EO namespace bbstd
1184 #endif // __bbstdMakeFileName_h_INCLUDED__
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}.
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,
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.
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}.
1212 % ==========================================
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
1220 \\ \small \texttt{BBTK\_ITK\_BLACK\_BOX\_INTERFACE(CLASS,BBTK\_PARENT,ITK\_PARENT) }: Black box interface for \itk object inherited boxes
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})
1253 %================================================
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}.
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 :
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.
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}.
1283 % ==========================================
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)}
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.
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}
1310 % ==========================================
1311 \subsubsection{Black box basic implementation file (.cxx)}
1312 % ==========================================
1314 Now let's have a look at the file \texttt{packages/std/bbstdMakeFileName.cxx}
1316 \begin{file}{\texttt{packages/std/bbstdMakeFileName.cxx}}
1319 #include "bbstdMakeFileName.h"
1320 #include "bbstdPackage.h"
1325 BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,MakeFileName);
1326 BBTK_BLACK_BOX_IMPLEMENTATION(MakeFileName,bbtk::AtomicBlackBox);
1328 void MakeFileName::bbUserConstructor()
1330 bbSetInputDirectory("");
1332 bbSetInputExtent("");
1335 void MakeFileName::DoProcess()
1340 // EO namespace bbstd
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.
1353 The macro \texttt{BBTK\_ADD\_BLACK\_BOX\_TO\_PACKAGE}
1354 then registers the box \texttt{MakeFileName} into the package \texttt{std}.
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.
1360 We then need to write the body of \texttt{bbUserConstrutor}
1361 and of the processing callback (here \texttt{DoProcess}).
1363 That's all we need for a 'basic' black box.
1364 The implementation related macros are summarized in table \ref{CPPImplementationBasicMacros}.
1366 % ==========================================
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)}
1376 % ==========================================
1377 \subsubsection{Widget black boxes \CPP macros}
1378 % ==========================================
1380 See the example of \texttt{package/wx/src/bbwxLayoutLine.h\textbar cxx}.
1381 The only differences with a non-widget black box are :
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})
1397 % ==========================================
1398 \subsubsection{VTK black boxes \CPP macros}
1399 % ==========================================
1401 See the example of \texttt{package/wx/src/bbvtkMarchingCubes.h\textbar cxx}.
1402 The macros are summarized in table \ref{CPPInterfaceBasicMacros}.
1404 % ==========================================
1405 \subsubsection{Template black boxes \CPP macros}
1406 % ==========================================
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.
1412 The files \texttt{package/std/src/bbstdStringTo.h\textbar cxx}
1413 provide an example of a class template with one template parameter.
1415 The files \texttt{package/std/src/bbstdCast.h\textbar cxx}
1416 provide an example of a class template with two template parameters.
1418 Class templates related macros are summarized in table \ref{CPPTemplateMacros}.
1419 % ==========================================
1421 \caption{\label{CPPTemplateMacros}Black box templates-related \CPP macros}
1422 \begin{tabular}{p{\textwidth}}\hline
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})
1446 {\bf IMPORTANT NOTE ON TEMPLATE BLACK BOXES NAMES:}
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}:
1457 BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(ToString,bbtk::AtomicBlackBox);
1458 BBTK_NAME(bbtk::HumanTypeName<T>()+"ToString");
1460 BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(ToString);
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.
1474 You can also use \texttt{bbtk::HumanTypeName<T>()}
1475 in the macro \texttt{BBTK\_DESCRIPTION}, like for example:
1477 BBTK_DESCRIPTION("Converts a "+bbtk::HumanTypeName<T>()+" ("
1478 +bbtk::TypeName<T>()+") into a string");
1482 % ==========================================
1483 \subsubsection{ITK black boxes \CPP macros}
1484 % ==========================================
1486 It is a special case of black box templates with also
1487 special macros for \itk object inherited black boxes.
1489 See the example of \texttt{package/wx/src/bbitkBinaryThresholdImageFilter.h\textbar cxx},
1490 the tables \ref{CPPInterfaceBasicMacros} and \ref{CPPTemplateMacros}.
1493 there is also a mechanism for making
1494 ``generic'' untemplatized itk black boxes.
1495 See the example in the file above.
1497 % ==========================================
1498 \section{Configure your project with \cmakens.}
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.
1503 % ==========================================
1504 \section{Compile your project.}
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.
1509 % ==========================================
1510 \section{Plug the new package.}
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.