Surface.h
Go to the documentation of this file.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
00030
00034
00036
00037
00038 #ifndef __SURFACE_H_
00039 #define __SURFACE_H_
00040
00041 #ifdef MIP_HOST_APPLE
00042 #include <applePatch.h>
00043 #endif
00044
00045 #include <stdio.h>
00046 #include <math.h>
00047 #include <vector>
00048 #include <iostream>
00049 #include <string>
00050 #include <sstream>
00051 #include <fstream>
00052 #include <sys/time.h>
00053 #include <sys/select.h>
00054 #include <assert.h>
00055 #include <Types.h>
00056 #include <Association.h>
00057 #include <S1.h>
00058
00059
00060
00061
00062
00063
00064
00065 #include <R3.h>
00066 #include <S1.h>
00067 #include <S3.h>
00068
00069
00070 #define MAX_NUM_PLANES 5000
00071 #define PLANES_DATA_ELEMENTS 7
00072 #define TRANS_MATRIX_DATA 9
00073 #define SOURCE_FILE_COLUMNS 22
00074 #define SOURCE_FILE_X_COORD_POS 0
00075 #define SOURCE_FILE_Z_COORD_POS 2
00076 #define SOURCE_FILE_a_COEFF_POS 18
00077 #define SOURCE_FILE_d_COEFF_POS 21
00078 #define X_COORD_POS 0
00079 #define Y_COORD_POS 1
00080 #define Z_COORD_POS 2
00081 #define a_COEFF_POS 3
00082 #define b_COEFF_POS 4
00083 #define c_COEFF_POS 5
00084 #define d_COEFF_POS 6
00085
00086 using namespace std;
00087
00090 class Surface {
00091 private:
00092
00093
00094
00095
00096
00097 int NumPlanes;
00098 char* nome;
00099
00100 Decimal DataIn[MAX_NUM_PLANES][PLANES_DATA_ELEMENTS];
00101
00102
00103
00104
00105 MIPMatrix *RotTransl;
00106
00107 int CalcNumPlanes(const char* file)
00108 {
00109 int tmp = 0;
00110 ifstream leggerefile(file,ios::in);
00111 char tempBuffer[200];
00112 leggerefile.getline (tempBuffer, 199);
00113 while(!(leggerefile.eof()))
00114 {
00115 leggerefile.getline (tempBuffer, 199);
00116 tmp++;
00117 }
00118 return tmp;
00119 }
00120
00121
00122 void BuildMatrixOfReferenceData(string namefile)
00123 {
00124 int q = 0;
00125 int row = 0;
00126 int col = 0;
00127 double tmp=0;
00128 const char *ptr1 = 0;
00129 char *ptr2 = 0;
00130 string filedata;
00131
00132 fstream filestr;
00133 cout << "BuildMatrixOfReferenceData() " << "\n";
00134 filestr.open(namefile.c_str(), ios::in);
00135 while(!(filestr.eof()) && (row < NumPlanes) && (row < MAX_NUM_PLANES))
00136 {
00137 filestr >> filedata;
00138 if(!(filestr.eof()))
00139 {
00140 if((q%SOURCE_FILE_COLUMNS) == 0)
00141 cout << "\n" << "Riga tabella: " << row+1 << "\n";
00142
00143
00144 ptr1 = filedata.data();
00145 tmp = atof(ptr1);
00146
00147 if((((q % SOURCE_FILE_COLUMNS) >= SOURCE_FILE_X_COORD_POS ) && ((q % SOURCE_FILE_COLUMNS) <= SOURCE_FILE_Z_COORD_POS)) ||
00148 (((q % SOURCE_FILE_COLUMNS) >= SOURCE_FILE_a_COEFF_POS) && ((q % SOURCE_FILE_COLUMNS) <= SOURCE_FILE_d_COEFF_POS)))
00149 {
00150 DataIn[row][col] = tmp;
00151 cout << "DataIn[" << row << "," << col << "]= " << DataIn[row][col] << "; ";
00152 col = (col+1)%7;
00153 }
00154 q++;
00155 if((q % SOURCE_FILE_COLUMNS) == 0)
00156 {
00157 row++;
00158
00159 }
00160 }
00161 }
00162
00163 filestr.close();
00164 cout << "\n";
00165 return;
00166 }
00167
00168
00169 void BuildRotTranslMatrix();
00170
00171 public:
00173 Surface(string namefile)
00174 {
00175 cout << "Surface construction started." << "\n";
00176 RotTransl = new MIPMatrix[MAX_NUM_PLANES]();
00177 NumPlanes = CalcNumPlanes(namefile.c_str());
00178
00179 cout << "Surface description file: " << namefile.c_str() << "\n";
00180 cout << "NumPlanes = " << NumPlanes << "\n";
00181 BuildMatrixOfReferenceData(namefile);
00182 BuildRotTranslMatrix();
00183 cout << "Surface model construction OK." << endl;
00184 }
00185
00186
00187 ~Surface ()
00188 {
00189 delete[] RotTransl;
00190 cout << "destr Surface" << endl;
00191 }
00192
00193
00194 int ReadNumPlanes()
00195 {
00196 return NumPlanes;
00197 }
00198
00199
00200 Decimal GetRotTranslMatrixElem(int NumMatrix, int row, int col)
00201 {
00202 int i;
00203
00204 i = (row - 1)*3 + (col - 1);
00205 return RotTransl[NumMatrix].GetMIPMatrixVal(row,col);
00206 }
00207
00208
00209 MIPMatrix* GetRotTranslMatrix(int NumMatrix)
00210 {
00211 return &RotTransl[NumMatrix];
00212 }
00213
00214
00215
00216 Position3D GetPlaneRefPoint(int Plane)
00217 {
00218 return Position3D(DataIn[Plane][0], DataIn[Plane][1], DataIn[Plane][2]);
00219 }
00220
00221
00222 Decimal GetCoef_a(int Plane)
00223 {
00224 return DataIn[Plane][3];
00225 }
00226
00227
00228 Decimal GetCoef_b(int Plane)
00229 {
00230 return DataIn[Plane][4];
00231 }
00232
00233
00234 Decimal GetCoef_c(int Plane)
00235 {
00236 return DataIn[Plane][5];
00237 }
00238
00239
00240 Decimal GetCoef_d(int Plane)
00241 {
00242 return DataIn[Plane][6];
00243 }
00244 };
00245 #endif
00246
00247
00248
00249