00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef IMAGE_STATE_SPATIAL_DOMAIN_HH
00026 #define IMAGE_STATE_SPATIAL_DOMAIN_HH
00027
00028 #include <iostream>
00029
00030 #include <ost/base.hh>
00031 #include <ost/img/point.hh>
00032 #include <ost/img/size.hh>
00033 #include <ost/img/extent.hh>
00034 #include <ost/img/pixel_sampling.hh>
00035 #include <ost/img/value_util.hh>
00036 #include "value_holder.hh"
00037 #include "index.hh"
00038
00039 namespace ost { namespace img { namespace image_state {
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 class DLLEXPORT_OST_IMG_BASE SpatialDomain {
00050 public:
00051 SpatialDomain(const Extent& e):
00052 extent_(e),
00053 physical_extent_(ExtractPhysicalExtent(e))
00054 {}
00055
00056
00057 DataDomain GetDomain() const {return SPATIAL;}
00058
00059 void SetSpatialOrigin(const Point& o) {
00060 extent_=Extent(o,extent_.GetSize());
00061 }
00062
00063 Point GetSpatialOrigin() const {
00064 return extent_.GetStart();
00065 }
00066
00067 Extent GetExtent() const {
00068 return extent_;
00069 }
00070
00071 Extent GetLogicalExtent() const {
00072 return extent_;
00073 }
00074
00075 Extent GetPhysicalExtent() const {
00076 return physical_extent_;
00077 }
00078
00079 template <typename V>
00080 Real GetReal(const Point &p, const ValueHolder<V>& data) const {
00081 if(extent_.Contains(p)) {
00082 return Val2Val<V,Real>(data.Value(Point2Index(p)));
00083 } else {
00084 return 0.0;
00085 }
00086 }
00087
00088 template <typename V>
00089 void SetReal(const Point &p, const Real& r, ValueHolder<V>& data) {
00090 if(extent_.Contains(p)) {
00091 data.Value(Point2Index(p))=Val2Val<Real,V>(r);
00092 }
00093 }
00094
00095 template <typename V>
00096 Complex GetComplex(const Point &p, const ValueHolder<V>& data) const {
00097 if(extent_.Contains(p)) {
00098 return Val2Val<V,Complex>(data.Value(Point2Index(p)));
00099 } else {
00100 return Complex(0.0,0.0);
00101 }
00102 }
00103
00104 template <typename V>
00105 void SetComplex(const Point &p, const Complex& c, ValueHolder<V>& data) {
00106 if(extent_.Contains(p)) {
00107 data.Value(Point2Index(p))=Val2Val<Complex,V>(c);
00108 }
00109 }
00110
00111 Index Point2Index(const Point& p) const {
00112 return Index(p[0]-extent_.GetStart()[0],
00113 p[1]-extent_.GetStart()[1],
00114 p[2]-extent_.GetStart()[2]);
00115 }
00116
00117 private:
00118 Extent extent_;
00119 Extent physical_extent_;
00120
00121 Extent ExtractPhysicalExtent(const Extent& e) const {
00122 #if 1
00123 Point pad;
00124 if(e.GetDim()==1) {
00125 pad=Point( (e.GetSize()[0]&0x1) ? 1 : 2,0,0);
00126 } else if(e.GetDim()==2) {
00127 pad=Point(0,(e.GetSize()[1]&0x1) ? 1 : 2,0);
00128 } else {
00129 pad=Point(0,0,(e.GetSize()[2]&0x1) ? 1 : 2);
00130 }
00131 return Extent(e.GetStart(),e.GetEnd()+pad);
00132 #else
00133 return Extent(e.GetStart(),e.GetEnd());
00134 #endif
00135 }
00136 };
00137
00138 }}}
00139
00140 #endif