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
{
10
12
inline
bool
reportProgress
(
ProgressCallback
cb,
float
v )
13
{
14
if
( cb )
15
return
cb( v );
16
return
true
;
17
}
18
21
inline
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
30
template
<
typename
F>
31
inline
bool
reportProgress
(
ProgressCallback
cb, F && f )
32
{
33
if
( cb )
34
return
cb( f() );
35
return
true
;
36
}
37
40
template
<
typename
F>
41
inline
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
49
inline
ProgressCallback
subprogress
(
ProgressCallback
cb,
float
from,
float
to )
50
{
51
ProgressCallback
res;
52
if
( cb )
53
res = [cb, from, to](
float
v ) {
return
cb( std::lerp( from, to, v ) ); };
54
return
res;
55
}
56
58
template
<
typename
F>
59
inline
ProgressCallback
subprogress
(
ProgressCallback
cb, F && f )
60
{
61
ProgressCallback
res;
62
if
( cb )
63
res = [cb, f = std::forward<F>( f )](
float
v ) {
return
cb( f( v ) ); };
64
return
res;
65
}
66
68
inline
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
MRMeshFwd.h
MR::ProgressCallback
std::function< bool(float)> ProgressCallback
Definition
MRMesh/MRMeshFwd.h:641
MR
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:49
MR::reportProgress
bool reportProgress(ProgressCallback cb, float v)
safely invokes
Definition
MRProgressCallback.h:12
MeshLib
source
MRMesh
MRProgressCallback.h
Generated by
1.11.0