]> Creatis software - bbtk.git/blob - kernel/src/bbtkUserBlackBox.h
Recreated the complete cvs tree because the project architecture deeply changed
[bbtk.git] / kernel / src / bbtkUserBlackBox.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkUserBlackBox.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::UserBlackBox : Ancestor of all user defined (concrete) black boxes
23  */
24
25 /**
26  *  \class bbtk::UserBlackBox
27  *  \brief Ancestor of all user defined (concrete) black boxes.
28  */
29  
30 #ifndef __bbtkUserBlackBox_h__
31 #define __bbtkUserBlackBox_h__
32
33 #include "bbtkBlackBox.h"
34 #include "bbtkUserBlackBoxDescriptor.h"
35
36 namespace bbtk
37 {
38
39  
40   //==================================================================
41   class BBTK_EXPORT UserBlackBox : public bbtk::BlackBox
42   {
43     //==================================================================
44   public: 
45     //==================================================================
46     /// Gets the output Data of a given label
47     Data bbGetOutput( const std::string &label );
48     ///  Gets the input Data of a given label
49     Data bbGetInput( const std::string &label );
50     ///  Sets the data of the output called <name>
51     void bbSetOutput( const std::string &name, Data data);
52     ///  Sets the data of the input called <name>
53     void bbSetInput( const std::string &name, Data data, 
54                      bool setModified = true);
55     ///  Sets the data of the input called <name>
56     void bbBruteForceSetInputPointer( const std::string &name, 
57                                       void* data, 
58                                       bool setModified = true);
59     //==================================================================
60
61     //==================================================================
62     ///  Destructor
63     virtual ~UserBlackBox();
64     //==================================================================
65
66     //==================================================================
67   protected:
68     //==================================================================
69     ///  Constructor with the UserBlackBox's instance name
70     UserBlackBox(const std::string &name, bool alloc = true);
71     /// Constructor from an existing box (copy) with a new instance name 
72     UserBlackBox(UserBlackBox& from, const std::string &name, 
73                  bool alloc = true);
74     //==================================================================
75
76   public:
77     //==================================================================   
78     /// Recursive pipeline processing in backward direction 
79     /// (recursion is in backward direction however execution always goes forward).
80     /// 
81     /// \returns The final status of the box (UPTODATE or MODIFIED)
82     ///
83     /// First checks that re-processing is needed (either Status==MODIFIED or InputProcessMode==Always)
84     /// then : 
85     /// - updates its inputs by calling bbUpdateInputs (which recursively calls bbBackwardUpdate on amont boxes)
86     /// - calls bbCreateWidget
87     /// - calls bbProcess which is the user callback which does the actual processing
88     /// - calls bbUpdateChildren
89     /// - calls bbShowWidget which shows the widget associated to the box (if any)
90     IOStatus bbBackwardUpdate(Connection* caller);
91     //==================================================================
92
93     //==================================================================
94     /// Recursive pipeline processing in forward direction along "Child"-"Parent" connections
95     /// 
96     /// First checks that re-processing is needed (either Status==MODIFIED or InputProcessMode==Always)
97     /// then : 
98     /// - calls bbCreateWidget
99     /// - calls bbProcess which is the user callback which does the actual processing
100     /// - calls bbUpdateChildren which recursively calls bbForwardUpdate on connections attached the "Child" output
101     // void bbForwardUpdate(Connection* caller);
102     //==================================================================
103   protected:
104     //==================================================================
105     /// User callback which computes the outputs as a function of the inputs. 
106     /// It is assumed to be deterministic and thus is only called is the inputs have changed 
107     /// (i.e. if the black box is marked as modified)
108     virtual void bbProcess() 
109     {
110       bbtkWarning("UserBlackBox::bbProcess() not overloaded for box '"
111                   <<bbGetFullName()
112                   <<"' : the box does nothing. Is it a bug or a feature ?"
113                   <<std::endl);
114     }
115     //==================================================================
116
117     //==================================================================
118     /// User callback called in the box contructor
119     virtual void bbUserConstructor() {}
120     /// User callback called in the box copy constructor
121     virtual void bbUserCopyConstructor() {}
122     /// User callback called in the box destructor
123     virtual void bbUserDestructor() {}
124     //==================================================================    
125
126      //==================================================================
127   private:
128     //================================================================== 
129     /// Default constructor is private : 
130     /// derived classes must use the constructor with the UserBlackBox's name
131     UserBlackBox() : BlackBox("") {}
132     //================================================================== 
133
134
135   };
136   // Class UserBlackBox
137   //===========================================================================
138
139
140
141 }
142 // namespace bbtk
143
144
145 #include "bbtkUserBlackBoxMacros.h"
146
147 #endif
148