Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages | Examples

vetDFMatrix.h

00001 
00033 #ifndef __VETLIB_VETDFMATRIX_H__
00034  #define __VETLIB_VETDFMATRIX_H__
00035 
00036  #include "../vetDefs.h"
00037  #include <stdio.h>
00038  #include <fstream>
00039 
00040 
00041 
00042 // for default filters
00043         #define VETDF_3x3_average                       8700
00044         #define VETDF_3x3_mean_removal          8701
00045         #define VETDF_3x3_gaussian                      8702
00046         #define VETDF_3x3_lowpass1                      8703
00047         #define VETDF_3x3_lowpass2                      8704
00048         #define VETDF_3x3_lowpass3                      8705
00049         #define VETDF_3x3_highpass1                     8706
00050         #define VETDF_3x3_highpass2                     8707
00051         #define VETDF_3x3_highpass3                     8708
00052         #define VETDF_3x3_edge_sd_h                     8709
00053         #define VETDF_3x3_edge_sd_v                     8710
00054         #define VETDF_3x3_edge_sd_hv            8711
00055         #define VETDF_3x3_laplacian1            8712
00056         #define VETDF_3x3_laplacian2            8713
00057         #define VETDF_3x3_laplacian3            8714
00058         #define VETDF_3x3_diagonal                      8715
00059         #define VETDF_3x3_horizontal            8716
00060         #define VETDF_3x3_vertical                      8717
00061         #define VETDF_3x3_east                          8718
00062         #define VETDF_3x3_west                          8719
00063         #define VETDF_3x3_north                         8720
00064         #define VETDF_3x3_south                         8721
00065         #define VETDF_3x3_south_east            8722
00066         #define VETDF_3x3_south_west            8723
00067         #define VETDF_3x3_north_east            8724
00068         #define VETDF_3x3_north_west            8725
00069         #define VETDF_3x3_sobel_h                       8726
00070         #define VETDF_3x3_sobel_v                       8727
00071         #define VETDF_3x3_prewitt_h                     8728
00072         #define VETDF_3x3_prewitt_v                     8729
00073         #define VETDF_3x3_emboss_east           8730
00074         #define VETDF_3x3_emboss_west           8731
00075         #define VETDF_3x3_emboss_south          8732
00076         #define VETDF_3x3_emboss_north          8733
00077         #define VETDF_3x3_emboss_south_east     8734
00078         #define VETDF_3x3_emboss_south_west     8735
00079         #define VETDF_3x3_emboss_north_east     8736
00080         #define VETDF_3x3_emboss_north_west     8737
00081 
00082 
00083 class vetDFMatrix
00084  {
00085         protected:
00086 
00087                 char* data;
00088                 char* norm;
00089 
00090                 unsigned int dim;
00091 
00092 
00093 
00094                 void setDim(unsigned int size)
00095                  {
00096                         dim = size;
00097                         data = new char[size*size+1];
00098                         norm = data+size*size;
00099                  };
00100 
00101         public:
00102 
00103                 vetDFMatrix()
00104                  {
00105                         data = NULL;
00106                         norm = NULL;
00107                         dim = 0;
00108                  };
00109 
00110                 vetDFMatrix(char* array, unsigned int size, bool doCopy = false)
00111                  {
00112                         if (doCopy && size)
00113                          {
00114                                 data = new char[size*size+1];
00115                                 memcpy(data, array, (size*size+1) * sizeof(char));
00116                          }
00117                         else
00118                                 data = array;
00119 
00120                         dim = size;
00121                         norm = data+size*size;
00122                  };
00123 
00124                 vetDFMatrix(const char* filename)
00125                  {
00126                         data = NULL;
00127                         norm = NULL;
00128                         dim = 0;
00129                         loadFromFile(filename);
00130                  };
00131 
00132                 vetDFMatrix(FILE *fp)
00133                  {
00134                         data = NULL;
00135                         norm = NULL;
00136                         dim = 0;
00137                         loadFromStream(fp);
00138                  };
00139 
00140 
00141                 ~vetDFMatrix()
00142                  {
00143                         if (data != NULL)              //BUGGGGGGGG
00144                                 delete [] data;
00145                  };
00146 
00147                 char* dup_data() { return data; };
00148                 unsigned int getDim() { return dim; };
00149 
00150 
00151 
00162                 char& operator [] (int i)
00163                 {
00164                         return data[i];
00165                 };
00166 
00177                 const char& operator [] (int i) const
00178                 {
00179                         return data[i];
00180                 };
00181 
00182 
00183 
00184 
00185 
00186 
00187                 VETRESULT saveToFile(const char* filename)
00188                  {
00189                         FILE *fp;
00190                         int ret = VETRET_OK;
00191 
00192                         if ( data == NULL )
00193                                 return VETRET_ILLEGAL_USE;
00194 
00195                         if ( (fp = fopen(filename, "w")) == NULL )
00196                                 return VETRET_PARAM_ERR;
00197 
00198 
00199                         ret = saveToStream(fp);
00200 
00201                         fclose(fp);
00202 
00203                         return ret ;
00204                  };
00205 
00206 
00207 
00208                 VETRESULT loadFromFile(const char* filename)
00209                  {
00210                         FILE *fp;
00211                         int ret = VETRET_OK;
00212 
00213                         if ( (fp=fopen(filename,"r")) == NULL )
00214                                 return VETRET_PARAM_ERR;
00215 
00216                         ret = loadFromStream(fp);
00217 
00218                         fclose(fp);
00219 
00220                         return ret;
00221                  };
00222 
00223                 VETRESULT saveToStream(FILE *fp)
00224                  {
00225                         if ( data == NULL )
00226                                 return VETRET_ILLEGAL_USE;
00227 
00228                         if( fprintf(fp, "%u\n", dim) == EOF )
00229                                 return VETRET_INTERNAL_ERR;
00230 
00231                         int ret = VETRET_OK;
00232 
00233 
00234 //                      for (unsigned int i=0; i < dim*dim+1; i++)
00235                                 if ( fprintf(fp, "%s ", data) == EOF)
00236                                         ret = VETRET_INTERNAL_ERR;
00237 
00238                         if ( fprintf(fp, "\n") == EOF )
00239                                 ret = VETRET_INTERNAL_ERR;
00240 
00241                         return ret;
00242                  };
00243 
00244 
00245                 VETRESULT loadFromStream(FILE *fp)
00246                  {
00247                         unsigned int newDim = 0;
00248 
00249                         if ( fscanf(fp,"%u\n",&newDim) == EOF )
00250                                 return VETRET_INTERNAL_ERR;
00251 
00252                         setDim(newDim);
00253 
00254 //                      char tmpValue[1];
00255                         int ret = VETRET_OK;
00256 
00257 //                      for (unsigned int i=0; i < newDim * newDim+1; i++)
00258                                 if( fscanf(fp, "%s", data) == EOF )
00259                                         ret = VETRET_INTERNAL_ERR;
00260 //                              else
00261 //                                      data[i] = *tmpValue;
00262 
00263                         return ret;
00264                  };
00265 
00266 
00267                 static vetDFMatrix* createKernel_3x3(int index)
00268                  {
00269 
00270 #include "../filters/vetDigitalFilters.def"
00271 
00272                         vetDFMatrix* ret = new vetDFMatrix(defaulFilters_3x3[index - VETDF_3x3_average], 3, true);
00273                         return ret;
00274                  };
00275 
00276 
00277  };
00278 
00279 #endif //__VETLIB_VETDFMATRIX_H__
00280 

Generated on Tue Jan 24 11:58:59 2006 for VETLib by  doxygen 1.4.4