2017-03-16 19:44:01 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2017-03-16 19:44:01 +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.
|
|
|
|
//============================================================================
|
|
|
|
|
2017-03-16 20:53:16 +00:00
|
|
|
#include <vtkm/worklet/ExtractGeometry.h>
|
2017-03-16 19:44:01 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
|
|
|
|
using vtkm::cont::testing::MakeTestDataSet;
|
|
|
|
|
2017-03-21 21:14:35 +00:00
|
|
|
class TestingExtractGeometry
|
2017-03-16 19:44:01 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-03-17 23:00:59 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-03-20 20:40:53 +00:00
|
|
|
void TestExplicitById() const
|
2017-03-16 19:44:01 +00:00
|
|
|
{
|
2017-03-17 23:00:59 +00:00
|
|
|
std::cout << "Testing extract cell explicit by id:" << std::endl;
|
2017-03-16 19:44:01 +00:00
|
|
|
|
2018-02-22 13:29:13 +00:00
|
|
|
using CellSetType = vtkm::cont::CellSetExplicit<>;
|
|
|
|
using OutCellSetType = vtkm::cont::CellSetPermutation<CellSetType>;
|
2017-03-16 19:44:01 +00:00
|
|
|
|
|
|
|
// Input data set created
|
2017-03-17 23:00:59 +00:00
|
|
|
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5();
|
|
|
|
CellSetType cellSet;
|
2019-08-13 17:08:54 +00:00
|
|
|
dataset.GetCellSet().CopyTo(cellSet);
|
2017-03-17 23:00:59 +00:00
|
|
|
|
|
|
|
// Cells to extract
|
|
|
|
const int nCells = 2;
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id cellids[nCells] = { 1, 2 };
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> cellIds = vtkm::cont::make_ArrayHandle(cellids, nCells);
|
|
|
|
|
2017-03-17 23:00:59 +00:00
|
|
|
// Output data set with cell set containing extracted cells and all points
|
|
|
|
vtkm::worklet::ExtractGeometry extractGeometry;
|
2018-08-30 15:53:18 +00:00
|
|
|
OutCellSetType outCellSet = extractGeometry.Run(cellSet, cellIds);
|
2017-03-20 20:40:53 +00:00
|
|
|
|
2017-06-13 19:48:27 +00:00
|
|
|
auto cellvar =
|
|
|
|
dataset.GetField("cellvar").GetData().Cast<vtkm::cont::ArrayHandle<vtkm::Float32>>();
|
2018-08-30 15:53:18 +00:00
|
|
|
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
|
2017-03-16 19:44:01 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nCells),
|
|
|
|
"Wrong result for ExtractCells");
|
2017-03-20 20:40:53 +00:00
|
|
|
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == nCells &&
|
2020-01-28 19:14:32 +00:00
|
|
|
cellFieldArray.ReadPortal().Get(0) == 110.f,
|
2017-03-20 20:40:53 +00:00
|
|
|
"Wrong cell field data");
|
2017-03-16 19:44:01 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 23:00:59 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-03-20 20:40:53 +00:00
|
|
|
void TestExplicitByBox() const
|
2017-03-16 19:44:01 +00:00
|
|
|
{
|
2017-03-17 23:00:59 +00:00
|
|
|
std::cout << "Testing extract cells with implicit function (box) on explicit:" << std::endl;
|
2017-03-16 19:44:01 +00:00
|
|
|
|
2018-02-22 13:29:13 +00:00
|
|
|
using CellSetType = vtkm::cont::CellSetExplicit<>;
|
2017-03-16 19:44:01 +00:00
|
|
|
|
|
|
|
// Input data set created
|
2017-03-17 23:00:59 +00:00
|
|
|
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5();
|
|
|
|
CellSetType cellSet;
|
2019-08-13 17:08:54 +00:00
|
|
|
dataset.GetCellSet().CopyTo(cellSet);
|
2017-03-17 23:00:59 +00:00
|
|
|
|
2017-03-16 19:44:01 +00:00
|
|
|
// Implicit function
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f minPoint(0.5f, 0.0f, 0.0f);
|
|
|
|
vtkm::Vec3f maxPoint(2.0f, 2.0f, 2.0f);
|
2017-05-04 19:13:53 +00:00
|
|
|
|
|
|
|
bool extractInside = true;
|
|
|
|
bool extractBoundaryCells = false;
|
|
|
|
bool extractOnlyBoundaryCells = false;
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-03-17 23:00:59 +00:00
|
|
|
// Output data set with cell set containing extracted cells and all points
|
|
|
|
vtkm::worklet::ExtractGeometry extractGeometry;
|
2017-06-13 19:48:27 +00:00
|
|
|
vtkm::cont::DynamicCellSet outCellSet =
|
|
|
|
extractGeometry.Run(cellSet,
|
|
|
|
dataset.GetCoordinateSystem("coordinates"),
|
2017-10-23 13:38:33 +00:00
|
|
|
vtkm::cont::make_ImplicitFunctionHandle<vtkm::Box>(minPoint, maxPoint),
|
2017-06-13 19:48:27 +00:00
|
|
|
extractInside,
|
|
|
|
extractBoundaryCells,
|
2018-08-30 15:53:18 +00:00
|
|
|
extractOnlyBoundaryCells);
|
2017-06-13 19:48:27 +00:00
|
|
|
|
|
|
|
auto cellvar =
|
|
|
|
dataset.GetField("cellvar").GetData().Cast<vtkm::cont::ArrayHandle<vtkm::Float32>>();
|
2018-08-30 15:53:18 +00:00
|
|
|
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
|
2017-06-13 19:48:27 +00:00
|
|
|
|
2017-03-16 19:44:01 +00:00
|
|
|
|
2017-03-17 23:00:59 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 2), "Wrong result for ExtractCells");
|
2017-03-20 20:40:53 +00:00
|
|
|
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 2 &&
|
2020-01-28 19:14:32 +00:00
|
|
|
cellFieldArray.ReadPortal().Get(1) == 120.2f,
|
2017-03-20 20:40:53 +00:00
|
|
|
"Wrong cell field data");
|
2017-03-16 19:44:01 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 23:00:59 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-03-20 20:40:53 +00:00
|
|
|
void TestUniformById2D() const
|
2017-03-16 19:44:01 +00:00
|
|
|
{
|
2017-03-16 20:53:16 +00:00
|
|
|
std::cout << "Testing extract cells structured by id:" << std::endl;
|
2017-03-16 19:44:01 +00:00
|
|
|
|
2018-02-22 13:29:13 +00:00
|
|
|
using CellSetType = vtkm::cont::CellSetStructured<2>;
|
|
|
|
using OutCellSetType = vtkm::cont::CellSetPermutation<CellSetType>;
|
2017-06-13 19:48:27 +00:00
|
|
|
|
2017-03-16 19:44:01 +00:00
|
|
|
|
|
|
|
// Input data set created
|
2017-03-17 23:00:59 +00:00
|
|
|
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet1();
|
2017-03-20 20:40:53 +00:00
|
|
|
CellSetType cellSet;
|
2019-08-13 17:08:54 +00:00
|
|
|
dataset.GetCellSet().CopyTo(cellSet);
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-03-16 20:53:16 +00:00
|
|
|
// Cells to extract
|
2017-03-17 23:00:59 +00:00
|
|
|
const int nCells = 5;
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id cellids[nCells] = { 0, 4, 5, 10, 15 };
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> cellIds = vtkm::cont::make_ArrayHandle(cellids, nCells);
|
2017-03-16 19:44:01 +00:00
|
|
|
|
2017-03-20 20:40:53 +00:00
|
|
|
// Output data set permutation of with only extracted cells
|
2017-03-17 23:00:59 +00:00
|
|
|
vtkm::worklet::ExtractGeometry extractGeometry;
|
2018-08-30 15:53:18 +00:00
|
|
|
OutCellSetType outCellSet = extractGeometry.Run(cellSet, cellIds);
|
2017-03-20 20:40:53 +00:00
|
|
|
|
2017-06-13 19:48:27 +00:00
|
|
|
auto cellvar =
|
|
|
|
dataset.GetField("cellvar").GetData().Cast<vtkm::cont::ArrayHandle<vtkm::Float32>>();
|
2018-08-30 15:53:18 +00:00
|
|
|
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
|
2017-03-16 19:44:01 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nCells),
|
|
|
|
"Wrong result for ExtractCells");
|
2017-03-20 20:40:53 +00:00
|
|
|
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == nCells &&
|
2020-01-28 19:14:32 +00:00
|
|
|
cellFieldArray.ReadPortal().Get(1) == 4.f,
|
2017-03-20 20:40:53 +00:00
|
|
|
"Wrong cell field data");
|
2017-03-16 19:44:01 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 23:00:59 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-03-20 20:40:53 +00:00
|
|
|
void TestUniformById3D() const
|
2017-03-16 19:44:01 +00:00
|
|
|
{
|
2017-03-17 23:00:59 +00:00
|
|
|
std::cout << "Testing extract cells structured by id:" << std::endl;
|
2017-03-16 19:44:01 +00:00
|
|
|
|
2018-02-22 13:29:13 +00:00
|
|
|
using CellSetType = vtkm::cont::CellSetStructured<3>;
|
|
|
|
using OutCellSetType = vtkm::cont::CellSetPermutation<CellSetType>;
|
2017-03-16 19:44:01 +00:00
|
|
|
|
|
|
|
// Input data set created
|
2017-03-17 23:00:59 +00:00
|
|
|
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
|
2017-03-20 20:40:53 +00:00
|
|
|
CellSetType cellSet;
|
2019-08-13 17:08:54 +00:00
|
|
|
dataset.GetCellSet().CopyTo(cellSet);
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-03-16 19:44:01 +00:00
|
|
|
// Cells to extract
|
2017-03-17 23:00:59 +00:00
|
|
|
const int nCells = 5;
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id cellids[nCells] = { 0, 4, 5, 10, 15 };
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id> cellIds = vtkm::cont::make_ArrayHandle(cellids, nCells);
|
2017-03-17 23:00:59 +00:00
|
|
|
|
2017-03-16 19:44:01 +00:00
|
|
|
// Output data set with cell set containing extracted cells and all points
|
2017-03-16 20:53:16 +00:00
|
|
|
vtkm::worklet::ExtractGeometry extractGeometry;
|
2018-08-30 15:53:18 +00:00
|
|
|
OutCellSetType outCellSet = extractGeometry.Run(cellSet, cellIds);
|
2017-03-20 20:40:53 +00:00
|
|
|
|
2017-06-13 19:48:27 +00:00
|
|
|
auto cellvar =
|
|
|
|
dataset.GetField("cellvar").GetData().Cast<vtkm::cont::ArrayHandle<vtkm::Float32>>();
|
2018-08-30 15:53:18 +00:00
|
|
|
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
|
2017-03-16 19:44:01 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), nCells),
|
|
|
|
"Wrong result for ExtractCells");
|
2017-03-20 20:40:53 +00:00
|
|
|
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == nCells &&
|
2020-01-28 19:14:32 +00:00
|
|
|
cellFieldArray.ReadPortal().Get(2) == 5.f,
|
2017-03-20 20:40:53 +00:00
|
|
|
"Wrong cell field data");
|
2017-03-16 19:44:01 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 23:00:59 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-03-20 20:40:53 +00:00
|
|
|
void TestUniformByBox() const
|
2017-03-16 19:44:01 +00:00
|
|
|
{
|
2017-03-17 23:00:59 +00:00
|
|
|
std::cout << "Testing extract cells with implicit function (box):" << std::endl;
|
2017-03-16 19:44:01 +00:00
|
|
|
|
2018-02-22 13:29:13 +00:00
|
|
|
using CellSetType = vtkm::cont::CellSetStructured<3>;
|
2017-03-16 19:44:01 +00:00
|
|
|
|
|
|
|
// Input data set created
|
2017-03-17 23:00:59 +00:00
|
|
|
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
|
2017-03-20 20:40:53 +00:00
|
|
|
CellSetType cellSet;
|
2019-08-13 17:08:54 +00:00
|
|
|
dataset.GetCellSet().CopyTo(cellSet);
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-03-16 19:44:01 +00:00
|
|
|
// Implicit function
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f minPoint(1.0f, 1.0f, 1.0f);
|
|
|
|
vtkm::Vec3f maxPoint(3.0f, 3.0f, 3.0f);
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-05-04 19:13:53 +00:00
|
|
|
bool extractInside = true;
|
|
|
|
bool extractBoundaryCells = false;
|
|
|
|
bool extractOnlyBoundaryCells = false;
|
|
|
|
|
2017-03-17 23:00:59 +00:00
|
|
|
// Output data set with cell set containing extracted points
|
2017-03-16 20:53:16 +00:00
|
|
|
vtkm::worklet::ExtractGeometry extractGeometry;
|
2017-06-13 19:48:27 +00:00
|
|
|
vtkm::cont::DynamicCellSet outCellSet =
|
|
|
|
extractGeometry.Run(cellSet,
|
|
|
|
dataset.GetCoordinateSystem("coords"),
|
2017-10-23 13:38:33 +00:00
|
|
|
vtkm::cont::make_ImplicitFunctionHandle<vtkm::Box>(minPoint, maxPoint),
|
2017-06-13 19:48:27 +00:00
|
|
|
extractInside,
|
|
|
|
extractBoundaryCells,
|
2018-08-30 15:53:18 +00:00
|
|
|
extractOnlyBoundaryCells);
|
2017-06-13 19:48:27 +00:00
|
|
|
|
|
|
|
auto cellvar =
|
|
|
|
dataset.GetField("cellvar").GetData().Cast<vtkm::cont::ArrayHandle<vtkm::Float32>>();
|
2018-08-30 15:53:18 +00:00
|
|
|
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
|
2017-03-16 19:44:01 +00:00
|
|
|
|
2017-03-17 23:00:59 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8), "Wrong result for ExtractCells");
|
2017-03-20 20:40:53 +00:00
|
|
|
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 8 &&
|
2020-01-28 19:14:32 +00:00
|
|
|
cellFieldArray.ReadPortal().Get(0) == 21.f,
|
2017-03-20 20:40:53 +00:00
|
|
|
"Wrong cell field data");
|
2017-03-17 23:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-03-20 20:40:53 +00:00
|
|
|
void TestUniformBySphere() const
|
2017-03-17 23:00:59 +00:00
|
|
|
{
|
|
|
|
std::cout << "Testing extract cells with implicit function (sphere):" << std::endl;
|
|
|
|
|
2018-02-22 13:29:13 +00:00
|
|
|
using CellSetType = vtkm::cont::CellSetStructured<3>;
|
2017-03-17 23:00:59 +00:00
|
|
|
|
|
|
|
// Input data set created
|
|
|
|
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet1();
|
2017-03-20 20:40:53 +00:00
|
|
|
CellSetType cellSet;
|
2019-08-13 17:08:54 +00:00
|
|
|
dataset.GetCellSet().CopyTo(cellSet);
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-03-17 23:00:59 +00:00
|
|
|
// Implicit function
|
2019-07-31 16:20:38 +00:00
|
|
|
vtkm::Vec3f center(2.f, 2.f, 2.f);
|
2017-03-29 22:24:42 +00:00
|
|
|
vtkm::FloatDefault radius(1.8f);
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-05-04 19:13:53 +00:00
|
|
|
bool extractInside = true;
|
|
|
|
bool extractBoundaryCells = false;
|
|
|
|
bool extractOnlyBoundaryCells = false;
|
|
|
|
|
2017-03-17 23:00:59 +00:00
|
|
|
// Output data set with cell set containing extracted cells
|
|
|
|
vtkm::worklet::ExtractGeometry extractGeometry;
|
2017-06-13 19:48:27 +00:00
|
|
|
vtkm::cont::DynamicCellSet outCellSet =
|
|
|
|
extractGeometry.Run(cellSet,
|
|
|
|
dataset.GetCoordinateSystem("coords"),
|
2017-10-23 13:38:33 +00:00
|
|
|
vtkm::cont::make_ImplicitFunctionHandle<vtkm::Sphere>(center, radius),
|
2017-06-13 19:48:27 +00:00
|
|
|
extractInside,
|
|
|
|
extractBoundaryCells,
|
2018-08-30 15:53:18 +00:00
|
|
|
extractOnlyBoundaryCells);
|
2017-06-13 19:48:27 +00:00
|
|
|
|
|
|
|
auto cellvar =
|
|
|
|
dataset.GetField("cellvar").GetData().Cast<vtkm::cont::ArrayHandle<vtkm::Float32>>();
|
2018-08-30 15:53:18 +00:00
|
|
|
auto cellFieldArray = extractGeometry.ProcessCellField(cellvar);
|
2017-03-17 23:00:59 +00:00
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 8), "Wrong result for ExtractCells");
|
2017-03-20 20:40:53 +00:00
|
|
|
VTKM_TEST_ASSERT(cellFieldArray.GetNumberOfValues() == 8 &&
|
2020-01-28 19:14:32 +00:00
|
|
|
cellFieldArray.ReadPortal().Get(1) == 22.f,
|
2017-03-20 20:40:53 +00:00
|
|
|
"Wrong cell field data");
|
2017-03-16 19:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void operator()() const
|
|
|
|
{
|
2017-03-20 20:40:53 +00:00
|
|
|
this->TestUniformById2D();
|
|
|
|
this->TestUniformById3D();
|
|
|
|
this->TestUniformBySphere();
|
2017-03-29 22:24:42 +00:00
|
|
|
this->TestUniformByBox();
|
|
|
|
this->TestExplicitById();
|
|
|
|
this->TestExplicitByBox();
|
2017-03-16 19:44:01 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-17 19:17:29 +00:00
|
|
|
int UnitTestExtractGeometry(int argc, char* argv[])
|
2017-03-16 19:44:01 +00:00
|
|
|
{
|
2018-10-17 19:17:29 +00:00
|
|
|
return vtkm::cont::testing::Testing::Run(TestingExtractGeometry(), argc, argv);
|
2017-03-16 19:44:01 +00:00
|
|
|
}
|