]> Creatis software - bbtk.git/blob - packages/itk/src/bbitkAnyImageToTypedImage.h
*** empty log message ***
[bbtk.git] / packages / itk / src / bbitkAnyImageToTypedImage.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbitkAnyImageToTypedImage.h,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:21 $
6   Version:   $Revision: 1.8 $
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   // BlackBox declaration
96   template <class itkImageTypePointer, class itkImageTypeConstPointer>
97   class AnyImageToConstTypedImage : public bbtk::AtomicBlackBox
98   {  
99     BBTK_TEMPLATE2_BLACK_BOX_INTERFACE(AnyImageToConstTypedImage,
100                                        bbtk::AtomicBlackBox,
101                                        itkImageTypePointer,
102                                        itkImageTypeConstPointer);
103     BBTK_DECLARE_INPUT(In,anyImagePointer);
104     BBTK_DECLARE_OUTPUT(Out,itkImageTypeConstPointer);
105     BBTK_PROCESS(DoIt);
106     void DoIt();
107   };
108   //=================================================================
109   
110   //=================================================================
111   // BlackBox description
112   BBTK_BEGIN_DESCRIBE_TEMPLATE2_BLACK_BOX(AnyImageToConstTypedImage,
113                                        bbtk::AtomicBlackBox);
114   BBTK_NAME(bbtk::HumanTypeName<anyImagePointer>() + "To" +
115             bbtk::HumanTypeName<T2>());
116   BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
117   BBTK_DESCRIPTION("Converts a generic itk image pointer ("+
118                    bbtk::HumanTypeName<anyImagePointer>()+
119                    ") into a const typed itk image pointer ("+
120                    bbtk::HumanTypeName<T2>()+")");
121   BBTK_CATEGORY("adaptor");
122   BBTK_DEFAULT_ADAPTOR();
123   BBTK_TEMPLATE2_INPUT(AnyImageToConstTypedImage,In,
124                       "Input generic image pointer",anyImagePointer);
125   BBTK_TEMPLATE2_OUTPUT(AnyImageToConstTypedImage,Out,
126                         "Output const typed image pointer",T2);
127   BBTK_END_DESCRIBE_TEMPLATE2_BLACK_BOX(AnyImageToConstTypedImage);
128   //=================================================================
129   
130   //=================================================================
131   template <class itkImageTypePointer, class itkImageTypeConstPointer>
132   void AnyImageToConstTypedImage<itkImageTypePointer,
133                                   itkImageTypeConstPointer>::DoIt()
134   {
135     if ( bbGetInputIn().type() == typeid(itkImageTypeConstPointer) )
136       {
137         bbSetOutputOut ( bbGetInputIn().template unsafe_get < itkImageTypeConstPointer >() );
138       }
139     else if ( bbGetInputIn().type() == typeid(itkImageTypePointer) )
140       {
141         bbSetOutputOut ( bbGetInputIn().template unsafe_get < itkImageTypePointer >() );
142       }
143     else 
144       {
145         bbtkError(this->bbGetFullName()<<+" : transform of <"
146                   <<bbtk::TypeName(bbGetInputIn().type())<<"> into <"
147                   <<bbtk::TypeName<itkImageTypeConstPointer>()<<"> not implemented");
148       }
149   }
150   //=================================================================
151
152
153 }
154 #endif
155 #endif