Viskores  1.0
CellShape.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_CellShape_h
19 #define viskores_CellShape_h
20 
21 #include <viskores/StaticAssert.h>
22 #include <viskores/Types.h>
23 
24 #include <lcl/Polygon.h>
25 #include <lcl/Shapes.h>
26 
27 // Vtk-c does not have tags for Empty and PolyLine. Define dummy tags here to
28 // avoid compilation errors. These tags are not used anywhere.
29 namespace lcl
30 {
31 struct Empty;
32 struct PolyLine;
33 }
34 
35 namespace viskores
36 {
37 
42 {
43  // Linear cells
45  CELL_SHAPE_EMPTY = lcl::ShapeId::EMPTY,
47  CELL_SHAPE_VERTEX = lcl::ShapeId::VERTEX,
48  //CELL_SHAPE_POLY_VERTEX = 2,
50  CELL_SHAPE_LINE = lcl::ShapeId::LINE,
56  CELL_SHAPE_TRIANGLE = lcl::ShapeId::TRIANGLE,
57  //CELL_SHAPE_TRIANGLE_STRIP = 6,
61  CELL_SHAPE_POLYGON = lcl::ShapeId::POLYGON,
62  //CELL_SHAPE_PIXEL = 8,
64  CELL_SHAPE_QUAD = lcl::ShapeId::QUAD,
67  CELL_SHAPE_TETRA = lcl::ShapeId::TETRA,
68  //CELL_SHAPE_VOXEL = 11,
70  CELL_SHAPE_HEXAHEDRON = lcl::ShapeId::HEXAHEDRON,
74  CELL_SHAPE_WEDGE = lcl::ShapeId::WEDGE,
76  CELL_SHAPE_PYRAMID = lcl::ShapeId::PYRAMID,
77 
79 };
80 
81 // If you wish to add cell shapes to this list, in addition to adding an index
82 // to the enum above, you at a minimum need to define an associated tag with
83 // VISKORES_DEFINE_CELL_TAG and add a condition to the viskoresGenericCellShapeMacro.
84 // There are also many other cell-specific features that code might expect such
85 // as \c CellTraits and interpolations.
86 
87 namespace internal
88 {
89 
93 template <typename T>
94 struct CellShapeTagCheck : std::false_type
95 {
96 };
97 
99 template <typename ViskoresCellShapeTag>
100 struct CellShapeTagViskoresToVtkc;
101 
102 } // namespace internal
103 
108 #define VISKORES_IS_CELL_SHAPE_TAG(tag) \
109  VISKORES_STATIC_ASSERT_MSG(::viskores::internal::CellShapeTagCheck<tag>::value, \
110  "Provided type is not a valid Viskores cell shape tag.")
111 
114 template <viskores::IdComponent Id>
116 {
117  // If you get a compile error for this class about Id not being defined, that
118  // probably means you are using an ID that does not have a defined cell
119  // shape.
120 
121  using valid = std::false_type;
122 };
123 
124 // Define a tag for each cell shape as well as the support structs to go
125 // between tags and ids. The following macro is only valid here.
126 
127 #define VISKORES_DEFINE_CELL_TAG(name, idname) \
128  struct CellShapeTag##name \
129  { \
130  static constexpr viskores::UInt8 Id = viskores::idname; \
131  }; \
132  namespace internal \
133  { \
134  template <> \
135  struct CellShapeTagCheck<viskores::CellShapeTag##name> : std::true_type \
136  { \
137  }; \
138  template <> \
139  struct CellShapeTagViskoresToVtkc<viskores::CellShapeTag##name> \
140  { \
141  using Type = lcl::name; \
142  }; \
143  } \
144  static inline VISKORES_EXEC_CONT const char* GetCellShapeName(viskores::CellShapeTag##name) \
145  { \
146  return #name; \
147  } \
148  template <> \
149  struct CellShapeIdToTag<viskores::idname> \
150  { \
151  using valid = std::true_type; \
152  using Tag = viskores::CellShapeTag##name; \
153  }
154 
157 //VISKORES_DEFINE_CELL_TAG(PolyVertex, CELL_SHAPE_POLY_VERTEX);
161 //VISKORES_DEFINE_CELL_TAG(TriangleStrip, CELL_SHAPE_TRIANGLE_STRIP);
163 //VISKORES_DEFINE_CELL_TAG(Pixel, CELL_SHAPE_PIXEL);
166 //VISKORES_DEFINE_CELL_TAG(Voxel, CELL_SHAPE_VOXEL);
170 
171 #undef VISKORES_DEFINE_CELL_TAG
172 
179 {
182  : Id(shape)
183  {
184  }
185 
189 };
190 
191 namespace internal
192 {
193 
194 template <typename ViskoresCellShapeTag>
195 VISKORES_EXEC_CONT inline typename CellShapeTagViskoresToVtkc<ViskoresCellShapeTag>::Type
196 make_LclCellShapeTag(const ViskoresCellShapeTag&, viskores::IdComponent numPoints = 0)
197 {
198  using VtkcCellShapeTag = typename CellShapeTagViskoresToVtkc<ViskoresCellShapeTag>::Type;
199  static_cast<void>(numPoints); // unused
200  return VtkcCellShapeTag{};
201 }
202 
204 inline lcl::Polygon make_LclCellShapeTag(const viskores::CellShapeTagPolygon&,
205  viskores::IdComponent numPoints = 0)
206 {
207  return lcl::Polygon(numPoints);
208 }
209 
211 inline lcl::Cell make_LclCellShapeTag(const viskores::CellShapeTagGeneric& tag,
212  viskores::IdComponent numPoints = 0)
213 {
214  return lcl::Cell(static_cast<std::int8_t>(tag.Id), numPoints);
215 }
216 
217 } // namespace internal
218 
219 #define viskoresGenericCellShapeMacroCase(cellShapeId, call) \
220  case viskores::cellShapeId: \
221  { \
222  using CellShapeTag = viskores::CellShapeIdToTag<viskores::cellShapeId>::Tag; \
223  call; \
224  } \
225  break
226 
257 #define viskoresGenericCellShapeMacro(call) \
258  viskoresGenericCellShapeMacroCase(CELL_SHAPE_EMPTY, call); \
259  viskoresGenericCellShapeMacroCase(CELL_SHAPE_VERTEX, call); \
260  viskoresGenericCellShapeMacroCase(CELL_SHAPE_LINE, call); \
261  viskoresGenericCellShapeMacroCase(CELL_SHAPE_POLY_LINE, call); \
262  viskoresGenericCellShapeMacroCase(CELL_SHAPE_TRIANGLE, call); \
263  viskoresGenericCellShapeMacroCase(CELL_SHAPE_POLYGON, call); \
264  viskoresGenericCellShapeMacroCase(CELL_SHAPE_QUAD, call); \
265  viskoresGenericCellShapeMacroCase(CELL_SHAPE_TETRA, call); \
266  viskoresGenericCellShapeMacroCase(CELL_SHAPE_HEXAHEDRON, call); \
267  viskoresGenericCellShapeMacroCase(CELL_SHAPE_WEDGE, call); \
268  viskoresGenericCellShapeMacroCase(CELL_SHAPE_PYRAMID, call)
269 
270 } // namespace viskores
271 
272 #endif //viskores_CellShape_h
viskores::CELL_SHAPE_PYRAMID
@ CELL_SHAPE_PYRAMID
A pyramid with a quadrilateral base and four triangular faces.0.
Definition: CellShape.h:76
viskores::CELL_SHAPE_POLYGON
@ CELL_SHAPE_POLYGON
A general polygon shape.
Definition: CellShape.h:61
viskores::CellShapeTagGeneric::Id
viskores::UInt8 Id
An identifier that corresponds to one of the CELL_SHAPE_* identifiers.
Definition: CellShape.h:188
Types.h
viskores::CellShapeIdToTag::valid
std::false_type valid
Definition: CellShape.h:121
VISKORES_DEFINE_CELL_TAG
#define VISKORES_DEFINE_CELL_TAG(name, idname)
Definition: CellShape.h:127
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
viskores::CELL_SHAPE_HEXAHEDRON
@ CELL_SHAPE_HEXAHEDRON
A hexahedron.
Definition: CellShape.h:70
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
viskores::CellShapeTagGeneric
A special cell shape tag that holds a cell shape that is not known at compile time.
Definition: CellShape.h:178
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
viskores::CELL_SHAPE_WEDGE
@ CELL_SHAPE_WEDGE
A wedge.
Definition: CellShape.h:74
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::CellShapeIdEnum
CellShapeIdEnum
CellShapeId identifies the type of each cell.
Definition: CellShape.h:41
viskores::CELL_SHAPE_TRIANGLE
@ CELL_SHAPE_TRIANGLE
A triangle.
Definition: CellShape.h:56
viskores::CELL_SHAPE_TETRA
@ CELL_SHAPE_TETRA
A tetrahedron.
Definition: CellShape.h:67
viskores::CELL_SHAPE_EMPTY
@ CELL_SHAPE_EMPTY
Placeholder for empty or invalid cells.
Definition: CellShape.h:45
viskores::Ray
Represent an infinite or semi-infinite line segment with a point and a direction.
Definition: Geometry.h:29
viskores::UInt8
uint8_t UInt8
Base type to use for 8-bit unsigned integer numbers.
Definition: Types.h:177
viskores::CellShapeTagPolygon
Definition: CellShape.h:162
viskores::CellShapeIdToTag
A traits-like class to get an CellShapeId known at compile time to a tag.
Definition: CellShape.h:115
viskores::CELL_SHAPE_VERTEX
@ CELL_SHAPE_VERTEX
Vertex cells of a single point.
Definition: CellShape.h:47
StaticAssert.h
viskores::CELL_SHAPE_QUAD
@ CELL_SHAPE_QUAD
A four-sided polygon.
Definition: CellShape.h:64
viskores::NUMBER_OF_CELL_SHAPES
@ NUMBER_OF_CELL_SHAPES
Definition: CellShape.h:78
viskores::CellShapeTagGeneric::CellShapeTagGeneric
CellShapeTagGeneric(viskores::UInt8 shape)
Definition: CellShape.h:181
viskores::CELL_SHAPE_POLY_LINE
@ CELL_SHAPE_POLY_LINE
A sequence of line segments.
Definition: CellShape.h:54
viskores::CELL_SHAPE_LINE
@ CELL_SHAPE_LINE
A line cell connecting two points.
Definition: CellShape.h:50
lcl
Definition: CellShape.h:29