2015-05-12 18:41:12 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2015-05-12 18:41:12 +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.
|
|
|
|
//============================================================================
|
|
|
|
|
2015-08-16 18:53:44 +00:00
|
|
|
#include <vtkm/CellShape.h>
|
2015-08-02 21:59:44 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/CellSetStructured.h>
|
|
|
|
#include <vtkm/cont/DataSet.h>
|
2016-09-28 15:38:31 +00:00
|
|
|
#include <vtkm/cont/serial/DeviceAdapterSerial.h>
|
2015-08-02 21:59:44 +00:00
|
|
|
|
|
|
|
#include <vtkm/exec/ConnectivityStructured.h>
|
2015-05-18 15:04:15 +00:00
|
|
|
|
2015-07-31 19:59:37 +00:00
|
|
|
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
2015-07-31 19:59:37 +00:00
|
|
|
|
2016-01-19 22:54:05 +00:00
|
|
|
static void TwoDimUniformTest();
|
|
|
|
static void ThreeDimUniformTest();
|
2015-05-12 18:41:12 +00:00
|
|
|
|
2016-01-19 22:54:05 +00:00
|
|
|
void TestDataSet_Uniform()
|
2015-05-12 18:41:12 +00:00
|
|
|
{
|
2015-08-25 15:03:44 +00:00
|
|
|
std::cout << std::endl;
|
2016-01-19 22:54:05 +00:00
|
|
|
std::cout << "--TestDataSet_Uniform--" << std::endl << std::endl;
|
2015-05-18 15:04:15 +00:00
|
|
|
|
2016-01-19 22:54:05 +00:00
|
|
|
TwoDimUniformTest();
|
|
|
|
ThreeDimUniformTest();
|
2015-05-18 15:04:15 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
static void TwoDimUniformTest()
|
2015-05-18 15:04:15 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
std::cout << "2D Uniform data set" << std::endl;
|
2015-08-25 15:03:44 +00:00
|
|
|
vtkm::cont::testing::MakeTestDataSet testDataSet;
|
2015-05-18 15:04:15 +00:00
|
|
|
|
2016-01-19 22:54:05 +00:00
|
|
|
vtkm::cont::DataSet dataSet = testDataSet.Make2DUniformDataSet0();
|
2015-05-18 15:04:15 +00:00
|
|
|
|
2016-01-14 19:01:05 +00:00
|
|
|
dataSet.PrintSummary(std::cout);
|
|
|
|
|
|
|
|
vtkm::cont::CellSetStructured<2> cellSet;
|
2022-01-04 23:42:55 +00:00
|
|
|
dataSet.GetCellSet().AsCellSet(cellSet);
|
2015-05-18 15:04:15 +00:00
|
|
|
|
2022-10-31 17:22:37 +00:00
|
|
|
VTKM_TEST_ASSERT(dataSet.GetNumberOfFields() == 3, "Incorrect number of fields");
|
2015-08-17 18:47:46 +00:00
|
|
|
VTKM_TEST_ASSERT(dataSet.GetNumberOfCoordinateSystems() == 1,
|
|
|
|
"Incorrect number of coordinate systems");
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(cellSet.GetNumberOfPoints() == 6, "Incorrect number of points");
|
|
|
|
VTKM_TEST_ASSERT(cellSet.GetNumberOfCells() == 2, "Incorrect number of cells");
|
|
|
|
VTKM_TEST_ASSERT(cellSet.GetPointDimensions() == vtkm::Id2(3, 2), "Incorrect point dimensions");
|
|
|
|
VTKM_TEST_ASSERT(cellSet.GetCellDimensions() == vtkm::Id2(2, 1), "Incorrect cell dimensions");
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-08-12 15:51:14 +00:00
|
|
|
// test various field-getting methods and associations
|
|
|
|
try
|
|
|
|
{
|
2019-08-13 14:10:52 +00:00
|
|
|
dataSet.GetCellField("cellvar");
|
2015-08-12 15:51:14 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2022-03-17 17:02:37 +00:00
|
|
|
VTKM_TEST_FAIL("Failed to get field 'cellvar' with Association::Cells.");
|
2015-08-12 15:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2019-08-13 14:10:52 +00:00
|
|
|
dataSet.GetPointField("pointvar");
|
2015-08-12 15:51:14 +00:00
|
|
|
}
|
2015-11-03 03:24:57 +00:00
|
|
|
catch (...)
|
2015-08-12 15:51:14 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_FAIL("Failed to get field 'pointvar' with ASSOC_POINT_SET.");
|
2015-08-12 15:51:14 +00:00
|
|
|
}
|
|
|
|
|
2015-08-25 15:03:44 +00:00
|
|
|
vtkm::Id numCells = cellSet.GetNumberOfCells();
|
|
|
|
for (vtkm::Id cellIndex = 0; cellIndex < numCells; cellIndex++)
|
|
|
|
{
|
|
|
|
VTKM_TEST_ASSERT(cellSet.GetNumberOfPointsInCell(cellIndex) == 4,
|
|
|
|
"Incorrect number of cell indices");
|
2015-08-16 21:31:36 +00:00
|
|
|
vtkm::IdComponent shape = cellSet.GetCellShape();
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(shape == vtkm::CELL_SHAPE_QUAD, "Incorrect element type.");
|
2015-08-25 15:03:44 +00:00
|
|
|
}
|
2015-05-18 15:04:15 +00:00
|
|
|
|
2020-01-21 20:18:03 +00:00
|
|
|
vtkm::cont::Token token;
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint, 2>
|
2019-07-30 16:53:51 +00:00
|
|
|
pointToCell = cellSet.PrepareForInput(vtkm::cont::DeviceAdapterTagSerial(),
|
2017-05-26 17:53:28 +00:00
|
|
|
vtkm::TopologyElementTagCell(),
|
2020-01-21 20:18:03 +00:00
|
|
|
vtkm::TopologyElementTagPoint(),
|
|
|
|
token);
|
2019-07-30 16:53:51 +00:00
|
|
|
vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell, 2>
|
|
|
|
cellToPoint = cellSet.PrepareForInput(vtkm::cont::DeviceAdapterTagSerial(),
|
|
|
|
vtkm::TopologyElementTagPoint(),
|
2020-01-21 20:18:03 +00:00
|
|
|
vtkm::TopologyElementTagCell(),
|
|
|
|
token);
|
2017-05-18 14:29:41 +00:00
|
|
|
|
|
|
|
vtkm::Id cells[2][4] = { { 0, 1, 4, 3 }, { 1, 2, 5, 4 } };
|
2015-08-25 15:03:44 +00:00
|
|
|
for (vtkm::Id cellIndex = 0; cellIndex < 2; cellIndex++)
|
|
|
|
{
|
2023-05-29 23:20:05 +00:00
|
|
|
vtkm::Id4 pointIds = pointToCell.GetIndices(pointToCell.FlatToLogicalVisitIndex(cellIndex));
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent localPointIndex = 0; localPointIndex < 4; localPointIndex++)
|
2015-08-25 15:03:44 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(pointIds[localPointIndex] == cells[cellIndex][localPointIndex],
|
|
|
|
"Incorrect point ID for cell");
|
2015-05-18 15:04:15 +00:00
|
|
|
}
|
2015-08-25 15:03:44 +00:00
|
|
|
}
|
2015-05-18 15:04:15 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id expectedCellIds[6][4] = { { 0, -1, -1, -1 }, { 0, 1, -1, -1 }, { 1, -1, -1, -1 },
|
|
|
|
{ 0, -1, -1, -1 }, { 0, 1, -1, -1 }, { 1, -1, -1, -1 } };
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-08-25 15:03:44 +00:00
|
|
|
for (vtkm::Id pointIndex = 0; pointIndex < 6; pointIndex++)
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::VecVariable<vtkm::Id, 4> retrievedCellIds =
|
2023-05-29 23:20:05 +00:00
|
|
|
cellToPoint.GetIndices(cellToPoint.FlatToLogicalVisitIndex(pointIndex));
|
2015-08-27 22:49:24 +00:00
|
|
|
VTKM_TEST_ASSERT(retrievedCellIds.GetNumberOfComponents() <= 4,
|
|
|
|
"Got wrong number of cell ids.");
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent cellIndex = 0; cellIndex < retrievedCellIds.GetNumberOfComponents();
|
2015-08-27 22:49:24 +00:00
|
|
|
cellIndex++)
|
2015-08-28 17:34:53 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(retrievedCellIds[cellIndex] == expectedCellIds[pointIndex][cellIndex],
|
|
|
|
"Incorrect cell ID for point");
|
2015-08-28 17:34:53 +00:00
|
|
|
}
|
2015-08-12 15:51:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
static void ThreeDimUniformTest()
|
2015-05-18 15:04:15 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
std::cout << "3D Uniform data set" << std::endl;
|
2015-08-25 15:03:44 +00:00
|
|
|
vtkm::cont::testing::MakeTestDataSet testDataSet;
|
2015-05-18 15:04:15 +00:00
|
|
|
|
2016-01-19 22:54:05 +00:00
|
|
|
vtkm::cont::DataSet dataSet = testDataSet.Make3DUniformDataSet0();
|
2015-05-20 19:26:10 +00:00
|
|
|
|
2016-01-14 19:01:05 +00:00
|
|
|
dataSet.PrintSummary(std::cout);
|
|
|
|
|
|
|
|
vtkm::cont::CellSetStructured<3> cellSet;
|
2022-01-04 23:42:55 +00:00
|
|
|
dataSet.GetCellSet().AsCellSet(cellSet);
|
2015-05-18 15:04:15 +00:00
|
|
|
|
2022-10-31 17:22:37 +00:00
|
|
|
VTKM_TEST_ASSERT(dataSet.GetNumberOfFields() == 3, "Incorrect number of fields");
|
2015-05-18 15:04:15 +00:00
|
|
|
|
2015-08-17 18:47:46 +00:00
|
|
|
VTKM_TEST_ASSERT(dataSet.GetNumberOfCoordinateSystems() == 1,
|
|
|
|
"Incorrect number of coordinate systems");
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(cellSet.GetNumberOfPoints() == 18, "Incorrect number of points");
|
2015-05-18 15:04:15 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(cellSet.GetNumberOfCells() == 4, "Incorrect number of cells");
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(cellSet.GetPointDimensions() == vtkm::Id3(3, 2, 3),
|
2016-01-20 16:24:31 +00:00
|
|
|
"Incorrect point dimensions");
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(cellSet.GetCellDimensions() == vtkm::Id3(2, 1, 2), "Incorrect cell dimensions");
|
2016-01-20 16:24:31 +00:00
|
|
|
|
2015-08-12 15:51:14 +00:00
|
|
|
try
|
|
|
|
{
|
2019-08-13 14:10:52 +00:00
|
|
|
dataSet.GetCellField("cellvar");
|
2015-08-12 15:51:14 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2022-03-17 17:02:37 +00:00
|
|
|
VTKM_TEST_FAIL("Failed to get field 'cellvar' with Association::Cells.");
|
2015-08-12 15:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2019-08-13 14:10:52 +00:00
|
|
|
dataSet.GetPointField("pointvar");
|
2015-08-12 15:51:14 +00:00
|
|
|
}
|
2015-11-03 03:24:57 +00:00
|
|
|
catch (...)
|
2015-08-12 15:51:14 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_FAIL("Failed to get field 'pointvar' with ASSOC_POINT_SET.");
|
2015-08-12 15:51:14 +00:00
|
|
|
}
|
|
|
|
|
2015-11-03 03:24:57 +00:00
|
|
|
vtkm::Id numCells = cellSet.GetNumberOfCells();
|
2015-08-25 15:03:44 +00:00
|
|
|
for (vtkm::Id cellIndex = 0; cellIndex < numCells; cellIndex++)
|
|
|
|
{
|
|
|
|
VTKM_TEST_ASSERT(cellSet.GetNumberOfPointsInCell(cellIndex) == 8,
|
|
|
|
"Incorrect number of cell indices");
|
2015-08-16 21:31:36 +00:00
|
|
|
vtkm::IdComponent shape = cellSet.GetCellShape();
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(shape == vtkm::CELL_SHAPE_HEXAHEDRON, "Incorrect element type.");
|
2015-08-25 15:03:44 +00:00
|
|
|
}
|
2015-05-18 15:04:15 +00:00
|
|
|
|
2020-01-21 20:18:03 +00:00
|
|
|
vtkm::cont::Token token;
|
|
|
|
|
2016-01-19 22:54:05 +00:00
|
|
|
//Test uniform connectivity.
|
2019-07-30 16:53:51 +00:00
|
|
|
vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagCell, vtkm::TopologyElementTagPoint, 3>
|
2017-05-26 17:53:28 +00:00
|
|
|
pointToCell = cellSet.PrepareForInput(vtkm::cont::DeviceAdapterTagSerial(),
|
2019-07-30 16:53:51 +00:00
|
|
|
vtkm::TopologyElementTagCell(),
|
2020-01-21 20:18:03 +00:00
|
|
|
vtkm::TopologyElementTagPoint(),
|
|
|
|
token);
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id expectedPointIds[8] = { 0, 1, 4, 3, 6, 7, 10, 9 };
|
|
|
|
vtkm::Vec<vtkm::Id, 8> retrievedPointIds = pointToCell.GetIndices(vtkm::Id3(0));
|
|
|
|
for (vtkm::IdComponent localPointIndex = 0; localPointIndex < 8; localPointIndex++)
|
2015-08-25 15:03:44 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(retrievedPointIds[localPointIndex] == expectedPointIds[localPointIndex],
|
|
|
|
"Incorrect point ID for cell");
|
2015-08-25 15:03:44 +00:00
|
|
|
}
|
2015-07-28 23:33:52 +00:00
|
|
|
|
2019-07-30 16:53:51 +00:00
|
|
|
vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell, 3>
|
2017-05-26 17:53:28 +00:00
|
|
|
cellToPoint = cellSet.PrepareForInput(vtkm::cont::DeviceAdapterTagSerial(),
|
2019-07-30 16:53:51 +00:00
|
|
|
vtkm::TopologyElementTagPoint(),
|
2020-01-21 20:18:03 +00:00
|
|
|
vtkm::TopologyElementTagCell(),
|
|
|
|
token);
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id retrievedCellIds[6] = { 0, -1, -1, -1, -1, -1 };
|
|
|
|
vtkm::VecVariable<vtkm::Id, 6> expectedCellIds = cellToPoint.GetIndices(vtkm::Id3(0));
|
2015-08-27 22:49:24 +00:00
|
|
|
VTKM_TEST_ASSERT(expectedCellIds.GetNumberOfComponents() <= 6,
|
|
|
|
"Got unexpected number of cell ids");
|
2015-08-25 15:03:44 +00:00
|
|
|
for (vtkm::IdComponent localPointIndex = 0;
|
2017-05-26 17:53:28 +00:00
|
|
|
localPointIndex < expectedCellIds.GetNumberOfComponents();
|
|
|
|
localPointIndex++)
|
2015-08-25 15:03:44 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(expectedCellIds[localPointIndex] == retrievedCellIds[localPointIndex],
|
|
|
|
"Incorrect cell ID for point");
|
2015-08-25 15:03:44 +00:00
|
|
|
}
|
2015-05-12 18:41:12 +00:00
|
|
|
}
|
|
|
|
|
2019-01-01 22:19:02 +00:00
|
|
|
int UnitTestDataSetUniform(int argc, char* argv[])
|
2015-05-12 18:41:12 +00:00
|
|
|
{
|
2019-01-01 22:19:02 +00:00
|
|
|
return vtkm::cont::testing::Testing::Run(TestDataSet_Uniform, argc, argv);
|
2015-05-14 16:22:39 +00:00
|
|
|
}
|