vtk-m2/vtkm/worklet/testing/UnitTestCellDeepCopy.cxx

95 lines
3.1 KiB
C++
Raw Normal View History

2016-11-05 03:23:07 +00:00
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
2019-04-15 23:24:21 +00:00
//
2016-11-05 03:23:07 +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/worklet/CellDeepCopy.h>
#include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/CellSetExplicit.h>
#include <vtkm/cont/CellSetPermutation.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
2017-05-18 14:29:41 +00:00
namespace
{
2016-11-05 03:23:07 +00:00
2017-05-18 14:29:41 +00:00
vtkm::cont::CellSetExplicit<> CreateCellSet()
2016-11-05 03:23:07 +00:00
{
vtkm::cont::testing::MakeTestDataSet makeData;
vtkm::cont::DataSet data = makeData.Make3DExplicitDataSet0();
vtkm::cont::CellSetExplicit<> cellSet;
data.GetCellSet().AsCellSet(cellSet);
2016-11-05 03:23:07 +00:00
return cellSet;
}
2017-05-18 14:29:41 +00:00
vtkm::cont::CellSetPermutation<vtkm::cont::CellSetExplicit<>,
vtkm::cont::ArrayHandleCounting<vtkm::Id>>
2016-11-05 03:23:07 +00:00
CreatePermutedCellSet()
{
std::cout << "Creating input cell set" << std::endl;
vtkm::cont::CellSetExplicit<> cellSet = CreateCellSet();
return vtkm::cont::make_CellSetPermutation(
vtkm::cont::ArrayHandleCounting<vtkm::Id>(
cellSet.GetNumberOfCells() - 1, -1, cellSet.GetNumberOfCells()),
2017-05-18 14:29:41 +00:00
cellSet);
2016-11-05 03:23:07 +00:00
}
2017-05-18 14:29:41 +00:00
template <typename CellSetType>
vtkm::cont::CellSetExplicit<> DoCellDeepCopy(const CellSetType& inCells)
2016-11-05 03:23:07 +00:00
{
std::cout << "Doing cell copy" << std::endl;
return vtkm::worklet::CellDeepCopy::Run(inCells);
2016-11-05 03:23:07 +00:00
}
2017-05-18 14:29:41 +00:00
void CheckOutput(const vtkm::cont::CellSetExplicit<>& copiedCells)
2016-11-05 03:23:07 +00:00
{
std::cout << "Checking copied cells" << std::endl;
vtkm::cont::CellSetExplicit<> originalCells = CreateCellSet();
vtkm::Id numberOfCells = copiedCells.GetNumberOfCells();
VTKM_TEST_ASSERT(numberOfCells == originalCells.GetNumberOfCells(),
"Result has wrong number of cells");
// Cells should be copied backward. Check that.
for (vtkm::Id cellIndex = 0; cellIndex < numberOfCells; cellIndex++)
{
vtkm::Id oCellIndex = numberOfCells - cellIndex - 1;
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(copiedCells.GetCellShape(cellIndex) == originalCells.GetCellShape(oCellIndex),
2016-11-05 03:23:07 +00:00
"Bad cell shape");
2017-05-18 14:29:41 +00:00
vtkm::IdComponent numPoints = copiedCells.GetNumberOfPointsInCell(cellIndex);
VTKM_TEST_ASSERT(numPoints == originalCells.GetNumberOfPointsInCell(oCellIndex),
"Bad number of points in cell");
2016-11-05 03:23:07 +00:00
// Only checking 3 points. All cells should have at least 3
vtkm::Id3 cellPoints{ 0 };
2016-11-05 03:23:07 +00:00
copiedCells.GetIndices(cellIndex, cellPoints);
vtkm::Id3 oCellPoints{ 0 };
2016-11-05 03:23:07 +00:00
originalCells.GetIndices(oCellIndex, oCellPoints);
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(cellPoints == oCellPoints, "Point indices not copied correctly");
2016-11-05 03:23:07 +00:00
}
}
void RunTest()
{
2017-05-18 14:29:41 +00:00
vtkm::cont::CellSetExplicit<> cellSet = DoCellDeepCopy(CreatePermutedCellSet());
2016-11-05 03:23:07 +00:00
CheckOutput(cellSet);
}
2017-05-18 14:29:41 +00:00
} // anonymous namespace
2016-11-05 03:23:07 +00:00
int UnitTestCellDeepCopy(int argc, char* argv[])
2016-11-05 03:23:07 +00:00
{
return vtkm::cont::testing::Testing::Run(RunTest, argc, argv);
2016-11-05 03:23:07 +00:00
}