48string 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
105int 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"
232 <<
"POINTS " <<
points.size() <<
" double\n";
237 << float(pt.x()) <<
' '
238 << float(pt.y()) <<
' '
239 << float(pt.z()) <<
nl;
243 <<
"VERTICES " <<
points.size() <<
' ' << (2 *
points.size()) <<
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;
293 <<
"POINT_DATA " <<
points.size() <<
nl
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;
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
T & emplace_back(Args &&... args)
Construct an element at the end of the list, return reference to the new list element.
void push_back(const T &val)
Copy append an element to the end of this list.
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
Sub-ranges of a string with a structure similar to std::match_results, but without the underlying reg...
bool empty() const noexcept
True if List is empty (ie, size() is zero).
void size(const label n)
Older name for setAddressableSize.
Extract command arguments and options from the supplied argc and argv parameters.
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
static void noParallel()
Remove the parallel options.
static void addNote(const string ¬e)
Add extra notes for the usage information.
A class for handling file names.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
A class for handling words, derived from Foam::string.
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define WarningInFunction
Report a warning using Foam::Warning.
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).
List< label > labelList
A List of labels.
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
vector point
Point is a vector.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).
static label readObjVertices(const SubStrings &tokens, DynamicList< label > &verts)
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.