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

85 lines
3.4 KiB
C++
Raw Normal View History

//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
2019-04-15 23:24:21 +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/RemoveUnusedPoints.h>
#include <vtkm/cont/testing/Testing.h>
2017-05-18 14:29:41 +00:00
namespace
{
2017-05-18 14:29:41 +00:00
vtkm::cont::CellSetExplicit<> CreateInputCellSet()
{
2019-08-13 21:28:37 +00:00
vtkm::cont::CellSetExplicit<> cellSet;
cellSet.PrepareToAddCells(2, 7);
2017-05-18 14:29:41 +00:00
cellSet.AddCell(vtkm::CELL_SHAPE_TRIANGLE, 3, vtkm::make_Vec<vtkm::Id>(0, 2, 4));
cellSet.AddCell(vtkm::CELL_SHAPE_QUAD, 4, vtkm::make_Vec<vtkm::Id>(4, 2, 6, 8));
cellSet.CompleteAddingCells(11);
return cellSet;
}
2017-05-18 14:29:41 +00:00
void CheckOutputCellSet(const vtkm::cont::CellSetExplicit<>& cellSet,
const vtkm::cont::ArrayHandle<vtkm::Float32>& field)
{
VTKM_TEST_ASSERT(cellSet.GetNumberOfCells() == 2, "Wrong num cells.");
VTKM_TEST_ASSERT(cellSet.GetNumberOfPoints() == 5, "Wrong num points.");
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(cellSet.GetCellShape(0) == vtkm::CELL_SHAPE_TRIANGLE, "Wrong shape");
VTKM_TEST_ASSERT(cellSet.GetCellShape(1) == vtkm::CELL_SHAPE_QUAD, "Wrong shape");
VTKM_TEST_ASSERT(cellSet.GetNumberOfPointsInCell(0) == 3, "Wrong num points");
VTKM_TEST_ASSERT(cellSet.GetNumberOfPointsInCell(1) == 4, "Wrong num points");
vtkm::Id3 pointIds3;
cellSet.GetIndices(0, pointIds3);
VTKM_TEST_ASSERT(pointIds3[0] == 0, "Wrong point id for cell");
VTKM_TEST_ASSERT(pointIds3[1] == 1, "Wrong point id for cell");
VTKM_TEST_ASSERT(pointIds3[2] == 2, "Wrong point id for cell");
vtkm::Id4 pointIds4;
cellSet.GetIndices(1, pointIds4);
VTKM_TEST_ASSERT(pointIds4[0] == 2, "Wrong point id for cell");
VTKM_TEST_ASSERT(pointIds4[1] == 1, "Wrong point id for cell");
VTKM_TEST_ASSERT(pointIds4[2] == 3, "Wrong point id for cell");
VTKM_TEST_ASSERT(pointIds4[3] == 4, "Wrong point id for cell");
auto fieldPortal = field.ReadPortal();
2017-10-27 14:42:22 +00:00
VTKM_TEST_ASSERT(test_equal(fieldPortal.Get(0), TestValue(0, vtkm::Float32())), "Bad field");
VTKM_TEST_ASSERT(test_equal(fieldPortal.Get(1), TestValue(2, vtkm::Float32())), "Bad field");
VTKM_TEST_ASSERT(test_equal(fieldPortal.Get(2), TestValue(4, vtkm::Float32())), "Bad field");
VTKM_TEST_ASSERT(test_equal(fieldPortal.Get(3), TestValue(6, vtkm::Float32())), "Bad field");
VTKM_TEST_ASSERT(test_equal(fieldPortal.Get(4), TestValue(8, vtkm::Float32())), "Bad field");
}
void RunTest()
{
std::cout << "Creating input" << std::endl;
vtkm::cont::CellSetExplicit<> inCellSet = CreateInputCellSet();
vtkm::cont::ArrayHandle<vtkm::Float32> inField;
inField.Allocate(inCellSet.GetNumberOfPoints());
SetPortal(inField.WritePortal());
std::cout << "Removing unused points" << std::endl;
vtkm::worklet::RemoveUnusedPoints compactPoints(inCellSet);
vtkm::cont::CellSetExplicit<> outCellSet = compactPoints.MapCellSet(inCellSet);
vtkm::cont::ArrayHandle<vtkm::Float32> outField = compactPoints.MapPointFieldDeep(inField);
std::cout << "Checking resulting cell set" << std::endl;
CheckOutputCellSet(outCellSet, outField);
}
} // anonymous namespace
int UnitTestRemoveUnusedPoints(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(RunTest, argc, argv);
}