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 #include "CUDA/CudaDrawOps.H"
00039 #include "CUDA/CudaImage.H"
00040 #include "Image/Rectangle.H"
00041 #include "CUDA/cudadefs.h"
00042 #include "Util/Assert.H"
00043 #include "Util/sformat.H"
00044 #include "rutz/trace.h"
00045 #include <cmath>
00046
00047
00048 void cudaDrawFilledRect(CudaImage<float> &dst, const Rectangle& r, const float color)
00049 {
00050 ASSERT(dst.initialized());
00051 const MemoryPolicy mp = dst.getMemoryPolicy();
00052 int dev = dst.getMemoryDevice();
00053 const int w=dst.getWidth();
00054 const int h=dst.getHeight();
00055 ASSERT(mp != HOST_MEMORY);
00056 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00057 int tile_width, tile_height;
00058 tile_width = tile_height = 1;
00059 if(r.width() > r.height())
00060 tile_width = tile.sz();
00061 else
00062 tile_height = tile.sz();
00063 cuda_c_drawFilledRect(dst.getCudaArrayPtr(),r.top(),r.left(),r.bottomI(),r.rightI(),color,w,h,tile_width,tile_height);
00064 }
00065
00066 void cudaDrawFilledRect(CudaImage<PixRGB<float> > &dst, const Rectangle& r, const PixRGB<float> color)
00067 {
00068 ASSERT(dst.initialized());
00069
00070 const MemoryPolicy mp = dst.getMemoryPolicy();
00071 int dev = dst.getMemoryDevice();
00072 const int w=dst.getWidth();
00073 const int h=dst.getHeight();
00074 ASSERT(mp != HOST_MEMORY);
00075 Dims tile = CudaDevices::getDeviceTileSize1D(dev);
00076 int tile_width, tile_height;
00077 tile_width = tile_height = 1;
00078 if(r.width() > r.height())
00079 tile_width = tile.sz();
00080 else
00081 tile_height = tile.sz();
00082 cuda_c_drawFilledRectRGB((float3_t *) dst.getCudaArrayPtr(),r.top(),r.left(),r.bottomI(),r.rightI(),(float3_t *)&color,w,h,tile_width,tile_height);
00083
00084 }
00085
00086
00087
00088
00089 template <class T> void cudaDrawRect(CudaImage<T>& dst, const Rectangle& r, const T color, const int rad)
00090 {
00091 ASSERT(dst.initialized());
00092 ASSERT(r.isValid());
00093 ASSERT(dst.rectangleOk(r));
00094
00095 int w=dst.getWidth();
00096 int h=dst.getHeight();
00097 int topB,topE,botB,botE,leftB,leftE,rightB,rightE;
00098
00099 topB = std::max(r.top()-rad,0);
00100 topE = std::min(r.top()+rad,h-1);
00101 botB = std::max(r.bottomI()-rad,0);
00102 botE = std::min(r.bottomI()+rad,h-1);
00103 leftB = std::max(r.left()-rad,0);
00104 leftE = std::min(r.left()+rad,w-1);
00105 rightB = std::max(r.rightI()-rad,0);
00106 rightE = std::min(r.rightI()+rad,w-1);
00107
00108 cudaDrawFilledRect(dst,Rectangle::tlbrI(topB,r.left(),topE,r.rightI()),color);
00109
00110 cudaDrawFilledRect(dst,Rectangle::tlbrI(botB,r.left(),botE,r.rightI()),color);
00111
00112 cudaDrawFilledRect(dst,Rectangle::tlbrI(topB,leftB,botE,leftE),color);
00113
00114 cudaDrawFilledRect(dst,Rectangle::tlbrI(topB,rightB,botE,rightE),color);
00115
00116 }
00117
00118 template void cudaDrawRect(CudaImage<PixRGB<float> >& dst, const Rectangle& r, const PixRGB<float> color, const int rad);
00119 template void cudaDrawRect(CudaImage<float>& dst, const Rectangle& r, const float color, const int rad);
00120
00121
00122
00123
00124
00125