SIRF  3.4.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 protected:
127 
129  virtual void set_up();
130 
132  virtual void set_up_forward();
133 
135  virtual void set_up_adjoint();
136 
138  void set_up_input_images();
139 
141  detail::ComplexNiftiImageData<dataType> _reference_image_niftis;
143  detail::ComplexNiftiImageData<dataType> _floating_image_niftis;
145  detail::ComplexNiftiImageData<dataType> _output_image_forward_niftis;
147  detail::ComplexNiftiImageData<dataType> _output_image_adjoint_niftis;
148 
150  std::shared_ptr<NiftiImageData3DDeformation<dataType> > _deformation_sptr;
152  std::shared_ptr<NiftyMoMo::BSplineTransformation> _adjoint_transformer_sptr;
154  std::shared_ptr<NiftiImageData<dataType> > _adjoint_input_weights_sptr;
156  std::shared_ptr<NiftiImageData<dataType> > _adjoint_output_weights_sptr;
157 };
158 }
virtual ~NiftyResampler()
Destructor.
Definition: NiftyResampler.h:109
Definition: NiftyResample.h:39
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 > > imag() const
Get imaginary component.
Definition: NiftyResampler.h:68
Definition: Resample.h:55
std::shared_ptr< NiftiImageData< dataType > > at(const unsigned idx)
at
Definition: NiftyResampler.h:76
This is an internal class requied by NiftyResampler to handle complex images.
Definition: NiftyResample.h:54
ComplexNiftiImageData()
Constructor.
Definition: NiftyResampler.h:58
std::shared_ptr< NiftiImageData< dataType > > & imag()
Get imaginary component.
Definition: NiftyResampler.h:70
Abstract resampling base class.
virtual ~ComplexNiftiImageData()
Destructor.
Definition: NiftyResampler.h:60
Abstract data container.
Definition: GeometricalInfo.cpp:141
std::shared_ptr< NiftiImageData< dataType > > & real()
Get real component.
Definition: NiftyResampler.h:66
size_t size() const
size
Definition: NiftyResampler.h:72
Resampling class based on nifty resample.
Definition: NiftyResample.h:101
const std::shared_ptr< const NiftiImageData< dataType > > real() const
Get real component.
Definition: NiftyResampler.h:64
NiftyResampler()
Constructor.
Definition: NiftyResampler.h:106