2016-12-02 03:08:18 +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 2016 Sandia Corporation.
|
|
|
|
// Copyright 2016 UT-Battelle, LLC.
|
|
|
|
// Copyright 2016 Los Alamos National Security.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/exec/CellEdge.h>
|
|
|
|
#include <vtkm/exec/CellFace.h>
|
|
|
|
|
|
|
|
#include <vtkm/CellShape.h>
|
|
|
|
#include <vtkm/CellTraits.h>
|
|
|
|
|
|
|
|
#include <vtkm/exec/FunctorBase.h>
|
|
|
|
|
|
|
|
#include <vtkm/testing/Testing.h>
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2016-12-02 03:08:18 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
using EdgeType = vtkm::Vec<vtkm::IdComponent, 2>;
|
2016-12-02 03:08:18 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
void MakeEdgeCononical(EdgeType& edge)
|
2016-12-02 03:08:18 +00:00
|
|
|
{
|
|
|
|
if (edge[1] < edge[0])
|
|
|
|
{
|
|
|
|
std::swap(edge[0], edge[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TestCellFacesFunctor
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename CellShapeTag>
|
2017-05-26 17:53:28 +00:00
|
|
|
void DoTest(vtkm::IdComponent numPoints,
|
|
|
|
CellShapeTag shape,
|
2016-12-02 03:08:18 +00:00
|
|
|
vtkm::CellTopologicalDimensionsTag<3>) const
|
|
|
|
{
|
|
|
|
// Stuff to fake running in the execution environment.
|
|
|
|
char messageBuffer[256];
|
|
|
|
messageBuffer[0] = '\0';
|
|
|
|
vtkm::exec::internal::ErrorMessageBuffer errorMessage(messageBuffer, 256);
|
|
|
|
vtkm::exec::FunctorBase workletProxy;
|
|
|
|
workletProxy.SetErrorMessageBuffer(errorMessage);
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::IdComponent numEdges = vtkm::exec::CellEdgeNumberOfEdges(numPoints, shape, workletProxy);
|
2016-12-02 03:08:18 +00:00
|
|
|
VTKM_TEST_ASSERT(numEdges > 0, "No edges?");
|
|
|
|
|
|
|
|
std::set<EdgeType> edgeSet;
|
|
|
|
for (vtkm::IdComponent edgeIndex = 0; edgeIndex < numEdges; edgeIndex++)
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
EdgeType edge = vtkm::exec::CellEdgeLocalIndices(numPoints, edgeIndex, shape, workletProxy);
|
2016-12-02 03:08:18 +00:00
|
|
|
VTKM_TEST_ASSERT(edge[0] >= 0, "Bad index in edge.");
|
|
|
|
VTKM_TEST_ASSERT(edge[0] < numPoints, "Bad index in edge.");
|
|
|
|
VTKM_TEST_ASSERT(edge[1] >= 0, "Bad index in edge.");
|
|
|
|
VTKM_TEST_ASSERT(edge[1] < numPoints, "Bad index in edge.");
|
|
|
|
VTKM_TEST_ASSERT(edge[0] != edge[1], "Degenerate edge.");
|
|
|
|
MakeEdgeCononical(edge);
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(edge[0] < edge[1], "Internal test error: MakeEdgeCononical failed");
|
|
|
|
VTKM_TEST_ASSERT(edgeSet.find(edge) == edgeSet.end(), "Found duplicate edge");
|
2016-12-02 03:08:18 +00:00
|
|
|
edgeSet.insert(edge);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::IdComponent numFaces = vtkm::exec::CellFaceNumberOfFaces(shape, workletProxy);
|
2016-12-02 03:08:18 +00:00
|
|
|
VTKM_TEST_ASSERT(numFaces > 0, "No faces?");
|
|
|
|
|
|
|
|
std::set<EdgeType> edgesFoundInFaces;
|
|
|
|
for (vtkm::IdComponent faceIndex = 0; faceIndex < numFaces; faceIndex++)
|
|
|
|
{
|
|
|
|
vtkm::VecCConst<vtkm::IdComponent> facePoints =
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::exec::CellFaceLocalIndices(faceIndex, shape, workletProxy);
|
2016-12-02 03:08:18 +00:00
|
|
|
vtkm::IdComponent numPointsInFace = facePoints.GetNumberOfComponents();
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(numPointsInFace >= 3, "Face has fewer points than a triangle.");
|
2016-12-02 03:08:18 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent pointIndex = 0; pointIndex < numPointsInFace; pointIndex++)
|
2016-12-02 03:08:18 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(facePoints[pointIndex] >= 0, "Invalid point index for face.");
|
|
|
|
VTKM_TEST_ASSERT(facePoints[pointIndex] <= numPoints, "Invalid point index for face.");
|
2016-12-02 03:08:18 +00:00
|
|
|
EdgeType edge;
|
2017-05-18 14:29:41 +00:00
|
|
|
if (pointIndex < numPointsInFace - 1)
|
2016-12-02 03:08:18 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
edge = EdgeType(facePoints[pointIndex], facePoints[pointIndex + 1]);
|
2016-12-02 03:08:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
edge = EdgeType(facePoints[0], facePoints[pointIndex]);
|
|
|
|
}
|
|
|
|
MakeEdgeCononical(edge);
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(edgeSet.find(edge) != edgeSet.end(), "Edge in face not in cell's edges");
|
2016-12-02 03:08:18 +00:00
|
|
|
edgesFoundInFaces.insert(edge);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VTKM_TEST_ASSERT(edgesFoundInFaces.size() == edgeSet.size(),
|
|
|
|
"Faces did not contain all edges in cell");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Case of cells that have 2 dimensions (no faces)
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename CellShapeTag>
|
2017-05-26 17:53:28 +00:00
|
|
|
void DoTest(vtkm::IdComponent numPoints,
|
|
|
|
CellShapeTag shape,
|
2016-12-02 03:08:18 +00:00
|
|
|
vtkm::CellTopologicalDimensionsTag<2>) const
|
|
|
|
{
|
|
|
|
// Stuff to fake running in the execution environment.
|
|
|
|
char messageBuffer[256];
|
|
|
|
messageBuffer[0] = '\0';
|
|
|
|
vtkm::exec::internal::ErrorMessageBuffer errorMessage(messageBuffer, 256);
|
|
|
|
vtkm::exec::FunctorBase workletProxy;
|
|
|
|
workletProxy.SetErrorMessageBuffer(errorMessage);
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::IdComponent numEdges = vtkm::exec::CellEdgeNumberOfEdges(numPoints, shape, workletProxy);
|
|
|
|
VTKM_TEST_ASSERT(numEdges == numPoints, "Polygons should have same number of points and edges");
|
2016-12-02 03:08:18 +00:00
|
|
|
|
|
|
|
std::set<EdgeType> edgeSet;
|
|
|
|
for (vtkm::IdComponent edgeIndex = 0; edgeIndex < numEdges; edgeIndex++)
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
EdgeType edge = vtkm::exec::CellEdgeLocalIndices(numPoints, edgeIndex, shape, workletProxy);
|
2016-12-02 03:08:18 +00:00
|
|
|
VTKM_TEST_ASSERT(edge[0] >= 0, "Bad index in edge.");
|
|
|
|
VTKM_TEST_ASSERT(edge[0] < numPoints, "Bad index in edge.");
|
|
|
|
VTKM_TEST_ASSERT(edge[1] >= 0, "Bad index in edge.");
|
|
|
|
VTKM_TEST_ASSERT(edge[1] < numPoints, "Bad index in edge.");
|
|
|
|
VTKM_TEST_ASSERT(edge[0] != edge[1], "Degenerate edge.");
|
|
|
|
MakeEdgeCononical(edge);
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(edge[0] < edge[1], "Internal test error: MakeEdgeCononical failed");
|
|
|
|
VTKM_TEST_ASSERT(edgeSet.find(edge) == edgeSet.end(), "Found duplicate edge");
|
2016-12-02 03:08:18 +00:00
|
|
|
edgeSet.insert(edge);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::IdComponent numFaces = vtkm::exec::CellFaceNumberOfFaces(shape, workletProxy);
|
2016-12-02 03:08:18 +00:00
|
|
|
VTKM_TEST_ASSERT(numFaces == 0, "Non 3D shape should have no faces");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Less important case of cells that have less than 2 dimensions
|
|
|
|
// (no faces or edges)
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename CellShapeTag, vtkm::IdComponent NumDimensions>
|
2017-05-26 17:53:28 +00:00
|
|
|
void DoTest(vtkm::IdComponent numPoints,
|
|
|
|
CellShapeTag shape,
|
2016-12-02 03:08:18 +00:00
|
|
|
vtkm::CellTopologicalDimensionsTag<NumDimensions>) const
|
|
|
|
{
|
|
|
|
// Stuff to fake running in the execution environment.
|
|
|
|
char messageBuffer[256];
|
|
|
|
messageBuffer[0] = '\0';
|
|
|
|
vtkm::exec::internal::ErrorMessageBuffer errorMessage(messageBuffer, 256);
|
|
|
|
vtkm::exec::FunctorBase workletProxy;
|
|
|
|
workletProxy.SetErrorMessageBuffer(errorMessage);
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::IdComponent numEdges = vtkm::exec::CellEdgeNumberOfEdges(numPoints, shape, workletProxy);
|
2016-12-02 03:08:18 +00:00
|
|
|
VTKM_TEST_ASSERT(numEdges == 0, "0D or 1D shape should have no edges");
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::IdComponent numFaces = vtkm::exec::CellFaceNumberOfFaces(shape, workletProxy);
|
2016-12-02 03:08:18 +00:00
|
|
|
VTKM_TEST_ASSERT(numFaces == 0, "Non 3D shape should have no faces");
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename CellShapeTag>
|
|
|
|
void TryShapeWithNumPoints(vtkm::IdComponent numPoints, CellShapeTag) const
|
2016-12-02 03:08:18 +00:00
|
|
|
{
|
|
|
|
std::cout << "--- Test shape tag directly"
|
2017-05-18 14:29:41 +00:00
|
|
|
<< " (" << numPoints << " points)" << std::endl;
|
2017-05-26 17:53:28 +00:00
|
|
|
this->DoTest(numPoints,
|
|
|
|
CellShapeTag(),
|
2017-05-18 14:29:41 +00:00
|
|
|
typename vtkm::CellTraits<CellShapeTag>::TopologicalDimensionsTag());
|
2016-12-02 03:08:18 +00:00
|
|
|
|
|
|
|
std::cout << "--- Test generic shape tag"
|
2017-05-18 14:29:41 +00:00
|
|
|
<< " (" << numPoints << " points)" << std::endl;
|
2017-05-26 17:53:28 +00:00
|
|
|
this->DoTest(numPoints,
|
|
|
|
vtkm::CellShapeTagGeneric(CellShapeTag::Id),
|
2017-05-18 14:29:41 +00:00
|
|
|
typename vtkm::CellTraits<CellShapeTag>::TopologicalDimensionsTag());
|
2016-12-02 03:08:18 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename CellShapeTag>
|
2016-12-02 03:08:18 +00:00
|
|
|
void operator()(CellShapeTag) const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
this->TryShapeWithNumPoints(vtkm::CellTraits<CellShapeTag>::NUM_POINTS, CellShapeTag());
|
2016-12-02 03:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void operator()(vtkm::CellShapeTagPolygon) const
|
|
|
|
{
|
|
|
|
for (vtkm::IdComponent numPoints = 3; numPoints < 7; numPoints++)
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
this->TryShapeWithNumPoints(numPoints, vtkm::CellShapeTagPolygon());
|
2016-12-02 03:08:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestAllShapes()
|
|
|
|
{
|
|
|
|
vtkm::testing::Testing::TryAllCellShapes(TestCellFacesFunctor());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
int UnitTestCellEdgeFace(int, char* [])
|
2016-12-02 03:08:18 +00:00
|
|
|
{
|
|
|
|
return vtkm::testing::Testing::Run(TestAllShapes);
|
|
|
|
}
|