SIRF  3.5.0
NiftyResampler.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>
54 class ComplexNiftiImageData
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  virtual float norm(int num_iter, int verb) const;
127 
128 protected:
129 
131  virtual void set_up();
132 
134  virtual void set_up_forward();
135 
137  virtual void set_up_adjoint();
138 
141 
150 
152  std::shared_ptr<NiftiImageData3DDeformation<dataType> > _deformation_sptr;
154  std::shared_ptr<NiftyMoMo::BSplineTransformation> _adjoint_transformer_sptr;
156  std::shared_ptr<NiftiImageData<dataType> > _adjoint_input_weights_sptr;
158  std::shared_ptr<NiftiImageData<dataType> > _adjoint_output_weights_sptr;
159 };
160 }
Abstract resampling base class.
virtual void forward(std::shared_ptr< ImageData > output_sptr, const std::shared_ptr< const ImageData > input_sptr)
Do the forward transformation.
std::shared_ptr< NiftiImageData3DDeformation< dataType > > _deformation_sptr
Deformation.
Definition: NiftyResample.h:157
virtual void set_up_adjoint()
Set up adjoint.
detail::ComplexNiftiImageData< dataType > _output_image_adjoint_niftis
Adjoint resampled image as a NiftiImageData.
Definition: NiftyResample.h:154
virtual void process()
Process. Equivalent of calling forward(floating_image). Use get_output to get resampled image.
virtual void adjoint(std::shared_ptr< ImageData > output_sptr, const std::shared_ptr< const ImageData > input_sptr)
Do the adjoint transformation.
virtual std::shared_ptr< ImageData > adjoint(const std::shared_ptr< const ImageData > input_sptr)
Do the adjoint transformation.
detail::ComplexNiftiImageData< dataType > _floating_image_niftis
Floating image as a NiftiImageData.
Definition: NiftyResample.h:150
std::shared_ptr< NiftyMoMo::BSplineTransformation > _adjoint_transformer_sptr
Needed for the adjoint transformation.
Definition: NiftyResample.h:159
virtual ~NiftyResampler()
Destructor.
Definition: NiftyResampler.h:109
detail::ComplexNiftiImageData< dataType > _reference_image_niftis
Reference image as a NiftiImageData.
Definition: NiftyResample.h:148
void set_up_input_images()
Set up the input images (convert from ImageData to NiftiImageData if necessary)
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 std::shared_ptr< ImageData > forward(const std::shared_ptr< const ImageData > input_sptr)
Do the forward transformation.
virtual void set_up_forward()
Set up forward.
NiftyResampler()
Constructor.
Definition: NiftyResampler.h:106
std::shared_ptr< NiftiImageData< dataType > > _adjoint_input_weights_sptr
Adjoint reference weights. Vector as may be complex.
Definition: NiftyResample.h:161
virtual void set_up()
Set up.
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: NiftyResampler.h:76
size_t size() const
size
Definition: NiftyResampler.h:72
const std::shared_ptr< const NiftiImageData< dataType > > imag() const
Get imaginary component.
Definition: NiftyResampler.h:68
std::shared_ptr< NiftiImageData< dataType > > & imag()
Get imaginary component.
Definition: NiftyResampler.h:70
const std::shared_ptr< const NiftiImageData< dataType > > at(const unsigned idx) const
at
Definition: NiftyResampler.h:74
bool is_complex() const
is complex
Definition: NiftyResampler.h:62
const std::shared_ptr< const NiftiImageData< dataType > > real() const
Get real component.
Definition: NiftyResampler.h:64
virtual ~ComplexNiftiImageData()
Destructor.
Definition: NiftyResampler.h:60
std::shared_ptr< NiftiImageData< dataType > > & real()
Get real component.
Definition: NiftyResampler.h:66
ComplexNiftiImageData()
Constructor.
Definition: NiftyResampler.h:58
Abstract data container.
Definition: GeometricalInfo.cpp:141