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
00039 #ifndef CUDAIMAGE_H_DEFINED
00040 #define CUDAIMAGE_H_DEFINED
00041
00042 #include "Util/Assert.H"
00043 #include "Util/Promotions.H"
00044 #include "Image/ArrayData.H"
00045 #include "Image/Point2D.H"
00046 #include "Image/Rectangle.H"
00047 #include "Image/Image.H"
00048 #include "Image/Pixels.H"
00049 #include "CUDA/wrap_c_cuda.h"
00050 #include <algorithm>
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 template <class T>
00063 class CudaImage
00064 {
00065 public:
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 inline CudaImage(const T* inarray, int width, int height, const MemoryPolicy mp, const int dev, const MemoryPolicy srcmp, const int srcdev);
00076
00077
00078
00079
00080
00081 inline CudaImage(const T* inarray, const Dims& dims, const MemoryPolicy mp, const int dev, const MemoryPolicy srcmp, const int srcdev);
00082
00083
00084 inline CudaImage(int width, int height, InitPolicy init, const MemoryPolicy mp, const int dev);
00085
00086
00087 inline explicit CudaImage(const Dims& dims, const MemoryPolicy mp, const int dev);
00088
00089
00090 inline explicit CudaImage(const Dims& dims, InitPolicy init, const MemoryPolicy mp, const int dev);
00091
00092
00093 inline CudaImage();
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 inline CudaImage(const CudaImage<T>& A);
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 inline CudaImage(const CudaImage<T>& A, const MemoryPolicy mp, const int dev);
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 inline CudaImage(const Image<T>& A, const MemoryPolicy mp, const int dev);
00124
00125
00126
00127
00128
00129
00130
00131 inline CudaImage<T>& operator=(const CudaImage<T>& A);
00132
00133
00134 inline ~CudaImage();
00135
00136
00137
00138
00139
00140
00141
00142 inline void freeMem();
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 inline CudaImage<float>& operator+=(const float val);
00153
00154
00155 inline CudaImage<float>& operator-=(const float val);
00156
00157
00158 inline CudaImage<float>& operator*=(const float val);
00159
00160
00161 inline CudaImage<float>& operator/=(const float val);
00162
00163
00164 inline CudaImage<float>& operator+=(const CudaImage<float>& im);
00165
00166
00167 inline CudaImage<float>& operator-=(const CudaImage<float>& im);
00168
00169
00170 inline CudaImage<float>& operator*=(const CudaImage<float>& im);
00171
00172
00173 inline CudaImage<float>& operator/=(const CudaImage<float>& im);
00174
00175
00176 inline CudaImage<float> operator+(const float val) const;
00177
00178
00179 inline CudaImage<float> operator-(const float val) const;
00180
00181
00182 inline CudaImage<float> operator*(const float val) const;
00183
00184
00185 inline CudaImage<float> operator/(const float val) const;
00186
00187
00188 inline CudaImage<float> operator+(const CudaImage<float>& im) const;
00189
00190
00191 inline CudaImage<float> operator-(const CudaImage<float>& im) const;
00192
00193
00194 inline CudaImage<float> operator*(const CudaImage<float>& im) const;
00195
00196
00197 inline CudaImage<float> operator/(const CudaImage<float>& im) const;
00198
00199
00200
00201
00202
00203
00204
00205
00206 inline void swap(CudaImage<T>& other);
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 inline CudaImage<T> deepcopy() const;
00253
00254
00255
00256
00257
00258 inline CudaImage<T> deepcopy(const MemoryPolicy mp, const int dev) const;
00259
00260 inline Image<T> exportToImage() const;
00261
00262
00263
00264 inline void resize(const Dims& dims, const bool clear = false);
00265
00266
00267
00268 inline void resize(const int width, const int height,
00269 const bool clear = false);
00270
00271
00272
00273
00274
00275
00276
00277
00278 inline bool initialized() const;
00279
00280
00281 inline int getSize() const;
00282
00283
00284 inline uint size() const;
00285
00286
00287 inline int getWidth() const;
00288
00289
00290 inline int getHeight() const;
00291
00292
00293 inline const Dims& getDims() const;
00294
00295
00296 inline Rectangle getBounds() const;
00297
00298
00299
00300
00301 template <class C>
00302 inline bool isSameSize(const C& other) const;
00303
00304
00305 inline bool is1D() const;
00306
00307
00308 inline bool isVector() const;
00309
00310
00311 inline bool isTransposedVector() const;
00312
00313
00314 inline bool isSquare() const;
00315
00316
00317 inline const T* getCudaArrayPtr() const;
00318
00319
00320 inline T* getCudaArrayPtr();
00321
00322
00323 inline bool coordsOk(const Point2D<int>& P) const;
00324
00325
00326 inline bool coordsOk(const int i, const int j) const;
00327
00328
00329
00330 inline bool coordsOk(const Point2D<float>& p) const;
00331
00332
00333
00334 inline bool coordsOk(const float i, const float j) const;
00335
00336
00337 inline bool rectangleOk(const Rectangle& rect) const;
00338
00339
00340 inline MemoryPolicy getMemoryPolicy() const;
00341
00342
00343 inline int getMemoryDevice() const;
00344
00345
00346
00347
00348 inline void clear(const char& val = 0);
00349
00350
00351
00352
00353
00354
00355
00356
00357 bool hasSameData(const CudaImage<T>& b) const;
00358
00359
00360
00361 long refCount() const throw();
00362
00363
00364
00365 bool isShared() const throw();
00366
00367
00368
00369 private:
00370
00371
00372
00373 ArrayHandle<T> itsHdl;
00374 inline const ArrayData<T>& impl() const;
00375 inline ArrayData<T>& uniq();
00376
00377 };
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409 template <class T>
00410 inline CudaImage<T> reshape(const CudaImage<T>& orig, const Dims& newdims)
00411 {
00412 ASSERT(orig.getDims().sz() == newdims.sz());
00413 return CudaImage<T>(orig.getCudaArrayPtr(), newdims, orig.getMemoryPolicy(), orig.getMemoryDevice(), orig.getMemoryPolicy(), orig.getMemoryDevice());
00414 }
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429 template <class T> inline
00430 CudaImage<T>::CudaImage(const T* inarray, int width, int height, MemoryPolicy trgmp, int trgdev, const MemoryPolicy srcmp, const int srcdev) :
00431 itsHdl(new ArrayData<T>(Dims(width, height), inarray, trgmp, trgdev, srcmp, srcdev))
00432 {}
00433
00434
00435 template <class T> inline
00436 CudaImage<T>::CudaImage(const T* inarray, const Dims& dims, MemoryPolicy trgmp, int trgdev, const MemoryPolicy srcmp, const int srcdev) :
00437 itsHdl(new ArrayData<T>(dims, inarray, trgmp, trgdev, srcmp, srcdev))
00438 {}
00439
00440
00441 template <class T> inline
00442 CudaImage<T>::CudaImage(int width, int height, InitPolicy init, MemoryPolicy mp, int dev) :
00443 itsHdl(new ArrayData<T>(Dims(width, height), init, mp, dev))
00444 {}
00445
00446
00447 template <class T> inline
00448 CudaImage<T>::CudaImage(const Dims& dims, const MemoryPolicy mp, const int dev) :
00449 itsHdl(new ArrayData<T>(dims, NO_INIT, mp, dev))
00450 {}
00451
00452
00453 template <class T> inline
00454 CudaImage<T>::CudaImage(const Dims& dims, InitPolicy init, const MemoryPolicy mp, const int dev) :
00455 itsHdl(new ArrayData<T>(dims, init, mp, dev))
00456 {}
00457
00458
00459 template <class T> inline
00460 CudaImage<T>::CudaImage() :
00461 itsHdl(new ArrayData<T>())
00462 {}
00463
00464
00465 template <class T> inline
00466 CudaImage<T>::CudaImage(const CudaImage<T>& A) :
00467 itsHdl(A.itsHdl)
00468 {}
00469
00470
00471 template <class T> inline
00472 CudaImage<T>::CudaImage(const CudaImage<T>& A, const MemoryPolicy mp, const int dev) :
00473 itsHdl(new ArrayData<T>(A.getDims(), NO_INIT, mp,dev))
00474 {
00475
00476 const MemoryPolicy srcmp = A.getMemoryPolicy();
00477 const int srcdev = A.getMemoryDevice();
00478
00479
00480 int n = size();
00481 ArrayHelper<T>::copy_initialize(getCudaArrayPtr(),n,A.getCudaArrayPtr(),mp,dev,srcmp,srcdev);
00482 }
00483
00484 template <class T> inline
00485 CudaImage<T>::CudaImage(const Image<T>& A, const MemoryPolicy mp, const int dev) :
00486 itsHdl(new ArrayData<T>(A.getDims(), NO_INIT, mp,dev))
00487 {
00488
00489
00490 int n = size();
00491 ArrayHelper<T>::copy_initialize(getCudaArrayPtr(),n,A.getArrayPtr(),mp,dev,HOST_MEMORY,CUDA_HOST_DEVICE_NUM);
00492 }
00493
00494
00495 template <class T> inline
00496 CudaImage<T>& CudaImage<T>::operator=(const CudaImage<T>& A)
00497 {
00498 CudaImage<T> A_copy( A );
00499 this->swap(A_copy);
00500 return *this;
00501 }
00502
00503 template <class T> inline
00504 CudaImage<float>& CudaImage<T>::operator+=(const float val)
00505 {
00506 const int dev = this->getMemoryDevice();
00507 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00508
00509 cuda_c_inplaceAddHostScalar(this->getCudaArrayPtr(), val, tile.sz(), this->size());
00510 return *this;
00511 }
00512
00513 template <class T> inline
00514 CudaImage<float>& CudaImage<T>::operator-=(const float val)
00515 {
00516 const int dev = this->getMemoryDevice();
00517 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00518
00519 cuda_c_inplaceSubtractHostScalar(this->getCudaArrayPtr(), val, tile.sz(), this->size());
00520 return *this;
00521 }
00522
00523 template <class T> inline
00524 CudaImage<float>& CudaImage<T>::operator*=(const float val)
00525 {
00526 const int dev = this->getMemoryDevice();
00527 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00528
00529 cuda_c_inplaceMultiplyHostScalar(this->getCudaArrayPtr(), val, tile.sz(), this->size());
00530 return *this;
00531 }
00532
00533 template <class T> inline
00534 CudaImage<float>& CudaImage<T>::operator/=(const float val)
00535 {
00536 const int dev = this->getMemoryDevice();
00537 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00538
00539 cuda_c_inplaceDivideHostScalar(this->getCudaArrayPtr(), val, tile.sz(), this->size());
00540 return *this;
00541 }
00542
00543
00544
00545
00546 template <class T> inline
00547 CudaImage<float>& CudaImage<T>::operator+=(const CudaImage<float>& im)
00548 {
00549 ASSERT(im.initialized());
00550 ASSERT(this->getMemoryDevice() == im.getMemoryDevice());
00551 const int dev = this->getMemoryDevice();
00552 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00553
00554 if(im.getSize() == 1)
00555 {
00556 cuda_c_inplaceAddScalar(this->getCudaArrayPtr(), im.getCudaArrayPtr(), tile.sz(), this->size());
00557 }
00558 else
00559 {
00560 ASSERT(this->isSameSize(im));
00561 cuda_c_inplaceAddImages(this->getCudaArrayPtr(), im.getCudaArrayPtr(), tile.sz(), this->size());
00562 }
00563 return *this;
00564 }
00565
00566 template <class T> inline
00567 CudaImage<float>& CudaImage<T>::operator-=(const CudaImage<float>& im)
00568 {
00569 ASSERT(im.initialized());
00570 ASSERT(this->getMemoryDevice() == im.getMemoryDevice());
00571 const int dev = this->getMemoryDevice();
00572 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00573
00574 if(im.getSize() == 1)
00575 {
00576 cuda_c_inplaceSubtractScalar(this->getCudaArrayPtr(), im.getCudaArrayPtr(), tile.sz(), this->size());
00577 }
00578 else
00579 {
00580 ASSERT(this->isSameSize(im));
00581 cuda_c_inplaceSubtractImages(this->getCudaArrayPtr(), im.getCudaArrayPtr(), tile.sz(), this->size());
00582 }
00583 return *this;
00584 }
00585
00586 template <class T> inline
00587 CudaImage<float>& CudaImage<T>::operator*=(const CudaImage<float>& im)
00588 {
00589 ASSERT(im.initialized());
00590 ASSERT(this->getMemoryDevice() == im.getMemoryDevice());
00591 const int dev = this->getMemoryDevice();
00592 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00593
00594 if(im.getSize() == 1)
00595 {
00596 cuda_c_inplaceMultiplyScalar(this->getCudaArrayPtr(), im.getCudaArrayPtr(), tile.sz(), this->size());
00597 }
00598 else
00599 {
00600 ASSERT(this->isSameSize(im));
00601 cuda_c_inplaceMultiplyImages(this->getCudaArrayPtr(), im.getCudaArrayPtr(), tile.sz(), this->size());
00602 }
00603 return *this;
00604 }
00605
00606 template <class T> inline
00607 CudaImage<float>& CudaImage<T>::operator/=(const CudaImage<float>& im)
00608 {
00609 ASSERT(im.initialized());
00610 ASSERT(this->getMemoryDevice() == im.getMemoryDevice());
00611 const int dev = this->getMemoryDevice();
00612 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00613
00614 if(im.getSize() == 1)
00615 {
00616 cuda_c_inplaceDivideScalar(this->getCudaArrayPtr(), im.getCudaArrayPtr(), tile.sz(), this->size());
00617 }
00618 else
00619 {
00620 ASSERT(this->isSameSize(im));
00621 cuda_c_inplaceDivideImages(this->getCudaArrayPtr(), im.getCudaArrayPtr(), tile.sz(), this->size());
00622 }
00623 return *this;
00624 }
00625
00626
00627 template <class T> inline
00628 CudaImage<float> CudaImage<T>::operator+(const float val) const
00629 {
00630 const int dev = this->getMemoryDevice();
00631 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00632 CudaImage<float> result(this->getDims(),NO_INIT,this->getMemoryPolicy(),dev);
00633
00634 cuda_c_addHostScalar(this->getCudaArrayPtr(), val, result.getCudaArrayPtr(), tile.sz(), this->size());
00635
00636 return result;
00637 }
00638
00639 template <class T> inline
00640 CudaImage<float> CudaImage<T>::operator-(const float val) const
00641 {
00642 const int dev = this->getMemoryDevice();
00643 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00644 CudaImage<float> result(this->getDims(),NO_INIT,this->getMemoryPolicy(),dev);
00645
00646 cuda_c_subtractHostScalar(this->getCudaArrayPtr(), val, result.getCudaArrayPtr(), tile.sz(), this->size());
00647
00648 return result;
00649 }
00650
00651 template <class T> inline
00652 CudaImage<float> CudaImage<T>::operator*(const float val) const
00653 {
00654 const int dev = this->getMemoryDevice();
00655 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00656 CudaImage<float> result(this->getDims(),NO_INIT,this->getMemoryPolicy(),dev);
00657
00658 cuda_c_multiplyHostScalar(this->getCudaArrayPtr(), val, result.getCudaArrayPtr(), tile.sz(), this->size());
00659
00660 return result;
00661 }
00662
00663 template <class T> inline
00664 CudaImage<float> CudaImage<T>::operator/(const float val) const
00665 {
00666 const int dev = this->getMemoryDevice();
00667 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00668 CudaImage<float> result(this->getDims(),NO_INIT,this->getMemoryPolicy(),dev);
00669
00670 cuda_c_divideHostScalar(this->getCudaArrayPtr(), val, result.getCudaArrayPtr(), tile.sz(), this->size());
00671
00672 return result;
00673 }
00674
00675
00676
00677
00678
00679 template <class T> inline
00680 CudaImage<float> CudaImage<T>::operator+(const CudaImage<float>& im) const
00681 {
00682 ASSERT(im.initialized());
00683 ASSERT(this->getMemoryDevice() == im.getMemoryDevice());
00684 const int dev = this->getMemoryDevice();
00685 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00686 CudaImage<float> result(this->getDims(),NO_INIT,this->getMemoryPolicy(),dev);
00687 if(im.getSize() == 1)
00688 {
00689 cuda_c_addScalar(this->getCudaArrayPtr(), im.getCudaArrayPtr(), result.getCudaArrayPtr(), tile.sz(), this->size());
00690 }
00691 else
00692 {
00693 ASSERT(this->isSameSize(im));
00694 cuda_c_addImages(this->getCudaArrayPtr(), im.getCudaArrayPtr(), result.getCudaArrayPtr(), tile.sz(), this->size());
00695 }
00696 return result;
00697 }
00698
00699 template <class T> inline
00700 CudaImage<float> CudaImage<T>::operator-(const CudaImage<float>& im) const
00701 {
00702 ASSERT(im.initialized());
00703 ASSERT(this->getMemoryDevice() == im.getMemoryDevice());
00704 const int dev = this->getMemoryDevice();
00705 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00706 CudaImage<float> result(this->getDims(),NO_INIT,this->getMemoryPolicy(),dev);
00707 if(im.getSize() == 1)
00708 {
00709 cuda_c_subtractScalar(this->getCudaArrayPtr(), im.getCudaArrayPtr(), result.getCudaArrayPtr(), tile.sz(), this->size());
00710 }
00711 else
00712 {
00713 ASSERT(this->isSameSize(im));
00714 cuda_c_subtractImages(this->getCudaArrayPtr(), im.getCudaArrayPtr(), result.getCudaArrayPtr(), tile.sz(), this->size());
00715 }
00716 return result;
00717 }
00718
00719 template <class T> inline
00720 CudaImage<float> CudaImage<T>::operator*(const CudaImage<float>& im) const
00721 {
00722 ASSERT(im.initialized());
00723 ASSERT(this->getMemoryDevice() == im.getMemoryDevice());
00724 const int dev = this->getMemoryDevice();
00725 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00726 CudaImage<float> result(this->getDims(),NO_INIT,this->getMemoryPolicy(),dev);
00727 if(im.getSize() == 1)
00728 {
00729 cuda_c_multiplyScalar(this->getCudaArrayPtr(), im.getCudaArrayPtr(), result.getCudaArrayPtr(), tile.sz(), this->size());
00730 }
00731 else
00732 {
00733 ASSERT(this->isSameSize(im));
00734 cuda_c_multiplyImages(this->getCudaArrayPtr(), im.getCudaArrayPtr(), result.getCudaArrayPtr(), tile.sz(), this->size());
00735 }
00736 return result;
00737 }
00738
00739 template <class T> inline
00740 CudaImage<float> CudaImage<T>::operator/(const CudaImage<float>& im) const
00741 {
00742 ASSERT(im.initialized());
00743 ASSERT(this->getMemoryDevice() == im.getMemoryDevice());
00744 const int dev = this->getMemoryDevice();
00745 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00746 CudaImage<float> result(this->getDims(),NO_INIT,this->getMemoryPolicy(),dev);
00747 if(im.getSize() == 1)
00748 {
00749 cuda_c_divideScalar(this->getCudaArrayPtr(), im.getCudaArrayPtr(), result.getCudaArrayPtr(), tile.sz(), this->size());
00750 }
00751 else
00752 {
00753 ASSERT(this->isSameSize(im));
00754 cuda_c_divideImages(this->getCudaArrayPtr(), im.getCudaArrayPtr(), result.getCudaArrayPtr(), tile.sz(), this->size());
00755 }
00756 return result;
00757 }
00758
00759
00760 template <class T> inline
00761 CudaImage<T>::~CudaImage()
00762 { }
00763
00764
00765 template <class T> inline
00766 void CudaImage<T>::freeMem()
00767 {
00768 CudaImage<T> empty;
00769 this->swap(empty);
00770 }
00771
00772
00773
00774
00775
00776
00777 template <class T> inline
00778 void CudaImage<T>::swap(CudaImage<T>& other)
00779 {
00780 itsHdl.swap(other.itsHdl);
00781 }
00782
00783
00784 template <class T> inline
00785 CudaImage<T> CudaImage<T>::deepcopy(const MemoryPolicy mp, const int dev) const
00786 {
00787
00788
00789 return CudaImage<T>(this->getCudaArrayPtr(), this->getDims(), mp, dev, this->getMemoryPolicy(), this->getMemoryDevice());
00790 }
00791
00792
00793 template <class T> inline
00794 Image<T> CudaImage<T>::exportToImage() const
00795 {
00796 if(getMemoryPolicy() == HOST_MEMORY)
00797 return Image<T>(getCudaArrayPtr(), getDims());
00798 else
00799 {
00800 Image<T> ret(getDims(),NO_INIT);
00801 ArrayHelper<T>::copy_initialize(ret.getArrayPtr(),size(),getCudaArrayPtr(),HOST_MEMORY,CUDA_HOST_DEVICE_NUM,getMemoryPolicy(),getMemoryDevice());
00802 return ret;
00803 }
00804 }
00805
00806
00807 template <class T> inline
00808 void CudaImage<T>::resize(const Dims& dims, const bool do_clear)
00809 {
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819 if (dims != getDims())
00820 {
00821 ArrayHandle<T> resized(new ArrayData<T>(dims, do_clear ? ZEROS:NO_INIT, this->getMemoryPolicy(), this->getMemoryDevice()));
00822 itsHdl.swap(resized);
00823 }
00824 else
00825 {
00826 if (do_clear) clear( 0 );
00827 }
00828 }
00829
00830
00831 template <class T> inline
00832 void CudaImage<T>::resize(const int width, const int height, const bool do_clear)
00833 {
00834 resize(Dims(width, height), do_clear);
00835 }
00836
00837
00838
00839
00840
00841
00842 template <class T> inline
00843 bool CudaImage<T>::initialized() const
00844 { return getWidth() > 0 && getHeight() > 0; }
00845
00846
00847 template <class T> inline
00848 int CudaImage<T>::getSize() const
00849 { return getDims().sz(); }
00850
00851
00852 template <class T> inline
00853 uint CudaImage<T>::size() const
00854 { return getDims().sz(); }
00855
00856
00857 template <class T> inline
00858 int CudaImage<T>::getWidth() const
00859 { return itsHdl.get().w(); }
00860
00861
00862 template <class T> inline
00863 int CudaImage<T>::getHeight() const
00864 { return itsHdl.get().h(); }
00865
00866
00867 template <class T> inline
00868 const Dims& CudaImage<T>::getDims() const
00869 { return itsHdl.get().dims(); }
00870
00871
00872 template <class T> inline
00873 Rectangle CudaImage<T>::getBounds() const
00874 { return Rectangle(Point2D<int>(0,0), itsHdl.get().dims()); }
00875
00876
00877 template <class T> template <class C> inline
00878 bool CudaImage<T>::isSameSize(const C& other) const
00879 { return getWidth() == other.getWidth() && getHeight() == other.getHeight(); }
00880
00881
00882 template <class T> inline
00883 bool CudaImage<T>::is1D() const
00884 { return (getWidth() == 1) || (getHeight() == 1); }
00885
00886
00887 template <class T> inline
00888 bool CudaImage<T>::isVector() const
00889 { return (getWidth() == 1); }
00890
00891
00892 template <class T> inline
00893 bool CudaImage<T>::isTransposedVector() const
00894 { return (getHeight() == 1); }
00895
00896
00897 template <class T> inline
00898 bool CudaImage<T>::isSquare() const
00899 { return (getWidth() == getHeight()); }
00900
00901
00902 template <class T> inline
00903 const T* CudaImage<T>::getCudaArrayPtr() const
00904 {
00905 return impl().data();
00906 }
00907
00908
00909 template <class T> inline
00910 T* CudaImage<T>::getCudaArrayPtr()
00911 {
00912 return uniq().dataw();
00913 }
00914
00915
00916 template <class T> inline
00917 bool CudaImage<T>::coordsOk(const Point2D<int>& P) const
00918 {
00919 return (P.i >= 0 && P.j >= 0 && P.i < getWidth() && P.j < getHeight());
00920 }
00921
00922
00923 template <class T> inline
00924 bool CudaImage<T>::coordsOk(const int i, const int j) const
00925 {
00926 return (i >= 0 && j >= 0 && i < getWidth() && j < getHeight());
00927 }
00928
00929
00930 template <class T> inline
00931 bool CudaImage<T>::coordsOk(const Point2D<float>& p) const
00932 {
00933 return this->coordsOk(p.i, p.j);
00934 }
00935
00936
00937 template <class T> inline
00938 bool CudaImage<T>::coordsOk(const float i, const float j) const
00939 {
00940 return (i >= 0.0F && j >= 0.0F &&
00941 i < float(getWidth() - 1) && j < float(getHeight() - 1));
00942 }
00943
00944
00945 template <class T> inline
00946 bool CudaImage<T>::rectangleOk(const Rectangle& rect) const
00947 {
00948 return (rect.left() < getWidth() && rect.rightI() < getWidth() &&
00949 rect.top() < getHeight() && rect.bottomI() < getHeight() &&
00950 rect.left() >= 0 && rect.rightI() >= 0 &&
00951 rect.top() >= 0 && rect.bottomI() >= 0);
00952 }
00953
00954
00955 template <class T> inline
00956 MemoryPolicy CudaImage<T>::getMemoryPolicy() const
00957 {
00958 return impl().getMemoryPolicy();
00959 }
00960
00961
00962 template <class T> inline
00963 int CudaImage<T>::getMemoryDevice() const
00964 {
00965 return impl().getMemoryDevice();
00966 }
00967
00968
00969
00970 template <class T> inline
00971 void CudaImage<T>::clear(const char &val)
00972 {
00973
00974
00975
00976
00977
00978 if (itsHdl.isShared())
00979 *this = CudaImage<T>(getDims(), NO_INIT, this->getMemoryPolicy(), this->getMemoryDevice());
00980
00981 CudaDevices::memset(this->getCudaArrayPtr(),val,size()*sizeof(T),this->getMemoryDevice());
00982 }
00983
00984
00985
00986
00987
00988 template <class T> inline
00989 bool CudaImage<T>::hasSameData(const CudaImage<T>& b) const
00990 { return itsHdl.hasSameData(b.itsHdl); }
00991
00992
00993 template <class T> inline
00994 long CudaImage<T>::refCount() const throw() { return itsHdl.refCount(); }
00995
00996
00997 template <class T> inline
00998 bool CudaImage<T>::isShared() const throw() { return itsHdl.isShared(); }
00999
01000
01001
01002
01003
01004 template <class T> inline
01005 const ArrayData<T>& CudaImage<T>::impl() const
01006 { return itsHdl.get(); }
01007
01008
01009 template <class T> inline
01010 ArrayData<T>& CudaImage<T>::uniq()
01011 { return itsHdl.uniq(this->getMemoryPolicy(),this->getMemoryDevice()); }
01012
01013
01014
01015
01016
01017
01018
01019 #endif