Go to the documentation of this file.
48 string getLine(std::ifstream& is)
53 std::getline(is,
line);
55 while (
line.starts_with(
'#'));
73 if (startNum == string::npos)
78 endNum =
line.find(
' ', startNum);
81 if (endNum != string::npos)
83 vertexSpec =
line.substr(startNum, endNum-startNum);
87 vertexSpec =
line.substr(startNum,
line.size() - startNum);
93 if (slashPos != string::npos)
114 int main(
int argc,
char *argv[])
118 "Read obj line (not surface) file and convert into legacy VTK file"
129 std::ifstream OBJfile(objName);
131 Info<<
"Processing file " << objName <<
endl;
145 bool hasWarned =
false;
148 while (OBJfile.good())
150 const string line = getLine(OBJfile);
153 if (
line.empty())
continue;
157 word cmd(lineStream);
163 lineStream >>
x >>
y >> z;
167 else if (cmd ==
"vn")
171 lineStream >>
x >>
y >> z;
190 <<
"Unrecognized OBJ command " << cmd <<
nl
191 <<
"In line " << lineStream.str()
192 <<
" at linenumber " << lineNo <<
nl
193 <<
"Only recognized commands are 'v' and 'l'.\n"
194 <<
"If this is a surface command use surfaceConvert instead"
195 <<
" to convert to a file format that can be read by VTK"
210 <<
"# vtk DataFile Version 2.0\n"
213 <<
"DATASET POLYDATA\n"
214 <<
"POINTS " <<
points.size() <<
" double\n";
219 << float(pt.x()) <<
' '
220 << float(pt.y()) <<
' '
221 << float(pt.z()) <<
nl;
225 <<
"VERTICES " <<
points.size() <<
' ' << (2 *
points.size()) <<
nl;
229 outFile << 1 <<
' ' << i <<
nl;
235 nItems += polyLines[polyI].size() + 1;
239 <<
"LINES " << polyLines.size() <<
' ' << nItems <<
nl;
245 outFile <<
line.size();
249 outFile <<
' ' <<
line[i];
258 nItems += polygons[polyI].size() + 1;
262 <<
"POLYGONS " << polygons.size() <<
' ' << nItems <<
nl;
268 outFile <<
line.size();
272 outFile <<
' ' <<
line[i];
279 <<
"POINT_DATA " <<
points.size() <<
nl
280 <<
"SCALARS pointID double 1\n"
281 <<
"LOOKUP_TABLE default\n";
297 if (!pointNormals.empty())
299 outFile <<
nl <<
"NORMALS pointNormals double\n";
301 for(
const vector&
n : pointNormals)
304 << float(
n.x()) <<
' '
305 << float(
n.y()) <<
' '
306 << float(
n.z()) <<
nl;
A class for handling words, derived from Foam::string.
A class for handling file names.
static void addNote(const string ¬e)
Extract command arguments and options from the supplied argc and argv parameters.
Input/output from string buffers.
Ostream & endl(Ostream &os)
DynamicList< T, SizeMin > & shrink()
T get(const label index) const
static void addArgument(const string &argName, const string &usage="")
DynamicList< T, SizeMin > & append(const T &val)
graph_traits< Graph >::vertices_size_type size_type
Vector< scalar > vector
A scalar version of the templated Vector.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Output to file stream, using an OSstream.
#define FatalErrorInFunction
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
vector point
Point is a vector.
Foam::argList args(argc, argv)
#define WarningInFunction