]> Creatis software - bbtk.git/blob - kernel/src/bbtkAtomicBlackBox.cxx
d42185163bdf9dd230273a65edeadd0bb414e272
[bbtk.git] / kernel / src / bbtkAtomicBlackBox.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkAtomicBlackBox.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/12/08 12:53:35 $
6   Version:   $Revision: 1.11 $
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   void AtomicBlackBox::bbBackwardUpdate( Connection::Pointer caller )
90   {
91     bbtkDebugMessageInc("process",3,
92                         "=> AtomicBlackBox::bbBackwardUpdate("
93                         <<(caller?caller->GetFullName():"0")<<") ["
94                         <<bbGetFullName()<<"]"<<std::endl);
95
96     // If already executing : return
97     if (bbGetExecuting()) 
98       {
99         bbtkDebugMessage("process",3,
100                          " -> already executing : returning"<<std::endl);
101         return; 
102       }
103
104     bbSetExecuting(true);
105     bool wasExecuting = bbGlobalGetSomeBoxExecuting();
106     bbGlobalSetSomeBoxExecuting(true);
107
108     // Updates its inputs
109     IOStatus s = bbUpdateInputs();
110     
111     if ( (s != UPTODATE) ||
112          bbBoxProcessModeIsAlways() )
113       {
114         // User process
115         bbProcess();
116         
117         // Displays the window (WxBlackbox)
118         bbShowWindow(caller);
119         
120         // Update the I/O statuses
121         bbComputePostProcessStatus();
122       }
123     else 
124       {
125         bbtkDebugMessage("process",5," -> Up-to-date : nothing to do"
126                          <<std::endl);
127       }
128
129     bbtkDebugMessage("process",3,
130             "<= AtomicBlackBox::bbBackwardUpdate() ["
131             <<bbGetFullName()<<"]"<<std::endl);
132
133     bbSetExecuting(false);
134     bbGlobalSetSomeBoxExecuting(wasExecuting);
135
136     return; // bbGetStatus();
137
138   }
139   //=========================================================================
140   
141     
142   //=========================================================================
143   Data AtomicBlackBox::bbGetOutput( const std::string &name )
144   {
145     bbtkDebugMessageInc("Data",7,
146             "AtomicBlackBox::bbGetOutput(\""<<name<<"\") ["
147             <<bbGetFullName()<<"]"
148             <<std::endl);
149     
150     Data p = ((AtomicBlackBoxOutputDescriptor*)bbGetDescriptor()
151                 ->GetOutputDescriptor(name))->GetGetFunctor()->Get(this);
152     
153     bbtkDebugDecTab("Data",7);
154     return p;
155   }
156   //=========================================================================
157   
158   
159   //=========================================================================
160   ///  Gets the input Data of a given name
161   Data AtomicBlackBox::bbGetInput( const std::string &name ) 
162   {
163     bbtkDebugMessageInc("Data",7,
164             "AtomicBlackBox::bbGetInput(\""<<name<<"\") ["
165             <<bbGetFullName()<<"]"
166             <<std::endl);  
167     
168     Data p = ((AtomicBlackBoxInputDescriptor*)bbGetDescriptor()
169                 ->GetInputDescriptor(name))->GetGetFunctor()->Get(this);
170     
171     bbtkDebugDecTab("Data",7);
172     return p;
173   }
174   //=========================================================================
175   
176   
177   //=========================================================================
178   ///  Sets the data of the output called <name>
179   void AtomicBlackBox::bbSetOutput( const std::string &name, Data data)
180   {
181     bbtkDebugMessageInc("Data",7,
182             "AtomicBlackBox::bbSetOutput(\""<<name<<"\",data) ["
183             <<bbGetFullName()<<"]"
184             <<std::endl); 
185     
186     ((AtomicBlackBoxOutputDescriptor*)bbGetDescriptor()
187         ->GetOutputDescriptor(name))->GetSetFunctor()->Set(this,data);
188     
189     bbtkDebugDecTab("Data",7);
190   }  
191   //=========================================================================
192   
193   
194   //=========================================================================
195   ///  Sets the data of the input called <name>
196   void AtomicBlackBox::bbSetInput(const std::string &name,
197                                   Data data, 
198                                   bool setModified )
199   {
200     bbtkDebugMessageInc("data",7,
201             "AtomicBlackBox::bbSetInput(\""<<name<<"\",data) ["
202             <<bbGetFullName()<<"]"
203             <<std::endl);  
204     ((AtomicBlackBoxInputDescriptor*)bbGetDescriptor()->GetInputDescriptor(name))->GetSetFunctor()->Set(this,data);
205     
206     if (setModified) 
207       {
208         bbSetStatusAndPropagate(bbGetInputConnectorMap().find(name)->second,
209                                 MODIFIED);
210       }
211     
212     bbtkDebugDecTab("data",7);
213   }
214   //=========================================================================
215   
216   //=========================================================================
217   ///  Sets the data of the input called <name>
218   void AtomicBlackBox::bbBruteForceSetInputPointer(const std::string &name, 
219                                                    void* data, 
220                                                    bool setModified
221                                                    )
222   {
223     bbtkDebugMessageInc("data",7,
224             "AtomicBlackBox::bbBruteForceSetInputPointer(\""
225             <<name<<"\",data) ["
226             <<bbGetFullName()<<"]"
227             <<std::endl);  
228     ((AtomicBlackBoxInputDescriptor*)bbGetDescriptor()
229         ->GetInputDescriptor(name))->GetSetFunctor()
230             ->BruteForceSetPointer(this,data);
231     
232     if (setModified) 
233       {
234         bbSetStatusAndPropagate(bbGetInputConnectorMap().find(name)->second,
235                                 MODIFIED);
236       }
237     
238     bbtkDebugDecTab("data",7);
239   }
240   //=========================================================================
241  
242
243
244   //==========================================================================
245   std::string AtomicBlackBox::GetObjectInfo() const 
246   {
247     std::stringstream i;
248     return i.str();
249   }
250   //==========================================================================
251
252   //==========================================================================
253   size_t AtomicBlackBox::GetObjectSize() const 
254   {
255     return sizeof(*this);
256   }
257   //==========================================================================
258   
259   //==========================================================================
260   size_t AtomicBlackBox::GetObjectRecursiveSize() const 
261   {
262     size_t s = GetObjectSize();
263     return s;
264   }
265   //==========================================================================
266
267  
268 }
269 // EO namespace bbtk