1 % ==========================================
2 \documentclass[11pt,final,a4paper]{article}
5 \title{The Black Box Toolkit\\User's Guide}
7 \author{Laurent Guigues}
9 % ==========================================
11 % ==========================================
14 % ==========================================
16 % ==========================================
18 % ==========================================
20 \section{What is {\bf bbtk} ?}
21 % ==========================================
22 \BBTK(\bbtkns) is a set of tools
23 (\CPP libraries and executables)
24 providing a \CPP framework for the definition
25 of elementary processing \emph{units}, called {\bf black boxes},
26 and the definition and execution of processing \emph{chains}
27 made up of these black boxes.
29 % ==========================================
30 \subsection{The black box philosophy}
31 % ==========================================
32 \href{http://en.wikipedia.org/wiki/Black_box_\%28disambiguation\%29}{Wikipedia}
33 defines a {\bf black box} as
34 \emph{``any component in a system in which only the input and output
35 characteristics are of interest, without regard to its internal mechanism
38 \BBTK provides a systematic framework
39 to encapsulate (or ``wrap'') any
40 existing \texttt{C} or \CPP processing code into an object
41 (a black box) having a {\bf generic symbolic interface}, where
44 \item{\bf generic} means that the interface is \emph{the same}
45 for all boxes. Hence one does not need to know which particular
46 method allows, say, to set a particular input or
47 get a particular output of the box.
48 One can use a black box in a purely abstract way.
49 \item{\bf symbolic} means a particular
50 input or output is referenced by a 'name', that is by a symbol
51 which identifies the input or output.
52 It also means that symbolic information (text!) is
53 attached to a box: description of the box, author,
54 description of its inputs and outputs, etc.
57 (in fact, genericity is achieved because the interface is symbolic.
58 I let you think about this\dots)
60 Of course, symbolic data attached to box can be
61 {\bf queried}: what are the inputs/outputs of the box ?
62 what are their type ? description ? etc.
63 This allows {\bf automatic documentation} of boxes.
65 The abstract definition of black boxes is the most basic
66 aspect of \BBTK architecture.
67 Another key aspect is the groupement of black boxes into
68 so called {\bf packages},
69 which are \emph{dynamic libraries} which can also
70 be queried, in particular about the boxes they provide.
71 The package structure then offers a mechanism which
72 is like a \emph{'plug-in'} mechanism.
73 \BBTK provides the methods to load a package at run-time,
74 and create instances of the boxes it contains.
76 These two mechanisms (black boxes and packages)
77 then gives the way to:
80 \item The definition of an {\bf interpreted language},
81 which allows to manipulate packages and boxes very easily in symbolic way.
82 \BBTK provides one: \bbi (the Black Box Interpreter).
83 \item {\bf Automatic documentation} of existing packages.
84 \texttt{html} documentation of packages is proposed by
85 the \bbdoc application.
88 Finally, these different components allow {\bf efficient}:
91 \item {\bf capitalization and reuse} of existing processings,
92 including {\bf documentation}
93 \item {\bf testing, prototyping} in a very simple script language
94 \item {\bf inter-operability} between atomic processings which
95 have been written by different persons, using different libraries, etc.
98 % ==========================================
99 \subsection{\bbtk components}
100 % ==========================================
103 \item A \CPP {\bf\emph{library}} - called \bbtk - which defines a framework
104 (abstract classes) to develop black boxes and to store them into
105 dynamic libraries, called black box \emph{packages}.
106 \item Different {\bf\emph{black box packages}}:
108 \item {\bf\emph{std}}: the 'standard' package including basic useful boxes.
109 \item {\bf\emph{wx}}: basic graphical interface elements (widgets: sliders, buttons, etc. based on the \texttt{wxWidgets} library).
110 \item {\bf\emph{itk}}: the basic image processing package, based on the \texttt{itk} library.
111 \item {\bf\emph{vtk}}: the basic image and surfaces processing package, based on the \texttt{vtk} library.
112 \item {\bf\emph{wxvtk}}: widget boxes based on the \texttt{vtk} library.
113 \item {\bf\emph{itkvtk}}: boxes to convert \texttt{itk} structures into \texttt{vtk} structures and conversally.
115 \item An {\bf\emph{interpreter}}, called \bbi, which allows to
116 load black box packages and to define and execute
117 processing chains by connecting various black boxes of the already loaded packages.
118 \item {\bf\emph{Utilities}}:
120 \item \bbfy generates the \CPP code of a black box from a
121 description file written in \texttt{xml}.
122 \item \bbdoc generates the html documentation of a black box package
123 (author, description, description of its black boxes:
124 author, description, inputs, outputs, and so on).
125 \item \bbCreatePackage creates a directory on disk which contains the basic files to start the development of a new black box package.
129 The general architecture of \BBTK
130 is shown in figure \ref{bb-architecture}.
133 \caption{\label{bb-architecture}\BBTK architecture}
135 \includegraphics[width=0.6\textwidth]{bb-architecture.png}
139 % ==========================================
140 \subsection{Structure of this guide}
141 % ==========================================
143 This guide is divided into two parts.
145 The first part (\ref{bbi})
146 is devoted to the use of the \emph{black box interpreter} \bbi.
147 This is the highest level of use of the toolkit, which
148 allows to create and execute processing chains by connecting
149 black boxes of existing packages.
151 The second part (\ref{cpp}) explains how to
152 use the black box toolkit framework in \CPP code,
153 typically to develop large applications which
154 involve complex graphical interfaces.
157 % ==========================================
158 % ==========================================
159 % ==========================================
160 % ==========================================
161 % ==========================================
162 % ==========================================
164 \section{The black box interpreter (bbi)}
166 % ==========================================
168 % ==========================================
169 %\subsection{Structure of this part}
170 % ==========================================
172 Using the black box interpreter is very simple.
173 Everything is done with only a few commands.
174 The philosophy of this part is also very simple:
175 it introduces the \bbi commands using examples,
176 starting with the most simple commands.
177 The first section of this part
178 (\ref{bbi-getting-started})
179 is designed like a tutorial,
180 which progressively introduces all the concepts of \bbi.
181 We suggest you run \bbi and follow the examples,
182 to see how it works in practice.
183 At the end of this section,
184 you will be able to use \bbi and write
185 own black box processing scripts.
188 the section \ref{bbi-more-on}
189 (called \emph{more on...})
190 goes deeper into various issues of \bbi.
191 Read it at your convenience,
192 either linearly to learn more about \bbi,
193 or in random order to get an answer
194 to a particular question.
196 Finally, the section \ref{bbi-reference}
197 summarizes all the commands of \bbi,
198 their parameters and effect.
199 Use it as a reference.
201 % ==========================================
202 \subsection{Getting started}
203 \label{bbi-getting-started}
204 % ==========================================
205 \subsubsection{Creating and executing black boxes}
206 % ==========================================
208 To run the black box interpreter,
209 open a console and type \texttt{bbi}
210 or double click on the application icon.
211 You get a message and a prompt:
214 BBI (Black Box Interpreter) - bbtk "1.0.0" - (c) Creatis 2007
223 you get the list of the commands of the interpreter:
249 To get help on a particular command type \texttt{help <command-name>},
259 Quits the program (during script execution it stops the complete execution)
262 The \texttt{help} command has multiple usages.
263 It is used to get help on almost anything in \bbi !
264 Type \texttt{'help help'} to get help on the \texttt{help} command itself:
269 (2) help <command name>
270 (3) help packages [all]
271 (4) help <package name> [all]
272 (5) help <black box type>
273 (6) help <black box name>
275 (1) Lists all available commands;
276 (2) Prints help on a particular command;
277 (3) Lists the packages loaded and their black boxes.
278 Add 'all' to list adaptors;
279 (4) Prints short help on the black boxes of a package.
280 Add 'all' to include adaptors;
281 (5) Prints full help on a black box type;
282 (6) Prints information on the inputs, outputs and connections of a black box instance.
285 At start \bbi does not know any black box.
286 If you type \texttt{'help packages'}, which is
287 the third form of the \texttt{help} command, you get:
294 which means that \bbi only knows one package
295 (library of black boxes) called \texttt{user}
296 and which contains a black box called \texttt{workspace}.
297 The \texttt{user} package is an internal package to \bbi,
298 which stores user-defined black box types.
299 At start, it already contains
300 one box, called \texttt{workspace}.
301 \texttt{workspace} is a special type of black box,
302 called complex black box, whose purpose is
303 to store other black boxes.
304 Any black box you create in \bbi is stored
305 in \texttt{workspace}
306 (this will be explained in details in sections
307 \ref{bbi-writing-scripts} and
308 \ref{bbi-more-on-complex-black-boxes}).
310 If you type \texttt{'help workspace'}, you get:
313 Complex Black Box <user::workspace>
321 In the text displayed,
322 the \texttt{user::} prepended to the name \texttt{workspace}
323 means that the box \texttt{workspace}
324 belongs to the \texttt{user} package.
325 Then comes a description and three lines which
326 tell that \texttt{workspace} does not have any input
327 nor output nor boxes yet.
329 In order to let \bbi know of some black boxes,
330 you must load another package.
331 The \texttt{std} package is the ``standard'' package,
332 which contains basic useful black boxes.
344 you get something like:
354 Now \bbi knows the package \texttt{std} and the black boxes it provides,
355 such as the \texttt{'Add'} box. Remark that the
356 content of \texttt{std} may vary from one version to another
357 as new black boxes might be added to it.
367 By: laurent.guigues@creatis.insa-lyon.fr
369 'In1' <double>: First number to add
370 'In2' <double>: Second number to add
371 'ProcessMode' <int> : Set the process mode of the box (0=Pipeline | 1=Always | 2=Reactive)
373 'Out' <double>: Result
377 the \texttt{std::} prepended to the name \texttt{Add}
378 means that the box \texttt{Add}
379 belongs to the \texttt{std} package.
380 Then comes a description
381 (the one which was provided by the author of the box),
382 the author(s) of the box (usually e-mail adress(es)).
383 Finally comes the lists of inputs and outputs of the box.
384 For each input or output, \bbi provides
385 its \emph{name} (between quotes, e.g. \texttt{'ProcessMode'}),
386 its \emph{type} (between \texttt{<>}, e.g. \texttt{<int>})
388 Remark that the box \texttt{Add} is not a 'complex' black box
389 but an 'atomic' box, hence its help does not
390 mention any information concerning possible internal boxes.
392 You can create an \emph{instance} of an \texttt{Add} box by
393 the command \texttt{new}:
398 The \texttt{'a'} at the end is the \emph{name} of the instance,
399 which will be used to reference it later.
400 It is important to make the difference between box \emph{types}
401 and \emph{instances} of box types.
402 The \texttt{Add} box of the package \texttt{std} is in fact
403 a \emph{type} of box, like \texttt{int} is a type of data
404 in \texttt{C} langage. The \texttt{new} command allows to create
405 an instance of a box type, exactly like \texttt{int i;} in
406 a \texttt{C} code declares a variable of type \texttt{int} whose
408 Of course, like in \texttt{C} Language, you can declare multiple boxes of the
411 After the creation of the box \texttt{a}, type:
418 Complex Black Box <user::workspace>
427 which means that \bbi's workspace now contains a black box
428 of type \texttt{std::Add} and name \texttt{a}.
430 Now look back at the help on \texttt{Add} boxes:
431 you can see that this type of box has two inputs,
432 with name \texttt{In1} and \texttt{In2},
433 and an output, with name \texttt{Out}.
435 You can set the input \texttt{In1}
436 of the \texttt{Add} box \texttt{a} to the value $1$
442 Similarly, setting the input \texttt{In2} of \texttt{a} to the value $2$
448 And you print the output \texttt{Out} of the box \texttt{a} with:
450 > print "result=$a.Out$"
454 In the string passed to the \texttt{print} command,
455 each substring enclosed between a couple of \$ is considered
456 as the name of an output of a box.
457 To process this special substrings, \bbi does:
459 \item Processes the box if needed (see below)
460 \item Converts the output of the box to a string if possible
462 \item Substitutes the result in the string to print
465 Box processing is needed if:
467 \item at least input has changed since last processing or
468 \item the input \texttt{'ProcessMode'} of the box is set to
469 \texttt{1}, which forces box reprocessing.
472 Note that all boxes have the input \texttt{'ProcessMode'}.
474 Another way to process the box \texttt{a} is to issue the command:
479 however this command does not display anything (except if the
480 box itself displays something in its processing).
481 It just processes the box if needed.
482 This command is used to execute boxes that do not have any output,
483 such as boxes that write something to a file or, display a
484 graphical interface, and so on.
492 % ==========================================
497 \item The \texttt{load} command allows to load a package.
498 \item \texttt{help} gives help on:
500 \item Available commands if you just type \texttt{help}.
501 \item A particular command if you type \texttt{help <command-name>}.
502 \item All available packages and their boxes (without description) if you type \texttt{help packages}.
503 \item A particular package and its boxes (with brief description) if you type \texttt{help <package-name>}.
504 \item A particular black box type (with full description) if you type \texttt{help <box-type-name>}. In particular, \texttt{help workspace} displays information on the content of the \texttt{'workspace'} black box, which stores the boxes created by the user (by \texttt{new}).
506 %\item \texttt{list} displays the list of black box instances created so far (by \texttt{new}).
507 \item \texttt{new} creates an instance of a black box.
508 \item \texttt{set} sets the value of an input of a black box.
509 \item In all \bbi, to reference the input called \texttt{i}
510 of a black box called \texttt{b} you must type \texttt{'b.i'}.
511 The same syntax holds for outputs.
512 \item \texttt{print} prints a string, substituting each substring of the form \$b.o\$ by the value of the output \texttt{o} of the black box \texttt{b}.
513 \item \texttt{exec} runs the process of a box if needed.
514 \item \texttt{quit} quits \bbi.
517 % ==========================================
519 % ==========================================
520 \subsubsection{Connecting black boxes}
521 \label{bbi-connecting-black-boxes}
522 % ==========================================
524 \BBTK allows to create
525 and execute processing chains,
526 also called \emph{pipelines},
527 by connecting black boxes.
528 This section explains how to do it with examples.
529 Read section \ref{bbi-more-on-pipeline-processing} to get
530 more information on pipeline processing.
532 First start \bbi and load the package \texttt{std}:
535 BBI (Black Box Interpreter) - bbtk "1.0.0" - (c) Creatis 2007
539 Assume you want to compute $1+2+3$. You can do it by
540 chaining two \texttt{Add} boxes, as shown in figure
541 \ref{bbi-fig-connecting-black-boxes-1}.
544 \caption{\label{bbi-fig-connecting-black-boxes-1}
545 A simple pipeline which adds 3 numbers}
547 \includegraphics[width=0.5\textwidth]{1plus2plus3.png}
551 The \bbi instructions to create and execute this pipeline are:
555 > connect a.Out b.In1
563 The first three commands build the pipeline,
564 the next three set its inputs and the last one
565 executes it and prints its output.
567 The command \texttt{'connect a.Out b.In1'} ``plugs'' the output
568 \texttt{Out} of the box \texttt{a} into the input \texttt{In1} of the
570 Once the boxes connected, the processing of the two boxes are chained:
571 getting the output of \texttt{b} requires getting its inputs,
572 hence getting the output of \texttt{a} which is connected to it.
573 This pipeline mechanism can recurse into arbitrary long
574 chains of boxes (see \ref{bbi-more-on-pipeline-processing}
577 Of course, to be able to connect two boxes,
578 the output and the input must be compatibles.
579 You can always connect an output to an input of the \emph{same} type,
580 but you can do more, thanks to particular black boxes called {\bf adaptors}.
582 An adaptor is a black box which has at least one input, called \texttt{In},
583 and at least one ouput called \texttt{Out} and whose role is to convert
584 a data of the type of \texttt{In}
585 into a data of the type of \texttt{Out} (other inputs or outputs may serve
586 to parameter the adaptor or retreive other usefull information).
588 In \bbi, if you type:
595 Package std v1.0.0 - laurent.guigues@creatis.insa-lyon.fr
596 Basic useful black boxes
598 Add : Adds its inputs
599 Cast<double,float> [DA] : Casts a double into a float
600 Cast<double,int> [DA] : Casts a double into a int
602 Convert<unsigned int,string> [DA] : Converts a unsigned int into a s...
603 Convert<unsigned short,string> [DA] : Converts a unsigned short into a...
604 Print : Prints its input to standard out...
608 The \texttt{Cast<?,?>} and \texttt{Convert<?,?>} boxes are \emph{default adaptors}, which is signaled by the tag \texttt{[DA]} before their descriptions.
610 Once you have loaded the package \texttt{std}, you can
611 plug an output of type \texttt{char} into an input of type \texttt{double}.
612 When \bbi encounters the \texttt{connect} command,
613 it looks for an adequate \emph{adaptor} in the loaded packages.
614 In our case, as the package \texttt{std} provides the
615 \texttt{Cast<char,double>} adaptor, \bbi automatically creates an
616 instance of this adaptor and place it \emph{between}
617 the output and the input you want to connect
618 (however this adaptor is hidden to you,
619 it is embedded into the created connection and does not appear
620 as an existing black box).
621 When the pipeline is processed the
622 adaptor converts the output data into the required input type,
623 in a totally transparent way.
624 In our example, the \texttt{Cast<char,double>} adaptor
625 would simply cast the value of the \texttt{char} into a \texttt{double},
626 however arbitrarily complex type conversion can be done.
629 if two adaptors with the same input and output types exist
630 in the packages loaded,
631 which one is chosen by \bbi at connection ?
632 -> Role of default adaptors
634 Note that the \texttt{set} and \texttt{print} commands of \bbi
635 work with adaptors from \texttt{string} to the type of the input to set
636 or from the type of the output to print to \texttt{string}.
637 Hence in order to \texttt{set} or \texttt{print} values the adequate
638 adaptors must be available in the packages currently loaded.
640 % ==========================================
645 \item The \texttt{connect} command allows to connect two black boxes
646 \item You can connect two black boxes if (and only if):
648 \item The output and the input are of the same type, or
649 \item There is an adaptor black box in the packages loaded which
650 converts data of the output type into data of the input type
652 \item \texttt{help <package name>} does not display the adaptors of the package. To see them use: \texttt{help <package name> all}.
656 % ==========================================
658 % ==========================================
659 \subsubsection{Creating complex black boxes}
660 \label{bbi-complex-black-boxes}
661 % ==========================================
663 Remember the pipeline of figure
664 \ref{bbi-fig-connecting-black-boxes-1}, which
665 computed the sum of three doubles ?
666 You can view it as a whole and define
667 a new black box type, which will be a \emph{complex black box},
668 having three inputs and one output,
669 as shown in figure \ref{bbi-fig-complex-black-box-1}.
672 \caption{\label{bbi-fig-complex-black-box-1}
673 Creating the complex black box \texttt{Add3}}
675 \includegraphics[width=0.5\textwidth]{Add3.png}
679 The \bbi commands to define this complex black box are
689 > connect a.Out b.In1
692 > description "adds 3 doubles"
693 > input x a.In1 "first double to add"
694 > input y a.In2 "second double to add"
695 > input z b.In2 "third double to add"
696 > output result b.Out "output"
703 As we will use \texttt{Add} boxes, we need to load the package \texttt{std}, which is done in first line.
705 The command \texttt{define} then starts the definition
706 of the complex box type, which will be called \texttt{Add3}.
708 The next three lines define the pipeline,
709 exactly in the same way than outside a complex box definition.
711 The commands \texttt{author}, \texttt{description}, \texttt{input}
712 and \texttt{output} are commands specific to complex boxes definition:
714 \texttt{author} and \texttt{description} are used for the documentation
715 of the new box. You can provide multiple \texttt{author} or
716 \texttt{description} commands, the arguments of the commands will
717 be concatenated to produce the final author and description strings.
719 \texttt{input} and \texttt{output} are used to define the inputs and outputs
720 of the new complex box.
721 Their syntax is the same: for each new input/output you need to say
722 to which internal input/output it corresponds and to provide
723 a help string documenting the input/output.
724 In our example, we define that the box \texttt{Add3} has
725 three inputs: \texttt{x}, \texttt{y} and \texttt{z}.
726 The input \texttt{x} corresponds to the input \texttt{In1} of the
727 internal box \texttt{a}.
728 In the same way, the external input \texttt{y}
729 corresponds to the internal input \texttt{a.In2}, and
730 the external input \texttt{In3} to \texttt{b.In2}.
731 The only output of the new box is called \texttt{result}
732 and corresponds to \texttt{b.Out}.
733 The figure \ref{bbi-fig-complex-black-box-1}
734 illustrates the external to internal
735 input/output correspondence.
737 Finally, the \texttt{endefine} command ends the definition of the
740 After this definition, if you ask for help
741 on packages, you get:
752 The \texttt{user} package now contains a new black box type, called
753 \texttt{Add3}. If you ask for help on this type of box, you get:
756 Complex Black Box <user::Add3>
760 'x' <double>: first double to add
761 'y' <double>: second double to add
762 'z' <double>: third double to add
764 'result' <double>: output
770 and you can use it like any other box, for example type:
782 % ==========================================
787 \item The \texttt{define/endefine} commands allows to define complex black box types, i.e. types of black boxes made up of other black boxes.
788 Inside a \texttt{define/endefine} block:
790 \item The \texttt{author} and \texttt{description} commands allow to document the new type of box
791 \item The \texttt{input} and \texttt{output} commands allow to define the inputs and outputs of the new type of box, that is to which inputs and outputs
792 of internal boxes they correspond.
796 % ==========================================
798 % ==========================================
799 \subsubsection{Writing scripts}
800 \label{bbi-writing-scripts}
801 % ==========================================
803 Once you have defined a new type of complex box, you
804 may like to reuse it. To do this, you can simply
805 write the \bbi commands defining the new box
806 into a text file and afterwards include that file in \bbi.
807 Doing this, you start writing \bbi scripts.
808 The conventionnal extension for such scripts is \texttt{bbs}
811 For example, the \texttt{Add3} complex box we previously worked on
812 can be defined in the \texttt{Add3.bbs} file:
814 \begin{file}{Add3.bbs}
816 # Defines the Add3 black box which adds 3 doubles
822 description "adds 3 doubles"
828 input x a.In1 "first double to add
829 input y a.In2 "second double to add
830 input z b.In2 "third double to add"
832 output result b.Out "output"
837 Lines starting with a \texttt{\#} character are ignored, they
838 are considered as comments by \bbi.
839 To use this file in \bbi, use the \texttt{include} command:
844 Complex Black Box <user::Add3>
848 'x' <double>: first double to add
849 'y' <double>: second double to add
850 'z' <double>: third double to add
852 'result' <double>: output
860 If the file has the \texttt{bbs} extension, you can ommit it and just type:
865 Of course, you can include script files in other script files,
866 like in the following example:
868 \begin{file}{Add4.bbs}
870 # Defines the Add4 black box which adds 4 doubles
875 description "adds 4 doubles"
879 input In1 a.In1 "first double to add
880 input In2 a.In2 "second double to add
881 input In3 a.In3 "third double to add"
882 input In4 b.In2 "fourth double to add"
883 output Out b.Out "output"
890 - naming conventions: one cbb per file with the same name
893 % ==========================================
898 \item The \texttt{include} command allows to include a script file in \bbi.
899 \item Lines starting with a \texttt{\#} are treated as comments in \bbi scripts.
902 % ==========================================
904 % ==========================================
905 \subsubsection{Creating command line applications}
906 \label{bbi-command-line-app}
907 % ==========================================
909 Now that you now how to create complex black boxes
910 (with \texttt{define/endefine}), think
911 back to the \texttt{workspace} object.
912 Remember that it is also
913 a \texttt{complex black box}.
914 In fact what you are doing when you type \bbi commands
915 outside a \texttt{define/endefine} block
916 is to progressively define the \texttt{workspace}
918 You can think of it like if at start
919 \bbi was issuing a command \texttt{'define workspace'}
920 and then letting you define the interior of the box
923 Remember that the command \texttt{inputs}
924 allows to define an input of a complex box.
925 Now, if you use the command \texttt{input}
926 outside a \texttt{define/endefine} block then
927 it defines an input of the \texttt{workspace} box,
928 that is an input of the \emph{main program}.
929 This input will then be connected to the
930 parameters that the user passes to the command line.
932 For example, consider the script:
934 \begin{file}{add.bbs}
938 input x a.In1 "first number to add"
939 input y a.In2 "second number to add"
944 The third and fourth lines define two inputs \texttt{x}
945 and \texttt{y}. When you execute this script,
946 you can pass these two arguments on the command line,
954 You can also invoke \bbi the option \texttt{-h},
955 which gives help on the \texttt{workspace} box:
962 'x' <double>: first number to add
963 'y' <double>: second number to add
966 To get a better help, use the \texttt{description}
967 and \texttt{author} commands:
969 \begin{file}{add.bbs}
971 description "Adds two numbers"
975 input x a.In1 "first number to add"
976 input y a.In2 "second number to add"
981 Now if you ask for help on the \texttt{add} script, you get:
988 'x' <double>: first number to add
989 'y' <double>: second number to add
992 Rather than getting the inputs of a script
993 from the command line, you can ask \bbi to
994 prompt the user for the values, using the \texttt{-t}
999 x=[the program waits for user answer]2
1000 y=[the program waits for user answer]5
1004 If \bbi is compiled in graphical mode (with \wx),
1005 you can also use the \texttt{-g} commutator.
1006 \bbi then prompts the user in graphical mode,
1007 displaying a dialog box for each input,
1008 like in fig. \ref{bb-input-dialog-box}.
1011 \caption{\label{bb-input-dialog-box}Input dialog box}
1013 \includegraphics[width=0.6\textwidth]{enter-the-value-of-x.png}
1017 % ==========================================
1022 \item The \texttt{input}, \texttt{description} and \texttt{author} commands,
1023 when they are used outside a \texttt{define/endefine} block allow
1024 to define the inputs, description and author of the main program.
1025 \item Inputs of the main program can be passed on the command line
1026 using the syntax \texttt{<input-name>=<value>}.
1027 No white space is allowed, if the value or the input name
1028 contains white spaces, enclose them
1029 between double quotes, e.g. \texttt{"parameter with white spaces = gnu's not unix"}.
1030 \item The \texttt{-h} option of \bbi prints help on the main program.
1031 \item The \texttt{-t} option of \bbi orders the program to prompt for its inputs in text mode.
1032 \item The \texttt{-g} option of \bbi orders the program to prompt for its inputs in graphical mode.
1035 % ==========================================
1037 % ==========================================
1038 \subsubsection{Using graphical interface boxes (widget boxes)}
1040 % ==========================================
1042 If \bbi is compiled in graphical mode
1043 (option \texttt{BUILD\_bbi\_GRAPHICAL} of \cmake, requires \wx),
1044 then you can use special black boxes which are
1045 graphical interface components (widgets).
1046 Basic components are provided in the package \texttt{wx},
1047 such as buttons, sliders, file open/save dialogs, etc.
1049 As first example, type the following commands in \bbi:
1056 When you type \texttt{enter} after the last line,
1057 a window pops up in which you can entrer a text.
1058 When you close the window, the text you entered is printed by
1059 the \texttt{print} command.
1061 Type \texttt{help wx}, you get something like:
1063 Package wx v1.0.0- eduardo.davila/laurent.guigues@creatis.insa-lyon.fr
1064 Basic graphical interface elements (slider, button ...) based on wxWidgets
1066 Button : Button that gives a string
1067 FileDialog : FileDialog widget (wxFileDialog)
1068 RadioButton : RadioButton group widget (wxRadioButton) 0-9 entries
1069 Sizer : Sizer widget (wxSizer)
1070 Slider : Slider widget (wxSlider)
1071 Split : Split widget (wxSplitterWindow)
1072 StaticText : wxWidget Static text
1073 TextCtrl : TextCtrl widget (wxTextCtrl)
1076 You can reproduce the same experiment as above using a
1077 \texttt{Slider} or a \texttt{FileDialog} rather than a \texttt{TextCtrl}.
1078 See the files \texttt{test*.bbs} in the \texttt{scripts/test} directory.
1080 There are two kind of widgets: ``terminal'' widgets and ``container'' widgets.
1081 The \texttt{TextCtrl}, \texttt{FileDialog} or \texttt{Slider} widgets
1082 are ``terminal'' widgets.
1083 ``container'' widgets are of another kind: they are made to
1084 contain other widgets in order to build larger dialog boxes.
1085 For example, the \texttt{Split} widget is a container which
1086 ``splits'' horizontally a window into two parts,
1087 each part including another widget.
1088 The size of the two parts can be adjusted by the user thanks
1091 The script \texttt{scripts/test/testSplit.bbs} demonstrate its use.
1092 Run it: it displays a window with two sliders.
1093 Move the sliders and close the window.
1094 The final positions of the sliders are printed out.
1095 Now edit the file to see how this is done:
1097 \begin{file}{scripts/test/testSplit.bbs}
1106 connect s.Child s1.Parent
1107 connect s.Child s2.Parent
1109 print s1=$s1.Out$\\n
1110 print s2=$s2.Out$\\n
1114 First, the two sliders \texttt{s1} and \texttt{s2} are created.
1115 A \texttt{Split} box \texttt{s} is also created.
1116 The \texttt{connect} commands then ``includes'' the sliders in the
1117 split ``container''.
1118 The input \texttt{Parent} is common to all widget boxes:
1119 every widget can be inserted into another widget.
1120 The output \texttt{Child} is specific of \emph{container}
1122 (in \bbi type \texttt{help Slider}:
1123 you will see the input \texttt{Parent};
1124 type \texttt{help Split}:
1125 you will see the input \texttt{Parent}
1126 and the output \texttt{Child}).
1127 When you connect the \texttt{Child} output of a container
1128 to the \texttt{Parent} input of a widget,
1129 you order to include the widget in the container.
1130 Of course, the order of connection is important.
1131 In our case, the slider \texttt{s1} is included first,
1132 then the slider \texttt{s2}: \texttt{s1} will be placed
1133 on top of \texttt{s2} (the \texttt{Split} box is
1134 implemented that way, but this is arbitrary choice).
1136 For the moment, there are only \emph{two} container widgets in the \texttt{wx} package:
1137 the \texttt{Split} widget we just described and the \texttt{Sizer}
1138 widget, which can have multiple children and
1139 divides its window into as much parts as children,
1140 each part of equal size.
1141 The orientation of the sizer can be changed by the input \texttt{Orientation}.
1142 See the example \texttt{test/testSizer.bbs}.
1143 With only those two containers you can already create
1144 complex dialog boxes (of course containers can be nested, which
1145 leads to tree-like structures of widgets).
1146 See the script \texttt{test/testSizerSplit.bbs} for an example.
1148 One word about a special widget in the package \texttt{wx}:
1149 the \texttt{Button}... to be continued.
1154 \item Make a tour of ``complex'' widgets of wxvtk
1155 \item Explain the role of ProcessMode to update widgets
1156 \item Explain the creation of complex widgets (containers, contained...)
1157 \item Explain the ``control'' mechanism in bbi (switch exec commands, e.g. Button)
1161 % ==========================================
1162 \subsection{More on ...}
1164 % ==========================================
1166 % ==========================================
1167 \subsubsection{Black box packages}
1168 \label{bbi-more-on-packages}
1169 % ==========================================
1171 % ==========================================
1172 \subsubsection{Pipeline processing}
1173 \label{bbi-more-on-pipeline-processing}
1174 % ==========================================
1176 % ==========================================
1177 \subsubsection{Complex black boxes}
1178 \label{bbi-more-on-complex-black-boxes}
1180 %\subsubsection{Advanced issues}
1181 %\paragraph{Reducing the number of inputs of a box}
1183 % ==========================================
1184 \subsubsection{Errors}
1185 \label{bbi-more-on-errors}
1187 % ==========================================
1188 \subsubsection{\bbtk configuration file and search pathes}
1189 \label{bbi-more-on-configuration}
1191 At start, \bbi tries to open an \texttt{xml}
1192 configuration file named \texttt{bbtk\_config.xml}.
1195 \item The current directory
1196 \item The subdir \texttt{.bbtk} of the user's home directory.
1198 \item On \texttt{Unix}, the home directory is the
1199 one stored by the environnement variable \texttt{HOME},
1200 typically \texttt{/home/username}.
1201 \item On \texttt{Windows}, the home directory is
1202 the user's profile directory stored by the environnement
1203 variable \texttt{USERPROFILE},
1204 typically \texttt{C:\\...}.
1206 \item If none of these two pathes contains the file then it creates
1207 a new one in the \texttt{.bbtk} directory.
1210 Once created, you can edit the \texttt{bbtk\_config.xml} file located
1211 in your \texttt{.bbtk} directory. It contains:
1213 \begin{file}{bbtk\_config.xml}
1215 <?xml version="1.0" encoding="iso-8859-1"?>
1217 <bbtk_url> http://www.creatis.insa-lyon.fr/software/bbtk </bbtk_url>
1218 <bbs_path> </bbs_path>
1219 <package_path> </package_path>
1220 <data_path> </data_path>
1225 You can add pathes to
1227 \item A custom folder in which to search for \texttt{.bbs} scripts (\texttt{include} command of \bbi) by adding an \texttt{xml} tag:
1228 \texttt{<bbs\_path>complete\_path\_to\_folder<\/bbs\_path>}.
1229 \item A custom folder in which to search for packages (\texttt{load} command of \bbi) by adding an \texttt{xml} tag:
1230 \texttt{<package\_path>complete\_path\_to\_folder<\/package\_path>}.
1233 % ==========================================
1234 \subsection{Language reference}
1235 \label{bbi-reference}
1236 % ==========================================
1242 % ==========================================
1244 \caption{\label{bbi-reference-box}
1245 \bbi pipeline creation and execution related commands.}
1247 \begin{tabular}{|lcm{6cm}|}
1249 Command & Parameters & Effect \\ \hline
1251 \texttt{new} & \texttt{<boxtype>} \texttt{<box-name>}&
1252 Creates a box of type \texttt{boxtype} and name
1256 \texttt{delete} & \texttt{<box-name>} &
1257 Destroys the box named \texttt{box-name}.
1260 \texttt{connect} & \texttt{<box1.output>} \texttt{<box2.input>} &
1262 \texttt{output} of the box named \texttt{box1}
1263 to the input \texttt{input} of the box named \texttt{box2} \\ \hline
1265 \texttt{set} & \texttt{<box.input>} \texttt{<value>} &
1266 Sets the input \texttt{input} of
1267 the box named \texttt{box} to the value \texttt{value}.
1268 There must exist an \texttt{adaptor}
1269 in the packages loaded which converts a \texttt{std::string}
1270 to the type of the input \texttt{input}.
1273 \texttt{print} & \texttt{<string>} &
1274 Prints the string after substituting each token of the form \texttt{\$box.output\$} by the adaptation to string of the value of the
1275 output \texttt{output} of the box named \texttt{box}.
1276 There must exist an \texttt{adaptor}
1277 in the packages loaded which converts
1278 the type of the output \texttt{output}
1279 to a \texttt{std::string}.
1282 \texttt{exec} & \texttt{<box-name>} &
1283 Executes the box named \texttt{box-name}.
1285 connected to its inputs
1286 are also processed recursively (pipeline processing).\\ \hline
1289 % ==========================================
1293 % ==========================================
1295 \caption{\label{bbi-reference-interpreter}\bbi intepreter related commands.}
1297 \begin{tabular}{|lcm{6cm}|}
1299 Command & Parameters & Effect \\ \hline
1303 Prints help on available commands \\ \hline
1305 & \texttt{<command-name>} &
1306 Prints help on the command \texttt{command-name} \\ \hline
1308 & \texttt{packages} &
1309 Prints help on available packages and their box types
1310 (without description)\\ \hline
1312 & \texttt{<package-name>} &
1313 Prints help on the package \texttt{package-name} and its boxes
1314 (with brief description).
1315 The package must have been previously loaded
1318 & \texttt{<box-type>} &
1319 Prints help (with full description) on the type of box
1321 The box type must belong to a package which has been previously loaded
1324 \texttt{include} & \texttt{<file-name>} &
1325 Includes and executes the content of the file named \texttt{file-name}
1326 exactly like if you were typing its content at the place were the
1327 \texttt{include} command is.
1330 \texttt{load} & \texttt{<package-name>} &
1331 Loads the package \texttt{package-name}\\ \hline
1333 \texttt{unload} & \texttt{<package-name>}&
1334 Unloads the package \texttt{package-name}.
1335 The package must have been previously loaded.
1336 No box of a type defined in this package must still exist.
1339 \texttt{message} & \texttt{<category>} \texttt{<level>} &
1340 Sets the level of verbosity of \bbi for the category of messages
1341 \texttt{category} to \texttt{level}.
1342 %See \ref{verbosity}.
1345 \texttt{config} & - & Displays the Configuration parameters\\ \hline
1347 \texttt{reset} & - & Deletes all boxes and unloads all packages so
1348 that \bbi gets back to its initial state \\ \hline
1350 \texttt{quit} & - & Exits the interpreter\\ \hline
1354 % ==========================================
1360 % ==========================================
1362 \caption{\label{bbi-reference-complex-box}
1363 \bbi complex black box definition related commands.}
1365 \begin{tabular}{|lcm{6cm}|}
1367 Command & Parameters & Effect \\ \hline
1370 \texttt{define} & \texttt{<box-type>} &
1371 Starts the definition of a complex black box of type
1372 \texttt{box-type}\\ \hline
1374 \texttt{endefine} & - &
1375 Ends the definition of a complex black box type\\ \hline
1378 \texttt{author} & \texttt{<string>} &
1379 Sets the author(s) of the complex black box currently being defined \\ \hline
1381 \texttt{description} & \texttt{<string>} &
1382 Sets the description of the complex black box currently being defined
1386 \texttt{input} & \texttt{<name>} \texttt{<box.input>} \texttt{<help>} &
1387 Defines a new input for the current complex black box,
1388 named \texttt{name}.
1389 It is defined as corresponding to
1390 the input \texttt{input} of the box \texttt{box}.
1391 \texttt{<help>} is the help string for the new input.
1392 The box \texttt{box} must already have been created in the complex box
1393 and of course have an input named \texttt{input}.
1397 \texttt{output} & \texttt{<name>} \texttt{<box.output>} \texttt{<help>} &
1398 Defines a new output for the current complex black box,
1399 named \texttt{name}.
1400 It is defined as corresponding to
1401 the output \texttt{output} of the box \texttt{box}.
1402 \texttt{<help>} is the help string for the new output.
1403 The box \texttt{box} must already have been created in the complex box and of course have an output named \texttt{output}.
1409 % ==========================================
1414 % ==========================================
1415 \vspace{0.5cm}\hrule
1416 \section{Using black boxes in \CPP programs}
1418 % ==========================================
1427 %\section{Conclusion}