Surface.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno   
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
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 //#ifdef FOUND_BOOST_SER
00060 // #include <boost/serialization/vector.hpp>
00061 // #include <boost/archive/text_iarchive.hpp>
00062 // #include <boost/archive/text_oarchive.hpp>
00063 //#endif
00064 
00065 #include <R3.h>
00066 #include <S1.h>
00067 #include <S3.h>
00068 //#include <MIPMatrix.h>
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 //#ifdef FOUND_BOOST_SER
00093 //  friend class boost::serialization::access;
00094 //  //std::cout.precision(15);
00095 //#endif
00096   
00097   int NumPlanes;  // Number of plane composing the road.
00098   char* nome;
00099   
00100   Decimal DataIn[MAX_NUM_PLANES][PLANES_DATA_ELEMENTS];// Array containig the relevant information about a point and a
00101                            // plane containing it. For each row we have:
00102                            // X,Y,Z coordinates of a point; a,b,c,d coefficients of plane equation
00103                            // containing the point.
00104   
00105   MIPMatrix *RotTransl;
00106   
00107   int CalcNumPlanes(const char* file)//Read file to get the number of the planes composing the surface.
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   // Function to fill the DataIn table with the data read from an external file. 
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 //    cout << "From file: " << q << "\n";
00143 //                       cout << "Val " << q << "= " << filedata << "\n";
00144                          ptr1 = filedata.data();
00145                          tmp = atof(ptr1);
00146                          // tmp = strtod(ptr1, &ptr2);                
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        //cout << "\n";
00159     }
00160                        }
00161                    }
00162                    //leggerefile.close();
00163      filestr.close();
00164      cout << "\n";
00165      return;
00166   }
00167 
00168                 // Build transformation matrices array
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());//Number of planes defined in input data file 1 plane for each file's row.
00178 //    NumPlanes = NumPlanes - 1;//last plane can't be used because there is no reference point after.
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       // Get num planes in surface.
00194   int ReadNumPlanes()
00195   { 
00196      return NumPlanes;
00197   }
00198   
00199   // Get Transformation matrix element.
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   // Get Transformation matrix.
00209   MIPMatrix* GetRotTranslMatrix(int NumMatrix)
00210   {  
00211      return &RotTransl[NumMatrix];
00212   }
00213 
00214 
00215       // Get DataIn matrix element.
00216   Position3D GetPlaneRefPoint(int Plane)
00217   {  
00218      return Position3D(DataIn[Plane][0], DataIn[Plane][1], DataIn[Plane][2]);
00219   }
00220   
00221       // Get "a" coefficient of plane equation.
00222   Decimal GetCoef_a(int Plane)
00223   {  
00224      return DataIn[Plane][3];
00225   }
00226   
00227       // Get "b" coefficient of plane equation.
00228   Decimal GetCoef_b(int Plane)
00229   {  
00230      return DataIn[Plane][4];
00231   }
00232 
00233       // Get "c" coefficient of plane equation.
00234   Decimal GetCoef_c(int Plane)
00235   {  
00236      return DataIn[Plane][5];
00237   }
00238 
00239       // Get "d" coefficient of plane equation.
00240   Decimal GetCoef_d(int Plane)
00241   {  
00242      return DataIn[Plane][6];
00243   }
00244 };
00245 #endif
00246 
00247 
00248 /* @} */
00249 

Generated on Mon Feb 20 07:01:07 2017 for MIP by  doxygen 1.5.6