Update variants of VTKDataSetReaders to compile into vtkm_io

This commit is contained in:
Kenneth Moreland 2020-05-19 13:04:12 -06:00
parent 0612be9c5b
commit 086439e71e
14 changed files with 615 additions and 449 deletions

@ -0,0 +1,12 @@
# Move VTK file readers and writers into vtkm_io
The legacy VTK file reader and writer were created back when VTK-m was a
header-only library. Things have changed and we now compile quite a bit of
code into libraries. At this point, there is no reason why the VTK file
reader/writer should be any different.
Thus, `VTKDataSetReader`, `VTKDataSetWriter`, and several supporting
classes are now compiled into the `vtk_io` library.
As a side effect, code using VTK-m will need to link to `vtk_io` if they
are using any readers or writers.

@ -35,7 +35,13 @@ set(template_sources
set(sources
DecodePNG.cxx
EncodePNG.cxx
VTKDataSetReader.cxx
VTKDataSetReaderBase.cxx
VTKPolyDataReader.cxx
VTKRectilinearGridReader.cxx
VTKStructuredGridReader.cxx
VTKStructuredPointsReader.cxx
VTKUnstructuredGridReader.cxx
)
vtkm_declare_headers(

@ -0,0 +1,92 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/io/VTKDataSetReader.h>
#include <vtkm/io/VTKPolyDataReader.h>
#include <vtkm/io/VTKRectilinearGridReader.h>
#include <vtkm/io/VTKStructuredGridReader.h>
#include <vtkm/io/VTKStructuredPointsReader.h>
#include <vtkm/io/VTKUnstructuredGridReader.h>
#include <memory>
namespace vtkm
{
namespace io
{
VTKDataSetReader::VTKDataSetReader(const char* fileName)
: VTKDataSetReaderBase(fileName)
{
}
VTKDataSetReader::VTKDataSetReader(const std::string& fileName)
: VTKDataSetReaderBase(fileName)
{
}
VTKDataSetReader::~VTKDataSetReader()
{
}
void VTKDataSetReader::PrintSummary(std::ostream& out) const
{
if (this->Reader)
{
this->Reader->PrintSummary(out);
}
else
{
VTKDataSetReaderBase::PrintSummary(out);
}
}
void VTKDataSetReader::CloseFile()
{
if (this->Reader)
{
this->Reader->CloseFile();
}
else
{
VTKDataSetReaderBase::CloseFile();
}
}
void VTKDataSetReader::Read()
{
switch (this->DataFile->Structure)
{
case vtkm::io::internal::DATASET_STRUCTURED_POINTS:
this->Reader.reset(new VTKStructuredPointsReader(""));
break;
case vtkm::io::internal::DATASET_STRUCTURED_GRID:
this->Reader.reset(new VTKStructuredGridReader(""));
break;
case vtkm::io::internal::DATASET_RECTILINEAR_GRID:
this->Reader.reset(new VTKRectilinearGridReader(""));
break;
case vtkm::io::internal::DATASET_POLYDATA:
this->Reader.reset(new VTKPolyDataReader(""));
break;
case vtkm::io::internal::DATASET_UNSTRUCTURED_GRID:
this->Reader.reset(new VTKUnstructuredGridReader(""));
break;
default:
throw vtkm::io::ErrorIO("Unsupported DataSet type.");
}
this->TransferDataFile(*this->Reader.get());
this->Reader->Read();
this->DataSet = this->Reader->GetDataSet();
}
}
} // namespace vtkm::io

@ -11,86 +11,27 @@
#define vtk_m_io_VTKDataSetReader_h
#include <vtkm/io/VTKDataSetReaderBase.h>
#include <vtkm/io/VTKPolyDataReader.h>
#include <vtkm/io/VTKRectilinearGridReader.h>
#include <vtkm/io/VTKStructuredGridReader.h>
#include <vtkm/io/VTKStructuredPointsReader.h>
#include <vtkm/io/VTKUnstructuredGridReader.h>
#include <memory>
namespace vtkm
{
namespace io
{
VTKM_SILENCE_WEAK_VTABLE_WARNING_START
class VTKDataSetReader : public VTKDataSetReaderBase
class VTKM_IO_EXPORT VTKDataSetReader : public VTKDataSetReaderBase
{
public:
explicit VTKDataSetReader(const char* fileName)
: VTKDataSetReaderBase(fileName)
{
}
VTKM_CONT VTKDataSetReader(const char* fileName);
VTKM_CONT VTKDataSetReader(const std::string& fileName);
VTKM_CONT ~VTKDataSetReader() override;
explicit VTKDataSetReader(const std::string& fileName)
: VTKDataSetReaderBase(fileName)
{
}
VTKDataSetReader(const VTKDataSetReader&) = delete;
void operator=(const VTKDataSetReader&) = delete;
virtual void PrintSummary(std::ostream& out) const
{
if (this->Reader)
{
this->Reader->PrintSummary(out);
}
else
{
VTKDataSetReaderBase::PrintSummary(out);
}
}
VTKM_CONT void PrintSummary(std::ostream& out) const override;
private:
virtual void CloseFile()
{
if (this->Reader)
{
this->Reader->CloseFile();
}
else
{
VTKDataSetReaderBase::CloseFile();
}
}
virtual void Read()
{
switch (this->DataFile->Structure)
{
case vtkm::io::internal::DATASET_STRUCTURED_POINTS:
this->Reader.reset(new VTKStructuredPointsReader(""));
break;
case vtkm::io::internal::DATASET_STRUCTURED_GRID:
this->Reader.reset(new VTKStructuredGridReader(""));
break;
case vtkm::io::internal::DATASET_RECTILINEAR_GRID:
this->Reader.reset(new VTKRectilinearGridReader(""));
break;
case vtkm::io::internal::DATASET_POLYDATA:
this->Reader.reset(new VTKPolyDataReader(""));
break;
case vtkm::io::internal::DATASET_UNSTRUCTURED_GRID:
this->Reader.reset(new VTKUnstructuredGridReader(""));
break;
default:
throw vtkm::io::ErrorIO("Unsupported DataSet type.");
}
this->TransferDataFile(*this->Reader.get());
this->Reader->Read();
this->DataSet = this->Reader->GetDataSet();
}
VTKM_CONT void CloseFile() override;
VTKM_CONT void Read() override;
std::unique_ptr<VTKDataSetReaderBase> Reader;
};

@ -0,0 +1,152 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/io/VTKPolyDataReader.h>
namespace
{
template <typename T>
inline vtkm::cont::ArrayHandle<T> ConcatinateArrayHandles(
const std::vector<vtkm::cont::ArrayHandle<T>>& arrays)
{
vtkm::Id size = 0;
for (std::size_t i = 0; i < arrays.size(); ++i)
{
size += arrays[i].GetNumberOfValues();
}
vtkm::cont::ArrayHandle<T> out;
out.Allocate(size);
auto outp = vtkm::cont::ArrayPortalToIteratorBegin(out.WritePortal());
for (std::size_t i = 0; i < arrays.size(); ++i)
{
std::copy(vtkm::cont::ArrayPortalToIteratorBegin(arrays[i].ReadPortal()),
vtkm::cont::ArrayPortalToIteratorEnd(arrays[i].ReadPortal()),
outp);
using DifferenceType = typename std::iterator_traits<decltype(outp)>::difference_type;
std::advance(outp, static_cast<DifferenceType>(arrays[i].GetNumberOfValues()));
}
return out;
}
}
namespace vtkm
{
namespace io
{
VTKPolyDataReader::VTKPolyDataReader(const char* fileName)
: VTKDataSetReaderBase(fileName)
{
}
VTKPolyDataReader::VTKPolyDataReader(const std::string& fileName)
: VTKDataSetReaderBase(fileName)
{
}
void VTKPolyDataReader::Read()
{
if (this->DataFile->Structure != vtkm::io::internal::DATASET_POLYDATA)
{
throw vtkm::io::ErrorIO("Incorrect DataSet type");
}
//We need to be able to handle VisIt files which dump Field data
//at the top of a VTK file
std::string tag;
this->DataFile->Stream >> tag;
if (tag == "FIELD")
{
this->ReadGlobalFields();
this->DataFile->Stream >> tag;
}
// Read the points
internal::parseAssert(tag == "POINTS");
this->ReadPoints();
vtkm::Id numPoints = this->DataSet.GetNumberOfPoints();
// Read the cellset
std::vector<vtkm::cont::ArrayHandle<vtkm::Id>> connectivityArrays;
std::vector<vtkm::cont::ArrayHandle<vtkm::IdComponent>> numIndicesArrays;
std::vector<vtkm::UInt8> shapesBuffer;
while (!this->DataFile->Stream.eof())
{
vtkm::UInt8 shape = vtkm::CELL_SHAPE_EMPTY;
this->DataFile->Stream >> tag;
if (tag == "VERTICES")
{
shape = vtkm::io::internal::CELL_SHAPE_POLY_VERTEX;
}
else if (tag == "LINES")
{
shape = vtkm::io::internal::CELL_SHAPE_POLY_LINE;
}
else if (tag == "POLYGONS")
{
shape = vtkm::CELL_SHAPE_POLYGON;
}
else if (tag == "TRIANGLE_STRIPS")
{
shape = vtkm::io::internal::CELL_SHAPE_TRIANGLE_STRIP;
}
else
{
this->DataFile->Stream.seekg(-static_cast<std::streamoff>(tag.length()), std::ios_base::cur);
break;
}
vtkm::cont::ArrayHandle<vtkm::Id> cellConnectivity;
vtkm::cont::ArrayHandle<vtkm::IdComponent> cellNumIndices;
this->ReadCells(cellConnectivity, cellNumIndices);
connectivityArrays.push_back(cellConnectivity);
numIndicesArrays.push_back(cellNumIndices);
shapesBuffer.insert(
shapesBuffer.end(), static_cast<std::size_t>(cellNumIndices.GetNumberOfValues()), shape);
}
vtkm::cont::ArrayHandle<vtkm::Id> connectivity = ConcatinateArrayHandles(connectivityArrays);
vtkm::cont::ArrayHandle<vtkm::IdComponent> numIndices = ConcatinateArrayHandles(numIndicesArrays);
vtkm::cont::ArrayHandle<vtkm::UInt8> shapes;
shapes.Allocate(static_cast<vtkm::Id>(shapesBuffer.size()));
std::copy(shapesBuffer.begin(),
shapesBuffer.end(),
vtkm::cont::ArrayPortalToIteratorBegin(shapes.WritePortal()));
vtkm::cont::ArrayHandle<vtkm::Id> permutation;
vtkm::io::internal::FixupCellSet(connectivity, numIndices, shapes, permutation);
this->SetCellsPermutation(permutation);
if (vtkm::io::internal::IsSingleShape(shapes))
{
vtkm::cont::CellSetSingleType<> cellSet;
cellSet.Fill(
numPoints, shapes.ReadPortal().Get(0), numIndices.ReadPortal().Get(0), connectivity);
this->DataSet.SetCellSet(cellSet);
}
else
{
auto offsets = vtkm::cont::ConvertNumIndicesToOffsets(numIndices);
vtkm::cont::CellSetExplicit<> cellSet;
cellSet.Fill(numPoints, shapes, connectivity, offsets);
this->DataSet.SetCellSet(cellSet);
}
// Read points and cell attributes
this->ReadAttributes();
}
}
} // namespace vtkm::io

@ -22,147 +22,15 @@ namespace vtkm
namespace io
{
namespace internal
{
template <typename T>
inline vtkm::cont::ArrayHandle<T> ConcatinateArrayHandles(
const std::vector<vtkm::cont::ArrayHandle<T>>& arrays)
{
vtkm::Id size = 0;
for (std::size_t i = 0; i < arrays.size(); ++i)
{
size += arrays[i].GetNumberOfValues();
}
vtkm::cont::ArrayHandle<T> out;
out.Allocate(size);
auto outp = vtkm::cont::ArrayPortalToIteratorBegin(out.WritePortal());
for (std::size_t i = 0; i < arrays.size(); ++i)
{
std::copy(vtkm::cont::ArrayPortalToIteratorBegin(arrays[i].ReadPortal()),
vtkm::cont::ArrayPortalToIteratorEnd(arrays[i].ReadPortal()),
outp);
using DifferenceType = typename std::iterator_traits<decltype(outp)>::difference_type;
std::advance(outp, static_cast<DifferenceType>(arrays[i].GetNumberOfValues()));
}
return out;
}
} // namespace internal
VTKM_SILENCE_WEAK_VTABLE_WARNING_START
class VTKPolyDataReader : public VTKDataSetReaderBase
class VTKM_IO_EXPORT VTKPolyDataReader : public VTKDataSetReaderBase
{
public:
explicit VTKPolyDataReader(const char* fileName)
: VTKDataSetReaderBase(fileName)
{
}
explicit VTKM_CONT VTKPolyDataReader(const char* fileName);
explicit VTKM_CONT VTKPolyDataReader(const std::string& fileName);
private:
virtual void Read()
{
if (this->DataFile->Structure != vtkm::io::internal::DATASET_POLYDATA)
{
throw vtkm::io::ErrorIO("Incorrect DataSet type");
}
//We need to be able to handle VisIt files which dump Field data
//at the top of a VTK file
std::string tag;
this->DataFile->Stream >> tag;
if (tag == "FIELD")
{
this->ReadGlobalFields();
this->DataFile->Stream >> tag;
}
// Read the points
internal::parseAssert(tag == "POINTS");
this->ReadPoints();
vtkm::Id numPoints = this->DataSet.GetNumberOfPoints();
// Read the cellset
std::vector<vtkm::cont::ArrayHandle<vtkm::Id>> connectivityArrays;
std::vector<vtkm::cont::ArrayHandle<vtkm::IdComponent>> numIndicesArrays;
std::vector<vtkm::UInt8> shapesBuffer;
while (!this->DataFile->Stream.eof())
{
vtkm::UInt8 shape = vtkm::CELL_SHAPE_EMPTY;
this->DataFile->Stream >> tag;
if (tag == "VERTICES")
{
shape = vtkm::io::internal::CELL_SHAPE_POLY_VERTEX;
}
else if (tag == "LINES")
{
shape = vtkm::io::internal::CELL_SHAPE_POLY_LINE;
}
else if (tag == "POLYGONS")
{
shape = vtkm::CELL_SHAPE_POLYGON;
}
else if (tag == "TRIANGLE_STRIPS")
{
shape = vtkm::io::internal::CELL_SHAPE_TRIANGLE_STRIP;
}
else
{
this->DataFile->Stream.seekg(-static_cast<std::streamoff>(tag.length()),
std::ios_base::cur);
break;
}
vtkm::cont::ArrayHandle<vtkm::Id> cellConnectivity;
vtkm::cont::ArrayHandle<vtkm::IdComponent> cellNumIndices;
this->ReadCells(cellConnectivity, cellNumIndices);
connectivityArrays.push_back(cellConnectivity);
numIndicesArrays.push_back(cellNumIndices);
shapesBuffer.insert(
shapesBuffer.end(), static_cast<std::size_t>(cellNumIndices.GetNumberOfValues()), shape);
}
vtkm::cont::ArrayHandle<vtkm::Id> connectivity =
internal::ConcatinateArrayHandles(connectivityArrays);
vtkm::cont::ArrayHandle<vtkm::IdComponent> numIndices =
internal::ConcatinateArrayHandles(numIndicesArrays);
vtkm::cont::ArrayHandle<vtkm::UInt8> shapes;
shapes.Allocate(static_cast<vtkm::Id>(shapesBuffer.size()));
std::copy(shapesBuffer.begin(),
shapesBuffer.end(),
vtkm::cont::ArrayPortalToIteratorBegin(shapes.WritePortal()));
vtkm::cont::ArrayHandle<vtkm::Id> permutation;
vtkm::io::internal::FixupCellSet(connectivity, numIndices, shapes, permutation);
this->SetCellsPermutation(permutation);
if (vtkm::io::internal::IsSingleShape(shapes))
{
vtkm::cont::CellSetSingleType<> cellSet;
cellSet.Fill(
numPoints, shapes.ReadPortal().Get(0), numIndices.ReadPortal().Get(0), connectivity);
this->DataSet.SetCellSet(cellSet);
}
else
{
auto offsets = vtkm::cont::ConvertNumIndicesToOffsets(numIndices);
vtkm::cont::CellSetExplicit<> cellSet;
cellSet.Fill(numPoints, shapes, connectivity, offsets);
this->DataSet.SetCellSet(cellSet);
}
// Read points and cell attributes
this->ReadAttributes();
}
void Read() override;
};
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
}
} // namespace vtkm::io

@ -0,0 +1,95 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/io/VTKRectilinearGridReader.h>
namespace vtkm
{
namespace io
{
VTKRectilinearGridReader::VTKRectilinearGridReader(const char* fileName)
: VTKDataSetReaderBase(fileName)
{
}
VTKRectilinearGridReader::VTKRectilinearGridReader(const std::string& fileName)
: VTKDataSetReaderBase(fileName)
{
}
void VTKRectilinearGridReader::Read()
{
if (this->DataFile->Structure != vtkm::io::internal::DATASET_RECTILINEAR_GRID)
throw vtkm::io::ErrorIO("Incorrect DataSet type");
//We need to be able to handle VisIt files which dump Field data
//at the top of a VTK file
std::string tag;
this->DataFile->Stream >> tag;
if (tag == "FIELD")
{
this->ReadGlobalFields();
this->DataFile->Stream >> tag;
}
// Read structured grid specific meta-data
internal::parseAssert(tag == "DIMENSIONS");
vtkm::Id3 dim;
this->DataFile->Stream >> dim[0] >> dim[1] >> dim[2] >> std::ws;
//Read the points.
std::string dataType;
std::size_t numPoints[3];
vtkm::cont::VariantArrayHandle X, Y, Z;
// Always read coordinates as vtkm::FloatDefault
std::string readDataType = vtkm::io::internal::DataTypeName<vtkm::FloatDefault>::Name();
this->DataFile->Stream >> tag >> numPoints[0] >> dataType >> std::ws;
if (tag != "X_COORDINATES")
throw vtkm::io::ErrorIO("X_COORDINATES tag not found");
X = this->DoReadArrayVariant(vtkm::cont::Field::Association::ANY, readDataType, numPoints[0], 1);
this->DataFile->Stream >> tag >> numPoints[1] >> dataType >> std::ws;
if (tag != "Y_COORDINATES")
throw vtkm::io::ErrorIO("Y_COORDINATES tag not found");
Y = this->DoReadArrayVariant(vtkm::cont::Field::Association::ANY, readDataType, numPoints[1], 1);
this->DataFile->Stream >> tag >> numPoints[2] >> dataType >> std::ws;
if (tag != "Z_COORDINATES")
throw vtkm::io::ErrorIO("Z_COORDINATES tag not found");
Z = this->DoReadArrayVariant(vtkm::cont::Field::Association::ANY, readDataType, numPoints[2], 1);
if (dim != vtkm::Id3(static_cast<vtkm::Id>(numPoints[0]),
static_cast<vtkm::Id>(numPoints[1]),
static_cast<vtkm::Id>(numPoints[2])))
throw vtkm::io::ErrorIO("DIMENSIONS not equal to number of points");
vtkm::cont::ArrayHandleCartesianProduct<vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
vtkm::cont::ArrayHandle<vtkm::FloatDefault>>
coords;
vtkm::cont::ArrayHandle<vtkm::FloatDefault> Xc, Yc, Zc;
X.CopyTo(Xc);
Y.CopyTo(Yc);
Z.CopyTo(Zc);
coords = vtkm::cont::make_ArrayHandleCartesianProduct(Xc, Yc, Zc);
vtkm::cont::CoordinateSystem coordSys("coordinates", coords);
this->DataSet.AddCoordinateSystem(coordSys);
this->DataSet.SetCellSet(internal::CreateCellSetStructured(dim));
// Read points and cell attributes
this->ReadAttributes();
}
}
} // namespace vtkm::io

@ -17,89 +17,15 @@ namespace vtkm
namespace io
{
VTKM_SILENCE_WEAK_VTABLE_WARNING_START
class VTKRectilinearGridReader : public VTKDataSetReaderBase
class VTKM_IO_EXPORT VTKRectilinearGridReader : public VTKDataSetReaderBase
{
public:
explicit VTKRectilinearGridReader(const char* fileName)
: VTKDataSetReaderBase(fileName)
{
}
explicit VTKM_CONT VTKRectilinearGridReader(const char* fileName);
explicit VTKM_CONT VTKRectilinearGridReader(const std::string& fileName);
private:
virtual void Read()
{
if (this->DataFile->Structure != vtkm::io::internal::DATASET_RECTILINEAR_GRID)
throw vtkm::io::ErrorIO("Incorrect DataSet type");
//We need to be able to handle VisIt files which dump Field data
//at the top of a VTK file
std::string tag;
this->DataFile->Stream >> tag;
if (tag == "FIELD")
{
this->ReadGlobalFields();
this->DataFile->Stream >> tag;
}
// Read structured grid specific meta-data
internal::parseAssert(tag == "DIMENSIONS");
vtkm::Id3 dim;
this->DataFile->Stream >> dim[0] >> dim[1] >> dim[2] >> std::ws;
//Read the points.
std::string dataType;
std::size_t numPoints[3];
vtkm::cont::VariantArrayHandle X, Y, Z;
// Always read coordinates as vtkm::FloatDefault
std::string readDataType = vtkm::io::internal::DataTypeName<vtkm::FloatDefault>::Name();
this->DataFile->Stream >> tag >> numPoints[0] >> dataType >> std::ws;
if (tag != "X_COORDINATES")
throw vtkm::io::ErrorIO("X_COORDINATES tag not found");
X =
this->DoReadArrayVariant(vtkm::cont::Field::Association::ANY, readDataType, numPoints[0], 1);
this->DataFile->Stream >> tag >> numPoints[1] >> dataType >> std::ws;
if (tag != "Y_COORDINATES")
throw vtkm::io::ErrorIO("Y_COORDINATES tag not found");
Y =
this->DoReadArrayVariant(vtkm::cont::Field::Association::ANY, readDataType, numPoints[1], 1);
this->DataFile->Stream >> tag >> numPoints[2] >> dataType >> std::ws;
if (tag != "Z_COORDINATES")
throw vtkm::io::ErrorIO("Z_COORDINATES tag not found");
Z =
this->DoReadArrayVariant(vtkm::cont::Field::Association::ANY, readDataType, numPoints[2], 1);
if (dim != vtkm::Id3(static_cast<vtkm::Id>(numPoints[0]),
static_cast<vtkm::Id>(numPoints[1]),
static_cast<vtkm::Id>(numPoints[2])))
throw vtkm::io::ErrorIO("DIMENSIONS not equal to number of points");
vtkm::cont::ArrayHandleCartesianProduct<vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
vtkm::cont::ArrayHandle<vtkm::FloatDefault>,
vtkm::cont::ArrayHandle<vtkm::FloatDefault>>
coords;
vtkm::cont::ArrayHandle<vtkm::FloatDefault> Xc, Yc, Zc;
X.CopyTo(Xc);
Y.CopyTo(Yc);
Z.CopyTo(Zc);
coords = vtkm::cont::make_ArrayHandleCartesianProduct(Xc, Yc, Zc);
vtkm::cont::CoordinateSystem coordSys("coordinates", coords);
this->DataSet.AddCoordinateSystem(coordSys);
this->DataSet.SetCellSet(internal::CreateCellSetStructured(dim));
// Read points and cell attributes
this->ReadAttributes();
}
VTKM_CONT void Read() override;
};
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
}
} // namespace vtkm::io

@ -0,0 +1,62 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/io/VTKStructuredGridReader.h>
namespace vtkm
{
namespace io
{
VTKStructuredGridReader::VTKStructuredGridReader(const char* fileName)
: VTKDataSetReaderBase(fileName)
{
}
VTKStructuredGridReader::VTKStructuredGridReader(const std::string& fileName)
: VTKDataSetReaderBase(fileName)
{
}
void VTKStructuredGridReader::Read()
{
if (this->DataFile->Structure != vtkm::io::internal::DATASET_STRUCTURED_GRID)
{
throw vtkm::io::ErrorIO("Incorrect DataSet type");
}
std::string tag;
//We need to be able to handle VisIt files which dump Field data
//at the top of a VTK file
this->DataFile->Stream >> tag;
if (tag == "FIELD")
{
this->ReadGlobalFields();
this->DataFile->Stream >> tag;
}
// Read structured grid specific meta-data
internal::parseAssert(tag == "DIMENSIONS");
vtkm::Id3 dim;
this->DataFile->Stream >> dim[0] >> dim[1] >> dim[2] >> std::ws;
this->DataSet.SetCellSet(internal::CreateCellSetStructured(dim));
// Read the points
this->DataFile->Stream >> tag;
internal::parseAssert(tag == "POINTS");
this->ReadPoints();
// Read points and cell attributes
this->ReadAttributes();
}
}
} // namespace vtkm::io

@ -17,53 +17,15 @@ namespace vtkm
namespace io
{
VTKM_SILENCE_WEAK_VTABLE_WARNING_START
class VTKStructuredGridReader : public VTKDataSetReaderBase
class VTKM_IO_EXPORT VTKStructuredGridReader : public VTKDataSetReaderBase
{
public:
explicit VTKStructuredGridReader(const char* fileName)
: VTKDataSetReaderBase(fileName)
{
}
explicit VTKM_CONT VTKStructuredGridReader(const char* fileName);
explicit VTKM_CONT VTKStructuredGridReader(const std::string& fileName);
private:
virtual void Read()
{
if (this->DataFile->Structure != vtkm::io::internal::DATASET_STRUCTURED_GRID)
{
throw vtkm::io::ErrorIO("Incorrect DataSet type");
}
std::string tag;
//We need to be able to handle VisIt files which dump Field data
//at the top of a VTK file
this->DataFile->Stream >> tag;
if (tag == "FIELD")
{
this->ReadGlobalFields();
this->DataFile->Stream >> tag;
}
// Read structured grid specific meta-data
internal::parseAssert(tag == "DIMENSIONS");
vtkm::Id3 dim;
this->DataFile->Stream >> dim[0] >> dim[1] >> dim[2] >> std::ws;
this->DataSet.SetCellSet(internal::CreateCellSetStructured(dim));
// Read the points
this->DataFile->Stream >> tag;
internal::parseAssert(tag == "POINTS");
this->ReadPoints();
// Read points and cell attributes
this->ReadAttributes();
}
VTKM_CONT void Read() override;
};
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
}
} // namespace vtkm::io

@ -0,0 +1,79 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/io/VTKStructuredPointsReader.h>
namespace vtkm
{
namespace io
{
VTKStructuredPointsReader::VTKStructuredPointsReader(const char* fileName)
: VTKDataSetReaderBase(fileName)
{
}
VTKStructuredPointsReader::VTKStructuredPointsReader(const std::string& fileName)
: VTKDataSetReaderBase(fileName)
{
}
void VTKStructuredPointsReader::Read()
{
if (this->DataFile->Structure != vtkm::io::internal::DATASET_STRUCTURED_POINTS)
{
throw vtkm::io::ErrorIO("Incorrect DataSet type");
}
std::string tag;
// Read structured points specific meta-data
vtkm::Id3 dim;
vtkm::Vec3f_32 origin, spacing;
//Two ways the file can describe the dimensions. The proper way is by
//using the DIMENSIONS keyword, but VisIt written VTK files spicify data
//bounds instead, as a FIELD
std::vector<vtkm::Float32> visitBounds;
this->DataFile->Stream >> tag;
if (tag == "FIELD")
{
this->ReadGlobalFields(&visitBounds);
this->DataFile->Stream >> tag;
}
if (visitBounds.empty())
{
internal::parseAssert(tag == "DIMENSIONS");
this->DataFile->Stream >> dim[0] >> dim[1] >> dim[2] >> std::ws;
this->DataFile->Stream >> tag;
}
internal::parseAssert(tag == "SPACING");
this->DataFile->Stream >> spacing[0] >> spacing[1] >> spacing[2] >> std::ws;
if (!visitBounds.empty())
{
//now with spacing and physical bounds we can back compute the dimensions
dim[0] = static_cast<vtkm::Id>((visitBounds[1] - visitBounds[0]) / spacing[0]);
dim[1] = static_cast<vtkm::Id>((visitBounds[3] - visitBounds[2]) / spacing[1]);
dim[2] = static_cast<vtkm::Id>((visitBounds[5] - visitBounds[4]) / spacing[2]);
}
this->DataFile->Stream >> tag >> origin[0] >> origin[1] >> origin[2] >> std::ws;
internal::parseAssert(tag == "ORIGIN");
this->DataSet.SetCellSet(internal::CreateCellSetStructured(dim));
this->DataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem("coordinates", dim, origin, spacing));
// Read points and cell attributes
this->ReadAttributes();
}
}
} // namespace vtkm::io

