OpenStructure
image_state_impl.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  Authors: Ansgar Philippsen, Andreas Schenk
23 */
24 
25 #ifndef IMAGE_STATE_IMPL_HH
26 #define IMAGE_STATE_IMPL_HH
27 
28 #include <iostream>
29 #include <boost/shared_ptr.hpp>
30 
31 #include <ost/base.hh>
32 #include <ost/img/value_util.hh>
34 
35 #include "image_state_base.hh"
37 #include "value_holder.hh"
38 
39 namespace ost { namespace img {
40 
41 class Size;
42 
43 namespace image_state {
44 
45 /*
46  Provides concrete implementation of abstract
47  ImageStateBase interface. The two template
48  parameters allow a combination of value
49  and domain to be specified, which is
50  utilized in the image state algorithms
51  as well as the binary dispatch code.
52 
53  Internally, the ValueHolder and Domain interplay
54  to provide the functionality
55 
56 */
57 // \internal
58 template <typename T, class D>
59 class TEMPLATE_EXPORT ImageStateImpl: public ImageStateBase
60 {
61 public:
63  typedef boost::shared_ptr<ImageStateImpl<T,D> > SharedPtrType;
64 
66 
68 
70 
71  // requires logical extent, not physical one!
72  ImageStateImpl(const Extent& e, const PixelSampling& s);
73 
74  // also takes absolute center, requires logical extent, not physical one!
75  ImageStateImpl(const Extent& e, const PixelSampling& s, const Vec3& c);
76 
77  virtual ~ImageStateImpl();
78 
79  SharedPtrType CloneState(bool cc=true) const;
80 
81  // image state base interface
82  virtual ImageStateBasePtr Clone(bool cc=true) const;
83 
84  virtual std::size_t MemSize() const;
85 
86  virtual DataType GetType() const;
87 
88  virtual DataDomain GetDomain() const;
89 
90  virtual void SetSpatialOrigin(const Point& o);
91 
92  virtual void CenterSpatialOrigin();
93 
94  virtual Point GetSpatialOrigin() const;
95 
96  virtual Extent GetExtent() const;
97 
98  virtual Extent GetLogicalExtent() const;
99 
100  virtual Real GetReal(const Point &p) const;
101 
102  virtual void SetReal(const Point &p, const Real& r);
103 
104  virtual Complex GetComplex(const Point &p) const;
105 
106  virtual void SetComplex(const Point &p, const Complex& c);
107 
108  virtual Real GetIntpolReal(const Vec3 &v) const;
109  virtual Real GetIntpolReal(const Vec2 &v) const;
110  virtual Real GetIntpolReal(const Real &d) const;
111 
112  virtual Complex GetIntpolComplex(const Vec3 &v) const;
113  virtual Complex GetIntpolComplex(const Vec2 &v) const;
114  virtual Complex GetIntpolComplex(const Real &d) const;
115 
117 
118  virtual const PixelSampling& GetSampling() const;
119 
120  virtual void SetSampling(const PixelSampling& s);
121 
122  virtual Vec3 GetAbsoluteOrigin() const;
123 
124  virtual void SetAbsoluteOrigin(const Vec3& c);
125 
126  virtual Vec3 IndexToCoord(const Point &p) const;
127 
128  virtual Vec3 CoordToIndex(const Vec3& c) const;
129 
130  virtual Vec3 FractionalIndexToCoord(const Vec3 &p) const;
131 
132  void AdjustPhaseOrigin(const Point& p);
133 
134  // value interface
136  // non-virtual member functions
137 
138  // retrieve value at specified point
139  /*
140  First converts point to index using domain policy,
141  then uses ValueHolderType::Value member function to
142  retrieve actual value. No boundary check is performed
143  here, this is the responsibility of the caller!
144  */
145  T& Value(const Point& p)
146  {
147  assert(domain_.GetExtent().Contains(p));
148  return data_.Value(domain_.Point2Index(p));
149  }
150 
151  // retrieve ro value at specified point
152  const T& Value(const Point& p) const
153  {
154  assert(domain_.GetExtent().Contains(p));
155  return data_.Value(domain_.Point2Index(p));
156  }
157 
159  T GetCheckedValue(const Point& p) const;
160 
162  void SetCheckedValue(const Point& p, const T& v);
163 
164  // calculate interpolated value at given point
165  /*
166  out-of-bounds values are automatically set to zero
167  */
168  T CalcIntpolValue(const Vec3& v) const;
169  T CalcIntpolValue(const Vec2& v) const;
170  T CalcIntpolValue(const Real& v) const;
171 
172  // pass-through to value holder
173  T& Value(const Index& i);
174 
175  // pass-through to value holder
176  const T& Value(const Index& i) const;
177 
178  // pass-through to value holder
179  T& Value(std::size_t i);
180 
181  // pass-through to value holder
182  const T& Value(std::size_t i) const;
183 
187  const ValueHolder<T>& Data() const;
188 
189  // other
190  Size GetSize() const;
191 
192  // visitor interface
193 
194  virtual void ApplyIP(ImageStateNonModVisitorBase& v) const;
195 
196  virtual void Apply(ImageStateNonModVisitorBase& v) const;
197 
199 
200  virtual void ApplyIP(const ImageStateConstModIPVisitorBase& v);
201 
203 
205 
207 
209 
211 
212  // operators
214  virtual ImageStateBase& operator+=(const Complex& v);
216  virtual ImageStateBase& operator-=(const Complex& v);
218  virtual ImageStateBase& operator*=(const Complex& v);
220  virtual ImageStateBase& operator/=(const Complex& v);
221 
222 protected:
223  // helper methods for operators above
224  template <typename U> void add_scalar(const U& v);
225  template <typename U> void mul_scalar(const U& v);
226 
227 private:
228  D domain_;
229  ValueHolder<T> data_;
230  PixelSampling sampling_;
231  geom::Vec3 absolute_origin_;
232 };
233 
234 
235 }}} // ns
236 
237 #endif
Three dimensional vector class, using Real precision.
Definition: vec3.hh:48
Defines lower and upper valid indices.
Definition: extent.hh:60
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
in-place modifying image state const visitor base class
out-of-place modifying image state const visitor base class
virtual ImageStateBase & operator+=(Real v)
const ValueHolder< T > & Data() const
direct access to value holder
ImageStateImpl(const ImageStateImpl< T, D > &s)
virtual void ApplyIP(ImageStateNonModVisitorBase &v) const
T GetCheckedValue(const Point &p) const
retrieve boundary checked value
virtual ImageStateBase & operator-=(Real v)
virtual ImageStateBase & operator*=(Real v)
virtual void SetComplex(const Point &p, const Complex &c)
set complex value at Point
virtual ImageStateBasePtr Apply(ImageStateMorphVisitorBase &v)
virtual const PixelSampling & GetSampling() const
virtual void SetReal(const Point &p, const Real &r)
set real value at Point
T CalcIntpolValue(const Real &v) const
virtual Complex GetComplex(const Point &p) const
virtual std::size_t MemSize() const
virtual ImageStateBase & operator+=(const Complex &v)
void AdjustPhaseOrigin(const Point &p)
virtual Vec3 FractionalIndexToCoord(const Vec3 &p) const
virtual void Apply(ImageStateNonModVisitorBase &v) const
virtual void SetSampling(const PixelSampling &s)
virtual void ApplyIP(ImageStateModIPVisitorBase &v)
T CalcIntpolValue(const Vec3 &v) const
virtual ImageStateBase & operator/=(const Complex &v)
ImageStateImpl(const Extent &e, const PixelSampling &s)
virtual Complex GetIntpolComplex(const Real &d) const
const T & Value(const Index &i) const
const T & Value(const Point &p) const
T CalcIntpolValue(const Vec2 &v) const
virtual ImageStateBasePtr Apply(const ImageStateConstModIPVisitorBase &v) const
void SetCheckedValue(const Point &p, const T &v)
set boundary checked value
virtual void SetAbsoluteOrigin(const Vec3 &c)
SharedPtrType CloneState(bool cc=true) const
virtual void SetSpatialOrigin(const Point &o)
Set spatial origin.
virtual ImageStateBase & operator-=(const Complex &v)
virtual Vec3 CoordToIndex(const Vec3 &c) const
virtual ImageStateBase & operator*=(const Complex &v)
virtual DataType GetType() const
Retrieve data type: REAL or COMPLEX.
virtual Point GetSpatialOrigin() const
Retrieve spatial origin.
virtual ImageStateBasePtr Apply(ImageStateModIPVisitorBase &v) const
virtual ImageStateBasePtr Apply(ImageStateModOPVisitorBase &v) const
virtual Vec3 IndexToCoord(const Point &p) const
virtual Extent GetLogicalExtent() const
Retrieve logical extent.
boost::shared_ptr< ImageStateImpl< T, D > > SharedPtrType
virtual Real GetReal(const Point &p) const
retrieve value at Point as Real
virtual Complex GetIntpolComplex(const Vec2 &v) const
virtual Extent GetExtent() const
Retrieve Extent.
virtual DataDomain GetDomain() const
Retrieve domain.
ImageStateImpl< T, D > & operator=(const ImageStateImpl< T, D > &s)
ImageStateImpl(const Extent &e, const PixelSampling &s, const Vec3 &c)
virtual Complex GetIntpolComplex(const Vec3 &v) const
virtual PixelSampling & GetSampling()
virtual ImageStateBasePtr Clone(bool cc=true) const
virtual ImageStateBase & operator/=(Real v)
const T & Value(std::size_t i) const
virtual void ApplyIP(const ImageStateConstModIPVisitorBase &v)
virtual Vec3 GetAbsoluteOrigin() const
ValueHolder< T > & Data()
direct access to value holder
virtual ImageStateBasePtr Apply(const ImageStateConstModOPVisitorBase &v) const
virtual Real GetIntpolReal(const Real &d) const
virtual Real GetIntpolReal(const Vec3 &v) const
virtual Real GetIntpolReal(const Vec2 &v) const
in-place modifying image state visitor base class
out-of-place modifying image state visitor base class
morphing image state visitor base class
non-modifying image state visitor base class
float Real
Definition: base.hh:44
std::complex< Real > Complex
Definition: base.hh:51
boost::shared_ptr< ImageStateBase > ImageStateBasePtr
DataDomain
underlying data type
Definition: data_types.hh:42
Definition: base.dox:1