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
00045 #ifndef __PIMAGEH__
00046 #define __PIMAGEH__
00047
00048 namespace pandore {
00049
00050 class Border2DIterator {
00051 private:
00052 Dimension2d _size;
00053 int _top;
00054 int _left;
00055 int _right;
00056 int _bottom;
00057 Point2d *_points;
00058 int _length;
00059 int _index;
00060
00061 public:
00062 Border2DIterator( const Dimension2d size, int c1, int c2, int c3, int c4 ): _size(size), _top(c1), _left(c2), _right(c3), _bottom(c4) {
00063 _length = size.w * _top
00064 + size.w * _bottom
00065 + size.h * _left
00066 + size.h * _right
00067 - 2 * (_top + _bottom);
00068 _points = new Point2d[_length];
00069 _index = 0;
00070
00071 Point2d p;
00072
00073 for (p.y = 0; p.y < _top; p.y++) {
00074 for (p.x = 0; p.x < _size.w; p.x++) {
00075 _points[_index++] = p;
00076 }
00077 }
00078
00079
00080 for (p.y = _size.h - _bottom; p.y < _size.h; p.y++) {
00081 for (p.x = 0; p.x < _size.w; p.x++) {
00082 _points[_index++] = p;
00083 }
00084 }
00085
00086
00087 for (p.x = 0; p.x < _left; p.x++) {
00088 for (p.y = _top; p.y < _size.h - _bottom; p.y++) {
00089 _points[_index++] = p;
00090 }
00091 }
00092
00093
00094 for (p.x = _size.w - _right; p.x < _size.w; p.x++) {
00095 for (p.y = _top; p.y < _size.h - _bottom; p.y++) {
00096 _points[_index++] = p;
00097 }
00098 }
00099 _index = 0;
00100 }
00101 bool hasNext() {
00102 return _index < _length;
00103 }
00104 Point2d next() {
00105 return _points[_index++];
00106 }
00107 };
00108
00109 class Border3DIterator {
00110 private:
00111 Dimension3d _size;
00112 int _top;
00113 int _left;
00114 int _right;
00115 int _bottom;
00116 int _front;
00117 int _back;
00118 Point3d *_points;
00119 int _length;
00120 int _index;
00121
00122 public:
00123 Border3DIterator( const Dimension3d size, int c1, int c2, int c3, int c4, int c5, int c6 ): _size(size), _top(c1), _left(c2), _right(c3), _bottom(c4),
00124 _front(c5), _back(c6) {
00125 _length = (_front + _back) * (_size.h * _size.w)
00126 + (_size.d - _top - _back) * (_top * _size.h + _bottom * _size.h + _left * (_size.w - _top - _bottom) + _right * (_size.w - _top - _bottom)) ;
00127 _points = new Point3d[_length];
00128 _index = 0;
00129
00130 Point3d p;
00131
00132 for (p.z = 0; p.z < _front; p.z++) {
00133 for (p.y = 0; p.y < _size.h; p.y++) {
00134 for (p.x = 0; p.x < _size.w; p.x++) {
00135 _points[_index++] = p;
00136 }
00137 }
00138 }
00139
00140 for (p.z = _front; p.z < _size.d - _back; p.z++) {
00141
00142 for (p.y = 0; p.y < _top; p.y++) {
00143 for (p.x = 0; p.x < _size.w; p.x++) {
00144 _points[_index++] = p;
00145 }
00146 }
00147
00148 for (p.y = _size.h- _bottom; p.y < _size.h; p.y++) {
00149 for (p.x = 0; p.x < _size.w; p.x++) {
00150 _points[_index++] = p;
00151 }
00152 }
00153
00154 for (p.x = 0; p.x < _left; p.x++) {
00155 for (p.y = _top; p.y < _size.h - _bottom; p.y++) {
00156 _points[_index++] = p;
00157 }
00158 }
00159
00160 for (p.x = _size.w - _right; p.x < _size.w; p.x++) {
00161 for (p.y = _top; p.y < _size.h - _bottom; p.y++) {
00162 _points[_index++] = p;
00163 }
00164 }
00165 }
00166
00167
00168 for (p.z = _size.d - _back; p.z < _size.d; p.z++) {
00169 for (p.y = 0; p.y < _size.h; p.y++) {
00170 for (p.x = 0; p.x < _size.w; p.x++) {
00171 _points[_index++] = p;
00172 }
00173 }
00174 }
00175 _index = 0;
00176
00177 }
00178 bool hasNext() {
00179 return _index < _length - 1;
00180 }
00181 Point3d next() {
00182 return _points[_index++];
00183 }
00184 };
00185
00189
00190 template< typename T >
00191 class Imx2d;
00192
00204 template< typename T >
00205 class Imx3d: public Pobject {
00206 protected:
00211 class Band1d {
00212 public:
00213
00221 explicit Band1d( const Imx3d<T> * const , T *offset ) : _offset(offset) {}
00222 T &operator[]( Long x ) { return _offset[x]; }
00223 const T &operator[]( Long x ) const { return _offset[x]; }
00224 T &operator[]( const Point1d &p ) { return _offset[p.x]; }
00225 const T & operator[]( const Point1d &p ) const { return _offset[p.x]; }
00226 private:
00227 T *_offset;
00228 };
00229
00235 class Band2d {
00236 public:
00237
00245 explicit Band2d( const Imx3d<T> * const image, T *offset ) : _image(image), _offset(offset) {}
00246 explicit Band2d(): _image(0), _offset(0) {};
00247 void New( const Imx3d<T> * const image, T *offset ) { _image = image; _offset=offset; }
00248
00249 Band1d operator[]( Long y ) { return Band1d(_image, &_offset[_image->ncol*y]); }
00250 const Band1d operator[]( Long y ) const { return Band1d(_image, &_offset[_image->ncol * y]); }
00251 T &operator[]( const Point2d &p ) { return _offset[_image->ncol * p.y + p.x]; }
00252 const T & operator[]( const Point2d &p ) const { return _offset[_image->ncol * p.y + p.x]; }
00253
00254 Band2d& operator=( const Imx2d<T> &ims ) {
00255 if (_image->Bands() != ims.Bands( )
00256 || _image->Depth() != ims.Depth()
00257 || _image->Height() != ims.Height()
00258 || _image->Width() != ims.Width()) {
00259 std::cerr << "Error: incomptabiles images for operator: 2D image = 3D image[i]" << std::endl;
00260 } else {
00261 T *ps = ims.Vector();
00262 T *pe = ps + ims.Bands() * ims.nrow * ims.ncol;
00263 T *pd = _offset;
00264 for (; ps<pe; ) {
00265 *(pd++) = (T)*(ps++);
00266 }
00267 }
00268 return *this;
00269 }
00270 Band2d& operator=( const T val ) {
00271 T *pd = _offset;
00272 T *pe = pd + _image->nbands * _image->nrow * _image->ncol;
00273 for (; pd < pe; ) {
00274 *(pd++) = val;
00275 }
00276 return *this;
00277 }
00278 private:
00279 const Imx3d<T> *_image;
00280 T *_offset;
00281 };
00282
00288 class Band3d {
00289 public:
00297 explicit Band3d( const Imx3d<T> * const image, T *offset ) : _image(image), _offset(offset) {}
00298
00299 Band2d operator[]( Long z ) { return Band2d(_image, &_offset[_image->matrixSize * z]); }
00300 explicit Band3d(): _image(0), _offset(0) {};
00301 void New( const Imx3d<T> * const image, T *offset ) { _image = image; _offset = offset; }
00302
00303 const Band2d operator[]( Long z ) const { return Band2d(_image, &_offset[_image->matrixSize * z]); }
00304 T &operator[]( const Point3d &p ) { return _offset[_image->matrixSize * p.z + _image->ncol * p.y + p.x]; }
00305 const T & operator[]( const Point3d &p ) const { return _offset[_image->matrixSize * p.z + _image->ncol * p.y + p.x]; }
00306 T &operator()( const Point3d &p ) { return _offset[_image->matrixSize * p.z + _image->ncol * p.y + p.x]; }
00307 const T & operator()( const Point3d &p ) const { return _offset[_image->matrixSize * p.z + _image->ncol * p.y + p.x]; }
00308
00309 private:
00310 const Imx3d<T> *_image;
00311 T *_offset;
00312 };
00313
00314 protected:
00316 T *_data;
00318 bool _isDataOwner;
00319
00321 Long nbands;
00323 Long ncol;
00325 Long nrow;
00327 Long ndep;
00329 Long matrixSize;
00330 Long volumeSize;
00331
00332 private:
00334 PColorSpace colorspace;
00335
00336 public:
00338 typedef T ValueType;
00339
00343 Typobj Type( ) const { return ( Typobj )Po_type< Imx3d< T > >::type; }
00344
00348 std::string Name( ) const { return TypeName< Imx3d < T > >::Name( ); }
00349
00353 Long Width( ) const { return ncol; }
00354
00358 Long Height( ) const { return nrow; }
00359
00363 Long Depth( ) const { return ndep; }
00364
00368 Long Bands( ) const { return nbands; }
00369
00373 Dimension3d Size( ) const {
00374 return Dimension3d(ndep, nrow, ncol);
00375 }
00376
00380 Ulong VectorSize( ) const {
00381 return (Ulong)volumeSize;
00382 }
00383
00388 PobjectProps Props( ) const {
00389 return PobjectProps(nbands, ncol, nrow, ndep, colorspace, 0, ndep * ncol * nrow);
00390 }
00391
00395 Imx3d( ): Pobject( ), _data(0), _isDataOwner(false), nbands(0), ncol(0), nrow(0), ndep(0), matrixSize(0), volumeSize(0), colorspace(RGB) {
00396 }
00397
00410 Imx3d( Long b, Long d, Long h, Long w, T *data = 0, bool isOwner = false ): Pobject (), _data(0), _isDataOwner(isOwner), nbands(0), ncol(0), nrow(0), ndep(0), matrixSize(0), volumeSize(0), colorspace( RGB ) {
00411 New(b, d, h, w, data);
00412 }
00413
00424 Imx3d( Long b, const Dimension3d &d, T *data = 0, bool isOwner = false ): Pobject ( ), _data(0), _isDataOwner(isOwner), nbands(0), ncol(0), nrow(0), ndep(0), matrixSize(0), volumeSize(0), colorspace(RGB) {
00425 New(b, d. d, d.h, d.w, data);
00426 }
00427
00438 Imx3d( const PobjectProps &p, T *data = 0, bool isOwner = false ): Pobject ( ), _data(0), _isDataOwner(isOwner), nbands(0), ncol(0), nrow(0), ndep(0), matrixSize(0), volumeSize(0) {
00439 New(p, data);
00440 }
00441
00448 Imx3d( const Imx3d &ims ): Pobject(), _data(0), _isDataOwner(false), nbands(0), ncol(0), nrow(0), ndep(0) {
00449 New(ims.Props());
00450 *this = ims;
00451 }
00452
00453 ~Imx3d( ) {
00454 Delete();
00455 }
00456
00469 void New( Long b, Long d, Long h, Long w, T *data = 0, bool isOwner = false ) {
00470 Long size = b * w * h * d;
00471 if (size <= 0) {
00472 throw std::runtime_error("Memory allocation error: block too big.");
00473 }
00474 if (data != 0 || (nbands * ncol * nrow * ndep != size)) {
00475 Delete();
00476
00477 if (data == 0) {
00478 _isDataOwner = true;
00479 _data = new T[size];
00480 } else {
00481 _isDataOwner = isOwner;
00482 _data = data;
00483 }
00484 }
00485 ndep = d;
00486 nrow = h;
00487 ncol = w;
00488 nbands = b;
00489 matrixSize = ncol * nrow;
00490
00491 volumeSize = matrixSize * ndep;
00492 }
00493
00503 void New( Long b, const Dimension3d &d, T *data = 0) {
00504 New(b, d.d, d.h, d.w, data);
00505 }
00506
00515 virtual void New( const PobjectProps &p, T *data = 0, bool isOwner = false ) {
00516 New(p.nbands, p.ndep, p.nrow, p.ncol, data, isOwner);
00517 colorspace = p.colorspace;
00518 }
00519
00523 void Delete( ) {
00524 if (_isDataOwner) {
00525 delete[] _data;
00526 }
00527 _data = 0;
00528 nbands = ndep = nrow = ncol = matrixSize = volumeSize = 0L;
00529 }
00530
00535 virtual Pobject* Clone( ) const {
00536 Imx3d< T > *tmp = new Imx3d< T > (nbands, ndep, nrow, ncol);
00537 *tmp = *this;
00538
00539 return tmp;
00540 }
00541
00547 Imx3d< T > &operator=( const T val ) {
00548 T *bp = Vector();
00549 T *ep = bp + (nbands * ndep * nrow * ncol);
00550
00551 for (; bp < ep; *(bp++) = val) ;
00552
00553 return *this;
00554 }
00555
00562 template< typename U >
00563 Imx3d< T > &operator=( const Imx3d< U > &src ) {
00564 if (Bands() != src.Bands( ) || Depth() != src.Depth() ||
00565 Height() != src.Height() || Width() != src.Width()) {
00566 Delete();
00567 New(src.Bands(), src.Depth(), src.Height(), src.Width());
00568 }
00569 T *pd = Vector();
00570 U *ps = src.Vector();
00571 U *pe = ps + nbands * ndep * nrow * ncol;
00572
00573 for (; ps < pe; ) {
00574 *(pd++) = (T)*(ps++);
00575 }
00576 return *this;
00577 }
00578
00585 Imx3d< T > &operator=( const Imx3d< T > &src ) {
00586 if (Bands() != src.Bands( )
00587 || Depth() != src.Depth()
00588 || Height() != src.Height()
00589 || Width() != src.Width()) {
00590 Delete();
00591 New(src.Bands(), src.Depth(), src.Height(), src.Width());
00592 }
00593 memcpy(Vector(), src.Vector(), nbands * ndep * nrow * ncol * sizeof(T));
00594 return *this;
00595 }
00596
00601 T* Vector( Long band = 0 ) const {
00602 return &_data[volumeSize * band];
00603 }
00604
00609 Band3d operator[]( Long band ) {
00610 return Band3d(this, &_data[volumeSize * band]);
00611 }
00612
00617 const Band3d operator[]( Long band ) const {
00618 return Band3d(this, &_data[volumeSize * band]);
00619 }
00620
00629 T &operator()( Long b, Long z, Long y, Long x ) {
00630 return _data[volumeSize * b + matrixSize * z + ncol * y + x];
00631 }
00632
00641 const T &operator()( Long b, Long z, Long y, Long x ) const {
00642 return _data[volumeSize * b + matrixSize * z + ncol * y + x];
00643 }
00644
00645
00652 T &operator()( Long b, Point3d &p ) {
00653 return _data[volumeSize * b + matrixSize * p.z + ncol * p.y + p.x];
00654 }
00655
00662 const T &operator()( Long b, Point3d &p ) const {
00663 return _data[volumeSize * b + matrixSize * p.z + ncol * p.y + p.x];
00664 }
00665
00673 virtual Errc LoadAttributes( FILE *file ) {
00674 Long attr[4];
00675
00676 if (this->Fdecode((void*)attr, sizeof(*attr), 4, file) < 4) {
00677 return FAILURE;
00678 }
00679 New(attr[0], attr[1], attr[2], attr[3]);
00680 return SUCCESS;
00681 }
00682
00688 virtual Errc SaveAttributes( FILE *file ) const {
00689 Long attr[4];
00690
00691 attr[0] = nbands;
00692 attr[1] = ndep;
00693 attr[2] = nrow;
00694 attr[3] = ncol;
00695 if (this->Fencode((void*)attr, sizeof(*attr), 4, file) < 4) {
00696 return FAILURE;
00697 }
00698 return SUCCESS;
00699 }
00700
00708 virtual Errc LoadData( FILE *file ) {
00709 size_t x = volumeSize;
00710
00711
00712
00713
00714 #ifdef _WIN32
00715 if (x * sizeof(T) < (size_t)67076095) {
00716 #endif
00717 size_t a;
00718 for (int b = 0; b < nbands; b++) {
00719 if ((a = this->Fdecode((void*)Vector(b), sizeof(T), x, file)) < x) {
00720 return FAILURE;
00721 }
00722 }
00723 #ifdef _WIN32
00724 } else {
00725 x = matrixSize;
00726 for (int b = 0; b < nbands; b++) {
00727 T *data = Vector(b);
00728 for (int z = 0; z < ndep; z++) {
00729 if (this->Fdecode((void*)data, sizeof(T), x, file) < x) {
00730 return FAILURE;
00731 }
00732 data += x;
00733 }
00734 }
00735 }
00736 #endif
00737 return SUCCESS;
00738 }
00739
00745 virtual Errc SaveData( FILE *file ) const {
00746 size_t x = volumeSize;
00747
00748
00749
00750 #ifdef _WIN32
00751 if (x * sizeof(T) < (size_t)67076095) {
00752 #endif
00753 for (int b = 0; b < nbands; b++) {
00754 if (this->Fencode((void*)Vector(b), sizeof(T), x, file) < x) {
00755 return FAILURE;
00756 }
00757 }
00758 #ifdef _WIN32
00759 } else {
00760 x = matrixSize;
00761 for (int b = 0; b < nbands; b++) {
00762 T *data = Vector(b);
00763 for (int z = 0; z < ndep; z++) {
00764 if (this->Fencode((void*)data, sizeof(T), x, file) < x) {
00765 return FAILURE;
00766 }
00767 data += x;
00768 }
00769 }
00770 }
00771 #endif
00772 return SUCCESS;
00773 }
00774
00782 virtual Pobject* Mask( const Pobject* mask ) {
00783 if ((!mask)
00784 || (mask->Type() != Po_Reg3d)
00785 || (reinterpret_cast<const Imx3d<Long>*>(mask)->Size() != Size())) {
00786 std::cerr << "Warning: bad mask format... ignored" << std::endl;
00787 return this;
00788 }
00789 Imx3d< T > *objd = (Imx3d< T >*)Clone();
00790 const Imx3d<Long> *m = reinterpret_cast<const Imx3d<Long>*>(mask);
00791 for (int b = 0; b < nbands; b++) {
00792 Ulong *pm = (Ulong*)m->Vector(0);
00793 T *pp = objd->Vector(b);
00794 T *pq = Vector(b);
00795 for (int i = 0; i < volumeSize; i++, pq++, pm++, pp++) {
00796 *pp = (*pm == 0) ? 0 : *pq;
00797 }
00798 }
00799 return objd;
00800 }
00801
00810 virtual Pobject* UnMask( const Pobject* mask, const Pobject* reference ) {
00811 if ((!mask)
00812 || (mask->Type() != Po_Reg3d)
00813 || (reinterpret_cast<const Imx3d<Long>*>(mask)->Size() != Size())
00814 || (reference->Type() != Type())
00815 || (reinterpret_cast<const Imx3d<T>*>(reference)->Size() != Size())) {
00816 std::cerr << "Warning: bad unmask format... ignored" << std::endl;
00817 return this;
00818 }
00819
00820
00821 const Imx3d< T > *objs = reinterpret_cast<const Imx3d< T >*>(reference);
00822 Imx3d< T > *objd = (Imx3d< T >*)Clone();
00823 const Imx3d<Long> *m = reinterpret_cast<const Imx3d<Long>*>(mask);
00824 for (int b = 0; b < nbands; b++) {
00825 Ulong *pm = (Ulong*)m->Vector(0);
00826 T *pp = objd->Vector(b);
00827 T *pq = Vector(b);
00828 T *ps = objs->Vector(b);
00829
00830 for (int i = 0; i < volumeSize; i++, pp++, pq++, pm++, ps++) {
00831 *pp = (*pm == 0) ? *ps : *pq;
00832 }
00833 }
00834 return objd;
00835 }
00836
00840 PColorSpace ColorSpace( ) const { return colorspace; }
00841
00847 PColorSpace ColorSpace( PColorSpace e ) { return colorspace=e; }
00848
00857 bool Hold( Long z, Long y, Long x ) const {
00858 return (z>=0) && (z < ndep) && (y >= 0) && (y < nrow) && (x >= 0) && (x < ncol);
00859 }
00860
00866 bool Hold( const Point3d &pt ) const {
00867 return (pt.z >= 0) && (pt.z < ndep) && (pt.y >= 0) && (pt.y < nrow) && (pt.x >= 0) && (pt.x < ncol);
00868 }
00869
00877 Errc Frame( ValueType val, Long d, Long h, Long l ) {
00878 if ((d < 0) || (h < 0) || (l < 0)) {
00879 return FAILURE;
00880 }
00881 for (int b = 0; b < nbands; b++) {
00882 for (int z = 0; z < ndep; z++) {
00883 for (int y = 0; y < nrow; y++) {
00884 for (int x = 0; x < l; x++) {
00885 operator()(b, z, y, x) = (T)val;
00886 operator()(b, z, y, ncol - 1 - x) = (T)val;
00887 }
00888 }
00889 }
00890 for (int z = 0; z < ndep; z++) {
00891 for (int y = 0; y < h; y++) {
00892 for (int x = l; x < ncol - l; x++) {
00893 operator()(b, z, y, x) = (T)val;
00894 operator()(b, z, nrow - 1 - y, x) = (T)val;
00895 }
00896 }
00897 }
00898 for (int z = 0; z < d; z++) {
00899 for (int y = h; y < nrow - h; y++) {
00900 for (int x = l; x < ncol - l; x++) {
00901 operator()(b, z, y, x) = (T)val;
00902 operator()(b, ndep - 1 - z , y, x) = (T)val;
00903 }
00904 }
00905 }
00906 }
00907 return SUCCESS;
00908 }
00909
00915 Errc Frame( ValueType v, Long d ) {
00916 return Frame(v, d, d, d);
00917 }
00918
00925 template < typename U>
00926 Errc Frame( const Imx3d < U> &ims, Long d ) {
00927 return Frame(ims, d, d, d);
00928 }
00929
00938 template < typename U >
00939 Errc Frame( const Imx3d < U > &ims, Long d, Long h, Long l ) {
00940 if (l == -1) {
00941 l = h = d;
00942 }
00943 if ((d < 0) || (h < 0) || (l < 0)) {
00944 return FAILURE;
00945 }
00946 for ( int b = 0; b < nbands; b++ ) {
00947 for (int i = 0; i < ndep; i++) {
00948 for (int j = 0; j < nrow; j++) {
00949 for (int k = 0; k < l; k++) {
00950 operator()(b, i, j, k) = ( T )ims(b, i, j, k);
00951 operator()(b, i, j, ncol - 1 - k) = ( T )ims(b, i, j, ncol - 1 - k);
00952 }
00953 }
00954 }
00955 for (int i = 0; i < ndep; i++) {
00956 for (int j = 0; j < h; j++) {
00957 for (int k = l; k < ncol - l; k++) {
00958 operator()(b, i, j, k) = ( T )ims(b, i, j , k);
00959 operator()(b, i, nrow - 1 - j, k) = ( T )ims(b, i, nrow - 1 - j, k);
00960 }
00961 }
00962 }
00963 for (int i = 0; i < d; i++) {
00964 for (int j = h; j < nrow - h; j++) {
00965 for (int k = l; k<ncol-l; k++) {
00966 operator()(b, i, j, k) = ( T )ims(b, i, j, k);
00967 operator()(b, ndep - 1 - i, j, k) = ( T )ims(b, ndep - 1 - i, j, k);
00968 }
00969 }
00970 }
00971 }
00972 return SUCCESS;
00973 }
00974
00975 Border3DIterator *getBorderIterator( int c1, int c2, int c3, int c4, int c5, int c6 ) const {
00976 return new Border3DIterator(Size(), c1, c2, c3, c4, c5, c6);
00977 }
00978 };
00979
00983
00991 template< typename T >
00992 class Imx2d: public Imx3d < T > {
00993 protected:
00994 using Imx3d < T>::_data;
00995 using Imx3d < T>::ncol;
00996 using Imx3d < T>::nrow;
00997 using Imx3d < T>::nbands;
00998 using Imx3d < T>::matrixSize;
00999 using Imx3d < T>::ColorSpace;
01000
01001 public:
01003 typedef T ValueType;
01004
01008 Typobj Type( ) const { return ( Typobj )Po_type< Imx2d < T > >::type; }
01009
01013 std::string Name( ) const { return TypeName< Imx2d < T > >::Name( ); }
01014
01018 Dimension2d Size( ) const{ return Dimension2d(nrow, ncol); }
01019
01023 Imx2d( ): Imx3d < T>( ) { }
01024
01036 Imx2d( Long b, Long h, Long w, T *data = 0, bool isOwner = false ): Imx3d < T>( ) { New(b, h, w , data, isOwner); }
01037
01048 Imx2d( Long b, const Dimension2d &d, T *data = 0, bool isOwner = false ): Imx3d < T>( ) { New(b, d.h, d.w, data, isOwner); }
01049
01058 Imx2d( const PobjectProps &p, T *data = 0, bool isOwner = false ): Imx3d < T>( ) { New(p, data, isOwner); }
01059
01071 void New( Long b, Long h, Long w, T *data = 0, bool isOwner = false ) { Imx3d < T>::New(b, 1, h, w, data, isOwner); }
01072
01083 void New( Long b, const Dimension2d &d, T *data = 0, bool isOwner = false ) {
01084 New(b, d.h, d.w, data, isOwner);
01085 }
01086
01095 void New( const PobjectProps &p, T *data = 0, bool isOwner = false ) {
01096 New(p.nbands, p.nrow, p.ncol, data, isOwner);
01097 ColorSpace(p.colorspace);
01098 }
01099
01104 Pobject* Clone( ) const {
01105 Imx2d < T > *tmp = new Imx2d < T >(nbands, nrow, ncol);
01106 *tmp = *this;
01107 return tmp;
01108 }
01109
01110
01111
01112
01113
01114
01115 Imx2d < T > &operator=( const T val ) {
01116 Imx3d < T>::operator=(val);
01117 return *this;
01118 }
01119
01126 template< typename U >
01127 Imx2d < T > &operator=( const Imx2d < U > &src ) {
01128 Imx3d < T>::operator=(src);
01129 return *this;
01130 }
01131
01138 Imx2d < T > &operator=( const Imx2d < T > &src ) {
01139 Imx3d < T>::operator=(src);
01140 return *this;
01141 }
01142
01147 T* Vector( Long band = 0 ) const {
01148 return &_data[matrixSize * band];
01149 }
01150
01155 typename Imx3d < T>::Band2d operator[]( Long band ) { return typename Imx3d < T>::Band2d(this, &_data[matrixSize * band]); }
01156
01161 const typename Imx3d < T>::Band2d operator[]( Long band ) const { return typename Imx3d < T>::Band2d(this, &_data[matrixSize * band]); }
01162
01170 T &operator()( Long b, Long y, Long x ) { return _data[matrixSize * b + ncol * y + x]; }
01171
01179 const T &operator()( Long b, Long y, Long x ) const { return _data[matrixSize * b + ncol * y + x]; }
01180
01187 const T &operator()( Long b, Point2d &p ) const { return _data[matrixSize * b + ncol * p.y + p.x]; }
01188
01195 T &operator()( Long b, Point2d &p ) { return _data[matrixSize * b + ncol * p.y + p.x]; }
01196
01204 Errc LoadAttributes( FILE *file ) {
01205 Long attr[3];
01206
01207 if (this->Fdecode((void*)attr, sizeof(*attr), 3, file) < 3) {
01208 return FAILURE;
01209 }
01210 New(attr[0], attr[1], attr[2]);
01211 return SUCCESS;
01212 }
01213
01219 Errc SaveAttributes( FILE *file ) const {
01220 Long attr[3];
01221
01222 attr[0] = nbands;
01223 attr[1] = nrow;
01224 attr[2] = ncol;
01225 if (this->Fencode((void*)attr, sizeof(*attr), 3, file) < 3) {
01226 return FAILURE;
01227 }
01228 return SUCCESS;
01229 }
01230
01238 Pobject* Mask( const Pobject* mask ) {
01239 if ((!mask)
01240 || (mask->Type() != Po_Reg2d)
01241 || (reinterpret_cast<const Imx2d < Long >*>(mask))->Size() != Size()){
01242 std::cerr << "Warning: bad mask format... ignored" << std::endl;
01243 return this;
01244 }
01245
01246 Imx2d < T > *objd = (Imx2d < T> *)Clone();
01247 const Imx2d < Long > *m = reinterpret_cast<const Imx2d < Long >*>(mask);
01248 for (int b = 0; b < nbands; b++) {
01249 Ulong *pm = (Ulong*)m->Vector(0);
01250 T *pp = objd->Vector(b);
01251 T *pq = Vector(b);
01252
01253 for (int i = 0; i < matrixSize; i++, pp++, pq++, pm++) {
01254 *pp = (*pm == 0)? 0 : *pq;
01255 }
01256 }
01257 return objd;
01258 }
01259
01260
01269 Pobject* UnMask( const Pobject* mask, const Pobject* reference ) {
01270 if ((!mask)
01271 || (mask->Type() != Po_Reg2d)
01272 || (reinterpret_cast<const Imx2d < Long >*>(mask)->Size() != Size())
01273 || (reference->Type() != Type())
01274 || (reinterpret_cast<const Imx2d < T >*>(reference)->Size() != Size())) {
01275 std::cerr << "Warning: bad unmask format... ignored" << std::endl;
01276 return this;
01277 }
01278
01279 const Imx2d < T > *objs = reinterpret_cast<const Imx2d < T > *>(reference);
01280 const Imx2d < Long > *m = reinterpret_cast<const Imx2d < Long > *>(mask);
01281 Imx2d < T > *objd = (Imx2d < T > *)Clone();
01282 for (int b = 0; b < nbands; b++) {
01283 Ulong *pm = (Ulong*)m->Vector(0);
01284 T *pp = objd->Vector(b);
01285 T *pq = Vector(b);
01286 T *ps = objs->Vector(b);
01287
01288 for (int i = 0; i<matrixSize; i++, pp++, pq++, pm++, ps++) {
01289 *pp = (*pm == 0) ? *ps : *pq;
01290 }
01291 }
01292 return objd;
01293 }
01294
01302 bool Hold( Long y, Long x ) const { return (y >= 0) && (y < nrow) && (x >= 0) && (x < ncol); }
01303
01309 bool Hold( const Point2d &pt ) const { return (pt.y >= 0) && (pt.y < nrow) && (pt.x >= 0) && ( pt.x < ncol); }
01310
01316 Errc Frame( ValueType val, Long h ) { return Imx3d < T>::Frame(val, 0, h, h ); }
01317
01324 Errc Frame( ValueType val, Long h, Long l ) { return Imx3d < T>::Frame(val, 0, h, l); }
01325
01332 template < typename U >
01333 Errc Frame( const Imx2d < U > &ims, Long h ) { return Imx3d < T>::Frame(ims, 0, h, h); }
01334
01342 template < typename U >
01343 Errc Frame( const Imx2d < U > &ims, Long h, Long l ) { return Imx3d < T>::Frame(ims, 0, h, l); }
01344
01345 Border2DIterator *getBorderIterator( int c1, int c2, int c3, int c4 ) const {
01346 return new Border2DIterator(Size(), c1, c2, c3, c4);
01347 }
01348
01355 Imx2d( const Imx2d &ims ): Imx3d < T>( ) { New(ims.Props()); *this = ims; }
01356 };
01357
01361
01369 template <class T>
01370 class Imx1d: public Imx3d < T > {
01371 protected:
01372 using Imx3d < T>::_data;
01373 using Imx3d < T>::ncol;
01374 using Imx3d < T>::nbands;
01375 using Imx3d < T>::ColorSpace;
01376
01377 public:
01379 typedef T ValueType;
01380
01384 Typobj Type( ) const { return ( Typobj )Po_type< Imx1d < T > >::type; }
01385
01389 std::string Name( ) const { return TypeName< Imx1d < T > >::Name( ); }
01390
01394 Dimension1d Size( ) const{ return Dimension1d( ncol ); }
01395
01399 Imx1d( ): Imx3d < T>( ) { }
01400
01411 Imx1d( Long b, Long w, T *data = 0, bool isOwner = false ): Imx3d < T>( ) { New(b, w, data, isOwner); }
01412
01423 Imx1d( Long b, const Dimension1d &d, T *data = 0, bool isOwner = false ): Imx3d < T>( ) {
01424 New(b, d.w, data, isOwner);
01425 }
01426
01437 Imx1d( const PobjectProps &p, T *data = 0, bool isOwner = false ): Imx3d < T>( ) {
01438 New(p, data, isOwner);
01439 }
01440
01451 void New( Long b, Long w, T *data = 0, bool isOwner = false ) {
01452 Imx3d < T>::New(b, 1, 1, w, data, isOwner);
01453 }
01454
01465 void New( Long b, const Dimension1d &d, T *data = 0, bool isOwner = false ) {
01466 New(b, d.w, data, isOwner);
01467 }
01468
01477 void New( const PobjectProps &p, T *data = 0, bool isOwner = false ) {
01478 New(p.nbands, p.ncol, data, isOwner); ColorSpace(p.colorspace);
01479 }
01480
01485 Pobject* Clone( ) const {
01486 Imx1d < T > *tmp = new Imx1d < T >(nbands, ncol);
01487 *tmp = *this;
01488
01489 return tmp;
01490 }
01491
01492
01493
01494
01495
01496
01497 Imx1d < T > &operator=( const T val ) { Imx3d < T>::operator=( val ); return *this; }
01498
01505 template< typename U >
01506 Imx1d < T > &operator=( const Imx1d < U > &src ) { Imx3d < T>::operator=( src ); return *this; }
01507
01514 Imx1d < T > &operator=( const Imx1d < T > &src ) { Imx3d < T>::operator=( src ); return *this; }
01515
01520 T* Vector( Long band = 0 ) const { return &_data[ncol * band]; }
01521
01526 typename Imx3d < T>::Band1d operator[]( Long band ) {
01527 return typename Imx3d < T>::Band1d(this, &_data[ncol * band]);
01528 }
01529
01534 const typename Imx3d < T>::Band1d operator[]( Long band ) const { return typename Imx3d < T>::Band1d(this, &_data[ncol * band]); }
01535
01542 T &operator()( Long b, Long x ) { return _data[ncol * b + x]; }
01543
01550 const T &operator()( Long b, Long x ) const { return _data[ncol * b + x]; }
01551
01558 T &operator()( Long b, Point1d &p ) { return _data[ncol * b + p.x]; }
01559
01566 const T &operator()( Long b, Point1d &p ) const { return _data[ncol * b + p.x]; }
01567
01575 Errc LoadAttributes( FILE* file ) {
01576 Long attr[2];
01577
01578 if (this->Fdecode((void*)attr, sizeof(*attr), 2, file) < 2) {
01579 return FAILURE;
01580 }
01581 New(attr[0], attr[1]);
01582 return SUCCESS;
01583 }
01584
01590 Errc SaveAttributes( FILE* file ) const {
01591 Long attr[2];
01592
01593 attr[0] = nbands; attr[1] = ncol;
01594 if (this->Fencode((void*)attr, sizeof(*attr), 2, file) < 2) {
01595 return FAILURE;
01596 }
01597 return SUCCESS;
01598 }
01599
01607 Pobject* Mask( const Pobject* mask ) {
01608 if ((!mask)
01609 || (mask->Type() != Po_Reg1d)
01610 || (reinterpret_cast<const Imx1d < Long >*>(mask)->Size() != Size())) {
01611 std::cerr << "Warning: bad mask format... ignored" << std::endl;
01612 return this;
01613 }
01614
01615 Imx1d < T > *objd = (Imx1d < T >*)Clone();
01616 const Imx1d < Long > *m = reinterpret_cast<const Imx1d < Long >*>(mask);
01617 for (int b = 0; b < nbands; b++) {
01618 Ulong *pm = (Ulong*)m->Vector(0);
01619 T *pp = objd->Vector(b);
01620 T *pq = Vector(b);
01621
01622 for (int i = 0; i < ncol; i++, pp++, pq++, pm++) {
01623 *pp = (*pm == 0) ? 0 : *pq;
01624 }
01625 }
01626 return objd;
01627 }
01628
01637 Pobject* UnMask( const Pobject* mask, const Pobject* reference ) {
01638 if ((!mask)
01639 || (mask->Type() != Po_Reg1d)
01640 || (reinterpret_cast<const Imx1d < Long >*>(mask)->Size() != Size())
01641 || (reference->Type() != Type())
01642 || (reinterpret_cast<const Imx1d < T>*>(reference)->Size() != Size())) {
01643 std::cerr << "Warning: bad unmask format... ignored" << std::endl;
01644 return this;
01645 }
01646 if ((mask == NULL) || (mask->Type() != Po_Reg1d) || (reference->Type() != Type())) {
01647 return this;
01648 }
01649
01650 const Imx1d < T > *objs = reinterpret_cast<const Imx1d < T > *>(reference);
01651 const Imx1d < Long > *m = reinterpret_cast<const Imx1d < Long >*>(mask);
01652 Imx1d < T > *objd = (Imx1d < T > *)Clone();
01653 for (int b = 0; b < nbands; b++) {
01654 Ulong *pm = (Ulong*)m->Vector(0);
01655 T *pp = objd->Vector(b);
01656 T *pq = Vector(b);
01657 T *ps = objs->Vector(b);
01658
01659 for (int i = 0; i < ncol; i++, pp++, pq++, pm++, ps++) {
01660 *pp = (*pm == 0) ? *ps : *pq;
01661 }
01662 }
01663 return objd;
01664 }
01665
01672 bool Hold( Long x ) const { return (x >= 0) && (x < ncol); }
01673
01679 bool Hold( const Point1d &pt ) const { return (pt.x >= 0) && (pt.x < ncol); }
01680
01686 Errc Frame( ValueType val, Long l ) { return Imx3d < T>::Frame(val, 1, 1, l); }
01687
01694 template < typename U >
01695 Errc Frame( const Imx1d < U > &ims, Long l ) { return Imx3d < T>::Frame(ims, 1, 1, l); }
01696
01703 Imx1d( const Imx1d &ims ): Imx3d < T>() {
01704 New(ims.Props());
01705 *this = ims;
01706 }
01707 };
01708
01712
01720 template <class T>
01721 class Img1d: public Imx1d < T> {
01722 protected:
01723 using Imx1d < T>::ncol;
01724 using Imx1d < T>::nbands;
01725 using Imx1d < T>::ColorSpace;
01726
01727 public:
01729 typedef T ValueType;
01730
01734 Typobj Type( ) const { return ( Typobj )Po_type< Img1d < T > >::type; }
01735
01739 std::string Name( ) const { return TypeName< Img1d < T > >::Name( ); }
01740
01744 Img1d( ): Imx1d < T>( ) { }
01745
01755 Img1d( Long w, T *data = 0, bool isOwner = false ): Imx1d < T>( ) { New(w, data, isOwner); }
01756
01766 Img1d( const Dimension1d &d, T *data = 0, bool isOwner = false ): Imx1d < T>( ) { New(d.w, data, isOwner); }
01767
01778 Img1d( const PobjectProps &p, T *data = 0, bool isOwner = false ): Imx1d < T>( ) { New(p, data, isOwner); }
01779
01788 void New( Long w, T *data = 0, bool isOwner = false ) { Imx1d < T>::New(1, w, data, isOwner); }
01789
01798 void New( const Dimension1d &d, T *data = 0, bool isOwner = false ) { New(d.w, data, isOwner); }
01799
01808 void New( const PobjectProps &p, T *data = 0, bool isOwner = false ) { New(p.ncol, data, isOwner); ColorSpace(p.colorspace); }
01809
01814 Pobject* Clone( ) const {
01815 Img1d < T > *tmp = new Img1d < T >(ncol);
01816 *tmp = *this;
01817 return tmp;
01818 }
01819
01820
01821
01822
01823
01824
01825
01826 Img1d < T > &operator=( const T val ) {
01827 Imx1d < T>::operator=(val);
01828 return *this;
01829 }
01830
01837 template< typename U >
01838 Img1d < T > &operator=( const Img1d < U > &src ) {
01839 Imx1d < T>::operator=(src);
01840 return *this;
01841 }
01842
01849 Img1d < T > &operator=( const Img1d < T > &src ) {
01850 Imx1d < T>::operator=(src);
01851 return *this;
01852 }
01853
01857 ValueType* Vector( ) const { return Imx1d < T>::Vector( 0 ); }
01858
01863 ValueType &operator[]( Long col ) { return Imx1d < T>::operator()(0, col); }
01864
01869 const ValueType &operator[]( Long col ) const { return Imx1d < T>::operator()(0, col); }
01870
01876 ValueType &operator()( Long x ) { return Imx1d < T>::operator()(0, x); }
01877
01882 ValueType &operator[]( const Point1d &p ) { return Imx1d < T>::operator()(0, p.x); }
01883
01888 const ValueType &operator[]( const Point1d &p ) const { return Imx1d < T>::operator()(0, p.x); }
01889
01894 ValueType &operator()( const Point1d &p ) { return Imx1d < T>::operator()(0, p.x); }
01895
01900 const ValueType &operator()( const Point1d &p ) const { return Imx1d < T>::operator()(0, p.x); }
01901
01908 Img1d( const Img1d &ims ): Imx1d < T>() { New(ims.Props()); *this = ims; }
01909 };
01910
01914
01922 template< typename T >
01923 class Img2d: public Imx2d < T> {
01924 protected:
01925 using Imx2d < T>::nbands;
01926 using Imx2d < T>::nrow;
01927 using Imx2d < T>::ncol;
01928 using Imx2d < T>::ColorSpace;
01929
01930 public:
01932 typedef T ValueType;
01933
01937 Typobj Type( ) const { return ( Typobj )Po_type< Img2d < T > >::type; }
01938
01942 std::string Name( ) const { return TypeName< Img2d < T > >::Name( ); }
01943
01947 Img2d( ): Imx2d < T>( ) {}
01948
01959 Img2d( Long h, Long w, T *data = 0, bool isOwner = false ): Imx2d < T>( ) { New(h, w, data, isOwner); }
01960
01970 Img2d( const Dimension2d &d, T *data = 0, bool isOwner = false ): Imx2d < T>( ) { New(d.h, d.w, data, isOwner); }
01971
01982 Img2d( const PobjectProps &p, T *data = 0, bool isOwner = false ): Imx2d < T>( ) { New(p, data, isOwner); }
01983
01993 void New( Long h, Long w, T *data = 0, bool isOwner = false ) { Imx2d < T>::New(1, h, w, data, isOwner); }
01994
02003 void New( const Dimension2d &d, T *data = 0, bool isOwner = false ) { New(d.h, d.w, data, isOwner); }
02004
02013 void New( const PobjectProps &p, T *data = 0, bool isOwner = false ) { New(p.nrow, p.ncol, data, isOwner); ColorSpace(p.colorspace); }
02014
02019 Pobject* Clone( ) const {
02020 Img2d < T > *tmp = new Img2d < T >(nrow, ncol);
02021 *tmp = *this;
02022 return tmp;
02023 }
02024
02025
02026
02027
02028
02029
02030
02031 Img2d < T > &operator=( const T val ) {
02032 Imx2d < T>::operator=( val );
02033 return *this;
02034 }
02035
02042 template< typename U >
02043 Img2d < T > &operator=( const Img2d < U > &src ) {
02044 Imx2d < T>::operator=( src );
02045 return *this;
02046 }
02047
02054 Img2d < T > &operator=( const Img2d < T > &src ) {
02055 Imx2d < T>::operator=( src );
02056 return *this;
02057 }
02058
02062 ValueType* Vector( ) const {
02063 return Imx2d < T>::Vector( 0 );
02064 }
02065
02066
02071 typename Imx3d < T>::Band1d operator[]( Long row ) { return Imx2d < T>::operator[](0)[row]; }
02072
02077 const typename Imx3d < T>::Band1d operator[]( Long row ) const { return Imx2d < T>::operator[](0)[row]; }
02078
02085 ValueType &operator()( Long y, Long x ) { return Imx2d < T>::operator()(0, y, x); }
02086
02093 const ValueType &operator()( Long y, Long x ) const { return Imx2d < T>::operator()(0, y, x); }
02094
02099 ValueType &operator[]( const Point2d &p ) { return Imx2d < T>::operator()(0, p.y, p.x); }
02100
02105 const ValueType &operator[]( const Point2d &p ) const { return Imx2d < T>::operator()(0, p.y, p.x); }
02106
02111 ValueType &operator()( int, const Point2d &p ) { return Imx2d < T>::operator()(0, p.y, p.x); }
02112
02117 const ValueType &operator()( int, const Point2d &p ) const { return Imx2d < T>::operator()(0, p.y, p.x); }
02118
02123 ValueType &operator()( const Point2d &p ) { return Imx2d < T>::operator()(0, p.y, p.x); }
02124
02129 const ValueType &operator()( const Point2d &p ) const { return Imx2d < T>::operator()(0, p.y, p.x); }
02130
02137 Img2d( const Img2d &ims ): Imx2d < T>() { New(ims.Props()); *this = ims; }
02138 };
02139
02143
02151 template <typename T>
02152 class Img3d: public Imx3d < T> {
02153 protected:
02154 using Imx3d < T>::nbands;
02155 using Imx3d < T>::ncol;
02156 using Imx3d < T>::nrow;
02157 using Imx3d < T>::ndep;
02158 using Imx3d < T>::ColorSpace;
02159
02160 public:
02162 typedef T ValueType;
02163
02164
02168 Typobj Type( ) const { return ( Typobj )Po_type< Img3d < T > >::type; }
02169
02173 std::string Name( ) const { return TypeName< Img3d < T > >::Name( ); }
02174
02178 Img3d( ): Imx3d < T>( ) { }
02179
02191 Img3d( Long d, Long h, Long w, T *data = 0, bool isOwner = false ): Imx3d < T>( ) { New(d, h, w, data, isOwner); }
02192
02202 Img3d( const Dimension3d &d, T *data = 0, bool isOwner = false ): Imx3d < T>( ) { New(d.d, d.h, d.w, data, isOwner); }
02203
02214 Img3d( const PobjectProps &p, T *data = 0, bool isOwner = false ): Imx3d < T>( ) { New(p, data, isOwner); }
02215
02226 void New( Long d, Long h, Long w, T *data = 0, bool isOwner = false ) {
02227 Imx3d < T>::New(1, d, h, w, data, isOwner);
02228 }
02229
02238 void New( const Dimension3d &d, T *data = 0, bool isOwner = false ) {
02239 New(d.d, d.h, d.w, data, isOwner);
02240 }
02241
02250 void New( const PobjectProps &p, T *data = 0, bool isOwner = false ) {
02251 New(p.ndep, p.nrow, p.ncol, data, isOwner);
02252 ColorSpace(p.colorspace);
02253 }
02254
02259 Pobject* Clone( ) const {
02260 Img3d < T > *tmp = new Img3d < T >(ndep, nrow, ncol);
02261 *tmp = *this;
02262 return tmp;
02263 }
02264
02265
02266
02267
02268
02269
02270
02271
02272 Img3d < T > &operator=( const T val ) {
02273 Imx3d < T>::operator=( val );
02274 return *this;
02275 }
02276
02283 template< typename U >
02284 Img3d < T > &operator=( const Img3d < U > &src ) { Imx3d < T>::operator=( src ); return *this; }
02285
02292 Img3d < T > &operator=( const Img3d < T > &src ) { Imx3d < T>::operator=( src ); return *this; }
02293
02297 ValueType* Vector( ) const { return Imx3d < T>::Vector(0); }
02298
02303 typename Imx3d < T>::Band2d operator[]( Long dep ) { return Imx3d < T>::operator[](0)[dep]; }
02304
02309 const typename Imx3d < T>::Band2d operator[]( Long dep ) const { return Imx3d < T>::operator[](0)[dep]; }
02310
02318 ValueType &operator()( Long z, Long y, Long x ) { return Imx3d < T>::operator()(0, z, y, x); }
02319
02327 const ValueType &operator()( Long z, Long y, Long x ) const { return Imx3d < T>::operator()(0, z, y, x); }
02328
02333 ValueType &operator[]( const Point3d &p ) {return operator()(p.z, p.y, p.x); }
02334
02339 const ValueType &operator[]( const Point3d &p ) const { return operator()(p.z, p.y, p.x); }
02340
02345 ValueType &operator()( const Point3d &p ) {return operator()(p.z, p.y, p.x); }
02346
02351 const ValueType &operator()( const Point3d &p ) const { return operator()(p.z, p.y, p.x); }
02352
02357 const ValueType &operator()( int, const Point3d &p ) const { return operator()(p.z, p.y, p.x); }
02358
02363 ValueType &operator()( int, const Point3d &p ) {return operator()(p.z, p.y, p.x); }
02364
02371 Img3d( const Img3d &ims ): Imx3d < T>() {
02372 New(ims.Props());
02373 *this = ims;
02374 }
02375 };
02376
02380
02388 template< typename T >
02389 class Imc2d: public Imx2d < T> {
02390 protected:
02391 using Imx2d < T>::nbands;
02392 using Imx2d < T>::ncol;
02393 using Imx2d < T>::nrow;
02394
02395 public:
02396 using Imx2d < T>::ColorSpace;
02397
02399 typedef T ValueType;
02400
02402 typename Imx3d < T>::Band2d X;
02403
02405 typename Imx3d < T>::Band2d Y;
02406
02408 typename Imx3d < T>::Band2d Z;
02409
02413 Typobj Type( ) const { return ( Typobj )Po_type< Imc2d < T > >::type; }
02414
02418 std::string Name( ) const { return TypeName< Imc2d < T > >::Name( ); }
02419
02423 Imc2d( ): Imx2d < T>( ) { }
02424
02435 Imc2d( Long h, Long w, T *data = 0, bool isOwner = false ): Imx2d < T> ( ) {
02436 New(h, w, data, isOwner);
02437 }
02438
02448 Imc2d( const Dimension2d &d, T *data = 0, bool isOwner = false ): Imx2d < T>( ) {
02449 New(d, data, isOwner);
02450 }
02451
02465 Imc2d( Long b, const Dimension2d &d, T *data = 0, bool isOwner = false ): Imx2d < T>( ) {
02466 New(b, d.h, d.w, data, isOwner);
02467 }
02468
02480 Imc2d( Long b, Long h, Long w, T *data = 0, bool isOwner = false ): Imx2d < T>( ) {
02481 New(b, h, w, data, isOwner);
02482 }
02483
02494 Imc2d( const PobjectProps &p, T *data = 0, bool isOwner = false ): Imx2d < T>( ) {
02495 New(p, data, isOwner);
02496 }
02497
02508 void New( Long h, Long w, T *data = 0, bool isOwner = false ) {
02509 Imx2d < T>::New(3, h, w, data, isOwner);
02510
02511 X.New(this, Imx2d < T>::Vector(0));
02512 Y.New(this, Imx2d < T>::Vector(1));
02513 Z.New(this, Imx2d < T>::Vector(2));
02514 }
02515
02527 void New( Long , Long h, Long w, T *data = 0, bool isOwner = false ) { New(h, w, data, isOwner); }
02528
02538 void New( const Dimension2d &d, T *data = 0, bool isOwner = false ) { New(d.h, d.w, data, isOwner); }
02539
02550 void New( Long , const Dimension2d &d, T *data = 0, bool isOwner = false ) { New(d.h, d.w, data, isOwner); }
02551
02558 void New( const PobjectProps &p, T *data = 0, bool isOwner = false ) {
02559 ColorSpace(p.colorspace);
02560 New(p.nrow, p.ncol, data, isOwner);
02561 }
02562
02569 Pobject* Clone( ) const {
02570 Imc2d < T > *tmp = new Imc2d < T >(nrow, ncol);
02571 *tmp = *this;
02572 return tmp;
02573 }
02574
02575
02576
02577
02578
02579
02580
02581
02582 Imc2d < T > &operator=( const T val ) {
02583 Imx2d < T>::operator=( val );
02584 return *this;
02585 }
02586
02593 template< typename U >
02594 Imc2d < T > &operator=( const Imc2d < U > &src ) { Imx2d < T>::operator=( src ); return *this; }
02595
02602 Imc2d < T > &operator=( const Imc2d < T > &src ) { Imx2d < T>::operator=( src ); return *this; }
02603
02608 ValueType* VectorX( ) const { return Imx2d < T>::Vector( 0 ); }
02609
02614 ValueType* VectorY( ) const { return Imx2d < T>::Vector( 1 ); }
02615
02620 ValueType* VectorZ( ) const { return Imx2d < T>::Vector( 2 ); }
02621
02622
02630 Errc LoadAttributes( FILE *file ) {
02631 Long attr[3];
02632
02633 if (this->Fdecode((void*)attr, sizeof(*attr), 3, file) < 3) {
02634 return FAILURE;
02635 }
02636 New(attr[1], attr[2]);
02637
02638 PColorSpace c;
02639 if (this->Fdecode((void*)&c, sizeof(c), 1, file) < 1) {
02640 return FAILURE;
02641 }
02642 ColorSpace(c);
02643 return SUCCESS;
02644 }
02645
02651 Errc SaveAttributes( FILE *file ) const {
02652 if (Imx2d < T>::SaveAttributes(file) == FAILURE) {
02653 return FAILURE;
02654 }
02655
02656 PColorSpace c = ColorSpace();
02657 if (this->Fencode((void*)&c, sizeof(c), 1, file) < 1) {
02658 return FAILURE;
02659 }
02660 return SUCCESS;
02661 }
02662
02669 Imc2d( const Imc2d &ims ): Imx2d < T>() {
02670 New(ims.Props());
02671 *this = ims;
02672 }
02673 };
02674
02678
02686 template< typename T >
02687 class Imc3d: public Imx3d < T> {
02688 protected:
02689 using Imx3d < T>::nbands;
02690 using Imx3d < T>::ncol;
02691 using Imx3d < T>::nrow;
02692 using Imx3d < T>::ndep;
02693
02694 public:
02695 using Imx3d < T>::ColorSpace;
02696
02698 typedef T ValueType;
02699
02701 typename Imx3d < T>::Band3d X;
02702
02704 typename Imx3d < T>::Band3d Y;
02705
02707 typename Imx3d < T>::Band3d Z;
02708
02712 Typobj Type( ) const { return ( Typobj )Po_type< Imc3d < T > >::type; }
02713
02717 std::string Name( ) const { return TypeName< Imc3d <T> >::Name( ); }
02718
02722 Imc3d( ): Imx3d < T>( ) { }
02723
02736 Imc3d( Long b, Long d, Long h, Long w, T *data = 0, bool isOwner = false ): Imx3d < T>( ) { New(b, d, h, w, data, isOwner); }
02737
02748 Imc3d( Long b, const Dimension3d &d, T *data = 0, bool isOwner = false ): Imx3d < T>( ) { New(b, d, data, isOwner); }
02749
02761 Imc3d( Long d, Long h, Long w, T *data = 0, bool isOwner = false ): Imx3d < T>( ) { New(d, h, w, data, isOwner); }
02762
02772 Imc3d( const Dimension3d &d, T *data = 0, bool isOwner = false ): Imx3d < T>( ) { New(d, data, isOwner); }
02773
02784 Imc3d( const PobjectProps &p, T *data = 0, bool isOwner = false ): Imx3d < T>( ) { New(p, data, isOwner); }
02785
02798 void New( Long , Long d, Long h, Long w, T *data = 0, bool isOwner = false ) { New(d, h, w, data, isOwner); }
02799
02810 void New( Long , const Dimension3d &d, T *data = 0, bool isOwner = false ) { New(d.d, d.h, d.w, data, isOwner); }
02811
02823 void New( Long d, Long h, Long w, T *data = 0, bool isOwner = false ) {
02824 Imx3d < T>::New(3, d, h, w, data, isOwner);
02825
02826 X.New(this, Imx3d < T>::Vector(0));
02827 Y.New(this, Imx3d < T>::Vector(1));
02828 Z.New(this, Imx3d < T>::Vector(2));
02829 }
02839 void New( const Dimension3d &d, T *data = 0, bool isOwner = false ) {
02840 New(d.d, d.h, d.w, data, isOwner);
02841 }
02842
02849 void New( const PobjectProps &p, T* data = 0, bool isOwner = false ) {
02850 ColorSpace(p.colorspace);
02851 New(p.ndep, p.nrow, p.ncol, data, isOwner);
02852 }
02853
02858 Pobject* Clone( ) const {
02859 Imc3d < T > *tmp = new Imc3d < T >(ndep, nrow, ncol);
02860 *tmp = *this;
02861 return tmp;
02862 }
02863
02864
02865
02866
02867
02868
02869
02870
02871 Imc3d < T > &operator=( const T val ) {
02872 Imx3d < T>::operator=(val);
02873 return *this;
02874 }
02875
02882 template< typename U >
02883 Imc3d < T > &operator=( const Imc3d < U > &src ) {
02884 Imx3d < T>::operator=(src);
02885 return *this;
02886 }
02887
02894 Imc3d < T > &operator=( const Imc3d < T > &src ) {
02895 Imx3d < T>::operator=(src);
02896 return *this;
02897 }
02898
02903 ValueType* VectorX( ) const {
02904 return Imx3d < T>::Vector(0);
02905 }
02906
02911 ValueType* VectorY( ) const {
02912 return Imx3d < T>::Vector(1);
02913 }
02914
02919 ValueType* VectorZ( ) const {
02920 return Imx3d < T>::Vector(2);
02921 }
02922
02930 Errc LoadAttributes( FILE *file ) {
02931 Long attr[4];
02932
02933 if (this->Fdecode((void*)attr, sizeof(*attr), 4, file) < 4) {
02934 return FAILURE;
02935 }
02936 New(attr[1], attr[2], attr[3]);
02937
02938 PColorSpace c;
02939 if (this->Fdecode((void*)&c, sizeof(c), 1, file) < 1) {
02940 return FAILURE;
02941 }
02942 ColorSpace(c);
02943 return SUCCESS;
02944 }
02945
02951 Errc SaveAttributes( FILE *file ) const {
02952 if (Imx3d < T>::SaveAttributes(file) == FAILURE) {
02953 return FAILURE;
02954 }
02955 PColorSpace c=ColorSpace();
02956 if (this->Fencode((void*)&c, sizeof(c), 1, file) < 1) {
02957 return FAILURE;
02958 }
02959 return SUCCESS;
02960 }
02961
02968 Imc3d( const Imc3d &ims ): Imx3d < T>() { New(ims.Props()); *this = ims; }
02969 };
02970
02971 typedef Imx1d < Uchar > Imx1duc;
02972 typedef Imx1d < Long > Imx1dsl;
02973 typedef Imx1d < Float > Imx1dsf;
02974
02975 typedef Imx2d < Uchar > Imx2duc;
02976 typedef Imx2d < Long > Imx2dsl;
02977 typedef Imx2d < Float > Imx2dsf;
02978
02979 typedef Imx3d < Uchar > Imx3duc;
02980 typedef Imx3d < Long > Imx3dsl;
02981 typedef Imx3d < Float > Imx3dsf;
02982
02983 typedef Img1d < Uchar > Img1duc;
02984 typedef Img1d < Long > Img1dsl;
02985 typedef Img1d < Float > Img1dsf;
02986
02987 typedef Img2d < Uchar > Img2duc;
02988 typedef Img2d < Long > Img2dsl;
02989 typedef Img2d < Float > Img2dsf;
02990
02991 typedef Img3d < Uchar > Img3duc;
02992 typedef Img3d < Long > Img3dsl;
02993 typedef Img3d < Float > Img3dsf;
02994
02995 typedef Imc2d < Uchar > Imc2duc;
02996 typedef Imc2d < Long > Imc2dsl;
02997 typedef Imc2d < Float > Imc2dsf;
02998
02999 typedef Imc3d < Uchar > Imc3duc;
03000 typedef Imc3d < Long > Imc3dsl;
03001 typedef Imc3d < Float > Imc3dsf;
03002
03003
03004
03005
03006
03007
03008 template<> struct Po_type<Img1duc> {
03009 enum {type = Po_Img1duc };
03010 };
03011
03012
03013
03014
03015
03016
03017 template<> struct TypeName< Img1duc > {
03018 static std::string Name( ) { return "Img1duc"; }
03019 };
03020
03021
03022
03023
03024
03025 template<> struct Po_type<Img1dsl> {
03026 enum {type = Po_Img1dsl };
03027 };
03028
03029
03030
03031
03032
03033
03034 template<> struct TypeName< Img1dsl > {
03035 static std::string Name( ) { return "Img1dsl"; }
03036 };
03037
03038
03039
03040
03041
03042 template<> struct Po_type<Img1dsf> {
03043 enum {type = Po_Img1dsf };
03044 };
03045
03046
03047
03048
03049
03050
03051 template<> struct TypeName< Img1dsf > {
03052 static std::string Name( ) { return "Img1dsf"; }
03053 };
03054
03055
03056
03057
03058
03059 template<> struct Po_type<Img2duc> {
03060 enum {type = Po_Img2duc };
03061 };
03062
03063
03064
03065
03066
03067
03068 template<> struct TypeName< Img2duc > {
03069 static std::string Name( ) { return "Img2duc"; }
03070 };
03071
03072
03073
03074
03075
03076 template<> struct Po_type<Img2dsl> {
03077 enum {type = Po_Img2dsl };
03078 };
03079
03080
03081
03082
03083
03084
03085 template<> struct TypeName< Img2dsl > {
03086 static std::string Name( ) { return "Img2dsl"; }
03087 };
03088
03089
03090
03091
03092
03093 template<> struct Po_type<Img2dsf> {
03094 enum {type = Po_Img2dsf };
03095 };
03096
03097
03098
03099
03100
03101
03102 template<> struct TypeName< Img2dsf > {
03103 static std::string Name( ) { return "Img2dsf"; }
03104 };
03105
03106
03107
03108
03109
03110 template<> struct Po_type<Img3duc> {
03111 enum {type = Po_Img3duc };
03112 };
03113
03114
03115
03116
03117
03118
03119 template<> struct TypeName< Img3duc > {
03120 static std::string Name( ) { return "Img3duc"; }
03121 };
03122
03123
03124
03125
03126
03127 template<> struct Po_type<Img3dsl> {
03128 enum {type = Po_Img3dsl };
03129 };
03130
03131
03132
03133
03134
03135
03136 template<> struct TypeName< Img3dsl > {
03137 static std::string Name( ) { return "Img3dsl"; }
03138 };
03139
03140
03141
03142
03143
03144 template<> struct Po_type<Img3dsf> {
03145 enum {type = Po_Img3dsf };
03146 };
03147
03148
03149
03150
03151
03152
03153 template<> struct TypeName< Img3dsf > {
03154 static std::string Name( ) { return "Img3dsf"; }
03155 };
03156
03157
03158
03159
03160
03161 template<> struct Po_type<Imc2duc> {
03162 enum {type = Po_Imc2duc };
03163 };
03164
03165
03166
03167
03168
03169
03170 template<> struct TypeName< Imc2duc > {
03171 static std::string Name( ) { return "Imc2duc"; }
03172 };
03173
03174
03175
03176
03177
03178 template<> struct Po_type<Imc2dsl> {
03179 enum {type = Po_Imc2dsl };
03180 };
03181
03182
03183
03184
03185
03186
03187 template<> struct TypeName< Imc2dsl > {
03188 static std::string Name( ) { return "Imc2dsl"; }
03189 };
03190
03191
03192
03193
03194
03195 template<> struct Po_type<Imc2dsf> {
03196 enum {type = Po_Imc2dsf };
03197 };
03198
03199
03200
03201
03202
03203
03204 template<> struct TypeName< Imc2dsf > {
03205 static std::string Name( ) { return "Imc2dsf"; }
03206 };
03207
03208
03209
03210
03211
03212 template<> struct Po_type<Imc3duc> {
03213 enum {type = Po_Imc3duc };
03214 };
03215
03216
03217
03218
03219
03220
03221 template<> struct TypeName< Imc3duc > {
03222 static std::string Name( ) { return "Imc3duc"; }
03223 };
03224
03225
03226
03227
03228
03229 template<> struct Po_type<Imc3dsl> {
03230 enum {type = Po_Imc3dsl };
03231 };
03232
03233
03234
03235
03236
03237
03238 template<> struct TypeName< Imc3dsl > {
03239 static std::string Name( ) { return "Imc3dsl"; }
03240 };
03241
03242
03243
03244
03245
03246 template<> struct Po_type<Imc3dsf> {
03247 enum {type = Po_Imc3dsf };
03248 };
03249
03250
03251
03252
03253
03254
03255 template<> struct TypeName< Imc3dsf > {
03256 static std::string Name( ) { return "Imc3dsf"; }
03257 };
03258
03259
03260
03261
03262
03263 template<> struct Po_type<Imx1duc> {
03264 enum {type = Po_Imx1duc };
03265 };
03266
03267
03268
03269
03270
03271
03272 template<> struct TypeName< Imx1duc > {
03273 static std::string Name( ) { return "Imx1duc"; }
03274 };
03275
03276
03277
03278
03279
03280 template<> struct Po_type<Imx1dsl> {
03281 enum {type = Po_Imx1dsl };
03282 };
03283
03284
03285
03286
03287
03288
03289 template<> struct TypeName< Imx1dsl > {
03290 static std::string Name( ) { return "Imx1dsl"; }
03291 };
03292
03293
03294
03295
03296
03297 template<> struct Po_type<Imx1dsf> {
03298 enum {type = Po_Imx1dsf };
03299 };
03300
03301
03302
03303
03304
03305
03306 template<> struct TypeName< Imx1dsf > {
03307 static std::string Name( ) { return "Imx1dsf"; }
03308 };
03309
03310
03311
03312
03313
03314 template<> struct Po_type<Imx2duc> {
03315 enum {type = Po_Imx2duc };
03316 };
03317
03318
03319
03320
03321
03322
03323 template<> struct TypeName< Imx2duc > {
03324 static std::string Name( ) { return "Imx2duc"; }
03325 };
03326
03327
03328
03329
03330
03331 template<> struct Po_type<Imx2dsl> {
03332 enum {type = Po_Imx2dsl };
03333 };
03334
03335
03336
03337
03338
03339
03340 template<> struct TypeName< Imx2dsl > {
03341 static std::string Name( ) { return "Imx2dsl"; }
03342 };
03343
03344
03345
03346
03347
03348 template<> struct Po_type<Imx2dsf> {
03349 enum {type = Po_Imx2dsf };
03350 };
03351
03352
03353
03354
03355
03356
03357 template<> struct TypeName< Imx2dsf > {
03358 static std::string Name( ) { return "Imx2dsf"; }
03359 };
03360
03361
03362
03363
03364
03365 template<> struct Po_type<Imx3duc> {
03366 enum {type = Po_Imx3duc };
03367 };
03368
03369
03370
03371
03372
03373
03374 template<> struct TypeName< Imx3duc > {
03375 static std::string Name( ) { return "Imx3duc"; }
03376 };
03377
03378
03379
03380
03381
03382 template<> struct Po_type<Imx3dsl> {
03383 enum {type = Po_Imx3dsl };
03384 };
03385
03386
03387
03388
03389
03390
03391 template<> struct TypeName< Imx3dsl > {
03392 static std::string Name( ) { return "Imx3dsl"; }
03393 };
03394
03395
03396
03397
03398
03399 template<> struct Po_type<Imx3dsf> {
03400 enum {type = Po_Imx3dsf };
03401 };
03402
03403
03404
03405
03406
03407
03408 template<> struct TypeName< Imx3dsf > {
03409 static std::string Name( ) { return "Imx3dsf"; }
03410 };
03411
03412 }
03413
03414 #endif // __PIMAGEH__