@ -17,70 +17,15 @@ namespace vtkm
namespace io
{
VTKM_SILENCE_WEAK_VTABLE_WARNING_START
class VTKStructuredPointsReader : public VTKDataSetReaderBase
class VTKM_IO_EXPORT VTKStructuredPointsReader : public VTKDataSetReaderBase
{
public:
explicit VTKStructuredPointsReader(const char* fileName)
: VTKDataSetReaderBase(fileName)
{
}
explicit VTKM_CONT VTKStructuredPointsReader(const char* fileName);
explicit VTKM_CONT VTKStructuredPointsReader(const std::string& fileName);
private:
virtual void Read()
{
if (this->DataFile->Structure != vtkm::io::internal::DATASET_STRUCTURED_POINTS)
{
throw vtkm::io::ErrorIO("Incorrect DataSet type");
}
std::string tag;
// Read structured points specific meta-data
vtkm::Id3 dim;
vtkm::Vec3f_32 origin, spacing;
//Two ways the file can describe the dimensions. The proper way is by
//using the DIMENSIONS keyword, but VisIt written VTK files spicify data
//bounds instead, as a FIELD
std::vector<vtkm::Float32> visitBounds;
this->DataFile->Stream >> tag;
if (tag == "FIELD")
{
this->ReadGlobalFields(&visitBounds);
this->DataFile->Stream >> tag;
}
if (visitBounds.empty())
{
internal::parseAssert(tag == "DIMENSIONS");
this->DataFile->Stream >> dim[0] >> dim[1] >> dim[2] >> std::ws;
this->DataFile->Stream >> tag;
}
internal::parseAssert(tag == "SPACING");
this->DataFile->Stream >> spacing[0] >> spacing[1] >> spacing[2] >> std::ws;
if (!visitBounds.empty())
{
//now with spacing and physical bounds we can back compute the dimensions
dim[0] = static_cast<vtkm::Id>((visitBounds[1] - visitBounds[0]) / spacing[0]);
dim[1] = static_cast<vtkm::Id>((visitBounds[3] - visitBounds[2]) / spacing[1]);
dim[2] = static_cast<vtkm::Id>((visitBounds[5] - visitBounds[4]) / spacing[2]);
}
this->DataFile->Stream >> tag >> origin[0] >> origin[1] >> origin[2] >> std::ws;
internal::parseAssert(tag == "ORIGIN");
this->DataSet.SetCellSet(internal::CreateCellSetStructured(dim));
this->DataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem("coordinates", dim, origin, spacing));
// Read points and cell attributes
this->ReadAttributes();
}
VTKM_CONT void Read() override;
};
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
}
} // namespace vtkm::io

