OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
image_state_spatial_domain.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  Author: Ansgar Philippsen
23 */
24 
25 #ifndef IMAGE_STATE_SPATIAL_DOMAIN_HH
26 #define IMAGE_STATE_SPATIAL_DOMAIN_HH
27 
28 #include <iostream>
29 
30 #include <ost/base.hh>
31 #include <ost/img/point.hh>
32 #include <ost/img/size.hh>
33 #include <ost/img/extent.hh>
35 #include <ost/img/value_util.hh>
36 #include "value_holder.hh"
37 #include "index.hh"
38 
39 namespace ost { namespace img { namespace image_state {
40 
41 /*
42  while all domain implementations share a common interface
43  they should be seen as policy classes, used as a template
44  parameter, and thus are not derived from a common base class.
45 
46  copy ctor and assignment op should work automatically
47 */
48 
50 public:
51  SpatialDomain(const Extent& e):
52  extent_(e)
53  {}
54 
55  // interface for ImageStateImpl
56  DataDomain GetDomain() const {return SPATIAL;}
57 
58  void SetSpatialOrigin(const Point& o) {
59  extent_=Extent(o,extent_.GetSize());
60  }
61 
63  return extent_.GetStart();
64  }
65 
66  Extent GetExtent() const {
67  return extent_;
68  }
69 
71  return extent_;
72  }
73 
75  return extent_;
76  }
77 
78  template <typename V>
79  Real GetReal(const Point &p, const ValueHolder<V>& data) const {
80  if(extent_.Contains(p)) {
81  return Val2Val<V,Real>(data.Value(Point2Index(p)));
82  } else {
83  return 0.0;
84  }
85  }
86 
87  template <typename V>
88  void SetReal(const Point &p, const Real& r, ValueHolder<V>& data) {
89  if(extent_.Contains(p)) {
90  data.Value(Point2Index(p))=Val2Val<Real,V>(r);
91  }
92  }
93 
94  template <typename V>
95  Complex GetComplex(const Point &p, const ValueHolder<V>& data) const {
96  if(extent_.Contains(p)) {
97  return Val2Val<V,Complex>(data.Value(Point2Index(p)));
98  } else {
99  return Complex(0.0,0.0);
100  }
101  }
102 
103  template <typename V>
104  void SetComplex(const Point &p, const Complex& c, ValueHolder<V>& data) {
105  if(extent_.Contains(p)) {
106  data.Value(Point2Index(p))=Val2Val<Complex,V>(c);
107  }
108  }
109 
110  Index Point2Index(const Point& p) const {
111  Point start=extent_.GetStart();
112  return Index(p[0]-start[0],
113  p[1]-start[1],
114  p[2]-start[2]);
115  }
116 
117 private:
118  Extent extent_;
119 
120 };
121 
122 }}} // ns
123 
124 #endif
DataDomain
underlying data type
Definition: data_types.hh:42
float Real
Definition: base.hh:44
std::complex< Real > Complex
Definition: base.hh:51
V & Value(const Index &i)
return direct r/w access to the value without boundary check
Defines lower and upper valid indices.
Definition: extent.hh:60
void SetComplex(const Point &p, const Complex &c, ValueHolder< V > &data)
void SetReal(const Point &p, const Real &r, ValueHolder< V > &data)
Complex GetComplex(const Point &p, const ValueHolder< V > &data) const
class encapsulating 1D to 3D point
Definition: point.hh:43
#define DLLEXPORT_OST_IMG_BASE
Real GetReal(const Point &p, const ValueHolder< V > &data) const