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