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
37 I would add something very important to this definition :
38 not only the inputs and outputs are of interest but also
39 \emph{what the box does} !
40 Hence, I would say that a black box is any \emph{\bf documented}
41 component of a system, letting know the user
42 \emph{\bf what} the box is supposed to do and
43 \emph{\bf how to use it}
44 but not \emph{\bf how it does it}.
46 \BBTK provides a systematic framework
47 to encapsulate (or ``wrap'') any
48 existing \texttt{C} or \CPP processing code into an object
49 (a black box) having a {\bf generic symbolic interface}, where
52 \item{\bf generic} means that the interface is \emph{the same}
53 for all boxes. Hence one does not need to know which particular
54 method allows, say, to set a particular input or
55 get a particular output of the box.
56 One can use a black box in a purely abstract way.
57 \item{\bf symbolic} means that a particular
58 input or output is referenced by a 'name', that is by a symbol
59 which identifies the input or output.
60 It also means that symbolic information (text!) is
61 attached to a box: description of the box, author,
62 description of its inputs and outputs, etc.
65 (in fact, genericity is achieved because the interface is symbolic.
66 I let you think about this\dots)
68 Of course, symbolic data attached to box can be
69 {\bf queried}: what are the inputs/outputs of the box ?
70 what are their type ? description ? etc.
71 This allows {\bf automatic documentation} of boxes.
73 The abstract definition of black boxes is the most basic
74 aspect of \BBTK architecture.
75 Another key aspect is the groupement of black boxes into
76 so called {\bf packages},
77 which are \emph{dynamic libraries} which can also
78 be queried, in particular about the boxes they provide.
79 The package structure then offers a mechanism which
80 is like a \emph{'plug-in'} mechanism.
81 \BBTK provides the methods to load a package at run-time,
82 and create instances of the boxes it contains.
84 These two mechanisms (black boxes and packages)
85 then gives the way to:
88 \item The definition of an {\bf interpreted language},
89 which allows to manipulate packages and boxes very easily in symbolic way.
90 \BBTK provides one: \bbi (the Black Box Interpreter).
91 \item {\bf Automatic documentation} of existing packages.
92 \texttt{html} documentation of packages is proposed by
96 Finally, these different components allow {\bf efficient}:
99 \item {\bf capitalization and reuse} of existing processing units,
100 including {\bf documentation}
101 \item {\bf testing, prototyping} in a very simple script language
102 \item {\bf inter-operability} between atomic processings which
103 have been written by different persons, using different libraries, etc.
106 % ==========================================
107 \subsection{\bbtk components}
108 % ==========================================
111 \item A \CPP {\bf\emph{library}} - called \bbtk - which defines a framework
112 (abstract classes) to develop black boxes and to store them into
113 dynamic libraries, called black box \emph{packages}.
114 \item Different {\bf\emph{black box packages}}:
116 \item {\bf\emph{std}}: the 'standard' package including basic useful boxes.
117 \item {\bf\emph{wx}}: basic graphical interface elements (widgets: sliders, buttons, etc. based on the \texttt{wxWidgets} library).
118 \item {\bf\emph{itk}}: the basic image processing package, based on the \texttt{itk} library.
119 \item {\bf\emph{vtk}}: the basic image and surfaces processing package, based on the \texttt{vtk} library.
120 \item {\bf\emph{wxvtk}}: widget boxes based on the \texttt{vtk} library.
121 \item {\bf\emph{itkvtk}}: boxes to convert \texttt{itk} structures into \texttt{vtk} structures and conversally.
123 \item An {\bf\emph{interpreter}}, called \bbi, which allows to
124 load black box packages and to define and execute
125 processing chains by connecting various black boxes of the already loaded packages.
126 \item {\bf\emph{Utilities}}:
128 \item \bbfy generates the \CPP code of a black box from a
129 description file written in \texttt{xml}.
130 %\item \bbdoc generates the html documentation of a black box package
131 %(author, description, description of its black boxes:
132 %author, description, inputs, outputs, and so on).
133 \item \bbCreatePackage allows to create the basic file architecture
134 to start the development of a new black box package.
138 The general architecture of \BBTK
139 is shown in figure \ref{bb-architecture}.
142 \caption{\label{bb-architecture}\BBTK architecture}
144 \includegraphics[width=0.6\textwidth]{bb-architecture.png}
148 % ==========================================
149 \subsection{Structure of this guide}
150 % ==========================================
152 This guide is divided into two parts.
154 The first part (\ref{bbi})
155 is devoted to the use of the \emph{black box interpreter} \bbi.
156 This is the highest level of use of the toolkit, which
157 allows to create and execute processing chains by connecting
158 black boxes of existing packages.
160 The second part (\ref{cpp}) explains how to
161 use the black box toolkit framework in \CPP code,
162 typically to develop large applications which
163 involve complex graphical interfaces.
166 % ==========================================
167 % ==========================================
168 % ==========================================
169 % ==========================================
170 % ==========================================
171 % ==========================================
173 \section{The black box interpreter (bbi)}
175 % ==========================================
177 % ==========================================
178 %\subsection{Structure of this part}
179 % ==========================================
181 Using the black box interpreter is very simple.
182 Everything is done with only a few commands.
183 The philosophy of this part is also very simple:
184 it introduces the \bbi commands using examples,
185 starting with the most simple commands.
186 The first section of this part
187 (\ref{bbi-getting-started})
188 is designed like a tutorial,
189 which progressively introduces all the concepts of \bbi.
190 We suggest you run \bbi and follow the examples,
191 to see how it works in practice.
192 At the end of this section,
193 you will be able to use \bbi and write
194 own black box processing scripts.
197 the section \ref{bbi-more-on}
198 (called \emph{more on...})
199 goes deeper into various issues of \bbi.
200 Read it at your convenience,
201 either linearly to learn more about \bbi,
202 or in random order to get an answer
203 to a particular question.
205 Finally, the section \ref{bbi-reference}
206 summarizes all the commands of \bbi,
207 their parameters and effect.
208 Use it as a reference.
210 % ==========================================
211 \subsection{Getting started}
212 \label{bbi-getting-started}
213 % ==========================================
214 \subsubsection{Creating and executing black boxes}
215 % ==========================================
217 To run the black box interpreter,
218 open a console and type \texttt{bbi}
219 or double click on the application icon.
220 You get a window which looks like the one in figure
221 \ref{bbi-fig-bbi-gui}
222 (the exact appearance of \bbi is system and \bbtk version dependent)
223 \footnote{If you compiled \bbtk without \wx then \bbi does not have a
224 graphical interface but a simple prompt).
227 \caption{\label{bbi-fig-bbi-gui}The black box interpreter interface}
229 \includegraphics[width=0.7\textwidth]{bbi-gui.png}
233 The 'Command' tab is subdivided into two parts :
234 one single line zone at the bottom in which you can enter your commands and
235 one multiple line zone in which \bbi prints out the result of your commands.
238 Try typing in the input zone (in this manual,
239 the commands entered by the user will be preceded by a prompt '>') :
244 you get the list of the commands of the interpreter:
274 To get help on a particular command type \texttt{help <command-name>},
284 Quits the program (during script execution it stops the complete execution)
287 The \texttt{help} command has multiple usages.
288 It is used to get help on almost anything in \bbi !
289 Type \texttt{'help help'} to get help on the \texttt{help} command itself:
294 (2) help <command name>
295 (3) help packages [all]
296 (4) help <package name> [all]
297 (5) help <black box type>
298 (6) help <black box name>
300 (1) Lists all available commands;
301 (2) Prints help on a particular command;
302 (3) Lists the packages loaded and their black boxes.
303 Add 'all' to list adaptors;
304 (4) Prints short help on the black boxes of a package.
305 Add 'all' to include adaptors;
306 (5) Prints full help on a black box type;
307 (6) Prints information on the inputs, outputs and connections of a black box instance.
310 At start \bbi does not know any black box.
311 If you type \texttt{'help packages'}, which is
312 the third form of the \texttt{help} command, you get:
319 which means that \bbi only knows one package
320 (library of black boxes) called \texttt{user}
321 and which contains a black box called \texttt{workspace}.
322 The \texttt{user} package is an internal package to \bbi,
323 which stores user-defined black box types.
324 At start, it already contains
325 one box, called \texttt{workspace}.
326 \texttt{workspace} is a special type of black box,
327 called complex black box, whose purpose is
328 to store other black boxes.
329 Any black box you create in \bbi is stored
330 in \texttt{workspace}
331 (this will be explained in details in sections
332 \ref{bbi-writing-scripts} and
333 \ref{bbi-more-on-complex-black-boxes}).
335 If you type \texttt{'help workspace'}, you get:
338 Complex Black Box <user::workspace>
341 Category(s) : complex box;
347 In the text displayed,
348 the \texttt{user::} prepended to the name \texttt{workspace}
349 means that the box \texttt{workspace}
350 belongs to the \texttt{user} package.
351 Then comes a description and three lines which
352 tell that \texttt{workspace} does not have any input
353 nor output nor boxes yet.
355 In order to let \bbi know of some black boxes,
356 you must load another package.
357 The \texttt{std} package is the ``standard'' package,
358 which contains basic useful black boxes.
370 you get something like:
380 Now \bbi knows the package \texttt{std} and the black boxes it provides,
381 such as the \texttt{'Add'} box. Remark that the
382 content of \texttt{std} may vary from one version to another
383 as new black boxes might be added to it.
393 By: laurent.guigues at creatis.insa-lyon.fr
394 Categories : atomic box;math;
396 'BoxExecute' <bbtk::Void> : Any signal received by this input executes the box
397 'BoxProcessMode' <String> : Sets the processing mode of the box (Pipeline | Always | Reactive)
398 'In1' <Double> : First number to add
399 'In2' <Double> : Second number to add
401 'BoxChange' <bbtk::Void> : Signal modifications of the box
402 'Out' <Double> : Result'In1' <double>: First number to add
406 the \texttt{std::} prepended to the name \texttt{Add}
407 means that the box \texttt{Add}
408 belongs to the \texttt{std} package.
409 Then comes a description
410 (the one which was provided by the author of the box),
411 the author(s) of the box (usually e-mail adress(es)) and
412 the categories to which the box belong.
413 Finally comes the lists of inputs and outputs of the box.
414 For each input or output, \bbi provides
415 its \emph{name} (between quotes, e.g. \texttt{'ProcessMode'}),
416 its \emph{type} (between \texttt{<>}, e.g. \texttt{<Int>})
418 Remark that the box \texttt{Add} is not a 'complex' black box
419 but an 'atomic' box, hence its help does not
420 mention any information concerning possible internal boxes.
422 You can create an \emph{instance} of an \texttt{Add} box by
423 the command \texttt{new}:
428 The \texttt{'a'} at the end is the \emph{name} of the instance,
429 which will be used to reference it later.
430 It is important to make the difference between box \emph{types}
431 and \emph{instances} of box types.
432 The \texttt{Add} box of the package \texttt{std} is in fact
433 a \emph{type} of box, like \texttt{int} is a type of data
434 in \texttt{C} langage. The \texttt{new} command allows to create
435 an instance of a box type, exactly like \texttt{int i;} in
436 a \texttt{C} code declares a variable of type \texttt{int} whose
438 Of course, like in \texttt{C} Language, you can declare multiple boxes of the
441 After the creation of the box \texttt{a}, type:
448 Complex Black Box <user::workspace>
451 Category(s) : complex box;
458 which means that \bbi's workspace now contains a black box
459 of type \texttt{std::Add} and name \texttt{a}.
461 Now look back at the help on \texttt{Add} boxes:
462 you can see that this type of box has two inputs,
463 with name \texttt{In1} and \texttt{In2},
464 and an output, with name \texttt{Out}.
466 You can set the input \texttt{In1}
467 of the \texttt{Add} box \texttt{a} to the value $1$
473 Similarly, setting the input \texttt{In2} of \texttt{a} to the value $2$
479 And you print the output \texttt{Out} of the box \texttt{a} with:
481 > print "result=$a.Out$"
485 In the string passed to the \texttt{print} command,
486 each substring enclosed between a couple of \$ is considered
487 as the name of an output of a box.
488 To process this special substrings, \bbi does:
490 \item Processes the box if needed (see below)
491 \item Converts the output of the box to a string if possible
493 \item Substitutes the result in the string to print
496 Box processing is needed if:
498 \item at least input has changed since last processing or
499 \item the input \texttt{'BoxProcessMode'} of the box is set to
500 \texttt{'Always'}, which forces box reprocessing.
503 Note that all boxes have the input \texttt{'BoxProcessMode'}.
505 Another way to process the box \texttt{a} is to issue the command:
510 however this command does not display anything (except if the
511 box itself displays something in its processing).
512 It just processes the box if needed.
513 This command is used to execute boxes that do not have any output,
514 such as boxes that write something to a file or, display a
515 graphical interface, and so on.
523 % ==========================================
528 \item The \texttt{include} command allows to load a package.
529 \item \texttt{help} gives help on:
531 \item Available commands if you just type \texttt{help}.
532 \item A particular command if you type \texttt{help <command-name>}.
533 \item All available packages and their boxes (without description) if you type \texttt{help packages}.
534 \item A particular package and its boxes (with brief description) if you type \texttt{help <package-name>}.
535 \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}).
537 %\item \texttt{list} displays the list of black box instances created so far (by \texttt{new}).
538 \item \texttt{new} creates an instance of a black box.
539 \item \texttt{set} sets the value of an input of a black box.
540 \item In all \bbi, to reference the input called \texttt{i}
541 of a black box called \texttt{b} you must type \texttt{'b.i'}.
542 The same syntax holds for outputs.
543 \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}.
544 \item \texttt{exec} runs the process of a box if needed.
545 \item \texttt{quit} quits \bbi.
548 % ==========================================
550 % ==========================================
551 \subsubsection{Connecting black boxes}
552 \label{bbi-connecting-black-boxes}
553 % ==========================================
555 LG : THE GUIDE IS UP TO DATE UNTIL HERE
557 \BBTK allows to create
558 and execute processing chains,
559 also called \emph{pipelines},
560 by connecting black boxes.
561 This section explains how to do it with examples.
562 Read section \ref{bbi-more-on-pipeline-processing} to get
563 more information on pipeline processing.
565 First start \bbi and load the package \texttt{std}:
570 Assume you want to compute $1+2+3$. You can do it by
571 chaining two \texttt{Add} boxes, as shown in figure
572 \ref{bbi-fig-connecting-black-boxes-1}.
575 \caption{\label{bbi-fig-connecting-black-boxes-1}
576 A simple pipeline which adds 3 numbers}
578 \includegraphics[width=0.5\textwidth]{1plus2plus3.png}
582 The \bbi instructions to create and execute this pipeline are:
586 > connect a.Out b.In1
594 The first three commands build the pipeline,
595 the next three set its inputs and the last one
596 executes it and prints its output.
598 The command \texttt{'connect a.Out b.In1'} ``plugs'' the output
599 \texttt{Out} of the box \texttt{a} into the input \texttt{In1} of the
601 Once the boxes connected, the processing of the two boxes are chained:
602 getting the output of \texttt{b} requires getting its inputs,
603 hence getting the output of \texttt{a} which is connected to it.
604 This pipeline mechanism can recurse into arbitrary long
605 chains of boxes (see \ref{bbi-more-on-pipeline-processing}
608 Of course, to be able to connect two boxes,
609 the output and the input must be compatibles.
610 You can always connect an output to an input of the \emph{same} type,
611 but you can do more, thanks to particular black boxes called {\bf adaptors}.
613 An adaptor is a black box which has at least one input, called \texttt{In},
614 and at least one ouput called \texttt{Out} and whose role is to convert
615 a data of the type of \texttt{In}
616 into a data of the type of \texttt{Out} (other inputs or outputs may serve
617 to parameter the adaptor or retreive other usefull information).
619 In \bbi, if you type:
626 Package std v1.0.0 - laurent.guigues@creatis.insa-lyon.fr
627 Basic useful black boxes
629 Add : Adds its inputs
630 Cast<double,float> [DA] : Casts a double into a float
631 Cast<double,int> [DA] : Casts a double into a int
633 Convert<unsigned int,string> [DA] : Converts a unsigned int into a s...
634 Convert<unsigned short,string> [DA] : Converts a unsigned short into a...
635 Print : Prints its input to standard out...
639 The \texttt{Cast<?,?>} and \texttt{Convert<?,?>} boxes are \emph{default adaptors}, which is signaled by the tag \texttt{[DA]} before their descriptions.
641 Once you have loaded the package \texttt{std}, you can
642 plug an output of type \texttt{char} into an input of type \texttt{double}.
643 When \bbi encounters the \texttt{connect} command,
644 it looks for an adequate \emph{adaptor} in the loaded packages.
645 In our case, as the package \texttt{std} provides the
646 \texttt{Cast<char,double>} adaptor, \bbi automatically creates an
647 instance of this adaptor and place it \emph{between}
648 the output and the input you want to connect
649 (however this adaptor is hidden to you,
650 it is embedded into the created connection and does not appear
651 as an existing black box).
652 When the pipeline is processed the
653 adaptor converts the output data into the required input type,
654 in a totally transparent way.
655 In our example, the \texttt{Cast<char,double>} adaptor
656 would simply cast the value of the \texttt{char} into a \texttt{double},
657 however arbitrarily complex type conversion can be done.
660 if two adaptors with the same input and output types exist
661 in the packages loaded,
662 which one is chosen by \bbi at connection ?
663 -> Role of default adaptors
665 Note that the \texttt{set} and \texttt{print} commands of \bbi
666 work with adaptors from \texttt{string} to the type of the input to set
667 or from the type of the output to print to \texttt{string}.
668 Hence in order to \texttt{set} or \texttt{print} values the adequate
669 adaptors must be available in the packages currently loaded.
671 % ==========================================
676 \item The \texttt{connect} command allows to connect two black boxes
677 \item You can connect two black boxes if (and only if):
679 \item The output and the input are of the same type, or
680 \item There is an adaptor black box in the packages loaded which
681 converts data of the output type into data of the input type
683 \item \texttt{help <package name>} does not display the adaptors of the package. To see them use: \texttt{help <package name> all}.
687 % ==========================================
689 % ==========================================
690 \subsubsection{Creating complex black boxes}
691 \label{bbi-complex-black-boxes}
692 % ==========================================
694 Remember the pipeline of figure
695 \ref{bbi-fig-connecting-black-boxes-1}, which
696 computed the sum of three doubles ?
697 You can view it as a whole and define
698 a new black box type, which will be a \emph{complex black box},
699 having three inputs and one output,
700 as shown in figure \ref{bbi-fig-complex-black-box-1}.
703 \caption{\label{bbi-fig-complex-black-box-1}
704 Creating the complex black box \texttt{Add3}}
706 \includegraphics[width=0.5\textwidth]{Add3.png}
710 The \bbi commands to define this complex black box are
720 > connect a.Out b.In1
723 > description "adds 3 doubles"
724 > input x a.In1 "first double to add"
725 > input y a.In2 "second double to add"
726 > input z b.In2 "third double to add"
727 > output result b.Out "output"
734 As we will use \texttt{Add} boxes, we need to load the package \texttt{std}, which is done in first line.
736 The command \texttt{define} then starts the definition
737 of the complex box type, which will be called \texttt{Add3}.
739 The next three lines define the pipeline,
740 exactly in the same way than outside a complex box definition.
742 The commands \texttt{author}, \texttt{description}, \texttt{input}
743 and \texttt{output} are commands specific to complex boxes definition:
745 \texttt{author} and \texttt{description} are used for the documentation
746 of the new box. You can provide multiple \texttt{author} or
747 \texttt{description} commands, the arguments of the commands will
748 be concatenated to produce the final author and description strings.
750 \texttt{input} and \texttt{output} are used to define the inputs and outputs
751 of the new complex box.
752 Their syntax is the same: for each new input/output you need to say
753 to which internal input/output it corresponds and to provide
754 a help string documenting the input/output.
755 In our example, we define that the box \texttt{Add3} has
756 three inputs: \texttt{x}, \texttt{y} and \texttt{z}.
757 The input \texttt{x} corresponds to the input \texttt{In1} of the
758 internal box \texttt{a}.
759 In the same way, the external input \texttt{y}
760 corresponds to the internal input \texttt{a.In2}, and
761 the external input \texttt{In3} to \texttt{b.In2}.
762 The only output of the new box is called \texttt{result}
763 and corresponds to \texttt{b.Out}.
764 The figure \ref{bbi-fig-complex-black-box-1}
765 illustrates the external to internal
766 input/output correspondence.
768 Finally, the \texttt{endefine} command ends the definition of the
771 After this definition, if you ask for help
772 on packages, you get:
783 The \texttt{user} package now contains a new black box type, called
784 \texttt{Add3}. If you ask for help on this type of box, you get:
787 Complex Black Box <user::Add3>
791 'x' <double>: first double to add
792 'y' <double>: second double to add
793 'z' <double>: third double to add
795 'result' <double>: output
801 and you can use it like any other box, for example type:
813 % ==========================================
818 \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.
819 Inside a \texttt{define/endefine} block:
821 \item The \texttt{author} and \texttt{description} commands allow to document the new type of box
822 \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
823 of internal boxes they correspond.
827 % ==========================================
829 % ==========================================
830 \subsubsection{Writing scripts}
831 \label{bbi-writing-scripts}
832 % ==========================================
834 Once you have defined a new type of complex box, you
835 may like to reuse it. To do this, you can simply
836 write the \bbi commands defining the new box
837 into a text file and afterwards include that file in \bbi.
838 Doing this, you start writing \bbi scripts.
839 The conventionnal extension for such scripts is \texttt{bbs}
842 For example, the \texttt{Add3} complex box we previously worked on
843 can be defined in the \texttt{Add3.bbs} file:
845 \begin{file}{Add3.bbs}
847 # Defines the Add3 black box which adds 3 doubles
853 description "adds 3 doubles"
859 input x a.In1 "first double to add
860 input y a.In2 "second double to add
861 input z b.In2 "third double to add"
863 output result b.Out "output"
868 Lines starting with a \texttt{\#} character are ignored, they
869 are considered as comments by \bbi.
870 To use this file in \bbi, use the \texttt{include} command:
875 Complex Black Box <user::Add3>
879 'x' <double>: first double to add
880 'y' <double>: second double to add
881 'z' <double>: third double to add
883 'result' <double>: output
891 If the file has the \texttt{bbs} extension, you can ommit it and just type:
896 Of course, you can include script files in other script files,
897 like in the following example:
899 \begin{file}{Add4.bbs}
901 # Defines the Add4 black box which adds 4 doubles
906 description "adds 4 doubles"
910 input In1 a.In1 "first double to add
911 input In2 a.In2 "second double to add
912 input In3 a.In3 "third double to add"
913 input In4 b.In2 "fourth double to add"
914 output Out b.Out "output"
921 - naming conventions: one cbb per file with the same name
924 % ==========================================
929 \item The \texttt{include} command allows to include a script file in \bbi.
930 \item Lines starting with a \texttt{\#} are treated as comments in \bbi scripts.
933 % ==========================================
935 % ==========================================
936 \subsubsection{Creating command line applications}
937 \label{bbi-command-line-app}
938 % ==========================================
940 Now that you now how to create complex black boxes
941 (with \texttt{define/endefine}), think
942 back to the \texttt{workspace} object.
943 Remember that it is also
944 a \texttt{complex black box}.
945 In fact what you are doing when you type \bbi commands
946 outside a \texttt{define/endefine} block
947 is to progressively define the \texttt{workspace}
949 You can think of it like if at start
950 \bbi was issuing a command \texttt{'define workspace'}
951 and then letting you define the interior of the box
954 Remember that the command \texttt{inputs}
955 allows to define an input of a complex box.
956 Now, if you use the command \texttt{input}
957 outside a \texttt{define/endefine} block then
958 it defines an input of the \texttt{workspace} box,
959 that is an input of the \emph{main program}.
960 This input will then be connected to the
961 parameters that the user passes to the command line.
963 For example, consider the script:
965 \begin{file}{add.bbs}
969 input x a.In1 "first number to add"
970 input y a.In2 "second number to add"
975 The third and fourth lines define two inputs \texttt{x}
976 and \texttt{y}. When you execute this script,
977 you can pass these two arguments on the command line,
985 You can also invoke \bbi the option \texttt{-h},
986 which gives help on the \texttt{workspace} box:
993 'x' <double>: first number to add
994 'y' <double>: second number to add
997 To get a better help, use the \texttt{description}
998 and \texttt{author} commands:
1000 \begin{file}{add.bbs}
1002 description "Adds two numbers"
1003 author "foo@bar.com"
1006 input x a.In1 "first number to add"
1007 input y a.In2 "second number to add"
1012 Now if you ask for help on the \texttt{add} script, you get:
1019 'x' <double>: first number to add
1020 'y' <double>: second number to add
1023 Rather than getting the inputs of a script
1024 from the command line, you can ask \bbi to
1025 prompt the user for the values, using the \texttt{-t}
1030 x=[the program waits for user answer]2
1031 y=[the program waits for user answer]5
1035 If \bbi is compiled in graphical mode (with \wx),
1036 you can also use the \texttt{-g} commutator.
1037 \bbi then prompts the user in graphical mode,
1038 displaying a dialog box for each input,
1039 like in fig. \ref{bb-input-dialog-box}.
1042 \caption{\label{bb-input-dialog-box}Input dialog box}
1044 \includegraphics[width=0.6\textwidth]{enter-the-value-of-x.png}
1048 % ==========================================
1053 \item The \texttt{input}, \texttt{description} and \texttt{author} commands,
1054 when they are used outside a \texttt{define/endefine} block allow
1055 to define the inputs, description and author of the main program.
1056 \item Inputs of the main program can be passed on the command line
1057 using the syntax \texttt{<input-name>=<value>}.
1058 No white space is allowed, if the value or the input name
1059 contains white spaces, enclose them
1060 between double quotes, e.g. \texttt{"parameter with white spaces = gnu's not unix"}.
1061 \item The \texttt{-h} option of \bbi prints help on the main program.
1062 \item The \texttt{-t} option of \bbi orders the program to prompt for its inputs in text mode.
1063 \item The \texttt{-g} option of \bbi orders the program to prompt for its inputs in graphical mode.
1066 % ==========================================
1068 % ==========================================
1069 \subsubsection{Using graphical interface boxes (widget boxes)}
1071 % ==========================================
1073 If \bbi is compiled in graphical mode
1074 (option \texttt{BUILD\_bbi\_GRAPHICAL} of \cmake, requires \wx),
1075 then you can use special black boxes which are
1076 graphical interface components (widgets).
1077 Basic components are provided in the package \texttt{wx},
1078 such as buttons, sliders, file open/save dialogs, etc.
1080 As first example, type the following commands in \bbi:
1087 When you type \texttt{enter} after the last line,
1088 a window pops up in which you can entrer a text.
1089 When you close the window, the text you entered is printed by
1090 the \texttt{print} command.
1092 Type \texttt{help wx}, you get something like:
1094 Package wx v1.0.0- eduardo.davila/laurent.guigues@creatis.insa-lyon.fr
1095 Basic graphical interface elements (slider, button ...) based on wxWidgets
1097 Button : Button that gives a string
1098 FileDialog : FileDialog widget (wxFileDialog)
1099 RadioButton : RadioButton group widget (wxRadioButton) 0-9 entries
1100 Sizer : Sizer widget (wxSizer)
1101 Slider : Slider widget (wxSlider)
1102 Split : Split widget (wxSplitterWindow)
1103 StaticText : wxWidget Static text
1104 TextCtrl : TextCtrl widget (wxTextCtrl)
1107 You can reproduce the same experiment as above using a
1108 \texttt{Slider} or a \texttt{FileDialog} rather than a \texttt{TextCtrl}.
1109 See the files \texttt{test*.bbs} in the \texttt{scripts/test} directory.
1111 There are two kind of widgets: ``terminal'' widgets and ``container'' widgets.
1112 The \texttt{TextCtrl}, \texttt{FileDialog} or \texttt{Slider} widgets
1113 are ``terminal'' widgets.
1114 ``container'' widgets are of another kind: they are made to
1115 contain other widgets in order to build larger dialog boxes.
1116 For example, the \texttt{Split} widget is a container which
1117 ``splits'' horizontally a window into two parts,
1118 each part including another widget.
1119 The size of the two parts can be adjusted by the user thanks
1122 The script \texttt{scripts/test/testSplit.bbs} demonstrate its use.
1123 Run it: it displays a window with two sliders.
1124 Move the sliders and close the window.
1125 The final positions of the sliders are printed out.
1126 Now edit the file to see how this is done:
1128 \begin{file}{scripts/test/testSplit.bbs}
1137 connect s.Child s1.Parent
1138 connect s.Child s2.Parent
1140 print s1=$s1.Out$\\n
1141 print s2=$s2.Out$\\n
1145 First, the two sliders \texttt{s1} and \texttt{s2} are created.
1146 A \texttt{Split} box \texttt{s} is also created.
1147 The \texttt{connect} commands then ``includes'' the sliders in the
1148 split ``container''.
1149 The input \texttt{Parent} is common to all widget boxes:
1150 every widget can be inserted into another widget.
1151 The output \texttt{Child} is specific of \emph{container}
1153 (in \bbi type \texttt{help Slider}:
1154 you will see the input \texttt{Parent};
1155 type \texttt{help Split}:
1156 you will see the input \texttt{Parent}
1157 and the output \texttt{Child}).
1158 When you connect the \texttt{Child} output of a container
1159 to the \texttt{Parent} input of a widget,
1160 you order to include the widget in the container.
1161 Of course, the order of connection is important.
1162 In our case, the slider \texttt{s1} is included first,
1163 then the slider \texttt{s2}: \texttt{s1} will be placed
1164 on top of \texttt{s2} (the \texttt{Split} box is
1165 implemented that way, but this is arbitrary choice).
1167 For the moment, there are only \emph{two} container widgets in the \texttt{wx} package:
1168 the \texttt{Split} widget we just described and the \texttt{Sizer}
1169 widget, which can have multiple children and
1170 divides its window into as much parts as children,
1171 each part of equal size.
1172 The orientation of the sizer can be changed by the input \texttt{Orientation}.
1173 See the example \texttt{test/testSizer.bbs}.
1174 With only those two containers you can already create
1175 complex dialog boxes (of course containers can be nested, which
1176 leads to tree-like structures of widgets).
1177 See the script \texttt{test/testSizerSplit.bbs} for an example.
1179 One word about a special widget in the package \texttt{wx}:
1180 the \texttt{Button}... to be continued.
1185 \item Make a tour of ``complex'' widgets of wxvtk
1186 \item Explain the role of ProcessMode to update widgets
1187 \item Explain the creation of complex widgets (containers, contained...)
1188 \item Explain the ``control'' mechanism in bbi (switch exec commands, e.g. Button)
1192 % ==========================================
1193 \subsection{More on ...}
1195 % ==========================================
1197 % ==========================================
1198 \subsubsection{Black box packages}
1199 \label{bbi-more-on-packages}
1200 % ==========================================
1202 % ==========================================
1203 \subsubsection{Pipeline processing}
1204 \label{bbi-more-on-pipeline-processing}
1205 % ==========================================
1207 % ==========================================
1208 \subsubsection{Complex black boxes}
1209 \label{bbi-more-on-complex-black-boxes}
1211 %\subsubsection{Advanced issues}
1212 %\paragraph{Reducing the number of inputs of a box}
1214 % ==========================================
1215 \subsubsection{Errors}
1216 \label{bbi-more-on-errors}
1218 % ==========================================
1219 \subsubsection{\bbtk configuration file and search pathes}
1220 \label{bbi-more-on-configuration}
1222 At start, \bbi tries to open an \texttt{xml}
1223 configuration file named \texttt{bbtk\_config.xml}.
1226 \item The current directory
1227 \item The subdir \texttt{.bbtk} of the user's home directory.
1229 \item On \texttt{Unix}, the home directory is the
1230 one stored by the environnement variable \texttt{HOME},
1231 typically \texttt{/home/username}.
1232 \item On \texttt{Windows}, the home directory is
1233 the user's profile directory stored by the environnement
1234 variable \texttt{USERPROFILE},
1235 typically \texttt{C:\\...}.
1237 \item If none of these two pathes contains the file then it creates
1238 a new one in the \texttt{.bbtk} directory.
1241 Once created, you can edit the \texttt{bbtk\_config.xml} file located
1242 in your \texttt{.bbtk} directory. It contains:
1244 \begin{file}{bbtk\_config.xml}
1246 <?xml version="1.0" encoding="iso-8859-1"?>
1248 <bbtk_url> http://www.creatis.insa-lyon.fr/software/bbtk </bbtk_url>
1249 <bbs_path> </bbs_path>
1250 <package_path> </package_path>
1251 <data_path> </data_path>
1256 You can add pathes to
1258 \item A custom folder in which to search for \texttt{.bbs} scripts (\texttt{include} command of \bbi) by adding an \texttt{xml} tag:
1259 \texttt{<bbs\_path>complete\_path\_to\_folder<\/bbs\_path>}.
1260 \item A custom folder in which to search for packages (\texttt{load} command of \bbi) by adding an \texttt{xml} tag:
1261 \texttt{<package\_path>complete\_path\_to\_folder<\/package\_path>}.
1264 % ==========================================
1265 \subsection{Language reference}
1266 \label{bbi-reference}
1267 % ==========================================
1273 % ==========================================
1275 \caption{\label{bbi-reference-box}
1276 \bbi pipeline creation and execution related commands.}
1278 \begin{tabular}{|lcm{6cm}|}
1280 Command & Parameters & Effect \\ \hline
1282 \texttt{new} & \texttt{<boxtype>} \texttt{<box-name>}&
1283 Creates a box of type \texttt{boxtype} and name
1287 \texttt{delete} & \texttt{<box-name>} &
1288 Destroys the box named \texttt{box-name}.
1291 \texttt{connect} & \texttt{<box1.output>} \texttt{<box2.input>} &
1293 \texttt{output} of the box named \texttt{box1}
1294 to the input \texttt{input} of the box named \texttt{box2} \\ \hline
1296 \texttt{set} & \texttt{<box.input>} \texttt{<value>} &
1297 Sets the input \texttt{input} of
1298 the box named \texttt{box} to the value \texttt{value}.
1299 There must exist an \texttt{adaptor}
1300 in the packages loaded which converts a \texttt{std::string}
1301 to the type of the input \texttt{input}.
1304 \texttt{print} & \texttt{<string>} &
1305 Prints the string after substituting each token of the form \texttt{\$box.output\$} by the adaptation to string of the value of the
1306 output \texttt{output} of the box named \texttt{box}.
1307 There must exist an \texttt{adaptor}
1308 in the packages loaded which converts
1309 the type of the output \texttt{output}
1310 to a \texttt{std::string}.
1313 \texttt{exec} & \texttt{<box-name>} &
1314 Executes the box named \texttt{box-name}.
1316 connected to its inputs
1317 are also processed recursively (pipeline processing).\\ \hline
1320 % ==========================================
1324 % ==========================================
1326 \caption{\label{bbi-reference-interpreter}\bbi intepreter related commands.}
1328 \begin{tabular}{|lcm{6cm}|}
1330 Command & Parameters & Effect \\ \hline
1334 Prints help on available commands \\ \hline
1336 & \texttt{<command-name>} &
1337 Prints help on the command \texttt{command-name} \\ \hline
1339 & \texttt{packages} &
1340 Prints help on available packages and their box types
1341 (without description)\\ \hline
1343 & \texttt{<package-name>} &
1344 Prints help on the package \texttt{package-name} and its boxes
1345 (with brief description).
1346 The package must have been previously loaded
1349 & \texttt{<box-type>} &
1350 Prints help (with full description) on the type of box
1352 The box type must belong to a package which has been previously loaded
1355 \texttt{include} & \texttt{<file-name>} &
1356 Includes and executes the content of the file named \texttt{file-name}
1357 exactly like if you were typing its content at the place were the
1358 \texttt{include} command is.
1361 \texttt{load} & \texttt{<package-name>} &
1362 Loads the package \texttt{package-name}\\ \hline
1364 \texttt{unload} & \texttt{<package-name>}&
1365 Unloads the package \texttt{package-name}.
1366 The package must have been previously loaded.
1367 No box of a type defined in this package must still exist.
1370 \texttt{message} & \texttt{<category>} \texttt{<level>} &
1371 Sets the level of verbosity of \bbi for the category of messages
1372 \texttt{category} to \texttt{level}.
1373 %See \ref{verbosity}.
1376 \texttt{config} & - & Displays the Configuration parameters\\ \hline
1378 \texttt{reset} & - & Deletes all boxes and unloads all packages so
1379 that \bbi gets back to its initial state \\ \hline
1381 \texttt{quit} & - & Exits the interpreter\\ \hline
1385 % ==========================================
1391 % ==========================================
1393 \caption{\label{bbi-reference-complex-box}
1394 \bbi complex black box definition related commands.}
1396 \begin{tabular}{|lcm{6cm}|}
1398 Command & Parameters & Effect \\ \hline
1401 \texttt{define} & \texttt{<box-type>} &
1402 Starts the definition of a complex black box of type
1403 \texttt{box-type}\\ \hline
1405 \texttt{endefine} & - &
1406 Ends the definition of a complex black box type\\ \hline
1409 \texttt{author} & \texttt{<string>} &
1410 Sets the author(s) of the complex black box currently being defined \\ \hline
1412 \texttt{description} & \texttt{<string>} &
1413 Sets the description of the complex black box currently being defined
1417 \texttt{input} & \texttt{<name>} \texttt{<box.input>} \texttt{<help>} &
1418 Defines a new input for the current complex black box,
1419 named \texttt{name}.
1420 It is defined as corresponding to
1421 the input \texttt{input} of the box \texttt{box}.
1422 \texttt{<help>} is the help string for the new input.
1423 The box \texttt{box} must already have been created in the complex box
1424 and of course have an input named \texttt{input}.
1428 \texttt{output} & \texttt{<name>} \texttt{<box.output>} \texttt{<help>} &
1429 Defines a new output for the current complex black box,
1430 named \texttt{name}.
1431 It is defined as corresponding to
1432 the output \texttt{output} of the box \texttt{box}.
1433 \texttt{<help>} is the help string for the new output.
1434 The box \texttt{box} must already have been created in the complex box and of course have an output named \texttt{output}.
1440 % ==========================================
1445 % ==========================================
1446 \vspace{0.5cm}\hrule
1447 \section{Using black boxes in \CPP programs}
1449 % ==========================================
1458 %\section{Conclusion}