@ -0,0 +1,88 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/io/VTKUnstructuredGridReader.h>
#include <vtkm/io/internal/VTKDataSetCells.h>
namespace vtkm
{
namespace io
{
VTKUnstructuredGridReader::VTKUnstructuredGridReader(const char* fileName)
: VTKDataSetReaderBase(fileName)
{
}
VTKUnstructuredGridReader::VTKUnstructuredGridReader(const std::string& fileName)
: VTKDataSetReaderBase(fileName)
{
}
void VTKUnstructuredGridReader::Read()
{
if (this->DataFile->Structure != vtkm::io::internal::DATASET_UNSTRUCTURED_GRID)
{
throw vtkm::io::ErrorIO("Incorrect DataSet type");
}
//We need to be able to handle VisIt files which dump Field data
//at the top of a VTK file
std::string tag;
this->DataFile->Stream >> tag;
if (tag == "FIELD")
{
this->ReadGlobalFields();
this->DataFile->Stream >> tag;
}
// Read the points
internal::parseAssert(tag == "POINTS");
this->ReadPoints();
vtkm::Id numPoints = this->DataSet.GetNumberOfPoints();
// Read the cellset
vtkm::cont::ArrayHandle<vtkm::Id> connectivity;
vtkm::cont::ArrayHandle<vtkm::IdComponent> numIndices;
vtkm::cont::ArrayHandle<vtkm::UInt8> shapes;
this->DataFile->Stream >> tag;
internal::parseAssert(tag == "CELLS");
this->ReadCells(connectivity, numIndices);
this->ReadShapes(shapes);
vtkm::cont::ArrayHandle<vtkm::Id> permutation;
vtkm::io::internal::FixupCellSet(connectivity, numIndices, shapes, permutation);
this->SetCellsPermutation(permutation);
//DRP
if (false) //vtkm::io::internal::IsSingleShape(shapes))
{
vtkm::cont::CellSetSingleType<> cellSet;
cellSet.Fill(
numPoints, shapes.ReadPortal().Get(0), numIndices.ReadPortal().Get(0), connectivity);
this->DataSet.SetCellSet(cellSet);
}
else
{
auto offsets = vtkm::cont::ConvertNumIndicesToOffsets(numIndices);
vtkm::cont::CellSetExplicit<> cellSet;
cellSet.Fill(numPoints, shapes, connectivity, offsets);
this->DataSet.SetCellSet(cellSet);
}
// Read points and cell attributes
this->ReadAttributes();
}
}
}

