]> Creatis software - bbtk.git/blob - packages/itkvtk/src/bbitkvtkvtkImageData2itkImage.cxx
3afb1e81eb0df56651b8f6e670628131ef133bdb
[bbtk.git] / packages / itkvtk / src / bbitkvtkvtkImageData2itkImage.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbitkvtkvtkImageData2itkImage.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/04/18 12:59:50 $
7   Version:   $Revision: 1.2 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 /**
19  *  \file 
20  *  \brief 
21  */
22 #ifdef _USE_ITK_
23 #ifdef _USE_VTK_
24
25 #include "bbitkvtkvtkImageData2itkImage.h"
26 #include "bbitkvtkPackage.h"
27 // VtkToItkConnection 
28 #include "itkVTKImageToImageFilter.h"
29 // ItkToVtkConnection
30 //#include "itkImageToVTKImageFilter.h"
31
32
33 namespace bbitkvtk 
34 {
35   
36   BBTK_BLACK_BOX_IMPLEMENTATION(vtkImageData2itkImage,bbtk::AtomicBlackBox);
37
38   BBTK_ADD_BLACK_BOX_TO_PACKAGE(itkvtk,vtkImageData2itkImage);
39   
40 #define BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH_DIM(I,DIM,M)                \
41   if (I->GetDataDimension()==DIM)                                       \
42     {                                                                   \
43       if (I->GetScalarType()==VTK_CHAR) M<char,DIM>();                  \
44       else if (I->GetScalarType()==VTK_SIGNED_CHAR) M<signed char,DIM>(); \
45       else if (I->GetScalarType()==VTK_UNSIGNED_CHAR) M<unsigned char,DIM>(); \
46       else if (I->GetScalarType()==VTK_SHORT) M<short,DIM>();           \
47       else if (I->GetScalarType()==VTK_UNSIGNED_SHORT) M<unsigned short,DIM>(); \
48       else if (I->GetScalarType()==VTK_INT) M<int,DIM>();               \
49       else if (I->GetScalarType()==VTK_UNSIGNED_INT) M<unsigned int,DIM>(); \
50       else if (I->GetScalarType()==VTK_LONG) M<long,DIM>();             \
51       else if (I->GetScalarType()==VTK_UNSIGNED_LONG) M<unsigned long,DIM>(); \
52       else if (I->GetScalarType()==VTK_FLOAT) M<float,DIM>();           \
53       else if (I->GetScalarType()==VTK_DOUBLE) M<double,DIM>();         \
54     }
55   
56 #define BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH(I,M) \
57   BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH_DIM(I,2,M) \
58   BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH_DIM(I,3,M) 
59
60   void vtkImageData2itkImage::Convert()
61   {   
62     BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH(bbGetInputIn(),Convert)
63   }
64   
65
66
67    template<class T, unsigned int D>
68    void vtkImageData2itkImage::Convert()
69   {
70     bbtkDebugMessageInc("Core",9,"vtkImageData2itkImage<"
71                         <<bbtk::TypeName<T>()<<","<<D
72                         <<">::Convert()"<<std::endl);
73
74     typedef itk::Image<T,D> itkImageType;
75     typedef itk::VTKImageToImageFilter< itkImageType > VtkToItkConnection;
76     //typedef itk::ImageToVTKImageFilter< itkImageType > ItkToVtkConnection;
77
78
79     try 
80       {
81         typename VtkToItkConnection::Pointer conv = VtkToItkConnection::New();
82         conv->SetInput( this->bbGetInputIn() );
83         conv->Update();
84
85         // How to unreference the old output (is in an any...) ?
86         //if (bbGetOutputOut()) bbGetOutputOut()->Unreference();
87         
88         itkImageType* out = const_cast<itkImageType*>(conv->GetOutput());
89         out->Register();        
90         bbSetOutputOut(out);
91       }
92     catch( itk::ExceptionObject & e) 
93       {
94         bbtkError("vtkImageData2itkImage<"
95                   <<bbtk::TypeName<T>()<<","<<D
96                   <<">::Convert() : "<<e);
97       } 
98
99     bbtkDebugDecTab("Core",9);
100   }
101
102   
103
104
105
106
107 }
108 // eo namespace bbtk
109
110 #endif
111 // _USE_VTK_
112 #endif
113 // _USE_ITK_