VTK-m  2.1
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
37  CELL_SHAPE_EMPTY = lcl::ShapeId::EMPTY,
39  CELL_SHAPE_VERTEX = lcl::ShapeId::VERTEX,
40  //CELL_SHAPE_POLY_VERTEX = 2,
42  CELL_SHAPE_LINE = lcl::ShapeId::LINE,
48  CELL_SHAPE_TRIANGLE = lcl::ShapeId::TRIANGLE,
49  //CELL_SHAPE_TRIANGLE_STRIP = 6,
53  CELL_SHAPE_POLYGON = lcl::ShapeId::POLYGON,
54  //CELL_SHAPE_PIXEL = 8,
56  CELL_SHAPE_QUAD = lcl::ShapeId::QUAD,
59  CELL_SHAPE_TETRA = lcl::ShapeId::TETRA,
60  //CELL_SHAPE_VOXEL = 11,
62  CELL_SHAPE_HEXAHEDRON = lcl::ShapeId::HEXAHEDRON,
66  CELL_SHAPE_WEDGE = lcl::ShapeId::WEDGE,
68  CELL_SHAPE_PYRAMID = lcl::ShapeId::PYRAMID,
69 
71 };
72 
73 // If you wish to add cell shapes to this list, in addition to adding an index
74 // to the enum above, you at a minimum need to define an associated tag with
75 // VTKM_DEFINE_CELL_TAG and add a condition to the vtkmGenericCellShapeMacro.
76 // There are also many other cell-specific features that code might expect such
77 // as \c CellTraits and interpolations.
78 
79 namespace internal
80 {
81 
85 template <typename T>
86 struct CellShapeTagCheck : std::false_type
87 {
88 };
89 
91 template <typename VtkmCellShapeTag>
92 struct CellShapeTagVtkmToVtkc;
93 
94 } // namespace internal
95 
100 #define VTKM_IS_CELL_SHAPE_TAG(tag) \
101  VTKM_STATIC_ASSERT_MSG(::vtkm::internal::CellShapeTagCheck<tag>::value, \
102  "Provided type is not a valid VTK-m cell shape tag.")
103 
106 template <vtkm::IdComponent Id>
108 {
109  // If you get a compile error for this class about Id not being defined, that
110  // probably means you are using an ID that does not have a defined cell
111  // shape.
112 
113  using valid = std::false_type;
114 };
115 
116 // Define a tag for each cell shape as well as the support structs to go
117 // between tags and ids. The following macro is only valid here.
118 
119 #define VTKM_DEFINE_CELL_TAG(name, idname) \
120  struct CellShapeTag##name \
121  { \
122  static constexpr vtkm::UInt8 Id = vtkm::idname; \
123  }; \
124  namespace internal \
125  { \
126  template <> \
127  struct CellShapeTagCheck<vtkm::CellShapeTag##name> : std::true_type \
128  { \
129  }; \
130  template <> \
131  struct CellShapeTagVtkmToVtkc<vtkm::CellShapeTag##name> \
132  { \
133  using Type = lcl::name; \
134  }; \
135  } \
136  static inline VTKM_EXEC_CONT const char* GetCellShapeName(vtkm::CellShapeTag##name) \
137  { \
138  return #name; \
139  } \
140  template <> \
141  struct CellShapeIdToTag<vtkm::idname> \
142  { \
143  using valid = std::true_type; \
144  using Tag = vtkm::CellShapeTag##name; \
145  }
146 
149 //VTKM_DEFINE_CELL_TAG(PolyVertex, CELL_SHAPE_POLY_VERTEX);
153 //VTKM_DEFINE_CELL_TAG(TriangleStrip, CELL_SHAPE_TRIANGLE_STRIP);
155 //VTKM_DEFINE_CELL_TAG(Pixel, CELL_SHAPE_PIXEL);
158 //VTKM_DEFINE_CELL_TAG(Voxel, CELL_SHAPE_VOXEL);
162 
163 #undef VTKM_DEFINE_CELL_TAG
164 
171 {
174  : Id(shape)
175  {
176  }
177 
181 };
182 
183 namespace internal
184 {
185 
186 template <typename VtkmCellShapeTag>
187 VTKM_EXEC_CONT inline typename CellShapeTagVtkmToVtkc<VtkmCellShapeTag>::Type make_LclCellShapeTag(
188  const VtkmCellShapeTag&,
189  vtkm::IdComponent numPoints = 0)
190 {
191  using VtkcCellShapeTag = typename CellShapeTagVtkmToVtkc<VtkmCellShapeTag>::Type;
192  static_cast<void>(numPoints); // unused
193  return VtkcCellShapeTag{};
194 }
195 
197 inline lcl::Polygon make_LclCellShapeTag(const vtkm::CellShapeTagPolygon&,
198  vtkm::IdComponent numPoints = 0)
199 {
200  return lcl::Polygon(numPoints);
201 }
202 
204 inline lcl::Cell make_LclCellShapeTag(const vtkm::CellShapeTagGeneric& tag,
205  vtkm::IdComponent numPoints = 0)
206 {
207  return lcl::Cell(static_cast<std::int8_t>(tag.Id), numPoints);
208 }
209 
210 } // namespace internal
211 
212 #define vtkmGenericCellShapeMacroCase(cellShapeId, call) \
213  case vtkm::cellShapeId: \
214  { \
215  using CellShapeTag = vtkm::CellShapeIdToTag<vtkm::cellShapeId>::Tag; \
216  call; \
217  } \
218  break
219 
250 #define vtkmGenericCellShapeMacro(call) \
251  vtkmGenericCellShapeMacroCase(CELL_SHAPE_EMPTY, call); \
252  vtkmGenericCellShapeMacroCase(CELL_SHAPE_VERTEX, call); \
253  vtkmGenericCellShapeMacroCase(CELL_SHAPE_LINE, call); \
254  vtkmGenericCellShapeMacroCase(CELL_SHAPE_POLY_LINE, call); \
255  vtkmGenericCellShapeMacroCase(CELL_SHAPE_TRIANGLE, call); \
256  vtkmGenericCellShapeMacroCase(CELL_SHAPE_POLYGON, call); \
257  vtkmGenericCellShapeMacroCase(CELL_SHAPE_QUAD, call); \
258  vtkmGenericCellShapeMacroCase(CELL_SHAPE_TETRA, call); \
259  vtkmGenericCellShapeMacroCase(CELL_SHAPE_HEXAHEDRON, call); \
260  vtkmGenericCellShapeMacroCase(CELL_SHAPE_WEDGE, call); \
261  vtkmGenericCellShapeMacroCase(CELL_SHAPE_PYRAMID, call)
262 
263 } // namespace vtkm
264 
265 #endif //vtk_m_CellShape_h
vtkm::Ray
Represent an infinite or semi-infinite line segment with a point and a direction.
Definition: Geometry.h:21
vtkm::NUMBER_OF_CELL_SHAPES
@ NUMBER_OF_CELL_SHAPES
Definition: CellShape.h:70
vtkm::CELL_SHAPE_WEDGE
@ CELL_SHAPE_WEDGE
A wedge.
Definition: CellShape.h:66
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::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
vtkm::CellShapeIdToTag
A traits-like class to get an CellShapeId known at compile time to a tag.
Definition: CellShape.h:107
vtkm::CELL_SHAPE_EMPTY
@ CELL_SHAPE_EMPTY
Placeholder for empty or invalid cells.
Definition: CellShape.h:37
vtkm::CellShapeIdToTag::valid
std::false_type valid
Definition: CellShape.h:113
vtkm::CellShapeTagPolygon
Definition: CellShape.h:154
vtkm::CellShapeIdEnum
CellShapeIdEnum
CellShapeId identifies the type of each cell.
Definition: CellShape.h:33
VTKM_DEFINE_CELL_TAG
#define VTKM_DEFINE_CELL_TAG(name, idname)
Definition: CellShape.h:119
vtkm::CELL_SHAPE_POLY_LINE
@ CELL_SHAPE_POLY_LINE
A sequence of line segments.
Definition: CellShape.h:46
vtkm::CellShapeTagGeneric::CellShapeTagGeneric
CellShapeTagGeneric(vtkm::UInt8 shape)
Definition: CellShape.h:173
vtkm::CELL_SHAPE_TETRA
@ CELL_SHAPE_TETRA
A tetrahedron.
Definition: CellShape.h:59
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::CELL_SHAPE_HEXAHEDRON
@ CELL_SHAPE_HEXAHEDRON
A hexahedron.
Definition: CellShape.h:62
vtkm::UInt8
uint8_t UInt8
Base type to use for 8-bit unsigned integer numbers.
Definition: Types.h:169
vtkm::CELL_SHAPE_TRIANGLE
@ CELL_SHAPE_TRIANGLE
A triangle.
Definition: CellShape.h:48
vtkm::CELL_SHAPE_LINE
@ CELL_SHAPE_LINE
A line cell connecting two points.
Definition: CellShape.h:42
vtkm::CellShapeTagGeneric::Id
vtkm::UInt8 Id
An identifier that corresponds to one of the CELL_SHAPE_* identifiers.
Definition: CellShape.h:180
StaticAssert.h
vtkm::CellShapeTagGeneric
A special cell shape tag that holds a cell shape that is not known at compile time.
Definition: CellShape.h:170
vtkm::CELL_SHAPE_PYRAMID
@ CELL_SHAPE_PYRAMID
A pyramid with a quadrilateral base and four triangular faces.0.
Definition: CellShape.h:68
vtkm::CELL_SHAPE_POLYGON
@ CELL_SHAPE_POLYGON
A general polygon shape.
Definition: CellShape.h:53
vtkm::CELL_SHAPE_VERTEX
@ CELL_SHAPE_VERTEX
Vertex cells of a single point.
Definition: CellShape.h:39
vtkm::CELL_SHAPE_QUAD
@ CELL_SHAPE_QUAD
A four-sided polygon.
Definition: CellShape.h:56
lcl
Definition: CellShape.h:21