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
23#include <vrs/VrsExport.h>
24
25namespace vrs {
26
27using std::enable_if;
28using std::size_t;
29
30#pragma pack(push, 1)
31
39class VRS_API Bool {
40 public:
41 // NOLINTNEXTLINE(hicpp-explicit-conversions)
42 Bool(bool value = false) : value_(value) {}
43 Bool& operator=(bool value) {
44 value_ = value;
45 return *this;
46 }
47 // NOLINTNEXTLINE(hicpp-explicit-conversions)
48 operator bool() const {
49 return value_;
50 }
51 const bool* operator&() const {
52 return &value_;
53 }
54 bool* operator&() {
55 return &value_;
56 }
57 bool operator==(const Bool& rhs) const {
58 return value_ == rhs.value_;
59 }
60 bool operator==(bool rhs) const {
61 return value_ == rhs;
62 }
63 bool operator!=(const Bool& rhs) const {
64 return value_ != rhs.value_;
65 }
66 bool operator!=(bool rhs) const {
67 return value_ != rhs;
68 }
69
70 private:
71 bool value_;
72};
73
78template <typename T, size_t N>
79struct PointND {
80 using type = T;
81 static constexpr size_t kSize = N;
82
83 PointND() : dim{} {}
84 /* implicit */ PointND(const T arr[N]) {
85 operator=(arr);
86 }
87
89 template <typename Z = enable_if<(N == 2), T>>
90 PointND(T x, T y) : dim{x, y} {}
91
93 template <typename Z = enable_if<(N == 3), T>>
94 PointND(T x, T y, T z) : dim{x, y, z} {}
95
97 template <typename W = enable_if<(N == 4), T>>
98 PointND(T x, T y, T z, T w) : dim{x, y, z, w} {}
99
100 bool operator==(const PointND<T, N>& rhs) const {
101 for (size_t s = 0; s < N; s++) {
102 if (dim[s] != rhs.dim[s]) {
103 return false;
104 }
105 }
106 return true;
107 }
108 bool operator!=(const PointND<T, N>& rhs) const {
109 return !operator==(rhs);
110 }
111 PointND& operator=(const T rhs[N]) {
112 for (size_t s = 0; s < N; s++) {
113 dim[s] = rhs[s];
114 }
115 return *this;
116 }
117
118 // Convenience aliases for the dimensions that actually exist
119 T& x() {
120 return dim[0];
121 }
122 const T& x() const {
123 return dim[0];
124 }
125 T& y() {
126 return dim[1];
127 }
128 const T& y() const {
129 return dim[1];
130 }
131 template <typename Z = enable_if<(N > 2), T>>
132 T& z() {
133 return dim[2];
134 }
135 template <typename Z = enable_if<(N > 2), T>>
136 const T& z() const {
137 return dim[2];
138 }
139 template <typename W = enable_if<(N > 3), T>>
140 T& w() {
141 return dim[3];
142 }
143 template <typename W = enable_if<(N > 3), T>>
144 const T& w() const {
145 return dim[3];
146 }
147
148 T& operator[](size_t n) {
149 return dim[n];
150 }
151 const T& operator[](size_t n) const {
152 return dim[n];
153 }
154
155 T dim[N];
156};
157
164
171
178
180template <typename T, size_t N>
181struct MatrixND {
182 using type = T;
183 static constexpr size_t kMatrixSize = N;
184
185 MatrixND() = default;
186 /* implicit */ 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:39
Definition Compressor.cpp:113
MatrixND< float, 2 > Matrix2Df
2D float matrix class.
Definition DataPieceTypes.h:221
PointND< double, 2 > Point2Dd
2D double point class.
Definition DataPieceTypes.h:159
MatrixND< double, 4 > Matrix4Dd
4D double matrix class.
Definition DataPieceTypes.h:233
PointND< double, 3 > Point3Dd
3D double point class.
Definition DataPieceTypes.h:166
PointND< double, 4 > Point4Dd
4D double point class.
Definition DataPieceTypes.h:173
PointND< int32_t, 2 > Point2Di
2D int32_t point class.
Definition DataPieceTypes.h:163
MatrixND< float, 4 > Matrix4Df
4D float matrix class.
Definition DataPieceTypes.h:235
PointND< float, 2 > Point2Df
2D float point class.
Definition DataPieceTypes.h:161
MatrixND< float, 3 > Matrix3Df
3D float matrix class.
Definition DataPieceTypes.h:228
PointND< float, 4 > Point4Df
4D float point class.
Definition DataPieceTypes.h:175
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:168
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:170
PointND< int32_t, 4 > Point4Di
4D int32_t point class.
Definition DataPieceTypes.h:177
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:181
POD type for of 2, 3 and 4 dimensions points, each for either int32_t, float or double.
Definition DataPieceTypes.h:79
PointND(T x, T y, T z)
3D point constructor
Definition DataPieceTypes.h:94
PointND(T x, T y)
2D point constructor
Definition DataPieceTypes.h:90
PointND(T x, T y, T z, T w)
4D point constructor
Definition DataPieceTypes.h:98