]> Creatis software - bbtk.git/blob - kernel/src/bbtkAtomicBlackBox.h
#3203
[bbtk.git] / kernel / src / bbtkAtomicBlackBox.h
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la SantÈ)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and
11 #  abiding by the rules of distribution of free software. You can  use,
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B
13 #  license as circulated by CEA, CNRS and INRIA at the following URL
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability.
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbtkAtomicBlackBox.h,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:49:01 $
33   Version:   $Revision: 1.12 $
34 =========================================================================*/
35
36
37 /**
38  *  \file 
39  *  \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).
40  */
41
42 /**
43  *  \class bbtk::AtomicBlackBox
44  *  \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).
45  */
46  
47 #ifndef __bbtkAtomicBlackBox_h__
48 #define __bbtkAtomicBlackBox_h__
49
50 #include "bbtkBlackBox.h"
51 #include "bbtkAtomicBlackBoxDescriptor.h"
52 namespace bbtk
53 {
54
55  
56   //==================================================================
57   class BBTK_EXPORT AtomicBlackBox : public bbtk::BlackBox
58   {
59     //==================================================================
60   public: 
61     //==================================================================
62     bbtk::BlackBoxDescriptor::Pointer bbGetDescriptor() const
63     {
64       return bbmDescriptorPointer;
65     }
66     //==================================================================
67
68     //==================================================================
69     /// Gets the output Data of a given label
70     Data bbGetOutput( const std::string &label );
71     ///  Gets the input Data of a given label
72     Data bbGetInput( const std::string &label );
73     ///  Sets the data of the output called <name>
74     void bbSetOutput( const std::string &name, Data data);
75     ///  Sets the data of the input called <name>
76     void bbSetInput( const std::string &name, Data data, 
77                      bool setModified = true);
78     ///  Sets the data of the input called <name>
79     void bbBruteForceSetInputPointer( const std::string &name, 
80                                       void* data, 
81                                       bool setModified = true);
82     //==================================================================
83
84     //==================================================================
85     std::string GetObjectInfo() const;      
86     size_t GetObjectSize() const;
87     size_t GetObjectRecursiveSize() const;
88     //==================================================================
89
90     //==================================================================
91   protected:
92     //==================================================================
93     ///  Constructor with the AtomicBlackBox's instance name
94     AtomicBlackBox(const std::string &name, bool alloc = true);
95     /// Constructor from an existing box (copy) with a new instance name 
96     AtomicBlackBox(AtomicBlackBox& from, const std::string &name, 
97                  bool alloc = true);
98     ///  Destructor
99     virtual ~AtomicBlackBox();
100     /// 
101     virtual void bbLockDescriptor() = 0;
102     //==================================================================
103
104     //==================================================================
105     /// Calls the user defined processing method.
106     /// Overloaded in WxBlackBox to handle widget creation and show
107     virtual void bbProcess() { this->bbUserProcess(); }
108     //==================================================================
109
110     //==================================================================
111     /// User callback which computes the outputs as a function of the inputs. 
112     /// It is assumed to be deterministic and thus is only called 
113     /// if the inputs have changed 
114     virtual void bbUserProcess() 
115     {
116       bbtkWarning("AtomicBlackBox::bbUserProcess() not overloaded for box '"
117                   <<bbGetFullName()
118                   <<"' : the box does nothing. Is it a bug or a feature ?"
119                   <<std::endl);
120     }
121     //==================================================================
122
123     //==================================================================
124     /// *** TO BE REMOVED WHEN EVERYTHING IS OK ***
125     /// CHANGED RETURN TYPE OF bbUserConstructor FROM void TO int
126     /// TO PRODUCE COMPILATION ERROR IF AN USER DECLARES THE OLD 
127     /// METHOD bbUserConstructor IN ITS BOX
128     virtual int bbUserConstructor() { return 0; }
129     /// *** TO BE REMOVED WHEN EVERYTHING IS OK ***
130     /// THE SAME AS bbUserConstructor
131     virtual int bbUserCopyConstructor(bbtk::BlackBox::Pointer) { return 0; }
132     /// *** TO BE REMOVED WHEN EVERYTHING IS OK ***
133     /// THE SAME AS bbUserConstructor
134     virtual int bbUserDestructor() { return 0; }
135     //==================================================================    
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 // namespace bbtk
159
160
161 #include "bbtkAtomicBlackBoxMacros.h"
162
163 #endif
164