h5geo 0.4.0
C++17 and python API to work with geo-data (seismic, wells, maps, other in process) based on HDF5. Aimed at geoscientists and developers.
Loading...
Searching...
No Matches
h5point.h
1#ifndef H5POINT_H
2#define H5POINT_H
3
4#include <h5gt/H5DataType.hpp>
5
6namespace h5geo {
7
8// Compound types must be trivial (POD)
9// NO constructors, NO destructors, NO virtual member,
10// NO std::string as a var member
11// check it using 'std::is_trivial<h5geo::Point3>::value'
12
13
14//------------------------POINT1------------------------//
15
17typedef struct Point1{
18 void setX(const double& x) { p[0] = x; }
19
20 double& getX() { return p[0]; }
21
22 void setName(const std::string& s){
23 size_t nChar2copy = std::min(s.size(), size_t(H5GEO_CHAR_ARRAY_SIZE - 1));
24 if (nChar2copy < 1){
25 this->name[0] = '\0';
26 } else {
27 s.copy(this->name, nChar2copy);
28 this->name[nChar2copy] = '\0';
29 }
30 }
31
32 std::string getName() { return this->name; }
33
34 double p[1];
35 // needs to be public to calculate offset
36 char name[H5GEO_CHAR_ARRAY_SIZE];
38
39typedef std::vector<h5geo::Point1> Point1Array;
40
41
42//------------------------POINT2------------------------//
43
45typedef struct Point2{
46 void setX(const double& x) { p[0] = x; }
47 void setY(const double& y) { p[1] = y; }
48
49 double& getX() { return p[0]; }
50 double& getY() { return p[1]; }
51
52 void setName(const std::string& s){
53 size_t nChar2copy = std::min(s.size(), size_t(H5GEO_CHAR_ARRAY_SIZE - 1));
54 if (nChar2copy < 1){
55 this->name[0] = '\0';
56 } else {
57 s.copy(this->name, nChar2copy);
58 this->name[nChar2copy] = '\0';
59 }
60 }
61
62 std::string getName() { return this->name; }
63
64 // members must be public to calculate offset and to provide wider API
65 double p[2];
66 char name[H5GEO_CHAR_ARRAY_SIZE];
68
69typedef std::vector<h5geo::Point2> Point2Array;
70
71
72//------------------------POINT3------------------------//
73
75typedef struct Point3{
76 void setX(const double& x) { p[0] = x; }
77 void setY(const double& y) { p[1] = y; }
78 void setZ(const double& z) { p[2] = z; }
79
80 double& getX() { return p[0]; }
81 double& getY() { return p[1]; }
82 double& getZ() { return p[2]; }
83
84 void setName(const std::string& s){
85 size_t nChar2copy = std::min(s.size(), size_t(H5GEO_CHAR_ARRAY_SIZE - 1));
86 if (nChar2copy < 1){
87 this->name[0] = '\0';
88 } else {
89 s.copy(this->name, nChar2copy);
90 this->name[nChar2copy] = '\0';
91 }
92 }
93
94 std::string getName() { return this->name; }
95
96 double p[3];
97 char name[H5GEO_CHAR_ARRAY_SIZE];
99
100typedef std::vector<h5geo::Point3> Point3Array;
101
102//------------------------POINT4------------------------//
103
106typedef struct Point4{
107 void setX(const double& x) { p[0] = x; }
108 void setY(const double& y) { p[1] = y; }
109 void setZ(const double& z) { p[2] = z; }
110 void setVal(const double& val) { p[3] = val; }
111
112 double& getX() { return p[0]; }
113 double& getY() { return p[1]; }
114 double& getZ() { return p[2]; }
115 double& getVal() { return p[3]; }
116
117 void setName(const std::string& s){
118 size_t nChar2copy = std::min(s.size(), size_t(H5GEO_CHAR_ARRAY_SIZE - 1));
119 if (nChar2copy < 1){
120 this->name[0] = '\0';
121 } else {
122 s.copy(this->name, nChar2copy);
123 this->name[nChar2copy] = '\0';
124 }
125 }
126
127 std::string getName() { return this->name; }
128
129 double p[4];
130 char name[H5GEO_CHAR_ARRAY_SIZE];
132
133typedef std::vector<h5geo::Point4> Point4Array;
134
135
136
137inline h5gt::CompoundType create_compound_Point1() {
138 h5gt::CompoundType t(
139 {
140 {"x", h5gt::AtomicType<double>{}, offsetof(Point1, p[0])},
141 {"name", h5gt::AtomicType<h5gt::FixedLenStringArray<H5GEO_CHAR_ARRAY_SIZE>>{}, offsetof(Point1, name)}
142 }, sizeof (Point1));
143
144 return t;
145}
146
147inline h5gt::CompoundType create_compound_Point2() {
148 h5gt::CompoundType t(
149 {
150 {"x", h5gt::AtomicType<double>{}, offsetof(Point2, p[0])},
151 {"y", h5gt::AtomicType<double>{}, offsetof(Point2, p[1])},
152 {"name", h5gt::AtomicType<h5gt::FixedLenStringArray<H5GEO_CHAR_ARRAY_SIZE>>{}, offsetof(Point2, name)}
153 }, sizeof (Point2));
154
155 return t;
156}
157
158inline h5gt::CompoundType create_compound_Point3() {
159 h5gt::CompoundType t(
160 {
161 {"x", h5gt::AtomicType<double>{}, offsetof(Point3, p[0])},
162 {"y", h5gt::AtomicType<double>{}, offsetof(Point3, p[1])},
163 {"z", h5gt::AtomicType<double>{}, offsetof(Point3, p[2])},
164 {"name", h5gt::AtomicType<h5gt::FixedLenStringArray<H5GEO_CHAR_ARRAY_SIZE>>{}, offsetof(Point3, name)}
165 }, sizeof (Point3));
166
167 return t;
168}
169
170inline h5gt::CompoundType create_compound_Point4() {
171 h5gt::CompoundType t(
172 {
173 {"x", h5gt::AtomicType<double>{}, offsetof(Point4, p[0])},
174 {"y", h5gt::AtomicType<double>{}, offsetof(Point4, p[1])},
175 {"z", h5gt::AtomicType<double>{}, offsetof(Point4, p[2])},
176 {"val", h5gt::AtomicType<double>{}, offsetof(Point4, p[3])},
177 {"name", h5gt::AtomicType<h5gt::FixedLenStringArray<H5GEO_CHAR_ARRAY_SIZE>>{}, offsetof(Point4, name)}
178 }, sizeof (Point4));
179
180 return t;
181}
182
183
184} // h5geo
185
186
187H5GT_REGISTER_TYPE(h5geo::Point1, h5geo::create_compound_Point1);
188H5GT_REGISTER_TYPE(h5geo::Point2, h5geo::create_compound_Point2);
189H5GT_REGISTER_TYPE(h5geo::Point3, h5geo::create_compound_Point3);
190H5GT_REGISTER_TYPE(h5geo::Point4, h5geo::create_compound_Point4);
191
192#endif // H5CORE_TYPES_H
Basic namespace.
Definition h5base.h:29
struct h5geo::Point2 Point2
X, Y are always length.
struct h5geo::Point4 Point4
struct h5geo::Point3 Point3
X, Y are always length, Z either length or time (depending on Domain)
struct h5geo::Point1 Point1
X maybe length or time (depending on Domain)
X maybe length or time (depending on Domain)
Definition h5point.h:17
X, Y are always length.
Definition h5point.h:45
X, Y are always length, Z either length or time (depending on Domain)
Definition h5point.h:75
Definition h5point.h:106