]> Creatis software - bbtk.git/blob - doc/bouml/bbtkk/148098.bodies
mhb
[bbtk.git] / doc / bouml / bbtkk / 148098.bodies
1 class ResampleImageFilter
2 !!!188162.cpp!!!        ProcessSwitch() : void
3     bbtk::TypeInfo t = bbGetInputIn().type();
4     BBTK_TEMPLATE_ITK_IMAGE_SWITCH(t, this->Process);
5   
6 !!!188290.cpp!!!        Process() : void
7     bbtkDebugMessageInc("Core",9,
8                         "bbitk::ResampleImageFilter::Process<"
9                         <<bbtk::TypeName<T>()<<">()"<<std::endl);
10  
11     typedef T ImageType;
12     typedef itk::ResampleImageFilter<ImageType,ImageType> FilterType;
13     typename FilterType::Pointer filter = FilterType::New();
14     const unsigned int Dimension = ImageType::ImageDimension;
15
16     // Input
17     T* in = this->bbGetInputIn().get<T*>();
18     filter->SetInput( in );
19
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();
26     size = LPR.GetSize();
27     //    origin = LPR.GetIndex(); //in->GetOrigin();
28      for (unsigned int i=0;i<Dimension;++i) 
29       {
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]);
35        }
36    
37     filter->SetOutputOrigin (origin);
38     filter->SetSize (size);
39     filter->SetOutputSpacing( spacing );
40
41     filter->SetDefaultPixelValue (0);
42     filter->SetOutputDirection( in->GetDirection() );
43
44
45
46     // Transform
47     typedef itk::AffineTransform < double, Dimension> TransformType;
48     
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 );
53
54     
55  
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 );
61     }
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;
72       // }
73     } //end else if
74     // Interpolation 
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 );
80     }
81
82     filter->Update();
83     filter->GetOutput()->Register();
84     if (mOutput) mOutput->UnRegister();
85     this->bbSetOutputOut( filter->GetOutput() );
86     mOutput = filter->GetOutput();
87
88     bbtkDebugDecTab("Core",9);
89