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 /*=========================================================================
31 Module: $RCSfile: bbitkvtkvtkImageData2itkImage.cxx,v $
33 Date: $Date: 2012/11/16 08:50:49 $
34 Version: $Revision: 1.8 $
36 =========================================================================*/
46 #include "bbitkvtkvtkImageData2itkImage.h"
47 #include "bbitkvtkPackage.h"
48 #include "itkVTKImageToImageFilter.h"
54 BBTK_BLACK_BOX_IMPLEMENTATION(vtkImageData2itkImage,bbtk::AtomicBlackBox);
56 BBTK_ADD_BLACK_BOX_TO_PACKAGE(itkvtk,vtkImageData2itkImage);
58 #define BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH_DIM(I,DIM,M) \
59 if (I->GetDataDimension()==DIM) \
61 if (I->GetScalarType()==VTK_CHAR) M<char,DIM>(); \
62 else if (I->GetScalarType()==VTK_SIGNED_CHAR) M<signed char,DIM>(); \
63 else if (I->GetScalarType()==VTK_UNSIGNED_CHAR) M<unsigned char,DIM>(); \
64 else if (I->GetScalarType()==VTK_SHORT) M<short,DIM>(); \
65 else if (I->GetScalarType()==VTK_UNSIGNED_SHORT) M<unsigned short,DIM>(); \
66 else if (I->GetScalarType()==VTK_INT) M<int,DIM>(); \
67 else if (I->GetScalarType()==VTK_UNSIGNED_INT) M<unsigned int,DIM>(); \
68 else if (I->GetScalarType()==VTK_LONG) M<long,DIM>(); \
69 else if (I->GetScalarType()==VTK_UNSIGNED_LONG) M<unsigned long,DIM>(); \
70 else if (I->GetScalarType()==VTK_FLOAT) M<float,DIM>(); \
71 else if (I->GetScalarType()==VTK_DOUBLE) M<double,DIM>(); \
74 #define BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH(I,M) \
75 BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH_DIM(I,2,M) \
76 BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH_DIM(I,3,M)
78 void vtkImageData2itkImage::Convert()
80 BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH(bbGetInputIn(),Convert)
84 template<class T, unsigned int D>
85 void vtkImageData2itkImage::Convert()
87 bbtkDebugMessage("process",5,"==> ["<<bbGetFullName()<<"] : Convert<"
88 <<bbtk::TypeName<T>()<<","<<D
92 typedef itk::Image<T,D> itkImageType;
93 typedef itk::VTKImageToImageFilter< itkImageType > VtkToItkConnection;
94 typename VtkToItkConnection::Pointer conv;
96 // No converter yet : create it and set its input
99 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : No converter yet : creating it"<<std::endl);
100 conv = VtkToItkConnection::New();
102 conv->SetInput( this->bbGetInputIn() );
106 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Converter ok "<<std::endl);
107 // Input vtkImage type changed ?
108 // Have to change the converter and set its input
109 conv = dynamic_cast<VtkToItkConnection*>
110 ((itk::ProcessObject*)mConverter);
113 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Converter of wrong input type : reacreating it "<<std::endl);
115 mConverter->UnRegister();
116 conv = VtkToItkConnection::New();
118 conv->SetInput( this->bbGetInputIn() );
120 // Input image type did not change but input image pointer did:
122 else if ( this->bbGetInputIn() != conv->GetExporter()->GetInput())
124 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Converter input changed : resetting it"<<std::endl);
126 conv->SetInput( this->bbGetInputIn() );
130 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Nothing changed"<<std::endl);
136 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Trying update"<<std::endl);
140 itkImageType* out = const_cast<itkImageType*>(conv->GetOutput());
143 catch( itk::ExceptionObject & e)
145 bbtkError("vtkImageData2itkImage<"
146 <<bbtk::TypeName<T>()<<","<<D
147 <<">::Convert() : "<<e);
149 bbtkDebugMessage("process",5,"<== ["<<bbGetFullName()<<"] : Convert<"
150 <<bbtk::TypeName<T>()<<","<<D
151 <<">() *DONE*"<<std::endl);
155 void vtkImageData2itkImage::bbUserSetDefaultValues()
157 // bbSetOutputOut(NULL);
161 void vtkImageData2itkImage::bbUserInitializeProcessing()
165 void vtkImageData2itkImage::bbUserFinalizeProcessing()