1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main ()
{
ifstream myobject("Model_1.txt");
string line;
int number_of_lines = 0,counter=0,i=0;
/* if(!myobject.good())
{
cout << " Problem reading Object file! Aborting. ";
}
int number_of_lines = 0,counter=0,i=0;
while ( getline(myobject, line) )
{
++number_of_lines;
cout << number_of_lines << " " << line << endl; // Test
}
myobject.close();
*/
cout << "*************************************************************" << endl;
/*************************************************************/
// myobject.open("Model_1.txt");
// cout << 1 <<endl;
if(!myobject.good())
{
cout << " Problem reading Object file! Aborting. " << endl;
return 1;
}
int Buffer_float_vector[3];
float Buffer_int_vector[3];
float Coordinate_Matrix[number_of_lines][3];
// cout << 2 << endl;
counter=0;
while(!myobject.eof() )
{
getline(myobject, line);
cout << number_of_lines << " " << line << endl; // Test
if (line.c_str()[0] == 'v'){
line[0]=' '; // set pointer to 0 at the 1st character found
sscanf(line.c_str(),"%f %f %f", &Buffer_float_vector[0],
&Buffer_float_vector[1],
&Buffer_float_vector[2]);
cout << counter << endl;
cout << Buffer_float_vector[0] <<" "<< Buffer_float_vector[1] <<" "<< Buffer_float_vector[2] << endl; //
for(i=0;i=2;i++){
Coordinate_Matrix[counter][i]=Buffer_float_vector[i];
Buffer_float_vector[i]= ' '; //
}
counter++;
}
if (line.c_str()[0] == 'f'){
line[0] = ' ';
sscanf(line.c_str(),"%i %i %i",
&Buffer_int_vector[0],
&Buffer_int_vector[1],
&Buffer_int_vector[2] );
cout << counter << endl; //
for(int i=0;i=2;i++){
Coordinate_Matrix[counter][i]=Buffer_float_vector[i];
Buffer_int_vector[i]=' ';
}
counter++;
}
else{
counter = -1;
}
}
cout << " First Matrix Element : " << Coordinate_Matrix[1][0] << " || " << Coordinate_Matrix[1][1]
<< " || " << Coordinate_Matrix[0][2] << endl;
cout << " Last Matrix Element : " << Coordinate_Matrix[number_of_lines][0] << " || "
<< Coordinate_Matrix[number_of_lines][1] << " || "
<< Coordinate_Matrix[number_of_lines][2] << " || " << endl;
cout << " counter = " << counter;
myobject.close();
return 0;
}
|