diff --git a/vtkm/io/VTKDataSetReaderBase.cxx b/vtkm/io/VTKDataSetReaderBase.cxx index 4e6a30197..43794f302 100644 --- a/vtkm/io/VTKDataSetReaderBase.cxx +++ b/vtkm/io/VTKDataSetReaderBase.cxx @@ -11,7 +11,9 @@ #include #include +#include #include +#include #include #include #include @@ -258,25 +260,61 @@ void VTKDataSetReaderBase::ReadPoints() void VTKDataSetReaderBase::ReadCells(vtkm::cont::ArrayHandle& connectivity, vtkm::cont::ArrayHandle& numIndices) { - vtkm::Id numCells, numInts; - this->DataFile->Stream >> numCells >> numInts >> std::ws; - - connectivity.Allocate(numInts - numCells); - numIndices.Allocate(numCells); - - std::vector buffer(static_cast(numInts)); - this->ReadArray(buffer); - - vtkm::Int32* buffp = buffer.data(); - auto connectivityPortal = connectivity.WritePortal(); - auto numIndicesPortal = numIndices.WritePortal(); - for (vtkm::Id i = 0, connInd = 0; i < numCells; ++i) + if (this->DataFile->Version[0] < 5) { - vtkm::IdComponent numInds = static_cast(*buffp++); - numIndicesPortal.Set(i, numInds); - for (vtkm::IdComponent j = 0; j < numInds; ++j, ++connInd) + vtkm::Id numCells, numInts; + this->DataFile->Stream >> numCells >> numInts >> std::ws; + + connectivity.Allocate(numInts - numCells); + numIndices.Allocate(numCells); + + std::vector buffer(static_cast(numInts)); + this->ReadArray(buffer); + + vtkm::Int32* buffp = buffer.data(); + auto connectivityPortal = connectivity.WritePortal(); + auto numIndicesPortal = numIndices.WritePortal(); + for (vtkm::Id i = 0, connInd = 0; i < numCells; ++i) { - connectivityPortal.Set(connInd, static_cast(*buffp++)); + vtkm::IdComponent numInds = static_cast(*buffp++); + numIndicesPortal.Set(i, numInds); + for (vtkm::IdComponent j = 0; j < numInds; ++j, ++connInd) + { + connectivityPortal.Set(connInd, static_cast(*buffp++)); + } + } + } + else + { + vtkm::Id offsetsSize, connSize; + this->DataFile->Stream >> offsetsSize >> connSize >> std::ws; + + std::string tag, dataType; + this->DataFile->Stream >> tag >> dataType >> std::ws; + internal::parseAssert(tag == "OFFSETS"); + auto offsets = + this->DoReadArrayVariant(vtkm::cont::Field::Association::ANY, dataType, offsetsSize, 1); + offsets.CastAndCallForTypes, + vtkm::List>( + [&](const auto& offsetsAH) { + vtkm::cont::ArrayCopy(vtkm::cont::make_ArrayHandleOffsetsToNumComponents( + vtkm::cont::make_ArrayHandleCast(offsetsAH, vtkm::Id{})), + numIndices); + }); + + this->DataFile->Stream >> tag >> dataType >> std::ws; + internal::parseAssert(tag == "CONNECTIVITY"); + auto conn = + this->DoReadArrayVariant(vtkm::cont::Field::Association::ANY, dataType, connSize, 1); + if (conn.IsValueType()) + { + conn.AsArrayHandle(connectivity); + } + else + { + conn.CastAndCallForTypes, + vtkm::List>( + [&](const auto& connAH) { vtkm::cont::ArrayCopy(connAH, connectivity); }); } } } diff --git a/vtkm/io/internal/VTKDataSetTypes.h b/vtkm/io/internal/VTKDataSetTypes.h index 30e9ece20..eaeb811ea 100644 --- a/vtkm/io/internal/VTKDataSetTypes.h +++ b/vtkm/io/internal/VTKDataSetTypes.h @@ -37,14 +37,19 @@ enum DataType DTYPE_UNSIGNED_LONG, DTYPE_LONG, DTYPE_FLOAT, - DTYPE_DOUBLE + DTYPE_DOUBLE, + DTYPE_UNSIGNED_LONG_LONG, + DTYPE_LONG_LONG, + + DTYPE_COUNT }; inline const char* DataTypeString(int id) { static const char* strings[] = { - "", "bit", "unsigned_char", "char", "unsigned_short", "short", "unsigned_int", - "int", "unsigned_long", "long", "float", "double" + "", "bit", "unsigned_char", "char", "unsigned_short", + "short", "unsigned_int", "int", "unsigned_long", "long", + "float", "double", "vtktypeuint64", "vtktypeint64" }; return strings[id]; } @@ -52,7 +57,7 @@ inline const char* DataTypeString(int id) inline DataType DataTypeId(const std::string& str) { DataType type = DTYPE_UNKNOWN; - for (int id = 1; id < 12; ++id) + for (int id = 1; id < DTYPE_COUNT; ++id) { if (str == DataTypeString(id)) { @@ -220,9 +225,11 @@ inline void SelectTypeAndCall(DataType dtype, SelectVecTypeAndCall(vtkm::Int32(), numComponents, functor); break; case DTYPE_UNSIGNED_LONG: + case DTYPE_UNSIGNED_LONG_LONG: SelectVecTypeAndCall(vtkm::UInt64(), numComponents, functor); break; case DTYPE_LONG: + case DTYPE_LONG_LONG: SelectVecTypeAndCall(vtkm::Int64(), numComponents, functor); break; case DTYPE_FLOAT: