VTK-m  2.0
CellShape.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_CellShape_h
11 #define vtk_m_CellShape_h
12 
13 #include <vtkm/StaticAssert.h>
14 #include <vtkm/Types.h>
15 
16 #include <lcl/Polygon.h>
17 #include <lcl/Shapes.h>
18 
19 // Vtk-c does not have tags for Empty and PolyLine. Define dummy tags here to
20 // avoid compilation errors. These tags are not used anywhere.
21 namespace lcl
22 {
23 struct Empty;
24 struct PolyLine;
25 }
26 
27 namespace vtkm
28 {
29 
34 {
35  // Linear cells
36  CELL_SHAPE_EMPTY = lcl::ShapeId::EMPTY,
37  CELL_SHAPE_VERTEX = lcl::ShapeId::VERTEX,
38  //CELL_SHAPE_POLY_VERTEX = 2,
39  CELL_SHAPE_LINE = lcl::ShapeId::LINE,
41  CELL_SHAPE_TRIANGLE = lcl::ShapeId::TRIANGLE,
42  //CELL_SHAPE_TRIANGLE_STRIP = 6,
43  CELL_SHAPE_POLYGON = lcl::ShapeId::POLYGON,
44  //CELL_SHAPE_PIXEL = 8,
45  CELL_SHAPE_QUAD = lcl::ShapeId::QUAD,
46  CELL_SHAPE_TETRA = lcl::ShapeId::TETRA,
47  //CELL_SHAPE_VOXEL = 11,
48  CELL_SHAPE_HEXAHEDRON = lcl::ShapeId::HEXAHEDRON,
49  CELL_SHAPE_WEDGE = lcl::ShapeId::WEDGE,
50  CELL_SHAPE_PYRAMID = lcl::ShapeId::PYRAMID,
51 
53 };
54 
55 // If you wish to add cell shapes to this list, in addition to adding an index
56 // to the enum above, you at a minimum need to define an associated tag with
57 // VTKM_DEFINE_CELL_TAG and add a condition to the vtkmGenericCellShapeMacro.
58 // There are also many other cell-specific features that code might expect such
59 // as \c CellTraits and interpolations.
60 
61 namespace internal
62 {
63 
67 template <typename T>
68 struct CellShapeTagCheck : std::false_type
69 {
70 };
71 
73 template <typename VtkmCellShapeTag>
74 struct CellShapeTagVtkmToVtkc;
75 
76 } // namespace internal
77 
82 #define VTKM_IS_CELL_SHAPE_TAG(tag) \
83  VTKM_STATIC_ASSERT_MSG(::vtkm::internal::CellShapeTagCheck<tag>::value, \
84  "Provided type is not a valid VTK-m cell shape tag.")
85 
88 template <vtkm::IdComponent Id>
90 {
91  // If you get a compile error for this class about Id not being defined, that
92  // probably means you are using an ID that does not have a defined cell
93  // shape.
94 
95  using valid = std::false_type;
96 };
97 
98 // Define a tag for each cell shape as well as the support structs to go
99 // between tags and ids. The following macro is only valid here.
100 
101 #define VTKM_DEFINE_CELL_TAG(name, idname) \
102  struct CellShapeTag##name \
103  { \
104  static constexpr vtkm::UInt8 Id = vtkm::idname; \
105  }; \
106  namespace internal \
107  { \
108  template <> \
109  struct CellShapeTagCheck<vtkm::CellShapeTag##name> : std::true_type \
110  { \
111  }; \
112  template <> \
113  struct CellShapeTagVtkmToVtkc<vtkm::CellShapeTag##name> \
114  { \
115  using Type = lcl::name; \
116  }; \
117  } \
118  static inline VTKM_EXEC_CONT const char* GetCellShapeName(vtkm::CellShapeTag##name) \
119  { \
120  return #name; \
121  } \
122  template <> \
123  struct CellShapeIdToTag<vtkm::idname> \
124  { \
125  using valid = std::true_type; \
126  using Tag = vtkm::CellShapeTag##name; \
127  }
128 
131 //VTKM_DEFINE_CELL_TAG(PolyVertex, CELL_SHAPE_POLY_VERTEX);
135 //VTKM_DEFINE_CELL_TAG(TriangleStrip, CELL_SHAPE_TRIANGLE_STRIP);
137 //VTKM_DEFINE_CELL_TAG(Pixel, CELL_SHAPE_PIXEL);
140 //VTKM_DEFINE_CELL_TAG(Voxel, CELL_SHAPE_VOXEL);
144 
145 #undef VTKM_DEFINE_CELL_TAG
146 
153 {
156  : Id(shape)
157  {
158  }
159 
161 };
162 
163 namespace internal
164 {
165 
166 template <typename VtkmCellShapeTag>
167 VTKM_EXEC_CONT inline typename CellShapeTagVtkmToVtkc<VtkmCellShapeTag>::Type make_LclCellShapeTag(
168  const VtkmCellShapeTag&,
169  vtkm::IdComponent numPoints = 0)
170 {
171  using VtkcCellShapeTag = typename CellShapeTagVtkmToVtkc<VtkmCellShapeTag>::Type;
172  static_cast<void>(numPoints); // unused
173  return VtkcCellShapeTag{};
174 }
175 
177 inline lcl::Polygon make_LclCellShapeTag(const vtkm::CellShapeTagPolygon&,
178  vtkm::IdComponent numPoints = 0)
179 {
180  return lcl::Polygon(numPoints);
181 }
182 
184 inline lcl::Cell make_LclCellShapeTag(const vtkm::CellShapeTagGeneric& tag,
185  vtkm::IdComponent numPoints = 0)
186 {
187  return lcl::Cell(static_cast<std::int8_t>(tag.Id), numPoints);
188 }
189 
190 } // namespace internal
191 
192 #define vtkmGenericCellShapeMacroCase(cellShapeId, call) \
193  case vtkm::cellShapeId: \
194  { \
195  using CellShapeTag = vtkm::CellShapeIdToTag<vtkm::cellShapeId>::Tag; \
196  call; \
197  } \
198  break
199 
230 #define vtkmGenericCellShapeMacro(call) \
231  vtkmGenericCellShapeMacroCase(CELL_SHAPE_EMPTY, call); \
232  vtkmGenericCellShapeMacroCase(CELL_SHAPE_VERTEX, call); \
233  vtkmGenericCellShapeMacroCase(CELL_SHAPE_LINE, call); \
234  vtkmGenericCellShapeMacroCase(CELL_SHAPE_POLY_LINE, call); \
235  vtkmGenericCellShapeMacroCase(CELL_SHAPE_TRIANGLE, call); \
236  vtkmGenericCellShapeMacroCase(CELL_SHAPE_POLYGON, call); \
237  vtkmGenericCellShapeMacroCase(CELL_SHAPE_QUAD, call); \
238  vtkmGenericCellShapeMacroCase(CELL_SHAPE_TETRA, call); \
239  vtkmGenericCellShapeMacroCase(CELL_SHAPE_HEXAHEDRON, call); \
240  vtkmGenericCellShapeMacroCase(CELL_SHAPE_WEDGE, call); \
241  vtkmGenericCellShapeMacroCase(CELL_SHAPE_PYRAMID, call)
242 
243 } // namespace vtkm
244 
245 #endif //vtk_m_CellShape_h
vtkm::NUMBER_OF_CELL_SHAPES
@ NUMBER_OF_CELL_SHAPES
Definition: CellShape.h:52
vtkm::VTKM_DEFINE_CELL_TAG
VTKM_DEFINE_CELL_TAG(Empty, CELL_SHAPE_EMPTY)
vtkm::CELL_SHAPE_WEDGE
@ CELL_SHAPE_WEDGE
Definition: CellShape.h:49
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
Types.h
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::CellShapeTagGeneric::CellShapeTagGeneric
VTKM_EXEC_CONT CellShapeTagGeneric(vtkm::UInt8 shape)
Definition: CellShape.h:155
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::CellShapeIdToTag
A traits-like class to get an CellShapeId known at compile time to a tag.
Definition: CellShape.h:89
vtkm::CELL_SHAPE_EMPTY
@ CELL_SHAPE_EMPTY
Definition: CellShape.h:36
vtkm::CellShapeIdToTag::valid
std::false_type valid
Definition: CellShape.h:95
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::CellShapeIdEnum
CellShapeIdEnum
CellShapeId identifies the type of each cell.
Definition: CellShape.h:33
vtkm::Line
Ray< CoordType, Dim, true > Line
Lines are two-sided rays:
Definition: Geometry.h:330
vtkm::CELL_SHAPE_POLY_LINE
@ CELL_SHAPE_POLY_LINE
Definition: CellShape.h:40
vtkm::CELL_SHAPE_TETRA
@ CELL_SHAPE_TETRA
Definition: CellShape.h:46
vtkm::CELL_SHAPE_HEXAHEDRON
@ CELL_SHAPE_HEXAHEDRON
Definition: CellShape.h:48
vtkm::UInt8
uint8_t UInt8
Definition: Types.h:157
vtkm::CELL_SHAPE_TRIANGLE
@ CELL_SHAPE_TRIANGLE
Definition: CellShape.h:41
vtkm::CELL_SHAPE_LINE
@ CELL_SHAPE_LINE
Definition: CellShape.h:39
vtkm::CellShapeTagGeneric::Id
vtkm::UInt8 Id
Definition: CellShape.h:160
StaticAssert.h
vtkm::CellShapeTagGeneric
A special cell shape tag that holds a cell shape that is not known at compile time.
Definition: CellShape.h:152
vtkm::CELL_SHAPE_PYRAMID
@ CELL_SHAPE_PYRAMID
Definition: CellShape.h:50
vtkm::CELL_SHAPE_POLYGON
@ CELL_SHAPE_POLYGON
Definition: CellShape.h:43
vtkm::CELL_SHAPE_VERTEX
@ CELL_SHAPE_VERTEX
Definition: CellShape.h:37
vtkm::CELL_SHAPE_QUAD
@ CELL_SHAPE_QUAD
Definition: CellShape.h:45
lcl
Definition: CellShape.h:21