VRS
A file format for sensor data.
Loading...
Searching...
No Matches
DataPieceTypes.h
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <cstdint>
20
21#include <type_traits>
22
23namespace vrs {
24
25using std::enable_if;
26using std::size_t;
27
28#pragma pack(push, 1)
29
37class Bool {
38 public:
39 // NOLINTNEXTLINE(hicpp-explicit-conversions)
40 Bool(bool value = false) : value_(value) {}
41 Bool& operator=(bool value) {
42 value_ = value;
43 return *this;
44 }
45 // NOLINTNEXTLINE(hicpp-explicit-conversions)
46 operator bool() const {
47 return value_;
48 }
49 const bool* operator&() const {
50 return &value_;
51 }
52 bool* operator&() {
53 return &value_;
54 }
55 bool operator==(const Bool& rhs) const {
56 return value_ == rhs.value_;
57 }
58 bool operator==(bool rhs) const {
59 return value_ == rhs;
60 }
61 bool operator!=(const Bool& rhs) const {
62 return value_ != rhs.value_;
63 }
64 bool operator!=(bool rhs) const {
65 return value_ != rhs;
66 }
67
68 private:
69 bool value_;
70};
71
76template <typename T, size_t N>
77struct PointND {
78 using type = T;
79 static constexpr size_t kSize = N;
80
81 PointND() : dim{} {}
82 // NOLINTNEXTLINE(hicpp-explicit-conversions)
83 PointND(const T arr[N]) {
84 operator=(arr);
85 }
86
88 template <typename Z = enable_if<(N == 2), T>>
89 PointND(T x, T y) : dim{x, y} {}
90
92 template <typename Z = enable_if<(N == 3), T>>
93 PointND(T x, T y, T z) : dim{x, y, z} {}
94
96 template <typename W = enable_if<(N == 4), T>>
97 PointND(T x, T y, T z, T w) : dim{x, y, z, w} {}
98
99 bool operator==(const PointND<T, N>& rhs) const {
100 for (size_t s = 0; s < N; s++) {
101 if (dim[s] != rhs.dim[s]) {
102 return false;
103 }
104 }
105 return true;
106 }
107 bool operator!=(const PointND<T, N>& rhs) const {
108 return !operator==(rhs);
109 }
110 PointND& operator=(const T rhs[N]) {
111 for (size_t s = 0; s < N; s++) {
112 dim[s] = rhs[s];
113 }
114 return *this;
115 }
116
117 // Convenience aliases for the dimensions that actually exist
118 T& x() {
119 return dim[0];
120 }
121 const T& x() const {
122 return dim[0];
123 }
124 T& y() {
125 return dim[1];
126 }
127 const T& y() const {
128 return dim[1];
129 }
130 template <typename Z = enable_if<(N > 2), T>>
131 T& z() {
132 return dim[2];
133 }
134 template <typename Z = enable_if<(N > 2), T>>
135 const T& z() const {
136 return dim[2];
137 }
138 template <typename W = enable_if<(N > 3), T>>
139 T& w() {
140 return dim[3];
141 }
142 template <typename W = enable_if<(N > 3), T>>
143 const T& w() const {
144 return dim[3];
145 }
146
147 T& operator[](size_t n) {
148 return dim[n];
149 }
150 const T& operator[](size_t n) const {
151 return dim[n];
152 }
153
154 T dim[N];
155};
156
163
170
177
179template <typename T, size_t N>
180struct MatrixND {
181 using type = T;
182 static constexpr size_t kMatrixSize = N;
183
184 MatrixND() = default;
185 // NOLINTNEXTLINE(hicpp-explicit-conversions)
186 MatrixND(const T arr[N][N]) {
187 operator=(arr);
188 }
189
190 PointND<T, N>& operator[](size_t n) {
191 return points[n];
192 }
193 const PointND<T, N>& operator[](size_t n) const {
194 return points[n];
195 }
196
197 bool operator==(const MatrixND<T, N>& rhs) const {
198 for (size_t s = 0; s < N; s++) {
199 if (points[s] != rhs[s]) {
200 return false;
201 }
202 }
203 return true;
204 }
205 bool operator!=(const MatrixND<T, N>& rhs) const {
206 return !operator==(rhs);
207 }
208 MatrixND& operator=(const T rhs[N][N]) {
209 for (size_t s = 0; s < N; s++) {
210 points[s] = rhs[s];
211 }
212 return *this;
213 }
214
215 PointND<T, N> points[N];
216};
217
224
231
238
239#pragma pack(pop)
240
241} // namespace vrs
Substitute for bool POD type, which can be used safely in DataPiece templates.
Definition DataPieceTypes.h:37
Definition AsyncDiskFileChunk.hpp:49
MatrixND< float, 2 > Matrix2Df
2D float matrix class.
Definition DataPieceTypes.h:221
PointND< double, 2 > Point2Dd
2D double point class.
Definition DataPieceTypes.h:158
MatrixND< double, 4 > Matrix4Dd
4D double matrix class.
Definition DataPieceTypes.h:233
PointND< double, 3 > Point3Dd
3D double point class.
Definition DataPieceTypes.h:165
PointND< double, 4 > Point4Dd
4D double point class.
Definition DataPieceTypes.h:172
PointND< int32_t, 2 > Point2Di
2D int32_t point class.
Definition DataPieceTypes.h:162
MatrixND< float, 4 > Matrix4Df
4D float matrix class.
Definition DataPieceTypes.h:235
PointND< float, 2 > Point2Df
2D float point class.
Definition DataPieceTypes.h:160
MatrixND< float, 3 > Matrix3Df
3D float matrix class.
Definition DataPieceTypes.h:228
PointND< float, 4 > Point4Df
4D float point class.
Definition DataPieceTypes.h:174
MatrixND< int32_t, 3 > Matrix3Di
3D int32_t matrix class.
Definition DataPieceTypes.h:230
PointND< float, 3 > Point3Df
3D float point class.
Definition DataPieceTypes.h:167
MatrixND< double, 3 > Matrix3Dd
3D double matrix class.
Definition DataPieceTypes.h:226
PointND< int32_t, 3 > Point3Di
3D int32_t point class.
Definition DataPieceTypes.h:169
PointND< int32_t, 4 > Point4Di
4D int32_t point class.
Definition DataPieceTypes.h:176
MatrixND< int32_t, 2 > Matrix2Di
2D int32_t matrix class.
Definition DataPieceTypes.h:223
MatrixND< double, 2 > Matrix2Dd
2D double matrix class.
Definition DataPieceTypes.h:219
MatrixND< int32_t, 4 > Matrix4Di
4D int32_t matrix class.
Definition DataPieceTypes.h:237
Class to represent matrices of 3 and 4 dimensions, each for either int32_t, float or double.
Definition DataPieceTypes.h:180
POD type for of 2, 3 and 4 dimensions points, each for either int32_t, float or double.
Definition DataPieceTypes.h:77
PointND(T x, T y, T z)
3D point constructor
Definition DataPieceTypes.h:93
PointND(T x, T y)
2D point constructor
Definition DataPieceTypes.h:89
PointND(T x, T y, T z, T w)
4D point constructor
Definition DataPieceTypes.h:97