Add VisIt file reader.

This commit is contained in:
Dave Pugmire 2023-03-13 16:13:21 -04:00
parent 1037b80bb5
commit f60f437000
6 changed files with 204 additions and 0 deletions

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:62accba30cde47cac6980dbec18c6edc08e48f353da8f0817a810e66631cb89e
size 38

@ -30,6 +30,7 @@ set(headers
VTKStructuredGridReader.h
VTKStructuredPointsReader.h
VTKUnstructuredGridReader.h
VTKVisItFileReader.h
)
set(template_sources
@ -57,6 +58,7 @@ set(sources
VTKStructuredGridReader.cxx
VTKStructuredPointsReader.cxx
VTKUnstructuredGridReader.cxx
VTKVisItFileReader.cxx
)
if (VTKm_ENABLE_HDF5_IO)

@ -0,0 +1,99 @@
//============================================================================
// 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 <algorithm>
#include <fstream>
#include <vtkm/io/ErrorIO.h>
#include <vtkm/io/VTKDataSetReader.h>
#include <vtkm/io/VTKVisItFileReader.h>
namespace vtkm
{
namespace io
{
VTKVisItFileReader::VTKVisItFileReader(const char* fileName)
: FileName(fileName)
{
}
VTKVisItFileReader::VTKVisItFileReader(const std::string& fileName)
: FileName(fileName)
{
}
vtkm::cont::PartitionedDataSet VTKVisItFileReader::ReadPartitionedDataSet()
{
//Get the base path of the input file.
std::string baseDirPath = ".";
baseDirPath = "../vtk-m/data/data/uniform";
//Get the base dir name
auto pos = this->FileName.rfind("/");
if (pos != std::string::npos)
baseDirPath = baseDirPath.substr(0, pos);
//Open up the file of filenames.
std::ifstream stream(this->FileName);
if (stream.fail())
throw vtkm::io::ErrorIO("Failed to open file: " + this->FileName);
int numBlocks = -1;
std::string line;
std::vector<std::string> fileNames;
while (stream.good())
{
std::getline(stream, line);
if (line.size() == 0 || line[0] == '#')
continue;
else if (line.find("!NBLOCKS") != std::string::npos)
{
if (numBlocks > 0)
throw vtkm::io::ErrorIO("Invalid file: " + this->FileName +
". Number of blocks already specified");
numBlocks = std::atoi(line.substr(8, line.size()).c_str());
if (numBlocks <= 0)
throw vtkm::io::ErrorIO("Invalid file: " + this->FileName +
". Number of blocks must be > 0");
}
else if (numBlocks > 0)
{
char char_to_remove = ' ';
line.erase(std::remove(line.begin(), line.end(), char_to_remove), line.end());
if (line.find(".vtk") != std::string::npos)
fileNames.push_back(baseDirPath + "/" + line);
else
std::cerr << "Skipping: " << line << std::endl;
}
else
{
std::cerr << "Skipping line: " << line << std::endl;
}
}
vtkm::cont::PartitionedDataSet pds;
//Read all the files.
for (const auto fn : fileNames)
{
std::ifstream s(fn);
if (s.fail())
throw vtkm::io::ErrorIO("Failed to open file: " + fn);
vtkm::io::VTKDataSetReader reader(fn);
pds.AppendPartition(reader.ReadDataSet());
}
return pds;
}
}
} //vtkm::io

@ -0,0 +1,39 @@
//============================================================================
// 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 vtkm_io_VTKVisItFileReader_h
#define vtkm_io_VTKVisItFileReader_h
#include <string>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/PartitionedDataSet.h>
#include <vtkm/io/vtkm_io_export.h>
namespace vtkm
{
namespace io
{
class VTKM_IO_EXPORT VTKVisItFileReader
{
public:
VTKM_CONT VTKVisItFileReader(const char* fileName);
VTKM_CONT VTKVisItFileReader(const std::string& fileName);
VTKM_CONT vtkm::cont::PartitionedDataSet ReadPartitionedDataSet();
private:
std::string FileName;
};
}
} //vtkm::io
#endif //vtkm_io_VTKVisItFileReader_h

@ -10,6 +10,7 @@
set(unit_tests
UnitTestBOVDataSetReader.cxx
UnitTestVisItFileDataSetReader.cxx
UnitTestFileUtils.cxx
UnitTestPixelTypes.cxx
UnitTestVTKDataSetReader.cxx

@ -0,0 +1,60 @@
//============================================================================
// 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 <string>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/io/ErrorIO.h>
#include <vtkm/io/VTKVisItFileReader.h>
namespace
{
inline vtkm::cont::PartitionedDataSet readVisItFileDataSet(const std::string& fname)
{
vtkm::cont::PartitionedDataSet pds;
vtkm::io::VTKVisItFileReader reader(fname);
try
{
pds = reader.ReadPartitionedDataSet();
}
catch (vtkm::io::ErrorIO& e)
{
std::string message("Error reading ");
message += fname;
message += ", ";
message += e.GetMessage();
VTKM_TEST_FAIL(message.c_str());
}
return pds;
}
} // anonymous namespace
void TestReadingVisItFileDataSet()
{
std::string visItFile = vtkm::cont::testing::Testing::DataPath("uniform/venn250.visit");
auto const& pds = readVisItFileDataSet(visItFile);
VTKM_TEST_ASSERT(pds.GetNumberOfPartitions() == 2, "Incorrect number of partitions");
for (const auto& ds : pds)
{
VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == 63001, "Wrong number of points in partition");
VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 5, "Wrong number of fields in partition");
}
}
int UnitTestVisItFileDataSetReader(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(TestReadingVisItFileDataSet, argc, argv);
}