SIRF  3.4.0
ImageData.h
1 /*
2 SyneRBI Synergistic Image Reconstruction Framework (SIRF)
3 Copyright 2018 - 2020 Rutherford Appleton Laboratory STFC
4 Copyright 2018 - 2020 University College London
5 
6 This is software developed for the Collaborative Computational
7 Project in Synergistic Reconstruction for Biomedical Imaging (formerly CCP PETMR)
8 (http://www.ccpsynerbi.ac.uk/).
9 
10 Licensed under the Apache License, Version 2.0 (the "License");
11 you may not use this file except in compliance with the License.
12 You may obtain a copy of the License at
13 http://www.apache.org/licenses/LICENSE-2.0
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19 
20 */
21 #pragma once
22 
23 #ifndef SIRF_ABSTRACT_IMAGE_DATA_TYPE
24 #define SIRF_ABSTRACT_IMAGE_DATA_TYPE
25 
26 #include "sirf/common/ANumRef.h"
27 #include "sirf/common/DataContainer.h"
28 #include "sirf/common/ANumRef.h"
29 #include "sirf/common/GeometricalInfo.h"
30 
36 namespace sirf {
37  class ImageData : public DataContainer
38  {
39  public:
40  virtual ~ImageData() {}
41  virtual Dimensions dimensions() const = 0; // to go to DataContainer eventually
42  //virtual void get_data(void* data) const = 0;
43  //virtual void set_data(const void* data) = 0;
44  class Iterator {
45  public:
46  virtual ~Iterator() {}
47  virtual Iterator& operator++() = 0;
48  virtual ANumRef& operator*() = 0;
49  virtual bool operator==(const Iterator&) const = 0;
50  virtual bool operator!=(const Iterator&) const = 0;
51  };
53  public:
54  virtual ~Iterator_const() {}
55  virtual Iterator_const& operator++() = 0;
56  virtual const ANumRef& operator*() const = 0;
57  virtual bool operator==(const Iterator_const&) const = 0;
58  virtual bool operator!=(const Iterator_const&) const = 0;
59  };
60  virtual Iterator& begin() = 0;
61  virtual Iterator_const& begin() const = 0;
62  virtual Iterator& end() = 0;
63  virtual Iterator_const& end() const = 0;
64  virtual bool ordered() const
65  {
66  return true;
67  }
68  void copy(Iterator_const& src, Iterator& dst, Iterator& end) const
69  {
70  for (; dst != end; ++dst, ++src)
71  *dst = *src;
72  }
73  void fill(const ImageData& im)
74  {
75  Iterator_const& src = im.begin();
76  Iterator& dst = this->begin();
77  Iterator& end = this->end();
78  for (; dst != end; ++dst, ++src)
79  *dst = *src;
80  }
82  //virtual void write(const std::string &filename) const = 0;
83  virtual bool operator==(const ImageData& id) const
84  {
85  if (&id == this)
86  return true;
89  if (gi_self != gi_other)
90  return false;
91  float s = 0.0f;
92  float sx = 0.0f;
93  float sy = 0.0f;
94  complex_float_t zx;
95  complex_float_t zy;
96  Iterator_const& x = this->begin();
97  Iterator_const& y = id.begin();
98  for (; x != this->end(); ++x, ++y) {
99  zx = (*x).complex_float();
100  zy = (*y).complex_float();
101  sx += std::abs(zx*zx);
102  sy += std::abs(zy*zy);
103  zx -= zy;
104  s += std::abs(zx*zx);
105  }
106  float t = std::max(sx, sy);
107  bool same = (s <= 1e-6*t);
108  return same;
109  }
110  virtual bool operator!=(const ImageData& id) const
111  {
112  return !(*this == id);
113  }
115  std::shared_ptr<const VoxelisedGeometricalInfo3D > get_geom_info_sptr() const
116  {
117  // If the geometrical info has not been created yet, throw an error
118  if (!_geom_info_sptr)
119  throw std::runtime_error("Geometrical info not initialised. This implies that"
120  " your constructor did not call set_up_geom_info() or there was "
121  "an error. Build in debug mode and lookout for any printed text "
122  "containing '::set_up_geom_info()'.");
123  return _geom_info_sptr;
124  }
126  std::unique_ptr<ImageData> clone() const
127  {
128  return std::unique_ptr<ImageData>(this->clone_impl());
129  }
131  virtual bool is_complex() const { return false; }
133  virtual void reorient(const VoxelisedGeometricalInfo3D &);
135  static bool can_reorient(const VoxelisedGeometricalInfo3D &geom_1, const VoxelisedGeometricalInfo3D &geom_2, const bool throw_error);
137  virtual void set_up_geom_info() = 0;
138  protected:
140  virtual ImageData* clone_impl() const = 0;
142  void set_geom_info(const std::shared_ptr<VoxelisedGeometricalInfo3D> geom_info_sptr) { _geom_info_sptr = geom_info_sptr; }
143  private:
144  std::shared_ptr<VoxelisedGeometricalInfo3D> _geom_info_sptr;
145  };
146 }
147 
148 #endif
Definition: ImageData.h:37
Definition: GeometricalInfo.h:49
virtual void set_up_geom_info()=0
Populate the geometrical info metadata (from the image&#39;s own metadata)
virtual bool operator==(const ImageData &id) const
Write image to file.
Definition: ImageData.h:83
Definition: ImageData.h:52
virtual bool is_complex() const
Is complex? Unless overwridden (Gadgetron), assume not complex.
Definition: ImageData.h:131
virtual ImageData * clone_impl() const =0
Clone helper function. Don&#39;t use.
std::unique_ptr< ImageData > clone() const
Clone and return as unique pointer.
Definition: ImageData.h:126
Definition: ImageData.h:44
virtual void reorient(const VoxelisedGeometricalInfo3D &)
Reorient image. Requires that dimesions and spacing match.
Definition: ImageData.cpp:25
Definition: ANumRef.h:53
Abstract data container.
Definition: GeometricalInfo.cpp:141
void set_geom_info(const std::shared_ptr< VoxelisedGeometricalInfo3D > geom_info_sptr)
Set geom info.
Definition: ImageData.h:142
Definition: GeometricalInfo.h:32
Definition: DataContainer.h:41
static bool can_reorient(const VoxelisedGeometricalInfo3D &geom_1, const VoxelisedGeometricalInfo3D &geom_2, const bool throw_error)
Can reorient? (check dimensions and spacing)
Definition: ImageData.cpp:30
std::shared_ptr< const VoxelisedGeometricalInfo3D > get_geom_info_sptr() const
Get geometrical info.
Definition: ImageData.h:115