85 void Foam::vtkUnstructuredReader::warnUnhandledType
92 if (warningGiven.
insert(type))
95 <<
"Skipping unknown cell type " << type <<
endl;
100 void Foam::vtkUnstructuredReader::extractCells
117 label celli = cells_.size();
118 cells_.setSize(celli+cellTypes.
size());
119 cellMap_.setSize(cells_.size(), -1);
121 label facei = faces_.size();
122 faces_.setSize(facei+cellTypes.
size());
123 faceMap_.setSize(faces_.size(), -1);
125 label lineI = lines_.size();
126 lines_.setSize(lineI+cellTypes.
size());
127 lineMap_.setSize(lines_.size(), -1);
137 switch (cellTypes[i])
141 warnUnhandledType(inFile, cellTypes[i], warningGiven);
142 label nRead = cellVertData[dataIndex++];
148 ) <<
"Expected size 1 for VTK_VERTEX but found " 155 case VTK_POLY_VERTEX:
157 warnUnhandledType(inFile, cellTypes[i], warningGiven);
158 label nRead = cellVertData[dataIndex++];
166 label nRead = cellVertData[dataIndex++];
172 ) <<
"Expected size 2 for VTK_LINE but found " 178 segment[0] = cellVertData[dataIndex++];
179 segment[1] = cellVertData[dataIndex++];
186 label nRead = cellVertData[dataIndex++];
192 segment[i] = cellVertData[dataIndex++];
200 face&
f = faces_[facei++];
202 label nRead = cellVertData[dataIndex++];
208 ) <<
"Expected size 3 for VTK_TRIANGLE but found " 211 f[0] = cellVertData[dataIndex++];
212 f[1] = cellVertData[dataIndex++];
213 f[2] = cellVertData[dataIndex++];
220 face&
f = faces_[facei++];
222 label nRead = cellVertData[dataIndex++];
228 ) <<
"Expected size 4 for VTK_QUAD but found " 231 f[0] = cellVertData[dataIndex++];
232 f[1] = cellVertData[dataIndex++];
233 f[2] = cellVertData[dataIndex++];
234 f[3] = cellVertData[dataIndex++];
241 face&
f = faces_[facei++];
242 label nRead = cellVertData[dataIndex++];
246 f[fp] = cellVertData[dataIndex++];
253 label nRead = cellVertData[dataIndex++];
259 ) <<
"Expected size 4 for VTK_TETRA but found " 262 tetPoints[0] = cellVertData[dataIndex++];
263 tetPoints[1] = cellVertData[dataIndex++];
264 tetPoints[2] = cellVertData[dataIndex++];
265 tetPoints[3] = cellVertData[dataIndex++];
267 cells_[celli++] =
cellShape(tet, tetPoints,
true);
273 label nRead = cellVertData[dataIndex++];
279 ) <<
"Expected size 5 for VTK_PYRAMID but found " 282 pyrPoints[0] = cellVertData[dataIndex++];
283 pyrPoints[1] = cellVertData[dataIndex++];
284 pyrPoints[2] = cellVertData[dataIndex++];
285 pyrPoints[3] = cellVertData[dataIndex++];
286 pyrPoints[4] = cellVertData[dataIndex++];
288 cells_[celli++] =
cellShape(pyr, pyrPoints,
true);
294 label nRead = cellVertData[dataIndex++];
300 ) <<
"Expected size 6 for VTK_WEDGE but found " 303 prismPoints[0] = cellVertData[dataIndex++];
304 prismPoints[2] = cellVertData[dataIndex++];
305 prismPoints[1] = cellVertData[dataIndex++];
306 prismPoints[3] = cellVertData[dataIndex++];
307 prismPoints[5] = cellVertData[dataIndex++];
308 prismPoints[4] = cellVertData[dataIndex++];
310 cells_[celli++] =
cellShape(prism, prismPoints,
true);
316 label nRead = cellVertData[dataIndex++];
322 ) <<
"Expected size 8 for VTK_HEXAHEDRON but found " 325 hexPoints[0] = cellVertData[dataIndex++];
326 hexPoints[1] = cellVertData[dataIndex++];
327 hexPoints[2] = cellVertData[dataIndex++];
328 hexPoints[3] = cellVertData[dataIndex++];
329 hexPoints[4] = cellVertData[dataIndex++];
330 hexPoints[5] = cellVertData[dataIndex++];
331 hexPoints[6] = cellVertData[dataIndex++];
332 hexPoints[7] = cellVertData[dataIndex++];
334 cells_[celli++] =
cellShape(hex, hexPoints,
true);
339 warnUnhandledType(inFile, cellTypes[i], warningGiven);
340 label nRead = cellVertData[dataIndex++];
347 Info<<
"Read " << celli <<
" cells;" << facei <<
" faces." <<
endl;
349 cells_.setSize(celli);
350 cellMap_.setSize(celli);
351 faces_.setSize(facei);
352 faceMap_.setSize(facei);
353 lines_.setSize(lineI);
354 lineMap_.setSize(lineI);
358 void Foam::vtkUnstructuredReader::readField
362 const word& arrayName,
363 const word& dataType,
367 switch (vtkDataTypeNames[dataType])
388 readBlock(inFile, fieldVals().size(), fieldVals());
409 readBlock(inFile, fieldVals().size(), fieldVals());
418 Info<<
"Reading strings:" << size <<
endl;
434 inFile.
getLine(fieldVals()[0]);
439 inFile.
getLine(fieldVals()[i]);
448 <<
"Unhandled type " << vtkDataTypeNames[dataType] <<
endl 449 <<
"Skipping " << size
450 <<
" words." <<
endl;
452 readBlock(inFile, size, fieldVals);
463 const label wantedSize
468 word dataName(inFile);
471 Info<<
"dataName:" << dataName <<
endl;
476 Pout<<
"numArrays:" << numArrays <<
endl;
478 for (
label i = 0; i < numArrays; i++)
480 word arrayName(inFile);
483 word dataType(inFile);
487 Info<<
"Reading field " << arrayName
488 <<
" of " << numTuples <<
" tuples of rank " << numComp <<
endl;
491 if (wantedSize != -1 && numTuples != wantedSize)
494 <<
"Expected " << wantedSize <<
" tuples but only have " 514 const parseMode readMode
517 if (readMode == CELL_DATA)
521 else if (readMode == POINT_DATA)
540 cellData_(
IOobject(
"cellData", obr)),
541 pointData_(
IOobject(
"pointData", obr)),
542 otherData_(
IOobject(
"otherData", obr))
548 void Foam::vtkUnstructuredReader::read(
ISstream& inFile)
553 Info<<
"Header : " << header_ <<
endl;
558 Info<<
"Title : " << title_ <<
endl;
563 Info<<
"dataType : " << dataType_ <<
endl;
566 if (dataType_ ==
"BINARY")
573 label wantedSize = -1;
579 while (inFile.
good())
591 <<
" tag:" << tag <<
endl;
594 if (tag ==
"DATASET")
596 word geomType(inFile);
599 Info<<
"geomType : " << geomType <<
endl;
601 readMode = parseModeNames[geomType];
604 else if (tag ==
"POINTS")
607 points_.setSize(nPoints);
610 Info<<
"Reading " << nPoints <<
" numbers representing " 611 << points_.size() <<
" coordinates." <<
endl;
614 word primitiveTag(inFile);
615 if (primitiveTag !=
"float" && primitiveTag !=
"double")
618 <<
"Expected 'float' entry but found " 624 inFile >> points_[i].x() >> points_[i].y() >> points_[i].z();
627 else if (tag ==
"CELLS")
633 Info<<
"Reading " << nCells <<
" cells or faces." <<
endl;
635 readBlock(inFile, nNumbers, cellVerts);
637 else if (tag ==
"CELL_TYPES")
642 readBlock(inFile, nCellTypes, cellTypes);
644 if (cellTypes.
size() > 0 && cellVerts.
size() == 0)
647 <<
"Found " << cellTypes.
size()
648 <<
" cellTypes but no cells." 652 extractCells(inFile, cellTypes, cellVerts);
655 else if (tag ==
"LINES")
661 Info<<
"Reading " << nLines <<
" lines." <<
endl;
664 readBlock(inFile, nNumbers, lineVerts);
666 label lineI = lines_.size();
667 lines_.setSize(lineI+nLines);
668 lineMap_.setSize(lines_.size());
671 for (
label i = 0; i < nLines; i++)
673 lineMap_[lineI] = lineI;
678 f[fp] = lineVerts[elemI++];
683 else if (tag ==
"POLYGONS")
691 Info<<
"Reading " << nFaces <<
" faces." <<
endl;
694 readBlock(inFile, nNumbers, faceVerts);
696 label facei = faces_.size();
697 faces_.setSize(facei+nFaces);
698 faceMap_.setSize(faces_.size());
701 for (
label i = 0; i < nFaces; i++)
703 faceMap_[facei] = facei;
704 face&
f = faces_[facei];
708 f[fp] = faceVerts[elemI++];
713 else if (tag ==
"POINT_DATA")
716 readMode = POINT_DATA;
717 wantedSize = points_.
size();
720 if (nPoints != wantedSize)
723 <<
"Reading POINT_DATA : expected " << wantedSize
727 else if (tag ==
"CELL_DATA")
729 readMode = CELL_DATA;
730 wantedSize = cells_.size()+faces_.size()+lines_.size();
733 if (nCells != wantedSize)
736 <<
"Reading CELL_DATA : expected " 741 else if (tag ==
"FIELD")
744 readFieldArray(inFile, selectRegistry(readMode), wantedSize);
746 else if (tag ==
"SCALARS")
757 Info<<
"Reading scalar " << dataName
758 <<
" of type " << dataType
759 <<
" from lookup table" <<
endl;
762 word lookupTableTag(inFile);
763 if (lookupTableTag !=
"LOOKUP_TABLE")
766 <<
"Expected tag LOOKUP_TABLE but read " 771 word lookupTableName(inFile);
776 selectRegistry(readMode),
782 else if (tag ==
"VECTORS" || tag ==
"NORMALS")
792 Info<<
"Reading vector " << dataName
793 <<
" of type " << dataType <<
endl;
809 vtkDataTypeNames[dataType] == VTK_FLOAT
810 || vtkDataTypeNames[dataType] == VTK_DOUBLE
814 scalarField s(*dynamic_cast<const scalarField*>(iter()));
833 fieldVals()[i].x() = s[elemI++];
834 fieldVals()[i].y() = s[elemI++];
835 fieldVals()[i].z() = s[elemI++];
840 else if (tag ==
"TEXTURE_COORDINATES")
852 Info<<
"Reading texture coords " << dataName
853 <<
" dimension " << dim
854 <<
" of type " << dataType <<
endl;
858 readBlock(inFile, coords.size(), coords);
860 else if (tag ==
"TRIANGLE_STRIPS")
866 Info<<
"Reading " << nStrips <<
" triangle strips." <<
endl;
869 readBlock(inFile, nNumbers, faceVerts);
874 for (
label i = 0; i < nStrips; i++)
876 label nVerts = faceVerts[elemI++];
884 faces_.setSize(facei+nTris);
885 faceMap_.setSize(faces_.size());
887 for (
label i = 0; i < nStrips; i++)
889 label nVerts = faceVerts[elemI++];
890 label nTris = nVerts-2;
893 faceMap_[facei] = facei;
894 face&
f = faces_[facei++];
896 f[0] = faceVerts[elemI++];
897 f[1] = faceVerts[elemI++];
898 f[2] = faceVerts[elemI++];
899 for (
label triI = 1; triI < nTris; triI++)
901 faceMap_[facei] = facei;
902 face& f = faces_[facei++];
904 f[0] = faceVerts[elemI-1];
905 f[1] = faceVerts[elemI-2];
906 f[2] = faceVerts[elemI++];
913 <<
"Unsupported tag " 920 Info<<
"Read points:" << points_.size()
921 <<
" cellShapes:" << cells_.size()
922 <<
" faces:" << faces_.size()
923 <<
" lines:" << lines_.size()
927 printFieldStats<vectorIOField>(cellData_);
928 printFieldStats<scalarIOField>(cellData_);
929 printFieldStats<labelIOField>(cellData_);
930 printFieldStats<stringIOList>(cellData_);
934 printFieldStats<vectorIOField>(pointData_);
935 printFieldStats<scalarIOField>(pointData_);
936 printFieldStats<labelIOField>(pointData_);
937 printFieldStats<stringIOList>(pointData_);
941 printFieldStats<vectorIOField>(otherData_);
942 printFieldStats<scalarIOField>(otherData_);
943 printFieldStats<labelIOField>(otherData_);
944 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 NULL.
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.
bool good() const
Return true if next operation might succeed.
Ostream & endl(Ostream &os)
Add newline and flush stream.
A List of objects of type <T> with automated input and output.
bool insert(const Key &key)
Insert a new entry.
Initialise the NamedEnum HashTable from the static list of names.
static const NamedEnum< vtkDataSetType, 3 > vtkDataSetTypeNames
bool erase(const iterator &)
Erase a hashedEntry specified by given iterator.
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
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.
prefixOSstream Pout(cout,"Pout")
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.
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Tet storage. Null constructable (unfortunately tetrahedron<point, point> is not)
Input from memory buffer stream.
label lineNumber() const
Return current stream line number.
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.