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{
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 range, Int64 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 {
41 case ScalarType::UInt8:
42 M( uint8_t )
43 case ScalarType::UInt16:
44 M( uint16_t )
45 case ScalarType::Int8:
46 M( int8_t )
47 case ScalarType::Int16:
48 M( int16_t )
49 case ScalarType::Int32:
50 M( int32_t )
51 case ScalarType::UInt32:
52 M( uint32_t )
53 case ScalarType::UInt64:
54 M( uint64_t )
55 case ScalarType::Int64:
56 M( int64_t )
57 case ScalarType::Float32:
58 M( float )
59 case ScalarType::Float64:
60 M( double )
61 case ScalarType::Float32_4:
62 return f( *((const float*)c + 3 ) );
63 case ScalarType::Unknown:
64 return {};
65 case ScalarType::Count:
67 }
69#undef M
70}
71
72
73} // namespace MR
#define MR_UNREACHABLE
Definition MRMeshFwd.h:804
#define M(T)
#define MRVOXELS_API
Definition MRVoxelsFwd.h:14
ScalarType
Definition MRCameraOrientationPlugin.h:8
MRVOXELS_API std::function< float(const char *)> getTypeConverter(ScalarType scalarType, Uint64 range, Int64 min)
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