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