76 void Foam::vtkUnstructuredReader::warnUnhandledType
83 if (warningGiven.insert(
type))
86 <<
"Skipping unknown cell type " <<
type <<
endl;
91 void Foam::vtkUnstructuredReader::extractCells
108 label celli = cells_.size();
109 cells_.setSize(celli+cellTypes.size());
110 cellMap_.setSize(cells_.size(), -1);
112 label facei = faces_.size();
113 faces_.setSize(facei+cellTypes.size());
114 faceMap_.setSize(faces_.size(), -1);
116 label lineI = lines_.size();
117 lines_.setSize(lineI+cellTypes.size());
118 lineMap_.setSize(lines_.size(), -1);
128 switch (cellTypes[i])
132 warnUnhandledType(inFile, cellTypes[i], warningGiven);
133 label nRead = cellVertData[dataIndex++];
139 ) <<
"Expected size 1 for VTK_VERTEX but found "
146 case VTK_POLY_VERTEX:
148 warnUnhandledType(inFile, cellTypes[i], warningGiven);
149 label nRead = cellVertData[dataIndex++];
157 label nRead = cellVertData[dataIndex++];
163 ) <<
"Expected size 2 for VTK_LINE but found "
169 segment[0] = cellVertData[dataIndex++];
170 segment[1] = cellVertData[dataIndex++];
177 label nRead = cellVertData[dataIndex++];
183 segment[i] = cellVertData[dataIndex++];
191 face&
f = faces_[facei++];
193 label nRead = cellVertData[dataIndex++];
199 ) <<
"Expected size 3 for VTK_TRIANGLE but found "
202 f[0] = cellVertData[dataIndex++];
203 f[1] = cellVertData[dataIndex++];
204 f[2] = cellVertData[dataIndex++];
211 face&
f = faces_[facei++];
213 label nRead = cellVertData[dataIndex++];
219 ) <<
"Expected size 4 for VTK_QUAD but found "
222 f[0] = cellVertData[dataIndex++];
223 f[1] = cellVertData[dataIndex++];
224 f[2] = cellVertData[dataIndex++];
225 f[3] = cellVertData[dataIndex++];
232 face&
f = faces_[facei++];
233 label nRead = cellVertData[dataIndex++];
237 f[fp] = cellVertData[dataIndex++];
244 label nRead = cellVertData[dataIndex++];
250 ) <<
"Expected size 4 for VTK_TETRA but found "
253 tetPoints[0] = cellVertData[dataIndex++];
254 tetPoints[1] = cellVertData[dataIndex++];
255 tetPoints[2] = cellVertData[dataIndex++];
256 tetPoints[3] = cellVertData[dataIndex++];
258 cells_[celli++] = cellShape(tet, tetPoints,
true);
264 label nRead = cellVertData[dataIndex++];
270 ) <<
"Expected size 5 for VTK_PYRAMID but found "
273 pyrPoints[0] = cellVertData[dataIndex++];
274 pyrPoints[1] = cellVertData[dataIndex++];
275 pyrPoints[2] = cellVertData[dataIndex++];
276 pyrPoints[3] = cellVertData[dataIndex++];
277 pyrPoints[4] = cellVertData[dataIndex++];
279 cells_[celli++] = cellShape(pyr, pyrPoints,
true);
285 label nRead = cellVertData[dataIndex++];
291 ) <<
"Expected size 6 for VTK_WEDGE but found "
294 prismPoints[0] = cellVertData[dataIndex++];
295 prismPoints[2] = cellVertData[dataIndex++];
296 prismPoints[1] = cellVertData[dataIndex++];
297 prismPoints[3] = cellVertData[dataIndex++];
298 prismPoints[5] = cellVertData[dataIndex++];
299 prismPoints[4] = cellVertData[dataIndex++];
301 cells_[celli++] = cellShape(prism, prismPoints,
true);
307 label nRead = cellVertData[dataIndex++];
313 ) <<
"Expected size 8 for VTK_HEXAHEDRON but found "
316 hexPoints[0] = cellVertData[dataIndex++];
317 hexPoints[1] = cellVertData[dataIndex++];
318 hexPoints[2] = cellVertData[dataIndex++];
319 hexPoints[3] = cellVertData[dataIndex++];
320 hexPoints[4] = cellVertData[dataIndex++];
321 hexPoints[5] = cellVertData[dataIndex++];
322 hexPoints[6] = cellVertData[dataIndex++];
323 hexPoints[7] = cellVertData[dataIndex++];
325 cells_[celli++] = cellShape(
hex, hexPoints,
true);
330 warnUnhandledType(inFile, cellTypes[i], warningGiven);
331 label nRead = cellVertData[dataIndex++];
338 Info<<
"Read " << celli <<
" cells;" << facei <<
" faces." <<
endl;
340 cells_.setSize(celli);
341 cellMap_.setSize(celli);
342 faces_.setSize(facei);
343 faceMap_.setSize(facei);
344 lines_.setSize(lineI);
345 lineMap_.setSize(lineI);
349 void Foam::vtkUnstructuredReader::readField
353 const word& arrayName,
354 const word& dataType,
358 switch (vtkDataTypeNames[dataType])
366 autoPtr<labelIOField> fieldVals
379 readBlock(inFile, fieldVals().size(), fieldVals());
387 autoPtr<scalarIOField> fieldVals
400 readBlock(inFile, fieldVals().size(), fieldVals());
409 Info<<
"Reading strings:" << size <<
endl;
411 autoPtr<stringIOList> fieldVals
425 inFile.getLine(fieldVals()[0]);
430 inFile.getLine(fieldVals()[i]);
439 <<
"Unhandled type " << vtkDataTypeNames[dataType] <<
endl
440 <<
"Skipping " << size
441 <<
" words." <<
endl;
443 readBlock(inFile, size, fieldVals);
454 const label wantedSize
459 word dataName(inFile);
462 Info<<
"dataName:" << dataName <<
endl;
467 Pout<<
"numArrays:" << numArrays <<
endl;
469 for (
label i = 0; i < numArrays; i++)
471 word arrayName(inFile);
474 word dataType(inFile);
478 Info<<
"Reading field " << arrayName
479 <<
" of " << numTuples <<
" tuples of rank " << numComp <<
endl;
482 if (wantedSize != -1 && numTuples != wantedSize)
485 <<
"Expected " << wantedSize <<
" tuples but only have "
505 const parseMode readMode
508 if (readMode == CELL_DATA)
512 else if (readMode == POINT_DATA)
531 cellData_(
IOobject(
"cellData", obr)),
532 pointData_(
IOobject(
"pointData", obr)),
533 otherData_(
IOobject(
"otherData", obr))
539 void Foam::vtkUnstructuredReader::read(
ISstream& inFile)
544 Info<<
"Header : " << header_ <<
endl;
549 Info<<
"Title : " << title_ <<
endl;
554 Info<<
"dataType : " << dataType_ <<
endl;
557 if (dataType_ ==
"BINARY")
563 parseMode readMode = NOMODE;
564 label wantedSize = -1;
570 while (inFile.
good())
582 <<
" tag:" << tag <<
endl;
585 if (tag ==
"DATASET")
587 word geomType(inFile);
590 Info<<
"geomType : " << geomType <<
endl;
592 readMode = parseModeNames[geomType];
595 else if (tag ==
"POINTS")
601 Info<<
"Reading " <<
nPoints <<
" numbers representing "
602 << points_.size() <<
" coordinates." <<
endl;
605 word primitiveTag(inFile);
606 if (primitiveTag !=
"float" && primitiveTag !=
"double")
609 <<
"Expected 'float' entry but found "
615 inFile >> points_[i].x() >> points_[i].y() >> points_[i].z();
618 else if (tag ==
"CELLS")
628 Info<<
"Reading " << nCells <<
" cells or faces." <<
endl;
632 readBlock(inFile, nNumbers, cellVerts);
634 else if (next.isWord() && next.wordToken() ==
"OFFSETS")
640 Info<<
"Reading " << nCells <<
" cells or faces." <<
endl;
644 const token offsetsIntType(inFile);
646 readBlock(inFile, nCells + 1, cellOffsets);
649 const token connectivityTag(inFile);
652 !connectivityTag.isWord()
653 || connectivityTag.wordToken() !=
"CONNECTIVITY"
657 <<
"Expected 'CONNECTIVITY' but found "
663 const token connectivityIntType(inFile);
665 readBlock(inFile, nNumbers, cellConnectivity);
668 cellVerts.resize(nCells + nNumbers);
671 label cellOffseti = 0, cellVerti = 0;
672 cellOffseti < nCells;
676 const label cellConnectivityi0 =
677 cellOffsets[cellOffseti];
678 const label cellConnectivityi1 =
679 cellOffsets[cellOffseti + 1];
681 const label n = cellConnectivityi1 - cellConnectivityi0;
683 cellVerts[cellVerti ++] =
n;
685 for (
label i = 0; i <
n; ++ i)
687 cellVerts[cellVerti ++] =
688 cellConnectivity[cellConnectivityi0 + i];
695 <<
"Expected 'label' entry or 'OFFSETS' but found "
700 else if (tag ==
"CELL_TYPES")
705 readBlock(inFile, nCellTypes, cellTypes);
707 if (cellTypes.size() > 0 && cellVerts.size() == 0)
710 <<
"Found " << cellTypes.size()
711 <<
" cellTypes but no cells."
715 extractCells(inFile, cellTypes, cellVerts);
718 else if (tag ==
"LINES")
724 Info<<
"Reading " << nLines <<
" lines." <<
endl;
727 readBlock(inFile, nNumbers, lineVerts);
729 label lineI = lines_.size();
730 lines_.setSize(lineI+nLines);
731 lineMap_.setSize(lines_.size());
734 for (
label i = 0; i < nLines; i++)
736 lineMap_[lineI] = lineI;
741 f[fp] = lineVerts[elemI++];
746 else if (tag ==
"POLYGONS")
754 Info<<
"Reading " << nFaces <<
" faces." <<
endl;
757 readBlock(inFile, nNumbers, faceVerts);
759 label facei = faces_.size();
760 faces_.setSize(facei+nFaces);
761 faceMap_.setSize(faces_.size());
764 for (
label i = 0; i < nFaces; i++)
766 faceMap_[facei] = facei;
767 face&
f = faces_[facei];
771 f[fp] = faceVerts[elemI++];
776 else if (tag ==
"POINT_DATA")
779 readMode = POINT_DATA;
780 wantedSize = points_.
size();
786 <<
"Reading POINT_DATA : expected " << wantedSize
790 else if (tag ==
"CELL_DATA")
792 readMode = CELL_DATA;
793 wantedSize = cells_.size()+faces_.size()+lines_.size();
796 if (nCells != wantedSize)
799 <<
"Reading CELL_DATA : expected "
804 else if (tag ==
"FIELD")
807 readFieldArray(inFile, selectRegistry(readMode), wantedSize);
809 else if (tag ==
"SCALARS")
813 IStringStream is(line);
820 Info<<
"Reading scalar " << dataName
821 <<
" of type " << dataType
822 <<
" from lookup table" <<
endl;
825 word lookupTableTag(inFile);
826 if (lookupTableTag !=
"LOOKUP_TABLE")
829 <<
"Expected tag LOOKUP_TABLE but read "
834 word lookupTableName(inFile);
839 selectRegistry(readMode),
845 else if (tag ==
"VECTORS" || tag ==
"NORMALS")
850 IStringStream is(line);
855 Info<<
"Reading vector " << dataName
856 <<
" of type " << dataType <<
endl;
859 objectRegistry& reg = selectRegistry(readMode);
872 vtkDataTypeNames[dataType] == VTK_FLOAT
873 || vtkDataTypeNames[dataType] == VTK_DOUBLE
879 autoPtr<vectorIOField> fieldVals
896 fieldVals()[i].x() =
s[elemI++];
897 fieldVals()[i].y() =
s[elemI++];
898 fieldVals()[i].z() =
s[elemI++];
903 else if (tag ==
"TENSORS")
908 IStringStream is(line);
913 Info<<
"Reading tensor " << dataName
914 <<
" of type " << dataType <<
endl;
917 objectRegistry& reg = selectRegistry(readMode);
930 vtkDataTypeNames[dataType] == VTK_FLOAT
931 || vtkDataTypeNames[dataType] == VTK_DOUBLE
937 autoPtr<tensorIOField> fieldVals
954 fieldVals()[i].xx() =
s[elemI++];
955 fieldVals()[i].xy() =
s[elemI++];
956 fieldVals()[i].xz() =
s[elemI++];
957 fieldVals()[i].yx() =
s[elemI++];
958 fieldVals()[i].yy() =
s[elemI++];
959 fieldVals()[i].yz() =
s[elemI++];
960 fieldVals()[i].zx() =
s[elemI++];
961 fieldVals()[i].zy() =
s[elemI++];
962 fieldVals()[i].zz() =
s[elemI++];
967 else if (tag ==
"TEXTURE_COORDINATES")
972 IStringStream is(line);
979 Info<<
"Reading texture coords " << dataName
980 <<
" dimension " << dim
981 <<
" of type " << dataType <<
endl;
985 readBlock(inFile, coords.size(), coords);
987 else if (tag ==
"TRIANGLE_STRIPS")
993 Info<<
"Reading " << nStrips <<
" triangle strips." <<
endl;
996 readBlock(inFile, nNumbers, faceVerts);
1001 for (
label i = 0; i < nStrips; i++)
1003 label nVerts = faceVerts[elemI++];
1010 label facei = faces_.size();
1011 faces_.setSize(facei+nTris);
1012 faceMap_.setSize(faces_.size());
1014 for (
label i = 0; i < nStrips; i++)
1016 label nVerts = faceVerts[elemI++];
1017 label nTris = nVerts-2;
1020 faceMap_[facei] = facei;
1021 face&
f = faces_[facei++];
1023 f[0] = faceVerts[elemI++];
1024 f[1] = faceVerts[elemI++];
1025 f[2] = faceVerts[elemI++];
1026 for (
label triI = 1; triI < nTris; triI++)
1028 faceMap_[facei] = facei;
1029 face&
f = faces_[facei++];
1031 f[0] = faceVerts[elemI-1];
1032 f[1] = faceVerts[elemI-2];
1033 f[2] = faceVerts[elemI++];
1037 else if (tag ==
"METADATA")
1053 <<
"Unsupported tag "
1060 Info<<
"Read points:" << points_.size()
1061 <<
" cellShapes:" << cells_.size()
1062 <<
" faces:" << faces_.size()
1063 <<
" lines:" << lines_.size()
1067 printFieldStats<scalarIOField>(cellData_);
1068 printFieldStats<vectorIOField>(cellData_);
1069 printFieldStats<tensorIOField>(cellData_);
1070 printFieldStats<labelIOField>(cellData_);
1071 printFieldStats<stringIOList>(cellData_);
1075 printFieldStats<scalarIOField>(pointData_);
1076 printFieldStats<vectorIOField>(pointData_);
1077 printFieldStats<tensorIOField>(pointData_);
1078 printFieldStats<labelIOField>(pointData_);
1079 printFieldStats<stringIOList>(pointData_);
1083 printFieldStats<scalarIOField>(otherData_);
1084 printFieldStats<vectorIOField>(otherData_);
1085 printFieldStats<tensorIOField>(otherData_);
1086 printFieldStats<labelIOField>(otherData_);
1087 printFieldStats<stringIOList>(otherData_);
#define forAll(list, i)
Loop across all elements in list.
friend class iterator
Declare friendship with the iterator.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
label lineNumber() const
Return current stream line number.
ISstream & getLine(string &, const bool continuation=true)
Read line into a string.
bool good() const
Return true if next operation might succeed.
void putBack(const token &)
Put back token.
void size(const label)
Override size to be inconsistent with allocated storage.
void setSize(const label)
Reset size of List.
Initialise the NamedEnum HashTable from the static list of names.
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or nullptr.
Registry of regIOobjects.
void store()
Transfer ownership of this object to its registry.
Reader for vtk unstructured_grid legacy files. Supports single CELLS, POINTS etc. entry only.
static const NamedEnum< parseMode, 5 > parseModeNames
vtkUnstructuredReader(const objectRegistry &obr, ISstream &)
Construct from Istream, read all.
static const NamedEnum< vtkDataSetType, 3 > vtkDataSetTypeNames
static const NamedEnum< vtkDataType, 8 > vtkDataTypeNames
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), lagrangian::cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Info<< "Calculating turbulent flame speed field St\n"<< endl;volScalarField St(IOobject("St", runTime.name(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), flameWrinkling->Xi() *Su);multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
string trim(const string &)
Return string trimmed of leading and trailing whitespace.
errorManipArg< error, int > exit(error &err, const int errNo=1)
List< label > labelList
A List of labels.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
IOField< tensor > tensorIOField
tensorField with IO.
IOstream & hex(IOstream &io)
IOField< scalar > scalarIOField
scalarField with IO.
IOField< label > labelIOField
labelField with IO.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
IOList< string > stringIOList
IO of a list of strings.
IOField< vector > vectorIOField
vectorField with IO.
label readLabel(Istream &is)
prefixOSstream Pout(cout, "Pout")
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.