51 { vtkDataType::VTK_INT,
"int" },
53 { vtkDataType::VTK_UINT,
"unsigned_int" },
54 { vtkDataType::VTK_LONG,
"long" },
55 { vtkDataType::VTK_ULONG,
"unsigned_long" },
56 { vtkDataType::VTK_FLOAT,
"float" },
57 { vtkDataType::VTK_DOUBLE,
"double" },
58 { vtkDataType::VTK_STRING,
"string" },
59 { vtkDataType::VTK_ID,
"vtkIdType" },
69 { vtkDataSetType::VTK_FIELD,
"FIELD" },
70 { vtkDataSetType::VTK_SCALARS,
"SCALARS" },
71 { vtkDataSetType::VTK_VECTORS,
"VECTORS" },
81 { parseMode::NOMODE,
"NOMODE" },
82 { parseMode::UNSTRUCTURED_GRID,
"UNSTRUCTURED_GRID" },
83 { parseMode::POLYDATA,
"POLYDATA" },
84 { parseMode::CELL_DATA,
"CELL_DATA" },
85 { parseMode::POINT_DATA,
"POINT_DATA" },
110void Foam::vtkUnstructuredReader::warnUnhandledType
114 labelHashSet& warningGiven
117 if (warningGiven.insert(
type))
120 <<
"Skipping unknown cell type " <<
type <<
nl;
127void Foam::vtkUnstructuredReader::readOffsetsConnectivity
130 const char* entryName,
131 const label nOffsets,
133 const label nConnectivity,
140 if (!tok.isWord(
"OFFSETS"))
143 <<
"Expected OFFSETS for " << entryName
152 if (!tok.isWord(
"CONNECTIVITY"))
155 <<
"Expected CONNECTIVITY for " << entryName
156 <<
", found " << tok.info() <<
nl
160 readBlock(is, nConnectivity, connectivity);
164void Foam::vtkUnstructuredReader::extractCells
178 label nCells = 0,
nFaces = 0, nLines = 0;
212 label celli = cells_.size();
213 cells_.resize(celli + nCells);
214 cellMap_.resize(cells_.size(), -1);
216 label facei = faces_.size();
217 faces_.resize(facei +
nFaces);
218 faceMap_.resize(faces_.size(), -1);
220 label linei = lines_.size();
221 lines_.resize(linei + nLines);
222 lineMap_.resize(lines_.size(), -1);
239 ? elemVerts[dataIndex++]
240 : (elemOffsets[elemi+1] - elemOffsets[elemi])
251 warnUnhandledType(is,
cellTypes[elemi], warningGiven);
255 <<
"Expected size 1 for VTK_VERTEX, found "
264 warnUnhandledType(is,
cellTypes[elemi], warningGiven);
273 <<
"Expected size 2 for VTK_LINE, found "
277 lineMap_[linei] = elemi;
280 lines_[linei++] = verts;
286 lineMap_[linei] = elemi;
289 lines_[linei++] = verts;
298 <<
"Expected size 3 for VTK_TRIANGLE, found "
302 faceMap_[facei] = elemi;
305 static_cast<labelList&
>(faces_[facei++]) = verts;
314 <<
"Expected size 4 for VTK_QUAD, found "
318 faceMap_[facei] = elemi;
321 static_cast<labelList&
>(faces_[facei++]) = verts;
327 faceMap_[facei] = elemi;
330 static_cast<labelList&
>(faces_[facei++]) = verts;
339 <<
"Expected size 4 for VTK_TETRA, found "
343 cellMap_[celli] = elemi;
346 cells_[celli++].reset(tet, verts,
true);
355 <<
"Expected size 5 for VTK_PYRAMID, found "
359 cellMap_[celli] = elemi;
362 cells_[celli++].reset(pyr, verts,
true);
371 <<
"Expected size 6 for VTK_WEDGE, found "
375 cellMap_[celli] = elemi;
386 cells_[celli++].reset(prism, shape,
true);
395 <<
"Expected size 8 for VTK_HEXAHEDRON, found "
399 cellMap_[celli] = elemi;
402 cells_[celli++].reset(
hex, verts,
true);
408 warnUnhandledType(is,
cellTypes[elemi], warningGiven);
416 <<
" cells:" << celli
417 <<
" faces:" << facei
418 <<
" lines:" << linei
421 cells_.resize(celli);
422 cellMap_.resize(celli);
424 faces_.resize(facei);
425 faceMap_.resize(facei);
427 lines_.resize(linei);
428 lineMap_.resize(linei);
432void Foam::vtkUnstructuredReader::readField
436 const word& arrayName,
437 const word& dataType,
441 if (vtkDataTypeNames.found(dataType))
443 switch (vtkDataTypeNames[dataType])
454 IOobject(arrayName,
"", obj),
457 readBlock(inFile, fieldVals().size(), fieldVals());
467 IOobject(arrayName,
"", obj),
470 readBlock(inFile, fieldVals().size(), fieldVals());
478 <<
"Reading strings:" << size <<
nl;
482 IOobject(arrayName,
"", obj),
486 inFile.getLine(fieldVals()[0]);
489 for (
string&
s : fieldVals())
500 <<
"Unhandled type " << dataType <<
nl
501 <<
"Skipping " << size
512 <<
"Unhandled type " << dataType <<
nl
513 <<
"Skipping " << size
525 const label wantedSize
530 word dataName(inFile);
533 <<
"dataName:" << dataName <<
nl;
538 Pout<<
"numArrays:" << numArrays <<
nl;
540 for (label i = 0; i < numArrays; i++)
542 word arrayName(inFile);
545 word dataType(inFile);
548 <<
"Reading field " << arrayName
549 <<
" of " << numTuples <<
" tuples of rank " << numComp <<
nl;
551 if (wantedSize != -1 && numTuples != wantedSize)
554 <<
"Expected " << wantedSize <<
" tuples but only have "
575 const parseMode readMode
578 if (readMode == CELL_DATA)
582 else if (readMode == POINT_DATA)
600 cellData_(
IOobject(
"cellData", obr)),
601 pointData_(
IOobject(
"pointData", obr)),
602 otherData_(
IOobject(
"otherData", obr))
631 if (dataType_ ==
"BINARY")
634 <<
"Binary reading not supported" <<
nl
638 parseMode readMode = NOMODE;
639 label wantedSize = -1;
647 while (inFile.
read(tok).
good() && tok.isWord())
649 const word tag = tok.wordToken();
653 <<
" tag:" << tag <<
nl;
655 if (tag ==
"DATASET")
657 word geomType(inFile);
660 readMode = parseModeNames[geomType];
663 else if (tag ==
"POINTS")
669 <<
"Reading " <<
nPoints <<
" coordinates" <<
nl;
671 word primitiveTag(inFile);
672 if (primitiveTag !=
"float" && primitiveTag !=
"double")
675 <<
"Expected 'float' entry, found "
676 << primitiveTag <<
nl
681 inFile >>
p.x() >>
p.y() >>
p.z();
684 else if (tag ==
"CELLS")
693 <<
"Reading " << nCells
694 <<
" cells/faces (single block)" <<
nl;
703 const label nOffsets(nCells);
707 <<
"Reading offsets/connectivity for "
708 << nCells <<
" cells/faces" <<
nl;
710 readOffsetsConnectivity
714 nOffsets, cellOffsets,
719 else if (tag ==
"CELL_TYPES")
721 const label nCellTypes(
readLabel(inFile));
730 <<
" cellTypes but no cells." <<
nl
734 extractCells(inFile,
cellTypes, cellOffsets, cellVerts);
738 else if (tag ==
"LINES")
749 <<
"Reading " << nLines
750 <<
" lines (single block)" <<
nl;
758 const label nOffsets(nLines);
762 <<
"Reading offsets/connectivity for "
763 << nLines <<
" lines" <<
nl;
765 readOffsetsConnectivity
769 nOffsets, elemOffsets,
775 label linei = lines_.size();
776 lines_.resize(linei+nLines);
777 lineMap_.resize(lines_.size());
780 for (label i = 0; i < nLines; i++)
785 ? elemVerts[dataIndex++]
786 : (elemOffsets[i+1] - elemOffsets[i])
791 lineMap_[linei] = linei;
792 lines_[linei++] = verts;
795 else if (tag ==
"POLYGONS")
807 <<
" faces (single block)" <<
nl;
815 const label nOffsets(
nFaces);
819 <<
"Reading offsets/connectivity for "
822 readOffsetsConnectivity
826 nOffsets, elemOffsets,
832 label facei = faces_.size();
833 faces_.resize(facei+
nFaces);
834 faceMap_.resize(faces_.size());
837 for (label i = 0; i <
nFaces; ++i)
842 ? elemVerts[dataIndex++]
843 : (elemOffsets[i+1] - elemOffsets[i])
848 faceMap_[facei] = facei;
849 static_cast<labelList&
>(faces_[facei++]) = verts;
852 else if (tag ==
"POINT_DATA")
856 wantedSize = points_.size();
862 <<
"Reading POINT_DATA : expected " << wantedSize
867 else if (tag ==
"CELL_DATA")
870 wantedSize = cells_.size()+faces_.size()+lines_.size();
873 if (nCells != wantedSize)
876 <<
"Reading CELL_DATA : expected "
878 <<
" but read " << nCells <<
nl
882 else if (tag ==
"FIELD")
885 readFieldArray(inFile, selectRegistry(readMode), wantedSize);
887 else if (tag ==
"SCALARS")
891 IStringStream is(line);
897 <<
"Reading scalar " << dataName
898 <<
" of type " << dataType
899 <<
" from lookup table" <<
nl;
901 word lookupTableTag(inFile);
902 if (lookupTableTag !=
"LOOKUP_TABLE")
905 <<
"Expected tag LOOKUP_TABLE but read "
906 << lookupTableTag <<
nl
910 word lookupTableName(inFile);
915 selectRegistry(readMode),
921 else if (tag ==
"VECTORS" || tag ==
"NORMALS")
926 IStringStream is(line);
930 <<
"Reading vector " << dataName
931 <<
" of type " << dataType <<
nl;
933 objectRegistry& reg = selectRegistry(readMode);
946 vtkDataTypeNames[dataType] == VTK_FLOAT
947 || vtkDataTypeNames[dataType] == VTK_DOUBLE
950 objectRegistry::iterator iter = reg.find(dataName);
955 IOobject(dataName,
"", reg),
960 for (
vector& val : fieldVals())
962 val.x() =
s[elemI++];
963 val.y() =
s[elemI++];
964 val.z() =
s[elemI++];
969 else if (tag ==
"TEXTURE_COORDINATES")
974 IStringStream is(line);
980 <<
"Reading texture coords " << dataName
981 <<
" dimension " << dim
982 <<
" of type " << dataType <<
nl;
985 readBlock(inFile, coords.size(), coords);
987 else if (tag ==
"TRIANGLE_STRIPS")
1001 <<
"Reading " << nStrips
1002 <<
" strips (single block)" <<
nl;
1008 label dataIndex = 0;
1009 for (label i = 0; i < nStrips; ++i)
1011 const label nVerts = elemVerts[dataIndex++];
1013 dataIndex += nVerts;
1021 const label nOffsets(nStrips);
1025 <<
"Reading offsets/connectivity for "
1026 << nStrips <<
" triangle strips." <<
nl;
1028 readOffsetsConnectivity
1032 nOffsets, elemOffsets,
1037 for (label i = 0; i < nStrips; ++i)
1039 const label nVerts = (elemOffsets[i+1] - elemOffsets[i]);
1045 label facei = faces_.
size();
1046 faces_.resize(facei+
nFaces);
1047 faceMap_.resize(faces_.size());
1049 label dataIndex = 0;
1050 for (label i = 0; i < nStrips; ++i)
1052 const label nVerts =
1055 ? elemVerts[dataIndex++]
1056 : (elemOffsets[i+1] - elemOffsets[i])
1058 const label nTris = nVerts-2;
1066 for (label triI = 0; triI < nTris; ++triI)
1068 faceMap_[facei] = facei;
1069 face&
f = faces_[facei++];
1074 if ((triI % 2) == 0)
1077 f[0] = elemVerts[dataIndex-2];
1078 f[1] = elemVerts[dataIndex-1];
1083 f[0] = elemVerts[dataIndex-1];
1084 f[1] = elemVerts[dataIndex-2];
1086 f[2] = elemVerts[dataIndex++];
1090 else if (tag ==
"METADATA")
1092 word infoTag(inFile);
1093 if (infoTag !=
"INFORMATION")
1096 <<
"Unsupported tag "
1102 <<
"Ignoring " << nInfo <<
" metadata information." <<
nl;
1106 for (label i = 0; i < 2*nInfo; i++)
1114 <<
"Unsupported tag "
1128 for (cellShape& shape : cells_)
1130 if (shape.model() == prism)
1145 const point bottomCc(bottom.centre());
1146 const vector bottomNormal(bottom.areaNormal());
1147 const point topCc(top.centre());
1149 if (((topCc - bottomCc) & bottomNormal) < 0)
1152 std::swap(shape[0], shape[3]);
1153 std::swap(shape[1], shape[4]);
1154 std::swap(shape[2], shape[5]);
1162 <<
" prismatic cells" <<
nl;
1168 Info<<
"Read points:" << points_.size()
1169 <<
" cells:" << cells_.size()
1170 <<
" faces:" << faces_.size()
1171 <<
" lines:" << lines_.size()
1174 Info<<
"Cell fields:" <<
nl;
1175 printFieldStats<vectorIOField>(cellData_);
1176 printFieldStats<scalarIOField>(cellData_);
1177 printFieldStats<labelIOField>(cellData_);
1178 printFieldStats<stringIOList>(cellData_);
1181 Info<<
"Point fields:" <<
nl;
1182 printFieldStats<vectorIOField>(pointData_);
1183 printFieldStats<scalarIOField>(pointData_);
1184 printFieldStats<labelIOField>(pointData_);
1185 printFieldStats<stringIOList>(pointData_);
1188 Info<<
"Other fields:" <<
nl;
1189 printFieldStats<vectorIOField>(otherData_);
1190 printFieldStats<scalarIOField>(otherData_);
1191 printFieldStats<labelIOField>(otherData_);
1192 printFieldStats<stringIOList>(otherData_);
static bool split(const std::string &line, std::string &key, std::string &val)
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Defines the attributes of an object for which implicit objectRegistry management is supported,...
label lineNumber() const noexcept
Const access to the current stream line number.
bool good() const noexcept
True if next operation might succeed.
Generic input stream using a standard (STL) stream.
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
virtual Istream & read(token &t)
Return next token from stream.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void resize(const label len)
Adjust allocated size of list.
virtual bool read()
Re-read model coefficients if they have changed.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
void size(const label n)
Older name for setAddressableSize.
reference ref() const
A reference to the entry (Error if not found)
Registry of regIOobjects.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
Reader for vtk UNSTRUCTURED_GRID legacy files. Supports single CELLS, POINTS etc. entry only.
static const Enum< parseMode > parseModeNames
static const Enum< vtkDataSetType > vtkDataSetTypeNames
vtkDataSetType
Enumeration defining the vtk dataset types.
static const Enum< vtkDataType > vtkDataTypeNames
parseMode
Enumeration defining the parse mode - type of data being read.
vtkDataType
Enumeration defining the vtk data types.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
const labelList nFaces(UPstream::listGatherValues< label >(aMesh.nFaces()))
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
#define DebugInfo
Report an information message using Foam::Info.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
#define WarningInFunction
Report a warning using Foam::Warning.
Foam::SubStrings< StringType > splitSpace(const StringType &str)
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)
vector point
Point is a vector.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
triangle< point, const point & > triPointRef
A triangle using referred points.
SubList< label > labelSubList
A SubList of labels.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
UList< label > labelUList
A UList of labels.
static void readBlock(Istream &is, const label n, List< T > &list)
constexpr char nl
The newline '\n' character (0x0a)
const labelList & cellTypes
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
#define forAll(list, i)
Loop across all elements in list.