MeshLib Documentation
Loading...
Searching...
No Matches
MRScalarConvert.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRVoxelsFwd.h"
4
5namespace MR
6{
7
9enum class ScalarType
10{
11 UInt8,
12 Int8,
13 UInt16,
14 Int16,
15 UInt32,
16 Int32,
17 UInt64,
18 Int64,
19 Float32,
20 Float64,
21 Float32_4,
22 Unknown,
23 Count
24};
25
30MRVOXELS_API std::function<float ( const char* )> getTypeConverter( ScalarType scalarType, uint64_t range, int64_t min );
31
32
34template <typename F>
35std::invoke_result_t<F, int> visitScalarType( F&& f, ScalarType scalarType, const char* c )
36{
37#define M(T) return f( *( const T* )( c ) );
38
39 switch ( scalarType )
40 {
42 M( uint8_t )
44 M( uint16_t )
46 M( int8_t )
48 M( int16_t )
50 M( int32_t )
52 M( uint32_t )
54 M( uint64_t )
56 M( int64_t )
58 M( float )
60 M( double )
62 return f( *((const float*)c + 3 ) );
64 return {};
67 }
69#undef M
70}
71
72
73} // namespace MR
#define MR_UNREACHABLE
Definition MRMesh/MRMeshFwd.h:637
#define M(T)
#define MRVOXELS_API
Definition MRVoxelsFwd.h:13
Definition MRCameraOrientationPlugin.h:8
MRVOXELS_API std::function< float(const char *)> getTypeConverter(ScalarType scalarType, uint64_t range, int64_t min)
ScalarType
scalar value's binary format type
Definition MRScalarConvert.h:10
@ Float32_4
the last value from float[4]
std::invoke_result_t< F, int > visitScalarType(F &&f, ScalarType scalarType, const char *c)
More general template to pass a single value of specified format scalarType to a generic function f.
Definition MRScalarConvert.h:35