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