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" },
110 void Foam::vtkUnstructuredReader::warnUnhandledType
117 if (warningGiven.insert(
type))
120 <<
"Skipping unknown cell type " <<
type <<
nl;
127 void 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);
164 void 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);
432 void 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))
608 void Foam::vtkUnstructuredReader::read(ISstream& inFile)
610 inFile.getLine(header_);
625 inFile.getLine(title_);
628 inFile.getLine(dataType_);
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();
652 <<
"line:" << inFile.lineNumber()
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")
806 <<
"Reading " << nFaces
807 <<
" faces (single block)" <<
nl;
815 const label nOffsets(nFaces);
819 <<
"Reading offsets/connectivity for " 820 << nFaces <<
" faces" <<
nl;
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")
890 inFile.getLine(line);
891 ISpanStream is(line);
898 <<
"Reading scalar " << dataName
899 <<
" of type " << dataType
900 <<
" from lookup table" <<
nl;
902 word lookupTableTag(inFile);
903 if (lookupTableTag !=
"LOOKUP_TABLE")
906 <<
"Expected tag LOOKUP_TABLE but read " 907 << lookupTableTag <<
nl 911 word lookupTableName(inFile);
916 selectRegistry(readMode),
922 else if (tag ==
"VECTORS" || tag ==
"NORMALS")
926 inFile.getLine(line);
927 ISpanStream is(line);
932 <<
"Reading vector " << dataName
933 <<
" of type " << dataType <<
nl;
935 objectRegistry& reg = selectRegistry(readMode);
948 vtkDataTypeNames[dataType] == VTK_FLOAT
949 || vtkDataTypeNames[dataType] == VTK_DOUBLE
952 objectRegistry::iterator iter = reg.find(dataName);
953 scalarField s(*dynamic_cast<const scalarField*>(iter()));
957 IOobject(dataName,
"", reg),
962 for (
vector& val : fieldVals())
964 val.x() =
s[elemI++];
965 val.y() =
s[elemI++];
966 val.z() =
s[elemI++];
971 else if (tag ==
"TEXTURE_COORDINATES")
975 inFile.getLine(line);
976 ISpanStream is(line);
983 <<
"Reading texture coords " << dataName
984 <<
" dimension " << dim
985 <<
" of type " << dataType <<
nl;
988 readBlock(inFile, coords.size(), coords);
990 else if (tag ==
"TRIANGLE_STRIPS")
1004 <<
"Reading " << nStrips
1005 <<
" strips (single block)" <<
nl;
1011 label dataIndex = 0;
1012 for (label i = 0; i < nStrips; ++i)
1014 const label nVerts = elemVerts[dataIndex++];
1016 dataIndex += nVerts;
1024 const label nOffsets(nStrips);
1028 <<
"Reading offsets/connectivity for " 1029 << nStrips <<
" triangle strips." <<
nl;
1031 readOffsetsConnectivity
1035 nOffsets, elemOffsets,
1040 for (label i = 0; i < nStrips; ++i)
1042 const label nVerts = (elemOffsets[i+1] - elemOffsets[i]);
1048 label facei = faces_.size();
1049 faces_.resize(facei+nFaces);
1050 faceMap_.resize(faces_.size());
1052 label dataIndex = 0;
1053 for (label i = 0; i < nStrips; ++i)
1055 const label nVerts =
1058 ? elemVerts[dataIndex++]
1059 : (elemOffsets[i+1] - elemOffsets[i])
1061 const label nTris = nVerts-2;
1069 for (label triI = 0; triI < nTris; ++triI)
1071 faceMap_[facei] = facei;
1072 face&
f = faces_[facei++];
1077 if ((triI % 2) == 0)
1080 f[0] = elemVerts[dataIndex-2];
1081 f[1] = elemVerts[dataIndex-1];
1086 f[0] = elemVerts[dataIndex-1];
1087 f[1] = elemVerts[dataIndex-2];
1089 f[2] = elemVerts[dataIndex++];
1093 else if (tag ==
"METADATA")
1095 word infoTag(inFile);
1096 if (infoTag !=
"INFORMATION")
1099 <<
"Unsupported tag " 1105 <<
"Ignoring " << nInfo <<
" metadata information." <<
nl;
1108 inFile.getLine(
nullptr);
1109 for (label i = 0; i < 2*nInfo; i++)
1111 inFile.getLine(
nullptr);
1117 <<
"Unsupported tag " 1131 for (cellShape& shape : cells_)
1133 if (shape.model() == prism)
1148 const point bottomCc(bottom.centre());
1149 const vector bottomNormal(bottom.areaNormal());
1150 const point topCc(top.centre());
1152 if (((topCc - bottomCc) & bottomNormal) < 0)
1155 std::swap(shape[0], shape[3]);
1156 std::swap(shape[1], shape[4]);
1157 std::swap(shape[2], shape[5]);
1165 <<
" prismatic cells" <<
nl;
1171 Info<<
"Read points:" << points_.size()
1172 <<
" cells:" << cells_.size()
1173 <<
" faces:" << faces_.size()
1174 <<
" lines:" << lines_.size()
1177 Info<<
"Cell fields:" <<
nl;
1178 printFieldStats<vectorIOField>(cellData_);
1179 printFieldStats<scalarIOField>(cellData_);
1180 printFieldStats<labelIOField>(cellData_);
1181 printFieldStats<stringIOList>(cellData_);
1184 Info<<
"Point fields:" <<
nl;
1185 printFieldStats<vectorIOField>(pointData_);
1186 printFieldStats<scalarIOField>(pointData_);
1187 printFieldStats<labelIOField>(pointData_);
1188 printFieldStats<stringIOList>(pointData_);
1191 Info<<
"Other fields:" <<
nl;
1192 printFieldStats<vectorIOField>(otherData_);
1193 printFieldStats<scalarIOField>(otherData_);
1194 printFieldStats<labelIOField>(otherData_);
1195 printFieldStats<stringIOList>(otherData_);
SubList< label > labelSubList
A SubList of labels.
static void readBlock(Istream &is, const label n, List< T > &list)
void size(const label n)
Older name for setAddressableSize.
errorManipArg< error, int > exit(error &err, const int errNo=1)
void resize(const label len)
Adjust allocated size of list.
IOstream & hex(IOstream &io)
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
constexpr char nl
The newline '\n' character (0x0a)
bool empty() const noexcept
True if List is empty (ie, size() is zero)
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
bool store()
Register object with its registry and transfer ownership to the registry.
vtkDataSetType
Enumeration defining the vtk dataset types.
UList< label > labelUList
A UList of labels.
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
#define forAll(list, i)
Loop across all elements in list.
static const cellModel & ref(const modelType model)
Look up reference to cellModel by enumeration. Fatal on failure.
static const Enum< parseMode > parseModeNames
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
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.
vtkUnstructuredReader(const objectRegistry &obr, ISstream &is)
Construct from input stream, read all.
const labelList & cellTypes
#define DebugInfo
Report an information message using Foam::Info.
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
vtkDataType
Enumeration defining the vtk data types.
static bool split(const std::string &line, std::string &key, std::string &val)
Generic input stream using a standard (STL) stream.
vector point
Point is a vector.
#define WarningInFunction
Report a warning using Foam::Warning.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
static const Enum< vtkDataType > vtkDataTypeNames
triangle< point, const point & > triPointRef
A triangle using referred points.
parseMode
Enumeration defining the parse mode - type of data being read.
messageStream Info
Information stream (stdout output on master, null elsewhere)
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
static const Enum< vtkDataSetType > vtkDataSetTypeNames
Foam::SubStrings< StringType > splitSpace(const StringType &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.
Registry of regIOobjects.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
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))
Defines the attributes of an object for which implicit objectRegistry management is supported...
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...