mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Merge topic 'deprecate_reader'
9a68931c0 Do not add half-baked 1.6 release notes; let Robert consolidate release notes. 01b61be46 Start release notes for 1.6 697369fc1 Remove deprecation warnings throughout the project. d610176ab First commit demos backwards compatibility and printing of warnings. Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !2067
This commit is contained in:
commit
becb289694
@ -157,7 +157,7 @@ Marching Cubes algorithm on it, and render the results to an image:
|
||||
#include <vtkm/Range.h>
|
||||
#include <vtkm/cont/ColorTable.h>
|
||||
#include <vtkm/filter/Contour.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/rendering/Actor.h>
|
||||
#include <vtkm/rendering/Camera.h>
|
||||
#include <vtkm/rendering/CanvasRayTracer.h>
|
||||
@ -166,7 +166,7 @@ Marching Cubes algorithm on it, and render the results to an image:
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
|
||||
vtkm::io::reader::VTKDataSetReader reader("path/to/vtk_image_file");
|
||||
vtkm::io::VTKDataSetReader reader("path/to/vtk_image_file.vtk");
|
||||
vtkm::cont::DataSet inputData = reader.ReadDataSet();
|
||||
std::string fieldName = "scalars";
|
||||
|
||||
|
@ -44,7 +44,7 @@
|
||||
#include <vtkm/filter/WarpScalar.h>
|
||||
#include <vtkm/filter/WarpVector.h>
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
|
||||
#include <vtkm/source/Wavelet.h>
|
||||
#include <vtkm/worklet/DispatcherMapField.h>
|
||||
@ -1005,7 +1005,7 @@ void InitDataSet(int& argc, char** argv)
|
||||
if (!filename.empty())
|
||||
{
|
||||
std::cerr << "[InitDataSet] Loading file: " << filename << "\n";
|
||||
vtkm::io::reader::VTKDataSetReader reader(filename);
|
||||
vtkm::io::VTKDataSetReader reader(filename);
|
||||
InputDataSet = reader.ReadDataSet();
|
||||
}
|
||||
else
|
||||
|
7
docs/changelog/io_reorganize.md
Normal file
7
docs/changelog/io_reorganize.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Reorganization of `io` directory
|
||||
|
||||
The `vtkm/io` directory has been flattened.
|
||||
Namely, the files in `vtkm/io/reader` and `vtkm/io/writer` have been moved up into `vtkm/io`,
|
||||
with the associated changes in namespaces.
|
||||
|
||||
In addition, `vtkm/cont/EncodePNG.h` and `vtkm/cont/DecodePNG.h` have been moved to a more natural home in `vtkm/io`.
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/filter/ClipWithField.h>
|
||||
|
||||
@ -26,7 +26,7 @@ int main(int argc, char* argv[])
|
||||
clipFilter.SetClipValue(20.0);
|
||||
vtkm::cont::DataSet output = clipFilter.Execute(input);
|
||||
|
||||
vtkm::io::writer::VTKDataSetWriter writer("out_data.vtk");
|
||||
vtkm::io::VTKDataSetWriter writer("out_data.vtk");
|
||||
writer.WriteDataSet(output);
|
||||
|
||||
return 0;
|
||||
|
@ -11,8 +11,8 @@
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/worklet/CosmoTools.h>
|
||||
|
||||
|
@ -11,8 +11,8 @@
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/worklet/CosmoTools.h>
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <vtkm/filter/CreateResult.h>
|
||||
#include <vtkm/filter/FilterField.h>
|
||||
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
|
||||
@ -90,7 +90,7 @@ int main(int argc, char** argv)
|
||||
helloField.SetActiveField("point_vectors");
|
||||
vtkm::cont::DataSet outputData = helloField.Execute(inputData);
|
||||
|
||||
vtkm::io::writer::VTKDataSetWriter writer("out_data.vtk");
|
||||
vtkm::io::VTKDataSetWriter writer("out_data.vtk");
|
||||
writer.WriteDataSet(outputData);
|
||||
|
||||
return 0;
|
||||
|
@ -20,8 +20,8 @@
|
||||
#include <vtkm/cont/DataSetFieldAdd.h>
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/filter/LagrangianStructures.h>
|
||||
|
||||
@ -38,7 +38,7 @@ int main(int argc, char** argv)
|
||||
|
||||
std::cout << "Reading input dataset" << std::endl;
|
||||
vtkm::cont::DataSet input;
|
||||
vtkm::io::reader::VTKDataSetReader reader(datasetName);
|
||||
vtkm::io::VTKDataSetReader reader(datasetName);
|
||||
input = reader.ReadDataSet();
|
||||
std::cout << "Read input dataset" << std::endl;
|
||||
|
||||
@ -50,7 +50,7 @@ int main(int argc, char** argv)
|
||||
lcsFilter.SetActiveField(variableName);
|
||||
|
||||
vtkm::cont::DataSet output = lcsFilter.Execute(input);
|
||||
vtkm::io::writer::VTKDataSetWriter writer("out.vtk");
|
||||
vtkm::io::VTKDataSetWriter writer("out.vtk");
|
||||
writer.WriteDataSet(output);
|
||||
std::cout << "Written output dataset" << std::endl;
|
||||
|
||||
|
@ -24,8 +24,8 @@
|
||||
#include <vtkm/cont/DataSetBuilderExplicit.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/filter/MeshQuality.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
|
||||
/**
|
||||
@ -206,7 +206,7 @@ int TestMetrics(const char* outFileName,
|
||||
vtkm::cont::DataSet outputData;
|
||||
try
|
||||
{
|
||||
vtkm::io::writer::VTKDataSetWriter writer("testZoo_withPolygons.vtk");
|
||||
vtkm::io::VTKDataSetWriter writer("testZoo_withPolygons.vtk");
|
||||
writer.WriteDataSet(data);
|
||||
|
||||
outputData = filter.Execute(data);
|
||||
@ -220,7 +220,7 @@ int TestMetrics(const char* outFileName,
|
||||
}
|
||||
try
|
||||
{
|
||||
vtkm::io::writer::VTKDataSetWriter writer(outFileName);
|
||||
vtkm::io::VTKDataSetWriter writer(outFileName);
|
||||
writer.WriteDataSet(outputData);
|
||||
std::cout << "finished writing data\n";
|
||||
}
|
||||
@ -253,7 +253,7 @@ int main(int argc, char* argv[])
|
||||
break;
|
||||
}
|
||||
vtkm::cont::DataSet input;
|
||||
vtkm::io::reader::VTKDataSetReader reader(argv[1]);
|
||||
vtkm::io::VTKDataSetReader reader(argv[1]);
|
||||
|
||||
|
||||
// A cell metric is now computed for every shape type that exists in the
|
||||
|
@ -11,8 +11,8 @@
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
#include <vtkm/filter/Streamline.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
// Example computing streamlines.
|
||||
// An example vector field is available in the vtk-m data directory: magField.vtk
|
||||
@ -46,7 +46,7 @@ int main(int argc, char** argv)
|
||||
|
||||
if (dataFile.find(".vtk") != std::string::npos)
|
||||
{
|
||||
vtkm::io::reader::VTKDataSetReader rdr(dataFile);
|
||||
vtkm::io::VTKDataSetReader rdr(dataFile);
|
||||
ds = rdr.ReadDataSet();
|
||||
}
|
||||
else
|
||||
@ -83,7 +83,7 @@ int main(int argc, char** argv)
|
||||
streamline.SetActiveField(varName);
|
||||
auto output = streamline.Execute(ds);
|
||||
|
||||
vtkm::io::writer::VTKDataSetWriter wrt(outputFile);
|
||||
vtkm::io::VTKDataSetWriter wrt(outputFile);
|
||||
wrt.WriteDataSet(output);
|
||||
|
||||
return 0;
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <complex>
|
||||
#include <vtkm/cont/DataSetBuilderExplicit.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
#include <vtkm/worklet/Tube.h>
|
||||
|
||||
#include <vtkm/cont/ColorTable.h>
|
||||
|
@ -12,8 +12,8 @@
|
||||
#include <vtkm/cont/EnvironmentTracker.h>
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/thirdparty/diy/diy.h>
|
||||
|
||||
@ -44,7 +44,7 @@ int main(int argc, char* argv[])
|
||||
vtkm::cont::DataSet input;
|
||||
if (comm.rank() == 0)
|
||||
{
|
||||
vtkm::io::reader::VTKDataSetReader reader(argv[1]);
|
||||
vtkm::io::VTKDataSetReader reader(argv[1]);
|
||||
input = reader.ReadDataSet();
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ int main(int argc, char* argv[])
|
||||
std::ostringstream str;
|
||||
str << argv[2] << "-" << comm.rank() << ".vtk";
|
||||
|
||||
vtkm::io::writer::VTKDataSetWriter writer(str.str());
|
||||
vtkm::io::VTKDataSetWriter writer(str.str());
|
||||
writer.WriteDataSet(output);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -18,8 +18,8 @@
|
||||
|
||||
#include <vtkm/filter/Pathline.h>
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
@ -63,10 +63,10 @@ int main(int argc, char** argv)
|
||||
stepSize = static_cast<vtkm::Float32>(atof(argv[7]));
|
||||
outputName = std::string(argv[8]);
|
||||
|
||||
vtkm::io::reader::VTKDataSetReader reader1(datasetName1);
|
||||
vtkm::io::VTKDataSetReader reader1(datasetName1);
|
||||
vtkm::cont::DataSet ds1 = reader1.ReadDataSet();
|
||||
|
||||
vtkm::io::reader::VTKDataSetReader reader2(datasetName2);
|
||||
vtkm::io::VTKDataSetReader reader2(datasetName2);
|
||||
vtkm::cont::DataSet ds2 = reader2.ReadDataSet();
|
||||
|
||||
// Use the coordinate system as seeds for performing advection
|
||||
@ -109,7 +109,7 @@ int main(int argc, char** argv)
|
||||
// The way to verify if the code produces correct streamlines
|
||||
// is to do a visual test by using VisIt/ParaView to visualize
|
||||
// the file written by this method.
|
||||
vtkm::io::writer::VTKDataSetWriter writer(outputName);
|
||||
vtkm::io::VTKDataSetWriter writer(outputName);
|
||||
writer.WriteDataSet(output);
|
||||
return 0;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/filter/Tetrahedralize.h>
|
||||
|
||||
@ -25,7 +25,7 @@ int main(int argc, char* argv[])
|
||||
vtkm::filter::Tetrahedralize tetrahedralizeFilter;
|
||||
vtkm::cont::DataSet output = tetrahedralizeFilter.Execute(input);
|
||||
|
||||
vtkm::io::writer::VTKDataSetWriter writer("out_tets.vtk");
|
||||
vtkm::io::VTKDataSetWriter writer("out_tets.vtk");
|
||||
writer.WriteDataSet(output);
|
||||
|
||||
return 0;
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
#include <vtkm/io/VTKDataSetWriter.h>
|
||||
|
||||
#include <vtkm/filter/Triangulate.h>
|
||||
|
||||
@ -24,7 +24,7 @@ int main(int argc, char* argv[])
|
||||
vtkm::filter::Triangulate triangulateFilter;
|
||||
vtkm::cont::DataSet output = triangulateFilter.Execute(input);
|
||||
|
||||
vtkm::io::writer::VTKDataSetWriter writer("out_tris.vtk");
|
||||
vtkm::io::VTKDataSetWriter writer("out_tris.vtk");
|
||||
writer.WriteDataSet(output);
|
||||
|
||||
return 0;
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/filter/MeshQuality.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
|
||||
//Adapted from vtkm/cont/testing/MakeTestDataSet.h
|
||||
//Modified the content of the MakeExplicitDataSetZoo() function
|
||||
|
248
vtkm/io/BOVDataSetReader.h
Normal file
248
vtkm/io/BOVDataSetReader.h
Normal file
@ -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 <fstream>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/DataSetBuilderUniform.h>
|
||||
#include <vtkm/cont/DataSetFieldAdd.h>
|
||||
#include <vtkm/io/ErrorIO.h>
|
||||
|
||||
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<<"::"<<line<<"::"<<std::endl;
|
||||
std::size_t pos = line.find(":");
|
||||
if (pos == std::string::npos)
|
||||
throw vtkm::io::ErrorIO("Unsupported option: " + line);
|
||||
token = line.substr(0, pos);
|
||||
options = line.substr(pos + 1, line.size() - 1);
|
||||
//std::cout<<token<<"::"<<options<<std::endl;
|
||||
|
||||
std::stringstream strStream(options);
|
||||
|
||||
//Format supports both space and "_" separated tokens...
|
||||
if (token.find("DATA") != std::string::npos && token.find("FILE") != std::string::npos)
|
||||
{
|
||||
strStream >> 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<vtkm::FloatDefault>(dim[0] - 1);
|
||||
spacing[1] = (spacing[1]) / static_cast<vtkm::FloatDefault>(dim[1] - 1);
|
||||
spacing[2] = (spacing[2]) / static_cast<vtkm::FloatDefault>(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<vtkm::Float32> var;
|
||||
ReadScalar(fullPathDataFile, numTuples, var);
|
||||
dsf.AddPointField(this->DataSet, variableName, var);
|
||||
}
|
||||
else if (dataFormat == DoubleData)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Float64> var;
|
||||
ReadScalar(fullPathDataFile, numTuples, var);
|
||||
dsf.AddPointField(this->DataSet, variableName, var);
|
||||
}
|
||||
}
|
||||
else if (numComponents == 3)
|
||||
{
|
||||
if (dataFormat == FloatData)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3f_32> var;
|
||||
ReadVector(fullPathDataFile, numTuples, var);
|
||||
dsf.AddPointField(this->DataSet, variableName, var);
|
||||
}
|
||||
else if (dataFormat == DoubleData)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3f_64> var;
|
||||
ReadVector(fullPathDataFile, numTuples, var);
|
||||
dsf.AddPointField(this->DataSet, variableName, var);
|
||||
}
|
||||
}
|
||||
|
||||
this->Loaded = true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void ReadBuffer(const std::string& fName, const vtkm::Id& sz, std::vector<T>& buff)
|
||||
{
|
||||
FILE* fp = fopen(fName.c_str(), "rb");
|
||||
size_t readSize = static_cast<size_t>(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 <typename T>
|
||||
void ReadScalar(const std::string& fName,
|
||||
const vtkm::Id& nTuples,
|
||||
vtkm::cont::ArrayHandle<T>& var)
|
||||
{
|
||||
std::vector<T> 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 <typename T>
|
||||
void ReadVector(const std::string& fName,
|
||||
const vtkm::Id& nTuples,
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& var)
|
||||
{
|
||||
std::vector<T> buff;
|
||||
ReadBuffer(fName, nTuples * 3, buff);
|
||||
|
||||
var.Allocate(nTuples);
|
||||
vtkm::Vec<T, 3> v;
|
||||
for (vtkm::Id i = 0; i < nTuples; i++)
|
||||
{
|
||||
v[0] = buff[static_cast<size_t>(i * 3 + 0)];
|
||||
v[1] = buff[static_cast<size_t>(i * 3 + 1)];
|
||||
v[2] = buff[static_cast<size_t>(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
|
@ -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
|
||||
)
|
||||
|
||||
|
100
vtkm/io/VTKDataSetReader.h
Normal file
100
vtkm/io/VTKDataSetReader.h
Normal file
@ -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 <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
|
||||
{
|
||||
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<VTKDataSetReaderBase> Reader;
|
||||
};
|
||||
}
|
||||
} // vtkm::io
|
||||
|
||||
#endif // vtk_m_io_VTKReader_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 <vtkm/io/internal/Endian.h>
|
||||
#include <vtkm/io/internal/VTKDataSetCells.h>
|
||||
@ -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
|
@ -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 <vtkm/io/reader/VTKDataSetReaderBase.h>
|
||||
#include <vtkm/io/VTKDataSetReaderBase.h>
|
||||
|
||||
#include <vtkm/cont/ArrayPortalToIterators.h>
|
||||
|
||||
@ -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
|
@ -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 <vtkm/io/reader/VTKDataSetReaderBase.h>
|
||||
#include <vtkm/io/VTKDataSetReaderBase.h>
|
||||
|
||||
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
|
@ -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 <vtkm/io/reader/VTKDataSetReaderBase.h>
|
||||
#include <vtkm/io/VTKDataSetReaderBase.h>
|
||||
|
||||
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
|
@ -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 <vtkm/io/reader/VTKDataSetReaderBase.h>
|
||||
#include <vtkm/io/VTKDataSetReaderBase.h>
|
||||
|
||||
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
|
@ -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 <vtkm/io/reader/VTKDataSetReaderBase.h>
|
||||
#include <vtkm/io/VTKDataSetReaderBase.h>
|
||||
|
||||
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
|
@ -10,11 +10,8 @@
|
||||
#ifndef vtk_m_io_reader_BOVDataSetReader_h
|
||||
#define vtk_m_io_reader_BOVDataSetReader_h
|
||||
|
||||
#include <fstream>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/DataSetBuilderUniform.h>
|
||||
#include <vtkm/cont/DataSetFieldAdd.h>
|
||||
#include <vtkm/io/ErrorIO.h>
|
||||
#include <vtkm/Deprecated.h>
|
||||
#include <vtkm/io/BOVDataSetReader.h>
|
||||
|
||||
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<<"::"<<line<<"::"<<std::endl;
|
||||
std::size_t pos = line.find(":");
|
||||
if (pos == std::string::npos)
|
||||
throw vtkm::io::ErrorIO("Unsupported option: " + line);
|
||||
token = line.substr(0, pos);
|
||||
options = line.substr(pos + 1, line.size() - 1);
|
||||
//std::cout<<token<<"::"<<options<<std::endl;
|
||||
|
||||
std::stringstream strStream(options);
|
||||
|
||||
//Format supports both space and "_" separated tokens...
|
||||
if (token.find("DATA") != std::string::npos && token.find("FILE") != std::string::npos)
|
||||
{
|
||||
strStream >> 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: "<<token<<std::endl;
|
||||
*/
|
||||
}
|
||||
|
||||
if (spacingSet)
|
||||
{
|
||||
spacing[0] = (spacing[0]) / static_cast<vtkm::FloatDefault>(dim[0] - 1);
|
||||
spacing[1] = (spacing[1]) / static_cast<vtkm::FloatDefault>(dim[1] - 1);
|
||||
spacing[2] = (spacing[2]) / static_cast<vtkm::FloatDefault>(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<<std::endl;
|
||||
std::size_t pos = FileName.rfind("/");
|
||||
if (pos != std::string::npos)
|
||||
baseDir = this->FileName.substr(0, pos);
|
||||
std::cout<<"BASE: "<<baseDir<<std::endl;
|
||||
|
||||
if (bovFile.substr(0,2) == "./")
|
||||
{
|
||||
baseFile = bovFile.substr(2, bovFile.size()-2);
|
||||
}
|
||||
if (baseDir.size() == 0)
|
||||
fullPathDataFile = baseFile;
|
||||
else
|
||||
fullPathDataFile = baseDir + "/" + baseFile;
|
||||
std::cout<<baseDir<<" : "<<baseFile<<std::endl;
|
||||
std::cout<<fullPathDataFile<<std::endl;
|
||||
}
|
||||
*/
|
||||
|
||||
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<vtkm::Float32> var;
|
||||
ReadScalar(fullPathDataFile, numTuples, var);
|
||||
dsf.AddPointField(this->DataSet, variableName, var);
|
||||
}
|
||||
else if (dataFormat == DoubleData)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Float64> var;
|
||||
ReadScalar(fullPathDataFile, numTuples, var);
|
||||
dsf.AddPointField(this->DataSet, variableName, var);
|
||||
}
|
||||
}
|
||||
else if (numComponents == 3)
|
||||
{
|
||||
if (dataFormat == FloatData)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3f_32> var;
|
||||
ReadVector(fullPathDataFile, numTuples, var);
|
||||
dsf.AddPointField(this->DataSet, variableName, var);
|
||||
}
|
||||
else if (dataFormat == DoubleData)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3f_64> var;
|
||||
ReadVector(fullPathDataFile, numTuples, var);
|
||||
dsf.AddPointField(this->DataSet, variableName, var);
|
||||
}
|
||||
}
|
||||
|
||||
this->Loaded = true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void ReadBuffer(const std::string& fName, const vtkm::Id& sz, std::vector<T>& buff)
|
||||
{
|
||||
FILE* fp = fopen(fName.c_str(), "rb");
|
||||
size_t readSize = static_cast<size_t>(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 <typename T>
|
||||
void ReadScalar(const std::string& fName,
|
||||
const vtkm::Id& nTuples,
|
||||
vtkm::cont::ArrayHandle<T>& var)
|
||||
{
|
||||
std::vector<T> 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 <typename T>
|
||||
void ReadVector(const std::string& fName,
|
||||
const vtkm::Id& nTuples,
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& var)
|
||||
{
|
||||
std::vector<T> buff;
|
||||
ReadBuffer(fName, nTuples * 3, buff);
|
||||
|
||||
var.Allocate(nTuples);
|
||||
vtkm::Vec<T, 3> v;
|
||||
for (vtkm::Id i = 0; i < nTuples; i++)
|
||||
{
|
||||
v[0] = buff[static_cast<size_t>(i * 3 + 0)];
|
||||
v[1] = buff[static_cast<size_t>(i * 3 + 1)];
|
||||
v[2] = buff[static_cast<size_t>(i * 3 + 2)];
|
||||
var.WritePortal().Set(i, v);
|
||||
}
|
||||
}
|
||||
|
||||
std::string FileName;
|
||||
bool Loaded;
|
||||
vtkm::cont::DataSet DataSet;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -10,14 +10,8 @@
|
||||
#ifndef vtk_m_io_reader_VTKDataSetReader_h
|
||||
#define vtk_m_io_reader_VTKDataSetReader_h
|
||||
|
||||
#include <vtkm/io/reader/VTKDataSetReaderBase.h>
|
||||
#include <vtkm/io/reader/VTKPolyDataReader.h>
|
||||
#include <vtkm/io/reader/VTKRectilinearGridReader.h>
|
||||
#include <vtkm/io/reader/VTKStructuredGridReader.h>
|
||||
#include <vtkm/io/reader/VTKStructuredPointsReader.h>
|
||||
#include <vtkm/io/reader/VTKUnstructuredGridReader.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vtkm/Deprecated.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
|
||||
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<VTKDataSetReaderBase> Reader;
|
||||
};
|
||||
|
||||
VTKM_SILENCE_WEAK_VTABLE_WARNING_END
|
||||
}
|
||||
}
|
||||
} // vtkm::io::reader
|
||||
|
@ -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)
|
@ -9,6 +9,7 @@
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestVTKDataSetReader.cxx
|
||||
UnitTestVTKDataSetWriter.cxx
|
||||
)
|
||||
|
||||
|
4
vtkm/io/reader/testing/UnitTestVTKDataSetReader.cxx → vtkm/io/testing/UnitTestVTKDataSetReader.cxx
4
vtkm/io/reader/testing/UnitTestVTKDataSetReader.cxx → vtkm/io/testing/UnitTestVTKDataSetReader.cxx
@ -9,7 +9,7 @@
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -401,7 +401,7 @@ inline void createFile(const char* buffer, std::size_t size, const char* fname)
|
||||
inline vtkm::cont::DataSet readVTKDataSet(const char* fname)
|
||||
{
|
||||
vtkm::cont::DataSet ds;
|
||||
vtkm::io::reader::VTKDataSetReader reader(fname);
|
||||
vtkm::io::VTKDataSetReader reader(fname);
|
||||
try
|
||||
{
|
||||
ds = reader.ReadDataSet();
|
@ -11,7 +11,7 @@
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
#include <vtkm/rendering/Actor.h>
|
||||
#include <vtkm/rendering/Canvas.h>
|
||||
#include <vtkm/rendering/CanvasRayTracer.h>
|
||||
@ -38,7 +38,7 @@ void RenderTests()
|
||||
vtkm::cont::DataSet rectDS, unsDS;
|
||||
std::string basePath = vtkm::cont::testing::Testing::GetTestDataBasePath();
|
||||
std::string rectfname = basePath + "/rectilinear/noise.vtk";
|
||||
vtkm::io::reader::VTKDataSetReader rectReader(rectfname);
|
||||
vtkm::io::VTKDataSetReader rectReader(rectfname);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
#include <vtkm/exec/CellInterpolate.h>
|
||||
#include <vtkm/exec/ParametricCoordinates.h>
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/VTKDataSetReader.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user