MeshLib
 
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
7namespace MR
8{
9
11inline bool reportProgress( ProgressCallback cb, float v )
12{
13 if ( cb )
14 return cb( v );
15 return true;
16}
17
20inline bool reportProgress( ProgressCallback cb, float v, size_t counter, int divider )
21{
22 if ( cb && ( counter % divider == 0 ) )
23 return cb( v );
24 return true;
25}
26
29template<typename F>
30inline bool reportProgress( ProgressCallback cb, F && f )
31{
32 if ( cb )
33 return cb( f() );
34 return true;
35}
36
39template<typename F>
40inline bool reportProgress( ProgressCallback cb, F && f, size_t counter, int divider )
41{
42 if ( cb && ( counter % divider == 0 ) )
43 return cb( f() );
44 return true;
45}
46
48inline ProgressCallback subprogress( ProgressCallback cb, float from, float to )
49{
51 if ( cb )
52 res = [cb, from, to]( float v ) { return cb( ( 1 - v ) * from + v * to ); };
53 return res;
54}
55
57template<typename F>
59{
61 if ( cb )
62 res = [cb, f = std::forward<F>( f )]( float v ) { return cb( f( v ) ); };
63 return res;
64}
65
67inline ProgressCallback subprogress( ProgressCallback cb, size_t index, size_t count )
68{
69 assert( index < count );
70 if ( cb )
71 return [cb, index, count] ( float v ) { return cb( ( (float)index + v ) / (float)count ); };
72 else
73 return {};
74}
75
76} //namespace MR
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:589
Definition MRCameraOrientationPlugin.h:7
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:48
bool reportProgress(ProgressCallback cb, float v)
safely invokes
Definition MRProgressCallback.h:11