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 #ifndef __CHANNEL_GNX__
00031 #define __CHANNEL_GNX__
00032
00033
00034
00035 #include <stdlib.h>
00036 #include <iostream>
00037 using namespace std;
00038
00039 template<class T>
00040 class Channel
00041 {
00042 private:
00043 T *data;
00044 int id;
00045 protected:
00046 int width;
00047 int height;
00048 public:
00049 Channel(const int height, const int width);
00050 Channel();
00051 virtual ~Channel();
00052 virtual int GetId();
00053 virtual void SetId(const int id);
00054 virtual inline T Get(const int x, const int y);
00055 virtual inline void Set(const int x, const int y, const T val);
00056 virtual inline int GetWidth();
00057 virtual inline int GetHeight();
00058 virtual Channel<T>* EmptyClone();
00059 virtual T** GetRawData();
00060 virtual void ResetChannel();
00061 virtual void Normalize(int* x, int* y);
00062 virtual void Normalize(int* topleftx, int* toplefty, int* bottomrightx, int* bottomrighty);
00063 };
00064
00065
00066 template<class T>
00067 Channel<T>::Channel(const int height, const int width)
00068 {
00069 data = new T[width*height];
00070 this->height=height;
00071 this->width=width;
00072 id = 0;
00073 }
00074
00075 template<class T>
00076 Channel<T>::Channel()
00077 {
00078 data = 0;
00079 id = 0;
00080 }
00081
00082 template<class T>
00083 Channel<T>::~Channel()
00084 {
00085 if(data != 0)
00086 delete [] data;
00087 }
00088
00089 template<class T>
00090 void Channel<T>::SetId(const int id)
00091 {
00092 this->id = id;
00093 }
00094
00095 template<class T>
00096 int Channel<T>::GetId()
00097 {
00098 return(id);
00099 }
00100
00101 template<class T>
00102 inline T Channel<T>::Get(const int x, const int y)
00103 {
00104
00105
00106
00107
00108
00109 return(data[x+y*width]);
00110 }
00111
00112 template<class T>
00113 inline void Channel<T>::Set(const int x, const int y, const T val)
00114 {
00115
00116
00117
00118
00119
00120 data[x+y*width] = val;
00121 }
00122
00123
00124 template<class T>
00125 inline int Channel<T>::GetWidth()
00126 {
00127 return(width);
00128 }
00129
00130 template<class T>
00131 inline int Channel<T>::GetHeight()
00132 {
00133 return(height);
00134 }
00135
00136 template<class T>
00137 T** Channel<T>::GetRawData()
00138 {
00139 return(&data);
00140 }
00141
00142 template<class T>
00143 Channel<T>* Channel<T>::EmptyClone()
00144 {
00145 Channel<T> *copy = new Channel<T>(height,width);
00146 return(copy);
00147 }
00148
00149 template<class T>
00150 void Channel<T>::ResetChannel()
00151 {
00152 }
00153
00154 template<class T>
00155 void Channel<T>::Normalize(int* x, int* y)
00156
00157 {
00158
00159 if(*x<0)
00160 *x = 0;
00161 if(*y<0)
00162 *y = 0;
00163 if(*x >= width)
00164 *x = width-1;
00165 if(*y >= height)
00166 *y = height-1;
00167 }
00168
00169 template<class T>
00170
00171 void Channel<T>::Normalize(int* topleftx, int* toplefty, int* bottomrightx, int* bottomrighty)
00172 {
00173 int temp;
00174 Normalize(topleftx,toplefty);
00175 Normalize(bottomrightx,bottomrighty);
00176 if(*topleftx > *bottomrightx)
00177 {
00178 temp = *topleftx;
00179 *topleftx = *bottomrightx;
00180 *bottomrightx = temp;
00181 }
00182 if(*toplefty > *bottomrighty)
00183 {
00184 temp = *toplefty;
00185 *toplefty = *bottomrighty;
00186 *bottomrighty = temp;
00187 }
00188 }
00189
00190 #endif