1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #ifndef CLITKIMAGEFILLREGIONGENERICFILTER_CXX
19 #define CLITKIMAGEFILLREGIONGENERICFILTER_CXX
21 -------------------------------------------------------------------
22 * @file clitkImageFillRegionGenericFilter.cxx
23 * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
27 -------------------------------------------------------------------*/
29 #include "clitkImageFillRegionGenericFilter.h"
31 //--------------------------------------------------------------------
32 clitk::ImageFillRegionGenericFilter::ImageFillRegionGenericFilter():
33 clitk::ImageToImageGenericFilter<Self>("ImageFillRegion")
35 InitializeImageType<2>();
36 InitializeImageType<3>();
41 //--------------------------------------------------------------------
44 //--------------------------------------------------------------------
45 template<unsigned int Dim>
46 void clitk::ImageFillRegionGenericFilter::InitializeImageType()
48 // ADD_IMAGE_TYPE(Dim, char);
49 ADD_IMAGE_TYPE(Dim, short);
50 // ADD_IMAGE_TYPE(Dim, unsigned short);
51 // ADD_IMAGE_TYPE(Dim, int);
52 ADD_IMAGE_TYPE(Dim, float);
53 // ADD_IMAGE_TYPE(Dim, double);
55 //--------------------------------------------------------------------
59 //--------------------------------------------------------------------
60 template<class ImageType>
61 void clitk::ImageFillRegionGenericFilter::UpdateWithInputImageType()
65 typedef typename ImageType::PixelType PixelType;
66 static unsigned int Dim = ImageType::ImageDimension;
69 if (mSphericRegion) return Update_WithDimAndPixelType_SphericRegion<ImageType::ImageDimension,PixelType>();
72 typename ImageType::Pointer input = GetInput<ImageType>(0);
74 // Get pixel value in correct type
75 PixelType value = PixelTypeDownCast<double, PixelType>(mPixelValue);
78 typedef typename ImageType::RegionType RegionType;
79 typedef typename ImageType::SizeType SizeType;
80 typedef typename ImageType::IndexType IndexType;
84 for(unsigned int i=0; i<Dim; i++) {
89 region.SetIndex(start);
92 typedef itk::ImageRegionIterator<ImageType> IteratorType;
93 IteratorType it(input, region);
95 while (!it.IsAtEnd()) {
101 SetNextOutput<ImageType>(input);
103 //--------------------------------------------------------------------
105 //--------------------------------------------------------------------
106 template<unsigned int Dim, class PixelType>
107 void clitk::ImageFillRegionGenericFilter::Update_WithDimAndPixelType_SphericRegion()
111 typedef itk::Image<PixelType,Dim> ImageType;
112 //typename ImageType::Pointer input = clitk::readImage<ImageType>(mInputFilenames[0], mIOVerbose);
113 typename ImageType::Pointer input = GetInput<ImageType>(0);
115 // Get pixel value in correct type
116 PixelType value = PixelTypeDownCast<double, PixelType>(mPixelValue);
120 typename ImageType::SizeType size= input->GetLargestPossibleRegion().GetSize();
121 typename ImageType::SpacingType spacing= input->GetSpacing();
122 typename ImageType::PointType origin= input->GetOrigin();
124 for (unsigned int i=0; i<Dim; i++)
125 mCenter[i]=origin[i]+(double)size[i]/2*spacing[i];
129 typedef itk::ImageRegionIteratorWithIndex<ImageType> IteratorType;
130 IteratorType it(input, input->GetLargestPossibleRegion());
133 typename ImageType::PointType point;
134 //typename itk::Vector<double, Dim> distance;
135 typename ImageType::IndexType index;
139 while (!it.IsAtEnd()) {
142 input->TransformIndexToPhysicalPoint(index, point);
144 for(unsigned int i=0; i<Dim; i++)
145 distance+=powf( ( (mCenter[i]-point[i])/mRadius[i] ), 2);
147 // inside= ( (fabs(distance[i])<fabs(mRadius[i])) && inside );
148 // distance[i]=mCenter[i]-point[i];
149 // inside= ( (fabs(distance[i])<fabs(mRadius[i])) && inside );
158 SetNextOutput<ImageType>(input);
161 //--------------------------------------------------------------------
165 //--------------------------------------------------------------------
166 void clitk::ImageFillRegionGenericFilter::SetSphericRegion(std::vector<double> & radius,
167 std::vector<double> & center)
170 mRadius.resize(radius.size());
171 std::copy(radius.begin(), radius.end(), mRadius.begin());
173 mCenter.resize(center.size());
174 std::copy(center.begin(), center.end(), mCenter.begin());
175 mSphericRegion = true;
179 void clitk::ImageFillRegionGenericFilter::SetSphericRegion(std::vector<double> & radius)
182 mRadius.resize(radius.size());
183 std::copy(radius.begin(), radius.end(), mRadius.begin());
185 mSphericRegion = true;
187 //--------------------------------------------------------------------
190 #endif //define CLITKIMAGEFILLREGIONGENERICFILTER_CXX