MeshLib
 
Loading...
Searching...
No Matches
MRVDBProgressInterrupter.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRVoxelsFwd.h"
4
6#include <openvdb/util/NullInterrupter.h>
7#include <algorithm>
8#include <thread>
9
10namespace MR
11{
12
13// This class implements OpenVdb interrupter interface and provides ability to use MR::ProgressCallback in some OpenVdb operations
14struct ProgressInterrupter : openvdb::util::NullInterrupter
15{
17 , progressThreadId_{ std::this_thread::get_id() } {}
18 virtual bool wasInterrupted( int percent = -1 ) override
19 {
20 // OpenVdb uses worker threads from pool, in addition to the caller thread.
21 // It is assumed that the callback is periodically called in the caller thread.
22 if ( cb_ && progressThreadId_ == std::this_thread::get_id() )
23 wasInterrupted_ = !cb_( float( std::clamp( percent, 0, 100 ) ) / 100.0f );
24 return wasInterrupted_;
25 }
26 bool getWasInterrupted() const { return wasInterrupted_; }
27
28private:
29 bool wasInterrupted_{ false };
31 std::thread::id progressThreadId_;
32};
33
34} //namespace MR
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:571
Definition MRCameraOrientationPlugin.h:8
Definition MRVDBProgressInterrupter.h:15
bool getWasInterrupted() const
Definition MRVDBProgressInterrupter.h:26
virtual bool wasInterrupted(int percent=-1) override
Definition MRVDBProgressInterrupter.h:18
ProgressInterrupter(ProgressCallback cb)
Definition MRVDBProgressInterrupter.h:16