vtk-m/vtkm/worklet/testing/UnitTestCellSetConnectivity.cxx
Kenneth Moreland ea1a55359f Name tangle source fields appropriately
The `Tangle` source would create a point field generically named
`nodevar`. This name was not indicitive of the data or its source. Thus,
the output point field has been renamed `tangle`.

The `Tangle` source was also creating a cell field (named `cellvar`).
This field was really just a mirror of the cell indices (counting from 0
on up). This field has been removed from the input. If you want such a
field, you can now use the `GenerateIds` filter to add it to any data
set.
2021-10-04 13:44:27 -06:00

89 lines
3.0 KiB
C++

//============================================================================
// 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.
//============================================================================
#include <vtkm/filter/Contour.h>
#include <vtkm/cont/ArrayCopy.h>
#include <vtkm/worklet/connectivities/CellSetConnectivity.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/source/Tangle.h>
class TestCellSetConnectivity
{
public:
void TestTangleIsosurface() const
{
vtkm::Id3 dims(4, 4, 4);
vtkm::source::Tangle tangle(dims);
vtkm::cont::DataSet dataSet = tangle.Execute();
vtkm::filter::Contour filter;
filter.SetGenerateNormals(true);
filter.SetMergeDuplicatePoints(true);
filter.SetIsoValue(0, 0.1);
filter.SetActiveField("tangle");
vtkm::cont::DataSet outputData = filter.Execute(dataSet);
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");
}
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();
}
};
int UnitTestCellSetConnectivity(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::Run(TestCellSetConnectivity(), argc, argv);
}