1 /*=========================================================================
4 Module: $RCSfile: bbtkComplexBlackBox.h,v $
6 Date: $Date: 2008/04/18 12:59:15 $
7 Version: $Revision: 1.3 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
22 * \brief class bbtk::ComplexBlackBox : user defined complex black boxes
26 * \class bbtk::ComplexBlackBox
27 * \brief Abstract user defined black boxes
30 #ifndef __bbtkComplexBlackBox_h__
31 #define __bbtkComplexBlackBox_h__
33 #include "bbtkBlackBox.h"
34 #include "bbtkComplexBlackBoxDescriptor.h"
35 //#include "bbtkComplexBlackBoxInputDescriptor.h"
36 //#include "bbtkComplexBlackBoxOutputDescriptor.h"
44 //==================================================================
45 class BBTK_EXPORT ComplexBlackBox : public bbtk::BlackBox
47 BBTK_OBJECT_INTERFACE(ComplexBlackBox);
48 friend class ComplexBlackBoxDescriptor;
49 typedef BlackBox Superclass;
51 //==================================================================
52 // PUBLIC PART : ACCESSIBLE TO THE END-USER
53 /// Returns the pointer on the box' descriptor
54 BlackBoxDescriptor::Pointer bbGetDescriptor() const { return mDescriptor.lock(); }
55 /// Returns a pointer on a new instance with name <name>
56 //BlackBox* bbNew(const std::string& name);
57 /// Returns a pointer on a clone of the box with name <name>
58 BlackBox::Pointer bbClone(const std::string& name);
63 void SetAsPrototype() { mLockedDescriptor.reset(); }
64 /// Returns true if it is a prototype
65 bool IsAPrototype() const { return (!mLockedDescriptor); }
67 std::string bbGetNameWithParent() const;
69 void bbExecute(bool force = false);
71 Data bbGetOutput( const std::string &label );
72 Data bbGetInput ( const std::string &label );
73 void bbSetOutput( const std::string &name, Data data);
74 void bbSetInput ( const std::string &name, Data data,
75 bool setModified = true);
76 void bbBruteForceSetInputPointer( const std::string &name,
78 bool setModified = true);
80 /// Connects the input <name> to the connection c
81 virtual void bbConnectInput( const std::string& name,
82 Connection::Pointer c);
83 /// Connects the output <name> to the connection c
84 virtual void bbConnectOutput( const std::string& name,
85 Connection::Pointer c);
87 BlackBox::Pointer bbGetBlackBox( const std::string& name );
89 /// The type of map of black boxes
90 typedef std::map<std::string, BlackBox::Pointer> BlackBoxMapType;
92 const BlackBoxMapType& bbGetBlackBoxMap() { return mBlackBoxMap; }
94 void bbPrintBlackBoxes();
96 /// Generates a png image representing the pipeline graph of the
97 /// complex box and writes html code to insert it
98 /// into the output file stream.
100 /// level : depth of nested complex boxes graph development
101 /// (0:only this box level
102 /// output_dir is the directory in which to write the files
103 void bbInsertHTMLGraph( std::ofstream& s,
107 const std::string& output_dir,
108 bool relative_link );
110 /// Writes Graphviz-dot description in file.
111 /// Generates own description and recursively calls itself
112 /// on internal boxes with level-1
113 virtual void bbWriteDotFileBlackBox(FILE *ff,
114 BlackBox::Pointer parentblackbox,
115 int detail, int level,
117 bool relative_link );
119 virtual void bbWriteDotInputOutputName(FILE *ff,
121 int detail, int level);
123 virtual BlackBox::Pointer bbFindBlackBox(const std::string &blackboxname);
126 void Check(bool recursive=true);
131 //==================================================================
132 // PROTECTED PART : ACCESSIBLE TO ComplexBlackBoxDescriptor
133 static ComplexBlackBox::Pointer
134 New(const std::string &name,
135 ComplexBlackBoxDescriptor::Pointer desc);
138 /// Constructor that takes the ComplexBlackBox name
139 ComplexBlackBox(const std::string &name,
140 ComplexBlackBoxDescriptor::Pointer desc);
141 /// Constructor from an existing box (copy) with a new name
142 ComplexBlackBox(ComplexBlackBox& from, const std::string &name);
145 IOStatus bbBackwardUpdate(Connection::Pointer caller);
146 // void bbForwardUpdate(Connection* caller);
147 void bbSetModifiedStatus(BlackBoxInputConnector* c);
153 void bbAddBlackBox( BlackBox::Pointer );
154 void bbAddToExecutionList( const std::string& name );
155 void bbUnsafeAddBlackBox( BlackBox::Pointer );
156 void bbRemoveBlackBox( const std::string& name,
157 bool remove_connections = true);
158 void bbAddConnection( Connection::Pointer );
160 // void RemoveConnection( );
162 BlackBox::Pointer bbUnsafeGetBlackBox( const std::string& name );
165 void bbAllocateConnectors();
166 void bbDesallocateConnectors();
169 //==================================================================
170 // PRIVATE PART : MEMBERS AND USEFULL INTERNAL METHODS
172 /// Default constructor : derived classes must use the constructor with the ComplexBlackBox's name
173 //ComplexBlackBox() : BlackBox("") {}
175 // true if the box is a prototype of a ComplexBlackBoxDescriptor
176 // bool mIsAPrototype;
178 /// The descriptor pointer : is 0 if the box is a prototype
179 ComplexBlackBoxDescriptor::Pointer mLockedDescriptor;
180 /// The descriptor pointer
181 ComplexBlackBoxDescriptor::WeakPointer mDescriptor;
183 /// The map of black boxes
184 BlackBoxMapType mBlackBoxMap;
187 /// The type of list of connections
188 typedef std::list<Connection::Pointer> ConnectionListType;
189 /// The list of connections
190 ConnectionListType mConnectionList;
192 /// The execution list
193 std::vector<std::string> mExecutionList;
196 // Class ComplexBlackBox
197 //===========================================================================
205 //#include "bbtkComplexBlackBoxMacros.h"