1 class ResampleImageFilter
2 !!!188162.cpp!!! ProcessSwitch() : void
3 bbtk::TypeInfo t = bbGetInputIn().type();
4 BBTK_TEMPLATE_ITK_IMAGE_SWITCH(t, this->Process);
6 !!!188290.cpp!!! Process() : void
7 bbtkDebugMessageInc("Core",9,
8 "bbitk::ResampleImageFilter::Process<"
9 <<bbtk::TypeName<T>()<<">()"<<std::endl);
12 typedef itk::ResampleImageFilter<ImageType,ImageType> FilterType;
13 typename FilterType::Pointer filter = FilterType::New();
14 const unsigned int Dimension = ImageType::ImageDimension;
17 T* in = this->bbGetInputIn().get<T*>();
18 filter->SetInput( in );
20 // Size, Spacing, Origin and DefaultPixelVal
21 typename ImageType::SizeType size;
22 typename ImageType::SpacingType spacing;
23 typename ImageType::PointType origin;
24 typename ImageType::RegionType LPR;
25 LPR = in->GetLargestPossibleRegion();
27 // origin = LPR.GetIndex(); //in->GetOrigin();
28 for (unsigned int i=0;i<Dimension;++i)
30 origin[i] = LPR.GetIndex()[i]*in->GetSpacing()[i];
31 spacing[i] = bbGetInputSpacing()[i];
32 double tmp = (LPR.GetSize()[i]*in->GetSpacing()[i]/spacing[i] ) + 0.5;
33 size[i] = (long)floor(tmp);
34 // size[i] = (long)lrint(LPR.GetSize()[i]*in->GetSpacing()[i]/spacing[i]);
37 filter->SetOutputOrigin (origin);
38 filter->SetSize (size);
39 filter->SetOutputSpacing( spacing );
41 filter->SetDefaultPixelValue (0);
42 filter->SetOutputDirection( in->GetDirection() );
47 typedef itk::AffineTransform < double, Dimension> TransformType;
49 // Instance of the transform object to be passed to the resample filter
50 // By default, identity transform is applied
51 typename TransformType::Pointer transform = TransformType::New();
52 filter->SetTransform ( transform );
56 if ( bbGetInputInterpolation() == "NearestNeighbor" ) {
57 typedef itk::NearestNeighborInterpolateImageFunction < ImageType, double > InterpolatorType;
58 // We create an interpolator of the found type
59 typename InterpolatorType::Pointer interpolator = InterpolatorType::New();
60 filter->SetInterpolator( interpolator );
62 else if ( bbGetInputInterpolation() == "BSpline") {
63 typedef itk::BSplineInterpolateImageFunction < ImageType, double > InterpolatorType;
64 // We create an interpolator of the found type
65 typename InterpolatorType::Pointer interpolator = InterpolatorType::New();
66 filter->SetInterpolator(interpolator);
67 // When handling unsigned data, it is possible that the interpolated value is negative
68 // if ( (m_InputImage->GetComponentTypeAsString() == "uchar") ||
69 // (m_InputImage->GetComponentTypeAsString() == "ushort") ||
70 // (m_InputImage->GetComponentTypeAsString() == "uint") ) {
71 // std::cout << "Warning! you're using unsigned data ! The interpolated value may result negative! "<< std::endl;
75 else { // if ( bbGetInputInterpolation() == "Linear" ) {
76 typedef itk::LinearInterpolateImageFunction < ImageType, double > InterpolatorType;
77 // We create an interpolator of the found type
78 typename InterpolatorType::Pointer interpolator = InterpolatorType::New();
79 filter->SetInterpolator( interpolator );
83 filter->GetOutput()->Register();
84 if (mOutput) mOutput->UnRegister();
85 this->bbSetOutputOut( filter->GetOutput() );
86 mOutput = filter->GetOutput();
88 bbtkDebugDecTab("Core",9);