44 string getLine(std::ifstream& is)
49 std::getline(is, line);
51 while (line.size() && line[0] ==
'#');
58 labelList parseVertices(
const string& line)
69 if (startNum == string::npos)
74 endNum = line.find(
' ', startNum);
77 if (endNum != string::npos)
79 vertexSpec = line.substr(startNum, endNum-startNum);
83 vertexSpec = line.substr(startNum, line.size() - startNum);
89 if (slashPos != string::npos)
110 int main(
int argc,
char *argv[])
121 std::ifstream OBJfile(objName.c_str());
135 bool hasWarned =
false;
138 while (OBJfile.good())
140 string line = getLine(OBJfile);
152 lineStream >> x >> y >> z;
156 else if (cmd ==
"vn")
160 lineStream >> x >> y >> z;
166 polyLines.
append(parseVertices(line));
170 polygons.
append(parseVertices(line));
179 <<
"Unrecognised OBJ command " << cmd << nl
180 <<
"In line " << lineStream.str()
181 <<
" at linenumber " << lineNo << nl
182 <<
"Only recognised commands are 'v' and 'l'.\n" 183 <<
"If this is a surface command use surfaceConvert instead" 184 <<
" to convert to a file format that can be read by VTK" 199 <<
"# vtk DataFile Version 2.0\n" 202 <<
"DATASET POLYDATA\n" 203 <<
"POINTS " << points.
size() <<
" float\n";
207 const point& pt = points[i];
209 outFile << pt.
x() <<
' ' << pt.
y() <<
' ' << pt.
z() <<
nl;
213 <<
"VERTICES " << points.
size() <<
' ' << (2 * points.
size()) << nl;
217 outFile << 1 <<
' ' << i <<
nl;
223 nItems += polyLines[polyI].
size() + 1;
227 <<
"LINES " << polyLines.
size() <<
' ' << nItems <<
nl;
231 const labelList& line = polyLines[polyI];
233 outFile << line.
size();
237 outFile <<
' ' << line[i];
246 nItems += polygons[polyI].
size() + 1;
250 <<
"POLYGONS " << polygons.
size() <<
' ' << nItems <<
nl;
256 outFile << line.
size();
260 outFile <<
' ' << line[i];
267 <<
"POINT_DATA " << points.
size() << nl
268 <<
"SCALARS pointID float 1\n" 269 <<
"LOOKUP_TABLE default\n";
285 if (!pointNormals.
empty())
287 outFile << nl <<
"NORMALS pointNormals float\n";
291 const vector& n = pointNormals[i];
293 outFile << n.
x() <<
' ' << n.
y() <<
' ' << n.
z() <<
nl;
#define forAll(list, i)
Loop across all elements in list.
bool empty() const
Return true if the UList is empty (ie, size() is zero)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
A class for handling file names.
errorManipArg< error, int > exit(error &err, const int errNo=1)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
void size(const label)
Override size to be inconsistent with allocated storage.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Vector< scalar > vector
A scalar version of the templated Vector.
A class for handling words, derived from string.
Extract command arguments and options from the supplied argc and argv parameters. ...
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
graph_traits< Graph >::vertices_size_type size_type
DynamicList< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
vector point
Point is a vector.
#define WarningInFunction
Report a warning using Foam::Warning.
Input from memory buffer stream.
Foam::argList args(argc, argv)