2 % ==========================================
3 \documentclass[11pt,final,a4paper]{article}
6 \bbtkGuide[Package Developers' Guide]
8 % ==========================================
13 % ==========================================
14 \section{Introduction}
15 % ==========================================
17 This guide describes how to
18 create new \bbtk packages and black boxes.
19 How to use them is described in \bbtk Users' guide.
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 :
28 \item \textbf{Create a new package. }
29 This is described in section \ref{CreatePackage}.
31 \item \textbf{Describe your new box.}
32 You can do it either :
34 \item In \CPP code. You will have to write the class for
35 your box, mostly using \bbtk macros.
37 When configuring your project with \cmake,
38 the utility \bbfy will then generate the corresponding \CPP code.
41 This is described in section \ref{CreateBlackBox}.
45 % ==========================================
46 \section{Creating a new package}
48 % ==========================================
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.
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 :
63 bbCreatePackage <package-path> <package-name> [author] [description]
66 \bbStudio also offers a graphical interface to the \bbCreatePackage
68 You can run it with the menu \texttt{Tools $>$ Create Package}.
70 In both cases (using the command line tool or \bbStudio interface),
74 \item The {\bf directory} of your new package.
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.
91 \item The {\bf name} of your new package.
92 This name will be used to load the package in \CPP and \bbs scripts.
95 You must also provide the \texttt{author} list
96 and a \texttt{description} which will be used for your package documentation.
98 After running \bbCreatePackage or clicking 'Run' in \bbStudio interface
99 you should get a file structure like this (Linux users can verify it with the \texttt{tree} command):
104 |-- PackageConfig.cmake.in
106 |-- UsePackage.cmake.in
118 | | |-- CMakeLists.txt
119 | | `-- header.html.in
122 | |-- DoxyMainPage.txt.in
123 | `-- Doxyfile.txt.in
130 \item Edit the root CMakeLists.txt file to customize your package build settings (see \ref{RootCMakeLists} below)
132 \item Put your c++/xml boxes sources in 'src'.
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\}.
136 \item Put your script-defined boxes (complex boxes) in 'bbs/boxes'.
138 Please use the convention : If the name of your box is 'Box' then call the file 'bbBox.bbs' to let others know that the script defines a complex black box type.
140 \item Put your script-defined applications in 'bbs/appli'.
142 Please use the convention : Do not prepend 'bb' to the files.
144 \item Put your data in 'data'.
145 Any data put there will be installed and accessible in your scripts :
146 the package data path is provided by the box
147 \texttt{std::PrependPackageDataPath}.
149 \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'.
151 \item You can customize the main page of your doxygen doc by editing the file 'doc/doxygen/DoxyMainPage.txt.in'.
154 \subsection{Configuring the root \texttt{CMakeLists.txt}}
155 \label{RootCMakeLists}
157 First you must configure your new package build settings, by editing the file
158 \texttt{CMakeLists.txt} in the package root directory.
161 \begin{file}{CMakeLists.txt}
164 #===========================================================================
165 # CMAKE SETTINGS FOR BUILDING A BBTK PACKAGE
166 #===========================================================================
168 #===========================================================================
169 # THE NAME OF THE BBTK PACKAGE
170 SET(BBTK_PACKAGE_NAME MyPackage)
171 #===========================================================================
173 #===========================================================================
174 # IF IT IS A STANDALONE PROJECT UNCOMMENT NEXT LINE TO DECLARE YOUR PROJECT
175 # PROJECT(bb${BBTK_PACKAGE_NAME})
176 #===========================================================================
178 #===========================================================================
180 # !!! NO COMMA ALLOWED !!!
181 SET(${BBTK_PACKAGE_NAME}_AUTHOR "myself")
182 #===========================================================================
184 #===========================================================================
185 # PACKAGE DESCRIPTION
186 SET(${BBTK_PACKAGE_NAME}_DESCRIPTION "The kinkiest stuff you ve ever seen.")
187 #===========================================================================
189 #===========================================================================
190 # PACKAGE VERSION NUMBER
191 SET(${BBTK_PACKAGE_NAME}_MAJOR_VERSION 1)
192 SET(${BBTK_PACKAGE_NAME}_MINOR_VERSION 0)
193 SET(${BBTK_PACKAGE_NAME}_BUILD_VERSION 0)
194 #===========================================================================
196 #===========================================================================
197 # UNCOMMENT EACH LIBRARY NEEDED (WILL BE FOUND AND USED AUTOMATICALLY)
198 # SET(${BBTK_PACKAGE_NAME}_USE_VTK ON)
199 # SET(${BBTK_PACKAGE_NAME}_USE_ITK ON)
200 # SET(${BBTK_PACKAGE_NAME}_USE_GDCM ON)
201 # SET(${BBTK_PACKAGE_NAME}_USE_GSMIS ON)
202 # SET(${BBTK_PACKAGE_NAME}_USE_WXWIDGETS ON)
203 #===========================================================================
205 #===========================================================================
206 # LIST HERE THE OTHER bbtk PACKAGES NEEDED
207 # (WILL BE FOUND AND USED AUTOMATICALLY)
208 SET(${BBTK_PACKAGE_NAME}_USE_PACKAGES
215 #===========================================================================
217 #===========================================================================
218 # THE SOURCES OF THE PACKAGE
219 # EITHER UNCOMMENT NEXT LINE TO COMPILE ALL .cxx OF THE src DIRECTORY :
220 SET(${BBTK_PACKAGE_NAME}_COMPILE_ALL_CXX ON)
221 # ... OR LIST THE FILES TO COMPILE MANUALLY :
222 #SET(${BBTK_PACKAGE_NAME}_SOURCES
223 # LIST HERE THE FILES TO COMPILE TO BUILD THE LIB
224 # E.G. TO COMPILE "toto.cxx" ADD "toto" (NO EXTENSION)
225 # THE PATH MUST BE RELATIVE TO THE src FOLDER
227 #===========================================================================
229 #===========================================================================
230 # THE xml SOURCES OF THE PACKAGE
231 # EITHER UNCOMMENT NEXT LINE TO bbfy ALL .xml OF THE src DIRECTORY :
232 SET(${BBTK_PACKAGE_NAME}_COMPILE_ALL_XML ON)
233 # ... OR LIST THE FILES TO COMPILE MANUALLY :
234 #SET(${BBTK_PACKAGE_NAME}_XML_SOURCES
235 # LIST HERE THE FILES TO bbfy TO BUILD THE LIB
236 # E.G. TO bbfy "toto.xml" ADD "toto" (NO EXTENSION)
237 # THE PATH MUST BE RELATIVE TO THE src FOLDER
239 #===========================================================================
241 #===========================================================================
242 # THE SCRIPT-DEFINED BOXES OF THE PACKAGE (bbs)
243 # EITHER UNCOMMENT NEXT LINE TO INCLUDE ALL .bbs OF THE bbs/boxes DIRECTORY :
244 SET(${BBTK_PACKAGE_NAME}_INCLUDE_ALL_BBS_BOXES ON)
245 # ... OR LIST THE FILES TO INCLUDE MANUALLY :
246 # SET(${BBTK_PACKAGE_NAME}_BBS_BOXES
247 # LIST HERE THE bbs FILES TO INCLUDE
248 # E.G. TO INCLUDE "boxes/bbtoto.bbs" ADD "boxes/bbtoto" (NO EXTENSION)
249 # !! THE PATH MUST BE RELATIVE TO THE bbs FOLDER !!
251 #===========================================================================
253 #===========================================================================
254 # THE SCRIPT-DEFINED APPLICATIONS OF THE PACKAGE (bbs)
255 # EITHER UNCOMMENT NEXT LINE TO INCLUDE ALL .bbs OF THE bbs/appli DIRECTORY :
256 SET(${BBTK_PACKAGE_NAME}_INCLUDE_ALL_BBS_APPLI ON)
257 # ... OR LIST THE FILES TO INCLUDE MANUALLY :
258 # SET(${BBTK_PACKAGE_NAME}_BBS_APPLI
259 # LIST HERE THE bbs FILES TO INCLUDE
260 # E.G. TO INCLUDE "appli/testToto.bbs" ADD "appli/testToto" (NO EXTENSION)
261 # !! THE PATH MUST BE RELATIVE TO THE bbs FOLDER !!
263 #===========================================================================
265 #===========================================================================
266 SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS
267 # LIST HERE YOUR ADDITIONAL INCLUDE DIRECTORIES
271 # - automatically handled libraries or packages : wx, vtk... (see above)
272 # - the dirs automatically set by other libraries found by FIND_PACKAGE
274 #===========================================================================
276 #===========================================================================
277 SET(${BBTK_PACKAGE_NAME}_LIBS
278 # LIST HERE THE ADDITIONAL LIBS TO LINK AGAINST
279 # EXCEPT : the same libs than for INCLUDE_DIRS
281 #===========================================================================
283 #===========================================================================
284 # IF NEEDED : UNCOMMENT NEXT LINE
285 # AND LIST ADDITIONNAL DIRECTORIES
286 # IN WHICH TO LOOK FOR LIBRARIES TO LINK AGAINST
288 #===========================================================================
290 #===========================================================================
291 # SET TO TRUE TO HAVE INFORMATION ON LIBRARIES FOUND DURING CMAKE CONFIGURE
292 SET(FIND_PACKAGE_VERBOSE TRUE)
293 #===========================================================================
295 #===========================================================================
296 # END OF USER SECTION
297 #===========================================================================
299 #===========================================================================
300 # Include configuration script
301 INCLUDE(Configure.cmake)
302 #===========================================================================
304 #===========================================================================
306 #===========================================================================
311 The comments in the file should be easily understandable !
313 you can see some of the informations you supplied in previous step:
315 \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
316 \lin the object file will be called \texttt{libbb}name\texttt{.so}
317 and on \win it will be called \texttt{bb}name\texttt{.dll}.
318 \item The \textbf{author(s)} of the package. Preferably provide e-mail adresses.
319 \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.
322 You can additionaly set :
324 \item The \textbf{version} of the package.
326 \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.
327 \item The \textbf{core \bbtk packages used} by the package as \CPP libraries
328 (if you need to use the black boxes of these packages in your \CPP code,
329 i.e. include some header and link with the library).
330 The mecanisms to find these libraries,
331 their sources and to link against them are automatically handled
332 by the \cmake files installed by \bbCreatePackage.
333 You just have to uncomment a line to use one of these libraries.
335 \item The \textbf{\CPP sources} of the package : you can list each input \CPP
336 file explicitly or tell \cmake to include in the project all the \CPP files
337 of the 'src' directory (default).
339 \item The \textbf{\xml sources} of the package : you can list each input \xml
340 file explicitly or tell \cmake to include in the project all the \xml files
341 of the 'src' directory (default).
343 \item The \textbf{boxes \bbs sources} of the package : you can list each
345 file explicitly or tell \cmake to include in the project \emph{all}
346 the \bbs files of the 'bbs/boxes' directory (default, recommanded).
348 \item The \textbf{appli \bbs sources} of the package :
349 you can list each input \bbs
350 file explicitly or tell \cmake to include in the project \emph{all}
351 the \bbs files of the 'bbs/appli' directory (default, recommanded).
353 \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
354 \texttt{FIND\_PACKAGE} mechanism of \cmake.
356 \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
357 \texttt{FIND\_PACKAGE} mechanism of \cmake.
359 \item \textbf{Additional link directories} in which to find libraries not
360 automatically handled and which you did not find with the
361 \texttt{FIND\_PACKAGE} mechanism of \cmake.
365 Of course, this is only a framework and you can add any other \cmake commands
368 % ==========================================
369 \section{Creating a new box}
370 \label{CreateBlackBox}
371 % ==========================================
373 % ==========================================
374 \subsection{Principles}
375 % ==========================================
377 % ==========================================
378 \subsubsection{\texttt{C++} or \texttt{XML} ?}
379 % ==========================================
380 There are two ways to create a new black box in an existing package :
382 \item Write an \xml description file which will be automatically
383 translated in \CPP by the \bbfy application during build (recommanded).
384 \item Write the \CPP code of the box using \bbtk macros.
387 % ==========================================
388 \subsubsection{From which \bbtk class inherit ?}
389 % ==========================================
391 Apart from the choice of the description langage to use,
392 there is an important choice to do concerning the implementation of the box.
393 In \CPP, a black box is nothing but a class which has the standard
394 interface of all black boxes : what's its name ? inputs ? outputs ? and so on.
396 The abstract description of this interface is done in the class
397 \texttt{bbtk::BlackBox} of the \bbtk library
398 and is implemented in its children classes :
399 \texttt{bbtk::AtomicBlackBox} and \texttt{bbtk::WxBlackBox}
400 \footnote{all the classes of the \bbtk library are in a \emph{namespace}
402 and the \CPP header of a class called \texttt{NameOfAClass} is
403 in the file called \texttt{bbtkNameOfAClass.h}}.
405 To create a new black box, you have to inherit one of these two
406 concrete classes in order to inherit the black box interface and a
407 particular implementation of this interface.
409 If your black box is a \emph{Widget} black box,
410 that is a black box which has (or is)
411 a piece of a graphical interface based on the \wx library,
412 then it must inherit the class \texttt{bbtk::WxBlackBox}.
414 Concretely, a \texttt{bbtk::WxBlackBox} is associated
415 a \texttt{wxWindow} and must be able to return a pointer to it.
416 If your black box is not a widget black box
417 (that is : doesn't returns a pointer to a \texttt{wxWindow}),
418 it must inherit from \texttt{bbtk::AtomicBlackBox}.
419 NOTE : \emph{modal dialogs}
420 which are created and destroyed at the end of the process
421 method of the box are NOT \texttt{WxBlackBoxes} :
422 they do not return a \texttt{wxWindow},
423 see the code of \texttt{wx::FileSelector} for example.
425 % ==========================================
426 \subsubsection{Inherit or encapsulate ?}
427 % ==========================================
429 Now, your black box will do something (hopefully !).
430 When you decide to write a new black box,
431 you should be in one of these three cases :
433 \item You already have a \texttt{C}-like function which
434 does the processing that you wish to 'blackboxify' (bbfy in short).
435 \item You already have a \CPP class which
436 does the processing that you wish to 'blackboxify'
437 \item You start from scratch without any existing code
440 The idea of \BBTK is to embed processing codes into
441 \CPP objects which have a standard and generic interface -
442 namely black boxes - to be able to chain arbitrary
443 processes afterwards.
445 In \CPP, in order to embed an existing processing \emph{class}
446 into a standard interface you only have two possibilities :
448 \item {\bf Inherit} the existing processing class
449 \emph{and} the interface class (e.g. \texttt{bbtk::AtomicBlackBox}).
450 In this case you have to :
452 \item make the link between the inputs and outputs of the black box
453 and the interface of the inherited class
454 \item call the processing
455 method of the inherited class in the processing method of the black box.
457 \item {\bf Encapsulate} the existing processing class
458 in a class inherited from
459 the interface class (e.g. \texttt{bbtk::AtomicBlackBox}).
460 In this case you have to :
462 \item declare an instance of the processing class
463 as a member of the black box,
464 \item instantiate it at the right time
465 (either in the constructor or in the processing method of the black box)
466 \item in the processing method of the black box :
468 \item set the inputs of the member processing class with the inputs of the black box,
469 \item call the processing method of the encapsulated class
470 \item set the ouputs of the black box with the outputs of the encapsulated
476 If you wish to 'blackboxify' a C-like \emph{function},
477 you do not have the choice, you can only use the second mechanism,
478 namely encapsulation.
480 Obviously, the inheritance mechanism is more powerfull
481 and - when it is possible to use it - it demands less effort
482 because, as we will see, in \bbtk you can directly
483 link the accessors to the input and output data of the box
484 to the accessors of the inherited processing class,
485 as well as the procesing method of the black box
486 to the processing method of the inherited processing class,
487 very much like a callback mechanism.
488 %\itk and \vtk classes
490 % ==========================================
491 \subsubsection{Input and output accessors}
492 % ==========================================
494 When you encapsulate a processing class or a C function
495 or when you write down a black box from scratch,
496 you must access the inputs and outputs of the black box,
497 in order to interface it manually with your processing method
498 or simply write your processing code
499 (there are other cases in which you also need to access the
500 inputs and outputs, we will talk about them later).
502 The only thing you must know about the \CPP code generated
503 from your \xml or your \CPP macro-based description
504 is that when you declare an input
505 or an output of a black box then
506 two \emph{accessors} for this input or output are generated :
507 one to \emph{get} the value of the input or output and
508 one to \emph{set} it.
509 These accessors have normalized names :
512 \item The declaration of an {\bf input} called \texttt{NAME} and
513 of type \texttt{TYPE} generates the two accessors
514 \footnote{For the sake of simplicity, the parameters and return value are
515 shown here as if they were all passed by value.
516 However the actual code can use references.
517 The same way, the issue of const or non const methods is eluded here.
518 Different cases occur in practice.}:
520 \item \texttt{void bbSetInput<NAME>(<TYPE>);}
521 \item \texttt{<TYPE> bbGetInput<NAME>();}
523 \item The declaration of an {\bf output} called \texttt{NAME} and
524 of type \texttt{TYPE} generates the two accessors:
526 \item \texttt{void bbSetOutput<NAME>(<TYPE>);}
527 \item \texttt{<TYPE> bbGetOutput<NAME>();}
531 For example, declaring an input called \texttt{Image}
532 would generate the two accessors \texttt{bbSetInputImage} and
533 \texttt{bbGetInputImage}.
537 \item All \bbtk methods are prefixed by \texttt{bb}
538 to avoid conflicts with potential inherited methods.
539 \item An input and an output can have the same name (e.g. 'Image').
540 No conflict between accessors occur (e.g.
541 four distinct accessors are created :
542 \texttt{bbSetInputImage},
543 \texttt{bbGetInputImage},
544 \texttt{bbSetOutputImage} and
545 \texttt{bbGetOutputImage}).
549 % ==========================================
550 \subsection{Generate the black box skeleton}
551 % ==========================================
553 The command line application \bbCreateBlackBox
554 allows to create a skeleton \CPP or \xml files for a new black box.
555 It has a rather complex usage,
556 we recommand you use the graphical interface to it
557 which is accessible with \bbStudio menu \texttt{Tools $>$ Create black box}.
558 The interface looks like in fig. \ref{bbCreateBlackBox}.
561 \caption{\label{bbCreateBlackBox}Create Black Box interface}
563 \includegraphics[width=0.6\textwidth]{bbCreateBackBox.png}
567 You will have to give :
569 \item The {\bf name} of the box
570 \item The {\bf package} to which the box belongs (can we do it automatically ? LG : think about it)
571 \item The {\bf author}(s) of the box
572 \item A {\bf description} of the box
574 \item Its {\bf type}, either
576 \item Basic (inherits \texttt{AtomicBlackBox}, no particular Input/Output)
577 \item Widget (inherits \texttt{WxBlackBox}, has output 'Widget' of type 'wxWindow*')
578 \item VTK PolyDataAlgorithm (inherits \texttt{AtomicBlackBox} and a vtkPolyDataAlgorithm, has standard vtk I/O)
579 \item VTK ImageAlgorithm (inherits \texttt{AtomicBlackBox} and a vtkImageAlgorithm, has standard vtk I/O)
583 \item The output format of the file, either a C++ file or an XML file.
586 % ==========================================
587 \subsection{\texttt{XML} description of a box}
588 % ==========================================
590 % ==========================================
591 \subsubsection{General \texttt{xml} tags}
592 % ==========================================
594 Let us examine the \texttt{xml} file
595 describing the \texttt{Add} box of the \texttt{std} package :
597 \begin{file}{\texttt{packages/std/src/bbAdd.xml}}
600 <?xml version="1.0" encoding="iso-8859-1"?>
602 <blackbox name="Add">
604 <author>laurent.guigues@creatis.insa-lyon.fr </author>
605 <description>Adds its inputs </description>
606 <category>math </category>
608 <input name="In1" type="double" description="First number to add"/>
609 <input name="In2" type="double" description="Second number to add"/>
610 <output name="Out" type="double" description="Result"/>
613 bbSetOutputOut( bbGetInputIn1() + bbGetInputIn2() );
626 The tags and their role are easily understandable.
628 As the box is not a widget, we inherit implicitely from
629 \texttt{bbtk::AtomicBlackBox} (the default).
631 The only part of the file which needs a bit of explaination is
632 the body of the \texttt{process} tag, which describes the
633 actual code to execute in the box.
634 This code must be enclosed in a \texttt{<PRE></PRE>} tag
635 to tell the \xml parser not to interpret it as \xml instructions.
636 This is necessary to be able to use any symbol,
637 like the \texttt{<} and \texttt{>} which have a
638 special meaning in \xml.
639 In the case of the \texttt{Add} box, the process code
640 is very simple : remember that
641 \texttt{bbGetInputIn1()} is the
642 accessor to the input \texttt{In1} declared above and
643 \texttt{bbGetInputIn2()} is the
644 accessor to the input \texttt{In2};
645 the code simply adds the values of the two inputs
646 and sets the output \texttt{Out} with the resulting value.
648 To describe your own black boxes in \xml code,
649 you must modify the xml file generated by \bbCreateBlackBox :
652 \item Complete the description and author tags if you feel like.
653 \item Add the \texttt{\#include} directives to be put in the generated \texttt{.h} file
654 \item Create your inputs and outputs
655 \item Fill in the process tag
656 \item Fill in the constructor tag
657 \item Fill in the copyconstructor tag
658 \item Fill in the destructor tag
661 % ==========================================
662 \subsubsection{Writting new widget boxes in \xml}
663 % ==========================================
664 See the example \texttt{packages/wx/src/bbwxOutputText.xml}
666 \begin{file}{\texttt{packages/wx/src/bbwxOutputText.xml}}
669 <blackbox name="OutputText" widget>
671 <author>laurent.guigues at creatis.insa-lyon.fr</author>
672 <description>Text zone to be inserted into a window (wxStaticText)</description>
673 <category></category>
675 <input name="Title" type="std::string" description="Title prepended to the text"/>
676 <input name="In" type="std::string" description="Text"/>
679 bbSetOutputWidget( new wxStaticText ( bbGetWxParent() , -1 , _T("") ) );
681 </PRE></createwidget>
685 if (bbGetInputTitle()!="")
687 msg = bbGetInputTitle()+": " + bbGetInputIn();
691 msg = bbGetInputIn();
693 ((wxStaticText*)bbGetOutputWidget())->SetLabel( bbtk::std2wx( msg ) );
708 \item The attribute \texttt{widget} of the \texttt{blackbox} tag instructs
709 \bbfy that the box inherits from \texttt{bbtk::WxBlackBox}.
710 \item An output called \texttt{'Widget'} of type \texttt{wxWindow*} is
711 automatically declared (you do not have to do it).
712 \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
713 have been set with the newly created \texttt{wxWindow}.
714 Here we create a new \texttt{wxStaticText}.
715 The parent of the widget to create MUST BE the one provided by the method
716 \texttt{bbGetWxParent()} which returns a \texttt{wxWindow*}.
717 To update the static text after creation we simply call the \texttt{Process}
719 \item The body of the \texttt{process} method simply concatenates the
720 input \texttt{'Title'} (if non empty) and the input \texttt{'In'} and
721 updates the \texttt{wxStaticText}.
722 Remark that to get it, we use the \texttt{bbGetOutputWidget()} method
723 which returns a \texttt{wxWindow*} which we cast into a
724 \texttt{wxStaticText*} to use its specific method \texttt{SetLabel}.
727 More complex examples can be found in the \texttt{package/wx/src} folder.
729 % ==========================================
730 \subsubsection{Specific \texttt{xml} tags for \texttt{vtkImageAlgorithm} classes bbfication by inheritance}
731 % ==========================================
732 If you wish to bbfy a \vtk object which is a \texttt{vtkImageAlgorithm}
733 (such as \texttt{vtkImageGaussianSmooth}, \texttt{ImageAnisotropicDiffusion3D},
734 ...) we recommand you do it in \xml (you can have a look at the examples
735 in the \vtk core package 'src' folder).
736 The bbfication mechanism is inheritance.
738 You have to add the attribute \texttt{type="VTK\_ImageAlgorithm"}
739 to the \texttt{blackbox} tag :
741 <blackbox name="..." type="VTK_ImageAlgorithm">
744 You have to had an include tag which includes the vtk parent header, such as :
746 <include> vtkImageAnisotropicDiffusion3D.h </include>
749 You have to add the tag \texttt{vtkparent} which gives the \vtk parent of the box, e.g.:
751 <vtkparent> vtkImageAnisotropicDiffusion3D </vtkparent>
754 The \vtk algorithm input/ouput are wrapped directly using the
755 \texttt{special} attributes of the input and output tags.
756 A typical example is :
758 <input name="In" type="vtkImageData*" special="vtk input"
759 description="Input image"/>
760 <output name="Out" type="vtkImageData*" special="vtk output"
761 description="Output image"/>
763 The attribute \texttt{special="vtk input"} of the input 'In' definition
764 directly connects it to the input of the vtk object the box inherits.
765 No additional code is needed, the vtk object will directly receive
766 the value of this input.
767 The same mechanism hold for the output.
769 The parameters of the vtk object which are declared using
770 \texttt{vtkSetMacro} and \texttt{vtkGetMacro} can also be directly
771 wrapped using the attribute \texttt{special="vtk parameter"} of the input tag,
774 <input name="DiffusionThreshold" type="double" special="vtk parameter"
775 description="Difference threshold that stops diffusion"/>
777 The attribute \texttt{special="vtk parameter"}
778 of the input called \texttt{DiffusionThreshold} instructs \bbfy to
779 directly call the \texttt{SetDiffusionThreshold} and
780 \texttt{GetDiffusionThreshold}
781 methods of the vtk parent when needed.
784 For this mechanism to work,
785 the name of the \bbtk input MUST be the same than the name
786 of the \vtk parent parameter.
788 No \texttt{process} method has to be given,
789 \bbfy generates a process body for you, which simply calls the
790 \texttt{Update()} method of the vtk parent.
793 you can write your own \texttt{process} code which will overload
794 the default. Don't forget to call Update().
795 See \texttt{packages/vtk/src/bbvtkConeSource.xml} for an example.
797 % ==========================================
798 \subsubsection{Specific \texttt{xml} tags for \texttt{vtkPolyDataAlgorithm} classes bbfication by inheritance}
799 % ==========================================
800 If you wish to bbfy a \vtk object which is a \texttt{vtkPolyDataAlgorithm}
801 (such as \texttt{vtkConeSource}, ...)
802 we recommand you do it in \xml (you can have a look at the examples
803 in the \vtk core package 'src' folder).
804 The bbfication mechanism is inheritance.
806 You must use the same \xml tags and attributes than for wrapping a
807 \texttt{vtkImageAlgorithm} (see above) :
810 <blackbox name="..." type="VTK_PolyDataAlgorithm">
812 <vtkparent>the vtk Polydata class it inherits from</vtkparent>
813 <input name="..." type="vtkPolyData*" special="vtk input"
815 <output name="..." type="vtkPolyData*" special="vtk output"
817 <input name="..." type="double" special="vtk parameter"
822 % ==========================================
823 \subsubsection{Specific \texttt{xml} tags for \texttt{itk::ImageToImageFilter} classes bbfication by inheritance}
824 % ==========================================
830 % ==========================================
831 \subsubsection{\bbfy \texttt{xml} tags reference}
832 % ==========================================
834 See tables \ref{xml_tags}, \ref{xml_tags2}
835 % ==========================================
837 \caption{\label{xml_tags}
838 \bbfy \texttt{xml} tags reference (part 1)}
840 \begin{tabular}{|lcllm{6cm}|}
842 Tag & Attributes & Condition & Multiplicity & Description
845 \texttt{<blackbox>} & \texttt{name} & - & 1 & The name of the box \\ \hline
846 & \texttt{type} & - & 1 & The type of the box. In:
847 \{\texttt{standard} (default),
848 \texttt{ITK\_ImageToImageFilter},
849 \texttt{VTK\_ImageAlgorithm},
850 \texttt{VTK\_PolyDataAlgorithm}\} \\\hline
851 & \texttt{generic} & a) & 0-1 &
852 Generate the generic filter (see text)\\ \hline
853 & \texttt{widget} & - & 1 &
854 If present then the box inherits from \texttt{WxBlackBox}
855 (\texttt{AtomicBlackBox} if absent)
857 \texttt{<description>} & - & - & 0-n & The description of the box. Multiple occurrence are concatenated \\\hline
858 \texttt{<author>} & - & - & 0-n & The author of the box. Multiple occurrence are concatenated \\\hline
859 \texttt{<category>} & - & - & 0-1 & The box category (if more than one, they are separated with commas) see Tab \ref{categories}\\\hline
860 \texttt{<namespace>} & - & - & 0-1 & The namespace of the box.
861 Use \texttt{bbPACKAGE}, where \texttt{PACKAGE} is the name of the package\\\hline
862 \texttt{<include>} & - & - & 0-n & Additionnal file to include
863 (generates : \texttt{\#include 'value'})\\\hline
865 \texttt{<template>} & - & - & 0-n & Template parameter of the box. The template parameter list is generated in the order of appearance of the tag. \\\hline
867 \texttt{<itkparent>} & - & a) & 1 & The parent itk class (with namespace) \\\hline
869 \texttt{<vtkparent>} & - & b) & 1 & The parent vtk class \\\hline
871 \texttt{<input>} & \texttt{name} & - & 1 & The name of the input \\\hline
872 & \texttt{type} & - & 1 & The type of the input \\\hline
873 & \texttt{special} & - & 0-1 & In: \{\texttt{'itk input',
874 'vtk input', 'itk parameter', 'vtk parameter'}\} (see below).\\\hline
875 & \texttt{generic\_type} & c) & 0-1 & The ``generic'' type of the input (see text). \\\hline
881 \caption{\label{xml_tags2}
882 \bbfy \texttt{xml} tags reference (part 2)}
884 \begin{tabular}{|lcllm{6cm}|}
886 Tag & Attributes & Condition & Multiplicity & Description
888 \texttt{<output>} & \texttt{name} & - & 1 & The name of the output \\\hline
889 & \texttt{type} & - & 1 & The type of the output \\\hline
890 & \texttt{special} & - & 0-1 & In: \{\texttt{'itk output',
891 'vtk output'}\} (see below).\\\hline
892 & \texttt{generic\_type} & c) & 0-1 & The ``generic'' type of the output (see text).\\\hline
893 & \texttt{nature} & c) & 0-1 & The ``nature'' of the output (used for automatic GUI generation).\\\hline
894 \texttt{<process>} & - & - & 0-1 & The code of the processing method of the box. Must be put between clear tags : \texttt{<PRE></PRE>} \\\hline
895 \texttt{<createwidget>} & - & d) & 0-1 & The code of the widget creation
896 method of the box. Must be put between clear tags : \texttt{<PRE></PRE>}
898 \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
899 \texttt{<copyconstructor>} & - & - & 0-1 & The code of the user Copy Constructor of the box . Must be put between clear tags : \texttt{<PRE></PRE>} \\\hline
900 \texttt{<destructor>} & - & - & 0-1 & The code of the user Destructor of the box. Must be put between clear tags : \texttt{<PRE></PRE>} \\\hline
906 % ==========================================
908 \caption{\label{xml_tags-conditions}
909 \bbfy \texttt{xml} tags conditions}
911 \begin{tabular}{|ll|}
913 a) & \texttt{<blackbox type == 'ITK\_ImageToImageFilter'>} \\ \hline
914 b) & \texttt{<blackbox type == 'VTK\_ImageAlgorithm' or 'VTK\_PolyDataAlgorithm'>} \\ \hline
915 c) & \texttt{<blackbox type == 'ITK\_ImageToImageFilter'>} and
916 \texttt{<blackbox generic>} is present. \\ \hline
917 d) & \texttt{<blackbox widget>} is present \\ \hline
922 %\caption{\label{basic_parent}}
923 %\bbfy \texttt{Basic box parent}
925 %\begin{tabular}{|ll|}
927 %\texttt{bbtk::WxBlackBox}b) & If the blackbox associated to
928 %a \texttt{wxWindow} and is be able to return a pointer to it.... \\ \hline
929 %\texttt{bbtk::AtomicBlackBox} & Any other blackbox that doesn't return a pointer to a \texttt{wxWindow}%
936 % ==========================================
938 \caption{\label{categories} \texttt{Black Box} categories}
940 \begin{tabular}{|p{4cm}p{8cm}|}
942 \texttt{Category name} & : Meaning \\ \hline
944 \texttt{adaptor} & : Adaptor box \\ \hline
945 \texttt{application} & : Final application, end user intended \\ \hline
946 \texttt{atomic box} & : System category.
947 Automatically assigned to Atomic Black Boxes (c++ defined) \\ \hline
948 \texttt{complex box} & : System category.
949 Automatically assigned to Complex Black Boxes (script defined) \\ \hline
950 \texttt{command line} & : Script which defines a command line application (no embedded GUI, but command line imput parameters) \\ \hline
951 \texttt{demo} & : Demonstration \\ \hline
952 %\texttt{devel} & : Developer tool (bbCreatePackage.bbs, ...) \\ \hline
953 \texttt{dicom} & : DICOM aware box \\ \hline
954 \texttt{example} & : Example script showing a box use-case \\ \hline
955 \texttt{filter} & : Filtering box \\ \hline
956 \texttt{image} & : Image processing related box \\ \hline
957 % \texttt{interaction} & : \\ \hline
958 \texttt{math} & : Mathematical operations\\ \hline
959 \texttt{mesh} & : Mesh processing related box \\ \hline
960 \texttt{misc} & : A box that cannot be put in other category ! \\ \hline
961 \texttt{read/write} & : Box that read or write data from or to disk \\ \hline
962 \texttt{viewer} & : Box which displays some data \\ \hline
963 \texttt{widget} & : Piece of graphical interface \\ \hline
965 \texttt{3D object creator} & : Sophisticated 3D widget \\ \hline
966 \texttt{toolsbbtk} & : \bbtk development tools (GUICreatePackage, GUICreateBlackBox,...) \\ \hline
971 % ==========================================
973 \caption{\label{kinds}\texttt{Black box} kinds}
975 \begin{tabular}{|p{4cm}p{8cm}|}
977 \texttt{Kind} & Use as : \\ \hline & \\ \hline
978 \texttt{ADAPTOR} & \\ \hline
979 \texttt{DEFAULT\_ADAPTOR} & \\ \hline
980 \texttt{WIDGET\_ADAPTOR} & \\ \hline
981 \texttt{DEFAULT\_WIDGET\_ADAPTOR} & \\ \hline
982 \texttt{GUI} & \\ \hline
983 \texttt{DEFAULT\_GUI} & \\ \hline
984 \texttt{ALL} & If kind='ALL' then sets the level for all kinds\\ \hline
989 % ==========================================
991 \caption{\label{nature}Input/output \texttt{natures}}
993 \begin{tabular}{|ll|}
995 \texttt{Nature} & : Associated \texttt{DEFAULT\_GUI} box \\ \hline
998 \texttt{'file name'} & \texttt{wx::FileSelector}\\ \hline
999 \texttt{'directory name'} & \texttt{wx::DirectorySelector}\\ \hline
1000 % \texttt{'file extension'} & \\ \hline
1001 \texttt{'colour'} & \texttt{wx::ColourSelector}\\ \hline
1002 % \texttt{pixel type} & \\ \hline
1003 % \texttt{image dimension} & \\ \hline
1004 % \texttt{image index} & \\ \hline
1005 % \texttt{image size} & \\ \hline
1006 % \texttt{voxel size} & \\ \hline
1020 % ==========================================
1021 \subsection{\CPP description of a box}
1022 % ==========================================
1024 Almost everything is performed using macros.
1026 For a quick start, the best you have to do is to run \texttt{bbStudio}, then in the menu \texttt{Tools}, choose the item
1027 \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.
1029 % ==========================================
1030 \subsubsection{Black box basic header file (.h)}
1031 % ==========================================
1033 Let's have a look at the file \texttt{packages/std/bbstdMakeFileName.h}
1035 \begin{file}{\texttt{packages/std/bbstdMakeFileName.h}}
1038 #ifndef __bbstdMakeFileName_h_INCLUDED__
1039 #define __bbstdMakeFileName_h_INCLUDED__
1041 #include "bbtkAtomicBlackBox.h"
1045 class MakeFileName : public bbtk::AtomicBlackBox
1047 BBTK_BLACK_BOX_INTERFACE(MakeFileName,bbtk::AtomicBlackBox);
1048 BBTK_DECLARE_INPUT(Directory, std::string);
1049 BBTK_DECLARE_INPUT(File, std::string);
1050 BBTK_DECLARE_INPUT(Extent, std::string);
1051 BBTK_DECLARE_OUTPUT(Out, std::string);
1052 BBTK_PROCESS(DoProcess);
1055 virtual void bbUserConstructor();
1058 BBTK_BEGIN_DESCRIBE_BLACK_BOX(MakeFileName,bbtk::AtomicBlackBox);
1059 BBTK_NAME("MakeFileName");
1060 BBTK_AUTHOR("jpr@creatis.insa-lyon.fr");
1061 BBTK_CATEGORY("misc");
1062 BBTK_DESCRIPTION("Makes a kosher file name");
1063 BBTK_INPUT(MakeFileName,Directory,"Directory Name",std::string,
1065 BBTK_INPUT(MakeFileName,File, "File Name", std::string,
1067 BBTK_INPUT(MakeFileName,Extent, "Extention", std::string,
1070 BBTK_OUTPUT(MakeFileName,Out,"Full File Name",std::string,"file name");
1071 BBTK_END_DESCRIBE_BLACK_BOX(MakeFileName);
1074 // EO namespace bbstd
1076 #endif // __bbstdMakeFileName_h_INCLUDED__
1080 It includes \texttt{bbtkAtomicBlackBox.h}.
1081 The box class is \texttt{MakeFileName}.
1082 It inherits \texttt{bbtk::AtomicBlackBox}.
1083 It is in the \texttt{bbstd} namespace :
1084 each box of a given package, say PACK, must be inserted into
1085 the namespace \texttt{bbPACK}.
1087 The macro \texttt{BBTK\_BLACK\_BOX\_INTERFACE}
1088 declares the interface of the class : constructor, destructor,
1089 standard methods (e.g. New), etc.
1090 The following macros then declare inputs and outputs of the box,
1092 The macro \texttt{BBTK\_PROCESS} then declares which method to call
1093 when processing the box (the process callback).
1094 The callback itself is declared just below.
1096 The line \texttt{virtual void bbUserConstructor();} then
1097 overloads the virtual method \texttt{bbUserConstructor}
1098 which is used to perform specific things at construction time.
1099 You can also overload \texttt{bbUserCopyConstructor}
1100 and \texttt{bbUserDestructor} with the same signature.
1101 The black box interface macros are summarized in table
1102 \ref{CPPInterfaceBasicMacros}.
1104 % ==========================================
1106 \caption{\label{CPPInterfaceBasicMacros}Black box interface \CPP macros}
1107 \begin{tabular}{p{\textwidth}}\hline
1108 \\ \small \texttt{BBTK\_BLACK\_BOX\_INTERFACE(BOX\_NAME,BBTK\_PARENT)} :
1109 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!
1110 \\ \small \texttt{BBTK\_VTK\_BLACK\_BOX\_INTERFACE(CLASS,BBTK\_PARENT,VTK\_PARENT) } : Black box interface for \vtk object inherited boxes
1112 \\ \small \texttt{BBTK\_ITK\_BLACK\_BOX\_INTERFACE(CLASS,BBTK\_PARENT,ITK\_PARENT) } : Black box interface for \itk object inherited boxes
1114 \\ \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*, ...).
1115 \\ \small \texttt{BBTK\_DECLARE\_INHERITED\_INPUT(NAME,TYPE,GETMETHOD,SETMETHOD)} : Declares an input of the box which wraps the \texttt{GETMETHOD / SETMETHOD} accessors
1116 \\ \small \texttt{BBTK\_DECLARE\_VTK\_INPUT(NAME,TYPE)} :
1117 Declares a vtk object-inherited input
1118 \\ \small \texttt{BBTK\_DECLARE\_VTK\_IMAGE\_ALGORITHM\_INPUT(NAME,TYPE)} : Declares a vtkImageAlgorithm-inherited input
1119 \\ \small \texttt{BBTK\_DECLARE\_VTK\_POLY\_DATA\_ALGORITHM\_INPUT(NAME,TYPE)} : Declares a vtkPolyDataAlgorithm-inherited input
1120 \\ \small \texttt{BBTK\_DECLARE\_ITK\_INPUT (NAME,TYPE)} :
1121 Declares a itk object-inherited input
1122 \\ \small \texttt{BBTK\_DECLARE\_OUTPUT (NAME,TYPE) } :
1123 Declares an output of the box
1124 \\ \small \texttt{BBTK\_DECLARE\_INHERITED\_OUTPUT(NAME,TYPE,GETMETHOD,SETMETHOD)} :
1125 Declares an output of the box which wraps the \texttt{GETMETHOD / SETMETHOD} accessors
1126 \\ \small \texttt{BBTK\_DECLARE\_VTK\_OUTPUT(NAME,TYPE)} :
1127 Declares a vtk object-inherited output
1128 \\ \small \texttt{BBTK\_DECLARE\_ITK\_OUTPUT(NAME,TYPE)} :
1129 Declares a itk object-inherited output
1130 \\ \small \texttt{BBTK\_DECLARE\_VTK\_PARAM(VTK\_PARENT,NAME,TYPE)} :
1131 Declares an input corresponding to an inherited vtk parameter
1132 (you know, the ones that are declared by vtkSetMacro/vtkGetMacro). Its name must be the same than the vtk parameter name.
1133 \\ \small \texttt{BBTK\_DECLARE\_ITK\_PARAM(NAME,TYPE)} :
1134 Declares an input corresponding to an inherited itk parameter
1135 \\ \small \texttt{BBTK\_PROCESS(METHOD\_NAME)} :
1136 Defines the method to call when the box is processed.
1137 \\ \small \texttt{BBTK\_VTK\_PROCESS} : Defines AND implements the default processing method for vtk
1138 inherited black boxes (calls \texttt{vtkParent::Update})
1139 \\ \small \texttt{BBTK\_ITK\_PROCESS} : Defines AND implements the default processing method for itk
1140 inherited black boxes (calls \texttt{itkParent::Update})
1145 %================================================
1147 After the black box class declaration
1148 then comes a zone in which you describe your black box,
1149 between the macros \texttt{BBTK\_BEGIN\_DESCRIBE\_BLACK\_BOX}
1150 and \\ \texttt{BBTK\_END\_DESCRIBE\_BLACK\_BOX}.
1152 The macro \texttt{BBTK\_BEGIN\_DESCRIBE\_BLACK\_BOX}
1153 actually starts the declaration of another class,
1154 called \texttt{\textless BOXNAME \textgreater Descriptor}
1155 (in our case \texttt{MakeFileNameDescriptor}).
1156 The descriptor of a black box :
1158 \item has only one instance, which is stored in the package
1159 \item provides information about the box type (author, description, ...)
1160 which is used for documentation.
1161 \item provides information about the box I/Os, mainly their types
1162 (uses RTTI : \texttt{std::type\_info} ).
1163 \item is responsible for creating new instances of the box it describes.
1167 the macros which are between \texttt{BBTK\_BEGIN\_DESCRIBE\_BLACK\_BOX}
1168 and \texttt{BBTK\_END\_DESCRIBE\_BLACK\_BOX}
1169 provide the box name (the string),
1170 its authors, description, category,
1171 the descriptions of its inputs and outputs.
1172 Black box descriptor related
1173 are described in table \ref{CPPDescriptorBasicMacros}.
1175 % ==========================================
1177 \caption{\label{CPPDescriptorBasicMacros}Black box descriptor \CPP macros}
1178 \begin{tabular}{p{\textwidth}}\hline
1179 \\ \small \texttt{BBTK\_BEGIN\_DESCRIBE\_BLACK\_BOX(BOX\_NAME,BBTK\_PARENT) } :
1180 Yes, we know it's redundant with public inheritance ... That's why we allow you to describe your class in xml format!
1181 All the following items will be used in the Help interface; describe them carefully (i.e. in a Human understandable way!).
1182 \\ \small \texttt{BBTK\_ADAPTOR} : Declares that the box is an adaptor
1183 \\ \small \texttt{BBTK\_DEFAULT\_ADAPTOR} : Declares that the box is the default adaptor for its I/O types
1184 \\ \small \texttt{BBTK\_NAME(STRING)} : The name of your box
1185 \\ \small \texttt{BBTK\_AUTHOR(STRING)} : The author(s) (better you put e-mail adresses)
1186 \\ \small \texttt{BBTK\_DESCRIPTION(STRING)} : Brief description of what does the box
1187 \\ \small \texttt{BBTK\_CATEGORY(STRING)} : Box categories, semicolon separated (see table \ref{categories})
1188 \\ \small \texttt{BBTK\_INPUT(BOX\_NAME,INPUT\_NAME,DESCRIPTION,CPP\_TYPE,INPUT\_NATURE)}
1190 \item \texttt{BOX\_NAME} : The current black box name.
1191 \item \texttt{INPUT\_NAME} : The input name
1192 \item \texttt{DESCRIPTION} (string) : A brief description of what the parameter is used for.
1193 \item \texttt{CPP\_TYPE} : The \CPP type of the input (e.g. double, std::string, vtkImageData*, ...)
1194 \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.
1195 Supply an empty string ("") if you don't care.
1197 \\ \small\texttt{BBTK\_OUTPUT(BOX\_NAME,OUTPUT\_NAME,DESCRIPTION,CPP\_TYPE)} : The same
1198 \\ \small \texttt{BBTK\_END\_DESCRIBE\_BLACK\_BOX(BOX\_NAME)}
1199 \\ \hline\end{tabular}
1202 % ==========================================
1203 \subsubsection{Black box basic implementation file (.cxx)}
1204 % ==========================================
1206 Now let's have a look at the file \texttt{packages/std/bbstdMakeFileName.cxx}
1208 \begin{file}{\texttt{packages/std/bbstdMakeFileName.cxx}}
1211 #include "bbstdMakeFileName.h"
1212 #include "bbstdPackage.h"
1217 BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,MakeFileName);
1218 BBTK_BLACK_BOX_IMPLEMENTATION(MakeFileName,bbtk::AtomicBlackBox);
1220 void MakeFileName::bbUserConstructor()
1222 bbSetInputDirectory("");
1224 bbSetInputExtent("");
1227 void MakeFileName::DoProcess()
1232 // EO namespace bbstd
1236 The first line includes the header file.
1237 The second one includes the \texttt{std} package header file.
1238 This file is automatically generated during cmake configuration :
1239 for a package named \texttt{\textless PACK \textgreater}, \cmake
1240 creates the files \texttt{bb\textless PACK \textgreater Package.h}
1241 and \texttt{bb\textless PACK \textgreater Package.cxx}.
1242 The header is to be included in any box implementation file and
1243 the second one is compiled in the package library.
1245 The macro \texttt{BBTK\_ADD\_BLACK\_BOX\_TO\_PACKAGE}
1246 then registers the box \texttt{MakeFileName} into the package \texttt{std}.
1248 The macro \texttt{BBTK\_BLACK\_BOX\_IMPLEMENTATION} is the
1249 mirror macro of the macro \texttt{BBTK\_BLACK\_BOX\_INTERFACE} that
1250 was used in the header : it implements the methods declared in the header.
1252 We then need to write the body of \texttt{bbUserConstrutor}
1253 and of the processing callback (here \texttt{DoProcess}).
1255 That's all we need for a 'basic' black box.
1256 The implementation related macros are summarized in table \ref{CPPImplementationBasicMacros}.
1258 % ==========================================
1260 \caption{\label{CPPImplementationBasicMacros}Black box implementation \CPP macros}
1261 \begin{tabular}{p{\textwidth}}\hline
1262 \\ \small \texttt{BBTK\_ADD\_BLACK\_BOX\_TO\_PACKAGE(PACKAGE\_NAME,BOX\_NAME)}
1263 \\ \small \texttt{BBTK\_BLACK\_BOX\_IMPLEMENTATION(BOX\_NAME,BBTK\_PARENT)}
1268 % ==========================================
1269 \subsubsection{Widget black boxes \CPP macros}
1270 % ==========================================
1272 See the example of \texttt{package/wx/src/bbwxLayoutLine.h\textbar cxx}.
1273 The only differences with a non-widget black box are :
1275 \item The header must include \texttt{bbtkWxBlackBox.h} and \\
1276 the class must inherit \texttt{bbtk::WxBlackBox}.
1277 \item The black box interface must declare the widget creation callback
1278 with the macro \texttt{BBTK\_CREATE\_WIDGET(CALLBACK)}.
1279 The callback must be declared in the interface and implemented.
1280 \item You can overload the method \texttt{void bbUserOnShow()} which
1281 is called just after the \texttt{wxWindow} has been shown, e.g.
1282 to refresh its content. Note that \texttt{Layout} widget \emph{MUST}
1283 overload this method and call \texttt{bbUserOnShowWidget(INPUT\_NAME)}
1284 for all inputs which correspond to an 'embedded' window
1285 (the 'Widget1' ... 'WidgetN' inputs,
1286 see \texttt{package/wx/src/bbwxLayoutLine.cxx})
1289 % ==========================================
1290 \subsubsection{VTK black boxes \CPP macros}
1291 % ==========================================
1293 See the example of \texttt{package/wx/src/bbvtkMarchingCubes.h\textbar cxx}.
1294 The macros are summarized in table \ref{CPPInterfaceBasicMacros}.
1296 % ==========================================
1297 \subsubsection{Template black boxes \CPP macros}
1298 % ==========================================
1300 You can write down black box classes \emph{templates}.
1301 However, only \emph{actual} classes, that is instanciated templates,
1302 can be inserted into a package.
1304 The files \texttt{package/std/src/bbstdStringTo.h\textbar cxx}
1305 provide an example of a class template with one template parameter.
1307 The files \texttt{package/std/src/bbstdCast.h\textbar cxx}
1308 provide an example of a class template with two template parameters.
1310 Class templates related macros are summarized in table \ref{CPPTemplateMacros}.
1311 % ==========================================
1313 \caption{\label{CPPTemplateMacros}Black box templates-related \CPP macros}
1314 \begin{tabular}{p{\textwidth}}\hline
1316 \\ \small\texttt{BBTK\_TEMPLATE\_BLACK\_BOX\_INTERFACE(BOX\_NAME,BBTK\_PARENT, TEMPLATE\_PARAMETER)}
1317 \\ \small\texttt{BBTK\_TEMPLATE2\_BLACK\_BOX\_INTERFACE(BOX\_NAME,BBTK\_PARENT, TEMPLATE\_PARAMETER\_1, TEMPLATE\_PARAMETER\_2)}
1318 \\ \small\texttt{BBTK\_BEGIN\_DESCRIBE\_TEMPLATE\_BLACK\_BOX(BOX\_NAME,BBTK\_PARENT)} : Note that in the descriptor, the template parameter name is \texttt{T}
1319 \\ \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}
1320 \\ \small\texttt{BBTK\_END\_DESCRIBE\_TEMPLATE\_BLACK\_BOX(BOX\_NAME)}
1321 \\ \small\texttt{BBTK\_END\_DESCRIBE\_TEMPLATE2\_BLACK\_BOX(BOX\_NAME)}
1322 \\ \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.
1323 \\ \small\texttt{BBTK\_TEMPLATE2\_INPUT(BOX\_NAME,INPUT\_NAME,DESCRIPTION,CPP\_TYPE, INPUT\_NATURE)} : Same remark
1324 \\\small \texttt{BBTK\_TEMPLATE\_OUTPUT(BOX\_NAME,OUTPUT\_NAME,DESCRIPTION,CPP\_TYPE)} : Same remark
1325 \\ \small\texttt{BBTK\_TEMPLATE2\_OUTPUT(BOX\_NAME,OUTPUT\_NAME,DESCRIPTION,CPP\_TYPE)} : Same remark
1326 \\ \small\texttt{BBTK\_BLACK\_BOX\_TEMPLATE\_IMPLEMENTATION(BOX\_NAME,BBTK\_PARENT)}
1327 \\ \small\texttt{BBTK\_BLACK\_BOX\_TEMPLATE2\_IMPLEMENTATION(BOX\_NAME,BBTK\_PARENT)}
1328 \\ \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})
1329 \\ \small\texttt{BBTK\_ADD\_TEMPLATE2\_BLACK\_BOX\_TO\_PACKAGE(PACKAGE\_NAME,BOX\_NAME, TEMPLATE\_PARAMETER\_1\_VALUE, TEMPLATE\_PARAMETER\_2\_VALUE)} :
1330 The same for two template parameters (see e.g. \texttt{package/std/src/bbstdCast.cxx})
1338 {\bf IMPORTANT NOTE ON TEMPLATE BLACK BOXES NAMES:}
1340 Two different boxes registered in a package must have two different names.
1341 Hence when using black box classes templates,
1342 one must give different names to two instanciations of the template on
1343 two different types.
1344 This is typically done with inserting the template parameter type name in the
1345 black box class name.
1346 An example is provided in \texttt{package/std/src/bbstdStringTo.h} :
1349 BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(ToString,bbtk::AtomicBlackBox);
1350 BBTK_NAME(bbtk::HumanTypeName<T>()+"ToString");
1352 BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(ToString);
1355 To get the string corresponding to the name of a \CPP type
1356 (here the template parameter \texttt{T})
1357 one must use the template \bbtk function \texttt{bbtk::HumanTypeName<T>()}
1358 \footnote{\texttt{HumanTypeName} returns a human readable type name,
1359 without special chars such as \texttt{::} or \textless. For example the
1360 human readable type name of \texttt{std::vector\textless std::string \textgreater} is \texttt{VectorOfString}. The 'inhuman' type name is given
1361 by the function \texttt{bbtk::TypeName<T>()}.}.
1362 It is then concatenated to the name \texttt{ToString}.
1363 This thus gives the name \texttt{IntToString} to the black box \texttt{ToString\textless int \textgreater},
1364 \texttt{DoubleToString} to the black box \texttt{ToString\textless double \textgreater}, etc.
1366 You can also use \texttt{bbtk::HumanTypeName<T>()}
1367 in the macro \texttt{BBTK\_DESCRIPTION}, like for example:
1369 BBTK_DESCRIPTION("Converts a "+bbtk::HumanTypeName<T>()+" ("
1370 +bbtk::TypeName<T>()+") into a string");
1374 % ==========================================
1375 \subsubsection{ITK black boxes \CPP macros}
1376 % ==========================================
1378 It is a special cas of black box templates with also
1379 special macros for itk object inherited black boxes.
1381 See the example of \texttt{package/wx/src/bbitkBinaryThresholdImageFilter.h\textbar cxx},
1382 the tables \ref{CPPInterfaceBasicMacros} and \ref{CPPTemplateMacros}.
1385 there is also a mechanism for making
1386 ``generic'' untemplatized itk black boxes.
1387 See the example in the file above.
1389 % ==========================================