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