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_HALF_FREQUENCY_DOMAIN_HH
00026 #define IMAGE_STATE_HALF_FREQUENCY_DOMAIN_HH
00027
00028 #include <ost/base.hh>
00029 #include <ost/img/point.hh>
00030 #include <ost/img/size.hh>
00031 #include <ost/img/extent.hh>
00032 #include <ost/img/pixel_sampling.hh>
00033
00034 #include "value_holder.hh"
00035 #include "index.hh"
00036
00037 #define CONJPOINT(a) ((a)[2]==0 ?((a)[1]==0?(a)[0]>0:(a)[1]>0):(a)[2]>0) ? (a) : -(a)
00038
00039 namespace ost { namespace img { namespace image_state {
00040
00041 namespace {
00042
00043 int half_pos(int d)
00044 {
00045 return (d&0x1) ? (d-1)/2 : d/2;
00046 }
00047
00048 int half_neg(int d)
00049 {
00050 return (d&0x1) ? -((d-1)/2) : -(d/2-1);
00051 }
00052
00053 }
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 class DLLEXPORT_OST_IMG_BASE HalfFrequencyDomain {
00105 public:
00106 HalfFrequencyDomain(const Extent& e):
00107 logical_extent_(ExtractLogicalExtent(e)),
00108 physical_extent_(ExtractPhysicalExtent(e)),
00109 dim_(e.GetDim()),
00110 spat_ori_()
00111 {
00112 assert(dim_>=1 && dim_<=3);
00113 }
00114
00115 DataDomain GetDomain() const {return HALF_FREQUENCY;}
00116
00117 void SetSpatialOrigin(const Point& o) {spat_ori_=o;}
00118
00119 Point GetSpatialOrigin() const {return spat_ori_;}
00120
00121
00122 Extent GetExtent() const {return physical_extent_;}
00123
00124 Extent GetLogicalExtent() const { return logical_extent_;}
00125
00126 Extent GetPhysicalExtent() const { return physical_extent_;}
00127
00128 template <typename V>
00129 Real GetReal(const Point &p, const ValueHolder<V>& data) const {
00130 if(logical_extent_.Contains(p)) {
00131 return Val2Val<V,Real>(data.Value(Point2Index(CONJPOINT(p))));
00132 }
00133 return Real();
00134 }
00135
00136 template <typename V>
00137 void SetReal(const Point &p, const Real& r, ValueHolder<V>& data) {
00138 if(logical_extent_.Contains(p)) {
00139 Point cp=CONJPOINT(p);
00140 if(cp==p){
00141 data.Value(Point2Index(cp))=Val2Val<Real,V>(r);
00142 }
00143 }
00144 }
00145
00146 template <typename V>
00147 Complex GetComplex(const Point &p, const ValueHolder<V>& data) const {
00148 if(logical_extent_.Contains(p)) {
00149 Point cp=CONJPOINT(p);
00150 if(cp==p){
00151 return Val2Val<V,Complex>(data.Value(Point2Index(cp)));
00152 }else{
00153 return conj(Val2Val<V,Complex>(data.Value(Point2Index(cp))));
00154 }
00155 }
00156 return Complex();
00157 }
00158
00159 template <typename V>
00160 void SetComplex(const Point &p, const Complex& c, ValueHolder<V>& data) {
00161 if(logical_extent_.Contains(p)) {
00162 Point cp=CONJPOINT(p);
00163 if(cp==p){
00164 data.Value(Point2Index(cp))=Val2Val<Complex,V>(c);
00165 }
00166 }
00167 }
00168
00169 Index Point2Index(const Point& p) const {
00170 const Size& size=physical_extent_.GetSize();
00171 return Index(p[0]>=0?p[0]:size[0]+p[0],
00172 p[1]>=0?p[1]:size[1]+p[1],
00173 p[2]);
00174 }
00175
00176 Extent ExtractLogicalExtent(const Extent& e) const {
00177 #if 1
00178 return Extent(Point(half_neg(e.GetWidth()),half_neg(e.GetHeight()),half_neg(e.GetDepth())),
00179 Point(half_pos(e.GetWidth()),half_pos(e.GetHeight()),half_pos(e.GetDepth())));
00180 #else
00181
00182 if(e.GetDim()==1) {
00183 return Extent(Point(half_neg(e.GetWidth())),Point(half_pos(e.GetWidth())));
00184 } else if(e.GetDim()==2) {
00185 return Extent(Point(half_neg(e.GetWidth()),half_neg(e.GetHeight())),
00186 Point(half_pos(e.GetWidth()),half_pos(e.GetHeight())));
00187 } else {
00188 return Extent(Point(half_neg(e.GetWidth()),half_neg(e.GetHeight()),half_neg(e.GetDepth())),
00189 Point(half_pos(e.GetWidth()),half_pos(e.GetHeight()),half_pos(e.GetDepth())));
00190 }
00191 #endif
00192 }
00193
00194 Extent ExtractPhysicalExtent(const Extent& e) const {
00195 if(e.GetDim()==1) {
00196 return Extent(Point(0),Point(half_pos(e.GetWidth())));
00197 } else if(e.GetDim()==2) {
00198 return Extent(Point(half_neg(e.GetWidth()),0,0),
00199 Point(half_pos(e.GetWidth()),half_pos(e.GetHeight()),0));
00200 } else {
00201 return Extent(Point(half_neg(e.GetWidth()),half_neg(e.GetHeight()),0),
00202 Point(half_pos(e.GetWidth()),half_pos(e.GetHeight()),half_pos(e.GetDepth())));
00203 }
00204 }
00205
00206 private:
00207 Extent logical_extent_;
00208 Extent physical_extent_;
00209 int dim_;
00210 Point spat_ori_;
00211
00212 };
00213
00214
00215
00216 }}}
00217
00218 #endif