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 #ifndef MATRIX_H
00038 #define MATRIX_H
00039
00040 #include "attribute.hh"
00041
00042
00043
00044
00045
00046
00047
00048 class Matrix {
00049
00050 public:
00051
00052
00053 Matrix();
00054 Matrix(Matrix const & mat);
00055 Matrix(int tab[6], unsigned char color);
00056
00057
00058 ~Matrix();
00059
00060
00061 int Get_X_Min() const;
00062 int Get_X_Max() const;
00063 int Get_Y_Min() const;
00064 int Get_Y_Max() const;
00065 int Get_Z_Min() const;
00066 int Get_Z_Max() const;
00067 unsigned char Get_Color(int alpha, int b, int c) const;
00068 bool Get_Bit(int alpha, int b, int c, int bit) const;
00069 unsigned char Get_Value(int alpha, int b, int c) const;
00070
00071
00072 void Set_Color(int alpha, int b, int c, unsigned char color);
00073 void Set_Bit(int alpha, int b, int c, int bit);
00074 void Unset_Bit(int alpha, int b, int c, int bit);
00075 void Set_Value(int alpha, int b, int c, unsigned char val);
00076
00077
00078 private:
00079
00080
00081 unsigned char ***m;
00082
00083
00084 int limits[6];
00085 };
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 #include <cassert>
00097 #include "definition.hh"
00098
00099
00100
00101
00102 inline
00103 Matrix::Matrix()
00104 {
00105 for (int i=0; i<6; i++)
00106 limits[i] = 0;
00107
00108 m = NULL;
00109 }
00110
00111 inline
00112 Matrix::Matrix(int tab[6], unsigned char color)
00113 {
00114 for (int i=0; i<6; i++)
00115 limits[i] = tab[i];
00116
00117 m = new unsigned char**[tab[0]-tab[1]+1];
00118
00119 for (int i=0; i<limits[0]-limits[1]+1; i++)
00120 {
00121 m[i] = new unsigned char*[tab[2]-tab[3]+1];
00122
00123 for (int j=0; j<tab[2]-tab[3]+1; j++)
00124 {
00125 m[i][j] = new unsigned char[tab[4]-tab[5]+1];
00126
00127 for (int k=0; k<tab[4]-tab[5]+1; k++)
00128 m[i][j][k] = (m[i][j][k] & 0xFC) | (color & 0x3);
00129 }
00130 }
00131 }
00132
00133 inline
00134 Matrix::Matrix(Matrix const & mat)
00135 {
00136 for (int i=0; i<6; i++)
00137 limits[i] = mat.limits[i];
00138
00139 m = new unsigned char**[limits[0]-limits[1]+1];
00140
00141 for (int i=0; i<limits[0]-limits[1]+1; i++)
00142 {
00143 m[i] = new unsigned char*[limits[2]-limits[3]+1];
00144
00145 for (int j=0; j<limits[2]-limits[3]+1; j++)
00146 {
00147 m[i][j] = new unsigned char[limits[4]-limits[5]+1];
00148
00149 for (int k=0; k<limits[4]-limits[5]+1; k++)
00150 m[i][j][k] = mat.m[i][j][k];
00151 }
00152 }
00153 }
00154
00155
00156
00157 inline
00158 Matrix::~Matrix()
00159 {
00160 if (m != NULL)
00161 {
00162 for (int i=0; i<limits[0]-limits[1]+1; i++)
00163 {
00164 for (int j=0; j<limits[2]-limits[3]+1; j++)
00165 delete [] m[i][j];
00166 delete [] m[i];
00167 }
00168 delete [] m;
00169 }
00170 }
00171
00172
00173
00174 inline
00175 int Matrix::Get_X_Min() const
00176 {
00177 return limits[1];
00178 }
00179
00180 inline
00181 int Matrix::Get_X_Max() const
00182 {
00183 return limits[0];
00184 }
00185
00186 inline
00187 int Matrix::Get_Y_Min() const
00188 {
00189 return limits[3];
00190 }
00191
00192 inline
00193 int Matrix::Get_Y_Max() const
00194 {
00195 return limits[2];
00196 }
00197
00198 inline
00199 int Matrix::Get_Z_Min() const
00200 {
00201 return limits[5];
00202 }
00203
00204 inline
00205 int Matrix::Get_Z_Max() const
00206 {
00207 return limits[4];
00208 }
00209
00210 inline
00211 unsigned char Matrix::Get_Color(int alpha, int b, int c) const
00212 {
00213 assert(alpha >= limits[1] && alpha <= limits[0] &&
00214 b >= limits[3] && b <= limits[2] &&
00215 c >= limits[5] && c <= limits[4]);
00216
00217 return (m[alpha-limits[1]][b-limits[3]][c-limits[5]] & 0x3);
00218 }
00219
00220 inline
00221 bool Matrix::Get_Bit(int alpha, int b, int c, int bit) const
00222 {
00223 assert(alpha >= limits[1] && alpha <= limits[0] &&
00224 b >= limits[3] && b <= limits[2] &&
00225 c >= limits[5] && c <= limits[4]);
00226
00227 return ((m[alpha-limits[1]][b-limits[3]][c-limits[5]] >> bit) & 0x1);
00228 }
00229
00230 inline
00231 unsigned char Matrix::Get_Value(int alpha, int b, int c) const
00232 {
00233 assert(alpha >= limits[1] && alpha <= limits[0] &&
00234 b >= limits[3] && b <= limits[2] &&
00235 c >= limits[5] && c <= limits[4]);
00236
00237 return (m[alpha-limits[1]][b-limits[3]][c-limits[5]]);
00238 }
00239
00240
00241
00242 inline
00243 void Matrix::Set_Color(int alpha, int b, int c, unsigned char color)
00244 {
00245 assert(alpha >= limits[1] && alpha <= limits[0] &&
00246 b >= limits[3] && b <= limits[2] &&
00247 c >= limits[5] && c <= limits[4]);
00248
00249 m[alpha-limits[1]][b-limits[3]][c-limits[5]] =
00250 (m[alpha-limits[1]][b-limits[3]][c-limits[5]] & 0xFC) | (color & 0x3);
00251 }
00252
00253 inline
00254 void Matrix::Set_Bit(int alpha, int b, int c, int bit)
00255 {
00256 assert(alpha >= limits[1] && alpha <= limits[0] &&
00257 b >= limits[3] && b <= limits[2] &&
00258 c >= limits[5] && c <= limits[4]);
00259
00260 m[alpha-limits[1]][b-limits[3]][c-limits[5]] =
00261 (m[alpha-limits[1]][b-limits[3]][c-limits[5]] | (0x1 << bit));
00262 }
00263
00264 inline
00265 void Matrix::Unset_Bit(int alpha, int b, int c, int bit)
00266 {
00267 assert(alpha >= limits[1] && alpha <= limits[0] &&
00268 b >= limits[3] && b <= limits[2] &&
00269 c >= limits[5] && c <= limits[4]);
00270
00271 m[alpha-limits[1]][b-limits[3]][c-limits[5]] =
00272 (m[alpha-limits[1]][b-limits[3]][c-limits[5]] & (0xFF - (0x1 << bit)));
00273 }
00274
00275 inline
00276 void Matrix::Set_Value(int alpha, int b, int c, unsigned char val)
00277 {
00278 assert(alpha >= limits[1] && alpha <= limits[0] &&
00279 b >= limits[3] && b <= limits[2] &&
00280 c >= limits[5] && c <= limits[4]);
00281
00282 m[alpha-limits[1]][b-limits[3]][c-limits[5]] = val;
00283 }
00284
00285 #endif