OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-2011 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 
69  ImageStateImpl<T,D>& operator=(const ImageStateImpl<T,D>& s);
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 
116  virtual PixelSampling& GetSampling();
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 
185  ValueHolder<T>& Data();
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 
198  virtual void ApplyIP(ImageStateModIPVisitorBase& v);
199 
200  virtual void ApplyIP(const ImageStateConstModIPVisitorBase& v);
201 
202  virtual ImageStateBasePtr Apply(ImageStateModIPVisitorBase& v) const;
203 
204  virtual ImageStateBasePtr Apply(const ImageStateConstModIPVisitorBase& v) const;
205 
206  virtual ImageStateBasePtr Apply(ImageStateModOPVisitorBase& v) const;
207 
208  virtual ImageStateBasePtr Apply(const ImageStateConstModOPVisitorBase& v) const;
209 
211 
212  // operators
213  virtual ImageStateBase& operator+=(Real v);
214  virtual ImageStateBase& operator+=(const Complex& v);
215  virtual ImageStateBase& operator-=(Real v);
216  virtual ImageStateBase& operator-=(const Complex& v);
217  virtual ImageStateBase& operator*=(Real v);
218  virtual ImageStateBase& operator*=(const Complex& v);
219  virtual ImageStateBase& operator/=(Real 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