2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 //=========================================================================
29 // How to create and use a script defined black box
30 //=========================================================================
32 //=========================================================================
33 #include <bbtkInterpreter.h>
34 //=========================================================================
36 //=========================================================================
37 int main(int argv, char* argc[])
40 //bbtk::MessageManager::SetMessageLevel("all",9);
44 // Create an interpreter
45 bbtk::Interpreter::Pointer I = bbtk::Interpreter::New();
47 // We tell the interpreter to throw exceptions on error
50 // Interpret the file supposed to define a box called 'Processing'
51 I->InterpretFile("bbProcessing.bbs");
53 // Create an instance 'p' of the 'Processing' box
54 bbtk::BlackBox::Pointer p
55 = I->GetExecuter()->GetFactory()->NewBlackBox("Processing","p");
58 std::cout << "Enter a number : ";
62 // Set its input 'In' to num
63 p->bbSetInput("In",num);
68 // Print out the output 'Out':
69 // 1) We get the output with the generic bbGetOutput method.
70 // 2) It returns a bbtk::Data which can store any data type
71 // 3) We get the value of the data as a double using get<TYPE>()
72 // (because we know it's a double !)
73 double v = p->bbGetOutput("Out").get<double>();
75 std::cout << num << "+1 = "<<v<<std::endl;
77 //============================================================
78 // Second example : imagine the bbProcessing.bbs script has created
79 // the box "a" of type Processing
80 // Here we simulate it using:
81 I->InterpretLine("new Processing a");
82 // We get a the black box "a" in the workspace:
83 bbtk::BlackBox::Pointer a
84 = I->GetExecuter()->GetWorkspace()->GetPrototype()->bbGetBlackBox("a");
85 // Then the same as previously...
86 a->bbSetInput("In",num);
88 double w = p->bbGetOutput("Out").get<double>();
89 std::cout << "In case you did not understand:"<<std::endl<<num << "+1 = "<<w<<std::endl;
93 catch (bbtk::Exception e)
95 std::cout << "* ERROR : "<<e.GetErrorMessage()<<std::endl;
101 // To get the list of bbtk object still allocated after main ends
102 // bbtk::StaticInitTime::PrintObjectListInfo = true;
103 // bbtk::MessageManager::SetMessageLevel("object",1);
105 //=========================================================================