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 /*=========================================================================
30 Module: $RCSfile: bbtkComplexBlackBox.h,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.9 $
34 =========================================================================*/
42 * \brief class bbtk::ComplexBlackBox : user defined complex black boxes
46 * \class bbtk::ComplexBlackBox
47 * \brief Abstract user defined black boxes
50 #ifndef __bbtkComplexBlackBox_h__
51 #define __bbtkComplexBlackBox_h__
53 #include "bbtkBlackBox.h"
54 #include "bbtkComplexBlackBoxDescriptor.h"
55 //#include "bbtkComplexBlackBoxInputDescriptor.h"
56 //#include "bbtkComplexBlackBoxOutputDescriptor.h"
57 #include "creaSystem.h"
65 //==================================================================
66 class BBTK_EXPORT ComplexBlackBox : public bbtk::BlackBox
68 BBTK_OBJECT_INTERFACE(ComplexBlackBox);
69 friend class ComplexBlackBoxDescriptor;
70 typedef BlackBox Superclass;
72 //==================================================================
73 // PUBLIC PART : ACCESSIBLE TO THE END-USER
74 /// Returns the pointer on the box' descriptor
75 BlackBoxDescriptor::Pointer bbGetDescriptor() const { return mDescriptor.lock(); }
76 /// Returns a pointer on a new instance with name <name>
77 //BlackBox* bbNew(const std::string& name);
78 /// Returns a pointer on a clone of the box with name <name>
79 BlackBox::Pointer bbClone(const std::string& name);
84 void SetAsPrototype() { mLockedDescriptor.reset(); }
85 /// Returns true if it is a prototype
86 bool IsAPrototype() const { return (!mLockedDescriptor); }
88 std::string bbGetNameWithParent() const;
90 void bbExecute(bool force = false);
92 Data bbGetOutput( const std::string &label );
93 Data bbGetInput ( const std::string &label );
94 void bbSetOutput( const std::string &name, Data data);
95 void bbSetInput ( const std::string &name, Data data,
96 bool setModified = true);
97 void bbBruteForceSetInputPointer( const std::string &name,
99 bool setModified = true);
101 /// Connects the input <name> to the connection c
102 virtual void bbConnectInput( const std::string& name, Connection* c);
103 /// Connects the output <name> to the connection c
104 virtual void bbConnectOutput( const std::string& name, Connection* c);
106 BlackBox::Pointer bbGetBlackBox( const std::string& name );
108 /// The type of map of black boxes
109 typedef std::map<std::string, BlackBox::Pointer> BlackBoxMapType;
111 const BlackBoxMapType& bbGetBlackBoxMap() { return mBlackBoxMap; }
113 void bbPrintBlackBoxes();
115 /// Generates a png image representing the pipeline graph of the
116 /// complex box and writes html code to insert it
117 /// into the output file stream.
119 /// level : depth of nested complex boxes graph development
120 /// (0:only this box level
121 /// output_dir is the directory in which to write the files
122 void bbInsertHTMLGraph( std::ofstream& s,
126 const std::string& output_dir,
127 bool relative_link );
129 /// Writes Graphviz-dot description in file.
130 /// Generates own description and recursively calls itself
131 /// on internal boxes with level-1
132 virtual void bbWriteDotFileBlackBox(FILE *ff,
133 BlackBox::Pointer parentblackbox,
134 int detail, int level,
136 bool relative_link );
138 virtual void bbWriteDotInputOutputName(FILE *ff,
140 int detail, int level);
142 virtual BlackBox::Pointer bbFindBlackBox(const std::string &blackboxname);
145 void Check(bool recursive=true);
150 //==================================================================
151 // PROTECTED PART : ACCESSIBLE TO ComplexBlackBoxDescriptor
152 static ComplexBlackBox::Pointer
153 New(const std::string &name,
154 ComplexBlackBoxDescriptor::Pointer desc);
157 /// Constructor that takes the ComplexBlackBox name
158 ComplexBlackBox(const std::string &name,
159 ComplexBlackBoxDescriptor::Pointer desc);
160 /// Constructor from an existing box (copy) with a new name
161 ComplexBlackBox(ComplexBlackBox& from, const std::string &name);
167 void bbAddBlackBox( BlackBox::Pointer );
168 void bbAddToExecutionList( const std::string& name );
169 void bbUnsafeAddBlackBox( BlackBox::Pointer );
170 void bbRemoveBlackBox( const std::string& name,
171 bool remove_connections = true);
172 void bbAddConnection( Connection::Pointer );
174 // void RemoveConnection( );
176 BlackBox::Pointer bbUnsafeGetBlackBox( const std::string& name );
179 void bbAllocateConnectors();
180 void bbDesallocateConnectors();
183 //==================================================================
184 // PRIVATE PART : MEMBERS AND USEFULL INTERNAL METHODS
186 /// Default constructor : derived classes must use the constructor with the ComplexBlackBox's name
187 //ComplexBlackBox() : BlackBox("") {}
189 // true if the box is a prototype of a ComplexBlackBoxDescriptor
190 // bool mIsAPrototype;
192 /// The descriptor pointer : is 0 if the box is a prototype
193 ComplexBlackBoxDescriptor::Pointer mLockedDescriptor;
194 /// The descriptor pointer
195 ComplexBlackBoxDescriptor::WeakPointer mDescriptor;
197 /// The map of black boxes
198 BlackBoxMapType mBlackBoxMap;
201 /// The type of list of connections
202 typedef std::list<Connection::Pointer> ConnectionListType;
203 /// The list of connections
204 ConnectionListType mConnectionList;
206 /// The execution list
207 std::vector<std::string> mExecutionList;
210 // Class ComplexBlackBox
211 //===========================================================================
219 //#include "bbtkComplexBlackBoxMacros.h"