X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FvvToITK.h;h=be22b621258a5db13a57d08881d8382f95a3f79d;hb=d55f025b18f68066a52b8f33c2dc6481e82c2580;hp=47a92c85ccd609d426fcfd2f656d20ddda87e6e9;hpb=0083c3fb2c66812489631c7551709d121de51625;p=clitk.git diff --git a/common/vvToITK.h b/common/vvToITK.h index 47a92c8..be22b62 100644 --- a/common/vvToITK.h +++ b/common/vvToITK.h @@ -1,83 +1,132 @@ -#ifndef vvImageToITK_h -#define vvImageToITK_h +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://www.centreleonberard.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + ===========================================================================**/ + +#ifndef VVIMAGETOITK_H +#define VVIMAGETOITK_H + +// std #include + +// vv #include "vvImage.h" + +// itk #include #include #include "itkVTKImageToImageFilter.h" +//-------------------------------------------------------------------- ///Converts the vv image to itk, handling the 4D problem template std::vector::ConstPointer> vvImageToITKImageVector(vvImage::Pointer vv_image) ///Converts the vv image to itk, handling the 4D problem { - assert(Dim < 5 && Dim > 1); // We don't handle anything higher than 4-dimensional (for the moment :-p) - assert(vv_image->GetVTKImages().size() > 0); //we assume there is something to convert - typedef itk::Image< PixelType, Dim > OutputImageType; - std::vector::ConstPointer> result; - - typedef itk::Image< PixelType, Dim > ConnectorImageType; - typedef itk::VTKImageToImageFilter ConnectorType; - for (unsigned int i = 0; i < vv_image->GetVTKImages().size(); i++) + assert(Dim < 5 && Dim > 1); // We don't handle anything higher than 4-dimensional (for the moment :-p) + assert(vv_image->GetVTKImages().size() > 0); //we assume there is something to convert + typedef itk::Image< PixelType, Dim > OutputImageType; + std::vector::ConstPointer> result; + + typedef itk::Image< PixelType, Dim > ConnectorImageType; + typedef itk::VTKImageToImageFilter ConnectorType; + for (unsigned int i = 0; i < vv_image->GetVTKImages().size(); i++) { - typename ConnectorType::Pointer connector = ConnectorType::New(); - connector->SetInput(vv_image->GetVTKImages()[i]); - connector->Update(); - result.push_back(connector->GetOutput()); + typename ConnectorType::Pointer connector = ConnectorType::New(); + connector->SetInput(vv_image->GetVTKImages()[i]); + connector->Update(); + result.push_back(connector->GetOutput()); } - return result; + return result; } +//-------------------------------------------------------------------- + +//-------------------------------------------------------------------- ///Converts the vv image to itk, handling the 4D problem template typename ImageType::ConstPointer vvImageToITK(vvImage::Pointer vv_image) ///Converts the vv image to itk, handling the 4D problem { - const unsigned int Dim=ImageType::ImageDimension; - assert(Dim < 5 && Dim > 0); // We don't handle anything higher than 4-dimensional (for the moment :-p) - typedef ImageType OutputImageType; + const unsigned int Dim=ImageType::ImageDimension; + assert(Dim < 5 && Dim > 0); // We don't handle anything higher than 4-dimensional (for the moment :-p) + typedef ImageType OutputImageType; - if (Dim==4) + if (Dim==4) { - typedef itk::Image< typename ImageType::PixelType, 3 > ConnectorImageType; - typedef itk::VTKImageToImageFilter ConnectorType; - typedef itk::JoinSeriesImageFilter FilterType; + typedef itk::Image< typename ImageType::PixelType, 3 > ConnectorImageType; + typedef itk::VTKImageToImageFilter ConnectorType; + typedef itk::JoinSeriesImageFilter FilterType; - typename FilterType::Pointer filter = FilterType::New(); - filter->SetOrigin(vv_image->GetOrigin()[3]); - filter->SetSpacing(vv_image->GetSpacing()[3]); + typename FilterType::Pointer filter = FilterType::New(); + filter->SetOrigin(vv_image->GetOrigin()[3]); + filter->SetSpacing(vv_image->GetSpacing()[3]); - for (int i = 0; i < vv_image->GetSize()[3]; i++) + for (int i = 0; i < vv_image->GetSize()[3]; i++) { - typename ConnectorType::Pointer connector = ConnectorType::New(); - connector->SetInput(vv_image->GetVTKImages()[i]); - connector->Update(); - filter->PushBackInput(connector->GetOutput()); + typename ConnectorType::Pointer connector = ConnectorType::New(); + connector->SetInput(vv_image->GetVTKImages()[i]); + connector->Update(); + filter->PushBackInput(connector->GetOutput()); } - filter->Update(); - return filter->GetOutput(); + filter->Update(); + return filter->GetOutput(); } - else //Dim == 1,2,3 + else //Dim == 1,2,3 { - assert(!vv_image->IsTimeSequence()); //This case isn't implemented - typedef ImageType ConnectorImageType; - typedef itk::VTKImageToImageFilter ConnectorType; - typename ConnectorType::Pointer connector = ConnectorType::New(); - connector->SetInput(vv_image->GetVTKImages()[0]); - - connector->Update(); - return connector->GetOutput(); + assert(!vv_image->IsTimeSequence()); //This case isn't implemented + typedef ImageType ConnectorImageType; + typedef itk::VTKImageToImageFilter ConnectorType; + typename ConnectorType::Pointer connector = ConnectorType::New(); + connector->SetInput(vv_image->GetVTKImages()[0]); + connector->Update(); + return connector->GetOutput(); } } +//-------------------------------------------------------------------- + +//-------------------------------------------------------------------- ///Converts a single time frame of a vv image to itk. template typename itk::Image::ConstPointer vvSingleFrameToITK(vvImage::Pointer vv_image,int frame) ///Converts the vv image to itk, handling the 4D problem { - assert(Dim < 4 && Dim > 0); - typedef itk::Image< PixelType, Dim > OutputImageType; - typedef itk::Image< PixelType, Dim > ConnectorImageType; - typedef itk::VTKImageToImageFilter ConnectorType; - typename ConnectorType::Pointer connector = ConnectorType::New(); - connector->SetInput(vv_image->GetVTKImages()[frame]); - connector->Update(); - return connector->GetOutput(); + assert(Dim < 4 && Dim > 0); + typedef itk::Image< PixelType, Dim > OutputImageType; + typedef itk::Image< PixelType, Dim > ConnectorImageType; + typedef itk::VTKImageToImageFilter ConnectorType; + typename ConnectorType::Pointer connector = ConnectorType::New(); + connector->SetInput(vv_image->GetVTKImages()[frame]); + connector->Update(); + return connector->GetOutput(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +typename itk::Image::ConstPointer +ItkImageFromVtk(vtkImageData * input) +{ + typedef itk::Image< PixelType, Dim > OutputImageType; + typedef itk::Image< PixelType, Dim > ConnectorImageType; + typedef itk::VTKImageToImageFilter ConnectorType; + typename ConnectorType::Pointer connector = ConnectorType::New(); + connector->SetInput(input); + connector->Update(); + return connector->GetOutput(); } +//-------------------------------------------------------------------- + + #endif