]> Creatis software - bbtk.git/blob - kernel/src/bbtkAtomicBlackBox.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkAtomicBlackBox.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkAtomicBlackBox.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/06/27 08:12:46 $
7   Version:   $Revision: 1.7 $
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 : abstract user defined black boxes
23  */
24 #include "bbtkAtomicBlackBox.h"
25
26 namespace bbtk
27 {
28   
29   //=========================================================================
30   AtomicBlackBox::AtomicBlackBox(const std::string &name, bool alloc)
31     : BlackBox(name)
32   {
33     bbtkDebugMessage("object",3,
34                      "==> AtomicBlackBox::AtomicBlackBox(\""
35                      <<name<<"\")"<<std::endl);
36     bbtkDebugMessage("object",3,
37                      "<== AtomicBlackBox::AtomicBlackBox(\""
38                      <<name<<"\")"<<std::endl);
39   }
40   //========================================================================= 
41   
42   //=========================================================================
43   /// Constructor from an existing box (copy) with a new name 
44   AtomicBlackBox::AtomicBlackBox(AtomicBlackBox& from, 
45                 const std::string &name, 
46                 bool alloc)
47     : BlackBox(from,name)
48   {
49     bbtkDebugMessage("object",3,
50                      "==>AtomicBlackBox::AtomicBlackBox("
51                      <<from.bbGetFullName()<<",\""
52                      <<name<<"\")"<<std::endl);
53     bbtkDebugMessage("object",3,
54                      "<==AtomicBlackBox::AtomicBlackBox("
55                      <<from.bbGetFullName()<<",\""
56                      <<name<<"\")"<<std::endl);
57     
58   }
59   //=========================================================================
60   
61   
62   //=========================================================================
63   ///  Destructor
64   AtomicBlackBox::~AtomicBlackBox()
65   {
66     bbtkDebugMessage("object",3,"==> AtomicBlackBox::~AtomicBlackBox()"
67                      <<std::endl);
68     bbtkDebugMessage("object",3,"<== AtomicBlackBox::~AtomicBlackBox()"
69                      <<std::endl);
70   } 
71   //=========================================================================
72   
73
74
75   //=========================================================================
76   /// Main processing method of the box.
77   IOStatus AtomicBlackBox::bbBackwardUpdate( Connection::Pointer caller )
78   {
79     bbtkDebugMessageInc("process",3,
80                         "=> AtomicBlackBox::bbBackwardUpdate("
81                         <<(caller?caller->GetFullName():"0")<<") ["
82                         <<bbGetFullName()<<"]"<<std::endl);
83     
84     bbtkDebugMessage("process",5,"Initial Status  = "<<bbGetStatus()
85                     <<std::endl);
86     bbtkDebugMessage("process",5,"BoxProcessMode  = "
87                     <<bbGetInputBoxProcessMode()<<std::endl);
88    
89
90     if ( ( bbGetStatus() == MODIFIED ) ||
91         ( bbBoxProcessModeIsAlways() ) )
92       {
93
94         bbSetStatus(UPDATING);
95         
96         bool wasExecuting = bbGlobalGetSomeBoxExecuting();
97         bbGlobalSetSomeBoxExecuting(true);
98
99         // Updates its inputs
100         IOStatus s = bbUpdateInputs();
101     
102         bbtkDebugMessage("process",6,"Inputs post-update status = "<<s<<std::endl);
103         // If all inputs are in UPTODATE post-update status 
104         // and mProcessMode is not "Always"
105         // then the box is now UPTODATE
106         IOStatus new_status;
107         if ( ( s == UPTODATE ) && 
108             ( ! bbBoxProcessModeIsAlways() ) ) 
109             {
110                 new_status = UPTODATE;
111             }
112         else 
113             {
114                 // else it remains MODIFIED
115                  new_status = MODIFIED;
116             }
117         bbSetStatus(new_status);
118
119         // User process
120         bbProcess();
121
122         // Displays the window (WxBlackbox)
123         bbShowWindow(caller);
124
125         bbGlobalSetSomeBoxExecuting(wasExecuting);
126
127       }
128     else 
129       {
130         bbtkDebugMessage("process",5,"Up-to-date : nothing to do"<<std::endl);
131       }
132
133     bbtkDebugMessage("process",5,"Final Status    = "
134             <<bbGetStatus()<<std::endl);
135     bbtkDebugMessage("process",3,
136             "<= AtomicBlackBox::bbBackwardUpdate() ["
137             <<bbGetFullName()<<"]"<<std::endl);
138
139
140     return bbGetStatus();
141
142   }
143   //=========================================================================
144   
145     
146   //=========================================================================
147   Data AtomicBlackBox::bbGetOutput( const std::string &name )
148   {
149     bbtkDebugMessageInc("Data",7,
150             "AtomicBlackBox::bbGetOutput(\""<<name<<"\") ["
151             <<bbGetFullName()<<"]"
152             <<std::endl);
153     
154     Data p = ((AtomicBlackBoxOutputDescriptor*)bbGetDescriptor()
155                 ->GetOutputDescriptor(name))->GetGetFunctor()->Get(this);
156     
157     bbtkDebugDecTab("Data",7);
158     return p;
159   }
160   //=========================================================================
161   
162   
163   //=========================================================================
164   ///  Gets the input Data of a given name
165   Data AtomicBlackBox::bbGetInput( const std::string &name ) 
166   {
167     bbtkDebugMessageInc("Data",7,
168             "AtomicBlackBox::bbGetInput(\""<<name<<"\") ["
169             <<bbGetFullName()<<"]"
170             <<std::endl);  
171     
172     Data p = ((AtomicBlackBoxInputDescriptor*)bbGetDescriptor()
173                 ->GetInputDescriptor(name))->GetGetFunctor()->Get(this);
174     
175     bbtkDebugDecTab("Data",7);
176     return p;
177   }
178   //=========================================================================
179   
180   
181   //=========================================================================
182   ///  Sets the data of the output called <name>
183   void AtomicBlackBox::bbSetOutput( const std::string &name, Data data)
184   {
185     bbtkDebugMessageInc("Data",7,
186             "AtomicBlackBox::bbSetOutput(\""<<name<<"\",data) ["
187             <<bbGetFullName()<<"]"
188             <<std::endl); 
189     
190     ((AtomicBlackBoxOutputDescriptor*)bbGetDescriptor()
191         ->GetOutputDescriptor(name))->GetSetFunctor()->Set(this,data);
192     
193     bbtkDebugDecTab("Data",7);
194   }  
195   //=========================================================================
196   
197   
198   //=========================================================================
199   ///  Sets the data of the input called <name>
200   void AtomicBlackBox::bbSetInput(
201                 const std::string &name,
202                 Data data, 
203                 bool setModified )
204   {
205     bbtkDebugMessageInc("Data",7,
206             "AtomicBlackBox::bbSetInput(\""<<name<<"\",data) ["
207             <<bbGetFullName()<<"]"
208             <<std::endl);  
209     ((AtomicBlackBoxInputDescriptor*)bbGetDescriptor()->GetInputDescriptor(name))->GetSetFunctor()->Set(this,data);
210     
211     if (setModified) 
212         {
213             bbSetModifiedStatus();
214         }
215     
216     bbtkDebugDecTab("Data",7);
217   }
218   //=========================================================================
219   
220     //=========================================================================
221   ///  Sets the data of the input called <name>
222   void AtomicBlackBox::bbBruteForceSetInputPointer
223     (
224                     const std::string &name, 
225                     void* data, 
226                     bool setModified
227     )
228   {
229     bbtkDebugMessageInc("Data",7,
230             "AtomicBlackBox::bbBruteForceSetInputPointer(\""
231             <<name<<"\",data) ["
232             <<bbGetFullName()<<"]"
233             <<std::endl);  
234     ((AtomicBlackBoxInputDescriptor*)bbGetDescriptor()
235         ->GetInputDescriptor(name))->GetSetFunctor()
236             ->BruteForceSetPointer(this,data);
237     
238     if (setModified) 
239       {
240         bbSetModifiedStatus();
241       }
242     
243     bbtkDebugDecTab("Data",7);
244   }
245   //=========================================================================
246  
247
248
249   //==========================================================================
250   std::string AtomicBlackBox::GetObjectInfo() const 
251   {
252     std::stringstream i;
253     return i.str();
254   }
255   //==========================================================================
256
257   //==========================================================================
258   size_t AtomicBlackBox::GetObjectSize() const 
259   {
260     return sizeof(*this);
261   }
262   //==========================================================================
263   
264   //==========================================================================
265   size_t AtomicBlackBox::GetObjectRecursiveSize() const 
266   {
267     size_t s = GetObjectSize();
268     return s;
269   }
270   //==========================================================================
271
272  
273 }
274 // EO namespace bbtk