39 int read_obj( istream &is, vector<double> &coors,
45 is.getline( buf, MAXLEN);
46 if ( strncmp( buf,
"#OBJ", 4)==0 && !is.eof()) {
47 face_type = buf[4] -
'0';
48 assert( face_type == 3 || face_type == 4 || face_type == 6);
49 do { is.getline( buf, MAXLEN); }
while ( buf[0]==
'#' && !is.eof());
52 if ( strcmp( buf,
"off")==0 || strcmp( buf,
"OFF")==0 )
53 do { is.getline( buf, MAXLEN); }
while ( buf[0]==
'#' && !is.eof());
54 sscanf( buf,
"%d %d", &np, &nf);
57 coors.reserve( np*3); elems.reserve( nf*face_type);
60 for (
int i=0;
i<np; ++
i) {
61 do { is.getline( buf, MAXLEN); }
while ( buf[0]==
'#' && !is.eof());
63 sscanf( buf,
"%lf %lf %lf", &p0, &p1, &p2);
64 coors.push_back( p0); coors.push_back( p1); coors.push_back( p2);
68 vector<int> f( face_type);
69 while( is.peek() ==
'#' && !is.eof()) is.getline( buf, MAXLEN);
70 for (
int i=0;
i<nf; ++
i) {
71 for (
int j=0;
j<face_type; ++
j) {
72 is >> f[
j]; assert( f[
j] >= 1 && f[
j] <= np);
73 elems.push_back( f[
j]);
81 void read_ij( istream &is, vector<double> &coors,
int dims[2]) {
85 do { is.getline( buf, MAXLEN); }
while ( buf[0]==
'#' && !is.eof());
86 sscanf( buf,
"%d %d", &dims[0], &dims[1]);
88 int np=dims[0]*dims[1];
92 for (
int i=0;
i<np; ++
i) {
93 do { is.getline( buf, MAXLEN); }
while ( buf[0]==
'#' && !is.eof());
95 sscanf( buf,
"%lf %lf %lf", &p0, &p1, &p2);
96 coors.push_back( p0); coors.push_back( p1); coors.push_back( p2);
101 void write_ij( ostream &os,
const vector<double> &coors,
int dims[]) {
102 os << dims[0] <<
" " << dims[1] << endl;
106 for (
unsigned int i=0;
i<coors.size();
i+=3) {
107 sprintf( buf,
"%.10E\t%.10E\t%.10E", coors[
i],
108 coors[i+1], coors[i+2]);
int read_obj(std::istream &is, vector< double > &coors, vector< int > &elems)
void write_ij(ostream &os, const vector< double > &coors, int dims[])
void read_ij(std::istream &is, vector< double > &coors, int dims[2])