X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=filters%2FclitkSplitImageGenericFilter.cxx;h=e887b04e566da052bbfc4f705712b13d6821c4e8;hb=1a9df303827cc1ecccfe7deb5a300100e6c71978;hp=bb46dd971206a7324235a524e6126eddffa1ba9f;hpb=931a42358442f4ee4f314613c991c838d4b4e3b7;p=clitk.git diff --git a/filters/clitkSplitImageGenericFilter.cxx b/filters/clitkSplitImageGenericFilter.cxx index bb46dd9..e887b04 100644 --- a/filters/clitkSplitImageGenericFilter.cxx +++ b/filters/clitkSplitImageGenericFilter.cxx @@ -1,15 +1,20 @@ /*========================================================================= + 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 @@ -23,27 +28,56 @@ #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); + } } //--------------------------------------------------------------------