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 /* implicit */ PointND(const T arr[N]) {
83 operator=(arr);
84 }
85
87 template <typename Z = enable_if<(N == 2), T>>
88 PointND(T x, T y) : dim{x, y} {}
89
91 template <typename Z = enable_if<(N == 3), T>>
92 PointND(T x, T y, T z) : dim{x, y, z} {}
93
95 template <typename W = enable_if<(N == 4), T>>
96 PointND(T x, T y, T z, T w) : dim{x, y, z, w} {}
97
98 bool operator==(const PointND<T, N>& rhs) const {
99 for (size_t s = 0; s < N; s++) {
100 if (dim[s] != rhs.dim[s]) {
101 return false;
102 }
103 }
104 return true;
105 }
106 bool operator!=(const PointND<T, N>& rhs) const {
107 return !operator==(rhs);
108 }
109 PointND& operator=(const T rhs[N]) {
110 for (size_t s = 0; s < N; s++) {
111 dim[s] = rhs[s];
112 }
113 return *this;
114 }
115
116 // Convenience aliases for the dimensions that actually exist
117 T& x() {
118 return dim[0];
119 }
120 const T& x() const {
121 return dim[0];
122 }
123 T& y() {
124 return dim[1];
125 }
126 const T& y() const {
127 return dim[1];
128 }
129 template <typename Z = enable_if<(N > 2), T>>
130 T& z() {
131 return dim[2];
132 }
133 template <typename Z = enable_if<(N > 2), T>>
134 const T& z() const {
135 return dim[2];
136 }
137 template <typename W = enable_if<(N > 3), T>>
138 T& w() {
139 return dim[3];
140 }
141 template <typename W = enable_if<(N > 3), T>>
142 const T& w() const {
143 return dim[3];
144 }
145
146 T& operator[](size_t n) {
147 return dim[n];
148 }
149 const T& operator[](size_t n) const {
150 return dim[n];
151 }
152
153 T dim[N];
154};
155
162
169
176
178template <typename T, size_t N>
179struct MatrixND {
180 using type = T;
181 static constexpr size_t kMatrixSize = N;
182
183 MatrixND() = default;
184 /* implicit */ MatrixND(const T arr[N][N]) {
185 operator=(arr);
186 }
187
188 PointND<T, N>& operator[](size_t n) {
189 return points[n];
190 }
191 const PointND<T, N>& operator[](size_t n) const {
192 return points[n];
193 }
194
195 bool operator==(const MatrixND<T, N>& rhs) const {
196 for (size_t s = 0; s < N; s++) {
197 if (points[s] != rhs[s]) {
198 return false;
199 }
200 }
201 return true;
202 }
203 bool operator!=(const MatrixND<T, N>& rhs) const {
204 return !operator==(rhs);
205 }
206 MatrixND& operator=(const T rhs[N][N]) {
207 for (size_t s = 0; s < N; s++) {
208 points[s] = rhs[s];
209 }
210 return *this;
211 }
212
213 PointND<T, N> points[N];
214};
215
222
229
236
237#pragma pack(pop)
238
239} // namespace vrs
Substitute for bool POD type, which can be used safely in DataPiece templates.
Definition DataPieceTypes.h:37
Definition Compressor.cpp:113
MatrixND< float, 2 > Matrix2Df
2D float matrix class.
Definition DataPieceTypes.h:219
PointND< double, 2 > Point2Dd
2D double point class.
Definition DataPieceTypes.h:157
MatrixND< double, 4 > Matrix4Dd
4D double matrix class.
Definition DataPieceTypes.h:231
PointND< double, 3 > Point3Dd
3D double point class.
Definition DataPieceTypes.h:164
PointND< double, 4 > Point4Dd
4D double point class.
Definition DataPieceTypes.h:171
PointND< int32_t, 2 > Point2Di
2D int32_t point class.
Definition DataPieceTypes.h:161
MatrixND< float, 4 > Matrix4Df
4D float matrix class.
Definition DataPieceTypes.h:233
PointND< float, 2 > Point2Df
2D float point class.
Definition DataPieceTypes.h:159
MatrixND< float, 3 > Matrix3Df
3D float matrix class.
Definition DataPieceTypes.h:226
PointND< float, 4 > Point4Df
4D float point class.
Definition DataPieceTypes.h:173
MatrixND< int32_t, 3 > Matrix3Di
3D int32_t matrix class.
Definition DataPieceTypes.h:228
PointND< float, 3 > Point3Df
3D float point class.
Definition DataPieceTypes.h:166
MatrixND< double, 3 > Matrix3Dd
3D double matrix class.
Definition DataPieceTypes.h:224
PointND< int32_t, 3 > Point3Di
3D int32_t point class.
Definition DataPieceTypes.h:168
PointND< int32_t, 4 > Point4Di
4D int32_t point class.
Definition DataPieceTypes.h:175
MatrixND< int32_t, 2 > Matrix2Di
2D int32_t matrix class.
Definition DataPieceTypes.h:221
MatrixND< double, 2 > Matrix2Dd
2D double matrix class.
Definition DataPieceTypes.h:217
MatrixND< int32_t, 4 > Matrix4Di
4D int32_t matrix class.
Definition DataPieceTypes.h:235
Class to represent matrices of 3 and 4 dimensions, each for either int32_t, float or double.
Definition DataPieceTypes.h:179
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:92
PointND(T x, T y)
2D point constructor
Definition DataPieceTypes.h:88
PointND(T x, T y, T z, T w)
4D point constructor
Definition DataPieceTypes.h:96