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>
|
2018-01-02 23:44:35 +00:00
|
|
|
|
2018-03-21 19:35:02 +00:00
|
|
|
#include <vtkm/cont/ArrayCopy.h>
|
|
|
|
|
2018-01-02 23:44:35 +00:00
|
|
|
#include <vtkm/worklet/connectivities/CellSetConnectivity.h>
|
2017-12-22 17:31:02 +00:00
|
|
|
|
2018-03-21 19:35: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
|
|
|
|
2018-01-02 23:44:35 +00:00
|
|
|
class TestCellSetConnectivity
|
2017-12-22 17:31:02 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-01-02 23:44:35 +00:00
|
|
|
void TestTangleIsosurface() const
|
2017-12-22 17:31:02 +00:00
|
|
|
{
|
2018-01-02 23:44:35 +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
|
|
|
|
2019-08-19 14:56:11 +00:00
|
|
|
vtkm::filter::Contour filter;
|
2017-12-22 17:31:02 +00:00
|
|
|
filter.SetGenerateNormals(true);
|
|
|
|
filter.SetMergeDuplicatePoints(true);
|
2018-01-02 23:44:35 +00:00
|
|
|
filter.SetIsoValue(0, 0.1);
|
2018-03-02 20:49:07 +00:00
|
|
|
filter.SetActiveField("nodevar");
|
|
|
|
vtkm::cont::DataSet outputData = filter.Execute(dataSet);
|
2017-12-22 17:31:02 +00:00
|
|
|
|
|
|
|
auto cellSet = outputData.GetCellSet().Cast<vtkm::cont::CellSetSingleType<>>();
|
2018-01-02 23:44:35 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> componentArray;
|
2018-10-17 19:17:29 +00:00
|
|
|
vtkm::worklet::connectivity::CellSetConnectivity().Run(cellSet, componentArray);
|
2018-01-02 23:44:35 +00:00
|
|
|
|
2018-10-17 19:17:29 +00:00
|
|
|
using Algorithm = vtkm::cont::Algorithm;
|
2018-01-02 23:44:35 +00:00
|
|
|
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
|
|
|
}
|
2018-01-02 23:44:35 +00:00
|
|
|
|
2018-03-06 23:21:32 +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;
|
2018-10-17 19:17:29 +00:00
|
|
|
vtkm::worklet::connectivity::CellSetConnectivity().Run(cellSet, componentArray);
|
2018-03-06 23:21:32 +00:00
|
|
|
|
2018-10-17 19:17:29 +00:00
|
|
|
using Algorithm = vtkm::cont::Algorithm;
|
2018-03-06 23:21:32 +00:00
|
|
|
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;
|
2018-10-17 19:17:29 +00:00
|
|
|
vtkm::worklet::connectivity::CellSetConnectivity().Run(cellSet, componentArray);
|
2018-03-06 23:21:32 +00:00
|
|
|
|
2018-10-17 19:17:29 +00:00
|
|
|
using Algorithm = vtkm::cont::Algorithm;
|
2018-03-06 23:21:32 +00:00
|
|
|
Algorithm::Sort(componentArray);
|
|
|
|
Algorithm::Unique(componentArray);
|
|
|
|
VTKM_TEST_ASSERT(componentArray.GetNumberOfValues() == 1,
|
|
|
|
"Wrong number of connected components");
|
|
|
|
}
|
|
|
|
|
2018-05-08 17:52:32 +00:00
|
|
|
void operator()() const
|
|
|
|
{
|
2018-03-06 23:21:32 +00:00
|
|
|
this->TestTangleIsosurface();
|
|
|
|
this->TestExplicitDataSet();
|
|
|
|
this->TestUniformDataSet();
|
|
|
|
}
|
2017-12-22 17:31:02 +00:00
|
|
|
};
|
|
|
|
|
2018-10-17 19:17:29 +00:00
|
|
|
int UnitTestCellSetConnectivity(int argc, char* argv[])
|
2017-12-22 17:31:02 +00:00
|
|
|
{
|
2018-10-17 19:17:29 +00:00
|
|
|
return vtkm::cont::testing::Testing::Run(TestCellSetConnectivity(), argc, argv);
|
2018-01-03 00:22:54 +00:00
|
|
|
}
|