68 string getLine(std::ifstream& is)
73 std::getline(is, line);
75 while (line.size() && line[0] ==
'#');
82 labelList parseVertices(
const string& line)
87 string::size_type endNum = 1;
91 string::size_type startNum = line.find_first_not_of(
' ', endNum);
93 if (startNum == string::npos)
98 endNum = line.find(
' ', startNum);
101 if (endNum != string::npos)
103 vertexSpec = line.substr(startNum, endNum-startNum);
107 vertexSpec = line.substr(startNum, line.size() - startNum);
110 string::size_type slashPos = vertexSpec.find(
'/');
113 if (slashPos != string::npos)
135 int main(
int argc,
char *argv[])
146 std::ifstream OBJfile(objName.c_str());
159 bool hasWarned =
false;
162 while (OBJfile.good())
164 string line = getLine(OBJfile);
176 lineStream >> x >> y >> z;
182 polyLines.
append(parseVertices(line));
186 polygons.
append(parseVertices(line));
195 <<
"Unrecognized OBJ command " << cmd <<
nl
196 <<
"In line " << lineStream.str()
197 <<
" at linenumber " << lineNo <<
nl
198 <<
"Only recognized commands are 'v' and 'l'.\n"
199 <<
"If this is a surface command use surfaceConvert instead"
200 <<
" to convert to a file format that can be read by VTK"
215 <<
"# vtk DataFile Version 2.0\n"
218 <<
"DATASET POLYDATA\n"
219 <<
"POINTS " << points.
size() <<
" float\n";
223 const point& pt = points[i];
225 outFile << pt.
x() <<
' ' << pt.
y() <<
' ' << pt.
z() <<
nl;
231 nItems += polyLines[polyI].
size() + 1;
235 <<
"LINES " << polyLines.
size() <<
' ' << nItems <<
nl;
239 const labelList& line = polyLines[polyI];
241 outFile << line.
size();
245 outFile <<
' ' << line[i];
254 nItems += polygons[polyI].
size() + 1;
258 <<
"POLYGONS " << polygons.
size() <<
' ' << nItems <<
nl;
264 outFile << line.
size();
268 outFile <<
' ' << line[i];
275 <<
"POINT_DATA " << points.
size() << nl
276 <<
"SCALARS pointID float 1\n"
277 <<
"LOOKUP_TABLE default\n";