]> Creatis software - bbtk.git/blob - packages/itk/src/bbitkAnyImageToTypedImage.h
Feature #1774
[bbtk.git] / packages / itk / src / bbitkAnyImageToTypedImage.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   Program:   bbtk
29   Module:    $RCSfile: bbitkAnyImageToTypedImage.h,v $
30   Language:  C++
31   Date:      $Date: 2012/11/16 08:50:39 $
32   Version:   $Revision: 1.10 $
33 =========================================================================*/
34
35
36
37
38 #ifdef _USE_ITK_
39
40 #ifndef __bbitkAnyImageToTypedImage_h_INCLUDED__
41 #define __bbitkAnyImageToTypedImage_h_INCLUDED__
42
43 #include "bbtkAtomicBlackBox.h"
44 #include "bbitkImage.h"
45
46 namespace bbitk
47 {
48
49   //=================================================================
50   // BlackBox declaration
51   template <class itkImageTypePointer>
52   class AnyImageToTypedImage : public bbtk::AtomicBlackBox
53   {  
54     BBTK_TEMPLATE_BLACK_BOX_INTERFACE(AnyImageToTypedImage,
55                                       bbtk::AtomicBlackBox,
56                                       itkImageTypePointer);
57     BBTK_DECLARE_INPUT(In,anyImagePointer);
58     BBTK_DECLARE_OUTPUT(Out,itkImageTypePointer);
59     BBTK_PROCESS(DoIt);
60     void DoIt();
61   };
62   //=================================================================
63   
64   //=================================================================
65   // BlackBox description
66   BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(AnyImageToTypedImage,
67                                       bbtk::AtomicBlackBox);
68   BBTK_NAME(bbtk::HumanTypeName<anyImagePointer>() + "To"
69             +bbtk::HumanTypeName<T>());
70   BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
71   BBTK_DESCRIPTION("Converts a generic itk image pointer ("+
72                    bbtk::HumanTypeName<anyImagePointer>()+
73                    ") into a typed itk image pointer ("+
74                    bbtk::HumanTypeName<T>()+")");
75   BBTK_DEFAULT_ADAPTOR();
76   BBTK_TEMPLATE_INPUT(AnyImageToTypedImage,In,
77                       "Input generic image pointer",anyImagePointer);
78   BBTK_TEMPLATE_OUTPUT(AnyImageToTypedImage,Out,
79                         "Output typed image pointer",T);
80   BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(AnyImageToTypedImage);
81   //=================================================================
82   
83   //=================================================================
84   template <class itkImageTypePointer>
85   void AnyImageToTypedImage<itkImageTypePointer>::DoIt()
86   {
87     if ( bbGetInputIn().type() == typeid(itkImageTypePointer) )
88       {
89         bbSetOutputOut ( bbGetInputIn().template unsafe_get < itkImageTypePointer >() );
90       }
91     else 
92       {
93         bbtkError(this->bbGetFullName()<<+" : transform of <"
94                   <<bbtk::TypeName(bbGetInputIn().type())<<"> into <"
95                   <<bbtk::TypeName<itkImageTypePointer>()<<"> not implemented");
96       }
97   }
98   //=================================================================
99
100
101   //===================================================
102   template <class T1> 
103   void AnyImageToTypedImage<T1>::bbUserSetDefaultValues() {}
104   template <class T1> 
105   void AnyImageToTypedImage<T1>::bbUserInitializeProcessing(){}
106   template <class T1> 
107   void AnyImageToTypedImage<T1>::bbUserFinalizeProcessing() {}
108   //===================================================
109   
110
111
112
113
114
115
116
117
118
119
120
121
122
123   //=================================================================
124   // BlackBox declaration
125   template <class itkImageTypePointer, class itkImageTypeConstPointer>
126   class AnyImageToConstTypedImage : public bbtk::AtomicBlackBox
127   {  
128     BBTK_TEMPLATE2_BLACK_BOX_INTERFACE(AnyImageToConstTypedImage,
129                                        bbtk::AtomicBlackBox,
130                                        itkImageTypePointer,
131                                        itkImageTypeConstPointer);
132     BBTK_DECLARE_INPUT(In,anyImagePointer);
133     BBTK_DECLARE_OUTPUT(Out,itkImageTypeConstPointer);
134     BBTK_PROCESS(DoIt);
135     void DoIt();
136   };
137   //=================================================================
138   
139   //=================================================================
140   // BlackBox description
141   BBTK_BEGIN_DESCRIBE_TEMPLATE2_BLACK_BOX(AnyImageToConstTypedImage,
142                                        bbtk::AtomicBlackBox);
143   BBTK_NAME(bbtk::HumanTypeName<anyImagePointer>() + "To" +
144             bbtk::HumanTypeName<T2>());
145   BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
146   BBTK_DESCRIPTION("Converts a generic itk image pointer ("+
147                    bbtk::HumanTypeName<anyImagePointer>()+
148                    ") into a const typed itk image pointer ("+
149                    bbtk::HumanTypeName<T2>()+")");
150   BBTK_CATEGORY("adaptor");
151   BBTK_DEFAULT_ADAPTOR();
152   BBTK_TEMPLATE2_INPUT(AnyImageToConstTypedImage,In,
153                       "Input generic image pointer",anyImagePointer);
154   BBTK_TEMPLATE2_OUTPUT(AnyImageToConstTypedImage,Out,
155                         "Output const typed image pointer",T2);
156   BBTK_END_DESCRIBE_TEMPLATE2_BLACK_BOX(AnyImageToConstTypedImage);
157   //=================================================================
158   
159   //=================================================================
160   template <class itkImageTypePointer, class itkImageTypeConstPointer>
161   void AnyImageToConstTypedImage<itkImageTypePointer,
162                                   itkImageTypeConstPointer>::DoIt()
163   {
164     if ( bbGetInputIn().type() == typeid(itkImageTypeConstPointer) )
165       {
166         bbSetOutputOut ( bbGetInputIn().template unsafe_get < itkImageTypeConstPointer >() );
167       }
168     else if ( bbGetInputIn().type() == typeid(itkImageTypePointer) )
169       {
170         bbSetOutputOut ( bbGetInputIn().template unsafe_get < itkImageTypePointer >() );
171       }
172     else 
173       {
174         bbtkError(this->bbGetFullName()<<+" : transform of <"
175                   <<bbtk::TypeName(bbGetInputIn().type())<<"> into <"
176                   <<bbtk::TypeName<itkImageTypeConstPointer>()<<"> not implemented");
177       }
178   }
179   //=================================================================
180
181   //===================================================
182   template <class T1, class T2> 
183   void AnyImageToConstTypedImage<T1,T2>::bbUserSetDefaultValues() {}
184   template <class T1, class T2> 
185   void AnyImageToConstTypedImage<T1,T2>::bbUserInitializeProcessing(){}
186   template <class T1, class T2> 
187   void AnyImageToConstTypedImage<T1,T2>::bbUserFinalizeProcessing() {}
188   //===================================================
189   
190
191
192
193
194
195
196
197 }
198 #endif
199 #endif