1 /*=========================================================================
3 Module: $RCSfile: bbitkvtkitkImage2vtkImageData.cxx,v $
5 Date: $Date: 2008/11/25 11:17:17 $
6 Version: $Revision: 1.7 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
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.
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
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 * ------------------------------------------------------------------------ */
38 #include "bbitkvtkitkImage2vtkImageData.h"
39 #include "bbitkvtkPackage.h"
41 //#include "itkVTKImageToImageFilter.h"
43 #include "itkImageToVTKImageFilter.h"
48 BBTK_BLACK_BOX_IMPLEMENTATION(itkImage2vtkImageData,bbtk::AtomicBlackBox);
50 BBTK_ADD_BLACK_BOX_TO_PACKAGE(itkvtk,itkImage2vtkImageData);
55 void itkImage2vtkImageData::Convert()
57 bbtk::TypeInfo t = bbGetInputIn().type();
58 BBTK_TEMPLATE_ITK_IMAGE_SWITCH(t,Convert);
64 void itkImage2vtkImageData::Convert()
66 bbtkDebugMessage("process",5,"==> ["<<bbGetFullName()<<"] : Convert<"
70 typedef T itkImageType;
71 typedef itkImageType* itkImageTypePointer;
72 typedef itk::ImageToVTKImageFilter< itkImageType > ItkToVtkConnection;
73 typename ItkToVtkConnection::Pointer conv;
75 // No converter yet : create it and set its input
78 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : No converter yet : creating it"<<std::endl);
79 conv = ItkToVtkConnection::New();
81 conv->SetInput( this->bbGetInputIn().get< itkImageTypePointer >() );
85 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Converter ok "<<std::endl);
87 // Input itkImageType type changed ?
88 // Have to change the converter and set its input
89 conv = dynamic_cast<ItkToVtkConnection*>
90 ((itk::ProcessObject*)mConverter);
93 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Converter of wrong input type : reacreating it "<<std::endl);
95 mConverter->UnRegister();
96 conv = ItkToVtkConnection::New();
98 conv->SetInput( this->bbGetInputIn().get<itkImageTypePointer>() );
100 // Input image type did not change but input image pointer did:
102 else if ( this->bbGetInputIn().get<itkImageTypePointer>()
103 != (itkImageType*)(conv->GetExporter()->GetInputs()[0].GetPointer()))
105 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Converter input changed : resetting it"<<std::endl);
107 conv->SetInput( this->bbGetInputIn().get<itkImageTypePointer>() );
111 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Nothing changed"<<std::endl);
118 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Trying update"<<std::endl);
121 bbSetOutputOut(conv->GetOutput());
123 catch( itk::ExceptionObject & e)
125 bbtkError("itkImage2vtkImageData<"
126 <<bbtk::TypeName<T>()
127 <<">::Convert() : "<<e);
129 bbtkDebugMessage("process",5,"<== ["<<bbGetFullName()<<"] : Convert<"
130 <<bbtk::TypeName<T>()
131 <<">() *DONE*"<<std::endl);
136 void itkImage2vtkImageData::bbUserConstructor()
138 bbSetOutputOut(NULL);
141 void itkImage2vtkImageData::bbUserCopyConstructor(bbtk::BlackBox::Pointer)
143 bbSetOutputOut(NULL);
146 void itkImage2vtkImageData::bbUserDestructor()
152 // eo namespace bbitkvtk