46 string getLine(std::ifstream& is)
51 std::getline(is, line);
53 while (line.size() && line[0] ==
'#');
60 labelList parseVertices(
const string& line)
71 if (startNum == string::npos)
76 endNum = line.find(
' ', startNum);
79 if (endNum != string::npos)
81 vertexSpec = line.substr(startNum, endNum-startNum);
85 vertexSpec = line.substr(startNum, line.size() - startNum);
91 if (slashPos != string::npos)
112 int main(
int argc,
char *argv[])
122 std::ifstream OBJfile(objName.c_str());
136 bool hasWarned =
false;
139 while (OBJfile.good())
141 string line = getLine(OBJfile);
153 lineStream >> x >> y >> z;
157 else if (cmd ==
"vn")
161 lineStream >> x >> y >> z;
167 polyLines.
append(parseVertices(line));
171 polygons.
append(parseVertices(line));
180 <<
"Unrecognized OBJ command " << cmd << nl
181 <<
"In line " << lineStream.str()
182 <<
" at linenumber " << lineNo << nl
183 <<
"Only recognized commands are 'v' and 'l'.\n" 184 <<
"If this is a surface command use surfaceConvert instead" 185 <<
" to convert to a file format that can be read by VTK" 200 <<
"# vtk DataFile Version 2.0\n" 203 <<
"DATASET POLYDATA\n" 204 <<
"POINTS " << points.
size() <<
" float\n";
208 const point& pt = points[i];
210 outFile << pt.
x() <<
' ' << pt.
y() <<
' ' << pt.
z() <<
nl;
214 <<
"VERTICES " << points.
size() <<
' ' << (2 * points.
size()) << nl;
218 outFile << 1 <<
' ' << i <<
nl;
224 nItems += polyLines[polyI].
size() + 1;
228 <<
"LINES " << polyLines.
size() <<
' ' << nItems <<
nl;
232 const labelList& line = polyLines[polyI];
234 outFile << line.
size();
238 outFile <<
' ' << line[i];
247 nItems += polygons[polyI].
size() + 1;
251 <<
"POLYGONS " << polygons.
size() <<
' ' << nItems <<
nl;
257 outFile << line.
size();
261 outFile <<
' ' << line[i];
268 <<
"POINT_DATA " << points.
size() << nl
269 <<
"SCALARS pointID float 1\n" 270 <<
"LOOKUP_TABLE default\n";
286 if (!pointNormals.
empty())
288 outFile << nl <<
"NORMALS pointNormals float\n";
292 const vector& n = pointNormals[i];
294 outFile << n.
x() <<
' ' << n.
y() <<
' ' << n.
z() <<
nl;
#define forAll(list, i)
Loop across all elements in list.
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.
bool empty() const
Return true if the UList is empty (ie, size() is zero)
void size(const label)
Override size to be inconsistent with allocated storage.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static void noParallel()
Remove the parallel options.
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)