| RDB 2

dataTypes.hpp
Go to the documentation of this file.
1 /*
2 *******************************************************************************
3 *
4 * Copyright 2026 RIEGL Laser Measurement Systems
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * SPDX-License-Identifier: Apache-2.0
19 *
20 *******************************************************************************
21 */
22 /*!
23 *******************************************************************************
24 *
25 * \file dataTypes.hpp
26 * \author RIEGL LMS GmbH, Austria
27 * \brief Point attribute access data types
28 * \version 2015-10-14/AW: Initial version
29 * \version 2018-07-05/AW: Add tools to get data type enum and pointer of data
30 *
31 *******************************************************************************
32 */
33
34 #ifndef RIEGL_RDB_POINTCLOUD_DATATYPES_HPP
35 #define RIEGL_RDB_POINTCLOUD_DATATYPES_HPP
36
37 //---< INCLUDES >---------------------------------------------------------------
38
39 #include <array>
40 #include <vector>
41 #include <limits>
42 #include <cstdlib>
43 #include <cstdint>
44 #include <type_traits>
45
46 //---< NAMESPACE >--------------------------------------------------------------
47
48 namespace riegl {
49 namespace rdb {
50 namespace pointcloud {
51
52 //---< ENUM DataType >----------------------------------------------------------
53 /*!
54 * \brief Point attribute access data type
55 */
56 enum DataType
57 {
58 NONE = 0, //!< undefined data type
59 UINT8 = 1, //!< 8 bit unsigned integer
60 INT8 = 2, //!< 8 bit signed integer
61 UINT16 = 3, //!< 16 bit unsigned integer
62 INT16 = 4, //!< 16 bit signed integer
63 UINT32 = 5, //!< 32 bit unsigned integer
64 INT32 = 6, //!< 32 bit signed integer
65 UINT64 = 7, //!< 64 bit unsigned integer
66 INT64 = 8, //!< 64 bit signed integer
67 SINGLE = 9, //!< 32 bit single precision floating point value
68 DOUBLE = 10, //!< 64 bit double precision floating point value
69 FLOAT32 = SINGLE, //!< 32 bit single precision floating point value
70 FLOAT64 = DOUBLE //!< 64 bit double precision floating point value
71 };
72
73 //______________________________________________________________________________
74 /*!
75 * \brief Get RDB data type enumerator from data type
76 *
77 * \see dataTypeOf()
78 */
79 template <typename ValueType>
80 class DataTypeOf
81 {
82 private:
83 template <bool Integer, bool Signed, std::size_t Size, typename dummy = void> struct data_type_of { /* void */ };
84 template <typename dummy> struct data_type_of<true, false, 1, dummy> { static const auto type = UINT8; };
85 template <typename dummy> struct data_type_of<true, true, 1, dummy> { static const auto type = INT8; };
86 template <typename dummy> struct data_type_of<true, false, 2, dummy> { static const auto type = UINT16; };
87 template <typename dummy> struct data_type_of<true, true, 2, dummy> { static const auto type = INT16; };
88 template <typename dummy> struct data_type_of<true, false, 4, dummy> { static const auto type = UINT32; };
89 template <typename dummy> struct data_type_of<true, true, 4, dummy> { static const auto type = INT32; };
90 template <typename dummy> struct data_type_of<true, false, 8, dummy> { static const auto type = UINT64; };
91 template <typename dummy> struct data_type_of<true, true, 8, dummy> { static const auto type = INT64; };
92 template <typename dummy> struct data_type_of<false, true, 4, dummy> { static const auto type = FLOAT32; };
93 template <typename dummy> struct data_type_of<false, true, 8, dummy> { static const auto type = FLOAT64; };
94
95 private:
96 template <typename SomeType>
97 struct remove_container // no container at all or not supported container
98 {
99 typedef SomeType type;
100 };
101
102 template <typename SomeType, std::size_t Size>
103 struct remove_container< SomeType[Size] > // C style array
104 {
105 typedef SomeType type;
106 };
107
108 template <typename SomeType, std::size_t Size>
109 struct remove_container< std::array<SomeType, Size> > // C++ array
110 {
111 typedef SomeType type;
112 };
113
114 template <typename SomeType, class Allocator>
115 struct remove_container< std::vector<SomeType, Allocator> > // C++ vector
116 {
117 typedef SomeType type;
118 };
119
120 private:
121 typedef typename std::remove_cv <ValueType>::type TempType1;
122 typedef typename std::remove_pointer<TempType1>::type TempType2;
123 typedef typename std::remove_cv <TempType2>::type TempType3;
124 typedef typename remove_container <TempType3>::type TempType4;
125 typedef typename remove_container <TempType4>::type CoreType;
126
127 public:
128 //! Result RDB data type enumerator for given ValueType
129 static const DataType type = data_type_of<
130 std::numeric_limits<CoreType>::is_integer,
131 std::numeric_limits<CoreType>::is_signed,
132 sizeof(CoreType)
133 >::type;
134 };
135
136 //______________________________________________________________________________
137 /*!
138 * \brief Convenience wrapper for DataTypeOf class
139 *
140 * Example:
141 * \code
142 * std::cout << int(dataTypeOf< std::int32_t >()); // prints "6"
143 * std::cout << int(dataTypeOf< std::array<double,3> >()); // prints "10"
144 * \endcode
145 */
146 template <typename ValueType>
147 DataType dataTypeOf()
148 {
149 return DataTypeOf<ValueType>::type;
150 }
151
152 //______________________________________________________________________________
153 /*!
154 * \brief Convenience wrapper for DataTypeOf class
155 *
156 * Example:
157 * \code
158 * float amplitude;
159 * std::array<double,3> xyz;
160 * std::cout << int(dataTypeOf(amplitude)); // prints "9"
161 * std::cout << int(dataTypeOf(xyz)); // prints "10"
162 * \endcode
163 */
164 template <typename ValueType>
165 DataType dataTypeOf(const ValueType& value)
166 {
167 return DataTypeOf<ValueType>::type;
168 (void)value; // unused
169 }
170
171 //______________________________________________________________________________
172 /*!
173 * \brief Get pointer to variable or to data in a std::array or vector container
174 */
175 template <typename ValueType>
176 ValueType* dataPointerOf(ValueType* const value)
177 {
178 return value;
179 }
180 //! \copydoc dataPointerOf()
181 template <typename ValueType>
182 const ValueType* dataPointerOf(const ValueType* const value)
183 {
184 return value;
185 }
186 //! \copydoc dataPointerOf()
187 template <typename ValueType>
188 ValueType* dataPointerOf(ValueType& value)
189 {
190 return &value;
191 }
192 //! \copydoc dataPointerOf()
193 template <typename ValueType>
194 const ValueType* dataPointerOf(const ValueType& value)
195 {
196 return &value;
197 }
198 //! \copydoc dataPointerOf()
199 template <typename ValueType, std::size_t Size>
200 ValueType* dataPointerOf(std::array<ValueType, Size>& value)
201 {
202 return value.data();
203 }
204 //! \copydoc dataPointerOf()
205 template <typename ValueType, std::size_t Size>
206 const ValueType* dataPointerOf(const std::array<ValueType, Size>& value)
207 {
208 return value.data();
209 }
210 //! \copydoc dataPointerOf()
211 template <typename ValueType, class Allocator>
212 ValueType* dataPointerOf(std::vector<ValueType, Allocator>& value)
213 {
214 return value.data();
215 }
216 //! \copydoc dataPointerOf()
217 template <typename ValueType, class Allocator>
218 const ValueType* dataPointerOf(const std::vector<ValueType, Allocator>& value)
219 {
220 return value.data();
221 }
222
223 }}} // namespace riegl::rdb::pointcloud
224
225 #endif // RIEGL_RDB_POINTCLOUD_DATATYPES_HPP
riegl::rdb::pointcloud::INT64
64 bit signed integer
Definition: dataTypes.hpp:66
riegl::rdb::pointcloud::DataType
DataType
Point attribute access data type.
Definition: dataTypes.hpp:56
riegl::rdb::pointcloud::DataTypeOf
Get RDB data type enumerator from data type.
Definition: dataTypes.hpp:80
riegl::rdb::pointcloud::NONE
undefined data type
Definition: dataTypes.hpp:58
riegl::rdb::pointcloud::dataPointerOf
ValueType * dataPointerOf(ValueType *const value)
Get pointer to variable or to data in a std::array or vector container.
Definition: dataTypes.hpp:176
riegl::rdb::pointcloud::UINT8
8 bit unsigned integer
Definition: dataTypes.hpp:59
riegl::rdb::pointcloud::FLOAT32
32 bit single precision floating point value
Definition: dataTypes.hpp:69
riegl::rdb::pointcloud::UINT64
64 bit unsigned integer
Definition: dataTypes.hpp:65
riegl::rdb::pointcloud::DOUBLE
64 bit double precision floating point value
Definition: dataTypes.hpp:68
riegl
RIEGL Laser Measurement Systems GmbH, Austria.
Definition: context.hpp:48
riegl::rdb::pointcloud::INT8
8 bit signed integer
Definition: dataTypes.hpp:60
riegl::rdb::pointcloud::dataTypeOf
DataType dataTypeOf()
Convenience wrapper for DataTypeOf class.
Definition: dataTypes.hpp:147
riegl::rdb::pointcloud::INT16
16 bit signed integer
Definition: dataTypes.hpp:62
riegl::rdb::pointcloud::FLOAT64
64 bit double precision floating point value
Definition: dataTypes.hpp:70
riegl::rdb::pointcloud::SINGLE
32 bit single precision floating point value
Definition: dataTypes.hpp:67
riegl::rdb::pointcloud::INT32
32 bit signed integer
Definition: dataTypes.hpp:64
riegl::rdb::pointcloud::UINT16
16 bit unsigned integer
Definition: dataTypes.hpp:61
riegl::rdb::pointcloud::UINT32
32 bit unsigned integer
Definition: dataTypes.hpp:63
riegl::rdb::pointcloud::DataTypeOf::type
static const DataType type
Result RDB data type enumerator for given ValueType.
Definition: dataTypes.hpp:129