86 void Foam::vtkUnstructuredReader::warnUnhandledType
93 if (warningGiven.
insert(type))
96 <<
"Skipping unknown cell type " << type <<
endl;
101 void Foam::vtkUnstructuredReader::extractCells
118 label celli = cells_.size();
119 cells_.setSize(celli+cellTypes.
size());
120 cellMap_.setSize(cells_.size(), -1);
122 label facei = faces_.size();
123 faces_.setSize(facei+cellTypes.
size());
124 faceMap_.setSize(faces_.size(), -1);
126 label lineI = lines_.size();
127 lines_.setSize(lineI+cellTypes.
size());
128 lineMap_.setSize(lines_.size(), -1);
138 switch (cellTypes[i])
142 warnUnhandledType(inFile, cellTypes[i], warningGiven);
143 label nRead = cellVertData[dataIndex++];
149 ) <<
"Expected size 1 for VTK_VERTEX but found " 156 case VTK_POLY_VERTEX:
158 warnUnhandledType(inFile, cellTypes[i], warningGiven);
159 label nRead = cellVertData[dataIndex++];
167 label nRead = cellVertData[dataIndex++];
173 ) <<
"Expected size 2 for VTK_LINE but found " 179 segment[0] = cellVertData[dataIndex++];
180 segment[1] = cellVertData[dataIndex++];
187 label nRead = cellVertData[dataIndex++];
193 segment[i] = cellVertData[dataIndex++];
201 face&
f = faces_[facei++];
203 label nRead = cellVertData[dataIndex++];
209 ) <<
"Expected size 3 for VTK_TRIANGLE but found " 212 f[0] = cellVertData[dataIndex++];
213 f[1] = cellVertData[dataIndex++];
214 f[2] = cellVertData[dataIndex++];
221 face&
f = faces_[facei++];
223 label nRead = cellVertData[dataIndex++];
229 ) <<
"Expected size 4 for VTK_QUAD but found " 232 f[0] = cellVertData[dataIndex++];
233 f[1] = cellVertData[dataIndex++];
234 f[2] = cellVertData[dataIndex++];
235 f[3] = cellVertData[dataIndex++];
242 face&
f = faces_[facei++];
243 label nRead = cellVertData[dataIndex++];
247 f[fp] = cellVertData[dataIndex++];
254 label nRead = cellVertData[dataIndex++];
260 ) <<
"Expected size 4 for VTK_TETRA but found " 263 tetPoints[0] = cellVertData[dataIndex++];
264 tetPoints[1] = cellVertData[dataIndex++];
265 tetPoints[2] = cellVertData[dataIndex++];
266 tetPoints[3] = cellVertData[dataIndex++];
268 cells_[celli++] =
cellShape(tet, tetPoints,
true);
274 label nRead = cellVertData[dataIndex++];
280 ) <<
"Expected size 5 for VTK_PYRAMID but found " 283 pyrPoints[0] = cellVertData[dataIndex++];
284 pyrPoints[1] = cellVertData[dataIndex++];
285 pyrPoints[2] = cellVertData[dataIndex++];
286 pyrPoints[3] = cellVertData[dataIndex++];
287 pyrPoints[4] = cellVertData[dataIndex++];
289 cells_[celli++] =
cellShape(pyr, pyrPoints,
true);
295 label nRead = cellVertData[dataIndex++];
301 ) <<
"Expected size 6 for VTK_WEDGE but found " 304 prismPoints[0] = cellVertData[dataIndex++];
305 prismPoints[2] = cellVertData[dataIndex++];
306 prismPoints[1] = cellVertData[dataIndex++];
307 prismPoints[3] = cellVertData[dataIndex++];
308 prismPoints[5] = cellVertData[dataIndex++];
309 prismPoints[4] = cellVertData[dataIndex++];
311 cells_[celli++] =
cellShape(prism, prismPoints,
true);
317 label nRead = cellVertData[dataIndex++];
323 ) <<
"Expected size 8 for VTK_HEXAHEDRON but found " 326 hexPoints[0] = cellVertData[dataIndex++];
327 hexPoints[1] = cellVertData[dataIndex++];
328 hexPoints[2] = cellVertData[dataIndex++];
329 hexPoints[3] = cellVertData[dataIndex++];
330 hexPoints[4] = cellVertData[dataIndex++];
331 hexPoints[5] = cellVertData[dataIndex++];
332 hexPoints[6] = cellVertData[dataIndex++];
333 hexPoints[7] = cellVertData[dataIndex++];
335 cells_[celli++] =
cellShape(hex, hexPoints,
true);
340 warnUnhandledType(inFile, cellTypes[i], warningGiven);
341 label nRead = cellVertData[dataIndex++];
348 Info<<
"Read " << celli <<
" cells;" << facei <<
" faces." <<
endl;
350 cells_.setSize(celli);
351 cellMap_.setSize(celli);
352 faces_.setSize(facei);
353 faceMap_.setSize(facei);
354 lines_.setSize(lineI);
355 lineMap_.setSize(lineI);
359 void Foam::vtkUnstructuredReader::readField
363 const word& arrayName,
364 const word& dataType,
368 switch (vtkDataTypeNames[dataType])
389 readBlock(inFile, fieldVals().size(), fieldVals());
410 readBlock(inFile, fieldVals().size(), fieldVals());
419 Info<<
"Reading strings:" << size <<
endl;
435 inFile.
getLine(fieldVals()[0]);
440 inFile.
getLine(fieldVals()[i]);
449 <<
"Unhandled type " << vtkDataTypeNames[dataType] <<
endl 450 <<
"Skipping " << size
451 <<
" words." <<
endl;
453 readBlock(inFile, size, fieldVals);
464 const label wantedSize
469 word dataName(inFile);
472 Info<<
"dataName:" << dataName <<
endl;
477 Pout<<
"numArrays:" << numArrays <<
endl;
479 for (
label i = 0; i < numArrays; i++)
481 word arrayName(inFile);
484 word dataType(inFile);
488 Info<<
"Reading field " << arrayName
489 <<
" of " << numTuples <<
" tuples of rank " << numComp <<
endl;
492 if (wantedSize != -1 && numTuples != wantedSize)
495 <<
"Expected " << wantedSize <<
" tuples but only have " 515 const parseMode readMode
518 if (readMode == CELL_DATA)
522 else if (readMode == POINT_DATA)
541 cellData_(
IOobject(
"cellData", obr)),
542 pointData_(
IOobject(
"pointData", obr)),
543 otherData_(
IOobject(
"otherData", obr))
549 void Foam::vtkUnstructuredReader::read(
ISstream& inFile)
554 Info<<
"Header : " << header_ <<
endl;
559 Info<<
"Title : " << title_ <<
endl;
564 Info<<
"dataType : " << dataType_ <<
endl;
567 if (dataType_ ==
"BINARY")
574 label wantedSize = -1;
580 while (inFile.
good())
592 <<
" tag:" << tag <<
endl;
595 if (tag ==
"DATASET")
597 word geomType(inFile);
600 Info<<
"geomType : " << geomType <<
endl;
602 readMode = parseModeNames[geomType];
605 else if (tag ==
"POINTS")
608 points_.setSize(nPoints);
611 Info<<
"Reading " << nPoints <<
" numbers representing " 612 << points_.size() <<
" coordinates." <<
endl;
615 word primitiveTag(inFile);
616 if (primitiveTag !=
"float" && primitiveTag !=
"double")
619 <<
"Expected 'float' entry but found " 625 inFile >> points_[i].x() >> points_[i].y() >> points_[i].z();
628 else if (tag ==
"CELLS")
634 Info<<
"Reading " << nCells <<
" cells or faces." <<
endl;
636 readBlock(inFile, nNumbers, cellVerts);
638 else if (tag ==
"CELL_TYPES")
643 readBlock(inFile, nCellTypes, cellTypes);
645 if (cellTypes.
size() > 0 && cellVerts.
size() == 0)
648 <<
"Found " << cellTypes.
size()
649 <<
" cellTypes but no cells." 653 extractCells(inFile, cellTypes, cellVerts);
656 else if (tag ==
"LINES")
662 Info<<
"Reading " << nLines <<
" lines." <<
endl;
665 readBlock(inFile, nNumbers, lineVerts);
667 label lineI = lines_.size();
668 lines_.setSize(lineI+nLines);
669 lineMap_.setSize(lines_.size());
672 for (
label i = 0; i < nLines; i++)
674 lineMap_[lineI] = lineI;
679 f[fp] = lineVerts[elemI++];
684 else if (tag ==
"POLYGONS")
692 Info<<
"Reading " << nFaces <<
" faces." <<
endl;
695 readBlock(inFile, nNumbers, faceVerts);
697 label facei = faces_.size();
698 faces_.setSize(facei+nFaces);
699 faceMap_.setSize(faces_.size());
702 for (
label i = 0; i < nFaces; i++)
704 faceMap_[facei] = facei;
705 face&
f = faces_[facei];
709 f[fp] = faceVerts[elemI++];
714 else if (tag ==
"POINT_DATA")
717 readMode = POINT_DATA;
718 wantedSize = points_.
size();
721 if (nPoints != wantedSize)
724 <<
"Reading POINT_DATA : expected " << wantedSize
728 else if (tag ==
"CELL_DATA")
730 readMode = CELL_DATA;
731 wantedSize = cells_.size()+faces_.size()+lines_.size();
734 if (nCells != wantedSize)
737 <<
"Reading CELL_DATA : expected " 742 else if (tag ==
"FIELD")
745 readFieldArray(inFile, selectRegistry(readMode), wantedSize);
747 else if (tag ==
"SCALARS")
758 Info<<
"Reading scalar " << dataName
759 <<
" of type " << dataType
760 <<
" from lookup table" <<
endl;
763 word lookupTableTag(inFile);
764 if (lookupTableTag !=
"LOOKUP_TABLE")
767 <<
"Expected tag LOOKUP_TABLE but read " 772 word lookupTableName(inFile);
777 selectRegistry(readMode),
783 else if (tag ==
"VECTORS" || tag ==
"NORMALS")
793 Info<<
"Reading vector " << dataName
794 <<
" of type " << dataType <<
endl;
810 vtkDataTypeNames[dataType] == VTK_FLOAT
811 || vtkDataTypeNames[dataType] == VTK_DOUBLE
815 scalarField s(*dynamic_cast<const scalarField*>(iter()));
834 fieldVals()[i].x() = s[elemI++];
835 fieldVals()[i].y() = s[elemI++];
836 fieldVals()[i].z() = s[elemI++];
841 else if (tag ==
"TEXTURE_COORDINATES")
853 Info<<
"Reading texture coords " << dataName
854 <<
" dimension " << dim
855 <<
" of type " << dataType <<
endl;
859 readBlock(inFile, coords.size(), coords);
861 else if (tag ==
"TRIANGLE_STRIPS")
867 Info<<
"Reading " << nStrips <<
" triangle strips." <<
endl;
870 readBlock(inFile, nNumbers, faceVerts);
875 for (
label i = 0; i < nStrips; i++)
877 label nVerts = faceVerts[elemI++];
885 faces_.setSize(facei+nTris);
886 faceMap_.setSize(faces_.size());
888 for (
label i = 0; i < nStrips; i++)
890 label nVerts = faceVerts[elemI++];
891 label nTris = nVerts-2;
894 faceMap_[facei] = facei;
895 face&
f = faces_[facei++];
897 f[0] = faceVerts[elemI++];
898 f[1] = faceVerts[elemI++];
899 f[2] = faceVerts[elemI++];
900 for (
label triI = 1; triI < nTris; triI++)
902 faceMap_[facei] = facei;
903 face& f = faces_[facei++];
905 f[0] = faceVerts[elemI-1];
906 f[1] = faceVerts[elemI-2];
907 f[2] = faceVerts[elemI++];
911 else if (tag ==
"METADATA")
927 <<
"Unsupported tag " 934 Info<<
"Read points:" << points_.size()
935 <<
" cellShapes:" << cells_.size()
936 <<
" faces:" << faces_.size()
937 <<
" lines:" << lines_.size()
941 printFieldStats<vectorIOField>(cellData_);
942 printFieldStats<scalarIOField>(cellData_);
943 printFieldStats<labelIOField>(cellData_);
944 printFieldStats<stringIOList>(cellData_);
948 printFieldStats<vectorIOField>(pointData_);
949 printFieldStats<scalarIOField>(pointData_);
950 printFieldStats<labelIOField>(pointData_);
951 printFieldStats<stringIOList>(pointData_);
955 printFieldStats<vectorIOField>(otherData_);
956 printFieldStats<scalarIOField>(otherData_);
957 printFieldStats<labelIOField>(otherData_);
958 printFieldStats<stringIOList>(otherData_);
vtkUnstructuredReader(const objectRegistry &obr, ISstream &)
Construct from Istream, read all.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or nullptr.
errorManipArg< error, int > exit(error &err, const int errNo=1)
A face is a list of labels corresponding to mesh vertices.
IOstream & hex(IOstream &io)
An analytical geometric cellShape.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
void size(const label)
Override size to be inconsistent with allocated storage.
Ostream & endl(Ostream &os)
Add newline and flush stream.
A List of objects of type <T> with automated input and output.
label lineNumber() const
Return current stream line number.
bool insert(const Key &key)
Insert a new entry.
Initialise the NamedEnum HashTable from the static list of names.
bool good() const
Return true if next operation might succeed.
static const NamedEnum< vtkDataSetType, 3 > vtkDataSetTypeNames
bool erase(const iterator &)
Erase a hashedEntry specified by given iterator.
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
string trim(const string &)
Return string trimmed of leading and trailing whitespace.
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
bool read(const char *, int32_t &)
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().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))
An ordered pair of two objects of type <T> with first() and second() elements.
void clear()
Clear the list, i.e. set size to zero.
A class for handling words, derived from string.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
label readLabel(Istream &is)
void store()
Transfer ownership of this object to its registry.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
defineTypeNameAndDebug(combustionModel, 0)
void setSize(const label)
Reset size of List.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Input from memory buffer stream.
prefixOSstream Pout(cout, "Pout")
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Maps a geometry to a set of cell primitives, which enables geometric cell data to be calculated witho...
parseMode
Enumeration defining the parse mode - what type of data is being.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Registry of regIOobjects.
friend class iterator
Declare friendship with the iterator.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
static const NamedEnum< vtkDataType, 8 > vtkDataTypeNames
A primitive field of type <T> with automated input and output.
static const NamedEnum< parseMode, 5 > parseModeNames
ISstream & getLine(string &)
Raw, low-level getline into a string function.