MeshLib C++ Docs
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{
9
10
12enum class ScalarType
13{
14 UInt8,
15 Int8,
16 UInt16,
17 Int16,
18 UInt32,
19 Int32,
20 UInt64,
21 Int64,
22 Float32,
23 Float64,
24 Float32_4,
25 Unknown,
26 Count
27};
28
33MRVOXELS_API std::function<float ( const char* )> getTypeConverter( ScalarType scalarType, Uint64 range, Int64 min );
34
35
37template <typename F>
38std::invoke_result_t<F, int> visitScalarType( F&& f, ScalarType scalarType, const char* c )
39{
40#define M(T) return f( *( const T* )( c ) );
41
42 switch ( scalarType )
43 {
45 M( uint8_t )
47 M( uint16_t )
49 M( int8_t )
51 M( int16_t )
53 M( int32_t )
55 M( uint32_t )
57 M( uint64_t )
59 M( int64_t )
61 M( float )
63 M( double )
65 return f( *((const float*)c + 3 ) );
67 return {};
69 MR_UNREACHABLE
70 }
71 MR_UNREACHABLE
72#undef M
73}
74
75
76}
#define M(T)
MRVOXELS_API std::function< float(const char *)> getTypeConverter(ScalarType scalarType, Uint64 range, Int64 min)
ScalarType
scalar value's binary format type
Definition MRScalarConvert.h:13
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:38
@ Float32_4
the last value from float[4]
only for bindings generation
Definition MRCameraOrientationPlugin.h:8