00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TriangleMesh.h"
00013 #include <fstream>
00014 #include <iostream>
00015
00016 using namespace std;
00017
00018
00019 namespace columbia
00020 {
00021
00022 static bool skip_comment_line(istream& is, char comment_tag)
00023 {
00024 char next;
00025 while( is >> skipws >> next )
00026 {
00027 is.putback(next);
00028
00029 if(next == comment_tag)
00030 {
00031 while( is >> noskipws >> next && next != '\n' );
00032 }
00033 else
00034 return true;
00035 }
00036 return false;
00037 }
00038
00039
00040 TriangleMesh :: TriangleMesh(const char* obj_fname)
00041 {
00042 float x, y, z;
00043 int i, j, k;
00044
00045 ifstream is(obj_fname);
00046
00047 if(is)
00048 {
00049 V.push_back( Vertex() );
00050 while( skip_comment_line(is, '#') )
00051 {
00052 char type;
00053 if( ! (is >> type) ) break;
00054
00055 if(type == 'v')
00056 {
00057 is >> x >> y >> z;
00058
00059
00060 V.push_back( Vertex(4200 * x, 4200 * y, 4200 * z) );
00061 }
00062 else if(type == 'f')
00063 {
00064 is >> i >> j >> k;
00065 F.push_back( TriangleFace(i,j,k) );
00066 }
00067 }
00068 total_triangles = F.size();
00069 is.close();
00070 }
00071 else
00072 cerr << "Can't open input file " << obj_fname << endl;
00073 }
00074 };
00075
00076
00077
00078