OpenStructure
data.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 // Copyright (C) 2003-2010 by the IPLT authors
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 3.0 of the License, or (at your option)
10 // any later version.
11 // This library is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 // details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this library; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //------------------------------------------------------------------------------
20 
21 /*
22  abstract base class for generic data
23 
24  Author: Ansgar Philippsen
25 */
26 
27 #ifndef IMG_DATA_H
28 #define IMG_DATA_H
29 
30 #include <cmath>
31 
32 #include <boost/shared_ptr.hpp>
33 
34 #include <ost/img/module_config.hh>
35 #include <ost/base.hh>
36 #include "point.hh"
37 #include "extent.hh"
38 #include "data_types.hh"
39 #include "extent_iterator.hh"
40 #include "vecmat.hh"
41 
42 
43 namespace ost { namespace img {
44 
45 
46 //using namespace info;
47 
48 // forward declaration
49 class NonModAlgorithm;
50 class ModIPAlgorithm;
51 class DataObserver;
52 class PixelSampling;
53 class ImageHandle;
54 
56 
71 public:
76  virtual ~ConstData();
78 
83  virtual DataType GetType() const = 0;
84 
86  virtual DataDomain GetDomain() const = 0;
87 
89 
92  bool IsSpatial() const {return GetDomain()==SPATIAL;}
93 
95 
98  bool IsFrequency() const {
99  return GetDomain()==FREQUENCY || GetDomain()==HALF_FREQUENCY;
100  }
101 
103 
106  bool IsReal() const {return GetType()==REAL;}
107 
109 
112  bool IsComplex() const {return GetType()==COMPLEX;}
113 
115  virtual Extent GetExtent() const = 0;
116 
118  virtual Point GetSpatialOrigin() const = 0;
119 
121 
124  Size GetSize() const {return GetExtent().GetSize();}
125 
127 
134  virtual Real GetReal(const Point &p) const = 0;
135 
137  virtual Complex GetComplex(const Point &p) const = 0;
138 
140  virtual Real GetIntpolReal(const Vec3 &v) const = 0;
141  virtual Real GetIntpolReal(const Vec2 &v) const = 0;
142  virtual Real GetIntpolReal(const Real &d) const = 0;
143 
145  virtual Complex GetIntpolComplex(const Vec3 &v) const = 0;
146  virtual Complex GetIntpolComplex(const Vec2 &v) const = 0;
147  virtual Complex GetIntpolComplex(const Real &d) const = 0;
148 
149 
155  /*
156  Only a NonModAlgorithm can be applied to a Data instance,
157  the Mod IP/OP variants are part of the ImageHandle interface
158  */
159  virtual void Apply(NonModAlgorithm& a) const = 0;
160  virtual void ApplyIP(NonModAlgorithm& a) const=0;
162 
163 
168  virtual void Attach(DataObserver *o) const = 0;
169 
171  virtual void Detach(DataObserver *o) const = 0;
172 
174  virtual void Notify() const = 0;
176 
181  virtual Real OverallDifference(const ConstData& d) const;
182  virtual Real NormDifference(const ConstData& d) const;
184 
185 
195 
197  Vec3 GetPixelSampling() const;
198 
200  Vec3 GetSpatialSampling() const;
201 
203  Vec3 GetFrequencySampling() const;
204 
205  // Index to coordinate conversion
206  /*
207  Returns the physical dimensions of a given Point based on
208  the sampling of the current domain.
209  */
210  //Vec3 IndexToCoord(const Point &p) const;
211 
212  // Convert coordinates back to (fractional) indices
213  /*
214  Returns the location within the Data that corresponds to
215  the given physical coordinate.
216  */
217  //Vec3 CoordToIndex(const Vec3& c) const;
219 
220 
221 
222  protected:
223  ConstData(const ConstData& d);
225 
231  virtual PixelSampling& Sampling() = 0;
232  virtual const PixelSampling& Sampling() const = 0;
234 
236  void CalcIntpolWeights(Vec3 v, Real w[8], Point p[8]) const;
237 
238 private:
239 
240 };
241 
242 
244 
254 public:
258  Data();
259  virtual ~Data();
261 
262 
267  virtual void SetSpatialOrigin(const Point& o) = 0;
269 
273 
274  void SetPixelSampling(const Vec3&);
276  void SetPixelSampling(Real d) {SetPixelSampling(Vec3(d,d,d));}
278  void SetSpatialSampling(const Vec3&);
281 
282  virtual void Apply(NonModAlgorithm& a) const=0;
283  virtual void ApplyIP(NonModAlgorithm& a) const=0;
284 
285  protected:
286  Data(const Data& d);
287  Data& operator=(const Data& d);
288 };
289 
290 
291 
292 }} // namespace img
293 
294 #endif
Abstract base class for read-only data.
Definition: data.hh:70
virtual PixelSampling & Sampling()=0
bool IsComplex() const
Returns true if data is currently of complex type.
Definition: data.hh:112
ConstData(const ConstData &d)
virtual Real OverallDifference(const ConstData &d) const
virtual Point GetSpatialOrigin() const =0
Retrieve spatial origin.
bool IsFrequency() const
Returns true if data is currently in frequency domain.
Definition: data.hh:98
virtual void Apply(NonModAlgorithm &a) const =0
Algorithm interface: NonModAlgorithm.
virtual void Detach(DataObserver *o) const =0
DataObserver interface: detach observer.
virtual Complex GetIntpolComplex(const Vec3 &v) const =0
Get interpolated complex value from 3D,2D or 1D vec.
void CalcIntpolWeights(Vec3 v, Real w[8], Point p[8]) const
implements interpolation
virtual Extent GetExtent() const =0
Return (logical) extent of data.
virtual Real NormDifference(const ConstData &d) const
Vec3 GetSpatialSampling() const
return spatial pixel dimensions
virtual Complex GetComplex(const Point &p) const =0
Get explicit complex value.
virtual Real GetIntpolReal(const Vec3 &v) const =0
Get interpolated real value from 3D,2D or 1D vec.
virtual Real GetIntpolReal(const Vec2 &v) const =0
virtual const PixelSampling & Sampling() const =0
Vec3 GetFrequencySampling() const
return frequency pixel dimensions
ConstData & operator=(const ConstData &d)
virtual Real GetIntpolReal(const Real &d) const =0
virtual void Notify() const =0
Notify each observer that state has changed.
bool IsReal() const
Returns true if data is currently of real type.
Definition: data.hh:106
virtual void Attach(DataObserver *o) const =0
DataObserver interface: attach observer.
Size GetSize() const
Return Size.
Definition: data.hh:124
virtual Real GetReal(const Point &p) const =0
Get explicit real value.
bool IsSpatial() const
Returns true if data is currently in spatial domain.
Definition: data.hh:92
virtual DataDomain GetDomain() const =0
Return domain: SPATIAL, FREQUENCY or HALF_FREQUENCY.
virtual Complex GetIntpolComplex(const Real &d) const =0
virtual void ApplyIP(NonModAlgorithm &a) const =0
Vec3 GetPixelSampling() const
return pixel sampling of the current domain
virtual Complex GetIntpolComplex(const Vec2 &v) const =0
virtual DataType GetType() const =0
Return type of data: REAL or COMPLEX.
Abstract base class for data.
Definition: data.hh:253
void SetPixelSampling(Real d)
Set uniform pixel dimensions of the current domain.
Definition: data.hh:276
virtual void Apply(NonModAlgorithm &a) const =0
Algorithm interface: NonModAlgorithm.
void SetPixelSampling(const Vec3 &)
void SetSpatialSampling(const Vec3 &)
set spatial pixel dimensions (non-uniform)
virtual ~Data()
Data(const Data &d)
virtual void SetSpatialOrigin(const Point &o)=0
Set the spatial origin.
virtual void ApplyIP(NonModAlgorithm &a) const =0
void SetSpatialSampling(Real d)
set spatial pixel dimensions (uniform)
Definition: data.hh:280
Data & operator=(const Data &d)
Abstract base class of data observer.
Defines lower and upper valid indices.
Definition: extent.hh:60
Non-modifying Algorithm, abstract base class.
Helper class to handle pixel sampling.
class encapsulating 1D to 3D point
Definition: point.hh:47
class encapsulating 1D to 3D size
Definition: size.hh:39
#define DLLEXPORT_OST_IMG_BASE
float Real
Definition: base.hh:44
std::complex< Real > Complex
Definition: base.hh:51
DataDomain
underlying data type
Definition: data_types.hh:42
@ HALF_FREQUENCY
Definition: data_types.hh:44
Definition: base.dox:1