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" 219 << float(pt.x()) <<
' ' 220 <<
float(pt.y()) <<
' ' 221 <<
float(pt.z()) <<
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];
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;
static void addNote(const string ¬e)
Add extra notes for the usage information.
void size(const label n)
Older name for setAddressableSize.
A class for handling file names.
errorManipArg< error, int > exit(error &err, const int errNo=1)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Input/output from string buffers.
void append(const T &val)
Append an element at the end of the list.
Output to file stream as an OSstream, normally using std::ofstream for the actual output...
constexpr char nl
The newline '\n' character (0x0a)
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static void noParallel()
Remove the parallel options.
#define forAll(list, i)
Loop across all elements in list.
A class for handling words, derived from Foam::string.
Extract command arguments and options from the supplied argc and argv parameters. ...
void append(const T &val)
Copy append an element to the end of this list.
graph_traits< Graph >::vertices_size_type size_type
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
DynamicList< T, SizeMin > & shrink()
Calls shrink_to_fit() and returns a reference to the DynamicList.
vector point
Point is a vector.
T get(const label index) const
Get a value from the argument at index.
#define WarningInFunction
Report a warning using Foam::Warning.
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::argList args(argc, argv)