SIRF  3.4.0
Resample.h
Go to the documentation of this file.
1 /*
2 SyneRBI Synergistic Image Reconstruction Framework (SIRF)
3 Copyright 2017 - 2020 University College London
4 
5 This is software developed for the Collaborative Computational
6 Project in Synergistic Reconstruction for Biomedical Imaging (formerly CCP PETMR)
7 (http://www.ccpsynerbi.ac.uk/).
8 
9 Licensed under the Apache License, Version 2.0 (the "License");
10 you may not use this file except in compliance with the License.
11 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 
19 */
20 
30 #pragma once
31 
32 #include <vector>
33 #include <memory>
35 #include "sirf/iUtilities/iutilities.h"
36 
37 namespace sirf {
38 
39 // Forward declarations
40 template<class dataType> class Transformation;
41 class ImageData;
42 
54 template<class dataType>
55 class Resampler
56 {
57 public:
58 
61  NOTSET = -1,
62  NEARESTNEIGHBOUR = 0,
63  LINEAR = 1,
64  CUBICSPLINE = 3,
65  SINC = 4
66  };
67 
70 
72  virtual ~Resampler() {}
73 
75  virtual void set_reference_image(const std::shared_ptr<const ImageData> reference_image_sptr);
76 
78  virtual void set_floating_image(const std::shared_ptr<const ImageData> floating_image_sptr);
79 
81  virtual void add_transformation(const std::shared_ptr<const Transformation<dataType> > transformation_sptr);
82 
85 
87  virtual void set_interpolation_type(const enum InterpolationType type);
88 
91 
94 
97 
100 
103 
105  void set_padding_value(const float padding_value) { _padding_value = padding_value; }
106 
108  virtual void process() = 0;
109 
111  const std::shared_ptr<const ImageData> get_output_sptr() const { return _output_image_sptr; }
112 
114  virtual std::shared_ptr<ImageData> forward(const std::shared_ptr<const ImageData> input_sptr) = 0;
115 
117  virtual void forward(std::shared_ptr<ImageData> output_sptr, const std::shared_ptr<const ImageData> input_sptr) = 0;
118 
120  virtual std::shared_ptr<ImageData> adjoint(const std::shared_ptr<const ImageData> input_sptr) = 0;
121 
123  virtual void adjoint(std::shared_ptr<ImageData> output_sptr, const std::shared_ptr<const ImageData> input_sptr) = 0;
124 
126  virtual std::shared_ptr<ImageData> backward(const std::shared_ptr<const ImageData> input_sptr);
127 
129  virtual void backward(std::shared_ptr<ImageData> output_sptr, const std::shared_ptr<const ImageData> input_sptr);
130 
131 protected:
132 
134  virtual void set_up() = 0;
135 
137  virtual void set_up_forward() = 0;
138 
140  virtual void set_up_adjoint() = 0;
141 
143  virtual void check_parameters();
144 
146  std::shared_ptr<const ImageData> _reference_image_sptr;
148  std::shared_ptr<const ImageData> _floating_image_sptr;
149 
151  std::vector<std::shared_ptr<const Transformation<dataType> > > _transformations;
152 
155 
157  std::shared_ptr<ImageData> _output_image_sptr;
158 
160  float _padding_value = 0;
161  bool _need_to_set_up = true;
162  bool _need_to_set_up_forward = true;
163  bool _need_to_set_up_adjoint = true;
164 };
165 }
void set_interpolation_type_to_linear()
Set interpolation type to linear.
Definition: Resample.h:93
virtual void add_transformation(const std::shared_ptr< const Transformation< dataType > > transformation_sptr)
Add transformation.
Definition: Resample.cpp:55
virtual void process()=0
Process. Equivalent of calling forward(floating_image). Use get_output to get resampled image...
void set_interpolation_type_to_nearest_neighbour()
Set interpolation type to nearest neighbour.
Definition: Resample.h:90
virtual std::shared_ptr< ImageData > adjoint(const std::shared_ptr< const ImageData > input_sptr)=0
Do the adjoint transformation.
InterpolationType
Interpolation type.
Definition: Resample.h:60
Base class for transformations.
void set_padding_value(const float padding_value)
Set padding value.
Definition: Resample.h:105
std::shared_ptr< ImageData > _output_image_sptr
Output image.
Definition: Resample.h:157
const std::shared_ptr< const ImageData > get_output_sptr() const
Get output.
Definition: Resample.h:111
Definition: Resample.h:55
virtual void check_parameters()
Check parameters.
Definition: Resample.cpp:73
virtual void set_floating_image(const std::shared_ptr< const ImageData > floating_image_sptr)
Set floating image. This is the image that would be the floating if you were doing a forward transfor...
Definition: Resample.cpp:46
virtual void set_interpolation_type(const enum InterpolationType type)
Set interpolation type (0=nearest neighbour, 1=linear, 3=cubic, 4=sinc)
Definition: Resample.cpp:64
void set_interpolation_type_to_cubic_spline()
Set interpolation type to cubic spline.
Definition: Resample.h:96
virtual ~Resampler()
Destructor.
Definition: Resample.h:72
Forward declarations.
Definition: Registration.h:39
InterpolationType _interpolation_type
Interpolation type.
Definition: Resample.h:154
virtual void set_up_adjoint()=0
Set up adjoint.
virtual void set_up()=0
Set up.
Abstract data container.
Definition: GeometricalInfo.cpp:141
float _padding_value
Padding value.
Definition: Resample.h:160
Resampler()
Constructor.
Definition: Resample.h:69
virtual void set_reference_image(const std::shared_ptr< const ImageData > reference_image_sptr)
Set reference image. This is the image that would be the reference if you were doing a forward transf...
Definition: Resample.cpp:36
const InterpolationType get_interpolation_type() const
Get interpolation type.
Definition: Resample.h:102
std::shared_ptr< const ImageData > _floating_image_sptr
Floating image.
Definition: Resample.h:148
void set_interpolation_type_to_sinc()
Set interpolation type to sinc.
Definition: Resample.h:99
std::vector< std::shared_ptr< const Transformation< dataType > > > _transformations
Transformations (could be mixture of affine, displacements, deformations).
Definition: Resample.h:151
virtual std::shared_ptr< ImageData > forward(const std::shared_ptr< const ImageData > input_sptr)=0
Do the forward transformation.
virtual std::shared_ptr< ImageData > backward(const std::shared_ptr< const ImageData > input_sptr)
Backward. Alias for Adjoint.
Definition: Resample.cpp:85
void clear_transformations()
Clear transformations.
Definition: Resample.h:84
virtual void set_up_forward()=0
Set up forward.
std::shared_ptr< const ImageData > _reference_image_sptr
Reference image.
Definition: Resample.h:146