1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10
11 #include <vtkm/worklet/DispatcherMapField.h>
12 #include <vtkm/worklet/Tetrahedralize.h>
13
14 #include <vtkm/cont/DataSet.h>
15 #include <vtkm/cont/DataSetBuilderExplicit.h>
16 #include <vtkm/cont/testing/MakeTestDataSet.h>
17 #include <vtkm/cont/testing/Testing.h>
18
19 using vtkm::cont::testing::MakeTestDataSet;
20
21 class TestingTetrahedralize
22 {
23 public:
24 //
25 // Create a uniform 3D structured cell set as input
26 // Add a field which is the index type which is (i+j+k) % 2 to alternate tetrahedralization pattern
27 // Points are all the same, but each hexahedron cell becomes 5 tetrahedral cells
28 //
TestStructured() const29 void TestStructured() const
30 {
31 std::cout << "Testing TetrahedralizeStructured" << std::endl;
32 using CellSetType = vtkm::cont::CellSetStructured<3>;
33 using OutCellSetType = vtkm::cont::CellSetSingleType<>;
34
35 // Create the input uniform cell set
36 vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DUniformDataSet0();
37 CellSetType cellSet;
38 dataSet.GetCellSet().CopyTo(cellSet);
39
40 // Convert uniform hexahedra to tetrahedra
41 vtkm::worklet::Tetrahedralize tetrahedralize;
42 OutCellSetType outCellSet = tetrahedralize.Run(cellSet);
43
44 // Create the output dataset with same coordinate system
45 vtkm::cont::DataSet outDataSet;
46 outDataSet.AddCoordinateSystem(dataSet.GetCoordinateSystem(0));
47 outDataSet.SetCellSet(outCellSet);
48
49 VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), cellSet.GetNumberOfCells() * 5),
50 "Wrong result for Tetrahedralize filter");
51 }
52
53 //
54 // Create an explicit 3D cell set as input and fill
55 // Points are all the same, but each cell becomes tetrahedra
56 //
TestExplicit() const57 void TestExplicit() const
58 {
59 std::cout << "Testing TetrahedralizeExplicit" << std::endl;
60 using CellSetType = vtkm::cont::CellSetExplicit<>;
61 using OutCellSetType = vtkm::cont::CellSetSingleType<>;
62
63 // Create the input explicit cell set
64 vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DExplicitDataSet5();
65 CellSetType cellSet;
66 dataSet.GetCellSet().CopyTo(cellSet);
67 vtkm::cont::ArrayHandle<vtkm::IdComponent> outCellsPerCell;
68
69 // Convert explicit cells to tetrahedra
70 vtkm::worklet::Tetrahedralize tetrahedralize;
71 OutCellSetType outCellSet = tetrahedralize.Run(cellSet);
72
73 // Create the output dataset explicit cell set with same coordinate system
74 vtkm::cont::DataSet outDataSet;
75 outDataSet.AddCoordinateSystem(dataSet.GetCoordinateSystem(0));
76 outDataSet.SetCellSet(outCellSet);
77
78 VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 11),
79 "Wrong result for Tetrahedralize filter");
80 }
81
operator ()() const82 void operator()() const
83 {
84 TestStructured();
85 TestExplicit();
86 }
87 };
88
UnitTestTetrahedralize(int argc,char * argv[])89 int UnitTestTetrahedralize(int argc, char* argv[])
90 {
91 return vtkm::cont::testing::Testing::Run(TestingTetrahedralize(), argc, argv);
92 }
93