Esempio n. 1
0
void SurfaceExtraction::process() {
    if (!meshes_) {
        meshes_ = std::make_shared<std::vector<std::shared_ptr<Mesh>>>();
        outport_.setData(meshes_);
    }

    auto data = volume_.getSourceVectorData();
    auto changed = volume_.getChangedOutports();
    result_.resize(data.size());
    meshes_->resize(data.size());

    for (size_t i = 0; i < data.size(); ++i) {
        auto vol = data[i].second;

        switch (method_.get()) {
            case TETRA: {
                if (util::is_future_ready(result_[i].result)) {
                    (*meshes_)[i] = std::move(result_[i].result.get());
                    result_[i].status = 1.0f;
                    dirty_ = false;
                }

                float iso = isoValue_.get();
                vec4 color = static_cast<FloatVec4Property*>(colors_[i])->get();
                if (!result_[i].result.valid() &&
                    (util::contains(changed, data[i].first) || !result_[i].isSame(iso, color))) {
                    result_[i].set(
                        iso, color, 0.0f,
                        dispatchPool([this, vol, iso, color, i]() -> std::shared_ptr<Mesh> {
                            auto m =
                                MarchingTetrahedron::apply(vol, iso, color, [this, i](float s) {
                                    this->result_[i].status = s;
                                    float status = 0;
                                    for (const auto& e : this->result_) status += e.status;
                                    status /= result_.size();
                                    dispatchFront([status](ProgressBar& pb) {
                                        pb.updateProgress(status);
                                        if (status < 1.0f)
                                            pb.show();
                                        else
                                            pb.hide();
                                    }, std::ref(this->getProgressBar()));
                                });

                            dispatchFront([this]() {
                                dirty_ = true;
                                invalidate(InvalidationLevel::InvalidOutput);
                            });

                            return m;
                        }));
                }
                break;
            }
            default:
                break;
        }
    }
}
Esempio n. 2
0
std::unique_ptr<Canvas> CanvasGLFW::createHiddenCanvas() {
    auto res = dispatchFront([&]() {
        auto canvas = util::make_unique<CanvasGLFW>(windowTitle_, screenDimensions_);
        return std::move(canvas);
    });
    return res.get();
}
Esempio n. 3
0
std::unique_ptr<Canvas> CanvasQt::create() {
    auto thread = QThread::currentThread();
    auto res = dispatchFront([&thread]() {
        auto canvas = util::make_unique<HiddenCanvasQt>();
    #if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
        canvas->context()->moveToThread(thread);
    #endif
        return canvas;
    });
    return res.get();
}
Esempio n. 4
0
void Delay::delay() {
    auto deadline = std::chrono::steady_clock::now() + interval_;
    std::unique_lock<std::mutex> lock{mutex_};
    while (enabled_) {
        if (cvar_.wait_until(lock, deadline) == std::cv_status::timeout) {
            lock.unlock();
            auto tmp = callback_;
            dispatchFront([tmp]() { (*tmp)(); });

            lock.lock();
            enabled_ = false;
        }
    }
}
Esempio n. 5
0
void Timer::timer() {
    auto deadline = std::chrono::steady_clock::now() + interval_;
    std::unique_lock<std::mutex> lock{callback_->mutex};
    
    while (callback_->enabled) {
        if (callback_->cvar.wait_until(lock, deadline) == std::cv_status::timeout) {
            lock.unlock();
            // skip if previous not done.
            if (!result_.valid() ||
                result_.wait_for(std::chrono::duration<int, std::milli>(0)) ==
                    std::future_status::ready) {
                auto tmp = callback_;
                result_ = dispatchFront([tmp]() { 
                    std::unique_lock<std::mutex> l(tmp->mutex, std::try_to_lock);
                    if (l && tmp->enabled) (tmp->callback)();                     
                }
                );
            }
            deadline += interval_;
            lock.lock();
        }
    }
}