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
00030
00031
00032
00033
00034
00035
00036
00037
00038
00056 #ifndef __PREGIONH__
00057 #define __PREGIONH__
00058
00059 namespace pandore {
00060
00061
00062 class Reg1d;
00063 class Reg2d;
00064 class Reg3d;
00065
00066
00067
00068
00069
00070
00071 template<>
00072 struct TypeName< Reg1d > {
00077 static std::string Name() {
00078 return "Reg1d";
00079 }
00080 };
00081
00082
00083
00084
00085
00086
00087 template<>
00088 struct TypeName< Reg2d > {
00093 static std::string Name() {
00094 return "Reg2d";
00095 }
00096 };
00097
00098
00099
00100
00101
00102
00103
00104 template<>
00105 struct TypeName< Reg3d > {
00110 static std::string Name() {
00111 return "Reg3d";
00112 }
00113 };
00114
00132 class Reg1d: public Img1d<Long> {
00133 protected:
00135 Long nlabels;
00136
00137 public:
00139 typedef Ulong ValueType;
00140
00145 Typobj Type() const {
00146 return Po_Reg1d;
00147 }
00148
00153 std::string Name() const {
00154 return TypeName< Reg1d >::Name();
00155 }
00156
00161 Ulong Labels() const {
00162 return nlabels;
00163 }
00164
00170 Ulong Labels( Ulong n ) {
00171 return nlabels = n;
00172 }
00173
00178 PobjectProps Props() const {
00179 return PobjectProps(nbands, ncol, 0, 0, (PColorSpace)0, nlabels, nlabels + 1);
00180 }
00181
00185 Reg1d(): Img1d<Long>(), nlabels(0) {}
00186
00193 Reg1d( Long w ): Img1d<Long>(w), nlabels(0) {}
00194
00201 Reg1d( const Dimension1d& d ): Img1d<Long>(d), nlabels(0) {}
00202
00209 Reg1d( const PobjectProps& p ): Img1d<Long>(p.ncol), nlabels(p.nlabels) {}
00210
00216 void New( Long w ) { Img1d<Long>::New(w); nlabels = 0L; }
00217
00223 void New( const Dimension1d& d ) { New(d.w); }
00224
00230 void New( const PobjectProps& p ) {
00231 New(p.ncol);
00232 nlabels = p.nlabels;
00233 }
00234
00238 void Delete () { Img1d<Long>::Delete(); nlabels = 0L; }
00239
00244 Pobject* Clone( ) const {
00245 Reg1d *tmp = new Reg1d(ncol);
00246 *tmp = *this;
00247 return tmp;
00248 }
00249
00254 ValueType* Vector() const {
00255 return (ValueType*)Img1d<Long>::Vector();
00256 }
00257
00263 ValueType& operator[]( Long col ) {
00264 return (ValueType&)Imx1d<Long>::operator[](0)[col];
00265 }
00266
00272 const ValueType& operator[]( Long col ) const {
00273 return (ValueType&)Imx1d<Long>::operator[](0)[col];
00274 }
00275
00281 ValueType& operator()( Long col ) {
00282 return (ValueType&)Imx1d<Long>::operator()(0, col);
00283 }
00284
00290 const ValueType& operator()( Long col ) const {
00291 return (ValueType&)Imx1d<Long>::operator()(0, col);
00292 }
00293
00299 ValueType& operator[]( const Point1d& p ) {
00300 return (ValueType&)Imx1d<Long>::operator[](0)[p.x];
00301 }
00302
00308 const ValueType& operator[]( const Point1d& p ) const {
00309 return (ValueType&)Imx1d<Long>::operator[](0)[p.x];
00310 }
00311
00318 Reg1d& operator=(const Reg1d::ValueType val) {
00319 Img1d<Long>::operator=(val);
00320 nlabels = (val > 0) ? val : 0;
00321 return *this;
00322 }
00323
00329 Reg1d& operator=(const Reg1d &rgs) {
00330 nlabels = rgs.nlabels;
00331 memcpy(Vector(), rgs.Vector(), ncol * sizeof(Reg1d::ValueType));
00332 return *this;
00333 }
00334
00341 Errc LoadAttributes( FILE *file );
00342
00348 Errc SaveAttributes( FILE *file ) const;
00349
00355 Errc LoadData( FILE *file );
00356
00362 Errc SaveData( FILE *file ) const;
00363
00372 Pobject *Mask( const Pobject *mask );
00373
00383 Pobject *UnMask( const Pobject *mask, const Pobject *reference );
00384
00391 Reg1d( const Reg1d &rgs ): Img1d<Long>() {
00392 New(rgs.Props());
00393 *this = rgs;
00394 }
00395 };
00396
00414 class Reg2d: public Img2d<Long> {
00415 public:
00420 class Band1dr {
00421 public:
00422
00429 explicit Band1dr( const Imx3d<Long> * const region, Long *offset ) : _region(region), _offset(offset) {}
00430 Ulong &operator[]( Long x ) {
00431 return (Ulong&)_offset[x];
00432 }
00433 const Ulong &operator[]( Long x ) const {
00434 return (Ulong&)_offset[x];
00435 }
00436 private:
00437 const Imx3d<Long> *_region;
00438 Long *_offset;
00439 };
00440
00441
00443 Ulong nlabels;
00444
00445 public:
00447 typedef Ulong ValueType;
00448
00453 Typobj Type() const {
00454 return Po_Reg2d;
00455 }
00456
00461 std::string Name() const {
00462 return TypeName< Reg2d >::Name();
00463 }
00464
00469 Ulong Labels() const {
00470 return nlabels;
00471 }
00472
00478 Ulong Labels( Ulong n ) {
00479 return nlabels = n;
00480 }
00481
00486 PobjectProps Props() const {
00487 return PobjectProps(nbands, ncol, nrow, 0, (PColorSpace)0, nlabels, nlabels + 1);
00488 }
00489
00493 Reg2d(): Img2d<Long>(), nlabels(0) {}
00494
00502 Reg2d(Long h, Long w): Img2d<Long>(h, w), nlabels(0) {}
00503
00510 Reg2d(const Dimension2d& d): Img2d<Long>(d), nlabels(0) {}
00511
00518 Reg2d(const PobjectProps& p): Img2d<Long>(p.nrow, p.ncol), nlabels(p.nlabels) { }
00519
00526 void New( Long h, Long w ) { Img2d<Long>::New(h, w); nlabels = 0L; }
00527
00533 void New( const Dimension2d &d ) { New(d.h, d.w); }
00534
00540 void New( const PobjectProps &p, Ulong * data = 0 ) {
00541 Img2d<Long>::New(p.nrow, p.ncol, (Long*)data);
00542 nlabels = p.nlabels;
00543 }
00544
00548 void Delete() { Img2d<Long>::Delete(); nlabels = 0L; }
00549
00554 Pobject* Clone( ) const {
00555 Reg2d *tmp = new Reg2d(nrow, ncol);
00556 *tmp = *this;
00557 return tmp;
00558 }
00559
00564 ValueType* Vector() const {
00565 return (ValueType*)Img2d<Long>::Vector();
00566 }
00567
00573 Band1dr operator[]( Long row ) {
00574 return Band1dr(this, &_data[ncol*row]);
00575 }
00576
00582 const Band1dr operator[]( Long row ) const {
00583 return Band1dr(this, &_data[ncol*row]);
00584 }
00585
00592 ValueType& operator()( Long y, Long x ) {
00593 return (ValueType&) Imx2d<Long>::operator()(0, y, x);
00594 }
00595
00602 const ValueType& operator()( Long y, Long x ) const {
00603 return (ValueType&)Imx2d<Long>::operator()(0, y, x);
00604 }
00605
00611 ValueType& operator[]( const Point2d& p ) {
00612 return (ValueType&) Imx2d<Long>::operator()(0, p.y, p.x);
00613 }
00614
00620 const ValueType& operator[]( const Point2d& p ) const {
00621 return (ValueType&)Imx2d<Long>::operator()(0, p.y, p.x);
00622 }
00623
00630 Reg2d& operator=( const Reg2d::ValueType val ) {
00631 Img2d<Long>::operator=(val);
00632 nlabels = (val > 0) ? val : 0;
00633 return *this;
00634 }
00635
00641 Reg2d& operator=( const Reg2d &rgs ) {
00642 nlabels = rgs.nlabels;
00643 memcpy(Vector(), rgs.Vector(), nrow * ncol * sizeof(Reg2d::ValueType));
00644 return *this;
00645 }
00646
00653 Errc LoadAttributes( FILE *file );
00654
00660 Errc SaveAttributes( FILE *file ) const;
00666 Errc LoadData( FILE *file );
00667
00674 Errc SaveData( FILE *file ) const;
00675
00684 Pobject* Mask( const Pobject *mask );
00685
00695 Pobject* UnMask( const Pobject *mask, const Pobject *reference );
00696
00703 Reg2d( const Reg2d &rgs ): Img2d<Long>() {
00704 New(rgs.Props());
00705 *this = rgs;
00706 }
00707 };
00708
00726 class Reg3d: public Img3d<Long> {
00732 class Band2dr {
00733 public:
00734
00741 explicit Band2dr( const Imx3d<Long> *region, Long *offset ) : _region(region), _offset(offset) {}
00742 explicit Band2dr(): _region(0), _offset(0) {};
00743 Reg2d::Band1dr operator[]( Long y ) {
00744 return Reg2d::Band1dr(_region, &_offset[_region->Width() * y]);
00745 }
00746 const Reg2d::Band1dr operator[]( Long y ) const {
00747 return Reg2d::Band1dr(_region, &_offset[_region->Width() * y]);
00748 }
00749 private:
00750 const Imx3d<Long> *_region;
00751 Long *_offset;
00752 };
00753 protected:
00755 Ulong nlabels;
00756
00757 public:
00759 typedef Ulong ValueType;
00760
00765 Typobj Type() const {
00766 return Po_Reg3d;
00767 }
00768
00773 std::string Name() const {
00774 return TypeName< Reg3d >::Name();
00775 }
00776
00781 Ulong Labels() const {
00782 return nlabels;
00783 }
00784
00790 Ulong Labels( Ulong n ) {
00791 return nlabels = n;
00792 }
00793
00798 PobjectProps Props() const {
00799 return PobjectProps(nbands, ncol, nrow, ndep, (PColorSpace)0, nlabels, nlabels + 1);
00800 }
00801
00805 Reg3d(): Img3d<Long>(), nlabels(0) {}
00806
00815 Reg3d( Long d, Long h, Long w ): Img3d<Long>(d, h, w), nlabels(0) {}
00816
00823 Reg3d( const Dimension3d& d ): Img3d<Long>(d), nlabels(0) {}
00824
00831 Reg3d(const PobjectProps& p): Img3d<Long>(p.ndep, p.nrow, p.ncol), nlabels(p.nlabels) {}
00832
00840 void New( Long d, Long h, Long w ) { Img3d<Long>::New(d, h, w); nlabels = 0L; }
00841
00847 void New( const Dimension3d& d ) { New(d.d, d.h, d.w); }
00848
00854 void New( const PobjectProps& p, Long *data = 0 ) {
00855 Img3d<Long>::New(p.ndep, p.nrow, p.ncol, (Long*)data);
00856 nlabels = p.nlabels;
00857 }
00858
00862 void Delete () { Img3d<Long>::Delete(); nlabels = 0L; }
00863
00868 Pobject* Clone( ) const {
00869 Reg3d *tmp = new Reg3d(ndep, nrow, ncol);
00870 *tmp = *this;
00871 return tmp;
00872 }
00873
00878 ValueType* Vector() const {
00879 return (ValueType*)Img3d<Long>::Vector();
00880
00881 }
00882
00889 Reg3d& operator=( const Reg3d::ValueType val ) {
00890 Img3d<Long>::operator=(val);
00891 nlabels = (val > 0) ? val : 0;
00892 return *this;
00893 }
00894
00900 Reg3d& operator=( const Reg3d &rgs ) {
00901 nlabels = rgs.nlabels;
00902 memcpy(Vector(), rgs.Vector(), ndep * nrow * ncol * sizeof(Reg3d::ValueType));
00903 return *this;
00904 }
00905
00911 Band2dr operator[]( Long dep ) {
00912 return Band2dr(this, &_data[matrixSize * dep]);
00913 }
00914
00920 const Band2dr operator[]( Long dep ) const {
00921 return Band2dr(this, &_data[matrixSize * dep]);
00922 }
00923
00931 ValueType& operator()( Long z, Long y, Long x ) {
00932 return (ValueType&) Imx3d<Long>::operator()(0, z, y, x);
00933 }
00934
00943 const ValueType& operator()( Long z, Long y, Long x ) const {
00944 return (ValueType&)Imx3d<Long>::operator()(0, z, y, x);
00945 }
00946
00952 ValueType& operator[]( const Point3d& p ) {
00953 return (ValueType&) Imx3d<Long>::operator()(0, p.z, p.y, p.x);
00954 }
00955
00961 const ValueType& operator[]( const Point3d& p ) const {
00962 return (ValueType&)Imx3d<Long>::operator()(0, p.z, p.y, p.x);
00963 }
00964
00971 Errc LoadAttributes( FILE *file );
00972
00978 Errc SaveAttributes( FILE *file ) const;
00979
00985 Errc LoadData( FILE *file );
00986
00993 Errc SaveData( FILE *file ) const;
00994
01002 Pobject* Mask( const Pobject *mask );
01003
01013 Pobject* UnMask( const Pobject *mask, const Pobject *reference );
01014
01021 Reg3d( const Reg3d &rgs ): Img3d<Long>() {
01022 New(rgs.Props());
01023 *this = rgs;
01024 }
01025 };
01026
01027 }
01028 #endif // __PREGIONH__