1 /*=========================================================================
3 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
4 l'Image). All rights reserved. See Doc/License.txt or
5 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
7 This software is distributed WITHOUT ANY WARRANTY; without even
8 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9 PURPOSE. See the above copyright notices for more information.
11 =========================================================================*/
13 #ifndef CLITKIMAGEFILLREGIONGENERICFILTER_CXX
14 #define CLITKIMAGEFILLREGIONGENERICFILTER_CXX
17 -------------------------------------------------------------------
18 * @file clitkImageFillRegionGenericFilter.cxx
19 * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
23 -------------------------------------------------------------------*/
25 #include "clitkImageFillRegionGenericFilter.h"
27 //--------------------------------------------------------------------
28 clitk::ImageFillRegionGenericFilter::ImageFillRegionGenericFilter():
29 clitk::ImageToImageGenericFilter<Self>("ImageFillRegion") {
30 InitializeImageType<2>();
31 InitializeImageType<3>();
36 //--------------------------------------------------------------------
39 //--------------------------------------------------------------------
40 template<unsigned int Dim>
41 void clitk::ImageFillRegionGenericFilter::InitializeImageType() {
42 // ADD_IMAGE_TYPE(Dim, char);
43 ADD_IMAGE_TYPE(Dim, short);
44 // ADD_IMAGE_TYPE(Dim, unsigned short);
45 // ADD_IMAGE_TYPE(Dim, int);
46 ADD_IMAGE_TYPE(Dim, float);
47 // ADD_IMAGE_TYPE(Dim, double);
49 //--------------------------------------------------------------------
53 //--------------------------------------------------------------------
54 template<class ImageType>
55 void clitk::ImageFillRegionGenericFilter::UpdateWithInputImageType() {
58 typedef typename ImageType::PixelType PixelType;
59 static unsigned int Dim = ImageType::ImageDimension;
62 if (mSphericRegion) return Update_WithDimAndPixelType_SphericRegion<ImageType::ImageDimension,PixelType>();
65 typename ImageType::Pointer input = GetInput<ImageType>(0);
67 // Get pixel value in correct type
68 PixelType value = PixelTypeDownCast<double, PixelType>(mPixelValue);
71 typedef typename ImageType::RegionType RegionType;
72 typedef typename ImageType::SizeType SizeType;
73 typedef typename ImageType::IndexType IndexType;
77 for(unsigned int i=0; i<Dim; i++) {
82 region.SetIndex(start);
85 typedef itk::ImageRegionIterator<ImageType> IteratorType;
86 IteratorType it(input, region);
88 while (!it.IsAtEnd()) {
94 SetNextOutput<ImageType>(input);
96 //--------------------------------------------------------------------
98 //--------------------------------------------------------------------
99 template<unsigned int Dim, class PixelType>
100 void clitk::ImageFillRegionGenericFilter::Update_WithDimAndPixelType_SphericRegion() {
103 typedef itk::Image<PixelType,Dim> ImageType;
104 //typename ImageType::Pointer input = clitk::readImage<ImageType>(mInputFilenames[0], mIOVerbose);
105 typename ImageType::Pointer input = GetInput<ImageType>(0);
107 // Get pixel value in correct type
108 PixelType value = PixelTypeDownCast<double, PixelType>(mPixelValue);
113 typename ImageType::SizeType size= input->GetLargestPossibleRegion().GetSize();
114 typename ImageType::SpacingType spacing= input->GetSpacing();
115 typename ImageType::PointType origin= input->GetOrigin();
117 for (unsigned int i=0; i<Dim; i++)
118 mCenter[i]=origin[i]+(double)size[i]/2*spacing[i];
122 typedef itk::ImageRegionIteratorWithIndex<ImageType> IteratorType;
123 IteratorType it(input, input->GetLargestPossibleRegion());
126 typename ImageType::PointType point;
127 //typename itk::Vector<double, Dim> distance;
128 typename ImageType::IndexType index;
132 while (!it.IsAtEnd())
136 input->TransformIndexToPhysicalPoint(index, point);
138 for(unsigned int i=0; i<Dim; i++)
139 distance+=powf( ( (mCenter[i]-point[i])/mRadius[i] ), 2);
141 // inside= ( (fabs(distance[i])<fabs(mRadius[i])) && inside );
142 // distance[i]=mCenter[i]-point[i];
143 // inside= ( (fabs(distance[i])<fabs(mRadius[i])) && inside );
152 SetNextOutput<ImageType>(input);
155 //--------------------------------------------------------------------
159 //--------------------------------------------------------------------
160 void clitk::ImageFillRegionGenericFilter::SetSphericRegion(std::vector<double> & radius,
161 std::vector<double> & center)
164 mRadius.resize(radius.size());
165 std::copy(radius.begin(), radius.end(), mRadius.begin());
167 mCenter.resize(center.size());
168 std::copy(center.begin(), center.end(), mCenter.begin());
169 mSphericRegion = true;
173 void clitk::ImageFillRegionGenericFilter::SetSphericRegion(std::vector<double> & radius) {
175 mRadius.resize(radius.size());
176 std::copy(radius.begin(), radius.end(), mRadius.begin());
178 mSphericRegion = true;
180 //--------------------------------------------------------------------
183 #endif //define CLITKIMAGEFILLREGIONGENERICFILTER_CXX