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
00026
00027
00028
00029 #ifndef IMG_IMAGE_HANDLE_H
00030 #define IMG_IMAGE_HANDLE_H
00031
00032 #include <boost/shared_ptr.hpp>
00033
00034 #include <ost/img/module_config.hh>
00035 #include <ost/message.hh>
00036 #include <ost/base.hh>
00037
00038 #include "data.hh"
00039 #include "observable.hh"
00040 #include "extent_iterator.hh"
00041
00042 #include "image_state/image_state_visitor_fw.hh"
00043 #include "image_state/image_state_base_fw.hh"
00044
00045 #include <ost/img/module_config.hh>
00046
00047 namespace test_image {
00048 void test_Observer();
00049 }
00050
00051 namespace ost { namespace img {
00052
00053 using image_state::ImageStateBase;
00054 using image_state::ImageStateBasePtr;
00055 using image_state::ImageStateNonModVisitorBase;
00056 using image_state::ImageStateModIPVisitorBase;
00057 using image_state::ImageStateConstModIPVisitorBase;
00058 using image_state::ImageStateModOPVisitorBase;
00059 using image_state::ImageStateConstModOPVisitorBase;
00060 using image_state::ImageStateMorphVisitorBase;
00061
00062
00063 class Point;
00064 class Extent;
00065 class Size;
00066 class NonModAlgorithm;
00067 class ModIPAlgorithm;
00068 class ConstModIPAlgorithm;
00069 class ModOPAlgorithm;
00070 class ConstModOPAlgorithm;
00071 class DataObserver;
00072
00074 class DLLEXPORT InvalidImageHandle: public Error {
00075 public:
00076 InvalidImageHandle(): Error("Attempt to use invalid ImageHandle") {}
00077 };
00078
00079
00080 class ConstImageHandle;
00081
00083
00111 class DLLEXPORT_OST_IMG_BASE ImageHandle: public Data {
00112 friend ImageHandle DoCreateImage(const Extent& e, DataType type, DataDomain dom);
00113
00114
00115 friend void test_image::test_Observer();
00116
00117
00118 friend class ConstImageHandle;
00119
00120 typedef Observable DataObservable;
00121 typedef boost::shared_ptr<DataObservable> ObsPtr;
00122
00123 typedef boost::shared_ptr<ImageStateBasePtr> StatePtrPtr;
00124
00125 public:
00127
00132 ImageHandle();
00133
00135
00138 ImageHandle(const ImageHandle& h);
00139
00141
00145 ImageHandle& operator=(const ImageHandle& h);
00146
00148
00149
00153 ImageHandle Copy(bool cc=true) const;
00154
00156
00160 ImageHandle Extract(const Extent& e) const;
00161
00163
00169 void Paste(const Data& d);
00170
00172
00179 void Set(const ImageHandle& h);
00180
00182 void Swap(ImageHandle& h);
00183
00185
00193 void Reset(const Extent &e, DataType type=REAL,DataDomain dom=SPATIAL);
00194
00196 bool IsValid() const;
00197
00199 long MemSize() const;
00201
00202
00206
00207 virtual DataType GetType() const;
00208
00210 virtual DataDomain GetDomain() const;
00211
00213
00216 virtual Extent GetExtent() const;
00217
00219
00224 virtual Point GetSpatialOrigin() const;
00225
00227
00228
00229
00230
00231 void SetSpatialOrigin(const Point& p);
00232
00234
00235
00236
00237
00238
00239
00240
00241 void CenterSpatialOrigin();
00243
00245
00246
00247
00248
00249 Vec3 GetAbsoluteOrigin() const;
00250
00252
00253
00254
00255
00256 void SetAbsoluteOrigin(const Vec3& c) ;
00257
00259
00260
00261
00262
00263
00264 Vec3 IndexToCoord(const Point &p) const;
00265
00267
00268
00269
00270
00271
00272
00273 Vec3 CoordToIndex(const Vec3& c) const;
00274
00276
00277
00278
00279
00280
00281
00282 Vec3 FractionalIndexToCoord(const Vec3 &p) const;
00283
00290
00291 virtual Real GetReal(const Point& p) const;
00292
00295 void SetReal(const Point &p, Real r);
00296
00298 virtual Complex GetComplex(const Point& p) const;
00299
00301 void SetComplex(const Point &p, const Complex& c);
00303
00305 virtual Real GetIntpolReal(const Vec3 &v) const;
00306 virtual Real GetIntpolReal(const Vec2 &v) const;
00307 virtual Real GetIntpolReal(const Real &d) const;
00308
00310 virtual Complex GetIntpolComplex(const Vec3 &v) const;
00311 virtual Complex GetIntpolComplex(const Vec2 &v) const;
00312 virtual Complex GetIntpolComplex(const Real &d) const;
00313
00314
00315
00320
00321 virtual void Attach(DataObserver *o) const;
00322
00324 virtual void Detach(DataObserver *o) const;
00325
00327 virtual void Notify() const;
00328 virtual void Notify(const Extent& e) const;
00329 virtual void Notify(const Point& p) const;
00330
00331
00338
00340
00343 void Apply(NonModAlgorithm& a) const;
00344
00346
00350 void ApplyIP(NonModAlgorithm& a) const;
00351
00353 void ApplyIP(ModIPAlgorithm& a);
00354
00356
00360 ImageHandle Apply(ModIPAlgorithm& a) const;
00361
00363 void ApplyIP(const ConstModIPAlgorithm& a);
00364
00366
00370 ImageHandle Apply(const ConstModIPAlgorithm& a) const;
00371
00373
00379 void ApplyIP(ModOPAlgorithm& a);
00380
00382
00385 ImageHandle Apply(ModOPAlgorithm& a) const;
00386
00388
00394 void ApplyIP(const ConstModOPAlgorithm& a);
00395
00397
00400 ImageHandle Apply(const ConstModOPAlgorithm& a) const;
00402
00403
00409
00410 void StateApply(ImageStateNonModVisitorBase& v) const;
00411
00413 void StateApplyIP(ImageStateModIPVisitorBase& v);
00415 ImageHandle StateApply(ImageStateModIPVisitorBase& v) const;
00417 void StateApplyIP(const ImageStateConstModIPVisitorBase& v);
00419 ImageHandle StateApply(const ImageStateConstModIPVisitorBase& v) const;
00421 void StateApplyIP(ImageStateModOPVisitorBase& v);
00423 ImageHandle StateApply(ImageStateModOPVisitorBase& v) const;
00425 void StateApplyIP(const ImageStateConstModOPVisitorBase& v);
00427 ImageHandle StateApply(const ImageStateConstModOPVisitorBase& v) const;
00429 void StateApplyIP(ImageStateMorphVisitorBase& v);
00431 ImageHandle StateApply(ImageStateMorphVisitorBase& v) const;
00433 ExtentIterator GetIterator() const ;
00434
00436
00442 bool operator==(const ImageHandle& ih) const;
00443 bool operator!=(const ImageHandle& ih) const;
00445
00449 ImageHandle& operator+=(Real v);
00450 ImageHandle& operator+=(const Complex& v);
00451 ImageHandle& operator-=(Real v);
00452 ImageHandle& operator-=(const Complex& v);
00453 ImageHandle& operator*=(Real v);
00454 ImageHandle& operator*=(const Complex& v);
00455 ImageHandle& operator/=(Real v);
00456 ImageHandle& operator/=(const Complex& v);
00457
00458 void Reciproce();
00459
00460 ImageHandle& operator+=(const ConstImageHandle& h);
00461 ImageHandle& operator-=(const ConstImageHandle& h);
00462 ImageHandle& operator*=(const ConstImageHandle& h);
00463 ImageHandle& operator/=(const ConstImageHandle& h);
00464
00466
00470 ImageStateBasePtr& ImageStatePtr();
00471 const ImageStateBasePtr& ImageStatePtr() const;
00473
00474 protected:
00476 ImageHandle(const StatePtrPtr& spp);
00477
00479 virtual PixelSampling& Sampling();
00481 virtual const PixelSampling& Sampling() const;
00482
00484 static ImageHandle Create(const Extent& e, DataType type, DataDomain dom);
00485
00486 private:
00487
00488 StatePtrPtr impl_;
00489 ObsPtr obs_;
00490
00491 bool equal(const ImageHandle& ih) const;
00492 };
00493
00494
00496
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516 class DLLEXPORT_OST_IMG_BASE ConstImageHandle: public ConstData {
00517 friend class ImageHandle;
00518 public:
00520 operator const Data& () const {return handle_;}
00521
00523 ConstImageHandle();
00524
00526
00529 ConstImageHandle(const ConstImageHandle& h);
00530
00532
00536 ConstImageHandle(const ImageHandle& h);
00537
00539
00543 ConstImageHandle& operator=(const ConstImageHandle& h);
00544
00546
00549 ConstImageHandle& operator=(const ImageHandle& h);
00550
00552
00553 ImageHandle Copy(bool cc=true) const;
00554
00556 ImageHandle Extract(const Extent& e) const;
00557
00559 bool IsValid() const;
00560
00562 long MemSize() const;
00564
00568
00569 DataType GetType() const;
00570
00572 DataDomain GetDomain() const;
00573
00575 Extent GetExtent() const;
00576
00578 Point GetSpatialOrigin() const;
00580
00582 Vec3 GetAbsoluteOrigin() const;
00583
00585 Vec3 IndexToCoord(const Point &p) const;
00586
00588 Vec3 CoordToIndex(const Vec3& c) const;
00589
00591 Vec3 FractionalIndexToCoord(const Vec3 &p) const;
00592
00596
00597 Real GetReal(const Point& p) const;
00598
00600 Complex GetComplex(const Point& p) const;
00602
00604 virtual Real GetIntpolReal(const Vec3 &v) const;
00605 virtual Real GetIntpolReal(const Vec2 &v) const;
00606 virtual Real GetIntpolReal(const Real &d) const;
00607
00609 virtual Complex GetIntpolComplex(const Vec3 &v) const;
00610 virtual Complex GetIntpolComplex(const Vec2 &v) const;
00611 virtual Complex GetIntpolComplex(const Real &d) const;
00612
00613
00616
00617 void Attach(DataObserver *o) const;
00618
00620 void Detach(DataObserver *o) const;
00621
00623 void Notify() const;
00624 void Notify(const Extent& e) const;
00625 void Notify(const Point& p) const;
00626
00627
00632
00634 void Apply(NonModAlgorithm& a) const;
00635 void ApplyIP(NonModAlgorithm& a) const;
00636
00638 ImageHandle Apply(ModIPAlgorithm& a) const;
00639
00641 ImageHandle Apply(const ConstModIPAlgorithm& a) const;
00642
00644 ImageHandle Apply(ModOPAlgorithm& a) const;
00645
00647 ImageHandle Apply(const ConstModOPAlgorithm& a) const;
00649
00654
00655 void StateApply(ImageStateNonModVisitorBase& v) const;
00656
00658 ImageHandle StateApply(ImageStateModIPVisitorBase& v) const;
00659
00661 ImageHandle StateApply(const ImageStateConstModIPVisitorBase& v) const;
00662
00664 ImageHandle StateApply(ImageStateModOPVisitorBase& v) const;
00665
00667 ImageHandle StateApply(const ImageStateConstModOPVisitorBase& v) const;
00668
00670 ImageHandle StateApply(ImageStateMorphVisitorBase& v) const;
00672 ExtentIterator GetIterator() const ;
00674
00678 bool operator==(const ConstImageHandle& ih) const;
00679 bool operator==(const ImageHandle& ih) const;
00680 bool operator!=(const ConstImageHandle& ih) const;
00681 bool operator!=(const ImageHandle& ih) const;
00683
00684 const ImageStateBasePtr& ImageStatePtr() const;
00685
00686 protected:
00687
00689 PixelSampling& Sampling();
00691 const PixelSampling& Sampling() const;
00692
00693 private:
00694
00695 ImageHandle handle_;
00696
00697 bool equal(const ConstImageHandle& h) const;
00698 bool equal(const ImageHandle& h) const;
00699 };
00700
00701
00709
00710 DLLEXPORT_OST_IMG_BASE bool operator==(const ImageHandle& lhs, const ConstImageHandle& rhs);
00711 DLLEXPORT_OST_IMG_BASE bool operator!=(const ImageHandle& lhs, const ConstImageHandle& rhs);
00712
00713 DLLEXPORT_OST_IMG_BASE ImageHandle operator+(const ConstImageHandle& h, Real v);
00714 DLLEXPORT_OST_IMG_BASE ImageHandle operator+(const ConstImageHandle& h, const Complex& v);
00715 DLLEXPORT_OST_IMG_BASE ImageHandle operator+(Real v, const ConstImageHandle& h);
00716 DLLEXPORT_OST_IMG_BASE ImageHandle operator+(const Complex& v, const ConstImageHandle& h);
00717 DLLEXPORT_OST_IMG_BASE ImageHandle operator-(const ConstImageHandle& h, Real v);
00718 DLLEXPORT_OST_IMG_BASE ImageHandle operator-(const ConstImageHandle& h, const Complex& v);
00719 DLLEXPORT_OST_IMG_BASE ImageHandle operator-(Real v, const ConstImageHandle& h);
00720 DLLEXPORT_OST_IMG_BASE ImageHandle operator-(const Complex& v, const ConstImageHandle& h);
00721 DLLEXPORT_OST_IMG_BASE ImageHandle operator*(const ConstImageHandle& h, Real v);
00722 DLLEXPORT_OST_IMG_BASE ImageHandle operator*(const ConstImageHandle& h, const Complex& v);
00723 DLLEXPORT_OST_IMG_BASE ImageHandle operator*(Real v, const ConstImageHandle& h);
00724 DLLEXPORT_OST_IMG_BASE ImageHandle operator*(const Complex& v, const ConstImageHandle& h);
00725 DLLEXPORT_OST_IMG_BASE ImageHandle operator/(const ConstImageHandle& h, Real v);
00726 DLLEXPORT_OST_IMG_BASE ImageHandle operator/(const ConstImageHandle& h, const Complex& v);
00727
00728 DLLEXPORT_OST_IMG_BASE ImageHandle operator+(const ConstImageHandle& h1, const ConstImageHandle& h2);
00729 DLLEXPORT_OST_IMG_BASE ImageHandle operator-(const ConstImageHandle& h1, const ConstImageHandle& h2);
00730 DLLEXPORT_OST_IMG_BASE ImageHandle operator*(const ConstImageHandle& h1, const ConstImageHandle& h2);
00731 DLLEXPORT_OST_IMG_BASE ImageHandle operator/(const ConstImageHandle& h1, const ConstImageHandle& h2);
00732
00733
00734 }}
00735
00736 #endif