48 string getLine(std::ifstream& is)
53 std::getline(is,
line);
55 while (
line.starts_with(
'#'));
75 for (
const auto& tok : tokens)
84 std::string vrtSpec(tok.str());
88 const auto slash = vrtSpec.find(
'/');
89 slash != std::string::npos
105 int main(
int argc,
char *argv[])
109 "Read obj line (not surface) file and convert into legacy VTK file" 120 std::ifstream OBJfile(objName);
122 Info<<
"Processing file " << objName <<
endl;
138 bool hasWarned =
false;
141 while (OBJfile.good())
143 const string line = getLine(OBJfile);
146 if (
line.empty())
continue;
151 if (tokens.size() < 2)
165 readScalar(tokens[1]),
166 readScalar(tokens[2]),
167 readScalar(tokens[3])
170 else if (cmd ==
"vn")
177 readScalar(tokens[1]),
178 readScalar(tokens[2]),
179 readScalar(tokens[3])
208 <<
"Unrecognized OBJ command " << cmd <<
nl 209 <<
"In line " <<
line 210 <<
" at linenumber " << lineNo <<
nl 211 <<
"Only recognized commands are 'v' and 'l'.\n" 212 <<
"If this is a surface command use surfaceConvert instead" 213 <<
" to convert to a file format that can be read by VTK" 228 <<
"# vtk DataFile Version 2.0\n" 231 <<
"DATASET POLYDATA\n" 237 << float(pt.x()) <<
' ' 238 <<
float(pt.y()) <<
' ' 239 <<
float(pt.z()) <<
nl;
247 outFile << 1 <<
' ' << i <<
nl;
253 nItems +=
line.size() + 1;
257 <<
"LINES " << polyLines.size() <<
' ' << nItems <<
nl;
261 outFile <<
line.size();
263 for (
const label vrt :
line)
265 outFile <<
' ' << vrt;
274 nItems +=
line.size() + 1;
278 <<
"POLYGONS " << polygons.size() <<
' ' << nItems <<
nl;
282 outFile <<
line.size();
284 for (
const label vrt :
line)
286 outFile <<
' ' << vrt;
294 <<
"SCALARS pointID double 1\n" 295 <<
"LOOKUP_TABLE default\n";
311 if (!pointNormals.
empty())
313 outFile <<
nl <<
"NORMALS pointNormals double\n";
315 for(
const vector&
n : pointNormals)
318 << float(
n.x()) <<
' ' 319 <<
float(
n.y()) <<
' ' 320 <<
float(
n.z()) <<
nl;
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
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)
Foam::SubStrings splitSpace(const std::string &str, std::string::size_type pos=0)
Split string into sub-strings at whitespace (TAB, NL, VT, FF, CR, SPC)
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.
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.
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
static void noParallel()
Remove the parallel options.
Sub-ranges of a string with a structure similar to std::match_results, but without the underlying reg...
#define forAll(list, i)
Loop across all elements in list.
A class for handling words, derived from Foam::string.
T & emplace_back(Args &&... args)
Construct an element at the end of the list, return reference to the new list element.
Extract command arguments and options from the supplied argc and argv parameters. ...
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
static label readObjVertices(const SubStrings &tokens, DynamicList< label > &verts)
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
void push_back(const T &val)
Copy append an element to the end of this list.
T & emplace_back(Args &&... args)
Construct an element at the end of the list, return reference to the new list element.
T get(const label index) const
Get a value from the argument at index.
#define WarningInFunction
Report a warning using Foam::Warning.
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)