2015-05-12 18:41:12 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// Copyright 2014 Sandia Corporation.
|
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
2015-06-03 19:06:43 +00:00
|
|
|
// Copyright 2014 Los Alamos National Security.
|
2015-05-12 18:41:12 +00:00
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
|
|
|
// the U.S. Government retains certain rights in this software.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
|
|
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
|
|
|
// this software.
|
|
|
|
//============================================================================
|
|
|
|
|
2015-05-15 16:03:52 +00:00
|
|
|
#include <vtkm/CellType.h>
|
2015-08-02 21:59:44 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/CellSetStructured.h>
|
|
|
|
#include <vtkm/cont/DataSet.h>
|
|
|
|
#include <vtkm/cont/DeviceAdapterSerial.h>
|
|
|
|
|
|
|
|
#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/Testing.h>
|
|
|
|
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
|
|
|
|
2015-05-18 15:04:15 +00:00
|
|
|
static void TwoDimRegularTest();
|
|
|
|
static void ThreeDimRegularTest();
|
2015-05-12 18:41:12 +00:00
|
|
|
|
|
|
|
void TestDataSet_Regular()
|
|
|
|
{
|
|
|
|
std::cout << std::endl;
|
|
|
|
std::cout << "--TestDataSet_Regular--" << std::endl << std::endl;
|
2015-05-18 15:04:15 +00:00
|
|
|
|
|
|
|
TwoDimRegularTest();
|
|
|
|
ThreeDimRegularTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
TwoDimRegularTest()
|
|
|
|
{
|
|
|
|
std::cout<<"2D Regular data set"<<std::endl;
|
2015-07-28 23:33:52 +00:00
|
|
|
vtkm::cont::testing::MakeTestDataSet testDataSet;
|
2015-05-18 15:04:15 +00:00
|
|
|
|
2015-07-28 23:33:52 +00:00
|
|
|
vtkm::cont::DataSet dataSet = testDataSet.Make2DRegularDataSet0();
|
2015-05-18 15:04:15 +00:00
|
|
|
|
2015-07-28 23:33:52 +00:00
|
|
|
typedef vtkm::cont::CellSetStructured<2> CellSetType;
|
|
|
|
CellSetType cellSet = dataSet.GetCellSet(0).CastTo<CellSetType>();
|
2015-05-18 15:04:15 +00:00
|
|
|
|
2015-07-28 23:33:52 +00:00
|
|
|
VTKM_TEST_ASSERT(dataSet.GetNumberOfCellSets() == 1,
|
2015-05-18 15:04:15 +00:00
|
|
|
"Incorrect number of cell sets");
|
2015-07-28 23:33:52 +00:00
|
|
|
VTKM_TEST_ASSERT(dataSet.GetNumberOfFields() == 4,
|
2015-05-19 20:49:17 +00:00
|
|
|
"Incorrect number of fields");
|
2015-08-02 21:59:44 +00:00
|
|
|
VTKM_TEST_ASSERT(cellSet.GetNumberOfPoints() == 6,
|
2015-08-03 16:06:59 +00:00
|
|
|
"Incorrect number of points");
|
2015-08-02 21:59:44 +00:00
|
|
|
VTKM_TEST_ASSERT(cellSet.GetNumberOfCells() == 2,
|
2015-05-18 15:04:15 +00:00
|
|
|
"Incorrect number of cells");
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-08-12 15:51:14 +00:00
|
|
|
// test various field-getting methods and associations
|
2015-08-12 17:59:14 +00:00
|
|
|
const vtkm::cont::Field &f1 = dataSet.GetField("pointvar");
|
|
|
|
VTKM_TEST_ASSERT(f1.GetAssociation() == vtkm::cont::Field::ASSOC_POINTS,
|
|
|
|
"Association of 'pointvar' was not ASSOC_POINTS");
|
|
|
|
|
2015-08-12 15:51:14 +00:00
|
|
|
try
|
|
|
|
{
|
2015-08-12 17:59:14 +00:00
|
|
|
//const vtkm::cont::Field &f2 =
|
|
|
|
dataSet.GetField("cellvar", vtkm::cont::Field::ASSOC_CELL_SET);
|
2015-08-12 15:51:14 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
VTKM_TEST_FAIL("Failed to get field 'cellvar' with ASSOC_CELL_SET.");
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2015-08-12 17:59:14 +00:00
|
|
|
//const vtkm::cont::Field &f3 =
|
|
|
|
dataSet.GetField("cellvar", vtkm::cont::Field::ASSOC_POINTS);
|
2015-08-12 15:51:14 +00:00
|
|
|
VTKM_TEST_FAIL("Failed to get expected error for association mismatch.");
|
|
|
|
}
|
|
|
|
catch (vtkm::cont::ErrorControlBadValue error)
|
|
|
|
{
|
|
|
|
std::cout << "Caught expected error for association mismatch: "
|
|
|
|
<< std::endl << " " << error.GetMessage() << std::endl;
|
|
|
|
}
|
|
|
|
|
2015-08-02 21:59:44 +00:00
|
|
|
vtkm::Id numCells = cellSet.GetNumberOfCells();
|
2015-07-28 23:33:52 +00:00
|
|
|
for (vtkm::Id cellIndex = 0; cellIndex < numCells; cellIndex++)
|
2015-05-18 15:04:15 +00:00
|
|
|
{
|
2015-08-03 16:06:59 +00:00
|
|
|
VTKM_TEST_ASSERT(cellSet.GetNumberOfPointsInCell(cellIndex) == 4,
|
2015-07-28 23:33:52 +00:00
|
|
|
"Incorrect number of cell indices");
|
2015-08-03 16:06:59 +00:00
|
|
|
vtkm::CellType shape = cellSet.GetCellShape();
|
2015-07-28 23:33:52 +00:00
|
|
|
VTKM_TEST_ASSERT(shape == vtkm::VTKM_PIXEL, "Incorrect element type.");
|
2015-05-18 15:04:15 +00:00
|
|
|
}
|
|
|
|
|
2015-08-02 21:59:44 +00:00
|
|
|
vtkm::exec::ConnectivityStructured<
|
2015-07-31 19:59:37 +00:00
|
|
|
vtkm::TopologyElementTagPoint,
|
|
|
|
vtkm::TopologyElementTagCell,
|
2015-08-02 21:59:44 +00:00
|
|
|
2> pointToCell =
|
|
|
|
cellSet.PrepareForInput(
|
|
|
|
vtkm::cont::DeviceAdapterTagSerial(),
|
|
|
|
vtkm::TopologyElementTagPoint(),
|
|
|
|
vtkm::TopologyElementTagCell());
|
|
|
|
vtkm::exec::ConnectivityStructured<
|
2015-07-31 19:59:37 +00:00
|
|
|
vtkm::TopologyElementTagCell,
|
|
|
|
vtkm::TopologyElementTagPoint,
|
2015-08-02 21:59:44 +00:00
|
|
|
2> cellToPoint =
|
|
|
|
cellSet.PrepareForInput(
|
|
|
|
vtkm::cont::DeviceAdapterTagSerial(),
|
|
|
|
vtkm::TopologyElementTagCell(),
|
|
|
|
vtkm::TopologyElementTagPoint());
|
|
|
|
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-05-18 17:17:03 +00:00
|
|
|
vtkm::Id cells[2][4] = {{0,1,3,4}, {1,2,4,5}};
|
2015-08-12 15:51:14 +00:00
|
|
|
vtkm::Vec<vtkm::Id,4> pointIds;
|
2015-07-28 23:33:52 +00:00
|
|
|
for (vtkm::Id cellIndex = 0; cellIndex < 2; cellIndex++)
|
2015-05-18 15:04:15 +00:00
|
|
|
{
|
2015-08-12 15:51:14 +00:00
|
|
|
pointToCell.GetIndices(cellIndex, pointIds);
|
2015-08-03 16:06:59 +00:00
|
|
|
for (vtkm::IdComponent localPointIndex = 0;
|
|
|
|
localPointIndex < 4;
|
|
|
|
localPointIndex++)
|
2015-07-28 23:33:52 +00:00
|
|
|
{
|
2015-08-03 16:06:59 +00:00
|
|
|
VTKM_TEST_ASSERT(
|
|
|
|
pointIds[localPointIndex] == cells[cellIndex][localPointIndex],
|
|
|
|
"Incorrect point ID for cell");
|
2015-07-28 23:33:52 +00:00
|
|
|
}
|
2015-05-18 15:04:15 +00:00
|
|
|
}
|
|
|
|
|
2015-07-28 23:33:52 +00:00
|
|
|
vtkm::Id expectedCellIds[6][4] = {{0,-1,-1,-1},
|
|
|
|
{0,1,-1,-1},
|
|
|
|
{0,-1,-1,-1},
|
|
|
|
{0,1,-1,-1},
|
|
|
|
{2,-1,-1,-1},
|
|
|
|
{2,3,-1,-1}};
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-07-28 23:33:52 +00:00
|
|
|
for (vtkm::Id pointIndex = 0; pointIndex < 6; pointIndex++)
|
2015-05-18 15:04:15 +00:00
|
|
|
{
|
2015-08-12 15:51:14 +00:00
|
|
|
vtkm::Vec<vtkm::Id,4> retrievedCellIds;
|
|
|
|
cellToPoint.GetIndices(pointIndex, retrievedCellIds);
|
2015-07-28 23:33:52 +00:00
|
|
|
for (vtkm::IdComponent cellIndex = 0; cellIndex < 4; cellIndex++)
|
|
|
|
VTKM_TEST_ASSERT(
|
|
|
|
retrievedCellIds[cellIndex] == expectedCellIds[pointIndex][cellIndex],
|
2015-08-03 16:06:59 +00:00
|
|
|
"Incorrect cell ID for point");
|
2015-05-18 15:04:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ThreeDimRegularTest()
|
|
|
|
{
|
|
|
|
std::cout<<"3D Regular data set"<<std::endl;
|
2015-07-28 23:33:52 +00:00
|
|
|
vtkm::cont::testing::MakeTestDataSet testDataSet;
|
2015-05-18 15:04:15 +00:00
|
|
|
|
2015-07-28 23:33:52 +00:00
|
|
|
vtkm::cont::DataSet dataSet = testDataSet.Make3DRegularDataSet0();
|
2015-05-20 19:26:10 +00:00
|
|
|
|
2015-07-28 23:33:52 +00:00
|
|
|
typedef vtkm::cont::CellSetStructured<3> CellSetType;
|
|
|
|
CellSetType cellSet = dataSet.GetCellSet(0).CastTo<CellSetType>();
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-07-28 23:33:52 +00:00
|
|
|
VTKM_TEST_ASSERT(dataSet.GetNumberOfCellSets() == 1,
|
2015-05-18 15:04:15 +00:00
|
|
|
"Incorrect number of cell sets");
|
|
|
|
|
2015-07-28 23:33:52 +00:00
|
|
|
VTKM_TEST_ASSERT(dataSet.GetNumberOfFields() == 5,
|
2015-05-18 15:04:15 +00:00
|
|
|
"Incorrect number of fields");
|
|
|
|
|
2015-08-02 21:59:44 +00:00
|
|
|
VTKM_TEST_ASSERT(cellSet.GetNumberOfPoints() == 18,
|
2015-08-03 16:06:59 +00:00
|
|
|
"Incorrect number of points");
|
2015-05-18 15:04:15 +00:00
|
|
|
|
2015-08-02 21:59:44 +00:00
|
|
|
VTKM_TEST_ASSERT(cellSet.GetNumberOfCells() == 4,
|
2015-05-18 15:04:15 +00:00
|
|
|
"Incorrect number of cells");
|
2015-05-28 19:30:13 +00:00
|
|
|
|
2015-08-12 15:51:14 +00:00
|
|
|
// test various field-getting methods and associations
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const vtkm::cont::Field &f2 = dataSet.GetField("cellvar",
|
|
|
|
vtkm::cont::Field::ASSOC_CELL_SET);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
VTKM_TEST_FAIL("Failed to get field 'cellvar' with ASSOC_CELL_SET.");
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const vtkm::cont::Field &f2 = dataSet.GetField("cellvar",
|
|
|
|
vtkm::cont::Field::ASSOC_POINTS);
|
|
|
|
VTKM_TEST_FAIL("Failed to get expected error for association mismatch.");
|
|
|
|
}
|
|
|
|
catch (vtkm::cont::ErrorControlBadValue error)
|
|
|
|
{
|
|
|
|
std::cout << "Caught expected error for association mismatch: "
|
|
|
|
<< std::endl << " " << error.GetMessage() << std::endl;
|
|
|
|
}
|
|
|
|
|
2015-08-02 21:59:44 +00:00
|
|
|
vtkm::Id numCells = cellSet.GetNumberOfCells();
|
2015-07-28 23:33:52 +00:00
|
|
|
for (vtkm::Id cellIndex = 0; cellIndex < numCells; cellIndex++)
|
2015-05-18 15:04:15 +00:00
|
|
|
{
|
2015-08-03 16:06:59 +00:00
|
|
|
VTKM_TEST_ASSERT(cellSet.GetNumberOfPointsInCell(cellIndex) == 8,
|
2015-07-28 23:33:52 +00:00
|
|
|
"Incorrect number of cell indices");
|
2015-08-03 16:06:59 +00:00
|
|
|
vtkm::CellType shape = cellSet.GetCellShape();
|
2015-07-28 23:33:52 +00:00
|
|
|
VTKM_TEST_ASSERT(shape == vtkm::VTKM_VOXEL, "Incorrect element type.");
|
2015-05-18 15:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Test regular connectivity.
|
2015-08-02 21:59:44 +00:00
|
|
|
vtkm::exec::ConnectivityStructured<
|
2015-07-31 19:59:37 +00:00
|
|
|
vtkm::TopologyElementTagPoint,
|
|
|
|
vtkm::TopologyElementTagCell,
|
2015-08-02 21:59:44 +00:00
|
|
|
3> pointToCell =
|
|
|
|
cellSet.PrepareForInput(
|
|
|
|
vtkm::cont::DeviceAdapterTagSerial(),
|
|
|
|
vtkm::TopologyElementTagPoint(),
|
|
|
|
vtkm::TopologyElementTagCell());
|
2015-07-28 23:33:52 +00:00
|
|
|
vtkm::Id expectedPointIds[8] = {0,1,3,4,6,7,9,10};
|
2015-08-12 15:51:14 +00:00
|
|
|
vtkm::Vec<vtkm::Id,8> retrievedPointIds;
|
|
|
|
pointToCell.GetIndices(0, retrievedPointIds);
|
2015-08-03 16:06:59 +00:00
|
|
|
for (vtkm::IdComponent localPointIndex = 0;
|
|
|
|
localPointIndex < 8;
|
|
|
|
localPointIndex++)
|
2015-07-28 23:33:52 +00:00
|
|
|
{
|
|
|
|
VTKM_TEST_ASSERT(
|
2015-08-03 16:06:59 +00:00
|
|
|
retrievedPointIds[localPointIndex] == expectedPointIds[localPointIndex],
|
|
|
|
"Incorrect point ID for cell");
|
2015-07-28 23:33:52 +00:00
|
|
|
}
|
|
|
|
|
2015-08-02 21:59:44 +00:00
|
|
|
vtkm::exec::ConnectivityStructured<
|
2015-07-31 19:59:37 +00:00
|
|
|
vtkm::TopologyElementTagCell,
|
|
|
|
vtkm::TopologyElementTagPoint,
|
2015-08-02 21:59:44 +00:00
|
|
|
3> cellToPoint =
|
|
|
|
cellSet.PrepareForInput(
|
|
|
|
vtkm::cont::DeviceAdapterTagSerial(),
|
|
|
|
vtkm::TopologyElementTagCell(),
|
|
|
|
vtkm::TopologyElementTagPoint());
|
2015-08-12 15:51:14 +00:00
|
|
|
vtkm::Vec<vtkm::Id,8> expectedCellIds;
|
|
|
|
vtkm::Id retrievedCellIds[8] = {0,-1,-1,-1,-1,-1,-1,-1};
|
|
|
|
cellToPoint.GetIndices(0, expectedCellIds);
|
2015-08-03 16:06:59 +00:00
|
|
|
for (vtkm::IdComponent localPointIndex = 0;
|
2015-08-12 15:51:14 +00:00
|
|
|
localPointIndex < 8;
|
2015-08-03 16:06:59 +00:00
|
|
|
localPointIndex++)
|
2015-07-28 23:33:52 +00:00
|
|
|
{
|
|
|
|
VTKM_TEST_ASSERT(
|
2015-08-03 16:06:59 +00:00
|
|
|
expectedCellIds[localPointIndex] == retrievedCellIds[localPointIndex],
|
|
|
|
"Incorrect cell ID for point");
|
2015-07-28 23:33:52 +00:00
|
|
|
}
|
2015-05-12 18:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int UnitTestDataSetRegular(int, char *[])
|
|
|
|
{
|
|
|
|
return vtkm::cont::testing::Testing::Run(TestDataSet_Regular);
|
2015-05-14 16:22:39 +00:00
|
|
|
}
|