X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=filters%2FclitkSplitImageGenericFilter.cxx;h=2b9502495bba3ab841326977dc62950c34f6165d;hb=4934205c18b17f41c1879acbfd70ca2f3b260175;hp=bb46dd971206a7324235a524e6126eddffa1ba9f;hpb=931a42358442f4ee4f314613c991c838d4b4e3b7;p=clitk.git diff --git a/filters/clitkSplitImageGenericFilter.cxx b/filters/clitkSplitImageGenericFilter.cxx index bb46dd9..2b95024 100644 --- a/filters/clitkSplitImageGenericFilter.cxx +++ b/filters/clitkSplitImageGenericFilter.cxx @@ -1,49 +1,85 @@ /*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv - 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/Gdcm/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. - -=========================================================================*/ + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.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 +======================================================================-====*/ /** ------------------------------------------------------------------- * @file clitkSplitImageGenericFilter.cxx * @author Joël Schaerer * @date 20 April 2009 - * @brief + * @brief -------------------------------------------------------------------*/ #include "clitkSplitImageGenericFilter.h" #include "clitkSplitImageGenericFilter.txx" //-------------------------------------------------------------------- -clitk::SplitImageGenericFilter::SplitImageGenericFilter() { +clitk::SplitImageGenericFilter::SplitImageGenericFilter(): + clitk::ImageToImageGenericFilter("SplitImage") +{ mSplitDimension = 0; + InitializeImageType<3>(); + InitializeImageType<4>(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void clitk::SplitImageGenericFilter::InitializeImageType() +{ + ADD_DEFAULT_IMAGE_TYPES(Dim); + ADD_VEC_IMAGE_TYPE(Dim, 3,float); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -void clitk::SplitImageGenericFilter::Update () { - - // Read the Dimension and PixelType - int Dimension, Components; - std::string PixelType; - ReadImageDimensionAndPixelType(this->mInputFilenames[0], Dimension, PixelType, Components); - - - // Call UpdateWithDim - if(Dimension==3) UpdateWithDim<3>(PixelType, Components); - else if (Dimension==4)UpdateWithDim<4>(PixelType, Components); - else - { - std::cout<<"Error, Only for 3 or 4 Dimensions!!!"< +void clitk::SplitImageGenericFilter::UpdateWithInputImageType() +{ + + // Read input + typedef typename ImageType::PixelType PixelType; + typedef itk::Image OutputImageType; + typename ImageType::Pointer input = this->GetInput(0); + typedef itk::ExtractImageFilter FilterType; + typename FilterType::Pointer filter= FilterType::New(); + + filter->SetInput(input); + typename ImageType::SizeType size=input->GetLargestPossibleRegion().GetSize(); + size[mSplitDimension]=0; + typename ImageType::RegionType extracted_region; + extracted_region.SetSize(size); + filter->SetExtractionRegion(extracted_region); + filter->Update(); + + typename ImageType::IndexType index=input->GetLargestPossibleRegion().GetIndex(); + std::string base_filename=GetOutputFilename(); + unsigned int number_of_output_images=input->GetLargestPossibleRegion().GetSize()[mSplitDimension]; + for (unsigned int i=0; iSetExtractionRegion(extracted_region); + filter->Update(); + SetOutputFilename(base_filename+"_"+ss.str()+".mhd"); + typename OutputImageType::Pointer output=filter->GetOutput(); + SetNextOutput(output); + } } //--------------------------------------------------------------------