]> Creatis software - bbtk.git/blob - kernel/src/bbtkAtomicBlackBox.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkAtomicBlackBox.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkAtomicBlackBox.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:12 $
6   Version:   $Revision: 1.8 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31
32 /**
33  *  \file 
34  *  \brief class bbtk::AtomicBlackBox : abstract user defined black boxes
35  */
36 #include "bbtkAtomicBlackBox.h"
37
38 namespace bbtk
39 {
40   
41   //=========================================================================
42   AtomicBlackBox::AtomicBlackBox(const std::string &name, bool alloc)
43     : BlackBox(name)
44   {
45     bbtkDebugMessage("object",3,
46                      "==> AtomicBlackBox::AtomicBlackBox(\""
47                      <<name<<"\")"<<std::endl);
48     bbtkDebugMessage("object",3,
49                      "<== AtomicBlackBox::AtomicBlackBox(\""
50                      <<name<<"\")"<<std::endl);
51   }
52   //========================================================================= 
53   
54   //=========================================================================
55   /// Constructor from an existing box (copy) with a new name 
56   AtomicBlackBox::AtomicBlackBox(AtomicBlackBox& from, 
57                 const std::string &name, 
58                 bool alloc)
59     : BlackBox(from,name)
60   {
61     bbtkDebugMessage("object",3,
62                      "==>AtomicBlackBox::AtomicBlackBox("
63                      <<from.bbGetFullName()<<",\""
64                      <<name<<"\")"<<std::endl);
65     bbtkDebugMessage("object",3,
66                      "<==AtomicBlackBox::AtomicBlackBox("
67                      <<from.bbGetFullName()<<",\""
68                      <<name<<"\")"<<std::endl);
69     
70   }
71   //=========================================================================
72   
73   
74   //=========================================================================
75   ///  Destructor
76   AtomicBlackBox::~AtomicBlackBox()
77   {
78     bbtkDebugMessage("object",3,"==> AtomicBlackBox::~AtomicBlackBox()"
79                      <<std::endl);
80     bbtkDebugMessage("object",3,"<== AtomicBlackBox::~AtomicBlackBox()"
81                      <<std::endl);
82   } 
83   //=========================================================================
84   
85
86
87   //=========================================================================
88   /// Main processing method of the box.
89   IOStatus AtomicBlackBox::bbBackwardUpdate( Connection::Pointer caller )
90   {
91     bbtkDebugMessageInc("process",3,
92                         "=> AtomicBlackBox::bbBackwardUpdate("
93                         <<(caller?caller->GetFullName():"0")<<") ["
94                         <<bbGetFullName()<<"]"<<std::endl);
95     
96     bbtkDebugMessage("process",5,"Initial Status  = "<<bbGetStatus()
97                     <<std::endl);
98     bbtkDebugMessage("process",5,"BoxProcessMode  = "
99                     <<bbGetInputBoxProcessMode()<<std::endl);
100    
101
102     if ( ( bbGetStatus() == MODIFIED ) ||
103         ( bbBoxProcessModeIsAlways() ) )
104       {
105
106         bbSetStatus(UPDATING);
107         
108         bool wasExecuting = bbGlobalGetSomeBoxExecuting();
109         bbGlobalSetSomeBoxExecuting(true);
110
111         // Updates its inputs
112         IOStatus s = bbUpdateInputs();
113     
114         bbtkDebugMessage("process",6,"Inputs post-update status = "<<s<<std::endl);
115         // If all inputs are in UPTODATE post-update status 
116         // and mProcessMode is not "Always"
117         // then the box is now UPTODATE
118         IOStatus new_status;
119         if ( ( s == UPTODATE ) && 
120             ( ! bbBoxProcessModeIsAlways() ) ) 
121             {
122                 new_status = UPTODATE;
123             }
124         else 
125             {
126                 // else it remains MODIFIED
127                  new_status = MODIFIED;
128             }
129         bbSetStatus(new_status);
130
131         // User process
132         bbProcess();
133
134         // Displays the window (WxBlackbox)
135         bbShowWindow(caller);
136
137         bbGlobalSetSomeBoxExecuting(wasExecuting);
138
139       }
140     else 
141       {
142         bbtkDebugMessage("process",5,"Up-to-date : nothing to do"<<std::endl);
143       }
144
145     bbtkDebugMessage("process",5,"Final Status    = "
146             <<bbGetStatus()<<std::endl);
147     bbtkDebugMessage("process",3,
148             "<= AtomicBlackBox::bbBackwardUpdate() ["
149             <<bbGetFullName()<<"]"<<std::endl);
150
151
152     return bbGetStatus();
153
154   }
155   //=========================================================================
156   
157     
158   //=========================================================================
159   Data AtomicBlackBox::bbGetOutput( const std::string &name )
160   {
161     bbtkDebugMessageInc("Data",7,
162             "AtomicBlackBox::bbGetOutput(\""<<name<<"\") ["
163             <<bbGetFullName()<<"]"
164             <<std::endl);
165     
166     Data p = ((AtomicBlackBoxOutputDescriptor*)bbGetDescriptor()
167                 ->GetOutputDescriptor(name))->GetGetFunctor()->Get(this);
168     
169     bbtkDebugDecTab("Data",7);
170     return p;
171   }
172   //=========================================================================
173   
174   
175   //=========================================================================
176   ///  Gets the input Data of a given name
177   Data AtomicBlackBox::bbGetInput( const std::string &name ) 
178   {
179     bbtkDebugMessageInc("Data",7,
180             "AtomicBlackBox::bbGetInput(\""<<name<<"\") ["
181             <<bbGetFullName()<<"]"
182             <<std::endl);  
183     
184     Data p = ((AtomicBlackBoxInputDescriptor*)bbGetDescriptor()
185                 ->GetInputDescriptor(name))->GetGetFunctor()->Get(this);
186     
187     bbtkDebugDecTab("Data",7);
188     return p;
189   }
190   //=========================================================================
191   
192   
193   //=========================================================================
194   ///  Sets the data of the output called <name>
195   void AtomicBlackBox::bbSetOutput( const std::string &name, Data data)
196   {
197     bbtkDebugMessageInc("Data",7,
198             "AtomicBlackBox::bbSetOutput(\""<<name<<"\",data) ["
199             <<bbGetFullName()<<"]"
200             <<std::endl); 
201     
202     ((AtomicBlackBoxOutputDescriptor*)bbGetDescriptor()
203         ->GetOutputDescriptor(name))->GetSetFunctor()->Set(this,data);
204     
205     bbtkDebugDecTab("Data",7);
206   }  
207   //=========================================================================
208   
209   
210   //=========================================================================
211   ///  Sets the data of the input called <name>
212   void AtomicBlackBox::bbSetInput(
213                 const std::string &name,
214                 Data data, 
215                 bool setModified )
216   {
217     bbtkDebugMessageInc("Data",7,
218             "AtomicBlackBox::bbSetInput(\""<<name<<"\",data) ["
219             <<bbGetFullName()<<"]"
220             <<std::endl);  
221     ((AtomicBlackBoxInputDescriptor*)bbGetDescriptor()->GetInputDescriptor(name))->GetSetFunctor()->Set(this,data);
222     
223     if (setModified) 
224         {
225             bbSetModifiedStatus();
226         }
227     
228     bbtkDebugDecTab("Data",7);
229   }
230   //=========================================================================
231   
232     //=========================================================================
233   ///  Sets the data of the input called <name>
234   void AtomicBlackBox::bbBruteForceSetInputPointer
235     (
236                     const std::string &name, 
237                     void* data, 
238                     bool setModified
239     )
240   {
241     bbtkDebugMessageInc("Data",7,
242             "AtomicBlackBox::bbBruteForceSetInputPointer(\""
243             <<name<<"\",data) ["
244             <<bbGetFullName()<<"]"
245             <<std::endl);  
246     ((AtomicBlackBoxInputDescriptor*)bbGetDescriptor()
247         ->GetInputDescriptor(name))->GetSetFunctor()
248             ->BruteForceSetPointer(this,data);
249     
250     if (setModified) 
251       {
252         bbSetModifiedStatus();
253       }
254     
255     bbtkDebugDecTab("Data",7);
256   }
257   //=========================================================================
258  
259
260
261   //==========================================================================
262   std::string AtomicBlackBox::GetObjectInfo() const 
263   {
264     std::stringstream i;
265     return i.str();
266   }
267   //==========================================================================
268
269   //==========================================================================
270   size_t AtomicBlackBox::GetObjectSize() const 
271   {
272     return sizeof(*this);
273   }
274   //==========================================================================
275   
276   //==========================================================================
277   size_t AtomicBlackBox::GetObjectRecursiveSize() const 
278   {
279     size_t s = GetObjectSize();
280     return s;
281   }
282   //==========================================================================
283
284  
285 }
286 // EO namespace bbtk