X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=filters%2FclitkImageFillRegionGenericFilter.cxx;h=85b60802f96442f6e1f3a896f28daaa905253191;hb=0083c3fb2c66812489631c7551709d121de51625;hp=59bbff4f85921a622b713b35b0b6f0a8b21d6c02;hpb=931a42358442f4ee4f314613c991c838d4b4e3b7;p=clitk.git diff --git a/filters/clitkImageFillRegionGenericFilter.cxx b/filters/clitkImageFillRegionGenericFilter.cxx index 59bbff4..85b6080 100644 --- a/filters/clitkImageFillRegionGenericFilter.cxx +++ b/filters/clitkImageFillRegionGenericFilter.cxx @@ -1,18 +1,5 @@ -/*========================================================================= - - 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. - -=========================================================================*/ - #ifndef CLITKIMAGEFILLREGIONGENERICFILTER_CXX #define CLITKIMAGEFILLREGIONGENERICFILTER_CXX - /** ------------------------------------------------------------------- * @file clitkImageFillRegionGenericFilter.cxx @@ -25,14 +12,137 @@ #include "clitkImageFillRegionGenericFilter.h" //-------------------------------------------------------------------- -clitk::ImageFillRegionGenericFilter::ImageFillRegionGenericFilter() { +clitk::ImageFillRegionGenericFilter::ImageFillRegionGenericFilter(): + clitk::ImageToImageGenericFilter("ImageFillRegion") { + InitializeImageType<2>(); + InitializeImageType<3>(); mPixelValue = 0; m_IsCentered=false; - mSphericRegion=false; + mSphericRegion=false; } //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +template +void clitk::ImageFillRegionGenericFilter::InitializeImageType() { + // ADD_IMAGE_TYPE(Dim, char); + ADD_IMAGE_TYPE(Dim, short); + // ADD_IMAGE_TYPE(Dim, unsigned short); +// ADD_IMAGE_TYPE(Dim, int); + ADD_IMAGE_TYPE(Dim, float); + // ADD_IMAGE_TYPE(Dim, double); +} +//-------------------------------------------------------------------- + + + +//-------------------------------------------------------------------- +template +void clitk::ImageFillRegionGenericFilter::UpdateWithInputImageType() { + + // Typedef + typedef typename ImageType::PixelType PixelType; + static unsigned int Dim = ImageType::ImageDimension; + + // Spheric region + if (mSphericRegion) return Update_WithDimAndPixelType_SphericRegion(); + + // Read input + typename ImageType::Pointer input = GetInput(0); + + // Get pixel value in correct type + PixelType value = PixelTypeDownCast(mPixelValue); + + // Get region + typedef typename ImageType::RegionType RegionType; + typedef typename ImageType::SizeType SizeType; + typedef typename ImageType::IndexType IndexType; + RegionType region; + SizeType size; + IndexType start; + for(unsigned int i=0; i IteratorType; + IteratorType it(input, region); + it.GoToBegin(); + while (!it.IsAtEnd()) { + it.Set(value); + ++it; + } + + // Write results + SetNextOutput(input); +} +//-------------------------------------------------------------------- + +//-------------------------------------------------------------------- +template +void clitk::ImageFillRegionGenericFilter::Update_WithDimAndPixelType_SphericRegion() { + + // Read input + typedef itk::Image ImageType; + //typename ImageType::Pointer input = clitk::readImage(mInputFilenames[0], mIOVerbose); + typename ImageType::Pointer input = GetInput(0); + + // Get pixel value in correct type + PixelType value = PixelTypeDownCast(mPixelValue); + + // Centered? + if(m_IsCentered) + { + typename ImageType::SizeType size= input->GetLargestPossibleRegion().GetSize(); + typename ImageType::SpacingType spacing= input->GetSpacing(); + typename ImageType::PointType origin= input->GetOrigin(); + mCenter.resize(Dim); + for (unsigned int i=0; i IteratorType; + IteratorType it(input, input->GetLargestPossibleRegion()); + it.GoToBegin(); + + typename ImageType::PointType point; + //typename itk::Vector distance; + typename ImageType::IndexType index; + //bool inside; + double distance; + + while (!it.IsAtEnd()) + { + // inside=true; + index=it.GetIndex(); + input->TransformIndexToPhysicalPoint(index, point); + distance=0.0; + for(unsigned int i=0; i(input); +} + +//-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- void clitk::ImageFillRegionGenericFilter::SetSphericRegion(std::vector & radius, std::vector & center) @@ -57,25 +167,4 @@ void clitk::ImageFillRegionGenericFilter::SetSphericRegion(std::vector & //-------------------------------------------------------------------- -//-------------------------------------------------------------------- -void clitk::ImageFillRegionGenericFilter::Update () { - - // Load image header - itk::ImageIOBase::Pointer header = clitk::readImageHeader(mInputFilenames[0]); - - // Determine dim, pixel type, number of components - mDim = header->GetNumberOfDimensions(); - mPixelTypeName = header->GetComponentTypeAsString(header->GetComponentType()); - mNbOfComponents = header->GetNumberOfComponents(); - - // Switch by dimension - if (mDim == 2) { Update_WithDim<2>(); return; } - if (mDim == 3) { Update_WithDim<3>(); return; } - // if (mDim == 4) { Update_WithDim<4>(); return; } - - std::cerr << "Error, dimension of input image is " << mDim << ", but I only work with 2,3,4." << std::endl; - exit(0); -} -//-------------------------------------------------------------------- - #endif //define CLITKIMAGEFILLREGIONGENERICFILTER_CXX