2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbstdMagicBox.h,v $
32 Date: $Date: 2012/11/16 08:51:32 $
33 Version: $Revision: 1.14 $
34 =========================================================================*/
37 #ifndef __bbstdMagicBox_h_INCLUDED_H__
38 #define __bbstdMagicBox_h_INCLUDED_H__
40 #include "bbtkAtomicBlackBox.h"
41 #include "bbstd_EXPORT.h"
46 //==================================================================
47 class bbstd_EXPORT MagicBox
49 public bbtk::AtomicBlackBox
51 BBTK_BLACK_BOX_INTERFACE(MagicBox,bbtk::AtomicBlackBox);
52 BBTK_DECLARE_INPUT(In,bbtk::Data);
53 BBTK_DECLARE_INPUT(Active,bool);
54 BBTK_DECLARE_OUTPUT(Out,bbtk::Data);
55 BBTK_PROCESS(DoProcess);
58 virtual void bbComputePostProcessStatus();
60 //==================================================================
63 //==================================================================
64 // We have to create a particular SetFunctor for MagicBox because
65 // its input is of type bbtk::Data (i.e. any) and :
66 // 1) an any cannot store an any (construction with an any invokes the copy constr.)
67 // 2) we cannot invoke the Set method with the content of the any because
69 // hence the Set method of the functor **MUST NOT** extract the
70 // content of the Data prior to invoking the set method of the box
71 class MagicBoxSetFunctor : public bbtk::AtomicBlackBoxSetFunctor
74 /// Type of pointer on a UBB::Set method
75 typedef void (MagicBox::*SetMethodPointerType)(bbtk::Data);
77 /// Construction with the pointer on the Set method
78 MagicBoxSetFunctor(SetMethodPointerType s) :
83 /// Concrete application of the Set method of object o
84 void Set(bbtk::AtomicBlackBox* o, const bbtk::Data& d)
86 bbtkDebugMessage("data",9,"MagicBoxSetfunctor::Set("<<
87 bbtk::HumanTypeName(d.type())<<
89 (((MagicBox*)o)->*mSetMethodPointer)(d);
93 bbtk::TypeInfo GetTypeInfo() const { return typeid(bbtk::Data); }
94 std::string GetTypeName() const { return bbtk::TypeName<bbtk::Data>(); }
95 std::string GetHumanTypeName() const { return bbtk::HumanTypeName<bbtk::Data>(); }
96 bool IsPointerType() const { return false; }
97 void BruteForceSetPointer(bbtk::AtomicBlackBox*, void*) {}
99 /// Pointer on the Set method
100 SetMethodPointerType mSetMethodPointer;
102 //===========================================================================
105 //===========================================================================
106 BBTK_BEGIN_DESCRIBE_BLACK_BOX(MagicBox,bbtk::AtomicBlackBox);
107 BBTK_NAME("MagicBox");
108 BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
109 BBTK_CATEGORY("misc");
110 BBTK_DESCRIPTION("Takes *any kind* of data and copies it to its output. Is a magic box as any box output can be plugged into it and its output can be plugged into any other box input (dynamic type checking, see below), hence it can be put between **any** two boxes. Type matching between its output and the input of the box(es) to which it is connected is made at *run-time*. The pipeline will be executed if the data types : i) match exactly ii) can be transformed by an adaptor iii) are related pointers, i.e. if the output pointer can be upcasted (static_cast) or downcasted (dynamic_cast) to an input type pointer (see the bbtk::any output connection rule in the guide for details). Important uses of the MagicBox are : 1) performing run-time pointer cast, either upward or backward an object hierarchy 2) perform data adaptation (adaptor creation) at run-time vs. pipeline creation time.");
113 (new bbtk::AtomicBlackBoxInputDescriptor
114 (typeid(MagicBoxDescriptor),
115 "In","Input data","",
116 new bbtk::AtomicBlackBoxTGetFunctor<MagicBox,bbtk::Data,bbtk::Data>
117 (&MagicBox::bbGetInputIn),
118 new MagicBoxSetFunctor (&MagicBox::bbSetInputIn) ) );
120 BBTK_INPUT(MagicBox, Active, "Active True/False (default True)",bool,"");
124 (new bbtk::AtomicBlackBoxOutputDescriptor
125 (typeid(MagicBoxDescriptor),
126 "Out","Output data","",
127 new bbtk::AtomicBlackBoxTGetFunctor<MagicBox,bbtk::Data,bbtk::Data>
128 (&MagicBox::bbGetOutputOut),
129 new MagicBoxSetFunctor (&MagicBox::bbSetOutputOut) ) );
130 BBTK_END_DESCRIBE_BLACK_BOX(MagicBox);
131 //===========================================================================
136 #endif // __bbstdMagicBox_h_INCLUDED_H__