]> Creatis software - bbtk.git/blob - kernel/src/bbtkComplexBlackBox.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkComplexBlackBox.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkComplexBlackBox.h,v $
5   Language:  C++
6   Date:      $Date: 2008/04/09 11:16:57 $
7   Version:   $Revision: 1.2 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18
19
20 /**
21  *  \file 
22  *  \brief class bbtk::ComplexBlackBox : user defined complex black boxes
23  */
24
25 /**
26  *  \class bbtk::ComplexBlackBox
27  *  \brief Abstract user defined black boxes
28  */
29  
30 #ifndef __bbtkComplexBlackBox_h__
31 #define __bbtkComplexBlackBox_h__
32
33 #include "bbtkBlackBox.h"
34 #include "bbtkComplexBlackBoxDescriptor.h"
35 //#include "bbtkComplexBlackBoxInputDescriptor.h"
36 //#include "bbtkComplexBlackBoxOutputDescriptor.h"
37 #include <list>
38
39 namespace bbtk
40 {
41
42
43  
44   //==================================================================
45   class BBTK_EXPORT ComplexBlackBox : public bbtk::BlackBox
46   {
47     friend class ComplexBlackBoxDescriptor;
48   public: 
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);
57
58     void bbExecute(bool force = false);
59   
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, 
66                                       void* data, 
67                                       bool setModified = true);
68
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);
73
74     BlackBox* bbGetBlackBox( const std::string& name );
75
76     const std::map<std::string, BlackBox*>& bbGetBlackBoxMap() 
77     { 
78       return mBlackBoxMap;
79     }
80
81     void bbPrintBlackBoxes();
82
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. 
86     /// detail : 
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, 
91                              int detail, 
92                              int level,
93                              bool instanceOrtype,
94                              const std::string& output_dir,
95                              bool relative_link );
96
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,
103                                         bool instanceOrtype,
104                                         bool relative_link );
105     
106     virtual void bbWriteDotInputOutputName(FILE *ff,
107                                            bool inputoutput, 
108                                            int detail, int level);
109     
110     virtual BlackBox *bbFindBlackBox(const std::string &blackboxname);
111     
112
113     void Check(bool recursive=true);
114
115   protected:
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);
122     // 
123    ~ComplexBlackBox();
124
125     
126   public:
127     IOStatus bbBackwardUpdate(Connection* caller);
128     //  void bbForwardUpdate(Connection* caller);
129     void bbSetModifiedStatus(BlackBoxInputConnector* c);
130
131   protected:
132   
133
134
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* );
140     
141     //    void RemoveConnection( );
142
143     BlackBox* bbUnsafeGetBlackBox( const std::string& name );
144
145     /// 
146     void bbAllocateConnectors();
147     void bbDesallocateConnectors();
148
149   private:
150     //==================================================================
151     // PRIVATE PART : MEMBERS AND USEFULL INTERNAL METHODS
152
153     /// Default constructor : derived classes must use the constructor with the ComplexBlackBox's name
154     ComplexBlackBox() : BlackBox("") {}
155     
156     /// The descriptor pointer
157     ComplexBlackBoxDescriptor* mDescriptor;
158     
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;
163     
164     
165     /// The type of list of connections
166     typedef std::list<Connection*> ConnectionListType;
167     /// The list of connections
168     ConnectionListType mConnectionList;
169
170 /// The execution list
171     std::vector<std::string> mExecutionList;
172     
173   };
174   // Class ComplexBlackBox
175   //===========================================================================
176
177
178
179 }
180 // namespace bbtk
181
182
183 //#include "bbtkComplexBlackBoxMacros.h"
184
185 #endif
186