1 /*=========================================================================
4 Module: $RCSfile: bbtkComplexBlackBox.h,v $
6 Date: $Date: 2008/04/22 14:30:25 $
7 Version: $Revision: 1.4 $
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, Connection* c);
82 /// Connects the output <name> to the connection c
83 virtual void bbConnectOutput( const std::string& name, Connection* c);
85 BlackBox::Pointer bbGetBlackBox( const std::string& name );
87 /// The type of map of black boxes
88 typedef std::map<std::string, BlackBox::Pointer> BlackBoxMapType;
90 const BlackBoxMapType& bbGetBlackBoxMap() { return mBlackBoxMap; }
92 void bbPrintBlackBoxes();
94 /// Generates a png image representing the pipeline graph of the
95 /// complex box and writes html code to insert it
96 /// into the output file stream.
98 /// level : depth of nested complex boxes graph development
99 /// (0:only this box level
100 /// output_dir is the directory in which to write the files
101 void bbInsertHTMLGraph( std::ofstream& s,
105 const std::string& output_dir,
106 bool relative_link );
108 /// Writes Graphviz-dot description in file.
109 /// Generates own description and recursively calls itself
110 /// on internal boxes with level-1
111 virtual void bbWriteDotFileBlackBox(FILE *ff,
112 BlackBox::Pointer parentblackbox,
113 int detail, int level,
115 bool relative_link );
117 virtual void bbWriteDotInputOutputName(FILE *ff,
119 int detail, int level);
121 virtual BlackBox::Pointer bbFindBlackBox(const std::string &blackboxname);
124 void Check(bool recursive=true);
129 //==================================================================
130 // PROTECTED PART : ACCESSIBLE TO ComplexBlackBoxDescriptor
131 static ComplexBlackBox::Pointer
132 New(const std::string &name,
133 ComplexBlackBoxDescriptor::Pointer desc);
136 /// Constructor that takes the ComplexBlackBox name
137 ComplexBlackBox(const std::string &name,
138 ComplexBlackBoxDescriptor::Pointer desc);
139 /// Constructor from an existing box (copy) with a new name
140 ComplexBlackBox(ComplexBlackBox& from, const std::string &name);
143 IOStatus bbBackwardUpdate(Connection::Pointer caller);
144 // void bbForwardUpdate(Connection* caller);
145 void bbSetModifiedStatus(BlackBoxInputConnector* c);
151 void bbAddBlackBox( BlackBox::Pointer );
152 void bbAddToExecutionList( const std::string& name );
153 void bbUnsafeAddBlackBox( BlackBox::Pointer );
154 void bbRemoveBlackBox( const std::string& name,
155 bool remove_connections = true);
156 void bbAddConnection( Connection::Pointer );
158 // void RemoveConnection( );
160 BlackBox::Pointer bbUnsafeGetBlackBox( const std::string& name );
163 void bbAllocateConnectors();
164 void bbDesallocateConnectors();
167 //==================================================================
168 // PRIVATE PART : MEMBERS AND USEFULL INTERNAL METHODS
170 /// Default constructor : derived classes must use the constructor with the ComplexBlackBox's name
171 //ComplexBlackBox() : BlackBox("") {}
173 // true if the box is a prototype of a ComplexBlackBoxDescriptor
174 // bool mIsAPrototype;
176 /// The descriptor pointer : is 0 if the box is a prototype
177 ComplexBlackBoxDescriptor::Pointer mLockedDescriptor;
178 /// The descriptor pointer
179 ComplexBlackBoxDescriptor::WeakPointer mDescriptor;
181 /// The map of black boxes
182 BlackBoxMapType mBlackBoxMap;
185 /// The type of list of connections
186 typedef std::list<Connection::Pointer> ConnectionListType;
187 /// The list of connections
188 ConnectionListType mConnectionList;
190 /// The execution list
191 std::vector<std::string> mExecutionList;
194 // Class ComplexBlackBox
195 //===========================================================================
203 //#include "bbtkComplexBlackBoxMacros.h"