Merge topic 'bov_test'

2fc636c27 Test BOV reader. Fix slow WritePortal().Set(idx, val) loop.

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Robert Maynard <robert.maynard@kitware.com>
Merge-request: !2081
This commit is contained in:
Nick 2020-05-12 20:18:35 +00:00 committed by Kitware Robot
commit 9d9e332b0d
3 changed files with 74 additions and 3 deletions

@ -214,8 +214,9 @@ private:
std::vector<T> buff;
ReadBuffer(fName, nTuples, buff);
var.Allocate(nTuples);
auto writePortal = var.WritePortal();
for (vtkm::Id i = 0; i < nTuples; i++)
var.WritePortal().Set(i, buff[(size_t)i]);
writePortal.Set(i, buff[(size_t)i]);
}
template <typename T>
@ -228,12 +229,13 @@ private:
var.Allocate(nTuples);
vtkm::Vec<T, 3> v;
auto writePortal = var.WritePortal();
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);
writePortal.Set(i, v);
}
}
@ -242,7 +244,6 @@ private:
vtkm::cont::DataSet DataSet;
};
}
}
} // vtkm::io
#endif // vtk_m_io_BOVReader_h

@ -9,6 +9,7 @@
##============================================================================
set(unit_tests
UnitTestBOVDataSetReader.cxx
UnitTestVTKDataSetReader.cxx
UnitTestVTKDataSetWriter.cxx
)

@ -0,0 +1,69 @@
//============================================================================
// 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/BOVDataSetReader.h>
namespace
{
inline vtkm::cont::DataSet readBOVDataSet(const char* fname)
{
vtkm::cont::DataSet ds;
vtkm::io::BOVDataSetReader reader(fname);
try
{
ds = reader.ReadDataSet();
}
catch (vtkm::io::ErrorIO& e)
{
std::string message("Error reading ");
message += fname;
message += ", ";
message += e.GetMessage();
VTKM_TEST_FAIL(message.c_str());
}
return ds;
}
} // anonymous namespace
void TestReadingBOVDataSet()
{
std::string bovFile = vtkm::cont::testing::Testing::GetTestDataBasePath() + "/uniform/noise.bov";
auto const& ds = readBOVDataSet(bovFile.data());
VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 1, "Incorrect number of fields");
// See the .bov file: DATA SIZE: 50 50 50
VTKM_TEST_ASSERT(ds.GetNumberOfPoints() == 50 * 50 * 50, "Incorrect number of points");
VTKM_TEST_ASSERT(ds.GetCellSet().GetNumberOfPoints() == 50 * 50 * 50,
"Incorrect number of points (from cell set)");
VTKM_TEST_ASSERT(ds.GetNumberOfCells() == 49 * 49 * 49, "Incorrect number of cells");
// See the .bov file: VARIABLE: "var"
VTKM_TEST_ASSERT(ds.HasField("var"), "Should have field 'var', but does not.");
VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 1, "There is only one field in noise.bov");
VTKM_TEST_ASSERT(ds.GetNumberOfCoordinateSystems() == 1,
"There is only one coordinate system in noise.bov");
auto const& field = ds.GetField("var");
// I'm pretty sure that all .bov files have their fields associated with points . . .
VTKM_TEST_ASSERT(field.GetAssociation() == vtkm::cont::Field::Association::POINTS,
"The field should be associated with points.");
}
int UnitTestBOVDataSetReader(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(TestReadingBOVDataSet, argc, argv);
}