]> Creatis software - bbtk.git/blob - kernel/src/bbtkComplexBlackBox.h
Recreated the complete cvs tree because the project architecture deeply changed
[bbtk.git] / kernel / src / bbtkComplexBlackBox.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkComplexBlackBox.h,v $
5   Language:  C++
6   Date:      $Date: 2008/01/22 15:02:00 $
7   Version:   $Revision: 1.1.1.1 $
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 clone of the box with name <name>
54     BlackBox* bbClone(const std::string& name);
55
56     void bbExecute(bool force = false);
57   
58     Data bbGetOutput( const std::string &label );
59     Data bbGetInput ( const std::string &label );
60     void bbSetOutput( const std::string &name, Data data);
61     void bbSetInput ( const std::string &name, Data data,
62                       bool setModified = true);
63     void bbBruteForceSetInputPointer( const std::string &name, 
64                                       void* data, 
65                                       bool setModified = true);
66
67     ~ComplexBlackBox();
68
69     BlackBox* bbGetBlackBox( const std::string& name );
70
71     const std::map<std::string, BlackBox*>& bbGetBlackBoxMap() 
72     { 
73       return mBlackBoxMap;
74     }
75
76     void bbPrintBlackBoxes();
77
78     /// Generates a png image representing the pipeline graph of the 
79     /// complex box and writes html code to insert it 
80     /// into the output file stream. 
81     /// detail : 
82     /// level : depth of nested complex boxes graph development 
83     /// (0:only this box level 
84     /// output_dir is the directory in which to write the files 
85     void bbInsertHTMLGraph(  std::ofstream& s, 
86                              int detail, 
87                              int level,
88                              bool instanceOrtype,
89                              const std::string& output_dir,
90                              bool relative_link );
91
92     /// Writes Graphviz-dot description in file.
93     /// Generates own description and recursively calls itself 
94     /// on internal boxes with level-1 
95     virtual void bbWriteDotFileBlackBox(FILE *ff,
96                                         BlackBox *parentblackbox, 
97                                         int detail, int level,
98                                         bool instanceOrtype,
99                                         bool relative_link );
100     
101     virtual void bbWriteDotInputOutputName(FILE *ff,
102                                            bool inputoutput, 
103                                            int detail, int level);
104     
105     virtual BlackBox *bbFindBlackBox(const std::string &blackboxname);
106     
107
108
109   protected:
110     //==================================================================
111     // PROTECTED PART : ACCESSIBLE TO ComplexBlackBoxDescriptor
112     ///  Constructor that takes the ComplexBlackBox name
113     ComplexBlackBox(const std::string &name, ComplexBlackBoxDescriptor* desc);
114     /// Constructor from an existing box (copy) with a new name 
115     ComplexBlackBox(ComplexBlackBox& from, const std::string &name);
116
117     
118   public:
119     IOStatus bbBackwardUpdate(Connection* caller);
120     //  void bbForwardUpdate(Connection* caller);
121     void bbSetModifiedStatus(BlackBoxInputConnector* c);
122
123   protected:
124   
125
126
127     void bbAddBlackBox( BlackBox* );
128     void bbAddToExecutionList( const std::string& name );
129     void bbUnsafeAddBlackBox( BlackBox* );
130     void bbRemoveBlackBox( const std::string& name );
131     void bbAddConnection( Connection* );
132     
133     //    void RemoveConnection( );
134
135     BlackBox* bbUnsafeGetBlackBox( const std::string& name );
136
137     /// 
138     void bbAllocateConnectors();
139     void bbDesallocateConnectors();
140
141   private:
142     //==================================================================
143     // PRIVATE PART : MEMBERS AND USEFULL INTERNAL METHODS
144
145     /// Default constructor : derived classes must use the constructor with the ComplexBlackBox's name
146     ComplexBlackBox() : BlackBox("") {}
147     
148     /// The descriptor pointer
149     ComplexBlackBoxDescriptor* mDescriptor;
150     
151     /// The type of map of black boxes
152     typedef std::map<std::string, BlackBox*> BlackBoxMapType;
153     /// The map of black boxes
154     BlackBoxMapType mBlackBoxMap;
155     
156     
157     /// The type of list of connections
158     typedef std::list<Connection*> ConnectionListType;
159     /// The list of connections
160     ConnectionListType mConnectionList;
161
162 /// The execution list
163     std::vector<std::string> mExecutionList;
164     
165   };
166   // Class ComplexBlackBox
167   //===========================================================================
168
169
170
171 }
172 // namespace bbtk
173
174
175 //#include "bbtkComplexBlackBoxMacros.h"
176
177 #endif
178