MeshLib C++ Docs
Loading...
Searching...
No Matches
MRScalarConvert.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include "MRBox.h"
5
6namespace MR
7{
10
11
29
31[[nodiscard]] MRMESH_API size_t getScalarTypeSize( ScalarType scalarType );
32
35
40MRMESH_API std::function<float ( const char* )> getTypeConverter( ScalarType scalarType, const MinMaxd& range );
41
42
44template <typename F>
45std::invoke_result_t<F, int> visitScalarType( F&& f, ScalarType scalarType, const char* c )
46{
47#define M(T) return f( *( const T* )( c ) );
48
49 switch ( scalarType )
50 {
52 M( uint8_t )
54 M( uint16_t )
56 M( int8_t )
58 M( int16_t )
60 M( int32_t )
62 M( uint32_t )
64 M( uint64_t )
66 M( int64_t )
68 M( float )
70 M( double )
72 return f( *((const float*)c + 3 ) );
74 return {};
77 }
79#undef M
80}
81
82
83}
#define MRMESH_API
Definition MRMeshFwd.h:85
#define MR_UNREACHABLE
Definition MRMeshFwd.h:863
#define M(T)
ScalarType
scalar value's binary format type
Definition MRScalarConvert.h:14
MinMax< double > MinMaxd
Definition MRMeshFwd.h:417
MinMaxd getScalarTypeMinMax(ScalarType scalarType)
returns the minimal and the maximal values of given type, or zeros for ScalarType::Unknown
std::function< float(const char *)> getTypeConverter(ScalarType scalarType, const MinMaxd &range)
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:45
size_t getScalarTypeSize(ScalarType scalarType)
returns the size in bytes of a value of given type, or 0 for ScalarType::Unknown
@ Count
Definition MRPdf.h:42
@ Float32
Definition MRScalarConvert.h:23
@ Int16
Definition MRScalarConvert.h:18
@ Float32_4
the last value from float[4]
Definition MRScalarConvert.h:25
@ Int8
Definition MRScalarConvert.h:16
@ Unknown
Definition MRScalarConvert.h:26
@ UInt16
Definition MRScalarConvert.h:17
@ UInt64
Definition MRScalarConvert.h:21
@ UInt8
Definition MRScalarConvert.h:15
@ Int32
Definition MRScalarConvert.h:20
@ Float64
Definition MRScalarConvert.h:24
@ UInt32
Definition MRScalarConvert.h:19
@ Count
Definition MRScalarConvert.h:27
@ Int64
Definition MRScalarConvert.h:22
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8