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
8
namespace
MR
9
{
12
13
15
inline
bool
reportProgress
( ProgressCallback cb,
float
v )
16
{
17
if
( cb )
18
return
cb( v );
19
return
true
;
20
}
21
24
inline
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
33
template
<
typename
F>
34
inline
bool
reportProgress
( ProgressCallback cb, F && f )
35
{
36
if
( cb )
37
return
cb( f() );
38
return
true
;
39
}
40
43
template
<
typename
F>
44
inline
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
52
inline
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
61
template
<
typename
F>
62
inline
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
71
inline
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
}
MR::subprogress
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
MR::reportProgress
bool reportProgress(ProgressCallback cb, float v)
safely invokes
Definition
MRProgressCallback.h:15
MR
only for bindings generation
Definition
MRCameraOrientationPlugin.h:8
MeshLib
source
MRMesh
MRProgressCallback.h
Generated by
1.11.0