MeshLib C++ Docs
Loading...
Searching...
No Matches
MRProgressCallback.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4
5#include <cassert>
6#include <cmath>
7
8namespace MR
9{
12
13
15inline bool reportProgress( ProgressCallback cb, float v )
16{
17 if ( cb )
18 return cb( v );
19 return true;
20}
21
24inline bool reportProgress( ProgressCallback cb, float v, size_t counter, int divider )
25{
26 if ( cb && ( counter % divider == 0 ) )
27 return cb( v );
28 return true;
29}
30
33template<typename F>
34inline bool reportProgress( ProgressCallback cb, F && f )
35{
36 if ( cb )
37 return cb( f() );
38 return true;
39}
40
43template<typename F>
44inline bool reportProgress( ProgressCallback cb, F && f, size_t counter, int divider )
45{
46 if ( cb && ( counter % divider == 0 ) )
47 return cb( f() );
48 return true;
49}
50
52inline ProgressCallback subprogress( ProgressCallback cb, float from, float to )
53{
54 ProgressCallback res;
55 if ( cb )
56 res = [cb, from, to]( float v ) { return cb( std::lerp( from, to, v ) ); };
57 return res;
58}
59
61template<typename F>
62inline ProgressCallback subprogress( ProgressCallback cb, F && f )
63{
64 ProgressCallback res;
65 if ( cb )
66 res = [cb, f = std::forward<F>( f )]( float v ) { return cb( f( v ) ); };
67 return res;
68}
69
71inline ProgressCallback subprogress( ProgressCallback cb, size_t index, size_t count )
72{
73 assert( index < count );
74 if ( cb )
75 return [cb, index, count] ( float v ) { return cb( ( (float)index + v ) / (float)count ); };
76 else
77 return {};
78}
79
80}
ProgressCallback subprogress(ProgressCallback cb, float from, float to)
returns a callback that maps [0,1] linearly into [from,to] in the call to
Definition MRProgressCallback.h:52
bool reportProgress(ProgressCallback cb, float v)
safely invokes
Definition MRProgressCallback.h:15
only for bindings generation
Definition MRCameraOrientationPlugin.h:8