1 /*=========================================================================
3 Module: $RCSfile: bbtkComplexBlackBox.h,v $
5 Date: $Date: 2009/10/05 22:44:48 $
6 Version: $Revision: 1.8 $
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"
50 #include "creaSystem.h"
58 //==================================================================
59 class BBTK_EXPORT ComplexBlackBox : public bbtk::BlackBox
61 BBTK_OBJECT_INTERFACE(ComplexBlackBox);
62 friend class ComplexBlackBoxDescriptor;
63 typedef BlackBox Superclass;
65 //==================================================================
66 // PUBLIC PART : ACCESSIBLE TO THE END-USER
67 /// Returns the pointer on the box' descriptor
68 BlackBoxDescriptor::Pointer bbGetDescriptor() const { return mDescriptor.lock(); }
69 /// Returns a pointer on a new instance with name <name>
70 //BlackBox* bbNew(const std::string& name);
71 /// Returns a pointer on a clone of the box with name <name>
72 BlackBox::Pointer bbClone(const std::string& name);
77 void SetAsPrototype() { mLockedDescriptor.reset(); }
78 /// Returns true if it is a prototype
79 bool IsAPrototype() const { return (!mLockedDescriptor); }
81 std::string bbGetNameWithParent() const;
83 void bbExecute(bool force = false);
85 Data bbGetOutput( const std::string &label );
86 Data bbGetInput ( const std::string &label );
87 void bbSetOutput( const std::string &name, Data data);
88 void bbSetInput ( const std::string &name, Data data,
89 bool setModified = true);
90 void bbBruteForceSetInputPointer( const std::string &name,
92 bool setModified = true);
94 /// Connects the input <name> to the connection c
95 virtual void bbConnectInput( const std::string& name, Connection* c);
96 /// Connects the output <name> to the connection c
97 virtual void bbConnectOutput( const std::string& name, Connection* c);
99 BlackBox::Pointer bbGetBlackBox( const std::string& name );
101 /// The type of map of black boxes
102 typedef std::map<std::string, BlackBox::Pointer> BlackBoxMapType;
104 const BlackBoxMapType& bbGetBlackBoxMap() { return mBlackBoxMap; }
106 void bbPrintBlackBoxes();
108 /// Generates a png image representing the pipeline graph of the
109 /// complex box and writes html code to insert it
110 /// into the output file stream.
112 /// level : depth of nested complex boxes graph development
113 /// (0:only this box level
114 /// output_dir is the directory in which to write the files
115 void bbInsertHTMLGraph( std::ofstream& s,
119 const std::string& output_dir,
120 bool relative_link );
122 /// Writes Graphviz-dot description in file.
123 /// Generates own description and recursively calls itself
124 /// on internal boxes with level-1
125 virtual void bbWriteDotFileBlackBox(FILE *ff,
126 BlackBox::Pointer parentblackbox,
127 int detail, int level,
129 bool relative_link );
131 virtual void bbWriteDotInputOutputName(FILE *ff,
133 int detail, int level);
135 virtual BlackBox::Pointer bbFindBlackBox(const std::string &blackboxname);
138 void Check(bool recursive=true);
143 //==================================================================
144 // PROTECTED PART : ACCESSIBLE TO ComplexBlackBoxDescriptor
145 static ComplexBlackBox::Pointer
146 New(const std::string &name,
147 ComplexBlackBoxDescriptor::Pointer desc);
150 /// Constructor that takes the ComplexBlackBox name
151 ComplexBlackBox(const std::string &name,
152 ComplexBlackBoxDescriptor::Pointer desc);
153 /// Constructor from an existing box (copy) with a new name
154 ComplexBlackBox(ComplexBlackBox& from, const std::string &name);
160 void bbAddBlackBox( BlackBox::Pointer );
161 void bbAddToExecutionList( const std::string& name );
162 void bbUnsafeAddBlackBox( BlackBox::Pointer );
163 void bbRemoveBlackBox( const std::string& name,
164 bool remove_connections = true);
165 void bbAddConnection( Connection::Pointer );
167 // void RemoveConnection( );
169 BlackBox::Pointer bbUnsafeGetBlackBox( const std::string& name );
172 void bbAllocateConnectors();
173 void bbDesallocateConnectors();
176 //==================================================================
177 // PRIVATE PART : MEMBERS AND USEFULL INTERNAL METHODS
179 /// Default constructor : derived classes must use the constructor with the ComplexBlackBox's name
180 //ComplexBlackBox() : BlackBox("") {}
182 // true if the box is a prototype of a ComplexBlackBoxDescriptor
183 // bool mIsAPrototype;
185 /// The descriptor pointer : is 0 if the box is a prototype
186 ComplexBlackBoxDescriptor::Pointer mLockedDescriptor;
187 /// The descriptor pointer
188 ComplexBlackBoxDescriptor::WeakPointer mDescriptor;
190 /// The map of black boxes
191 BlackBoxMapType mBlackBoxMap;
194 /// The type of list of connections
195 typedef std::list<Connection::Pointer> ConnectionListType;
196 /// The list of connections
197 ConnectionListType mConnectionList;
199 /// The execution list
200 std::vector<std::string> mExecutionList;
203 // Class ComplexBlackBox
204 //===========================================================================
212 //#include "bbtkComplexBlackBoxMacros.h"