00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef Array2D_h
00010 #define Array2D_h
00011
00012
00013
00014
00015
00016 #include "HxMakeFromShortData.h"
00017
00018 template <class T>
00019 class Array2D {
00020 private:
00021 unsigned dims[2];
00022 T *ptr;
00023 Array2D();
00024 public:
00025 Array2D(const Array2D &);
00026 Array2D & operator = (Array2D &arg)
00027 {
00028 for (unsigned i=0; i<dims[0]*dims[1]; i++) ptr[i]=arg[i];
00029 return *this;
00030 };
00031 ~Array2D() { delete []ptr; }
00032 Array2D(unsigned x, unsigned y, const T &val) {
00033 dims[0]=x;
00034 dims[1]=y;
00035 unsigned s=x*y;
00036 ptr = new T[s];
00037 for (unsigned i=0; i<s; i++) ptr[i]=val;
00038 }
00039 T & operator () (unsigned x, unsigned y) {
00040 #ifdef _DEBUG
00041 if (x>=dims[0] || y>=dims[1])
00042 throw HxString("x>=dims[0] || y>=dims[1]");
00043 #endif
00044 return ptr[x+dims[0]*y];
00045 }
00046
00047 T & operator [] (unsigned i) {
00048 return ptr[i];
00049 }
00050
00051
00052 int getDim(int n)
00053 {
00054 return dims[n];
00055 }
00056
00057 HxImageRep MakeHxImage()
00058 {
00059 int pixelDimensionality=1;
00060 int dimensions=2;
00061 HxSizes sizes(dims[0],dims[1],1);
00062
00063 short* data= new short[dims[0]*dims[1]];
00064 int i,j;
00065 int height,width;
00066 width=dims[0];
00067 height=dims[1];
00068 for(i=0;i<width;i++)
00069 for(j=0;j<height;j++)
00070 {
00071 data[j*width+i]=ptr[j*width+i];
00072 }
00073
00074
00075 HxImageRep gd = HxMakeFromShortData(
00076 pixelDimensionality,
00077 dimensions,
00078 sizes,
00079 data);
00080 return gd;
00081 }
00082
00083 };
00084
00085
00086 #endif