]> Creatis software - bbtk.git/blob - kernel/src/bbtkAtomicBlackBox.h
0af4403a74a2487652ec71a99ca82f2218c8ec85
[bbtk.git] / kernel / src / bbtkAtomicBlackBox.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkAtomicBlackBox.h,v $
5   Language:  C++
6   Date:      $Date: 2008/04/18 12:59:14 $
7   Version:   $Revision: 1.4 $
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::AtomicBlackBox : ancestor of all user defined (concrete) black boxes which are atomic (vs. complex boxes which are made up of other (atomic or complex) boxes).
23  */
24
25 /**
26  *  \class bbtk::AtomicBlackBox
27  *  \brief Ancestor of all user defined (concrete) black boxes which are atomic (vs. complex boxes which are made up of other (atomic or complex) boxes).
28  */
29  
30 #ifndef __bbtkAtomicBlackBox_h__
31 #define __bbtkAtomicBlackBox_h__
32
33 #include "bbtkBlackBox.h"
34 #include "bbtkAtomicBlackBoxDescriptor.h"
35
36 namespace bbtk
37 {
38
39  
40   //==================================================================
41   class BBTK_EXPORT AtomicBlackBox : public bbtk::BlackBox
42   {
43     //==================================================================
44   public: 
45     //==================================================================
46     bbtk::BlackBoxDescriptor::Pointer bbGetDescriptor() const
47     {
48       return bbmDescriptorPointer;
49     }
50     //==================================================================
51     /// Gets the output Data of a given label
52     Data bbGetOutput( const std::string &label );
53     ///  Gets the input Data of a given label
54     Data bbGetInput( const std::string &label );
55     ///  Sets the data of the output called <name>
56     void bbSetOutput( const std::string &name, Data data);
57     ///  Sets the data of the input called <name>
58     void bbSetInput( const std::string &name, Data data, 
59                      bool setModified = true);
60     ///  Sets the data of the input called <name>
61     void bbBruteForceSetInputPointer( const std::string &name, 
62                                       void* data, 
63                                       bool setModified = true);
64     //==================================================================
65
66     //==================================================================
67     std::string GetObjectInfo() const;      
68     size_t GetObjectSize() const;
69     size_t GetObjectRecursiveSize() const;
70     //==================================================================
71
72     //==================================================================
73   protected:
74     //==================================================================
75     ///  Constructor with the AtomicBlackBox's instance name
76     AtomicBlackBox(const std::string &name, bool alloc = true);
77     /// Constructor from an existing box (copy) with a new instance name 
78     AtomicBlackBox(AtomicBlackBox& from, const std::string &name, 
79                  bool alloc = true);
80     //==================================================================
81     //==================================================================
82     ///  Destructor
83     virtual ~AtomicBlackBox();
84     //==================================================================
85
86     //==================================================================
87   protected:
88     virtual void bbLockDescriptor() = 0;
89     //  private:
90     //    virtual void bbReleaseDescriptor();
91     //==================================================================
92
93   public:
94     //==================================================================   
95     /// Recursive pipeline processing in backward direction 
96     /// (recursion is in backward direction however execution always goes forward).
97     /// 
98     /// \returns The final status of the box (UPTODATE or MODIFIED)
99     ///
100     /// First checks that re-processing is needed (either Status==MODIFIED or InputProcessMode==Always)
101     /// then : 
102     /// - updates its inputs by calling bbUpdateInputs (which recursively calls bbBackwardUpdate on upstream boxes)
103     /// - calls bbProcess which here simply calls the user callback bbUserProcess which does the actual processing. 
104     ///    bbProcess is overloaded in WxBlackBox to handle widget creation and show
105     virtual IOStatus bbBackwardUpdate(Connection::Pointer caller);
106     //==================================================================
107
108     //==================================================================
109   protected:
110     //==================================================================
111     /// Calls the user defined processing method.
112     /// Overloaded in WxBlackBox to handle widget creation and show
113     virtual void bbProcess() { this->bbUserProcess(); }
114     //==================================================================
115
116     //==================================================================
117     /// User callback which computes the outputs as a function of the inputs. 
118     /// It is assumed to be deterministic and thus is only called is the inputs have changed 
119     /// (i.e. if the black box is marked as modified)
120     virtual void bbUserProcess() 
121     {
122       bbtkWarning("AtomicBlackBox::bbUserProcess() not overloaded for box '"
123                   <<bbGetFullName()
124                   <<"' : the box does nothing. Is it a bug or a feature ?"
125                   <<std::endl);
126     }
127     //==================================================================
128
129     //==================================================================
130     /// User callback called in the box contructor
131     virtual void bbUserConstructor() {}
132     /// User callback called in the box copy constructor
133     virtual void bbUserCopyConstructor() {}
134     /// User callback called in the box destructor
135     virtual void bbUserDestructor() {}
136     //==================================================================    
137
138      //==================================================================
139   private:
140     //================================================================== 
141     /// Default constructor is private : 
142     /// derived classes must use the constructor with the AtomicBlackBox's name
143     AtomicBlackBox() : BlackBox("") {}
144     //================================================================== 
145
146   protected:
147     //================================================================== 
148     // The pointer on the descriptor
149     bbtk::BlackBoxDescriptor::Pointer bbmDescriptorPointer;  
150     //================================================================== 
151
152   };
153   // Class AtomicBlackBox
154   //===========================================================================
155
156
157
158 }
159 // namespace bbtk
160
161
162 #include "bbtkAtomicBlackBoxMacros.h"
163
164 #endif
165