@ -17,77 +17,15 @@ namespace vtkm
namespace io
{
VTKM_SILENCE_WEAK_VTABLE_WARNING_START
class VTKUnstructuredGridReader : public VTKDataSetReaderBase
class VTKM_IO_EXPORT VTKUnstructuredGridReader : public VTKDataSetReaderBase
{
public:
explicit VTKUnstructuredGridReader(const char* fileName)
: VTKDataSetReaderBase(fileName)
{
}
explicit VTKM_CONT VTKUnstructuredGridReader(const char* fileName);
explicit VTKM_CONT VTKUnstructuredGridReader(const std::string& fileName);
private:
virtual void Read()
{
if (this->DataFile->Structure != vtkm::io::internal::DATASET_UNSTRUCTURED_GRID)
{
throw vtkm::io::ErrorIO("Incorrect DataSet type");
}
//We need to be able to handle VisIt files which dump Field data
//at the top of a VTK file
std::string tag;
this->DataFile->Stream >> tag;
if (tag == "FIELD")
{
this->ReadGlobalFields();
this->DataFile->Stream >> tag;
}
// Read the points
internal::parseAssert(tag == "POINTS");
this->ReadPoints();
vtkm::Id numPoints = this->DataSet.GetNumberOfPoints();
// Read the cellset
vtkm::cont::ArrayHandle<vtkm::Id> connectivity;
vtkm::cont::ArrayHandle<vtkm::IdComponent> numIndices;
vtkm::cont::ArrayHandle<vtkm::UInt8> shapes;
this->DataFile->Stream >> tag;
internal::parseAssert(tag == "CELLS");
this->ReadCells(connectivity, numIndices);
this->ReadShapes(shapes);
vtkm::cont::ArrayHandle<vtkm::Id> permutation;
vtkm::io::internal::FixupCellSet(connectivity, numIndices, shapes, permutation);
this->SetCellsPermutation(permutation);
//DRP
if (false) //vtkm::io::internal::IsSingleShape(shapes))
{
vtkm::cont::CellSetSingleType<> cellSet;
cellSet.Fill(
numPoints, shapes.ReadPortal().Get(0), numIndices.ReadPortal().Get(0), connectivity);
this->DataSet.SetCellSet(cellSet);
}
else
{
auto offsets = vtkm::cont::ConvertNumIndicesToOffsets(numIndices);
vtkm::cont::CellSetExplicit<> cellSet;
cellSet.Fill(numPoints, shapes, connectivity, offsets);
this->DataSet.SetCellSet(cellSet);
}
// Read points and cell attributes
this->ReadAttributes();
}
VTKM_CONT void Read() override;
};
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
}
} // namespace vtkm::io