2017-03-23 17:58:00 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2017-03-23 17:58:00 +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.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/worklet/DispatcherMapField.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/worklet/Tetrahedralize.h>
|
2017-03-23 17:58:00 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/DataSet.h>
|
|
|
|
#include <vtkm/cont/DataSetBuilderExplicit.h>
|
|
|
|
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
|
|
|
|
using vtkm::cont::testing::MakeTestDataSet;
|
|
|
|
|
|
|
|
class TestingTetrahedralize
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//
|
|
|
|
// Create a uniform 3D structured cell set as input
|
|
|
|
// Add a field which is the index type which is (i+j+k) % 2 to alternate tetrahedralization pattern
|
|
|
|
// Points are all the same, but each hexahedron cell becomes 5 tetrahedral cells
|
|
|
|
//
|
|
|
|
void TestStructured() const
|
|
|
|
{
|
|
|
|
std::cout << "Testing TetrahedralizeStructured" << std::endl;
|
2018-02-22 13:29:13 +00:00
|
|
|
using CellSetType = vtkm::cont::CellSetStructured<3>;
|
|
|
|
using OutCellSetType = vtkm::cont::CellSetSingleType<>;
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-03-23 17:58:00 +00:00
|
|
|
// Create the input uniform cell set
|
|
|
|
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DUniformDataSet0();
|
|
|
|
CellSetType cellSet;
|
2019-08-13 17:08:54 +00:00
|
|
|
dataSet.GetCellSet().CopyTo(cellSet);
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-03-23 17:58:00 +00:00
|
|
|
// Convert uniform hexahedra to tetrahedra
|
2017-03-24 22:34:53 +00:00
|
|
|
vtkm::worklet::Tetrahedralize tetrahedralize;
|
2018-08-28 20:36:50 +00:00
|
|
|
OutCellSetType outCellSet = tetrahedralize.Run(cellSet);
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-03-23 17:58:00 +00:00
|
|
|
// Create the output dataset with same coordinate system
|
|
|
|
vtkm::cont::DataSet outDataSet;
|
|
|
|
outDataSet.AddCoordinateSystem(dataSet.GetCoordinateSystem(0));
|
2019-08-13 17:08:54 +00:00
|
|
|
outDataSet.SetCellSet(outCellSet);
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-03-23 17:58:00 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), cellSet.GetNumberOfCells() * 5),
|
|
|
|
"Wrong result for Tetrahedralize filter");
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create an explicit 3D cell set as input and fill
|
|
|
|
// Points are all the same, but each cell becomes tetrahedra
|
|
|
|
//
|
|
|
|
void TestExplicit() const
|
|
|
|
{
|
|
|
|
std::cout << "Testing TetrahedralizeExplicit" << std::endl;
|
2018-02-22 13:29:13 +00:00
|
|
|
using CellSetType = vtkm::cont::CellSetExplicit<>;
|
|
|
|
using OutCellSetType = vtkm::cont::CellSetSingleType<>;
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-03-23 17:58:00 +00:00
|
|
|
// Create the input explicit cell set
|
|
|
|
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DExplicitDataSet5();
|
|
|
|
CellSetType cellSet;
|
2019-08-13 17:08:54 +00:00
|
|
|
dataSet.GetCellSet().CopyTo(cellSet);
|
2017-03-23 23:14:39 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::IdComponent> outCellsPerCell;
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-03-23 17:58:00 +00:00
|
|
|
// Convert explicit cells to tetrahedra
|
2017-03-24 22:34:53 +00:00
|
|
|
vtkm::worklet::Tetrahedralize tetrahedralize;
|
2018-08-28 20:36:50 +00:00
|
|
|
OutCellSetType outCellSet = tetrahedralize.Run(cellSet);
|
2017-05-18 14:29:41 +00:00
|
|
|
|
2017-03-23 17:58:00 +00:00
|
|
|
// Create the output dataset explicit cell set with same coordinate system
|
|
|
|
vtkm::cont::DataSet outDataSet;
|
|
|
|
outDataSet.AddCoordinateSystem(dataSet.GetCoordinateSystem(0));
|
2019-08-13 17:08:54 +00:00
|
|
|
outDataSet.SetCellSet(outCellSet);
|
2017-05-18 14:29:41 +00:00
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 11),
|
2017-03-23 17:58:00 +00:00
|
|
|
"Wrong result for Tetrahedralize filter");
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator()() const
|
|
|
|
{
|
|
|
|
TestStructured();
|
|
|
|
TestExplicit();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-17 19:17:29 +00:00
|
|
|
int UnitTestTetrahedralize(int argc, char* argv[])
|
2017-03-23 17:58:00 +00:00
|
|
|
{
|
2018-10-17 19:17:29 +00:00
|
|
|
return vtkm::cont::testing::Testing::Run(TestingTetrahedralize(), argc, argv);
|
2017-03-23 17:58:00 +00:00
|
|
|
}
|