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") {
34 InitializeImageType<2>();
35 InitializeImageType<3>();
40 //--------------------------------------------------------------------
43 //--------------------------------------------------------------------
44 template<unsigned int Dim>
45 void clitk::ImageFillRegionGenericFilter::InitializeImageType() {
46 // ADD_IMAGE_TYPE(Dim, char);
47 ADD_IMAGE_TYPE(Dim, short);
48 // ADD_IMAGE_TYPE(Dim, unsigned short);
49 // ADD_IMAGE_TYPE(Dim, int);
50 ADD_IMAGE_TYPE(Dim, float);
51 // ADD_IMAGE_TYPE(Dim, double);
53 //--------------------------------------------------------------------
57 //--------------------------------------------------------------------
58 template<class ImageType>
59 void clitk::ImageFillRegionGenericFilter::UpdateWithInputImageType() {
62 typedef typename ImageType::PixelType PixelType;
63 static unsigned int Dim = ImageType::ImageDimension;
66 if (mSphericRegion) return Update_WithDimAndPixelType_SphericRegion<ImageType::ImageDimension,PixelType>();
69 typename ImageType::Pointer input = GetInput<ImageType>(0);
71 // Get pixel value in correct type
72 PixelType value = PixelTypeDownCast<double, PixelType>(mPixelValue);
75 typedef typename ImageType::RegionType RegionType;
76 typedef typename ImageType::SizeType SizeType;
77 typedef typename ImageType::IndexType IndexType;
81 for(unsigned int i=0; i<Dim; i++) {
86 region.SetIndex(start);
89 typedef itk::ImageRegionIterator<ImageType> IteratorType;
90 IteratorType it(input, region);
92 while (!it.IsAtEnd()) {
98 SetNextOutput<ImageType>(input);
100 //--------------------------------------------------------------------
102 //--------------------------------------------------------------------
103 template<unsigned int Dim, class PixelType>
104 void clitk::ImageFillRegionGenericFilter::Update_WithDimAndPixelType_SphericRegion() {
107 typedef itk::Image<PixelType,Dim> ImageType;
108 //typename ImageType::Pointer input = clitk::readImage<ImageType>(mInputFilenames[0], mIOVerbose);
109 typename ImageType::Pointer input = GetInput<ImageType>(0);
111 // Get pixel value in correct type
112 PixelType value = PixelTypeDownCast<double, PixelType>(mPixelValue);
117 typename ImageType::SizeType size= input->GetLargestPossibleRegion().GetSize();
118 typename ImageType::SpacingType spacing= input->GetSpacing();
119 typename ImageType::PointType origin= input->GetOrigin();
121 for (unsigned int i=0; i<Dim; i++)
122 mCenter[i]=origin[i]+(double)size[i]/2*spacing[i];
126 typedef itk::ImageRegionIteratorWithIndex<ImageType> IteratorType;
127 IteratorType it(input, input->GetLargestPossibleRegion());
130 typename ImageType::PointType point;
131 //typename itk::Vector<double, Dim> distance;
132 typename ImageType::IndexType index;
136 while (!it.IsAtEnd())
140 input->TransformIndexToPhysicalPoint(index, point);
142 for(unsigned int i=0; i<Dim; i++)
143 distance+=powf( ( (mCenter[i]-point[i])/mRadius[i] ), 2);
145 // inside= ( (fabs(distance[i])<fabs(mRadius[i])) && inside );
146 // distance[i]=mCenter[i]-point[i];
147 // inside= ( (fabs(distance[i])<fabs(mRadius[i])) && inside );
156 SetNextOutput<ImageType>(input);
159 //--------------------------------------------------------------------
163 //--------------------------------------------------------------------
164 void clitk::ImageFillRegionGenericFilter::SetSphericRegion(std::vector<double> & radius,
165 std::vector<double> & center)
168 mRadius.resize(radius.size());
169 std::copy(radius.begin(), radius.end(), mRadius.begin());
171 mCenter.resize(center.size());
172 std::copy(center.begin(), center.end(), mCenter.begin());
173 mSphericRegion = true;
177 void clitk::ImageFillRegionGenericFilter::SetSphericRegion(std::vector<double> & radius) {
179 mRadius.resize(radius.size());
180 std::copy(radius.begin(), radius.end(), mRadius.begin());
182 mSphericRegion = true;
184 //--------------------------------------------------------------------
187 #endif //define CLITKIMAGEFILLREGIONGENERICFILTER_CXX