MeshLib Documentation
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
7
namespace
MR
8
{
9
11
inline
bool
reportProgress
(
ProgressCallback
cb,
float
v )
12
{
13
if
( cb )
14
return
cb( v );
15
return
true
;
16
}
17
20
inline
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
29
template
<
typename
F>
30
inline
bool
reportProgress
(
ProgressCallback
cb, F && f )
31
{
32
if
( cb )
33
return
cb( f() );
34
return
true
;
35
}
36
39
template
<
typename
F>
40
inline
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
48
inline
ProgressCallback
subprogress
(
ProgressCallback
cb,
float
from,
float
to )
49
{
50
ProgressCallback
res;
51
if
( cb )
52
res = [cb, from, to](
float
v ) {
return
cb( ( 1 - v ) * from + v * to ); };
53
return
res;
54
}
55
57
template
<
typename
F>
58
inline
ProgressCallback
subprogress
(
ProgressCallback
cb, F && f )
59
{
60
ProgressCallback
res;
61
if
( cb )
62
res = [cb, f = std::forward<F>( f )](
float
v ) {
return
cb( f( v ) ); };
63
return
res;
64
}
65
67
inline
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
MRMeshFwd.h
MR::ProgressCallback
std::function< bool(float)> ProgressCallback
Definition
MRMesh/MRMeshFwd.h:576
MR
Definition
MRCameraOrientationPlugin.h:8
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:48
MR::reportProgress
bool reportProgress(ProgressCallback cb, float v)
safely invokes
Definition
MRProgressCallback.h:11
MeshLib
source
MRMesh
MRProgressCallback.h
Generated by
1.11.0