2016-11-05 00:29:54 +00:00
|
|
|
//============================================================================
|
|
|
|
// 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.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2016 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2016-11-05 00:29:54 +00:00
|
|
|
// Copyright 2016 UT-Battelle, LLC.
|
|
|
|
// Copyright 2016 Los Alamos National Security.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2016-11-05 00:29:54 +00:00
|
|
|
// the U.S. Government retains certain rights in this software.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
|
|
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
|
|
|
// this software.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/worklet/RemoveUnusedPoints.h>
|
|
|
|
|
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2016-11-05 00:29:54 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::CellSetExplicit<> CreateInputCellSet()
|
2016-11-05 00:29:54 +00:00
|
|
|
{
|
2016-12-20 23:14:50 +00:00
|
|
|
vtkm::cont::CellSetExplicit<> cellSet("cells");
|
2016-11-05 00:29:54 +00:00
|
|
|
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));
|
2016-12-20 23:14:50 +00:00
|
|
|
cellSet.CompleteAddingCells(11);
|
2016-11-05 00:29:54 +00:00
|
|
|
return cellSet;
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
void CheckOutputCellSet(const vtkm::cont::CellSetExplicit<>& cellSet,
|
|
|
|
const vtkm::cont::ArrayHandle<vtkm::Float32>& field)
|
2016-11-05 00:29:54 +00:00
|
|
|
{
|
|
|
|
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");
|
2016-11-05 00:29:54 +00:00
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(cellSet.GetNumberOfPointsInCell(0) == 3, "Wrong num points");
|
|
|
|
VTKM_TEST_ASSERT(cellSet.GetNumberOfPointsInCell(1) == 4, "Wrong num points");
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Vec<vtkm::Id, 3> pointIds3;
|
2016-11-05 00:29:54 +00:00
|
|
|
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");
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Vec<vtkm::Id, 4> pointIds4;
|
2016-11-05 00:29:54 +00:00
|
|
|
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");
|
|
|
|
|
2017-10-27 14:42:22 +00:00
|
|
|
auto fieldPortal = field.GetPortalConstControl();
|
|
|
|
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");
|
2016-11-05 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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.GetPortalControl());
|
|
|
|
|
|
|
|
std::cout << "Removing unused points" << std::endl;
|
2018-08-30 15:53:18 +00:00
|
|
|
vtkm::worklet::RemoveUnusedPoints compactPoints(inCellSet);
|
|
|
|
vtkm::cont::CellSetExplicit<> outCellSet = compactPoints.MapCellSet(inCellSet);
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Float32> outField = compactPoints.MapPointFieldDeep(inField);
|
2016-11-05 00:29:54 +00:00
|
|
|
|
|
|
|
std::cout << "Checking resulting cell set" << std::endl;
|
|
|
|
CheckOutputCellSet(outCellSet, outField);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2018-10-17 19:17:29 +00:00
|
|
|
int UnitTestRemoveUnusedPoints(int argc, char* argv[])
|
2016-11-05 00:29:54 +00:00
|
|
|
{
|
2018-10-17 19:17:29 +00:00
|
|
|
return vtkm::cont::testing::Testing::Run(RunTest, argc, argv);
|
2016-11-05 00:29:54 +00:00
|
|
|
}
|