X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=filters%2FclitkSplitImageGenericFilter.cxx;h=4fd6eac9e0de58fb4d879f729767180a2e52f25e;hb=868922dc773690f1be8f21159f10fc4702e5c09f;hp=bb46dd971206a7324235a524e6126eddffa1ba9f;hpb=931a42358442f4ee4f314613c991c838d4b4e3b7;p=clitk.git diff --git a/filters/clitkSplitImageGenericFilter.cxx b/filters/clitkSplitImageGenericFilter.cxx index bb46dd9..4fd6eac 100644 --- a/filters/clitkSplitImageGenericFilter.cxx +++ b/filters/clitkSplitImageGenericFilter.cxx @@ -1,49 +1,95 @@ /*========================================================================= + 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" +#include //-------------------------------------------------------------------- -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(); + if(this->m_Png){ + typedef itk::Image< unsigned char, ImageType::ImageDimension-1 > OutputPngImageType; + typedef itk::IntensityWindowingImageFilter< OutputImageType, OutputPngImageType > CastFilterType; + typename CastFilterType::Pointer cast = CastFilterType::New(); + cast->SetWindowLevel(this->m_Window, this->m_Level); + cast->SetInput(filter->GetOutput()); + SetOutputFilename(base_filename+"_"+ss.str()+".png"); + SetNextOutput(cast->GetOutput()); + } + else { + SetOutputFilename(base_filename+"_"+ss.str()+".mhd"); + SetNextOutput(filter->GetOutput()); + } + } } //--------------------------------------------------------------------