Commit 601a839d authored by Robert Maynard's avatar Robert Maynard

VTK-m uses static const/constexpr when supported ( so not on cuda 7.5 )

These changes now allow VTK-m to compile on CUDA 7.5 by using const arrays,
when compiling with CUDA 8+ support we upgrade to static const arrays, and
lastly when CUDA is disabled we fully elevate to static constexpr.
parent 505e7aa1
......@@ -25,6 +25,7 @@
#include <vtkm/TypeTraits.h>
#include <vtkm/Types.h>
#include <vtkm/VecTraits.h>
#include <vtkm/internal/ExportMacros.h>
namespace vtkm
{
......@@ -56,6 +57,18 @@ struct VecAxisAlignedPointCoordinatesNumComponents<3>
static const vtkm::IdComponent NUM_COMPONENTS = 8;
};
struct VecAxisAlignedPointCoordinatesOffsetTable
{
VTKM_EXEC_CONT vtkm::FloatDefault Get(vtkm::Int32 i, vtkm::Int32 j) const
{
VTKM_STATIC_CONSTEXPR_ARRAY vtkm::FloatDefault offsetTable[8][3] = {
{ 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f }, { 1.0f, 0.0f, 1.0f }, { 1.0f, 1.0f, 1.0f }, { 0.0f, 1.0f, 1.0f }
};
return offsetTable[i][j];
}
};
} // namespace detail
/// \brief An implicit vector for point coordinates in axis aligned cells. For
......@@ -104,15 +117,10 @@ public:
VTKM_EXEC_CONT
ComponentType operator[](vtkm::IdComponent index) const
{
static const vtkm::FloatDefault VecAxisAlignedPointCoordinatesOffsetTable[8][3] = {
{ 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f }, { 1.0f, 0.0f, 1.0f }, { 1.0f, 1.0f, 1.0f }, { 0.0f, 1.0f, 1.0f }
};
const auto& offset = VecAxisAlignedPointCoordinatesOffsetTable[index];
return ComponentType(this->Origin[0] + offset[0] * this->Spacing[0],
this->Origin[1] + offset[1] * this->Spacing[1],
this->Origin[2] + offset[2] * this->Spacing[2]);
detail::VecAxisAlignedPointCoordinatesOffsetTable table;
return ComponentType(this->Origin[0] + table.Get(index, 0) * this->Spacing[0],
this->Origin[1] + table.Get(index, 1) * this->Spacing[1],
this->Origin[2] + table.Get(index, 2) * this->Spacing[2]);
}
VTKM_EXEC_CONT
......
......@@ -59,7 +59,7 @@ VTKM_EXEC_CONT vtkm::Vec<ValueType, N> Lerp(const vtkm::Vec<ValueType, N>& value
const vtkm::Vec<ValueType, N>& value1,
const vtkm::Vec<ValueType, N>& weight)
{
static const vtkm::Vec<ValueType, N> One(ValueType(1));
const vtkm::Vec<ValueType, N> One(ValueType(1));
return (One - weight) * value0 + weight * value1;
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -94,23 +94,28 @@ struct TestCellFacesFunctor
std::set<EdgeType> edgesFoundInFaces;
for (vtkm::IdComponent faceIndex = 0; faceIndex < numFaces; faceIndex++)
{
vtkm::VecCConst<vtkm::IdComponent> facePoints =
vtkm::exec::CellFaceLocalIndices(faceIndex, shape, workletProxy);
vtkm::IdComponent numPointsInFace = facePoints.GetNumberOfComponents();
vtkm::exec::detail::CellFaceTables table;
const vtkm::IdComponent numPointsInFace =
vtkm::exec::CellFaceNumberOfPoints(faceIndex, shape, workletProxy);
VTKM_TEST_ASSERT(numPointsInFace >= 3, "Face has fewer points than a triangle.");
for (vtkm::IdComponent pointIndex = 0; pointIndex < numPointsInFace; pointIndex++)
{
VTKM_TEST_ASSERT(facePoints[pointIndex] >= 0, "Invalid point index for face.");
VTKM_TEST_ASSERT(facePoints[pointIndex] <= numPoints, "Invalid point index for face.");
VTKM_TEST_ASSERT(table.PointsInFace(shape.Id, faceIndex, pointIndex) >= 0,
"Invalid point index for face.");
VTKM_TEST_ASSERT(table.PointsInFace(shape.Id, faceIndex, pointIndex) <= numPoints,
"Invalid point index for face.");
EdgeType edge;
if (pointIndex < numPointsInFace - 1)
{
edge = EdgeType(facePoints[pointIndex], facePoints[pointIndex + 1]);
edge = EdgeType(table.PointsInFace(shape.Id, faceIndex, pointIndex),
table.PointsInFace(shape.Id, faceIndex, pointIndex + 1));
}
else
{
edge = EdgeType(facePoints[0], facePoints[pointIndex]);
edge = EdgeType(table.PointsInFace(shape.Id, faceIndex, 0),
table.PointsInFace(shape.Id, faceIndex, pointIndex));
}
MakeEdgeCanonical(edge);
VTKM_TEST_ASSERT(edgeSet.find(edge) != edgeSet.end(), "Edge in face not in cell's edges");
......
......@@ -78,12 +78,17 @@
#endif
// cuda 7.5 doesn't support static const or static constexpr variables
// that exist inside methods or classes, so in those cases we gracefully
// fall back to using just constexpr
// that exist inside methods or classes, so in those cases we have to use
// just constexpr
#if defined(VTKM_CUDA_VERSION_MAJOR) && (VTKM_CUDA_VERSION_MAJOR < 8)
#define VTKM_STATIC_CONSTEXPR constexpr
#define VTKM_STATIC_CONSTEXPR_ARRAY constexpr
// cuda 8+ doesn't support static constexpr pointers/fixed size arrays
// that exist inside methods or classes, so in those cases we gracefully
// fall back to static const
#elif defined(VTKM_CUDA_VERSION_MAJOR) && (VTKM_CUDA_VERSION_MAJOR >= 8)
#define VTKM_STATIC_CONSTEXPR_ARRAY static const
#else
#define VTKM_STATIC_CONSTEXPR static constexpr
#define VTKM_STATIC_CONSTEXPR_ARRAY static constexpr
#endif
// Clang will warn about weak vtables (-Wweak-vtables) on exception classes,
......
......@@ -47,10 +47,10 @@ VTKM_EXEC_CONT inline void IntersectZoo(T xpoints[8],
vtkm::Int32 kx, ky, kz;
WaterTight<T> intersector;
intersector.FindDir(dir, sx, sy, sz, kx, ky, kz);
const vtkm::Int32 tableOffset =
CellTables::Get().ZooLookUp[CellTables::Get().CellTypeLookUp[shapeType]][0];
const vtkm::Int32 numTriangles =
CellTables::Get().ZooLookUp[CellTables::Get().CellTypeLookUp[shapeType]][1];
CellTables tables;
const vtkm::Int32 tableOffset = tables.ZooLookUp(tables.CellTypeLookUp(shapeType), 0);
const vtkm::Int32 numTriangles = tables.ZooLookUp(tables.CellTypeLookUp(shapeType), 1);
// Decompose each face into two triangles
for (int i = 0; i < 6; ++i)
distances[i] = -1.;
......@@ -58,16 +58,16 @@ VTKM_EXEC_CONT inline void IntersectZoo(T xpoints[8],
{
const vtkm::Int32 offset = tableOffset + i;
vtkm::Vec<T, 3> a, c, b;
a[0] = xpoints[CellTables::Get().ZooTable[offset][1]];
a[1] = ypoints[CellTables::Get().ZooTable[offset][1]];
a[2] = zpoints[CellTables::Get().ZooTable[offset][1]];
b[0] = xpoints[CellTables::Get().ZooTable[offset][2]];
b[1] = ypoints[CellTables::Get().ZooTable[offset][2]];
b[2] = zpoints[CellTables::Get().ZooTable[offset][2]];
c[0] = xpoints[CellTables::Get().ZooTable[offset][3]];
c[1] = ypoints[CellTables::Get().ZooTable[offset][3]];
c[2] = zpoints[CellTables::Get().ZooTable[offset][3]];
const vtkm::Int32 faceId = CellTables::Get().ZooTable[offset][0];
a[0] = xpoints[tables.ZooTable(offset, 1)];
a[1] = ypoints[tables.ZooTable(offset, 1)];
a[2] = zpoints[tables.ZooTable(offset, 1)];
b[0] = xpoints[tables.ZooTable(offset, 2)];
b[1] = ypoints[tables.ZooTable(offset, 2)];
b[2] = zpoints[tables.ZooTable(offset, 2)];
c[0] = xpoints[tables.ZooTable(offset, 3)];
c[1] = ypoints[tables.ZooTable(offset, 3)];
c[2] = zpoints[tables.ZooTable(offset, 3)];
const vtkm::Int32 faceId = tables.ZooTable(offset, 0);
T distance = -1.f;
T uNotUsed, vNotUsed;
......@@ -109,22 +109,24 @@ VTKM_EXEC_CONT inline void IntersectHex(T xpoints[8],
vtkm::Int32 kx, ky, kz;
WaterTight<T> intersector;
intersector.FindDir(dir, sx, sy, sz, kx, ky, kz);
CellTables tables;
// Decompose each face into two triangles
for (int i = 0; i < 6; ++i)
{
vtkm::Vec<T, 3> a, c, b, d;
a[0] = xpoints[CellTables::Get().ShapesFaceList[i][1]];
a[1] = ypoints[CellTables::Get().ShapesFaceList[i][1]];
a[2] = zpoints[CellTables::Get().ShapesFaceList[i][1]];
b[0] = xpoints[CellTables::Get().ShapesFaceList[i][2]];
b[1] = ypoints[CellTables::Get().ShapesFaceList[i][2]];
b[2] = zpoints[CellTables::Get().ShapesFaceList[i][2]];
c[0] = xpoints[CellTables::Get().ShapesFaceList[i][3]];
c[1] = ypoints[CellTables::Get().ShapesFaceList[i][3]];
c[2] = zpoints[CellTables::Get().ShapesFaceList[i][3]];
d[0] = xpoints[CellTables::Get().ShapesFaceList[i][4]];
d[1] = ypoints[CellTables::Get().ShapesFaceList[i][4]];
d[2] = zpoints[CellTables::Get().ShapesFaceList[i][4]];
a[0] = xpoints[tables.ShapesFaceList(i, 1)];
a[1] = ypoints[tables.ShapesFaceList(i, 1)];
a[2] = zpoints[tables.ShapesFaceList(i, 1)];
b[0] = xpoints[tables.ShapesFaceList(i, 2)];
b[1] = ypoints[tables.ShapesFaceList(i, 2)];
b[2] = zpoints[tables.ShapesFaceList(i, 2)];
c[0] = xpoints[tables.ShapesFaceList(i, 3)];
c[1] = ypoints[tables.ShapesFaceList(i, 3)];
c[2] = zpoints[tables.ShapesFaceList(i, 3)];
d[0] = xpoints[tables.ShapesFaceList(i, 4)];
d[1] = ypoints[tables.ShapesFaceList(i, 4)];
d[2] = zpoints[tables.ShapesFaceList(i, 4)];
T distance = -1.f;
distances[i] = distance; //init to -1
......@@ -191,20 +193,20 @@ VTKM_EXEC_CONT inline void IntersectTet(T xpoints[8],
WaterTight<T> intersector;
intersector.FindDir(dir, sx, sy, sz, kx, ky, kz);
const vtkm::Int32 tableOffset =
CellTables::Get().FaceLookUp[CellTables::Get().CellTypeLookUp[CELL_SHAPE_TETRA]][0];
CellTables tables;
const vtkm::Int32 tableOffset = tables.FaceLookUp(tables.CellTypeLookUp(CELL_SHAPE_TETRA), 0);
for (vtkm::Int32 i = 0; i < 4; ++i)
{
vtkm::Vec<T, 3> a, c, b;
a[0] = xpoints[CellTables::Get().ShapesFaceList[i + tableOffset][1]];
a[1] = ypoints[CellTables::Get().ShapesFaceList[i + tableOffset][1]];
a[2] = zpoints[CellTables::Get().ShapesFaceList[i + tableOffset][1]];
b[0] = xpoints[CellTables::Get().ShapesFaceList[i + tableOffset][2]];
b[1] = ypoints[CellTables::Get().ShapesFaceList[i + tableOffset][2]];
b[2] = zpoints[CellTables::Get().ShapesFaceList[i + tableOffset][2]];
c[0] = xpoints[CellTables::Get().ShapesFaceList[i + tableOffset][3]];
c[1] = ypoints[CellTables::Get().ShapesFaceList[i + tableOffset][3]];
c[2] = zpoints[CellTables::Get().ShapesFaceList[i + tableOffset][3]];
a[0] = xpoints[tables.ShapesFaceList(i + tableOffset, 1)];
a[1] = ypoints[tables.ShapesFaceList(i + tableOffset, 1)];
a[2] = zpoints[tables.ShapesFaceList(i + tableOffset, 1)];
b[0] = xpoints[tables.ShapesFaceList(i + tableOffset, 2)];
b[1] = ypoints[tables.ShapesFaceList(i + tableOffset, 2)];
b[2] = zpoints[tables.ShapesFaceList(i + tableOffset, 2)];
c[0] = xpoints[tables.ShapesFaceList(i + tableOffset, 3)];
c[1] = ypoints[tables.ShapesFaceList(i + tableOffset, 3)];
c[2] = zpoints[tables.ShapesFaceList(i + tableOffset, 3)];
T distance = -1.f;
distances[i] = distance; //init to -1
......@@ -248,24 +250,24 @@ VTKM_EXEC_CONT inline void IntersectWedge(T xpoints[8],
WaterTight<T> intersector;
intersector.FindDir(dir, sx, sy, sz, kx, ky, kz);
// TODO: try two sepate loops to see performance impact
const vtkm::Int32 tableOffset =
CellTables::Get().FaceLookUp[CellTables::Get().CellTypeLookUp[CELL_SHAPE_WEDGE]][0];
CellTables tables;
const vtkm::Int32 tableOffset = tables.FaceLookUp(tables.CellTypeLookUp(CELL_SHAPE_WEDGE), 0);
// Decompose each face into two triangles
for (int i = 0; i < 5; ++i)
{
vtkm::Vec<T, 3> a, c, b, d;
a[0] = xpoints[CellTables::Get().ShapesFaceList[i + tableOffset][1]];
a[1] = ypoints[CellTables::Get().ShapesFaceList[i + tableOffset][1]];
a[2] = zpoints[CellTables::Get().ShapesFaceList[i + tableOffset][1]];
b[0] = xpoints[CellTables::Get().ShapesFaceList[i + tableOffset][2]];
b[1] = ypoints[CellTables::Get().ShapesFaceList[i + tableOffset][2]];
b[2] = zpoints[CellTables::Get().ShapesFaceList[i + tableOffset][2]];
c[0] = xpoints[CellTables::Get().ShapesFaceList[i + tableOffset][3]];
c[1] = ypoints[CellTables::Get().ShapesFaceList[i + tableOffset][3]];
c[2] = zpoints[CellTables::Get().ShapesFaceList[i + tableOffset][3]];
d[0] = xpoints[CellTables::Get().ShapesFaceList[i + tableOffset][4]];
d[1] = ypoints[CellTables::Get().ShapesFaceList[i + tableOffset][4]];
d[2] = zpoints[CellTables::Get().ShapesFaceList[i + tableOffset][4]];
a[0] = xpoints[tables.ShapesFaceList(i + tableOffset, 1)];
a[1] = ypoints[tables.ShapesFaceList(i + tableOffset, 1)];
a[2] = zpoints[tables.ShapesFaceList(i + tableOffset, 1)];
b[0] = xpoints[tables.ShapesFaceList(i + tableOffset, 2)];
b[1] = ypoints[tables.ShapesFaceList(i + tableOffset, 2)];
b[2] = zpoints[tables.ShapesFaceList(i + tableOffset, 2)];
c[0] = xpoints[tables.ShapesFaceList(i + tableOffset, 3)];
c[1] = ypoints[tables.ShapesFaceList(i + tableOffset, 3)];
c[2] = zpoints[tables.ShapesFaceList(i + tableOffset, 3)];
d[0] = xpoints[tables.ShapesFaceList(i + tableOffset, 4)];
d[1] = ypoints[tables.ShapesFaceList(i + tableOffset, 4)];
d[2] = zpoints[tables.ShapesFaceList(i + tableOffset, 4)];
T distance = -1.f;
distances[i] = distance; //init to -1
......
......@@ -29,114 +29,117 @@ namespace rendering
{
namespace raytracing
{
class CellTables
struct CellTables
{
private:
struct Tables
// CellTypeLookUp: LookUp of Shapes to FaceLookUp
VTKM_EXEC vtkm::Int32 CellTypeLookUp(vtkm::Int32 x) const
{
vtkm::Int32 CellTypeLookUp[15];
vtkm::Int32 FaceLookUp[5][3];
vtkm::Int32 ShapesFaceList[20][5];
vtkm::Int32 ZooTable[30][4];
vtkm::Int32 ZooLookUp[5][2];
};
VTKM_STATIC_CONSTEXPR_ARRAY vtkm::Int32 lookup[15] = {
4, // 0 Nothing
4, // 1 Vertex
4, // 2 (Not Used) Poly Vertex
4, // 3 Line
4, // 4 (Not Used) Poly Line
4, // 5 Triangle
4, // 6 (not used) triangle strip
4, // 7 Polygon
4, // 8 (Not used)Pixel
4, // 9 Quad
1, // 10 Tetra
4, // 11 (Not used) Voxel
0, // 12 Hex
2, // 13 Wedge
3 // 14 Pyramid
};
return lookup[x];
}
public:
VTKM_EXEC_CONT static const Tables& Get()
// FaceLookUp
VTKM_EXEC vtkm::Int32 FaceLookUp(vtkm::Int32 x, vtkm::Int32 y) const
{
static const Tables tables = {
// CellTypeLookUp: LookUp of Shapes to FaceLookUp
{
4, // 0 Nothing
4, // 1 Vertex
4, // 2 (Not Used) Poly Vertex
4, // 3 Line
4, // 4 (Not Used) Poly Line
4, // 5 Triangle
4, // 6 (not used) triangle strip
4, // 7 Polygon
4, // 8 (Not used)Pixel
4, // 9 Quad
1, // 10 Tetra
4, // 11 (Not used) Voxel
0, // 12 Hex
2, // 13 Wedge
3 // 14 Pyramid
},
// FaceLookUp
{
{ 0, 6, 8 }, //hex offset into shapes face list, num faces and number of Indices
{ 6, 4, 4 }, //tet
{ 10, 5, 6 }, //wedge
{ 15, 5, 5 }, //pyramid
{ -1, 0, 0 } //unsupported shape
},
// ShapesFaceList:
// The convention for the faces is that looking from the outside of
// the shape at a face, triangles should wind CCW.
// Quads are broken up by {4=quad,a,b,c,d}:
// t1 = abc and t2 = acd. Indices of the face are ordered CW, and the mapping
// of t1 and t2 become CCW.
// Since we know the triangle winding, we could tell
// if we hit an inside face or outside face.
{ //hex
{ 4, 0, 1, 5, 4 }, //face 0
{ 4, 1, 2, 6, 5 },
{ 4, 3, 7, 6, 2 },
{ 4, 0, 4, 7, 3 },
{ 4, 0, 3, 2, 1 },
{ 4, 4, 5, 6, 7 }, //face 5
VTKM_STATIC_CONSTEXPR_ARRAY vtkm::Int32 faces[5][3] = {
{ 0, 6, 8 }, //hex offset into shapes face list, num faces and number of Indices
{ 6, 4, 4 }, //tet
{ 10, 5, 6 }, //wedge
{ 15, 5, 5 }, //pyramid
{ -1, 0, 0 } //unsupported shape
};
return faces[x][y];
}
//tet
{ 3, 0, 3, 1, -1 },
{ 3, 1, 2, 3, -1 },
{ 3, 0, 2, 3, -1 },
{ 3, 0, 2, 1, -1 },
// ShapesFaceList:
// The convention for the faces is that looking from the outside of
// the shape at a face, triangles should wind CCW.
// Quads are broken up by {4=quad,a,b,c,d}:
// t1 = abc and t2 = acd. Indices of the face are ordered CW, and the mapping
// of t1 and t2 become CCW.
// Since we know the triangle winding, we could tell
// if we hit an inside face or outside face.
VTKM_EXEC vtkm::Int32 ShapesFaceList(vtkm::Int32 x, vtkm::Int32 y) const
{
VTKM_STATIC_CONSTEXPR_ARRAY vtkm::Int32 shapes[20][5] = { //hex
{ 4, 0, 1, 5, 4 }, //face 0
{ 4, 1, 2, 6, 5 },
{ 4, 3, 7, 6, 2 },
{ 4, 0, 4, 7, 3 },
{ 4, 0, 3, 2, 1 },
{ 4, 4, 5, 6, 7 }, //face 5
//wedge
{ 3, 0, 1, 2, -1 },
{ 3, 3, 5, 4, -1 },
{ 4, 3, 0, 2, 5 },
{ 4, 1, 4, 5, 2 },
{ 4, 0, 3, 4, 1 },
//tet
{ 3, 0, 3, 1, -1 },
{ 3, 1, 2, 3, -1 },
{ 3, 0, 2, 3, -1 },
{ 3, 0, 2, 1, -1 },
//pyramid
{ 3, 0, 4, 1, -1 },
{ 3, 1, 2, 4, -1 },
{ 3, 2, 3, 4, -1 },
{ 3, 0, 4, 3, -1 },
{ 4, 3, 2, 1, 0 } },
//wedge
{ 3, 0, 1, 2, -1 },
{ 3, 3, 5, 4, -1 },
{ 4, 3, 0, 2, 5 },
{ 4, 1, 4, 5, 2 },
{ 4, 0, 3, 4, 1 },
// ZooTable:
// Test of zoo table.
// Format (faceNumber, triangle)
//
{ { 0, 0, 1, 5 }, // hex
{ 0, 0, 5, 4 }, { 1, 1, 2, 6 }, { 1, 1, 6, 5 }, { 2, 3, 7, 6 }, { 2, 3, 6, 2 },
{ 3, 0, 4, 7 }, { 3, 0, 7, 3 }, { 4, 0, 3, 2 }, { 4, 0, 2, 1 }, { 5, 4, 5, 6 },
{ 5, 4, 6, 7 }, { 0, 0, 3, 1 }, // Tet
{ 1, 1, 2, 3 }, { 2, 0, 2, 3 }, { 3, 0, 2, 1 }, { 0, 0, 1, 2 }, // Wedge
{ 1, 3, 5, 4 }, { 2, 3, 0, 2 }, { 2, 3, 2, 5 }, { 3, 1, 4, 5 }, { 3, 1, 5, 2 },
{ 4, 0, 3, 4 }, { 4, 0, 4, 1 }, { 0, 0, 4, 1 }, // Pyramid
{ 1, 1, 2, 4 }, { 2, 2, 3, 4 }, { 3, 0, 4, 3 }, { 4, 3, 2, 1 }, { 4, 3, 1, 0 } },
//pyramid
{ 3, 0, 4, 1, -1 },
{ 3, 1, 2, 4, -1 },
{ 3, 2, 3, 4, -1 },
{ 3, 0, 4, 3, -1 },
{ 4, 3, 2, 1, 0 }
};
return shapes[x][y];
}
// ZooLookUp:
// Offset into zoo table and the
// number of triangles for the shape
//
{
{ 0, 12 }, //hex offset into shapes face list, num faces and number of Indices
{ 12, 4 }, //tet
{ 16, 8 }, //wedge
{ 24, 6 }, //pyramid
{ -1, 0 } //unsupported shape
}
// ZooTable:
// Test of zoo table.
// Format (faceNumber, triangle)
VTKM_EXEC vtkm::Int32 ZooTable(vtkm::Int32 x, vtkm::Int32 y) const
{
VTKM_STATIC_CONSTEXPR_ARRAY vtkm::Int32 zoo[30][4] = {
{ 0, 0, 1, 5 }, // hex
{ 0, 0, 5, 4 }, { 1, 1, 2, 6 }, { 1, 1, 6, 5 }, { 2, 3, 7, 6 }, { 2, 3, 6, 2 },
{ 3, 0, 4, 7 }, { 3, 0, 7, 3 }, { 4, 0, 3, 2 }, { 4, 0, 2, 1 }, { 5, 4, 5, 6 },
{ 5, 4, 6, 7 }, { 0, 0, 3, 1 }, // Tet
{ 1, 1, 2, 3 }, { 2, 0, 2, 3 }, { 3, 0, 2, 1 }, { 0, 0, 1, 2 }, // Wedge
{ 1, 3, 5, 4 }, { 2, 3, 0, 2 }, { 2, 3, 2, 5 }, { 3, 1, 4, 5 }, { 3, 1, 5, 2 },
{ 4, 0, 3, 4 }, { 4, 0, 4, 1 }, { 0, 0, 4, 1 }, // Pyramid
{ 1, 1, 2, 4 }, { 2, 2, 3, 4 }, { 3, 0, 4, 3 }, { 4, 3, 2, 1 }, { 4, 3, 1, 0 }
};
return zoo[x][y];
}
return tables;
// ZooLookUp:
// Offset into zoo table and the
// number of triangles for the shape
//
VTKM_EXEC vtkm::Int32 ZooLookUp(vtkm::Int32 x, vtkm::Int32 y) const
{
VTKM_STATIC_CONSTEXPR_ARRAY vtkm::Int32 zoo[5][2] = {
{ 0, 12 }, //hex offset into shapes face list, num faces and number of Indices
{ 12, 4 }, //tet
{ 16, 8 }, //wedge
{ 24, 6 }, //pyramid
{ -1, 0 } //unsupported shape
};
return zoo[x][y];
}
};
......
......@@ -219,8 +219,9 @@ public:
}
const vtkm::UInt8 cellShape = MeshConn.GetCellShape(currentCell);
Intersector.IntersectCell(xpoints, ypoints, zpoints, dir, origin, distances, cellShape);
const vtkm::Int32 numFaces =
CellTables::Get().FaceLookUp[CellTables::Get().CellTypeLookUp[cellShape]][1];
CellTables tables;
const vtkm::Int32 numFaces = tables.FaceLookUp(tables.CellTypeLookUp(cellShape), 1);
//vtkm::Int32 minFace = 6;
vtkm::Int32 maxFace = -1;
......@@ -354,8 +355,9 @@ public:
const vtkm::UInt8 cellShape = MeshConn.GetCellShape(currentCell);
Intersector.IntersectCell(xpoints, ypoints, zpoints, dir, origin, distances, cellShape);
const vtkm::Int32 numFaces =
CellTables::Get().FaceLookUp[CellTables::Get().CellTypeLookUp[cellShape]][1];
CellTables tables;
const vtkm::Int32 numFaces = tables.FaceLookUp(tables.CellTypeLookUp(cellShape), 1);
//vtkm::Int32 minFace = 6;
vtkm::Int32 maxFace = -1;
......
......@@ -106,23 +106,24 @@ public:
inline vtkm::Int32 GetShapeOffset(const vtkm::UInt8& shapeType) const
{
CellTables tables;
//TODO: This might be better as if if if
vtkm::Int32 tableOffset = 0;
if (shapeType == vtkm::CELL_SHAPE_TETRA)
{
tableOffset = CellTables::Get().FaceLookUp[1][0];
tableOffset = tables.FaceLookUp(1, 0);
}
else if (shapeType == vtkm::CELL_SHAPE_HEXAHEDRON)
{
tableOffset = CellTables::Get().FaceLookUp[0][0];
tableOffset = tables.FaceLookUp(0, 0);
}
else if (shapeType == vtkm::CELL_SHAPE_WEDGE)
{
tableOffset = CellTables::Get().FaceLookUp[2][0];
tableOffset = tables.FaceLookUp(2, 0);
}
else if (shapeType == vtkm::CELL_SHAPE_PYRAMID)
{
tableOffset = CellTables::Get().FaceLookUp[3][0];
tableOffset = tables.FaceLookUp(3, 0);
}
else
printf("Error shape not recognized %d\n", (int)shapeType);
......@@ -172,6 +173,7 @@ public:
bool isInternal = false;
vtkm::Id connectedCell = -1;
CellTables tables;
while (currentIndex > -1 && myCode == myNeighbor)
{
myNeighbor = mortonCodes.Get(currentIndex);
......@@ -186,12 +188,13 @@ public:
vtkm::Id cellId2 = faceIdPairs.Get(currentIndex)[0];
BOUNDS_CHECK(shapes, cellId1);
BOUNDS_CHECK(shapes, cellId2);
vtkm::Id shape1Offset = GetShapeOffset(shapes.Get(cellId1)) + faceIdPairs.Get(index)[1];
vtkm::Id shape2Offset =
GetShapeOffset(shapes.Get(cellId2)) + faceIdPairs.Get(currentIndex)[1];
vtkm::Int32 shape1Offset =
GetShapeOffset(shapes.Get(cellId1)) + static_cast<vtkm::Int32>(faceIdPairs.Get(index)[1]);
vtkm::Int32 shape2Offset = GetShapeOffset(shapes.Get(cellId2)) +
static_cast<vtkm::Int32>(faceIdPairs.Get(currentIndex)[1]);
vtkm::Int32 icount1 = CellTables::Get().ShapesFaceList[shape1Offset][0];
vtkm::Int32 icount2 = CellTables::Get().ShapesFaceList[shape2Offset][0];
const vtkm::Int32 icount1 = tables.ShapesFaceList(shape1Offset, 0);
const vtkm::Int32 icount2 = tables.ShapesFaceList(shape2Offset, 0);
//Check to see if we have the same number of idices
if (icount1 != icount2)
continue;
......@@ -201,24 +204,25 @@ public:
vtkm::Vec<vtkm::Id, 4> indices1;
vtkm::Vec<vtkm::Id, 4> indices2;
for (vtkm::Int32 i = 1; i <= CellTables::Get().ShapesFaceList[shape1Offset][0]; ++i)
const auto faceLength = tables.ShapesFaceList(shape1Offset, 0);
for (vtkm::Int32 i = 1; i <= faceLength; ++i)
{
BOUNDS_CHECK(offsets, cellId1);
BOUNDS_CHECK(offsets, cellId2);
BOUNDS_CHECK(connectivity,
(offsets.Get(cellId1) + CellTables::Get().ShapesFaceList[shape1Offset][i]));
(offsets.Get(cellId1) + tables.ShapesFaceList(shape1Offset, i)));
BOUNDS_CHECK(connectivity,
(offsets.Get(cellId2) + CellTables::Get().ShapesFaceList[shape2Offset][i]));
indices1[i - 1] = connectivity.Get(offsets.Get(cellId1) +
CellTables::Get().ShapesFaceList[shape1Offset][i]);
indices2[i - 1] = connectivity.Get(offsets.Get(cellId2) +
CellTables::Get().ShapesFaceList[shape2Offset][i]);
(offsets.Get(cellId2) + tables.ShapesFaceList(shape2Offset, i)));
indices1[i - 1] =
connectivity.Get(offsets.Get(cellId1) + tables.ShapesFaceList(shape1Offset, i));
indices2[i - 1] =
connectivity.Get(offsets.Get(cellId2) + tables.ShapesFaceList(shape2Offset, i));
}
bool isEqual = true;
for (vtkm::Int32 i = 0; i < CellTables::Get().ShapesFaceList[shape1Offset][0]; ++i)
for (vtkm::Int32 i = 0; i < faceLength; ++i)
{
if (!IsIn(indices1[i], indices2, CellTables::Get().ShapesFaceList[shape1Offset][0]))
if (!IsIn(indices1[i], indices2, faceLength))
isEqual = false;
}
......@@ -281,14 +285,14 @@ public:
const OutIndicesPortalType& outputIndices,
const vtkm::Id& outputOffset) const
{
CellTables tables;
vtkm::Id cellId = faceIdPair[0];
BOUNDS_CHECK(shapeOffsets, cellId);
vtkm::Id offset = shapeOffsets.Get(cellId);
BOUNDS_CHECK(shapes, cellId);
vtkm::Int32 shapeId = static_cast<vtkm::Int32>(shapes.Get(cellId));
vtkm::Int32 shapesFaceOffset =
CellTables::Get().FaceLookUp[CellTables::Get().CellTypeLookUp[shapeId]][0];
vtkm::Int32 shapesFaceOffset = tables.FaceLookUp(tables.CellTypeLookUp(shapeId), 0);
if (shapesFaceOffset == -1)
{
printf("Unsupported Shape Type %d\n", shapeId);
......@@ -297,12 +301,12 @@ public:
vtkm::Vec<vtkm::Id, 4> faceIndices(-1, -1, -1, -1);
vtkm::Int32 tableIndex = static_cast<vtkm::Int32>(shapesFaceOffset + faceIdPair[1]);
const vtkm::Int32 numIndices = CellTables::Get().ShapesFaceList[tableIndex][0];
const vtkm::Int32 numIndices = tables.ShapesFaceList(tableIndex, 0);
for (vtkm::Int32 i = 1; i <= numIndices; ++i)
{
BOUNDS_CHECK(indices, offset + CellTables::Get().ShapesFaceList[tableIndex][i]);
faceIndices[i - 1] = indices.Get(offset + CellTables::Get().ShapesFaceList[tableIndex][i]);
BOUNDS_CHECK(indices, offset + tables.ShapesFaceList(tableIndex, i));
faceIndices[i - 1] = indices.Get(offset + tables.ShapesFaceList(tableIndex, i));
}