CellTraits.h 5.21 KB
Newer Older
Kenneth Moreland's avatar
Kenneth Moreland committed
1 2 3 4 5 6 7 8
//============================================================================
//  Copyright (c) Kitware, Inc.
//  All rights reserved.
//  See LICENSE.txt for details.
//  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.
//
9
//  Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
Kenneth Moreland's avatar
Kenneth Moreland committed
10 11 12
//  Copyright 2014 UT-Battelle, LLC.
//  Copyright 2014 Los Alamos National Security.
//
13
//  Under the terms of Contract DE-NA0003525 with NTESS,
Kenneth Moreland's avatar
Kenneth Moreland committed
14 15 16 17 18 19 20 21 22 23 24
//  the U.S. Government retains certain rights in this software.
//
//  Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
//  Laboratory (LANL), the U.S. Government retains certain rights in
//  this software.
//============================================================================
#ifndef vtk_m_CellTraits_h
#define vtk_m_CellTraits_h

#include <vtkm/CellShape.h>

25 26
namespace vtkm
{
Kenneth Moreland's avatar
Kenneth Moreland committed
27 28 29 30 31

/// \c vtkm::CellTraits::TopologyDimensionType is typedef to this with the
/// template parameter set to \c TOPOLOGICAL_DIMENSIONS. See \c
/// vtkm::CellTraits for more information.
///
32 33 34 35
template <vtkm::IdComponent dimension>
struct CellTopologicalDimensionsTag
{
};
Kenneth Moreland's avatar
Kenneth Moreland committed
36

37 38
/// \brief Tag for cell shapes with a fixed number of points.
///
39 40 41
struct CellTraitsTagSizeFixed
{
};
42 43 44

/// \brief Tag for cell shapes that can have a variable number of points.
///
45 46 47
struct CellTraitsTagSizeVariable
{
};
48

Kenneth Moreland's avatar
Kenneth Moreland committed
49 50 51 52 53 54
/// \brief Information about a cell based on its tag.
///
/// The templated CellTraits struct provides the basic high level information
/// about cells (like the number of vertices in the cell or its
/// dimensionality).
///
55
template <class CellTag>
Kenneth Moreland's avatar
Kenneth Moreland committed
56 57 58 59 60 61
struct CellTraits
#ifdef VTKM_DOXYGEN_ONLY
{
  /// This defines the topological dimensions of the cell type. 3 for
  /// polyhedra, 2 for polygons, 1 for lines, 0 for points.
  ///
62
  static const vtkm::IdComponent TOPOLOGICAL_DIMENSIONS = 3;
Kenneth Moreland's avatar
Kenneth Moreland committed
63 64 65 66 67 68

  /// This tag is typedef'ed to
  /// vtkm::CellTopologicalDimensionsTag<TOPOLOGICAL_DIMENSIONS>. This provides
  /// a convenient way to overload a function based on topological dimensions
  /// (which is usually more efficient than conditionals).
  ///
69
  using TopologicalDimensionsTag = vtkm::CellTopologicalDimensionsTag<TOPOLOGICAL_DIMENSIONS>;
70 71 72 73 74 75 76

  /// \brief A tag specifying whether the number of points is fixed.
  ///
  /// If set to \c CellTraitsTagSizeFixed, then \c NUM_POINTS is set. If set to
  /// \c CellTraitsTagSizeVariable, then the number of points is not known at
  /// compile time.
  ///
77
  using IsSizeFixed = vtkm::CellTraitsTagSizeFixed;
78 79 80 81 82 83

  /// \brief Number of points in the cell.
  ///
  /// This is only defined for cell shapes of a fixed number of points (i.e.
  /// \c IsSizedFixed is set to \c CellTraitsTagSizeFixed.
  ///
84
  static constexpr vtkm::IdComponent NUM_POINTS = 3;
Kenneth Moreland's avatar
Kenneth Moreland committed
85
};
86 87
#else  // VTKM_DOXYGEN_ONLY
  ;
Kenneth Moreland's avatar
Kenneth Moreland committed
88 89 90 91 92 93
#endif // VTKM_DOXYGEN_ONLY

//-----------------------------------------------------------------------------

// Define traits for every cell type.

94 95 96 97
#define VTKM_DEFINE_CELL_TRAITS(name, dimensions, numPoints)                                       \
  template <>                                                                                      \
  struct CellTraits<vtkm::CellShapeTag##name>                                                      \
  {                                                                                                \
98 99 100 101
    static constexpr vtkm::IdComponent TOPOLOGICAL_DIMENSIONS = dimensions;                        \
    using TopologicalDimensionsTag = vtkm::CellTopologicalDimensionsTag<TOPOLOGICAL_DIMENSIONS>;   \
    using IsSizeFixed = vtkm::CellTraitsTagSizeFixed;                                              \
    static constexpr vtkm::IdComponent NUM_POINTS = numPoints;                                     \
102 103
  }

104 105 106 107
#define VTKM_DEFINE_CELL_TRAITS_VARIABLE(name, dimensions)                                         \
  template <>                                                                                      \
  struct CellTraits<vtkm::CellShapeTag##name>                                                      \
  {                                                                                                \
108 109 110
    static constexpr vtkm::IdComponent TOPOLOGICAL_DIMENSIONS = dimensions;                        \
    using TopologicalDimensionsTag = vtkm::CellTopologicalDimensionsTag<TOPOLOGICAL_DIMENSIONS>;   \
    using IsSizeFixed = vtkm::CellTraitsTagSizeVariable;                                           \
Kenneth Moreland's avatar
Kenneth Moreland committed
111 112
  }

113 114 115 116 117 118 119 120
VTKM_DEFINE_CELL_TRAITS(Empty, 0, 0);
VTKM_DEFINE_CELL_TRAITS(Vertex, 0, 1);
//VTKM_DEFINE_CELL_TRAITS_VARIABLE(PolyVertex, 0);
VTKM_DEFINE_CELL_TRAITS(Line, 1, 2);
//VTKM_DEFINE_CELL_TRAITS_VARIABLE(PolyLine, 1);
VTKM_DEFINE_CELL_TRAITS(Triangle, 2, 3);
//VTKM_DEFINE_CELL_TRAITS_VARIABLE(TriangleStrip, 2);
VTKM_DEFINE_CELL_TRAITS_VARIABLE(Polygon, 2);
121
//VTKM_DEFINE_CELL_TRAITS(Pixel, 2, 4);
122 123
VTKM_DEFINE_CELL_TRAITS(Quad, 2, 4);
VTKM_DEFINE_CELL_TRAITS(Tetra, 3, 4);
124
//VTKM_DEFINE_CELL_TRAITS(Voxel, 3, 8);
125 126 127
VTKM_DEFINE_CELL_TRAITS(Hexahedron, 3, 8);
VTKM_DEFINE_CELL_TRAITS(Wedge, 3, 6);
VTKM_DEFINE_CELL_TRAITS(Pyramid, 3, 5);
Kenneth Moreland's avatar
Kenneth Moreland committed
128 129 130 131 132 133

#undef VTKM_DEFINE_CELL_TRAITS

} // namespace vtkm

#endif //vtk_m_CellTraits_h