vtktypes.hh 3.22 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
6
7
8
9
#pragma once

#include <cstdint>
#include <map>
#include <string>
#include <vector>

#include <dune/geometry/type.hh>

10
namespace Dune { namespace experimental
Praetorius, Simon's avatar
Praetorius, Simon committed
11
12
13
14
15
16
17
18
19
{
  namespace Vtk
  {
    enum FormatTypes {
      ASCII      = 1<<0,
      BINARY     = 1<<1,
      COMPRESSED = 1<<2,
      APPENDED = BINARY | COMPRESSED
    };
Praetorius, Simon's avatar
Praetorius, Simon committed
20
    std::string to_string (FormatTypes);
Praetorius, Simon's avatar
Praetorius, Simon committed
21
22
23
24
25
26
27
28
29
30

    enum DataTypes {
      UNKNOWN = 0,
      INT8, UINT8,
      INT16, UINT16,
      INT32, UINT32,
      INT64, UINT64,
      FLOAT32 = 32,
      FLOAT64 = 64
    };
Praetorius, Simon's avatar
Praetorius, Simon committed
31
    std::string to_string (DataTypes);
Praetorius, Simon's avatar
Praetorius, Simon committed
32

33
34
35
    enum CellParametrization {
      LINEAR,
      QUADRATIC
Praetorius, Simon's avatar
Praetorius, Simon committed
36
37
    };

38
39
40
    enum CellTypes : std::uint8_t {
      // Linear VTK cell types
      VERTEX         = 1,
41
      /* POLY_VERTEX    = 2, // not supported */
42
      LINE           = 3,
43
      /* POLY_LINE      = 4, // not supported */
44
      TRIANGLE       = 5,
45
46
47
      /* TRIANGLE_STRIP = 6, // not supported */
      POLYGON        = 7,
      /* PIXEL          = 8, // not supported */
48
49
      QUAD           = 9,
      TETRA          = 10,
50
      /* VOXEL          = 11, // not supported */
51
52
53
54
55
56
57
58
59
      HEXAHEDRON     = 12,
      WEDGE          = 13,
      PYRAMID        = 14,
      // Quadratic VTK cell types
      QUADRATIC_EDGE       = 21,
      QUADRATIC_TRIANGLE   = 22,
      QUADRATIC_QUAD       = 23,
      QUADRATIC_TETRA      = 24,
      QUADRATIC_HEXAHEDRON = 25
Praetorius, Simon's avatar
Praetorius, Simon committed
60
    };
Praetorius, Simon's avatar
Praetorius, Simon committed
61
    GeometryType to_geometry (std::uint8_t);
Praetorius, Simon's avatar
Praetorius, Simon committed
62
63
64

    struct Map
    {
65
      static std::map<std::string, DataTypes> to_datatype; // String -> DataTypes
Praetorius, Simon's avatar
Praetorius, Simon committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

      template <class T> struct Type {};

      static constexpr DataTypes typeImpl (Type<std::int8_t>)   { return INT8; }
      static constexpr DataTypes typeImpl (Type<std::uint8_t>)  { return UINT8; }
      static constexpr DataTypes typeImpl (Type<std::int16_t>)  { return INT16; }
      static constexpr DataTypes typeImpl (Type<std::uint16_t>) { return UINT16; }
      static constexpr DataTypes typeImpl (Type<std::int32_t>)  { return INT32; }
      static constexpr DataTypes typeImpl (Type<std::uint32_t>) { return UINT32; }
      static constexpr DataTypes typeImpl (Type<std::int64_t>)  { return INT64; }
      static constexpr DataTypes typeImpl (Type<std::uint64_t>) { return UINT64; }
      static constexpr DataTypes typeImpl (Type<float>)       { return FLOAT32; }
      static constexpr DataTypes typeImpl (Type<double>)      { return FLOAT64; }
      static constexpr DataTypes typeImpl (Type<long double>) { return FLOAT64; }

      template <class T>
      static constexpr DataTypes type = typeImpl(Type<T>{});
Praetorius, Simon's avatar
Praetorius, Simon committed
83
84
85
86
87
88
89
    };


    /// Mapping of Dune geometry types to VTK cell types
    class CellType
    {
    public:
90
      CellType (GeometryType const& t, CellParametrization = LINEAR);
Praetorius, Simon's avatar
Praetorius, Simon committed
91

92
      /// Return VTK Cell type
Praetorius, Simon's avatar
Praetorius, Simon committed
93
94
95
96
97
      std::uint8_t type () const
      {
        return type_;
      }

98
      /// Return a permutation of Dune elemenr vertices to conform to VTK element numbering
99
      int permutation (int idx) const
Praetorius, Simon's avatar
Praetorius, Simon committed
100
101
102
103
      {
        return permutation_[idx];
      }

104
105
106
107
108
      bool noPermutation () const
      {
        return noPermutation_;
      }

Praetorius, Simon's avatar
Praetorius, Simon committed
109
110
111
    private:
      std::uint8_t type_;
      std::vector<int> permutation_;
112
      bool noPermutation_;
Praetorius, Simon's avatar
Praetorius, Simon committed
113
114
115
    };

  } // end namespace Vtk
116
}} // end namespace Dune::experimental