]> Creatis software - bbtk.git/blob - kernel/src/bbtkAtomicBlackBox.h
7a98e5b9f9c6b281d1f62861435f031f2e0053fe
[bbtk.git] / kernel / src / bbtkAtomicBlackBox.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkAtomicBlackBox.h,v $
4   Language:  C++
5   Date:      $Date: 2010/01/14 13:17:27 $
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  *  \file 
33  *  \brief class bbtk::AtomicBlackBox : ancestor of all user defined (concrete) black boxes which are atomic (vs. ComplexBlackBox objects which are made up of other (atomic or complex) boxes).
34  */
35
36 /**
37  *  \class bbtk::AtomicBlackBox
38  *  \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).
39  */
40  
41 #ifndef __bbtkAtomicBlackBox_h__
42 #define __bbtkAtomicBlackBox_h__
43
44 #include "bbtkBlackBox.h"
45 #include "bbtkAtomicBlackBoxDescriptor.h"
46
47 namespace bbtk
48 {
49
50  
51   //==================================================================
52   class BBTK_EXPORT AtomicBlackBox : public bbtk::BlackBox
53   {
54     //==================================================================
55   public: 
56     //==================================================================
57     bbtk::BlackBoxDescriptor::Pointer bbGetDescriptor() const
58     {
59       return bbmDescriptorPointer;
60     }
61     //==================================================================
62
63     //==================================================================
64     /// Gets the output Data of a given label
65     Data bbGetOutput( const std::string &label );
66     ///  Gets the input Data of a given label
67     Data bbGetInput( const std::string &label );
68     ///  Sets the data of the output called <name>
69     void bbSetOutput( const std::string &name, Data data);
70     ///  Sets the data of the input called <name>
71     void bbSetInput( const std::string &name, Data data, 
72                      bool setModified = true);
73     ///  Sets the data of the input called <name>
74     void bbBruteForceSetInputPointer( const std::string &name, 
75                                       void* data, 
76                                       bool setModified = true);
77     //==================================================================
78
79     //==================================================================
80     std::string GetObjectInfo() const;      
81     size_t GetObjectSize() const;
82     size_t GetObjectRecursiveSize() const;
83     //==================================================================
84
85     //==================================================================
86   protected:
87     //==================================================================
88     ///  Constructor with the AtomicBlackBox's instance name
89     AtomicBlackBox(const std::string &name, bool alloc = true);
90     /// Constructor from an existing box (copy) with a new instance name 
91     AtomicBlackBox(AtomicBlackBox& from, const std::string &name, 
92                  bool alloc = true);
93     ///  Destructor
94     virtual ~AtomicBlackBox();
95     /// 
96     virtual void bbLockDescriptor() = 0;
97     //==================================================================
98
99     //==================================================================
100     /// Calls the user defined processing method.
101     /// Overloaded in WxBlackBox to handle widget creation and show
102     virtual void bbProcess() { this->bbUserProcess(); }
103     //==================================================================
104
105     //==================================================================
106     /// User callback which computes the outputs as a function of the inputs. 
107     /// It is assumed to be deterministic and thus is only called 
108     /// if the inputs have changed 
109     virtual void bbUserProcess() 
110     {
111       bbtkWarning("AtomicBlackBox::bbUserProcess() not overloaded for box '"
112                   <<bbGetFullName()
113                   <<"' : the box does nothing. Is it a bug or a feature ?"
114                   <<std::endl);
115     }
116     //==================================================================
117
118     //==================================================================
119     /// *** TO BE REMOVED WHEN EVERYTHING IS OK ***
120     /// CHANGED RETURN TYPE OF bbUserConstructor FROM void TO int
121     /// TO PRODUCE COMPILATION ERROR IF AN USER DECLARES THE OLD 
122     /// METHOD bbUserConstructor IN ITS BOX
123     virtual int bbUserConstructor() { return 0; }
124     /// *** TO BE REMOVED WHEN EVERYTHING IS OK ***
125     /// THE SAME AS bbUserConstructor
126     virtual int bbUserCopyConstructor(bbtk::BlackBox::Pointer) { return 0; }
127     /// *** TO BE REMOVED WHEN EVERYTHING IS OK ***
128     /// THE SAME AS bbUserConstructor
129     virtual int bbUserDestructor() { return 0; }
130     //==================================================================    
131
132
133      //==================================================================
134   private:
135     //================================================================== 
136     /// Default constructor is private : 
137     /// derived classes must use the constructor with the AtomicBlackBox's name
138     AtomicBlackBox() : BlackBox("") {}
139     //================================================================== 
140
141   protected:
142     //================================================================== 
143     // The pointer on the descriptor
144     bbtk::BlackBoxDescriptor::Pointer bbmDescriptorPointer;  
145     //================================================================== 
146
147   };
148   // Class AtomicBlackBox
149   //====================================================================
150
151
152 }
153 // namespace bbtk
154
155
156 #include "bbtkAtomicBlackBoxMacros.h"
157
158 #endif
159