1 /*=========================================================================
4 Module: $RCSfile: bbtkComplexBlackBox.h,v $
6 Date: $Date: 2008/04/09 11:16:57 $
7 Version: $Revision: 1.2 $
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 friend class ComplexBlackBoxDescriptor;
49 //==================================================================
50 // PUBLIC PART : ACCESSIBLE TO THE END-USER
51 /// Returns the pointer on the box' descriptor
52 BlackBoxDescriptor* bbGetDescriptor() const { return mDescriptor; }
53 /// Returns a pointer on a new instance with name <name>
54 //BlackBox* bbNew(const std::string& name);
55 /// Returns a pointer on a clone of the box with name <name>
56 BlackBox* bbClone(const std::string& name);
58 void bbExecute(bool force = false);
60 Data bbGetOutput( const std::string &label );
61 Data bbGetInput ( const std::string &label );
62 void bbSetOutput( const std::string &name, Data data);
63 void bbSetInput ( const std::string &name, Data data,
64 bool setModified = true);
65 void bbBruteForceSetInputPointer( const std::string &name,
67 bool setModified = true);
69 /// Connects the input <name> to the connection c
70 virtual void bbConnectInput( const std::string& name, Connection* c);
71 /// Connects the output <name> to the connection c
72 virtual void bbConnectOutput( const std::string& name, Connection* c);
74 BlackBox* bbGetBlackBox( const std::string& name );
76 const std::map<std::string, BlackBox*>& bbGetBlackBoxMap()
81 void bbPrintBlackBoxes();
83 /// Generates a png image representing the pipeline graph of the
84 /// complex box and writes html code to insert it
85 /// into the output file stream.
87 /// level : depth of nested complex boxes graph development
88 /// (0:only this box level
89 /// output_dir is the directory in which to write the files
90 void bbInsertHTMLGraph( std::ofstream& s,
94 const std::string& output_dir,
97 /// Writes Graphviz-dot description in file.
98 /// Generates own description and recursively calls itself
99 /// on internal boxes with level-1
100 virtual void bbWriteDotFileBlackBox(FILE *ff,
101 BlackBox *parentblackbox,
102 int detail, int level,
104 bool relative_link );
106 virtual void bbWriteDotInputOutputName(FILE *ff,
108 int detail, int level);
110 virtual BlackBox *bbFindBlackBox(const std::string &blackboxname);
113 void Check(bool recursive=true);
116 //==================================================================
117 // PROTECTED PART : ACCESSIBLE TO ComplexBlackBoxDescriptor
118 /// Constructor that takes the ComplexBlackBox name
119 ComplexBlackBox(const std::string &name, ComplexBlackBoxDescriptor* desc);
120 /// Constructor from an existing box (copy) with a new name
121 ComplexBlackBox(ComplexBlackBox& from, const std::string &name);
127 IOStatus bbBackwardUpdate(Connection* caller);
128 // void bbForwardUpdate(Connection* caller);
129 void bbSetModifiedStatus(BlackBoxInputConnector* c);
135 void bbAddBlackBox( BlackBox* );
136 void bbAddToExecutionList( const std::string& name );
137 void bbUnsafeAddBlackBox( BlackBox* );
138 void bbRemoveBlackBox( const std::string& name );
139 void bbAddConnection( Connection* );
141 // void RemoveConnection( );
143 BlackBox* bbUnsafeGetBlackBox( const std::string& name );
146 void bbAllocateConnectors();
147 void bbDesallocateConnectors();
150 //==================================================================
151 // PRIVATE PART : MEMBERS AND USEFULL INTERNAL METHODS
153 /// Default constructor : derived classes must use the constructor with the ComplexBlackBox's name
154 ComplexBlackBox() : BlackBox("") {}
156 /// The descriptor pointer
157 ComplexBlackBoxDescriptor* mDescriptor;
159 /// The type of map of black boxes
160 typedef std::map<std::string, BlackBox*> BlackBoxMapType;
161 /// The map of black boxes
162 BlackBoxMapType mBlackBoxMap;
165 /// The type of list of connections
166 typedef std::list<Connection*> ConnectionListType;
167 /// The list of connections
168 ConnectionListType mConnectionList;
170 /// The execution list
171 std::vector<std::string> mExecutionList;
174 // Class ComplexBlackBox
175 //===========================================================================
183 //#include "bbtkComplexBlackBoxMacros.h"