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 /*=========================================================================
30 Module: $RCSfile: bbitkvtkitkImageVector2vtkImageDataVector.cxx,v $
32 Date: $Date: 2012/11/16 08:50:49 $
33 Version: $Revision: 1.2 $
34 =========================================================================*/
45 #include "bbitkvtkitkImageVector2vtkImageDataVector.h"
46 #include "bbitkvtkPackage.h"
47 #include "itkImageToVTKImageFilter.h"
52 BBTK_BLACK_BOX_IMPLEMENTATION(itkImageVector2vtkImageDataVector,bbtk::AtomicBlackBox);
54 BBTK_ADD_BLACK_BOX_TO_PACKAGE(itkvtk,itkImageVector2vtkImageDataVector);
56 void itkImageVector2vtkImageDataVector::Convert()
58 // suppose *all* the images have the same type // JPR
59 bbtk::TypeInfo t = bbGetInputIn()[0].type();
60 BBTK_TEMPLATE_ITK_IMAGE_SWITCH(t,Convert);
64 void itkImageVector2vtkImageDataVector::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 int vectorSize = bbGetInputIn().size();
76 std::cout << " itkImageVector2vtkImageDataVector vector size :" << vectorSize << std::endl;
77 for (int i=0; i< vectorSize ; i++)
79 // No converter yet : create it and set its input
82 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : No converter yet : creating it"<<std::endl);
83 conv = ItkToVtkConnection::New();
85 conv->SetInput( this->bbGetInputIn()[i].get< itkImageTypePointer >() );
89 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Converter ok "<<std::endl);
91 // Input itkImageType type changed ?
92 // Have to change the converter and set its input
93 conv = dynamic_cast<ItkToVtkConnection*>
94 ((itk::ProcessObject*)mConverter);
97 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Converter of wrong input type : reacreating it "<<std::endl);
99 mConverter->UnRegister();
100 conv = ItkToVtkConnection::New();
102 conv->SetInput( this->bbGetInputIn()[i].get<itkImageTypePointer>() );
104 // Input image type did not change but input image pointer did:
106 else if ( this->bbGetInputIn()[i].get<itkImageTypePointer>()
107 != (itkImageType*)(conv->GetExporter()->GetInputs()[0].GetPointer()))
109 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Converter input changed : resetting it"<<std::endl);
111 conv->SetInput( this->bbGetInputIn()[i].get<itkImageTypePointer>() );
115 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Nothing changed"<<std::endl);
120 bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Trying update"<<std::endl);
123 m_Output_Vector.push_back(conv->GetOutput());
125 catch( itk::ExceptionObject & e)
127 bbtkError("itkImageVector2vtkImageDataVector<"
128 <<bbtk::TypeName<T>()
129 <<">::Convert() : "<<e);
131 bbtkDebugMessage("process",5,"<== ["<<bbGetFullName()<<"] : Convert<"
132 <<bbtk::TypeName<T>()
133 <<">() *DONE*"<<std::endl);
135 } // end iterate on vector size
137 bbSetOutputOut(m_Output_Vector);
142 void itkImageVector2vtkImageDataVector::bbUserSetDefaultValues()
144 // bbSetOutputOut(std::vector<vtkImageData*>); // syntax? JPR
148 void itkImageVector2vtkImageDataVector::bbUserInitializeProcessing()
152 void itkImageVector2vtkImageDataVector::bbUserFinalizeProcessing()
158 // eo namespace bbitkvtk