2016-01-19 14:59:31 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2016-01-19 14:59:31 +00:00
|
|
|
// 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/cont/testing/MakeTestDataSet.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
2022-01-29 20:12:01 +00:00
|
|
|
#include <vtkm/filter/field_conversion/CellAverage.h>
|
2016-01-19 14:59:31 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2016-01-19 14:59:31 +00:00
|
|
|
|
|
|
|
void TestCellAverageRegular3D()
|
|
|
|
{
|
2016-10-23 00:01:42 +00:00
|
|
|
std::cout << "Testing CellAverage Filter on 3D structured data" << std::endl;
|
2016-01-19 14:59:31 +00:00
|
|
|
|
|
|
|
vtkm::cont::testing::MakeTestDataSet testDataSet;
|
|
|
|
vtkm::cont::DataSet dataSet = testDataSet.Make3DUniformDataSet0();
|
|
|
|
|
2022-01-29 20:12:01 +00:00
|
|
|
vtkm::filter::field_conversion::CellAverage cellAverage;
|
2016-10-23 00:01:42 +00:00
|
|
|
cellAverage.SetOutputFieldName("avgvals");
|
2018-03-02 20:49:07 +00:00
|
|
|
cellAverage.SetActiveField("pointvar");
|
|
|
|
vtkm::cont::DataSet result = cellAverage.Execute(dataSet);
|
2016-01-19 14:59:31 +00:00
|
|
|
|
2019-08-13 14:10:52 +00:00
|
|
|
VTKM_TEST_ASSERT(result.HasCellField("avgvals") == true, "Result field not present.");
|
2016-01-19 14:59:31 +00:00
|
|
|
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Float32> resultArrayHandle;
|
2021-01-25 17:36:56 +00:00
|
|
|
result.GetCellField("avgvals").GetData().AsArrayHandle(resultArrayHandle);
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
|
|
|
vtkm::Float32 expected[4] = { 60.1875f, 70.2125f, 120.3375f, 130.3625f };
|
2016-10-23 00:01:42 +00:00
|
|
|
for (vtkm::Id i = 0; i < 4; ++i)
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
2020-01-28 19:14:32 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(resultArrayHandle.ReadPortal().Get(i), expected[i]),
|
2017-05-18 14:29:41 +00:00
|
|
|
"Wrong result for CellAverage worklet on 3D regular data");
|
2016-01-19 14:59:31 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-23 00:01:42 +00:00
|
|
|
|
|
|
|
std::cout << "Run again for point coordinates" << std::endl;
|
|
|
|
cellAverage.SetOutputFieldName("avgpos");
|
2018-03-02 20:49:07 +00:00
|
|
|
cellAverage.SetUseCoordinateSystemAsField(true);
|
|
|
|
result = cellAverage.Execute(dataSet);
|
2016-10-23 00:01:42 +00:00
|
|
|
|
2019-08-13 14:10:52 +00:00
|
|
|
VTKM_TEST_ASSERT(result.HasCellField("avgpos"), "Result field not present.");
|
2016-10-23 00:01:42 +00:00
|
|
|
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec3f> resultPointArray;
|
2019-08-13 14:10:52 +00:00
|
|
|
vtkm::cont::Field resultPointField = result.GetCellField("avgpos");
|
2021-01-25 17:36:56 +00:00
|
|
|
resultPointField.GetData().AsArrayHandle(resultPointArray);
|
2016-10-23 00:01:42 +00:00
|
|
|
{
|
|
|
|
vtkm::FloatDefault expected[4][3] = {
|
2017-05-18 14:29:41 +00:00
|
|
|
{ 0.5f, 0.5f, 0.5f }, { 1.5f, 0.5f, 0.5f }, { 0.5f, 0.5f, 1.5f }, { 1.5f, 0.5f, 1.5f }
|
2016-10-23 00:01:42 +00:00
|
|
|
};
|
|
|
|
for (vtkm::Id i = 0; i < 4; ++i)
|
|
|
|
{
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f expectedVec(expected[i][0], expected[i][1], expected[i][2]);
|
2020-01-28 19:14:32 +00:00
|
|
|
vtkm::Vec3f computedVec(resultPointArray.ReadPortal().Get(i));
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(computedVec, expectedVec),
|
|
|
|
"Wrong result for CellAverage worklet on 3D regular data");
|
2016-10-23 00:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-19 14:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestCellAverageRegular2D()
|
|
|
|
{
|
2018-06-14 20:49:11 +00:00
|
|
|
std::cout << "Testing CellAverage Filter on 2D structured data" << std::endl;
|
2016-01-19 14:59:31 +00:00
|
|
|
|
|
|
|
vtkm::cont::testing::MakeTestDataSet testDataSet;
|
|
|
|
vtkm::cont::DataSet dataSet = testDataSet.Make2DUniformDataSet0();
|
|
|
|
|
2022-01-29 20:12:01 +00:00
|
|
|
vtkm::filter::field_conversion::CellAverage cellAverage;
|
2018-03-02 20:49:07 +00:00
|
|
|
cellAverage.SetActiveField("pointvar");
|
2016-01-19 14:59:31 +00:00
|
|
|
|
2018-03-02 20:49:07 +00:00
|
|
|
vtkm::cont::DataSet result = cellAverage.Execute(dataSet);
|
2016-01-19 14:59:31 +00:00
|
|
|
|
2016-05-05 21:27:32 +00:00
|
|
|
// If no name is given, should have the same name as the input.
|
2019-08-13 14:10:52 +00:00
|
|
|
VTKM_TEST_ASSERT(result.HasPointField("pointvar"), "Field missing.");
|
2018-03-02 20:49:07 +00:00
|
|
|
|
2019-08-13 14:10:52 +00:00
|
|
|
vtkm::cont::Field resultField = result.GetCellField("pointvar");
|
2016-01-19 14:59:31 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Float32> resultArrayHandle;
|
2021-01-25 17:36:56 +00:00
|
|
|
resultField.GetData().AsArrayHandle(resultArrayHandle);
|
2018-03-02 20:49:07 +00:00
|
|
|
vtkm::Float32 expected[2] = { 30.1f, 40.1f };
|
|
|
|
for (int i = 0; i < 2; ++i)
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
2020-01-28 19:14:32 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(resultArrayHandle.ReadPortal().Get(i), expected[i]),
|
2018-03-02 20:49:07 +00:00
|
|
|
"Wrong result for CellAverage worklet on 2D regular data");
|
2016-01-19 14:59:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestCellAverageExplicit()
|
|
|
|
{
|
|
|
|
std::cout << "Testing CellAverage Filter on Explicit data" << std::endl;
|
|
|
|
|
|
|
|
vtkm::cont::testing::MakeTestDataSet testDataSet;
|
|
|
|
vtkm::cont::DataSet dataSet = testDataSet.Make3DExplicitDataSet0();
|
|
|
|
|
2022-01-29 20:12:01 +00:00
|
|
|
vtkm::filter::field_conversion::CellAverage cellAverage;
|
2018-03-02 20:49:07 +00:00
|
|
|
cellAverage.SetActiveField("pointvar");
|
2016-01-19 14:59:31 +00:00
|
|
|
|
2018-03-02 20:49:07 +00:00
|
|
|
vtkm::cont::DataSet result = cellAverage.Execute(dataSet);
|
2016-01-19 14:59:31 +00:00
|
|
|
|
2016-05-05 21:27:32 +00:00
|
|
|
// If no name is given, should have the same name as the input.
|
2019-08-13 14:10:52 +00:00
|
|
|
VTKM_TEST_ASSERT(result.HasCellField("pointvar"), "Field missing.");
|
2016-01-19 14:59:31 +00:00
|
|
|
|
2018-03-02 20:49:07 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Float32> resultArrayHandle;
|
2019-08-13 14:10:52 +00:00
|
|
|
vtkm::cont::Field resultField = result.GetCellField("pointvar");
|
2021-01-25 17:36:56 +00:00
|
|
|
resultField.GetData().AsArrayHandle(resultArrayHandle);
|
2018-03-02 20:49:07 +00:00
|
|
|
vtkm::Float32 expected[2] = { 20.1333f, 35.2f };
|
|
|
|
for (int i = 0; i < 2; ++i)
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
2020-01-28 19:14:32 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(resultArrayHandle.ReadPortal().Get(i), expected[i]),
|
2018-03-02 20:49:07 +00:00
|
|
|
"Wrong result for CellAverage worklet on 3D regular data");
|
2016-01-19 14:59:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestCellAverage()
|
|
|
|
{
|
|
|
|
TestCellAverageRegular2D();
|
|
|
|
TestCellAverageRegular3D();
|
|
|
|
TestCellAverageExplicit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:15:41 +00:00
|
|
|
int UnitTestCellAverageFilter(int argc, char* argv[])
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
2018-12-31 20:15:41 +00:00
|
|
|
return vtkm::cont::testing::Testing::Run(TestCellAverage, argc, argv);
|
2016-01-19 14:59:31 +00:00
|
|
|
}
|