1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #ifndef __ITKToVTKImageImport_TXX
27 #define __ITKToVTKImageImport_TXX
33 ** Default constructor, allocates the vtkImageExport and itkImageImport
34 ** Connects the pipelines and set them ready to be use
36 template<typename TypeImage>
37 ITKToVTKImageImport<TypeImage>::ITKToVTKImageImport(){
39 vtkimageexport = vtkImageExport::New();
40 imageimportpointer = ImageImportType::New();
42 imageimportpointer->SetUpdateInformationCallback(vtkimageexport->GetUpdateInformationCallback());
43 imageimportpointer->SetPipelineModifiedCallback(vtkimageexport->GetPipelineModifiedCallback());
44 imageimportpointer->SetWholeExtentCallback(vtkimageexport->GetWholeExtentCallback());
45 imageimportpointer->SetSpacingCallback(vtkimageexport->GetSpacingCallback());
46 imageimportpointer->SetOriginCallback(vtkimageexport->GetOriginCallback());
47 imageimportpointer->SetScalarTypeCallback(vtkimageexport->GetScalarTypeCallback());
48 imageimportpointer->SetNumberOfComponentsCallback(vtkimageexport->GetNumberOfComponentsCallback());
49 imageimportpointer->SetPropagateUpdateExtentCallback(vtkimageexport->GetPropagateUpdateExtentCallback());
50 imageimportpointer->SetUpdateDataCallback(vtkimageexport->GetUpdateDataCallback());
51 imageimportpointer->SetDataExtentCallback(vtkimageexport->GetDataExtentCallback());
52 imageimportpointer->SetBufferPointerCallback(vtkimageexport->GetBufferPointerCallback());
53 imageimportpointer->SetCallbackUserData(vtkimageexport->GetCallbackUserData());
56 imageexportpointer = ImageExportType::New();
57 vtkimageimport = vtkImageImport::New();
59 vtkimageimport->SetUpdateInformationCallback(imageexportpointer->GetUpdateInformationCallback());
60 vtkimageimport->SetPipelineModifiedCallback(imageexportpointer->GetPipelineModifiedCallback());
61 vtkimageimport->SetWholeExtentCallback(imageexportpointer->GetWholeExtentCallback());
62 vtkimageimport->SetSpacingCallback(imageexportpointer->GetSpacingCallback());
63 vtkimageimport->SetOriginCallback(imageexportpointer->GetOriginCallback());
64 vtkimageimport->SetScalarTypeCallback(imageexportpointer->GetScalarTypeCallback());
65 vtkimageimport->SetNumberOfComponentsCallback(imageexportpointer->GetNumberOfComponentsCallback());
66 vtkimageimport->SetPropagateUpdateExtentCallback(imageexportpointer->GetPropagateUpdateExtentCallback());
67 vtkimageimport->SetUpdateDataCallback(imageexportpointer->GetUpdateDataCallback());
68 vtkimageimport->SetDataExtentCallback(imageexportpointer->GetDataExtentCallback());
69 vtkimageimport->SetBufferPointerCallback(imageexportpointer->GetBufferPointerCallback());
70 vtkimageimport->SetCallbackUserData(imageexportpointer->GetCallbackUserData());
75 template<typename TypeImage >
76 ITKToVTKImageImport<TypeImage>::~ITKToVTKImageImport(){
77 /*std::cout<<"delete ~ITKToVTKImageImport(){"<<std::endl;*/
78 vtkimageimport->Delete();
79 vtkimageexport->Delete();
82 * set the vtkImage data to connect to itk pipeline
84 template<typename TypeImage>
85 void ITKToVTKImageImport<TypeImage>::SetVTKImage(vtkImageData* img) {
86 vtkimageexport->SetInput( img );
87 vtkimageexport->Update();
88 imageimportpointer->Update();
94 template<typename TypeImage>
95 typename ITKToVTKImageImport<TypeImage>::InputImagePointerType ITKToVTKImageImport<TypeImage>::GetOutputITKImage() {
96 if(vtkimageexport->GetInput()==0){
97 throw "Image not set to get the ItkImage, set the VtkImage before.\0";
99 return imageimportpointer->GetOutput();
103 * Get the vtkImageData from the itk image
105 template<typename TypeImage >
106 vtkImageData* ITKToVTKImageImport<TypeImage >::GetOutputVTKImage() {
107 return vtkimageimport->GetOutput();
110 * set the vtkImage data to connect to itk pipeline
112 template<typename TypeImage>
113 void ITKToVTKImageImport<TypeImage >::SetITKImage(InputImagePointerType itkimage){
114 //std::cout<<"image pointer setITKImage"<<img<<std::endl;
116 m_ITKImage = itkimage;
117 imageexportpointer->SetInput(itkimage);
118 imageexportpointer->Update();
119 vtkimageimport->Update();