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 " 576 const parseMode readMode
579 if (readMode == CELL_DATA)
583 else if (readMode == POINT_DATA)
601 cellData_(
IOobject(
"cellData", obr)),
602 pointData_(
IOobject(
"pointData", obr)),
603 otherData_(
IOobject(
"otherData", obr))
609 void Foam::vtkUnstructuredReader::read(ISstream& inFile)
611 inFile.getLine(header_);
626 inFile.getLine(title_);
629 inFile.getLine(dataType_);
632 if (dataType_ ==
"BINARY")
635 <<
"Binary reading not supported" <<
nl 639 parseMode readMode = NOMODE;
640 label wantedSize = -1;
648 while (inFile.read(tok).good() && tok.isWord())
650 const word tag = tok.wordToken();
653 <<
"line:" << inFile.lineNumber()
654 <<
" tag:" << tag <<
nl;
656 if (tag ==
"DATASET")
658 word geomType(inFile);
661 readMode = parseModeNames[geomType];
664 else if (tag ==
"POINTS")
670 <<
"Reading " <<
nPoints <<
" coordinates" <<
nl;
672 word primitiveTag(inFile);
673 if (primitiveTag !=
"float" && primitiveTag !=
"double")
676 <<
"Expected 'float' entry, found " 677 << primitiveTag <<
nl 682 inFile >>
p.x() >>
p.y() >>
p.z();
685 else if (tag ==
"CELLS")
694 <<
"Reading " << nCells
695 <<
" cells/faces (single block)" <<
nl;
704 const label nOffsets(nCells);
708 <<
"Reading offsets/connectivity for " 709 << nCells <<
" cells/faces" <<
nl;
711 readOffsetsConnectivity
715 nOffsets, cellOffsets,
720 else if (tag ==
"CELL_TYPES")
722 const label nCellTypes(
readLabel(inFile));
731 <<
" cellTypes but no cells." <<
nl 735 extractCells(inFile,
cellTypes, cellOffsets, cellVerts);
739 else if (tag ==
"LINES")
750 <<
"Reading " << nLines
751 <<
" lines (single block)" <<
nl;
759 const label nOffsets(nLines);
763 <<
"Reading offsets/connectivity for " 764 << nLines <<
" lines" <<
nl;
766 readOffsetsConnectivity
770 nOffsets, elemOffsets,
776 label linei = lines_.size();
777 lines_.resize(linei+nLines);
778 lineMap_.resize(lines_.size());
781 for (label i = 0; i < nLines; i++)
786 ? elemVerts[dataIndex++]
787 : (elemOffsets[i+1] - elemOffsets[i])
792 lineMap_[linei] = linei;
793 lines_[linei++] = verts;
796 else if (tag ==
"POLYGONS")
807 <<
"Reading " << nFaces
808 <<
" faces (single block)" <<
nl;
816 const label nOffsets(nFaces);
820 <<
"Reading offsets/connectivity for " 821 << nFaces <<
" faces" <<
nl;
823 readOffsetsConnectivity
827 nOffsets, elemOffsets,
833 label facei = faces_.size();
834 faces_.resize(facei+nFaces);
835 faceMap_.resize(faces_.size());
838 for (label i = 0; i < nFaces; ++i)
843 ? elemVerts[dataIndex++]
844 : (elemOffsets[i+1] - elemOffsets[i])
849 faceMap_[facei] = facei;
850 static_cast<labelList&
>(faces_[facei++]) = verts;
853 else if (tag ==
"POINT_DATA")
857 wantedSize = points_.size();
863 <<
"Reading POINT_DATA : expected " << wantedSize
868 else if (tag ==
"CELL_DATA")
871 wantedSize = cells_.size()+faces_.size()+lines_.size();
874 if (nCells != wantedSize)
877 <<
"Reading CELL_DATA : expected " 879 <<
" but read " << nCells <<
nl 883 else if (tag ==
"FIELD")
886 readFieldArray(inFile, selectRegistry(readMode), wantedSize);
888 else if (tag ==
"SCALARS")
891 inFile.getLine(line);
892 ISpanStream is(line);
899 <<
"Reading scalar " << dataName
900 <<
" of type " << dataType
901 <<
" from lookup table" <<
nl;
903 word lookupTableTag(inFile);
904 if (lookupTableTag !=
"LOOKUP_TABLE")
907 <<
"Expected tag LOOKUP_TABLE but read " 908 << lookupTableTag <<
nl 912 word lookupTableName(inFile);
917 selectRegistry(readMode),
923 else if (tag ==
"VECTORS" || tag ==
"NORMALS")
927 inFile.getLine(line);
928 ISpanStream is(line);
933 <<
"Reading vector " << dataName
934 <<
" of type " << dataType <<
nl;
936 objectRegistry& reg = selectRegistry(readMode);
949 vtkDataTypeNames[dataType] == VTK_FLOAT
950 || vtkDataTypeNames[dataType] == VTK_DOUBLE
953 objectRegistry::iterator iter = reg.find(dataName);
954 scalarField s(*dynamic_cast<const scalarField*>(iter()));
958 IOobject(dataName,
"", reg),
963 for (
vector& val : fieldVals())
965 val.x() =
s[elemI++];
966 val.y() =
s[elemI++];
967 val.z() =
s[elemI++];
972 else if (tag ==
"TEXTURE_COORDINATES")
976 inFile.getLine(line);
977 ISpanStream is(line);
984 <<
"Reading texture coords " << dataName
985 <<
" dimension " << dim
986 <<
" of type " << dataType <<
nl;
989 readBlock(inFile, coords.size(), coords);
991 else if (tag ==
"TRIANGLE_STRIPS")
1005 <<
"Reading " << nStrips
1006 <<
" strips (single block)" <<
nl;
1012 label dataIndex = 0;
1013 for (label i = 0; i < nStrips; ++i)
1015 const label nVerts = elemVerts[dataIndex++];
1017 dataIndex += nVerts;
1025 const label nOffsets(nStrips);
1029 <<
"Reading offsets/connectivity for " 1030 << nStrips <<
" triangle strips." <<
nl;
1032 readOffsetsConnectivity
1036 nOffsets, elemOffsets,
1041 for (label i = 0; i < nStrips; ++i)
1043 const label nVerts = (elemOffsets[i+1] - elemOffsets[i]);
1049 label facei = faces_.size();
1050 faces_.resize(facei+nFaces);
1051 faceMap_.resize(faces_.size());
1053 label dataIndex = 0;
1054 for (label i = 0; i < nStrips; ++i)
1056 const label nVerts =
1059 ? elemVerts[dataIndex++]
1060 : (elemOffsets[i+1] - elemOffsets[i])
1062 const label nTris = nVerts-2;
1070 for (label triI = 0; triI < nTris; ++triI)
1072 faceMap_[facei] = facei;
1073 face&
f = faces_[facei++];
1078 if ((triI % 2) == 0)
1081 f[0] = elemVerts[dataIndex-2];
1082 f[1] = elemVerts[dataIndex-1];
1087 f[0] = elemVerts[dataIndex-1];
1088 f[1] = elemVerts[dataIndex-2];
1090 f[2] = elemVerts[dataIndex++];
1094 else if (tag ==
"METADATA")
1096 word infoTag(inFile);
1097 if (infoTag !=
"INFORMATION")
1100 <<
"Unsupported tag " 1106 <<
"Ignoring " << nInfo <<
" metadata information." <<
nl;
1109 inFile.getLine(
nullptr);
1110 for (label i = 0; i < 2*nInfo; i++)
1112 inFile.getLine(
nullptr);
1118 <<
"Unsupported tag " 1132 for (cellShape& shape : cells_)
1134 if (shape.model() == prism)
1149 const point bottomCc(bottom.centre());
1150 const vector bottomNormal(bottom.areaNormal());
1151 const point topCc(top.centre());
1153 if (((topCc - bottomCc) & bottomNormal) < 0)
1156 std::swap(shape[0], shape[3]);
1157 std::swap(shape[1], shape[4]);
1158 std::swap(shape[2], shape[5]);
1166 <<
" prismatic cells" <<
nl;
1172 Info<<
"Read points:" << points_.size()
1173 <<
" cells:" << cells_.size()
1174 <<
" faces:" << faces_.size()
1175 <<
" lines:" << lines_.size()
1178 Info<<
"Cell fields:" <<
nl;
1179 printFieldStats<vectorIOField>(cellData_);
1180 printFieldStats<scalarIOField>(cellData_);
1181 printFieldStats<labelIOField>(cellData_);
1182 printFieldStats<stringIOList>(cellData_);
1185 Info<<
"Point fields:" <<
nl;
1186 printFieldStats<vectorIOField>(pointData_);
1187 printFieldStats<scalarIOField>(pointData_);
1188 printFieldStats<labelIOField>(pointData_);
1189 printFieldStats<stringIOList>(pointData_);
1192 Info<<
"Other fields:" <<
nl;
1193 printFieldStats<vectorIOField>(otherData_);
1194 printFieldStats<scalarIOField>(otherData_);
1195 printFieldStats<labelIOField>(otherData_);
1196 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)
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)
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.
const labelUList & cellTypes
vtkUnstructuredReader(const objectRegistry &obr, ISstream &is)
Construct from input stream, read all.
#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)
List< word > wordList
List of word.
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
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 ...