1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
/////////////////////////////////////////////////////////////
// //
// Copyright (c) 2003-2014 by The University of Queensland //
// Centre for Geoscience Computing //
// http://earth.uq.edu.au/centre-geoscience-computing //
// //
// Primary Business: Brisbane, Queensland, Australia //
// Licensed under the Open Software License version 3.0 //
// http://www.apache.org/licenses/LICENSE-2.0 //
// //
/////////////////////////////////////////////////////////////
#ifndef ESYS_LSM_VTKDATATYPE_H
#define ESYS_LSM_VTKDATATYPE_H
#include <vector>
#include <map>
#include <iostream>
#include <sstream>
#include "Foundation/vec3.h"
#include "Foundation/Matrix3.h"
namespace esys
{
namespace lsm
{
namespace vtk
{
typedef std::string ValueTypeName;
typedef std::string FormatTypeName;
static const ValueTypeName UInt8 = "UInt8";
static const ValueTypeName Int16 = "Int16";
static const ValueTypeName UInt16 = "UInt16";
static const ValueTypeName Int32 = "Int32";
static const ValueTypeName UInt32 = "UInt32";
static const ValueTypeName Int64 = "Int64";
static const ValueTypeName UInt64 = "UInt64";
static const ValueTypeName Float32 = "Float32";
static const ValueTypeName Float64 = "Float64";
static const FormatTypeName ascii = "ascii";
static const FormatTypeName binary = "binary";
static const FormatTypeName appended = "appended";
template <typename TmplType>
std::string quote(const TmplType &thing)
{
std::stringstream sStream;
sStream << "\"" << thing << "\"";
return sStream.str();
}
template <typename TmplValueType>
class DataType
{
public:
typedef TmplValueType value_type;
DataType(
const ValueTypeName &valueTypeName,
const std::string &dataName,
unsigned int numComponents,
const FormatTypeName &format = ascii,
unsigned int offset = 0
) :
m_valueTypeName(valueTypeName),
m_dataName(dataName),
m_numComponents(numComponents),
m_format(format),
m_offset(offset)
{
}
std::string getXmlAttributeString() const
{
std::stringstream sStream;
sStream
<< "type=" << quote(m_valueTypeName) << " "
<< "Name=" << quote(m_dataName) << " "
<< "NumberOfComponents=" << quote(m_numComponents) << " "
<< "format=" << quote(m_format);
if (m_format == appended) {
sStream << " offset=" << quote(m_offset);
}
return sStream.str();
}
private:
ValueTypeName m_valueTypeName;
std::string m_dataName;
unsigned int m_numComponents;
FormatTypeName m_format;
unsigned int m_offset;
};
class Float64Type : public DataType<double>
{
public:
typedef DataType<double> Inherited;
Float64Type(
const std::string &name,
const FormatTypeName &format=ascii,
int offset=0
)
: Inherited(Float64, name, 1, format, offset)
{
}
};
class Float32Type : public DataType<float>
{
public:
typedef DataType<float> Inherited;
Float32Type(
const std::string &name,
const FormatTypeName &format=ascii,
int offset=0
)
: Inherited(Float32, name, 1, format, offset)
{
}
};
class UInt8Type : public DataType<unsigned char>
{
public:
typedef DataType<unsigned char> Inherited;
UInt8Type(
const std::string &name,
const FormatTypeName &format=ascii,
int offset=0
)
: Inherited(UInt8, name, 1, format, offset)
{
}
};
class Int32Type : public DataType<int>
{
public:
typedef DataType<int> Inherited;
Int32Type(
const std::string &name,
const FormatTypeName &format=ascii,
int offset=0
)
: Inherited(Int32, name, 1, format, offset)
{
}
};
class Vec3Type : public DataType<Vec3>
{
public:
typedef DataType<Vec3> Inherited;
Vec3Type(
const std::string &name,
const FormatTypeName &format=ascii,
int offset=0
)
: Inherited(Float64, name, 3, format, offset)
{
}
};
class Matrix3Type : public DataType<Matrix3>
{
public:
typedef DataType<Matrix3> Inherited;
Matrix3Type(
const std::string &name,
const FormatTypeName &format=ascii,
int offset=0
)
: Inherited(Float64, name, 9, format, offset)
{
}
};
}
}
}
#endif
|