diff --git a/vtkm/io/BOVDataSetReader.h b/vtkm/io/BOVDataSetReader.h new file mode 100644 index 000000000..95b7e28ac --- /dev/null +++ b/vtkm/io/BOVDataSetReader.h @@ -0,0 +1,248 @@ +//============================================================================ +// 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. +//============================================================================ +#ifndef vtk_m_io_BOVDataSetReader_h +#define vtk_m_io_BOVDataSetReader_h + +#include +#include +#include +#include +#include + +namespace vtkm +{ +namespace io +{ + +class BOVDataSetReader +{ +public: + BOVDataSetReader(const char* fileName) + : FileName(fileName) + , Loaded(false) + , DataSet() + { + } + BOVDataSetReader(const std::string& fileName) + : FileName(fileName) + , Loaded(false) + , DataSet() + { + } + + const vtkm::cont::DataSet& ReadDataSet() + { + try + { + LoadFile(); + } + catch (std::ifstream::failure& e) + { + std::string message("IO Error: "); + throw vtkm::io::ErrorIO(message + e.what()); + } + return this->DataSet; + } + +private: + using DataFormat = enum { ByteData, ShortData, IntegerData, FloatData, DoubleData }; + + void LoadFile() + { + if (this->Loaded) + return; + + std::ifstream stream(this->FileName); + if (stream.fail()) + throw vtkm::io::ErrorIO("Failed to open file: " + this->FileName); + + DataFormat dataFormat = ByteData; + std::string bovFile, line, token, options, variableName; + vtkm::Id numComponents = 1; + vtkm::Id3 dim; + vtkm::Vec3f origin(0, 0, 0); + vtkm::Vec3f spacing(1, 1, 1); + bool spacingSet = false; + + while (stream.good()) + { + std::getline(stream, line); + if (line.size() == 0 || line[0] == '#') + continue; + //std::cout<<"::"<> bovFile >> std::ws; + } + else if (token.find("DATA") != std::string::npos && token.find("SIZE") != std::string::npos) + { + strStream >> dim[0] >> dim[1] >> dim[2] >> std::ws; + } + else if (token.find("BRICK") != std::string::npos && + token.find("ORIGIN") != std::string::npos) + { + strStream >> origin[0] >> origin[1] >> origin[2] >> std::ws; + } + + //DRP + else if (token.find("BRICK") != std::string::npos && token.find("SIZE") != std::string::npos) + { + strStream >> spacing[0] >> spacing[1] >> spacing[2] >> std::ws; + spacingSet = true; + } + else if (token.find("DATA") != std::string::npos && token.find("FORMAT") != std::string::npos) + { + std::string opt; + strStream >> opt >> std::ws; + if (opt.find("FLOAT") != std::string::npos || opt.find("REAL") != std::string::npos) + dataFormat = FloatData; + else if (opt.find("DOUBLE") != std::string::npos) + dataFormat = DoubleData; + else + throw vtkm::io::ErrorIO("Unsupported data type: " + token); + } + else if (token.find("DATA") != std::string::npos && + token.find("COMPONENTS") != std::string::npos) + { + strStream >> numComponents >> std::ws; + if (numComponents != 1 && numComponents != 3) + throw vtkm::io::ErrorIO("Unsupported number of components"); + } + else if (token.find("VARIABLE") != std::string::npos && + token.find("PALETTE") == std::string::npos) + { + strStream >> variableName >> std::ws; + if (variableName[0] == '"') + variableName = variableName.substr(1, variableName.size() - 2); + } + } + + if (spacingSet) + { + spacing[0] = (spacing[0]) / static_cast(dim[0] - 1); + spacing[1] = (spacing[1]) / static_cast(dim[1] - 1); + spacing[2] = (spacing[2]) / static_cast(dim[2] - 1); + } + + std::string fullPathDataFile; + std::size_t pos = FileName.rfind("/"); + if (pos != std::string::npos) + { + std::string baseDir; + baseDir = this->FileName.substr(0, pos); + fullPathDataFile = baseDir + "/" + bovFile; + } + else + fullPathDataFile = bovFile; + + + vtkm::cont::DataSetBuilderUniform dataSetBuilder; + vtkm::cont::DataSetFieldAdd dsf; + this->DataSet = dataSetBuilder.Create(dim, origin, spacing); + + vtkm::Id numTuples = dim[0] * dim[1] * dim[2]; + if (numComponents == 1) + { + if (dataFormat == FloatData) + { + vtkm::cont::ArrayHandle var; + ReadScalar(fullPathDataFile, numTuples, var); + dsf.AddPointField(this->DataSet, variableName, var); + } + else if (dataFormat == DoubleData) + { + vtkm::cont::ArrayHandle var; + ReadScalar(fullPathDataFile, numTuples, var); + dsf.AddPointField(this->DataSet, variableName, var); + } + } + else if (numComponents == 3) + { + if (dataFormat == FloatData) + { + vtkm::cont::ArrayHandle var; + ReadVector(fullPathDataFile, numTuples, var); + dsf.AddPointField(this->DataSet, variableName, var); + } + else if (dataFormat == DoubleData) + { + vtkm::cont::ArrayHandle var; + ReadVector(fullPathDataFile, numTuples, var); + dsf.AddPointField(this->DataSet, variableName, var); + } + } + + this->Loaded = true; + } + + template + void ReadBuffer(const std::string& fName, const vtkm::Id& sz, std::vector& buff) + { + FILE* fp = fopen(fName.c_str(), "rb"); + size_t readSize = static_cast(sz); + if (fp == nullptr) + throw vtkm::io::ErrorIO("Unable to open data file: " + fName); + buff.resize(readSize); + size_t nread = fread(&buff[0], sizeof(T), readSize, fp); + if (nread != readSize) + throw vtkm::io::ErrorIO("Data file read failed: " + fName); + fclose(fp); + } + + template + void ReadScalar(const std::string& fName, + const vtkm::Id& nTuples, + vtkm::cont::ArrayHandle& var) + { + std::vector buff; + ReadBuffer(fName, nTuples, buff); + var.Allocate(nTuples); + for (vtkm::Id i = 0; i < nTuples; i++) + var.WritePortal().Set(i, buff[(size_t)i]); + } + + template + void ReadVector(const std::string& fName, + const vtkm::Id& nTuples, + vtkm::cont::ArrayHandle>& var) + { + std::vector buff; + ReadBuffer(fName, nTuples * 3, buff); + + var.Allocate(nTuples); + vtkm::Vec v; + for (vtkm::Id i = 0; i < nTuples; i++) + { + v[0] = buff[static_cast(i * 3 + 0)]; + v[1] = buff[static_cast(i * 3 + 1)]; + v[2] = buff[static_cast(i * 3 + 2)]; + var.WritePortal().Set(i, v); + } + } + + std::string FileName; + bool Loaded; + vtkm::cont::DataSet DataSet; +}; +} +} +} // vtkm::io + +#endif // vtk_m_io_BOVReader_h diff --git a/vtkm/io/CMakeLists.txt b/vtkm/io/CMakeLists.txt index 62061203f..e8dfb0465 100644 --- a/vtkm/io/CMakeLists.txt +++ b/vtkm/io/CMakeLists.txt @@ -9,9 +9,17 @@ ##============================================================================ set(headers + BOVDataSetReader.h ErrorIO.h DecodePNG.h EncodePNG.h + VTKDataSetReader.h + VTKDataSetReaderBase.h + VTKPolyDataReader.h + VTKRectilinearGridReader.h + VTKStructuredGridReader.h + VTKStructuredPointsReader.h + VTKUnstructuredGridReader.h VTKDataSetWriter.h ) diff --git a/vtkm/io/VTKDataSetReader.h b/vtkm/io/VTKDataSetReader.h new file mode 100644 index 000000000..166c9466d --- /dev/null +++ b/vtkm/io/VTKDataSetReader.h @@ -0,0 +1,100 @@ +//============================================================================ +// 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. +//============================================================================ +#ifndef vtk_m_io_VTKDataSetReader_h +#define vtk_m_io_VTKDataSetReader_h + +#include +#include +#include +#include +#include +#include + +#include + +namespace vtkm +{ +namespace io +{ + +VTKM_SILENCE_WEAK_VTABLE_WARNING_START + +class VTKDataSetReader : public VTKDataSetReaderBase +{ +public: + explicit VTKDataSetReader(const char* fileName) + : VTKDataSetReaderBase(fileName) + { + } + + explicit VTKDataSetReader(const std::string& fileName) + : VTKDataSetReaderBase(fileName) + { + } + + virtual void PrintSummary(std::ostream& out) const + { + if (this->Reader) + { + this->Reader->PrintSummary(out); + } + else + { + VTKDataSetReaderBase::PrintSummary(out); + } + } + +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(); + } + + std::unique_ptr Reader; +}; +} +} // vtkm::io + +#endif // vtk_m_io_VTKReader_h diff --git a/vtkm/io/reader/VTKDataSetReaderBase.h b/vtkm/io/VTKDataSetReaderBase.h similarity index 99% rename from vtkm/io/reader/VTKDataSetReaderBase.h rename to vtkm/io/VTKDataSetReaderBase.h index 361b1381b..70292392c 100644 --- a/vtkm/io/reader/VTKDataSetReaderBase.h +++ b/vtkm/io/VTKDataSetReaderBase.h @@ -7,8 +7,8 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_io_reader_VTKDataSetReaderBase_h -#define vtk_m_io_reader_VTKDataSetReaderBase_h +#ifndef vtk_m_io_VTKDataSetReaderBase_h +#define vtk_m_io_VTKDataSetReaderBase_h #include #include @@ -34,8 +34,6 @@ namespace vtkm { namespace io { -namespace reader -{ namespace internal { @@ -1004,10 +1002,9 @@ private: VTKM_SILENCE_WEAK_VTABLE_WARNING_END } -} -} // vtkm::io::reader +} // vtkm::io VTKM_BASIC_TYPE_VECTOR(vtkm::io::internal::ColorChannel8) VTKM_BASIC_TYPE_VECTOR(vtkm::io::internal::DummyBitType) -#endif // vtk_m_io_reader_VTKDataSetReaderBase_h +#endif // vtk_m_io_VTKDataSetReaderBase_h diff --git a/vtkm/io/reader/VTKPolyDataReader.h b/vtkm/io/VTKPolyDataReader.h similarity index 95% rename from vtkm/io/reader/VTKPolyDataReader.h rename to vtkm/io/VTKPolyDataReader.h index 327cb26e0..3629f62ca 100644 --- a/vtkm/io/reader/VTKPolyDataReader.h +++ b/vtkm/io/VTKPolyDataReader.h @@ -7,10 +7,10 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_io_reader_VTKPolyDataReader_h -#define vtk_m_io_reader_VTKPolyDataReader_h +#ifndef vtk_m_io_VTKPolyDataReader_h +#define vtk_m_io_VTKPolyDataReader_h -#include +#include #include @@ -20,8 +20,6 @@ namespace vtkm { namespace io { -namespace reader -{ namespace internal { @@ -165,7 +163,6 @@ private: VTKM_SILENCE_WEAK_VTABLE_WARNING_END } -} -} // namespace vtkm::io:reader +} // namespace vtkm::io -#endif // vtk_m_io_reader_VTKPolyDataReader_h +#endif // vtk_m_io_VTKPolyDataReader_h diff --git a/vtkm/io/reader/VTKRectilinearGridReader.h b/vtkm/io/VTKRectilinearGridReader.h similarity index 93% rename from vtkm/io/reader/VTKRectilinearGridReader.h rename to vtkm/io/VTKRectilinearGridReader.h index e05334c2d..92a5c6e05 100644 --- a/vtkm/io/reader/VTKRectilinearGridReader.h +++ b/vtkm/io/VTKRectilinearGridReader.h @@ -7,17 +7,15 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_io_reader_VTKRectilinearGridReader_h -#define vtk_m_io_reader_VTKRectilinearGridReader_h +#ifndef vtk_m_io_VTKRectilinearGridReader_h +#define vtk_m_io_VTKRectilinearGridReader_h -#include +#include namespace vtkm { namespace io { -namespace reader -{ VTKM_SILENCE_WEAK_VTABLE_WARNING_START @@ -103,7 +101,6 @@ private: VTKM_SILENCE_WEAK_VTABLE_WARNING_END } -} -} // namespace vtkm::io:reader +} // namespace vtkm::io -#endif // vtk_m_io_reader_VTKRectilinearGridReader_h +#endif // vtk_m_io_VTKRectilinearGridReader_h diff --git a/vtkm/io/reader/VTKStructuredGridReader.h b/vtkm/io/VTKStructuredGridReader.h similarity index 86% rename from vtkm/io/reader/VTKStructuredGridReader.h rename to vtkm/io/VTKStructuredGridReader.h index 91bf75dad..b37e98301 100644 --- a/vtkm/io/reader/VTKStructuredGridReader.h +++ b/vtkm/io/VTKStructuredGridReader.h @@ -7,17 +7,15 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_io_reader_VTKStructuredGridReader_h -#define vtk_m_io_reader_VTKStructuredGridReader_h +#ifndef vtk_m_io_VTKStructuredGridReader_h +#define vtk_m_io_VTKStructuredGridReader_h -#include +#include namespace vtkm { namespace io { -namespace reader -{ VTKM_SILENCE_WEAK_VTABLE_WARNING_START @@ -67,7 +65,6 @@ private: VTKM_SILENCE_WEAK_VTABLE_WARNING_END } -} -} // namespace vtkm::io:reader +} // namespace vtkm::io -#endif // vtk_m_io_reader_VTKStructuredGridReader_h +#endif // vtk_m_io_VTKStructuredGridReader_h diff --git a/vtkm/io/reader/VTKStructuredPointsReader.h b/vtkm/io/VTKStructuredPointsReader.h similarity index 90% rename from vtkm/io/reader/VTKStructuredPointsReader.h rename to vtkm/io/VTKStructuredPointsReader.h index bbab78414..17d786380 100644 --- a/vtkm/io/reader/VTKStructuredPointsReader.h +++ b/vtkm/io/VTKStructuredPointsReader.h @@ -7,17 +7,15 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_io_reader_VTKStructuredPointsReader_h -#define vtk_m_io_reader_VTKStructuredPointsReader_h +#ifndef vtk_m_io_VTKStructuredPointsReader_h +#define vtk_m_io_VTKStructuredPointsReader_h -#include +#include namespace vtkm { namespace io { -namespace reader -{ VTKM_SILENCE_WEAK_VTABLE_WARNING_START @@ -84,7 +82,6 @@ private: VTKM_SILENCE_WEAK_VTABLE_WARNING_END } -} -} // namespace vtkm::io:reader +} // namespace vtkm::io -#endif // vtk_m_io_reader_VTKStructuredPointsReader_h +#endif // vtk_m_io_VTKStructuredPointsReader_h diff --git a/vtkm/io/reader/VTKUnstructuredGridReader.h b/vtkm/io/VTKUnstructuredGridReader.h similarity index 90% rename from vtkm/io/reader/VTKUnstructuredGridReader.h rename to vtkm/io/VTKUnstructuredGridReader.h index f94543427..bee4e06f8 100644 --- a/vtkm/io/reader/VTKUnstructuredGridReader.h +++ b/vtkm/io/VTKUnstructuredGridReader.h @@ -7,17 +7,15 @@ // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ -#ifndef vtk_m_io_reader_VTKUnstructuredGridReader_h -#define vtk_m_io_reader_VTKUnstructuredGridReader_h +#ifndef vtk_m_io_VTKUnstructuredGridReader_h +#define vtk_m_io_VTKUnstructuredGridReader_h -#include +#include namespace vtkm { namespace io { -namespace reader -{ VTKM_SILENCE_WEAK_VTABLE_WARNING_START @@ -91,7 +89,6 @@ private: VTKM_SILENCE_WEAK_VTABLE_WARNING_END } -} -} // namespace vtkm::io:reader +} // namespace vtkm::io -#endif // vtk_m_io_reader_VTKUnstructuredGridReader_h +#endif // vtk_m_io_VTKUnstructuredGridReader_h diff --git a/vtkm/io/reader/BOVDataSetReader.h b/vtkm/io/reader/BOVDataSetReader.h index 8d57a5ac8..df3bc7399 100644 --- a/vtkm/io/reader/BOVDataSetReader.h +++ b/vtkm/io/reader/BOVDataSetReader.h @@ -10,11 +10,8 @@ #ifndef vtk_m_io_reader_BOVDataSetReader_h #define vtk_m_io_reader_BOVDataSetReader_h -#include -#include -#include -#include -#include +#include +#include namespace vtkm { @@ -23,256 +20,18 @@ namespace io namespace reader { -class BOVDataSetReader +class VTKM_DEPRECATED(1.6, "Please use vtkm::io::BOVDataSetReader") BOVDataSetReader + : public io::BOVDataSetReader { public: BOVDataSetReader(const char* fileName) - : FileName(fileName) - , Loaded(false) - , DataSet() + : io::BOVDataSetReader(fileName) { } BOVDataSetReader(const std::string& fileName) - : FileName(fileName) - , Loaded(false) - , DataSet() + : BOVDataSetReader(fileName) { } - - const vtkm::cont::DataSet& ReadDataSet() - { - try - { - LoadFile(); - } - catch (std::ifstream::failure& e) - { - std::string message("IO Error: "); - throw vtkm::io::ErrorIO(message + e.what()); - } - return this->DataSet; - } - -private: - using DataFormat = enum { ByteData, ShortData, IntegerData, FloatData, DoubleData }; - - void LoadFile() - { - if (this->Loaded) - return; - - std::ifstream stream(this->FileName); - if (stream.fail()) - throw vtkm::io::ErrorIO("Failed to open file: " + this->FileName); - - DataFormat dataFormat = ByteData; - std::string bovFile, line, token, options, variableName; - vtkm::Id numComponents = 1; - vtkm::Id3 dim; - vtkm::Vec3f origin(0, 0, 0); - vtkm::Vec3f spacing(1, 1, 1); - bool spacingSet = false; - - while (stream.good()) - { - std::getline(stream, line); - if (line.size() == 0 || line[0] == '#') - continue; - //std::cout<<"::"<> bovFile >> std::ws; - } - else if (token.find("DATA") != std::string::npos && token.find("SIZE") != std::string::npos) - { - strStream >> dim[0] >> dim[1] >> dim[2] >> std::ws; - } - else if (token.find("BRICK") != std::string::npos && - token.find("ORIGIN") != std::string::npos) - { - strStream >> origin[0] >> origin[1] >> origin[2] >> std::ws; - } - - //DRP - else if (token.find("BRICK") != std::string::npos && token.find("SIZE") != std::string::npos) - { - strStream >> spacing[0] >> spacing[1] >> spacing[2] >> std::ws; - spacingSet = true; - } - else if (token.find("DATA") != std::string::npos && token.find("FORMAT") != std::string::npos) - { - std::string opt; - strStream >> opt >> std::ws; - if (opt.find("FLOAT") != std::string::npos || opt.find("REAL") != std::string::npos) - dataFormat = FloatData; - else if (opt.find("DOUBLE") != std::string::npos) - dataFormat = DoubleData; - else - throw vtkm::io::ErrorIO("Unsupported data type: " + token); - } - else if (token.find("DATA") != std::string::npos && - token.find("COMPONENTS") != std::string::npos) - { - strStream >> numComponents >> std::ws; - if (numComponents != 1 && numComponents != 3) - throw vtkm::io::ErrorIO("Unsupported number of components"); - } - else if (token.find("VARIABLE") != std::string::npos && - token.find("PALETTE") == std::string::npos) - { - strStream >> variableName >> std::ws; - if (variableName[0] == '"') - variableName = variableName.substr(1, variableName.size() - 2); - } - /* - else - std::cerr<<"Unsupported BOV option: "<(dim[0] - 1); - spacing[1] = (spacing[1]) / static_cast(dim[1] - 1); - spacing[2] = (spacing[2]) / static_cast(dim[2] - 1); - } - - std::string fullPathDataFile; - std::size_t pos = FileName.rfind("/"); - if (pos != std::string::npos) - { - std::string baseDir; - baseDir = this->FileName.substr(0, pos); - fullPathDataFile = baseDir + "/" + bovFile; - } - else - fullPathDataFile = bovFile; - - /* - //Get whole path for data file. - std::string fullPathDataFile; - if (bovFile[0] == '/') - fullPathDataFile = bovFile; - else - { - //Get base dir. - std::string baseDir, baseFile; - std::cout<FileName.substr(0, pos); - std::cout<<"BASE: "<DataSet = dataSetBuilder.Create(dim, origin, spacing); - - vtkm::Id numTuples = dim[0] * dim[1] * dim[2]; - if (numComponents == 1) - { - if (dataFormat == FloatData) - { - vtkm::cont::ArrayHandle var; - ReadScalar(fullPathDataFile, numTuples, var); - dsf.AddPointField(this->DataSet, variableName, var); - } - else if (dataFormat == DoubleData) - { - vtkm::cont::ArrayHandle var; - ReadScalar(fullPathDataFile, numTuples, var); - dsf.AddPointField(this->DataSet, variableName, var); - } - } - else if (numComponents == 3) - { - if (dataFormat == FloatData) - { - vtkm::cont::ArrayHandle var; - ReadVector(fullPathDataFile, numTuples, var); - dsf.AddPointField(this->DataSet, variableName, var); - } - else if (dataFormat == DoubleData) - { - vtkm::cont::ArrayHandle var; - ReadVector(fullPathDataFile, numTuples, var); - dsf.AddPointField(this->DataSet, variableName, var); - } - } - - this->Loaded = true; - } - - template - void ReadBuffer(const std::string& fName, const vtkm::Id& sz, std::vector& buff) - { - FILE* fp = fopen(fName.c_str(), "rb"); - size_t readSize = static_cast(sz); - if (fp == nullptr) - throw vtkm::io::ErrorIO("Unable to open data file: " + fName); - buff.resize(readSize); - size_t nread = fread(&buff[0], sizeof(T), readSize, fp); - if (nread != readSize) - throw vtkm::io::ErrorIO("Data file read failed: " + fName); - fclose(fp); - } - - template - void ReadScalar(const std::string& fName, - const vtkm::Id& nTuples, - vtkm::cont::ArrayHandle& var) - { - std::vector buff; - ReadBuffer(fName, nTuples, buff); - var.Allocate(nTuples); - for (vtkm::Id i = 0; i < nTuples; i++) - var.WritePortal().Set(i, buff[(size_t)i]); - } - - template - void ReadVector(const std::string& fName, - const vtkm::Id& nTuples, - vtkm::cont::ArrayHandle>& var) - { - std::vector buff; - ReadBuffer(fName, nTuples * 3, buff); - - var.Allocate(nTuples); - vtkm::Vec v; - for (vtkm::Id i = 0; i < nTuples; i++) - { - v[0] = buff[static_cast(i * 3 + 0)]; - v[1] = buff[static_cast(i * 3 + 1)]; - v[2] = buff[static_cast(i * 3 + 2)]; - var.WritePortal().Set(i, v); - } - } - - std::string FileName; - bool Loaded; - vtkm::cont::DataSet DataSet; }; } } diff --git a/vtkm/io/reader/CMakeLists.txt b/vtkm/io/reader/CMakeLists.txt index 79de09292..25047e830 100644 --- a/vtkm/io/reader/CMakeLists.txt +++ b/vtkm/io/reader/CMakeLists.txt @@ -10,15 +10,7 @@ set(headers BOVDataSetReader.h - VTKDataSetReaderBase.h - VTKPolyDataReader.h - VTKStructuredGridReader.h - VTKRectilinearGridReader.h - VTKStructuredPointsReader.h - VTKUnstructuredGridReader.h VTKDataSetReader.h ) vtkm_declare_headers(${headers}) - -add_subdirectory(testing) diff --git a/vtkm/io/reader/VTKDataSetReader.h b/vtkm/io/reader/VTKDataSetReader.h index a798b0b06..b14671a54 100644 --- a/vtkm/io/reader/VTKDataSetReader.h +++ b/vtkm/io/reader/VTKDataSetReader.h @@ -10,14 +10,8 @@ #ifndef vtk_m_io_reader_VTKDataSetReader_h #define vtk_m_io_reader_VTKDataSetReader_h -#include -#include -#include -#include -#include -#include - -#include +#include +#include namespace vtkm { @@ -26,78 +20,20 @@ namespace io namespace reader { -VTKM_SILENCE_WEAK_VTABLE_WARNING_START - -class VTKDataSetReader : public VTKDataSetReaderBase +class VTKM_DEPRECATED(1.6, "Please use vtkm::io::VTKDataSetReader") VTKDataSetReader + : public io::VTKDataSetReader { public: explicit VTKDataSetReader(const char* fileName) - : VTKDataSetReaderBase(fileName) + : io::VTKDataSetReader(fileName) { } explicit VTKDataSetReader(const std::string& fileName) - : VTKDataSetReaderBase(fileName) + : io::VTKDataSetReader(fileName) { } - - virtual void PrintSummary(std::ostream& out) const - { - if (this->Reader) - { - this->Reader->PrintSummary(out); - } - else - { - VTKDataSetReaderBase::PrintSummary(out); - } - } - -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(); - } - - std::unique_ptr Reader; }; - -VTKM_SILENCE_WEAK_VTABLE_WARNING_END } } } // vtkm::io::reader diff --git a/vtkm/io/reader/testing/CMakeLists.txt b/vtkm/io/reader/testing/CMakeLists.txt deleted file mode 100644 index d2f86da39..000000000 --- a/vtkm/io/reader/testing/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -##============================================================================ -## 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. -##============================================================================ - -set(unit_tests - UnitTestVTKDataSetReader.cxx -) - -vtkm_unit_tests(SOURCES ${unit_tests} ALL_BACKENDS) diff --git a/vtkm/io/testing/CMakeLists.txt b/vtkm/io/testing/CMakeLists.txt index 589c0738b..39c832efe 100644 --- a/vtkm/io/testing/CMakeLists.txt +++ b/vtkm/io/testing/CMakeLists.txt @@ -9,6 +9,7 @@ ##============================================================================ set(unit_tests + UnitTestVTKDataSetReader.cxx UnitTestVTKDataSetWriter.cxx ) diff --git a/vtkm/io/reader/testing/UnitTestVTKDataSetReader.cxx b/vtkm/io/testing/UnitTestVTKDataSetReader.cxx similarity index 100% rename from vtkm/io/reader/testing/UnitTestVTKDataSetReader.cxx rename to vtkm/io/testing/UnitTestVTKDataSetReader.cxx