vtk-m/vtkm/worklet/testing/UnitTestCellSetConnectivity.cxx

89 lines
3.0 KiB
C++
Raw Normal View History

2019-04-15 23:24:21 +00:00
//============================================================================
2017-12-22 17:31:02 +00:00
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
2018-01-03 21:29:06 +00:00
//
2017-12-22 17:31:02 +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.
2019-04-15 23:24:21 +00:00
//============================================================================
2019-08-18 01:10:57 +00:00
#include <vtkm/filter/Contour.h>
#include <vtkm/cont/ArrayCopy.h>
#include <vtkm/worklet/connectivities/CellSetConnectivity.h>
2017-12-22 17:31:02 +00:00
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
2019-08-27 22:42:25 +00:00
#include <vtkm/source/Tangle.h>
2017-12-22 17:31:02 +00:00
class TestCellSetConnectivity
2017-12-22 17:31:02 +00:00
{
public:
void TestTangleIsosurface() const
2017-12-22 17:31:02 +00:00
{
vtkm::Id3 dims(4, 4, 4);
2019-08-27 22:42:25 +00:00
vtkm::source::Tangle tangle(dims);
vtkm::cont::DataSet dataSet = tangle.Execute();
2017-12-22 17:31:02 +00:00
vtkm::filter::Contour filter;
2017-12-22 17:31:02 +00:00
filter.SetGenerateNormals(true);
filter.SetMergeDuplicatePoints(true);
filter.SetIsoValue(0, 0.1);
filter.SetActiveField("tangle");
vtkm::cont::DataSet outputData = filter.Execute(dataSet);
2017-12-22 17:31:02 +00:00
auto cellSet = outputData.GetCellSet().Cast<vtkm::cont::CellSetSingleType<>>();
vtkm::cont::ArrayHandle<vtkm::Id> componentArray;
vtkm::worklet::connectivity::CellSetConnectivity().Run(cellSet, componentArray);
using Algorithm = vtkm::cont::Algorithm;
Algorithm::Sort(componentArray);
Algorithm::Unique(componentArray);
VTKM_TEST_ASSERT(componentArray.GetNumberOfValues() == 8,
"Wrong number of connected components");
2017-12-22 17:31:02 +00:00
}
void TestExplicitDataSet() const
{
vtkm::cont::DataSet dataSet = vtkm::cont::testing::MakeTestDataSet().Make3DExplicitDataSet5();
auto cellSet = dataSet.GetCellSet().Cast<vtkm::cont::CellSetExplicit<>>();
vtkm::cont::ArrayHandle<vtkm::Id> componentArray;
vtkm::worklet::connectivity::CellSetConnectivity().Run(cellSet, componentArray);
using Algorithm = vtkm::cont::Algorithm;
Algorithm::Sort(componentArray);
Algorithm::Unique(componentArray);
VTKM_TEST_ASSERT(componentArray.GetNumberOfValues() == 1,
"Wrong number of connected components");
}
void TestUniformDataSet() const
{
vtkm::cont::DataSet dataSet = vtkm::cont::testing::MakeTestDataSet().Make3DUniformDataSet1();
auto cellSet = dataSet.GetCellSet();
vtkm::cont::ArrayHandle<vtkm::Id> componentArray;
vtkm::worklet::connectivity::CellSetConnectivity().Run(cellSet, componentArray);
using Algorithm = vtkm::cont::Algorithm;
Algorithm::Sort(componentArray);
Algorithm::Unique(componentArray);
VTKM_TEST_ASSERT(componentArray.GetNumberOfValues() == 1,
"Wrong number of connected components");
}
void operator()() const
{
this->TestTangleIsosurface();
this->TestExplicitDataSet();
this->TestUniformDataSet();
}
2017-12-22 17:31:02 +00:00
};
int UnitTestCellSetConnectivity(int argc, char* argv[])
2017-12-22 17:31:02 +00:00
{
return vtkm::cont::testing::Testing::Run(TestCellSetConnectivity(), argc, argv);
2018-01-03 00:22:54 +00:00
}