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{
10
12inline bool reportProgress( ProgressCallback cb, float v )
13{
14 if ( cb )
15 return cb( v );
16 return true;
17}
18
21inline bool reportProgress( ProgressCallback cb, float v, size_t counter, int divider )
22{
23 if ( cb && ( counter % divider == 0 ) )
24 return cb( v );
25 return true;
26}
27
30template<typename F>
31inline bool reportProgress( ProgressCallback cb, F && f )
32{
33 if ( cb )
34 return cb( f() );
35 return true;
36}
37
40template<typename F>
41inline bool reportProgress( ProgressCallback cb, F && f, size_t counter, int divider )
42{
43 if ( cb && ( counter % divider == 0 ) )
44 return cb( f() );
45 return true;
46}
47
49inline ProgressCallback subprogress( ProgressCallback cb, float from, float to )
50{
52 if ( cb )
53 res = [cb, from, to]( float v ) { return cb( std::lerp( from, to, v ) ); };
54 return res;
55}
56
58template<typename F>
60{
62 if ( cb )
63 res = [cb, f = std::forward<F>( f )]( float v ) { return cb( f( v ) ); };
64 return res;
65}
66
68inline ProgressCallback subprogress( ProgressCallback cb, size_t index, size_t count )
69{
70 assert( index < count );
71 if ( cb )
72 return [cb, index, count] ( float v ) { return cb( ( (float)index + v ) / (float)count ); };
73 else
74 return {};
75}
76
77} //namespace MR
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:641
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:49
bool reportProgress(ProgressCallback cb, float v)
safely invokes
Definition MRProgressCallback.h:12