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 "data_observer.hh"
00041 #include "function.hh"
00042 #include "extent_iterator.hh"
00043
00044 #include "image_state/image_state_visitor_fw.hh"
00045 #include "image_state/image_state_base_fw.hh"
00046
00047 #include <ost/img/module_config.hh>
00048
00049 namespace test_image {
00050 void test_Observer();
00051 }
00052
00053 namespace ost { namespace img {
00054
00055 using image_state::ImageStateBase;
00056 using image_state::ImageStateBasePtr;
00057 using image_state::ImageStateNonModVisitorBase;
00058 using image_state::ImageStateModIPVisitorBase;
00059 using image_state::ImageStateConstModIPVisitorBase;
00060 using image_state::ImageStateModOPVisitorBase;
00061 using image_state::ImageStateConstModOPVisitorBase;
00062 using image_state::ImageStateMorphVisitorBase;
00063
00064
00065 class Point;
00066 class Extent;
00067 class Size;
00068 class NonModAlgorithm;
00069 class ModIPAlgorithm;
00070 class ConstModIPAlgorithm;
00071 class ModOPAlgorithm;
00072 class ConstModOPAlgorithm;
00073
00075 class DLLEXPORT InvalidImageHandle: public Error {
00076 public:
00077 InvalidImageHandle(): Error("Attempt to use invalid ImageHandle") {}
00078 };
00079
00080
00081 class ConstImageHandle;
00082
00084
00112 class DLLEXPORT_OST_IMG_BASE ImageHandle: public Data {
00113 friend ImageHandle DoCreateImage(const Extent& e, DataType type, DataDomain dom);
00114
00115
00116 friend void test_image::test_Observer();
00117
00118
00119 friend class ConstImageHandle;
00120
00121 typedef Observable<DataObserver> DataObservable;
00122 typedef boost::shared_ptr<DataObservable> ObsPtr;
00123
00124 typedef boost::shared_ptr<ImageStateBasePtr> StatePtrPtr;
00125
00126 public:
00128
00133 ImageHandle();
00134
00136
00139 ImageHandle(const ImageHandle& h);
00140
00142
00146 ImageHandle& operator=(const ImageHandle& h);
00147
00149
00150
00154 ImageHandle Copy(bool cc=true) const;
00155
00157 ImageHandle Copy(const Extent& e) const;
00158
00160
00164 ImageHandle Extract(const Extent& e) const;
00165
00167
00173 void Paste(const Data& d);
00174
00176
00183 void Set(const ImageHandle& h);
00184
00186 void Swap(ImageHandle& h);
00187
00189
00197 void Reset(const Extent &e, DataType type=REAL,DataDomain dom=SPATIAL);
00198
00200 bool IsValid() const;
00201
00203 long MemSize() const;
00205
00206
00210
00211 virtual DataType GetType() const;
00212
00214 virtual DataDomain GetDomain() const;
00215
00217
00220 virtual Extent GetExtent() const;
00221
00223
00228 virtual Point GetSpatialOrigin() const;
00229
00231
00232
00233
00234
00235 void SetSpatialOrigin(const Point& p);
00236
00238
00239
00240
00241
00242
00243
00244
00245 void CenterSpatialOrigin();
00247
00249
00250
00251
00252
00253 Vec3 GetAbsoluteOrigin() const;
00254
00256
00257
00258
00259
00260 void SetAbsoluteOrigin(const Vec3& c) ;
00261
00263
00264
00265
00266
00267
00268 Vec3 IndexToCoord(const Point &p) const;
00269
00271
00272
00273
00274
00275
00276
00277 Vec3 CoordToIndex(const Vec3& c) const;
00278
00280
00281
00282
00283
00284
00285
00286 Vec3 FractionalIndexToCoord(const Vec3 &p) const;
00287
00294
00295 virtual Real GetReal(const Point& p) const;
00296
00299 void SetReal(const Point &p, Real r);
00300
00302 virtual Complex GetComplex(const Point& p) const;
00303
00305 void SetComplex(const Point &p, const Complex& c);
00307
00309 virtual Real GetIntpolReal(const Vec3 &v) const;
00310 virtual Real GetIntpolReal(const Vec2 &v) const;
00311 virtual Real GetIntpolReal(const Real &d) const;
00312
00314 virtual Complex GetIntpolComplex(const Vec3 &v) const;
00315 virtual Complex GetIntpolComplex(const Vec2 &v) const;
00316 virtual Complex GetIntpolComplex(const Real &d) const;
00317
00318
00319
00324
00325 virtual void Attach(DataObserver *o) const;
00326
00328 virtual void Detach(DataObserver *o) const;
00329
00331 virtual void Notify() const;
00332 virtual void Notify(const Extent& e) const;
00333 virtual void Notify(const Point& p) const;
00334
00335
00342
00344
00347 void Apply(NonModAlgorithm& a) const;
00348
00350
00354 void ApplyIP(NonModAlgorithm& a) const;
00355
00357 void ApplyIP(ModIPAlgorithm& a);
00358
00360
00364 ImageHandle Apply(ModIPAlgorithm& a) const;
00365
00367 void ApplyIP(const ConstModIPAlgorithm& a);
00368
00370
00374 ImageHandle Apply(const ConstModIPAlgorithm& a) const;
00375
00377
00383 void ApplyIP(ModOPAlgorithm& a);
00384
00386
00389 ImageHandle Apply(ModOPAlgorithm& a) const;
00390
00392
00398 void ApplyIP(const ConstModOPAlgorithm& a);
00399
00401
00404 ImageHandle Apply(const ConstModOPAlgorithm& a) const;
00406
00407
00413
00414 void StateApply(ImageStateNonModVisitorBase& v) const;
00415
00417 void StateApplyIP(ImageStateModIPVisitorBase& v);
00419 ImageHandle StateApply(ImageStateModIPVisitorBase& v) const;
00421 void StateApplyIP(const ImageStateConstModIPVisitorBase& v);
00423 ImageHandle StateApply(const ImageStateConstModIPVisitorBase& v) const;
00425 void StateApplyIP(ImageStateModOPVisitorBase& v);
00427 ImageHandle StateApply(ImageStateModOPVisitorBase& v) const;
00429 void StateApplyIP(const ImageStateConstModOPVisitorBase& v);
00431 ImageHandle StateApply(const ImageStateConstModOPVisitorBase& v) const;
00433 void StateApplyIP(ImageStateMorphVisitorBase& v);
00435 ImageHandle StateApply(ImageStateMorphVisitorBase& v) const;
00437 ExtentIterator GetIterator() const ;
00438
00440
00446 bool operator==(const ImageHandle& ih) const;
00447 bool operator!=(const ImageHandle& ih) const;
00449
00453 ImageHandle& operator+=(Real v);
00454 ImageHandle& operator+=(const Complex& v);
00455 ImageHandle& operator-=(Real v);
00456 ImageHandle& operator-=(const Complex& v);
00457 ImageHandle& operator*=(Real v);
00458 ImageHandle& operator*=(const Complex& v);
00459 ImageHandle& operator/=(Real v);
00460 ImageHandle& operator/=(const Complex& v);
00461
00462 void Reciproce();
00463
00464 ImageHandle& operator+=(const ConstImageHandle& h);
00465 ImageHandle& operator-=(const ConstImageHandle& h);
00466 ImageHandle& operator*=(const ConstImageHandle& h);
00467 ImageHandle& operator/=(const ConstImageHandle& h);
00468
00469 ImageHandle& operator+=(const Function& h);
00470 ImageHandle& operator-=(const Function& h);
00471 ImageHandle& operator*=(const Function& h);
00472 ImageHandle& operator/=(const Function& h);
00473
00475
00479 ImageStateBasePtr& ImageStatePtr();
00480 const ImageStateBasePtr& ImageStatePtr() const;
00482
00483 protected:
00485 ImageHandle(const StatePtrPtr& spp);
00486
00488 virtual PixelSampling& Sampling();
00490 virtual const PixelSampling& Sampling() const;
00491
00493 static ImageHandle Create(const Extent& e, DataType type, DataDomain dom);
00494
00495 private:
00496
00497 StatePtrPtr impl_;
00498 ObsPtr obs_;
00499
00500 bool equal(const ImageHandle& ih) const;
00501 };
00502
00503
00505
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525 class DLLEXPORT_OST_IMG_BASE ConstImageHandle: public ConstData {
00526 friend class ImageHandle;
00527 public:
00529 operator const Data& () const {return handle_;}
00530
00532 ConstImageHandle();
00533
00535
00538 ConstImageHandle(const ConstImageHandle& h);
00539
00541
00545 ConstImageHandle(const ImageHandle& h);
00546
00548
00552 ConstImageHandle& operator=(const ConstImageHandle& h);
00553
00555
00558 ConstImageHandle& operator=(const ImageHandle& h);
00559
00561
00562 ImageHandle Copy(bool cc=true) const;
00563
00565 ImageHandle Copy(const Extent& e) const;
00566
00568 ImageHandle Extract(const Extent& e) const;
00569
00571 bool IsValid() const;
00572
00574 long MemSize() const;
00576
00580
00581 DataType GetType() const;
00582
00584 DataDomain GetDomain() const;
00585
00587 Extent GetExtent() const;
00588
00590 Point GetSpatialOrigin() const;
00592
00594 Vec3 GetAbsoluteOrigin() const;
00595
00597 Vec3 IndexToCoord(const Point &p) const;
00598
00600 Vec3 CoordToIndex(const Vec3& c) const;
00601
00603 Vec3 FractionalIndexToCoord(const Vec3 &p) const;
00604
00608
00609 Real GetReal(const Point& p) const;
00610
00612 Complex GetComplex(const Point& p) const;
00614
00616 virtual Real GetIntpolReal(const Vec3 &v) const;
00617 virtual Real GetIntpolReal(const Vec2 &v) const;
00618 virtual Real GetIntpolReal(const Real &d) const;
00619
00621 virtual Complex GetIntpolComplex(const Vec3 &v) const;
00622 virtual Complex GetIntpolComplex(const Vec2 &v) const;
00623 virtual Complex GetIntpolComplex(const Real &d) const;
00624
00625
00628
00629 void Attach(DataObserver *o) const;
00630
00632 void Detach(DataObserver *o) const;
00633
00635 void Notify() const;
00636 void Notify(const Extent& e) const;
00637 void Notify(const Point& p) const;
00638
00639
00644
00646 void Apply(NonModAlgorithm& a) const;
00647 void ApplyIP(NonModAlgorithm& a) const;
00648
00650 ImageHandle Apply(ModIPAlgorithm& a) const;
00651
00653 ImageHandle Apply(const ConstModIPAlgorithm& a) const;
00654
00656 ImageHandle Apply(ModOPAlgorithm& a) const;
00657
00659 ImageHandle Apply(const ConstModOPAlgorithm& a) const;
00661
00666
00667 void StateApply(ImageStateNonModVisitorBase& v) const;
00668
00670 ImageHandle StateApply(ImageStateModIPVisitorBase& v) const;
00671
00673 ImageHandle StateApply(const ImageStateConstModIPVisitorBase& v) const;
00674
00676 ImageHandle StateApply(ImageStateModOPVisitorBase& v) const;
00677
00679 ImageHandle StateApply(const ImageStateConstModOPVisitorBase& v) const;
00680
00682 ImageHandle StateApply(ImageStateMorphVisitorBase& v) const;
00684 ExtentIterator GetIterator() const ;
00686
00690 bool operator==(const ConstImageHandle& ih) const;
00691 bool operator==(const ImageHandle& ih) const;
00692 bool operator!=(const ConstImageHandle& ih) const;
00693 bool operator!=(const ImageHandle& ih) const;
00695
00696 const ImageStateBasePtr& ImageStatePtr() const;
00697
00698 protected:
00699
00701 PixelSampling& Sampling();
00703 const PixelSampling& Sampling() const;
00704
00705 private:
00706
00707 ImageHandle handle_;
00708
00709 bool equal(const ConstImageHandle& h) const;
00710 bool equal(const ImageHandle& h) const;
00711 };
00712
00713
00721
00722 DLLEXPORT_OST_IMG_BASE bool operator==(const ImageHandle& lhs, const ConstImageHandle& rhs);
00723 DLLEXPORT_OST_IMG_BASE bool operator!=(const ImageHandle& lhs, const ConstImageHandle& rhs);
00724
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 DLLEXPORT_OST_IMG_BASE ImageHandle operator+(Real v, const ConstImageHandle& h);
00728 DLLEXPORT_OST_IMG_BASE ImageHandle operator+(const Complex& v, const ConstImageHandle& h);
00729 DLLEXPORT_OST_IMG_BASE ImageHandle operator-(const ConstImageHandle& h, Real v);
00730 DLLEXPORT_OST_IMG_BASE ImageHandle operator-(const ConstImageHandle& h, const Complex& v);
00731 DLLEXPORT_OST_IMG_BASE ImageHandle operator-(Real v, const ConstImageHandle& h);
00732 DLLEXPORT_OST_IMG_BASE ImageHandle operator-(const Complex& v, const ConstImageHandle& h);
00733 DLLEXPORT_OST_IMG_BASE ImageHandle operator*(const ConstImageHandle& h, Real v);
00734 DLLEXPORT_OST_IMG_BASE ImageHandle operator*(const ConstImageHandle& h, const Complex& v);
00735 DLLEXPORT_OST_IMG_BASE ImageHandle operator*(Real v, const ConstImageHandle& h);
00736 DLLEXPORT_OST_IMG_BASE ImageHandle operator*(const Complex& v, const ConstImageHandle& h);
00737 DLLEXPORT_OST_IMG_BASE ImageHandle operator/(const ConstImageHandle& h, Real v);
00738 DLLEXPORT_OST_IMG_BASE ImageHandle operator/(const ConstImageHandle& h, const Complex& v);
00739
00740 DLLEXPORT_OST_IMG_BASE ImageHandle operator+(const ConstImageHandle& h1, const ConstImageHandle& h2);
00741 DLLEXPORT_OST_IMG_BASE ImageHandle operator-(const ConstImageHandle& h1, const ConstImageHandle& h2);
00742 DLLEXPORT_OST_IMG_BASE ImageHandle operator*(const ConstImageHandle& h1, const ConstImageHandle& h2);
00743 DLLEXPORT_OST_IMG_BASE ImageHandle operator/(const ConstImageHandle& h1, const ConstImageHandle& h2);
00744
00745 DLLEXPORT_OST_IMG_BASE ImageHandle operator+(const ConstImageHandle& h1, const Function& h2);
00746 DLLEXPORT_OST_IMG_BASE ImageHandle operator-(const ConstImageHandle& h1, const Function& h2);
00747 DLLEXPORT_OST_IMG_BASE ImageHandle operator*(const ConstImageHandle& h1, const Function& h2);
00748 DLLEXPORT_OST_IMG_BASE ImageHandle operator/(const ConstImageHandle& h1, const Function& h2);
00749
00750 DLLEXPORT_OST_IMG_BASE ImageHandle operator+(const Function& h1, const ConstImageHandle& h2);
00751 DLLEXPORT_OST_IMG_BASE ImageHandle operator-(const Function& h1, const ConstImageHandle& h2);
00752 DLLEXPORT_OST_IMG_BASE ImageHandle operator*(const Function& h1, const ConstImageHandle& h2);
00753
00754 }}
00755
00756 #endif