X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=packages%2Fitkvtk%2Fsrc%2FbbitkvtkvtkImageData2itkImage.cxx;h=c1bf73479ebe65c21a13aa7ed165d097dc17880a;hb=d2b20f96a780fa2441c9e1412860394f653e37b6;hp=92d5fed9953938bdff5437e7540ce30a426e47bc;hpb=c0e5c17c45ecb106079122fcf1c7005b173092e5;p=bbtk.git diff --git a/packages/itkvtk/src/bbitkvtkvtkImageData2itkImage.cxx b/packages/itkvtk/src/bbitkvtkvtkImageData2itkImage.cxx index 92d5fed..c1bf734 100644 --- a/packages/itkvtk/src/bbitkvtkvtkImageData2itkImage.cxx +++ b/packages/itkvtk/src/bbitkvtkvtkImageData2itkImage.cxx @@ -1,20 +1,41 @@ +/* +# --------------------------------------------------------------------- +# +# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image +# pour la SantÈ) +# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton +# Previous Authors : Laurent Guigues, Jean-Pierre Roux +# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil +# +# This software is governed by the CeCILL-B license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL-B +# license as circulated by CEA, CNRS and INRIA at the following URL +# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +# or in the file LICENSE.txt. +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL-B license and that you accept its terms. +# ------------------------------------------------------------------------ */ + + /*========================================================================= - + Program: bbtk Module: $RCSfile: bbitkvtkvtkImageData2itkImage.cxx,v $ Language: C++ - Date: $Date: 2008/03/03 11:49:17 $ - Version: $Revision: 1.1 $ - - Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de - l'Image). All rights reserved. See Doc/License.txt or - http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - + Date: $Date: 2012/11/16 08:50:49 $ + Version: $Revision: 1.8 $ + =========================================================================*/ + + /** * \file * \brief @@ -24,69 +45,97 @@ #include "bbitkvtkvtkImageData2itkImage.h" #include "bbitkvtkPackage.h" -// VtkToItkConnection #include "itkVTKImageToImageFilter.h" -// ItkToVtkConnection -//#include "itkImageToVTKImageFilter.h" namespace bbitkvtk { - - BBTK_USER_BLACK_BOX_IMPLEMENTATION(vtkImageData2itkImage,bbtk::AtomicBlackBox); + + BBTK_BLACK_BOX_IMPLEMENTATION(vtkImageData2itkImage,bbtk::AtomicBlackBox); BBTK_ADD_BLACK_BOX_TO_PACKAGE(itkvtk,vtkImageData2itkImage); - -#define BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH_DIM(I,DIM,M) \ - if (I->GetDataDimension()==DIM) \ - { \ - if (I->GetScalarType()==VTK_CHAR) M(); \ - else if (I->GetScalarType()==VTK_SIGNED_CHAR) M(); \ - else if (I->GetScalarType()==VTK_UNSIGNED_CHAR) M(); \ - else if (I->GetScalarType()==VTK_SHORT) M(); \ + +#define BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH_DIM(I,DIM,M) \ + if (I->GetDataDimension()==DIM) \ + { \ + if (I->GetScalarType()==VTK_CHAR) M(); \ + else if (I->GetScalarType()==VTK_SIGNED_CHAR) M(); \ + else if (I->GetScalarType()==VTK_UNSIGNED_CHAR) M(); \ + else if (I->GetScalarType()==VTK_SHORT) M(); \ else if (I->GetScalarType()==VTK_UNSIGNED_SHORT) M(); \ - else if (I->GetScalarType()==VTK_INT) M(); \ - else if (I->GetScalarType()==VTK_UNSIGNED_INT) M(); \ - else if (I->GetScalarType()==VTK_LONG) M(); \ - else if (I->GetScalarType()==VTK_UNSIGNED_LONG) M(); \ - else if (I->GetScalarType()==VTK_FLOAT) M(); \ - else if (I->GetScalarType()==VTK_DOUBLE) M(); \ + else if (I->GetScalarType()==VTK_INT) M(); \ + else if (I->GetScalarType()==VTK_UNSIGNED_INT) M(); \ + else if (I->GetScalarType()==VTK_LONG) M(); \ + else if (I->GetScalarType()==VTK_UNSIGNED_LONG) M(); \ + else if (I->GetScalarType()==VTK_FLOAT) M(); \ + else if (I->GetScalarType()==VTK_DOUBLE) M(); \ } - + #define BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH(I,M) \ BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH_DIM(I,2,M) \ - BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH_DIM(I,3,M) + BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH_DIM(I,3,M) void vtkImageData2itkImage::Convert() - { - BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH(bbGetInputIn(),Convert) + { + BBTK_TEMPLATE_VTK_IMAGE_DATA_SWITCH(bbGetInputIn(),Convert) } - template void vtkImageData2itkImage::Convert() - { - bbtkDebugMessageInc("Core",9,"vtkImageData2itkImage<" + { + bbtkDebugMessage("process",5,"==> ["<()<<","<::Convert()"<()"< itkImageType; typedef itk::VTKImageToImageFilter< itkImageType > VtkToItkConnection; - //typedef itk::ImageToVTKImageFilter< itkImageType > ItkToVtkConnection; + typename VtkToItkConnection::Pointer conv; - - try + // No converter yet : create it and set its input + if (!mConverter) { - typename VtkToItkConnection::Pointer conv = VtkToItkConnection::New(); + bbtkDebugMessage("process",5," ["<SetInput( this->bbGetInputIn() ); - conv->Update(); - - // How to unreference the old output (is in an any...) ? - //if (bbGetOutputOut()) bbGetOutputOut()->Unreference(); + } + else + { + bbtkDebugMessage("process",5," ["< + ((itk::ProcessObject*)mConverter); + if (!conv) + { + bbtkDebugMessage("process",5," ["<UnRegister(); + conv = VtkToItkConnection::New(); + mConverter = conv; + conv->SetInput( this->bbGetInputIn() ); + } + // Input image type did not change but input image pointer did: + // set new input + else if ( this->bbGetInputIn() != conv->GetExporter()->GetInput()) + { + bbtkDebugMessage("process",5," ["<SetInput( this->bbGetInputIn() ); + } + else + { + bbtkDebugMessage("process",5," ["<Update(); itkImageType* out = const_cast(conv->GetOutput()); - out->Register(); bbSetOutputOut(out); } catch( itk::ExceptionObject & e) @@ -95,13 +144,25 @@ namespace bbitkvtk <()<<","<::Convert() : "<()<<","<() *DONE*"<