1 /*=========================================================================
3 Module: $RCSfile: bbtkComplexBlackBox.h,v $
5 Date: $Date: 2008/12/11 09:50:35 $
6 Version: $Revision: 1.7 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
35 * \brief class bbtk::ComplexBlackBox : user defined complex black boxes
39 * \class bbtk::ComplexBlackBox
40 * \brief Abstract user defined black boxes
43 #ifndef __bbtkComplexBlackBox_h__
44 #define __bbtkComplexBlackBox_h__
46 #include "bbtkBlackBox.h"
47 #include "bbtkComplexBlackBoxDescriptor.h"
48 //#include "bbtkComplexBlackBoxInputDescriptor.h"
49 //#include "bbtkComplexBlackBoxOutputDescriptor.h"
57 //==================================================================
58 class BBTK_EXPORT ComplexBlackBox : public bbtk::BlackBox
60 BBTK_OBJECT_INTERFACE(ComplexBlackBox);
61 friend class ComplexBlackBoxDescriptor;
62 typedef BlackBox Superclass;
64 //==================================================================
65 // PUBLIC PART : ACCESSIBLE TO THE END-USER
66 /// Returns the pointer on the box' descriptor
67 BlackBoxDescriptor::Pointer bbGetDescriptor() const { return mDescriptor.lock(); }
68 /// Returns a pointer on a new instance with name <name>
69 //BlackBox* bbNew(const std::string& name);
70 /// Returns a pointer on a clone of the box with name <name>
71 BlackBox::Pointer bbClone(const std::string& name);
76 void SetAsPrototype() { mLockedDescriptor.reset(); }
77 /// Returns true if it is a prototype
78 bool IsAPrototype() const { return (!mLockedDescriptor); }
80 std::string bbGetNameWithParent() const;
82 void bbExecute(bool force = false);
84 Data bbGetOutput( const std::string &label );
85 Data bbGetInput ( const std::string &label );
86 void bbSetOutput( const std::string &name, Data data);
87 void bbSetInput ( const std::string &name, Data data,
88 bool setModified = true);
89 void bbBruteForceSetInputPointer( const std::string &name,
91 bool setModified = true);
93 /// Connects the input <name> to the connection c
94 virtual void bbConnectInput( const std::string& name, Connection* c);
95 /// Connects the output <name> to the connection c
96 virtual void bbConnectOutput( const std::string& name, Connection* c);
98 BlackBox::Pointer bbGetBlackBox( const std::string& name );
100 /// The type of map of black boxes
101 typedef std::map<std::string, BlackBox::Pointer> BlackBoxMapType;
103 const BlackBoxMapType& bbGetBlackBoxMap() { return mBlackBoxMap; }
105 void bbPrintBlackBoxes();
107 /// Generates a png image representing the pipeline graph of the
108 /// complex box and writes html code to insert it
109 /// into the output file stream.
111 /// level : depth of nested complex boxes graph development
112 /// (0:only this box level
113 /// output_dir is the directory in which to write the files
114 void bbInsertHTMLGraph( std::ofstream& s,
118 const std::string& output_dir,
119 bool relative_link );
121 /// Writes Graphviz-dot description in file.
122 /// Generates own description and recursively calls itself
123 /// on internal boxes with level-1
124 virtual void bbWriteDotFileBlackBox(FILE *ff,
125 BlackBox::Pointer parentblackbox,
126 int detail, int level,
128 bool relative_link );
130 virtual void bbWriteDotInputOutputName(FILE *ff,
132 int detail, int level);
134 virtual BlackBox::Pointer bbFindBlackBox(const std::string &blackboxname);
137 void Check(bool recursive=true);
142 //==================================================================
143 // PROTECTED PART : ACCESSIBLE TO ComplexBlackBoxDescriptor
144 static ComplexBlackBox::Pointer
145 New(const std::string &name,
146 ComplexBlackBoxDescriptor::Pointer desc);
149 /// Constructor that takes the ComplexBlackBox name
150 ComplexBlackBox(const std::string &name,
151 ComplexBlackBoxDescriptor::Pointer desc);
152 /// Constructor from an existing box (copy) with a new name
153 ComplexBlackBox(ComplexBlackBox& from, const std::string &name);
159 void bbAddBlackBox( BlackBox::Pointer );
160 void bbAddToExecutionList( const std::string& name );
161 void bbUnsafeAddBlackBox( BlackBox::Pointer );
162 void bbRemoveBlackBox( const std::string& name,
163 bool remove_connections = true);
164 void bbAddConnection( Connection::Pointer );
166 // void RemoveConnection( );
168 BlackBox::Pointer bbUnsafeGetBlackBox( const std::string& name );
171 void bbAllocateConnectors();
172 void bbDesallocateConnectors();
175 //==================================================================
176 // PRIVATE PART : MEMBERS AND USEFULL INTERNAL METHODS
178 /// Default constructor : derived classes must use the constructor with the ComplexBlackBox's name
179 //ComplexBlackBox() : BlackBox("") {}
181 // true if the box is a prototype of a ComplexBlackBoxDescriptor
182 // bool mIsAPrototype;
184 /// The descriptor pointer : is 0 if the box is a prototype
185 ComplexBlackBoxDescriptor::Pointer mLockedDescriptor;
186 /// The descriptor pointer
187 ComplexBlackBoxDescriptor::WeakPointer mDescriptor;
189 /// The map of black boxes
190 BlackBoxMapType mBlackBoxMap;
193 /// The type of list of connections
194 typedef std::list<Connection::Pointer> ConnectionListType;
195 /// The list of connections
196 ConnectionListType mConnectionList;
198 /// The execution list
199 std::vector<std::string> mExecutionList;
202 // Class ComplexBlackBox
203 //===========================================================================
211 //#include "bbtkComplexBlackBoxMacros.h"