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 ? their 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:
277 To get help on a particular command type \texttt{help <command-name>},
287 Quits the program (during script execution it stops the complete execution)
290 The \texttt{help} command has multiple usages.
291 It is used to get help on almost anything in \bbi !
292 Type \texttt{'help help'} to get help on the \texttt{help} command itself:
297 (2) help <command name>
298 (3) help packages [all]
299 (4) help <package name> [all]
300 (5) help <black box type>
301 (6) help <black box name>
303 (1) Lists all available commands;
304 (2) Prints help on a particular command;
305 (3) Lists the packages loaded and their black boxes.
306 Add 'all' to list adaptors;
307 (4) Prints short help on the black boxes of a package.
308 Add 'all' to include adaptors;
309 (5) Prints full help on a black box type;
310 (6) Prints information on the inputs, outputs and connections of a black box instance.
313 At start \bbi does not know any black box.
314 If you type \texttt{'help packages'}, which is
315 the third form of the \texttt{help} command, you get:
322 which means that \bbi only knows one package
323 (library of black boxes) called \texttt{user}
324 and which contains a black box called \texttt{workspace}.
325 The \texttt{user} package is an internal package to \bbi,
326 which stores user-defined black box types.
327 At start, it already contains
328 one box, called \texttt{workspace}.
329 \texttt{workspace} is a special type of black box,
330 called complex black box, whose purpose is
331 to store other black boxes.
332 Any black box you create in \bbi is stored
333 in \texttt{workspace}
334 (this will be explained in details in sections
335 \ref{bbi-writing-scripts} and
336 \ref{bbi-more-on-complex-black-boxes}).
338 If you type \texttt{'help workspace'}, you get:
341 Complex Black Box <user::workspace>
344 Category(s) : complex box;
350 In the text displayed,
351 the \texttt{user::} prepended to the name \texttt{workspace}
352 means that the box \texttt{workspace}
353 belongs to the \texttt{user} package.
354 Then comes a description and three lines which
355 tell that \texttt{workspace} does not have any input
356 nor output nor boxes yet.
358 In order to let \bbi know of some black boxes,
359 you must load another package.
360 The \texttt{std} package is the ``standard'' package,
361 which contains basic useful black boxes.
373 you get something like:
388 Now \bbi knows the package \texttt{std} and the black boxes it provides,
389 such as the \texttt{'Add'} box, the \texttt{'ConcatStrings'}. Remark that the
390 content of \texttt{std} may vary from one version to another
391 as new black boxes might be added to it.
401 By : laurent.guigues@creatis.insa-lyon.fr
402 Categories : atomic box;math;
404 'BoxExecute' <bbtk::Void> [signal] : Any signal received by this input executes the box
405 'BoxProcessMode' <String> [] : Sets the processing mode of the box (Pipeline | Always | Reactive)
406 'In1' <Double> [] : First number to add
407 'In2' <Double> [] : Second number to add
409 'BoxChange' <bbtk::Void> [signal] : Signals modifications of the box
410 'Out' <Double> [] : Result
414 the \texttt{std::} prepended to the name \texttt{Add}
415 means that the box \texttt{Add}
416 belongs to the \texttt{std} package.
417 Then comes a description
418 (the one which was provided by the author of the box),
419 the author(s) of the box (usually e-mail adress(es)) and
420 the categories to which the box belong.
421 Finally comes the lists of inputs and outputs of the box.
422 For each input or output, \bbi provides
423 its \emph{name} (between quotes, e.g. \texttt{'ProcessMode'}),
424 its \emph{type} (between \texttt{<>}, e.g. \texttt{<Int>})
426 Remark that the box \texttt{Add} is not a 'complex' black box
427 but an 'atomic' box, hence its help does not
428 mention any information concerning possible internal boxes.
430 You can create an \emph{instance} of an \texttt{Add} box by
431 the command \texttt{new}:
436 The \texttt{'a'} at the end is the \emph{name} of the instance,
437 which will be used to reference it later.
438 It is important to distinguish a box \emph{types}
439 and an \emph{instance} of a box type.
440 The \texttt{Add} box of the package \texttt{std} is actually
441 a \emph{box type} , like \texttt{int} is a data type
442 in \texttt{C} langage. The \texttt{new} command allows to create
443 an instance of a box type, exactly like \texttt{int i;} in
444 a \texttt{C} code declares a variable of type \texttt{int} whose
446 Of course, like in \texttt{C} Language, you can declare multiple boxes of the
449 After the creation of the box \texttt{a}, type:
456 Complex Black Box <user::workspace>
459 Category(s) : complex box;
466 which means that \bbi workspace now contains a black box named \texttt{a},
467 of type \texttt{std::Add}.
469 Now look back at the help on \texttt{Add} boxes:
470 you can see that this type of box has two inputs,
471 with name \texttt{In1} and \texttt{In2},
472 and an output, with name \texttt{Out}.
474 You can set the input \texttt{In1}
475 of the \texttt{Add} box \texttt{a} to the value $1$
481 Similarly, setting the input \texttt{In2} of \texttt{a} to the value $2$
487 And you print the output \texttt{Out} of the box \texttt{a} with:
489 > print "result=$a.Out$"
493 In the string passed to the \texttt{print} command,
494 each substring enclosed between a couple of \$ is considered
495 as the name of an output of a box.
496 To process this special substrings, \bbi does:
498 \item Processes the box if needed (see below)
499 \item Converts the output of the box to a string if possible
501 \item Substitutes the result in the string to print
502 \item postpone an implicit 'new line' character to the string
505 Box processing is needed if:
507 \item at least input has changed since last processing or
508 \item the input \texttt{'BoxProcessMode'} of the box is set to
509 \texttt{'Always'}, which forces box reprocessing.
512 Note that all boxes have the input \texttt{'BoxProcessMode'}.
514 Another way to process the box \texttt{a} is to issue the command:
519 however this command does not display anything (except if the
520 box itself displays something in its processing).
521 It just processes the box if needed.
522 This command is used to execute boxes that do not have any output,
523 such as boxes that write something to a file or, display a
524 graphical interface, and so on.
532 % ==========================================
537 \item The \texttt{include} command allows to load a package.
538 \item \texttt{help} gives help on:
540 \item Available commands if you just type \texttt{help}.
541 \item A particular command if you type \texttt{help <command-name>}.
542 \item All available packages and their boxes (without description) if you type \texttt{help packages}.
543 \item A particular package and its boxes (with brief description) if you type \texttt{help <package-name>}.
544 \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}).
546 %\item \texttt{list} displays the list of black box instances created so far (by \texttt{new}).
547 \item \texttt{new} creates an instance of a black box.
548 \item \texttt{set} sets the value of an input of a black box.
549 \item In all \bbi, to reference the input called \texttt{i}
550 of a black box called \texttt{b} you must type \texttt{'b.i'}.
551 The same syntax holds for outputs.
552 \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}. Note that an
553 implicit trailing 'new line character' is added at the final string.
554 \item \texttt{exec} runs the process of a box if needed.
555 \item \texttt{quit} quits \bbi.
558 % ==========================================
560 % ==========================================
561 \subsubsection{Connecting black boxes}
562 \label{bbi-connecting-black-boxes}
563 % ==========================================
565 LG : THE GUIDE IS UP TO DATE UNTIL HERE
567 \BBTK allows to create
568 and execute processing chains,
569 also called \emph{pipelines},
570 by connecting black boxes.
571 This section explains how to do it with examples.
572 Read section \ref{bbi-more-on-pipeline-processing} to get
573 more information on pipeline processing.
575 First start \bbi and load the package \texttt{std}:
580 Assume you want to compute $1+2+3$. You can do it by
581 chaining two \texttt{Add} boxes, as shown in figure
582 \ref{bbi-fig-connecting-black-boxes-1}.
585 \caption{\label{bbi-fig-connecting-black-boxes-1}
586 A simple pipeline which adds 3 numbers}
588 \includegraphics[width=0.5\textwidth]{1plus2plus3.png}
592 The \bbi instructions to create and execute this pipeline are:
596 > connect a.Out b.In1
604 The first three commands build the pipeline,
605 the next three set its inputs and the last one
606 executes it and prints its output.
608 The command \texttt{'connect a.Out b.In1'} ``plugs'' the output
609 \texttt{Out} of the box \texttt{a} into the input \texttt{In1} of the
611 Once the boxes connected, the processing of the two boxes are chained:
612 getting the output of \texttt{b} requires getting its inputs,
613 hence getting the output of \texttt{a} which is connected to it.
614 This pipeline mechanism can recurse into arbitrary long
615 chains of boxes (see \ref{bbi-more-on-pipeline-processing}
618 Of course, to be able to connect two boxes,
619 the output and the input must be compatibles.
620 You can always connect an output to an input of the \emph{same} type,
621 but you can do more, thanks to particular black boxes called {\bf adaptors}.
623 An adaptor is a black box which has at least one input, called \texttt{In},
624 and at least one ouput called \texttt{Out} and whose role is to convert
625 a data of the type of \texttt{In}
626 into a data of the type of \texttt{Out} (other inputs or outputs may serve
627 to parameter the adaptor or retreive other usefull information).
629 In \bbi, if you type:
636 Package std v1.0.0 - laurent.guigues@creatis.insa-lyon.fr
637 Basic useful black boxes
639 Add : Adds its inputs
640 Cast<double,float> [DA] : Casts a double into a float
641 Cast<double,int> [DA] : Casts a double into a int
643 Convert<unsigned int,string> [DA] : Converts a unsigned int into a s...
644 Convert<unsigned short,string> [DA] : Converts a unsigned short into a...
645 Print : Prints its input to standard out...
649 The \texttt{Cast<?,?>} and \texttt{Convert<?,?>} boxes are \emph{default adaptors}, which is signaled by the tag \texttt{[DA]} before their descriptions.
651 Once you have loaded the package \texttt{std}, you can
652 plug an output of type \texttt{char} into an input of type \texttt{double}.
653 When \bbi encounters the \texttt{connect} command,
654 it looks for an adequate \emph{adaptor} in the loaded packages.
655 In our case, as the package \texttt{std} provides the
656 \texttt{Cast<char,double>} adaptor, \bbi automatically creates an
657 instance of this adaptor and place it \emph{between}
658 the output and the input you want to connect
659 (however this adaptor is hidden to you,
660 it is embedded into the created connection and does not appear
661 as an existing black box).
662 When the pipeline is processed the
663 adaptor converts the output data into the required input type,
664 in a totally transparent way.
665 In our example, the \texttt{Cast<char,double>} adaptor
666 would simply cast the value of the \texttt{char} into a \texttt{double},
667 however arbitrarily complex type conversion can be done.
670 if two adaptors with the same input and output types exist
671 in the packages loaded,
672 which one is chosen by \bbi at connection ?
673 -> Role of default adaptors
675 Note that the \texttt{set} and \texttt{print} commands of \bbi
676 work with adaptors from \texttt{string} to the type of the input to set
677 or from the type of the output to print to \texttt{string}.
678 Hence in order to \texttt{set} or \texttt{print} values the adequate
679 adaptors must be available in the packages currently loaded.
681 % ==========================================
686 \item The \texttt{connect} command allows to connect two black boxes
687 \item You can connect two black boxes if (and only if):
689 \item The output and the input are of the same type, or
690 \item There is an adaptor black box in the packages loaded which
691 converts data of the output type into data of the input type
693 \item \texttt{help <package name>} does not display the adaptors of the package. To see them use: \texttt{help <package name> all}.
697 % ==========================================
699 % ==========================================
700 \subsubsection{Creating complex black boxes}
701 \label{bbi-complex-black-boxes}
702 % ==========================================
704 Remember the pipeline of figure
705 \ref{bbi-fig-connecting-black-boxes-1}, which
706 computed the sum of three doubles ?
707 You can view it as a whole and define
708 a new black box type, which will be a \emph{complex black box},
709 having three inputs and one output,
710 as shown in figure \ref{bbi-fig-complex-black-box-1}.
713 \caption{\label{bbi-fig-complex-black-box-1}
714 Creating the complex black box \texttt{Add3}}
716 \includegraphics[width=0.5\textwidth]{Add3.png}
720 The \bbi commands to define this complex black box are
730 > connect a.Out b.In1
733 > description "adds 3 doubles"
734 > input x a.In1 "first double to add"
735 > input y a.In2 "second double to add"
736 > input z b.In2 "third double to add"
737 > output result b.Out "output"
744 As we will use \texttt{Add} boxes, we need to load the package \texttt{std}, which is done in first line.
746 The command \texttt{define} then starts the definition
747 of the complex box type, which will be called \texttt{Add3}.
749 The next three lines define the pipeline,
750 exactly in the same way than outside a complex box definition.
752 The commands \texttt{author}, \texttt{description}, \texttt{input}
753 and \texttt{output} are commands specific to complex boxes definition:
755 \texttt{author} and \texttt{description} are used for the documentation
756 of the new box. You can provide multiple \texttt{author} or
757 \texttt{description} commands, the arguments of the commands will
758 be concatenated to produce the final author and description strings.
760 \texttt{input} and \texttt{output} are used to define the inputs and outputs
761 of the new complex box.
762 Their syntax is the same: for each new input/output you need to say
763 to which internal input/output it corresponds and to provide
764 a help string documenting the input/output.
765 In our example, we define that the box \texttt{Add3} has
766 three inputs: \texttt{x}, \texttt{y} and \texttt{z}.
767 The input \texttt{x} corresponds to the input \texttt{In1} of the
768 internal box \texttt{a}.
769 In the same way, the external input \texttt{y}
770 corresponds to the internal input \texttt{a.In2}, and
771 the external input \texttt{In3} to \texttt{b.In2}.
772 The only output of the new box is called \texttt{result}
773 and corresponds to \texttt{b.Out}.
774 The figure \ref{bbi-fig-complex-black-box-1}
775 illustrates the external to internal
776 input/output correspondence.
778 Finally, the \texttt{endefine} command ends the definition of the
781 After this definition, if you ask for help
782 on packages, you get:
793 The \texttt{user} package now contains a new black box type, called
794 \texttt{Add3}. If you ask for help on this type of box, you get:
797 Complex Black Box <user::Add3>
801 'x' <double>: first double to add
802 'y' <double>: second double to add
803 'z' <double>: third double to add
805 'result' <double>: output
811 and you can use it like any other box, for example type:
823 % ==========================================
828 \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.
829 Inside a \texttt{define/endefine} block:
831 \item The \texttt{author} and \texttt{description} commands allow to document the new type of box
832 \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
833 of internal boxes they correspond.
837 % ==========================================
839 % ==========================================
840 \subsubsection{Writing scripts}
841 \label{bbi-writing-scripts}
842 % ==========================================
844 Once you have defined a new type of complex box, you
845 may like to reuse it. To do this, you can simply
846 write the \bbi commands defining the new box
847 into a text file and afterwards include that file in \bbi.
848 Doing this, you start writing \bbi scripts.
849 The conventionnal extension for such scripts is \texttt{bbs}
852 For example, the \texttt{Add3} complex box we previously worked on
853 can be defined in the \texttt{Add3.bbs} file:
855 \begin{file}{Add3.bbs}
857 # Defines the Add3 black box which adds 3 doubles
863 description "adds 3 doubles"
869 input x a.In1 "first double to add
870 input y a.In2 "second double to add
871 input z b.In2 "third double to add"
873 output result b.Out "output"
878 Lines starting with a \texttt{\#} character are ignored, they
879 are considered as comments by \bbi.
880 To use this file in \bbi, use the \texttt{include} command:
885 Complex Black Box <user::Add3>
889 'x' <double>: first double to add
890 'y' <double>: second double to add
891 'z' <double>: third double to add
893 'result' <double>: output
901 If the file has the \texttt{bbs} extension, you can ommit it and just type:
906 Of course, you can include script files in other script files,
907 like in the following example:
909 \begin{file}{Add4.bbs}
911 # Defines the Add4 black box which adds 4 doubles
916 description "adds 4 doubles"
920 input In1 a.In1 "first double to add
921 input In2 a.In2 "second double to add
922 input In3 a.In3 "third double to add"
923 input In4 b.In2 "fourth double to add"
924 output Out b.Out "output"
931 - naming conventions: one cbb per file with the same name
934 % ==========================================
939 \item The \texttt{include} command allows to include a script file in \bbi.
940 \item Lines starting with a \texttt{\#} are treated as comments in \bbi scripts.
943 % ==========================================
945 % ==========================================
946 \subsubsection{Creating command line applications}
947 \label{bbi-command-line-app}
948 % ==========================================
950 Now that you now how to create complex black boxes
951 (with \texttt{define/endefine}), think
952 back to the \texttt{workspace} object.
953 Remember that it is also
954 a \texttt{complex black box}.
955 In fact what you are doing when you type \bbi commands
956 outside a \texttt{define/endefine} block
957 is to progressively define the \texttt{workspace}
959 You can think of it like if at start
960 \bbi was issuing a command \texttt{'define workspace'}
961 and then letting you define the interior of the box
964 Remember that the command \texttt{inputs}
965 allows to define an input of a complex box.
966 Now, if you use the command \texttt{input}
967 outside a \texttt{define/endefine} block then
968 it defines an input of the \texttt{workspace} box,
969 that is an input of the \emph{main program}.
970 This input will then be connected to the
971 parameters that the user passes to the command line.
973 For example, consider the script:
975 \begin{file}{add.bbs}
979 input x a.In1 "first number to add"
980 input y a.In2 "second number to add"
985 The third and fourth lines define two inputs \texttt{x}
986 and \texttt{y}. When you execute this script,
987 you can pass these two arguments on the command line,
995 You can also invoke \bbi the option \texttt{-h},
996 which gives help on the \texttt{workspace} box:
1003 'x' <double>: first number to add
1004 'y' <double>: second number to add
1007 To get a better help, use the \texttt{description}
1008 and \texttt{author} commands:
1010 \begin{file}{add.bbs}
1012 description "Adds two numbers"
1013 author "foo@bar.com"
1016 input x a.In1 "first number to add"
1017 input y a.In2 "second number to add"
1022 Now if you ask for help on the \texttt{add} script, you get:
1029 'x' <double>: first number to add
1030 'y' <double>: second number to add
1033 Rather than getting the inputs of a script
1034 from the command line, you can ask \bbi to
1035 prompt the user for the values, using the \texttt{-t}
1040 x=[the program waits for user answer]2
1041 y=[the program waits for user answer]5
1045 If \bbi is compiled in graphical mode (with \wx),
1046 you can also use the \texttt{-g} commutator.
1047 \bbi then prompts the user in graphical mode,
1048 displaying a dialog box for each input,
1049 like in fig. \ref{bb-input-dialog-box}.
1052 \caption{\label{bb-input-dialog-box}Input dialog box}
1054 \includegraphics[width=0.6\textwidth]{enter-the-value-of-x.png}
1058 % ==========================================
1063 \item The \texttt{input}, \texttt{description} and \texttt{author} commands,
1064 when they are used outside a \texttt{define/endefine} block allow
1065 to define the inputs, description and author of the main program.
1066 \item Inputs of the main program can be passed on the command line
1067 using the syntax \texttt{<input-name>=<value>}.
1068 No white space is allowed, if the value or the input name
1069 contains white spaces, enclose them
1070 between double quotes, e.g. \texttt{"parameter with white spaces = gnu's not unix"}.
1071 \item The \texttt{-h} option of \bbi prints help on the main program.
1072 \item The \texttt{-t} option of \bbi orders the program to prompt for its inputs in text mode.
1073 \item The \texttt{-g} option of \bbi orders the program to prompt for its inputs in graphical mode.
1076 % ==========================================
1078 % ==========================================
1079 \subsubsection{Using graphical interface boxes (widget boxes)}
1081 % ==========================================
1083 If \bbi is compiled in graphical mode
1084 (option \texttt{BUILD\_bbi\_GRAPHICAL} of \cmake, requires \wx),
1085 then you can use special black boxes which are
1086 graphical interface components (widgets).
1087 Basic components are provided in the package \texttt{wx},
1088 such as buttons, sliders, file open/save dialogs, etc.
1090 As first example, type the following commands in \bbi:
1097 When you type \texttt{enter} after the last line,
1098 a window pops up in which you can entrer a text.
1099 When you close the window, the text you entered is printed by
1100 the \texttt{print} command.
1102 Type \texttt{help wx}, you get something like:
1104 Package wx v1.0.0- info-dev@creatis.insa-lyon.fr
1105 Basic graphical interface elements (slider, button ...) based on wxWidgets
1107 Button : Button that gives a string
1108 ColourSelectorButton :
1109 ColourSelector : Colour Selector widget (wxColourDialog)
1112 FileSelector : FileDialog widget (wxFileDialog)
1113 InputText : TextCtrl widget (wxTextCtrl)
1114 LayoutLine : Sizer widget (wxSizer)
1115 LayoutSplit : Split widget (wxSplitterWindow)
1117 OutputText : wxWidget Static text
1118 RadioButton : RadioButton group widget (wxRadioButton) 0-9 entries
1119 Slider : Slider widget (wxSlider)
1123 You can reproduce the same experiment as above using a
1124 \texttt{Slider} or a \texttt{FileDialog} rather than a \texttt{TextCtrl}.
1125 See the files \texttt{test*.bbs} in the \texttt{scripts/test} directory.
1127 There are two kind of widgets: ``terminal'' widgets and ``container'' widgets.
1128 The \texttt{TextCtrl}, \texttt{FileDialog} or \texttt{Slider} widgets
1129 are ``terminal'' widgets.
1130 ``container'' widgets are of another kind: they are made to
1131 contain other widgets in order to build larger dialog boxes.
1132 For example, the \texttt{Split} widget is a container which
1133 ``splits'' horizontally a window into two parts,
1134 each part including another widget.
1135 The size of the two parts can be adjusted by the user thanks
1138 The script \texttt{scripts/test/testSplit.bbs} demonstrate its use.
1139 Run it: it displays a window with two sliders.
1140 Move the sliders and close the window.
1141 The final positions of the sliders are printed out.
1142 Now edit the file to see how this is done:
1144 \begin{file}{scripts/test/testSplit.bbs}
1153 connect s.Child s1.Parent
1154 connect s.Child s2.Parent
1156 print s1=$s1.Out$\\n
1157 print s2=$s2.Out$\\n
1161 First, the two sliders \texttt{s1} and \texttt{s2} are created.
1162 A \texttt{Split} box \texttt{s} is also created.
1163 The \texttt{connect} commands then ``includes'' the sliders in the
1164 split ``container''.
1165 The input \texttt{Parent} is common to all widget boxes:
1166 every widget can be inserted into another widget.
1167 The output \texttt{Child} is specific of \emph{container}
1169 (in \bbi type \texttt{help Slider}:
1170 you will see the input \texttt{Parent};
1171 type \texttt{help Split}:
1172 you will see the input \texttt{Parent}
1173 and the output \texttt{Child}).
1174 When you connect the \texttt{Child} output of a container
1175 to the \texttt{Parent} input of a widget,
1176 you order to include the widget in the container.
1177 Of course, the order of connection is important.
1178 In our case, the slider \texttt{s1} is included first,
1179 then the slider \texttt{s2}: \texttt{s1} will be placed
1180 on top of \texttt{s2} (the \texttt{Split} box is
1181 implemented that way, but this is arbitrary choice).
1183 For the moment, there are only \emph{two} container widgets in the \texttt{wx} package:
1184 the \texttt{Split} widget we just described and the \texttt{Sizer}
1185 widget, which can have multiple children and
1186 divides its window into as much parts as children,
1187 each part of equal size.
1188 The orientation of the sizer can be changed by the input \texttt{Orientation}.
1189 See the example \texttt{test/testSizer.bbs}.
1190 With only those two containers you can already create
1191 complex dialog boxes (of course containers can be nested, which
1192 leads to tree-like structures of widgets).
1193 See the script \texttt{test/testSizerSplit.bbs} for an example.
1195 One word about a special widget in the package \texttt{wx}:
1196 the \texttt{Button}... to be continued.
1201 \item Make a tour of ``complex'' widgets of wxvtk
1202 \item Explain the role of ProcessMode to update widgets
1203 \item Explain the creation of complex widgets (containers, contained...)
1204 \item Explain the ``control'' mechanism in bbi (switch exec commands, e.g. Button)
1208 % ==========================================
1209 \subsection{More on ...}
1211 % ==========================================
1213 % ==========================================
1214 \subsubsection{Black box packages}
1215 \label{bbi-more-on-packages}
1216 % ==========================================
1218 % ==========================================
1219 \subsubsection{Pipeline processing}
1220 \label{bbi-more-on-pipeline-processing}
1221 % ==========================================
1223 % ==========================================
1224 \subsubsection{Complex black boxes}
1225 \label{bbi-more-on-complex-black-boxes}
1227 %\subsubsection{Advanced issues}
1228 %\paragraph{Reducing the number of inputs of a box}
1230 % ==========================================
1231 \subsubsection{Errors}
1232 \label{bbi-more-on-errors}
1234 % ==========================================
1235 \subsubsection{\bbtk configuration file and search pathes}
1236 \label{bbi-more-on-configuration}
1238 At start, \bbi tries to open an \texttt{xml}
1239 configuration file named \texttt{bbtk\_config.xml}.
1242 \item The current directory
1243 \item The subdir \texttt{.bbtk} of the user's home directory.
1245 \item On \texttt{Unix}, the home directory is the
1246 one stored by the environnement variable \texttt{HOME},
1247 typically \texttt{/home/username}.
1248 \item On \texttt{Windows}, the home directory is
1249 the user's profile directory stored by the environnement
1250 variable \texttt{USERPROFILE},
1251 typically \texttt{C:\\...}.
1253 \item If none of these two pathes contains the file then it creates
1254 a new one in the \texttt{.bbtk} directory.
1257 Once created, you can edit the \texttt{bbtk\_config.xml} file located
1258 in your \texttt{.bbtk} directory. It contains:
1260 \begin{file}{bbtk\_config.xml}
1262 <?xml version="1.0" encoding="iso-8859-1"?>
1264 <bbtk_url> http://www.creatis.insa-lyon.fr/software/bbtk </bbtk_url>
1265 <bbs_path> </bbs_path>
1266 <package_path> </package_path>
1267 <data_path> </data_path>
1272 You can add pathes to
1274 \item A custom folder in which to search for \texttt{.bbs} scripts (\texttt{include} command of \bbi) by adding an \texttt{xml} tag:
1275 \texttt{<bbs\_path>complete\_path\_to\_folder<\/bbs\_path>}.
1276 \item A custom folder in which to search for packages (\texttt{load} command of \bbi) by adding an \texttt{xml} tag:
1277 \texttt{<package\_path>complete\_path\_to\_folder<\/package\_path>}.
1280 % ==========================================
1281 \subsection{Language reference}
1282 \label{bbi-reference}
1283 % ==========================================
1289 % ==========================================
1291 \caption{\label{bbi-reference-box}
1292 \bbi pipeline creation and execution related commands.}
1294 \begin{tabular}{|lcm{6cm}|}
1296 Command & Parameters & Effect \\ \hline
1298 \texttt{new} & \texttt{<boxtype>} \texttt{<box-name>}&
1299 Creates a box of type \texttt{boxtype} and name
1303 \texttt{delete} & \texttt{<box-name>} &
1304 Destroys the box named \texttt{box-name}.
1307 \texttt{connect} & \texttt{<box1.output>} \texttt{<box2.input>} &
1309 \texttt{output} of the box named \texttt{box1}
1310 to the input \texttt{input} of the box named \texttt{box2} \\ \hline
1312 \texttt{set} & \texttt{<box.input>} \texttt{<value>} &
1313 Sets the input \texttt{input} of
1314 the box named \texttt{box} to the value \texttt{value}.
1315 There must exist an \texttt{adaptor}
1316 in the packages loaded which converts a \texttt{std::string}
1317 to the type of the input \texttt{input}.
1320 \texttt{print} & \texttt{<string>} &
1321 Prints the string after substituting each token of the form \texttt{\$box.output\$} by the adaptation to string of the value of the
1322 output \texttt{output} of the box named \texttt{box}.
1323 There must exist an \texttt{adaptor}
1324 in the packages loaded which converts
1325 the type of the output \texttt{output}
1326 to a \texttt{std::string}.
1329 \texttt{exec} & \texttt{<box-name>} &
1330 Executes the box named \texttt{box-name}.
1332 connected to its inputs
1333 are also processed recursively (pipeline processing).\\ \hline
1336 % ==========================================
1340 % ==========================================
1342 \caption{\label{bbi-reference-interpreter}\bbi intepreter related commands.}
1344 \begin{tabular}{|lcm{6cm}|}
1346 Command & Parameters & Effect \\ \hline
1350 Prints help on available commands \\ \hline
1352 & \texttt{<command-name>} &
1353 Prints help on the command \texttt{command-name} \\ \hline
1355 & \texttt{packages} &
1356 Prints help on available packages and their box types
1357 (without description)\\ \hline
1359 & \texttt{<package-name>} &
1360 Prints help on the package \texttt{package-name} and its boxes
1361 (with brief description).
1362 The package must have been previously loaded
1365 & \texttt{<box-type>} &
1366 Prints help (with full description) on the type of box
1368 The box type must belong to a package which has been previously loaded
1371 \texttt{include} & \texttt{<file-name>} &
1372 Includes and executes the content of the file named \texttt{file-name}
1373 exactly like if you were typing its content at the place were the
1374 \texttt{include} command is.
1377 \texttt{load} & \texttt{<package-name>} &
1378 Loads the package \texttt{package-name}\\ \hline
1380 \texttt{unload} & \texttt{<package-name>}&
1381 Unloads the package \texttt{package-name}.
1382 The package must have been previously loaded.
1383 No box of a type defined in this package must still exist.
1386 \texttt{message} & \texttt{<category>} \texttt{<level>} &
1387 Sets the level of verbosity of \bbi for the category of messages
1388 \texttt{category} to \texttt{level}.
1389 %See \ref{verbosity}.
1392 \texttt{config} & - & Displays the Configuration parameters\\ \hline
1394 \texttt{reset} & - & Deletes all boxes and unloads all packages so
1395 that \bbi gets back to its initial state \\ \hline
1397 \texttt{quit} & - & Exits the interpreter\\ \hline
1401 % ==========================================
1407 % ==========================================
1409 \caption{\label{bbi-reference-complex-box}
1410 \bbi complex black box definition related commands.}
1412 \begin{tabular}{|lcm{6cm}|}
1414 Command & Parameters & Effect \\ \hline
1417 \texttt{define} & \texttt{<box-type>} &
1418 Starts the definition of a complex black box of type
1419 \texttt{box-type}\\ \hline
1421 \texttt{endefine} & - &
1422 Ends the definition of a complex black box type\\ \hline
1425 \texttt{author} & \texttt{<string>} &
1426 Sets the author(s) of the complex black box currently being defined \\ \hline
1428 \texttt{description} & \texttt{<string>} &
1429 Sets the description of the complex black box currently being defined
1433 \texttt{input} & \texttt{<name>} \texttt{<box.input>} \texttt{<help>} &
1434 Defines a new input for the current complex black box,
1435 named \texttt{name}.
1436 It is defined as corresponding to
1437 the input \texttt{input} of the box \texttt{box}.
1438 \texttt{<help>} is the help string for the new input.
1439 The box \texttt{box} must already have been created in the complex box
1440 and of course have an input named \texttt{input}.
1444 \texttt{output} & \texttt{<name>} \texttt{<box.output>} \texttt{<help>} &
1445 Defines a new output for the current complex black box,
1446 named \texttt{name}.
1447 It is defined as corresponding to
1448 the output \texttt{output} of the box \texttt{box}.
1449 \texttt{<help>} is the help string for the new output.
1450 The box \texttt{box} must already have been created in the complex box and of course have an output named \texttt{output}.
1456 % ==========================================
1461 % ==========================================
1462 \vspace{0.5cm}\hrule
1463 \section{Using black boxes in \CPP programs}
1465 % ==========================================
1474 %\section{Conclusion}