2015-02-09 22:04:09 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2015-02-09 22:04:09 +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
|
|
|
#ifndef vtk_m_CellShape_h
|
|
|
|
#define vtk_m_CellShape_h
|
2015-02-09 22:04:09 +00:00
|
|
|
|
2015-09-17 19:45:35 +00:00
|
|
|
#include <vtkm/StaticAssert.h>
|
2015-08-16 21:31:36 +00:00
|
|
|
#include <vtkm/Types.h>
|
|
|
|
|
2019-10-07 19:38:36 +00:00
|
|
|
#include <lcl/Polygon.h>
|
|
|
|
#include <lcl/Shapes.h>
|
2019-09-25 01:22:10 +00:00
|
|
|
|
|
|
|
// Vtk-c does not have tags for Empty and PolyLine. Define dummy tags here to
|
|
|
|
// avoid compilation errors. These tags are not used anywhere.
|
2019-10-07 19:38:36 +00:00
|
|
|
namespace lcl
|
2019-09-25 01:22:10 +00:00
|
|
|
{
|
|
|
|
struct Empty;
|
|
|
|
struct PolyLine;
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
2015-02-09 22:04:09 +00:00
|
|
|
|
2015-08-16 18:53:44 +00:00
|
|
|
/// CellShapeId identifies the type of each cell. Currently these are designed
|
|
|
|
/// to match up with VTK cell types.
|
2015-02-09 22:04:09 +00:00
|
|
|
///
|
2015-08-16 21:31:36 +00:00
|
|
|
enum CellShapeIdEnum
|
2015-02-09 22:04:09 +00:00
|
|
|
{
|
|
|
|
// Linear cells
|
2024-03-12 19:06:20 +00:00
|
|
|
/// Placeholder for empty or invalid cells.
|
2019-10-07 19:38:36 +00:00
|
|
|
CELL_SHAPE_EMPTY = lcl::ShapeId::EMPTY,
|
2024-03-12 19:06:20 +00:00
|
|
|
/// Vertex cells of a single point.
|
2019-10-07 19:38:36 +00:00
|
|
|
CELL_SHAPE_VERTEX = lcl::ShapeId::VERTEX,
|
2015-08-16 18:53:44 +00:00
|
|
|
//CELL_SHAPE_POLY_VERTEX = 2,
|
2024-03-12 19:06:20 +00:00
|
|
|
/// A line cell connecting two points.
|
2019-10-07 19:38:36 +00:00
|
|
|
CELL_SHAPE_LINE = lcl::ShapeId::LINE,
|
2024-03-12 19:06:20 +00:00
|
|
|
/// A sequence of line segments.
|
|
|
|
/// A polyline has 2 or more points, and the points are connected in order
|
|
|
|
/// by line segments forming a piecewise linear curve.
|
2019-05-17 17:35:35 +00:00
|
|
|
CELL_SHAPE_POLY_LINE = 4,
|
2024-03-12 19:06:20 +00:00
|
|
|
/// A triangle.
|
2019-10-07 19:38:36 +00:00
|
|
|
CELL_SHAPE_TRIANGLE = lcl::ShapeId::TRIANGLE,
|
2015-08-16 18:53:44 +00:00
|
|
|
//CELL_SHAPE_TRIANGLE_STRIP = 6,
|
2024-03-12 19:06:20 +00:00
|
|
|
/// A general polygon shape.
|
|
|
|
/// All polygons have points ordered in counterclockwise order around the front side.
|
|
|
|
/// Some operations may be invalid if the polygon is not a convex shape.
|
2019-10-07 19:38:36 +00:00
|
|
|
CELL_SHAPE_POLYGON = lcl::ShapeId::POLYGON,
|
2015-11-17 16:32:19 +00:00
|
|
|
//CELL_SHAPE_PIXEL = 8,
|
2024-03-12 19:06:20 +00:00
|
|
|
/// A four-sided polygon.
|
2019-10-07 19:38:36 +00:00
|
|
|
CELL_SHAPE_QUAD = lcl::ShapeId::QUAD,
|
2024-03-12 19:06:20 +00:00
|
|
|
/// A tetrahedron.
|
|
|
|
/// A tetrahedron is a 3D polyhedron with 4 points and 4 triangular faces.
|
2019-10-07 19:38:36 +00:00
|
|
|
CELL_SHAPE_TETRA = lcl::ShapeId::TETRA,
|
2015-11-17 16:32:19 +00:00
|
|
|
//CELL_SHAPE_VOXEL = 11,
|
2024-03-12 19:06:20 +00:00
|
|
|
/// A hexahedron.
|
2019-10-07 19:38:36 +00:00
|
|
|
CELL_SHAPE_HEXAHEDRON = lcl::ShapeId::HEXAHEDRON,
|
2024-03-12 19:06:20 +00:00
|
|
|
/// A wedge.
|
|
|
|
/// Wedges are simple prisms that can be formed by extruding a triangle.
|
|
|
|
/// They have 2 triangular faces and 3 quadrilateral faces.
|
2019-10-07 19:38:36 +00:00
|
|
|
CELL_SHAPE_WEDGE = lcl::ShapeId::WEDGE,
|
2024-03-12 19:06:20 +00:00
|
|
|
/// A pyramid with a quadrilateral base and four triangular faces.0
|
2019-10-07 19:38:36 +00:00
|
|
|
CELL_SHAPE_PYRAMID = lcl::ShapeId::PYRAMID,
|
2015-02-09 22:04:09 +00:00
|
|
|
|
2015-08-16 18:53:44 +00:00
|
|
|
NUMBER_OF_CELL_SHAPES
|
2015-02-09 22:04:09 +00:00
|
|
|
};
|
|
|
|
|
2015-08-16 21:31:36 +00:00
|
|
|
// If you wish to add cell shapes to this list, in addition to adding an index
|
2015-08-19 16:01:26 +00:00
|
|
|
// to the enum above, you at a minimum need to define an associated tag with
|
2015-08-16 21:31:36 +00:00
|
|
|
// VTKM_DEFINE_CELL_TAG and add a condition to the vtkmGenericCellShapeMacro.
|
2015-08-19 16:01:26 +00:00
|
|
|
// There are also many other cell-specific features that code might expect such
|
|
|
|
// as \c CellTraits and interpolations.
|
2015-08-16 21:31:36 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace internal
|
|
|
|
{
|
2015-08-16 21:31:36 +00:00
|
|
|
|
|
|
|
/// A class that can be used to determine if a class is a CellShapeTag or not.
|
2016-08-29 15:13:00 +00:00
|
|
|
/// The class will be either std::true_type or std::false_type.
|
2015-08-16 21:31:36 +00:00
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
|
|
|
struct CellShapeTagCheck : std::false_type
|
|
|
|
{
|
|
|
|
};
|
2015-08-16 21:31:36 +00:00
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
/// Convert VTK-m tag to VTK-c tag
|
|
|
|
template <typename VtkmCellShapeTag>
|
|
|
|
struct CellShapeTagVtkmToVtkc;
|
|
|
|
|
2015-08-16 21:31:36 +00:00
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
/// Checks that the argument is a proper cell shape tag. This is a handy
|
|
|
|
/// concept check to make sure that a template argument is a proper cell shape
|
|
|
|
/// tag.
|
|
|
|
///
|
2020-08-17 14:18:24 +00:00
|
|
|
#define VTKM_IS_CELL_SHAPE_TAG(tag) \
|
|
|
|
VTKM_STATIC_ASSERT_MSG(::vtkm::internal::CellShapeTagCheck<tag>::value, \
|
2017-05-18 14:29:41 +00:00
|
|
|
"Provided type is not a valid VTK-m cell shape tag.")
|
2015-08-16 21:31:36 +00:00
|
|
|
|
|
|
|
/// A traits-like class to get an CellShapeId known at compile time to a tag.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <vtkm::IdComponent Id>
|
|
|
|
struct CellShapeIdToTag
|
|
|
|
{
|
2015-08-16 21:31:36 +00:00
|
|
|
// If you get a compile error for this class about Id not being defined, that
|
|
|
|
// probably means you are using an ID that does not have a defined cell
|
|
|
|
// shape.
|
|
|
|
|
2017-06-23 18:50:34 +00:00
|
|
|
using valid = std::false_type;
|
2015-08-16 21:31:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Define a tag for each cell shape as well as the support structs to go
|
|
|
|
// between tags and ids. The following macro is only valid here.
|
|
|
|
|
2020-08-17 14:18:24 +00:00
|
|
|
#define VTKM_DEFINE_CELL_TAG(name, idname) \
|
|
|
|
struct CellShapeTag##name \
|
|
|
|
{ \
|
|
|
|
static constexpr vtkm::UInt8 Id = vtkm::idname; \
|
|
|
|
}; \
|
|
|
|
namespace internal \
|
|
|
|
{ \
|
|
|
|
template <> \
|
|
|
|
struct CellShapeTagCheck<vtkm::CellShapeTag##name> : std::true_type \
|
|
|
|
{ \
|
|
|
|
}; \
|
|
|
|
template <> \
|
|
|
|
struct CellShapeTagVtkmToVtkc<vtkm::CellShapeTag##name> \
|
|
|
|
{ \
|
|
|
|
using Type = lcl::name; \
|
|
|
|
}; \
|
|
|
|
} \
|
|
|
|
static inline VTKM_EXEC_CONT const char* GetCellShapeName(vtkm::CellShapeTag##name) \
|
|
|
|
{ \
|
|
|
|
return #name; \
|
|
|
|
} \
|
|
|
|
template <> \
|
|
|
|
struct CellShapeIdToTag<vtkm::idname> \
|
|
|
|
{ \
|
|
|
|
using valid = std::true_type; \
|
|
|
|
using Tag = vtkm::CellShapeTag##name; \
|
2015-08-16 21:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_DEFINE_CELL_TAG(Empty, CELL_SHAPE_EMPTY);
|
|
|
|
VTKM_DEFINE_CELL_TAG(Vertex, CELL_SHAPE_VERTEX);
|
|
|
|
//VTKM_DEFINE_CELL_TAG(PolyVertex, CELL_SHAPE_POLY_VERTEX);
|
|
|
|
VTKM_DEFINE_CELL_TAG(Line, CELL_SHAPE_LINE);
|
2019-05-17 17:35:35 +00:00
|
|
|
VTKM_DEFINE_CELL_TAG(PolyLine, CELL_SHAPE_POLY_LINE);
|
2015-08-16 21:31:36 +00:00
|
|
|
VTKM_DEFINE_CELL_TAG(Triangle, CELL_SHAPE_TRIANGLE);
|
|
|
|
//VTKM_DEFINE_CELL_TAG(TriangleStrip, CELL_SHAPE_TRIANGLE_STRIP);
|
|
|
|
VTKM_DEFINE_CELL_TAG(Polygon, CELL_SHAPE_POLYGON);
|
2015-08-27 23:03:13 +00:00
|
|
|
//VTKM_DEFINE_CELL_TAG(Pixel, CELL_SHAPE_PIXEL);
|
2015-08-16 21:31:36 +00:00
|
|
|
VTKM_DEFINE_CELL_TAG(Quad, CELL_SHAPE_QUAD);
|
|
|
|
VTKM_DEFINE_CELL_TAG(Tetra, CELL_SHAPE_TETRA);
|
2015-08-27 23:03:13 +00:00
|
|
|
//VTKM_DEFINE_CELL_TAG(Voxel, CELL_SHAPE_VOXEL);
|
2015-08-16 21:31:36 +00:00
|
|
|
VTKM_DEFINE_CELL_TAG(Hexahedron, CELL_SHAPE_HEXAHEDRON);
|
|
|
|
VTKM_DEFINE_CELL_TAG(Wedge, CELL_SHAPE_WEDGE);
|
|
|
|
VTKM_DEFINE_CELL_TAG(Pyramid, CELL_SHAPE_PYRAMID);
|
|
|
|
|
|
|
|
#undef VTKM_DEFINE_CELL_TAG
|
|
|
|
|
|
|
|
/// A special cell shape tag that holds a cell shape that is not known at
|
|
|
|
/// compile time. Unlike other cell set tags, the Id field is set at runtime
|
|
|
|
/// so its value cannot be used in template parameters. You need to use
|
|
|
|
/// \c vtkmGenericCellShapeMacro to specialize on the cell type.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
struct CellShapeTagGeneric
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
CellShapeTagGeneric(vtkm::UInt8 shape)
|
|
|
|
: Id(shape)
|
|
|
|
{
|
|
|
|
}
|
2015-08-16 21:31:36 +00:00
|
|
|
|
2024-03-12 19:06:20 +00:00
|
|
|
/// An identifier that corresponds to one of the `CELL_SHAPE_*` identifiers.
|
|
|
|
/// This value is used to detect the proper shape at runtime.
|
2016-11-05 02:59:19 +00:00
|
|
|
vtkm::UInt8 Id;
|
2015-08-16 21:31:36 +00:00
|
|
|
};
|
|
|
|
|
2019-09-25 01:22:10 +00:00
|
|
|
namespace internal
|
|
|
|
{
|
|
|
|
|
|
|
|
template <typename VtkmCellShapeTag>
|
2020-03-11 23:56:05 +00:00
|
|
|
VTKM_EXEC_CONT inline typename CellShapeTagVtkmToVtkc<VtkmCellShapeTag>::Type make_LclCellShapeTag(
|
2019-09-25 01:22:10 +00:00
|
|
|
const VtkmCellShapeTag&,
|
|
|
|
vtkm::IdComponent numPoints = 0)
|
|
|
|
{
|
|
|
|
using VtkcCellShapeTag = typename CellShapeTagVtkmToVtkc<VtkmCellShapeTag>::Type;
|
|
|
|
static_cast<void>(numPoints); // unused
|
|
|
|
return VtkcCellShapeTag{};
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC_CONT
|
2020-03-11 23:56:05 +00:00
|
|
|
inline lcl::Polygon make_LclCellShapeTag(const vtkm::CellShapeTagPolygon&,
|
|
|
|
vtkm::IdComponent numPoints = 0)
|
2019-09-25 01:22:10 +00:00
|
|
|
{
|
2019-10-07 19:38:36 +00:00
|
|
|
return lcl::Polygon(numPoints);
|
2019-09-25 01:22:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC_CONT
|
2020-03-11 23:56:05 +00:00
|
|
|
inline lcl::Cell make_LclCellShapeTag(const vtkm::CellShapeTagGeneric& tag,
|
|
|
|
vtkm::IdComponent numPoints = 0)
|
2019-09-25 01:22:10 +00:00
|
|
|
{
|
2019-10-07 19:38:36 +00:00
|
|
|
return lcl::Cell(static_cast<std::int8_t>(tag.Id), numPoints);
|
2019-09-25 01:22:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
2020-08-17 14:18:24 +00:00
|
|
|
#define vtkmGenericCellShapeMacroCase(cellShapeId, call) \
|
|
|
|
case vtkm::cellShapeId: \
|
|
|
|
{ \
|
|
|
|
using CellShapeTag = vtkm::CellShapeIdToTag<vtkm::cellShapeId>::Tag; \
|
|
|
|
call; \
|
|
|
|
} \
|
2017-05-18 14:29:41 +00:00
|
|
|
break
|
2015-08-16 21:31:36 +00:00
|
|
|
|
|
|
|
/// \brief A macro used in a \c switch statement to determine cell shape.
|
|
|
|
///
|
|
|
|
/// The \c vtkmGenericCellShapeMacro is a series of case statements for all
|
|
|
|
/// of the cell shapes supported by VTK-m. This macro is intended to be used
|
|
|
|
/// inside of a switch statement on a cell type. For each cell shape condition,
|
|
|
|
/// a \c CellShapeTag typedef is created and the given \c call is executed.
|
|
|
|
///
|
|
|
|
/// A typical use case of this class is to create the specialization of a
|
|
|
|
/// function overloaded on a cell shape tag for the generic cell shape like as
|
|
|
|
/// following.
|
|
|
|
///
|
|
|
|
/// \code{.cpp}
|
|
|
|
/// template<typename WorkletType>
|
2016-10-19 22:42:58 +00:00
|
|
|
/// VTKM_EXEC
|
2015-08-16 21:31:36 +00:00
|
|
|
/// void MyCellOperation(vtkm::CellShapeTagGeneric cellShape,
|
|
|
|
/// const vtkm::exec::FunctorBase &worklet)
|
|
|
|
/// {
|
|
|
|
/// switch(cellShape.CellShapeId)
|
|
|
|
/// {
|
|
|
|
/// vtkmGenericCellShapeMacro(
|
|
|
|
/// MyCellOperation(CellShapeTag())
|
|
|
|
/// );
|
|
|
|
/// default: worklet.RaiseError("Encountered unknown cell shape."); break
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// \endcode
|
|
|
|
///
|
|
|
|
/// Note that \c vtkmGenericCellShapeMacro does not have a default case. You
|
|
|
|
/// should consider adding one that gives a
|
|
|
|
///
|
2020-08-17 14:18:24 +00:00
|
|
|
#define vtkmGenericCellShapeMacro(call) \
|
|
|
|
vtkmGenericCellShapeMacroCase(CELL_SHAPE_EMPTY, call); \
|
|
|
|
vtkmGenericCellShapeMacroCase(CELL_SHAPE_VERTEX, call); \
|
|
|
|
vtkmGenericCellShapeMacroCase(CELL_SHAPE_LINE, call); \
|
|
|
|
vtkmGenericCellShapeMacroCase(CELL_SHAPE_POLY_LINE, call); \
|
|
|
|
vtkmGenericCellShapeMacroCase(CELL_SHAPE_TRIANGLE, call); \
|
|
|
|
vtkmGenericCellShapeMacroCase(CELL_SHAPE_POLYGON, call); \
|
|
|
|
vtkmGenericCellShapeMacroCase(CELL_SHAPE_QUAD, call); \
|
|
|
|
vtkmGenericCellShapeMacroCase(CELL_SHAPE_TETRA, call); \
|
|
|
|
vtkmGenericCellShapeMacroCase(CELL_SHAPE_HEXAHEDRON, call); \
|
|
|
|
vtkmGenericCellShapeMacroCase(CELL_SHAPE_WEDGE, call); \
|
2015-08-16 21:31:36 +00:00
|
|
|
vtkmGenericCellShapeMacroCase(CELL_SHAPE_PYRAMID, call)
|
2015-02-09 22:04:09 +00:00
|
|
|
|
|
|
|
} // namespace vtkm
|
|
|
|
|
2015-08-16 18:53:44 +00:00
|
|
|
#endif //vtk_m_CellShape_h
|