SIRF  3.6.0
NiftyResample.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 <nifti1_io.h>
33 #include <string>
34 #include <vector>
35 #include <iostream>
36 #include "sirf/Reg/Resample.h"
37 #include "sirf/iUtilities/iutilities.h"
38 
39 namespace NiftyMoMo {
40 class BSplineTransformation;
41 }
42 
43 namespace sirf {
44 
45 namespace detail {
53 template<class dataType>
55 {
56 public:
62  bool is_complex() const { return _imag_sptr != nullptr; }
64  const std::shared_ptr<const NiftiImageData<dataType> > real() const { return _real_sptr; }
66  std::shared_ptr<NiftiImageData<dataType> > &real() { return _real_sptr; }
68  const std::shared_ptr<const NiftiImageData<dataType> > imag() const { return _imag_sptr; }
70  std::shared_ptr<NiftiImageData<dataType> > &imag() { return _imag_sptr; }
72  size_t size() const { return is_complex() ? 2 : 1; }
74  const std::shared_ptr<const NiftiImageData<dataType> > at(const unsigned idx) const { check_bounds(idx); return idx == 0 ? real() : imag(); }
76  std::shared_ptr<NiftiImageData<dataType> > at(const unsigned idx) { check_bounds(idx); return idx == 0 ? real() : imag(); }
77 
78 private:
79  void check_bounds(const unsigned idx) const
80  {
81  if (idx > 1)
82  throw std::runtime_error("ComplexNiftiImageData::at(): Exceeds index range");
83  if (idx == 1 && !is_complex())
84  throw std::runtime_error("ComplexNiftiImageData::at(): Trying to access imaginary part of non-complex image");
85  }
86  std::shared_ptr<NiftiImageData<dataType> > _real_sptr;
87  std::shared_ptr<NiftiImageData<dataType> > _imag_sptr;
88 };
89 }
90 
100 template<class dataType>
101 class NiftyResampler : public Resampler<dataType>
102 {
103 public:
104 
107 
109  virtual ~NiftyResampler() {}
110 
112  virtual void process();
113 
115  virtual std::shared_ptr<ImageData> forward(const std::shared_ptr<const ImageData> input_sptr);
116 
118  virtual void forward(std::shared_ptr<ImageData> output_sptr, const std::shared_ptr<const ImageData> input_sptr);
119 
121  virtual std::shared_ptr<ImageData> adjoint(const std::shared_ptr<const ImageData> input_sptr);
122 
124  virtual void adjoint(std::shared_ptr<ImageData> output_sptr, const std::shared_ptr<const ImageData> input_sptr);
125 
126  std::shared_ptr<const ImageData> reference_image_sptr() const
127  {
128  return this->_reference_image_sptr;
129  }
130 
131  virtual float norm(int num_iter, int verb) const;
132 
133 protected:
134 
136  virtual void set_up();
137 
139  virtual void set_up_forward();
140 
142  virtual void set_up_adjoint();
143 
145  void set_up_input_images();
146 
155 
157  std::shared_ptr<NiftiImageData3DDeformation<dataType> > _deformation_sptr;
159  std::shared_ptr<NiftyMoMo::BSplineTransformation> _adjoint_transformer_sptr;
161  std::shared_ptr<NiftiImageData<dataType> > _adjoint_input_weights_sptr;
163  std::shared_ptr<NiftiImageData<dataType> > _adjoint_output_weights_sptr;
164 };
165 }
Abstract resampling base class.
Resampling class based on nifty resample.
Definition: NiftyResample.h:102
std::shared_ptr< NiftiImageData3DDeformation< dataType > > _deformation_sptr
Deformation.
Definition: NiftyResample.h:157
detail::ComplexNiftiImageData< dataType > _output_image_adjoint_niftis
Adjoint resampled image as a NiftiImageData.
Definition: NiftyResample.h:154
detail::ComplexNiftiImageData< dataType > _floating_image_niftis
Floating image as a NiftiImageData.
Definition: NiftyResample.h:150
virtual std::shared_ptr< ImageData > adjoint(const std::shared_ptr< const ImageData > input_sptr)
Do the adjoint transformation.
Definition: NiftyResampler.cpp:298
std::shared_ptr< NiftyMoMo::BSplineTransformation > _adjoint_transformer_sptr
Needed for the adjoint transformation.
Definition: NiftyResample.h:159
virtual ~NiftyResampler()
Destructor.
Definition: NiftyResample.h:109
virtual void set_up()
Set up.
Definition: NiftyResampler.cpp:101
detail::ComplexNiftiImageData< dataType > _reference_image_niftis
Reference image as a NiftiImageData.
Definition: NiftyResample.h:148
virtual void set_up_adjoint()
Set up adjoint.
Definition: NiftyResampler.cpp:145
std::shared_ptr< NiftiImageData< dataType > > _adjoint_output_weights_sptr
Adjoint output weights. Vector as may be complex.
Definition: NiftyResample.h:163
detail::ComplexNiftiImageData< dataType > _output_image_forward_niftis
Forward resampled image as a NiftiImageData.
Definition: NiftyResample.h:152
virtual void set_up_forward()
Set up forward.
Definition: NiftyResampler.cpp:129
virtual void process()
Process. Equivalent of calling forward(floating_image). Use get_output to get resampled image.
Definition: NiftyResampler.cpp:192
NiftyResampler()
Constructor.
Definition: NiftyResample.h:106
std::shared_ptr< NiftiImageData< dataType > > _adjoint_input_weights_sptr
Adjoint reference weights. Vector as may be complex.
Definition: NiftyResample.h:161
virtual std::shared_ptr< ImageData > forward(const std::shared_ptr< const ImageData > input_sptr)
Do the forward transformation.
Definition: NiftyResampler.cpp:255
void set_up_input_images()
Set up the input images (convert from ImageData to NiftiImageData if necessary)
Definition: NiftyResampler.cpp:198
Definition: Resample.h:58
std::shared_ptr< const ImageData > _reference_image_sptr
Reference image.
Definition: Resample.h:162
This is an internal class requied by NiftyResampler to handle complex images.
Definition: NiftyResample.h:55
std::shared_ptr< NiftiImageData< dataType > > at(const unsigned idx)
at
Definition: NiftyResample.h:76
size_t size() const
size
Definition: NiftyResample.h:72
const std::shared_ptr< const NiftiImageData< dataType > > imag() const
Get imaginary component.
Definition: NiftyResample.h:68
std::shared_ptr< NiftiImageData< dataType > > & imag()
Get imaginary component.
Definition: NiftyResample.h:70
const std::shared_ptr< const NiftiImageData< dataType > > at(const unsigned idx) const
at
Definition: NiftyResample.h:74
bool is_complex() const
is complex
Definition: NiftyResample.h:62
const std::shared_ptr< const NiftiImageData< dataType > > real() const
Get real component.
Definition: NiftyResample.h:64
virtual ~ComplexNiftiImageData()
Destructor.
Definition: NiftyResample.h:60
std::shared_ptr< NiftiImageData< dataType > > & real()
Get real component.
Definition: NiftyResample.h:66
ComplexNiftiImageData()
Constructor.
Definition: NiftyResample.h:58
Abstract data container.
Definition: GeometricalInfo.cpp:141