75 void Foam::vtkUnstructuredReader::warnUnhandledType
82 if (warningGiven.insert(
type))
85 <<
"Skipping unknown cell type " <<
type <<
endl;
90 void Foam::vtkUnstructuredReader::extractCells
107 label celli = cells_.size();
108 cells_.setSize(celli+cellTypes.size());
109 cellMap_.setSize(cells_.size(), -1);
111 label facei = faces_.size();
112 faces_.setSize(facei+cellTypes.size());
113 faceMap_.setSize(faces_.size(), -1);
115 label lineI = lines_.size();
116 lines_.setSize(lineI+cellTypes.size());
117 lineMap_.setSize(lines_.size(), -1);
127 switch (cellTypes[i])
131 warnUnhandledType(inFile, cellTypes[i], warningGiven);
132 label nRead = cellVertData[dataIndex++];
138 ) <<
"Expected size 1 for VTK_VERTEX but found "
145 case VTK_POLY_VERTEX:
147 warnUnhandledType(inFile, cellTypes[i], warningGiven);
148 label nRead = cellVertData[dataIndex++];
156 label nRead = cellVertData[dataIndex++];
162 ) <<
"Expected size 2 for VTK_LINE but found "
168 segment[0] = cellVertData[dataIndex++];
169 segment[1] = cellVertData[dataIndex++];
176 label nRead = cellVertData[dataIndex++];
182 segment[i] = cellVertData[dataIndex++];
190 face&
f = faces_[facei++];
192 label nRead = cellVertData[dataIndex++];
198 ) <<
"Expected size 3 for VTK_TRIANGLE but found "
201 f[0] = cellVertData[dataIndex++];
202 f[1] = cellVertData[dataIndex++];
203 f[2] = cellVertData[dataIndex++];
210 face&
f = faces_[facei++];
212 label nRead = cellVertData[dataIndex++];
218 ) <<
"Expected size 4 for VTK_QUAD but found "
221 f[0] = cellVertData[dataIndex++];
222 f[1] = cellVertData[dataIndex++];
223 f[2] = cellVertData[dataIndex++];
224 f[3] = cellVertData[dataIndex++];
231 face&
f = faces_[facei++];
232 label nRead = cellVertData[dataIndex++];
236 f[fp] = cellVertData[dataIndex++];
243 label nRead = cellVertData[dataIndex++];
249 ) <<
"Expected size 4 for VTK_TETRA but found "
252 tetPoints[0] = cellVertData[dataIndex++];
253 tetPoints[1] = cellVertData[dataIndex++];
254 tetPoints[2] = cellVertData[dataIndex++];
255 tetPoints[3] = cellVertData[dataIndex++];
257 cells_[celli++] = cellShape(tet, tetPoints,
true);
263 label nRead = cellVertData[dataIndex++];
269 ) <<
"Expected size 5 for VTK_PYRAMID but found "
272 pyrPoints[0] = cellVertData[dataIndex++];
273 pyrPoints[1] = cellVertData[dataIndex++];
274 pyrPoints[2] = cellVertData[dataIndex++];
275 pyrPoints[3] = cellVertData[dataIndex++];
276 pyrPoints[4] = cellVertData[dataIndex++];
278 cells_[celli++] = cellShape(pyr, pyrPoints,
true);
284 label nRead = cellVertData[dataIndex++];
290 ) <<
"Expected size 6 for VTK_WEDGE but found "
293 prismPoints[0] = cellVertData[dataIndex++];
294 prismPoints[2] = cellVertData[dataIndex++];
295 prismPoints[1] = cellVertData[dataIndex++];
296 prismPoints[3] = cellVertData[dataIndex++];
297 prismPoints[5] = cellVertData[dataIndex++];
298 prismPoints[4] = cellVertData[dataIndex++];
300 cells_[celli++] = cellShape(prism, prismPoints,
true);
306 label nRead = cellVertData[dataIndex++];
312 ) <<
"Expected size 8 for VTK_HEXAHEDRON but found "
315 hexPoints[0] = cellVertData[dataIndex++];
316 hexPoints[1] = cellVertData[dataIndex++];
317 hexPoints[2] = cellVertData[dataIndex++];
318 hexPoints[3] = cellVertData[dataIndex++];
319 hexPoints[4] = cellVertData[dataIndex++];
320 hexPoints[5] = cellVertData[dataIndex++];
321 hexPoints[6] = cellVertData[dataIndex++];
322 hexPoints[7] = cellVertData[dataIndex++];
324 cells_[celli++] = cellShape(
hex, hexPoints,
true);
329 warnUnhandledType(inFile, cellTypes[i], warningGiven);
330 label nRead = cellVertData[dataIndex++];
337 Info<<
"Read " << celli <<
" cells;" << facei <<
" faces." <<
endl;
339 cells_.setSize(celli);
340 cellMap_.setSize(celli);
341 faces_.setSize(facei);
342 faceMap_.setSize(facei);
343 lines_.setSize(lineI);
344 lineMap_.setSize(lineI);
348 void Foam::vtkUnstructuredReader::readField
352 const word& arrayName,
353 const word& dataType,
357 switch (vtkDataTypeNames[dataType])
365 autoPtr<labelIOField> fieldVals
378 readBlock(inFile, fieldVals().size(), fieldVals());
386 autoPtr<scalarIOField> fieldVals
399 readBlock(inFile, fieldVals().size(), fieldVals());
408 Info<<
"Reading strings:" << size <<
endl;
410 autoPtr<stringIOList> fieldVals
424 inFile.getLine(fieldVals()[0]);
429 inFile.getLine(fieldVals()[i]);
438 <<
"Unhandled type " << vtkDataTypeNames[dataType] <<
endl
439 <<
"Skipping " << size
440 <<
" words." <<
endl;
442 readBlock(inFile, size, fieldVals);
453 const label wantedSize
458 word dataName(inFile);
461 Info<<
"dataName:" << dataName <<
endl;
466 Pout<<
"numArrays:" << numArrays <<
endl;
468 for (
label i = 0; i < numArrays; i++)
470 word arrayName(inFile);
473 word dataType(inFile);
477 Info<<
"Reading field " << arrayName
478 <<
" of " << numTuples <<
" tuples of rank " << numComp <<
endl;
481 if (wantedSize != -1 && numTuples != wantedSize)
484 <<
"Expected " << wantedSize <<
" tuples but only have "
504 const parseMode readMode
507 if (readMode == CELL_DATA)
511 else if (readMode == POINT_DATA)
530 cellData_(
IOobject(
"cellData", obr)),
531 pointData_(
IOobject(
"pointData", obr)),
532 otherData_(
IOobject(
"otherData", obr))
538 void Foam::vtkUnstructuredReader::read(
ISstream& inFile)
543 Info<<
"Header : " << header_ <<
endl;
548 Info<<
"Title : " << title_ <<
endl;
553 Info<<
"dataType : " << dataType_ <<
endl;
556 if (dataType_ ==
"BINARY")
562 parseMode readMode = NOMODE;
563 label wantedSize = -1;
569 while (inFile.
good())
581 <<
" tag:" << tag <<
endl;
584 if (tag ==
"DATASET")
586 word geomType(inFile);
589 Info<<
"geomType : " << geomType <<
endl;
591 readMode = parseModeNames[geomType];
594 else if (tag ==
"POINTS")
600 Info<<
"Reading " <<
nPoints <<
" numbers representing "
601 << points_.size() <<
" coordinates." <<
endl;
604 word primitiveTag(inFile);
605 if (primitiveTag !=
"float" && primitiveTag !=
"double")
608 <<
"Expected 'float' entry but found "
614 inFile >> points_[i].x() >> points_[i].y() >> points_[i].z();
617 else if (tag ==
"CELLS")
623 Info<<
"Reading " << nCells <<
" cells or faces." <<
endl;
625 readBlock(inFile, nNumbers, cellVerts);
627 else if (tag ==
"CELL_TYPES")
632 readBlock(inFile, nCellTypes, cellTypes);
634 if (cellTypes.size() > 0 && cellVerts.size() == 0)
637 <<
"Found " << cellTypes.size()
638 <<
" cellTypes but no cells."
642 extractCells(inFile, cellTypes, cellVerts);
645 else if (tag ==
"LINES")
651 Info<<
"Reading " << nLines <<
" lines." <<
endl;
654 readBlock(inFile, nNumbers, lineVerts);
656 label lineI = lines_.size();
657 lines_.setSize(lineI+nLines);
658 lineMap_.setSize(lines_.size());
661 for (
label i = 0; i < nLines; i++)
663 lineMap_[lineI] = lineI;
668 f[fp] = lineVerts[elemI++];
673 else if (tag ==
"POLYGONS")
681 Info<<
"Reading " << nFaces <<
" faces." <<
endl;
684 readBlock(inFile, nNumbers, faceVerts);
686 label facei = faces_.size();
687 faces_.setSize(facei+nFaces);
688 faceMap_.setSize(faces_.size());
691 for (
label i = 0; i < nFaces; i++)
693 faceMap_[facei] = facei;
694 face&
f = faces_[facei];
698 f[fp] = faceVerts[elemI++];
703 else if (tag ==
"POINT_DATA")
706 readMode = POINT_DATA;
707 wantedSize = points_.
size();
713 <<
"Reading POINT_DATA : expected " << wantedSize
717 else if (tag ==
"CELL_DATA")
719 readMode = CELL_DATA;
720 wantedSize = cells_.size()+faces_.size()+lines_.size();
723 if (nCells != wantedSize)
726 <<
"Reading CELL_DATA : expected "
731 else if (tag ==
"FIELD")
734 readFieldArray(inFile, selectRegistry(readMode), wantedSize);
736 else if (tag ==
"SCALARS")
740 IStringStream is(line);
747 Info<<
"Reading scalar " << dataName
748 <<
" of type " << dataType
749 <<
" from lookup table" <<
endl;
752 word lookupTableTag(inFile);
753 if (lookupTableTag !=
"LOOKUP_TABLE")
756 <<
"Expected tag LOOKUP_TABLE but read "
761 word lookupTableName(inFile);
766 selectRegistry(readMode),
772 else if (tag ==
"VECTORS" || tag ==
"NORMALS")
777 IStringStream is(line);
782 Info<<
"Reading vector " << dataName
783 <<
" of type " << dataType <<
endl;
786 objectRegistry& reg = selectRegistry(readMode);
799 vtkDataTypeNames[dataType] == VTK_FLOAT
800 || vtkDataTypeNames[dataType] == VTK_DOUBLE
806 autoPtr<vectorIOField> fieldVals
823 fieldVals()[i].x() =
s[elemI++];
824 fieldVals()[i].y() =
s[elemI++];
825 fieldVals()[i].z() =
s[elemI++];
830 else if (tag ==
"TEXTURE_COORDINATES")
835 IStringStream is(line);
842 Info<<
"Reading texture coords " << dataName
843 <<
" dimension " << dim
844 <<
" of type " << dataType <<
endl;
848 readBlock(inFile, coords.size(), coords);
850 else if (tag ==
"TRIANGLE_STRIPS")
856 Info<<
"Reading " << nStrips <<
" triangle strips." <<
endl;
859 readBlock(inFile, nNumbers, faceVerts);
864 for (
label i = 0; i < nStrips; i++)
866 label nVerts = faceVerts[elemI++];
873 label facei = faces_.size();
874 faces_.setSize(facei+nTris);
875 faceMap_.setSize(faces_.size());
877 for (
label i = 0; i < nStrips; i++)
879 label nVerts = faceVerts[elemI++];
880 label nTris = nVerts-2;
883 faceMap_[facei] = facei;
884 face&
f = faces_[facei++];
886 f[0] = faceVerts[elemI++];
887 f[1] = faceVerts[elemI++];
888 f[2] = faceVerts[elemI++];
889 for (
label triI = 1; triI < nTris; triI++)
891 faceMap_[facei] = facei;
892 face&
f = faces_[facei++];
894 f[0] = faceVerts[elemI-1];
895 f[1] = faceVerts[elemI-2];
896 f[2] = faceVerts[elemI++];
900 else if (tag ==
"METADATA")
916 <<
"Unsupported tag "
923 Info<<
"Read points:" << points_.size()
924 <<
" cellShapes:" << cells_.size()
925 <<
" faces:" << faces_.size()
926 <<
" lines:" << lines_.size()
930 printFieldStats<vectorIOField>(cellData_);
931 printFieldStats<scalarIOField>(cellData_);
932 printFieldStats<labelIOField>(cellData_);
933 printFieldStats<stringIOList>(cellData_);
937 printFieldStats<vectorIOField>(pointData_);
938 printFieldStats<scalarIOField>(pointData_);
939 printFieldStats<labelIOField>(pointData_);
940 printFieldStats<stringIOList>(pointData_);
944 printFieldStats<vectorIOField>(otherData_);
945 printFieldStats<scalarIOField>(otherData_);
946 printFieldStats<labelIOField>(otherData_);
947 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.
bool good() const
Return true if next operation might succeed.
ISstream & getLine(string &, const bool continuation=true)
Read line into a string.
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.
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.
defineTypeNameAndDebug(combustionModel, 0)
label readLabel(Istream &is)
prefixOSstream Pout(cout, "Pout")
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.