MCPcopy Create free account
hub / github.com/MrNeRF/LichtFeld-Studio / renderViewThreadSafe

Function renderViewThreadSafe

src/python/lfs/py_rendering.cpp:544–618  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

542 }
543
544 [[nodiscard]] std::optional<core::Tensor> renderViewThreadSafe(
545 const glm::mat3& rotation,
546 const glm::vec3& translation,
547 const int width,
548 const int height,
549 const float fov_degrees,
550 const PreviewReadback readback,
551 const std::optional<glm::vec3>& background_color_override,
552 const std::optional<bool> orthographic_override = std::nullopt,
553 const std::optional<float> ortho_scale_override = std::nullopt) {
554 auto invoke_render = [&]() -> std::optional<core::Tensor> {
555 return renderViewOnViewerThread(
556 rotation,
557 translation,
558 width,
559 height,
560 fov_degrees,
561 readback,
562 background_color_override,
563 orthographic_override,
564 ortho_scale_override);
565 };
566
567 auto* const viewer = get_visualizer();
568 if (!viewer || viewer->isOnViewerThread()) {
569 return invoke_render();
570 }
571 if (!viewer->acceptsPostedWork()) {
572 return std::nullopt;
573 }
574
575 auto promise = std::make_shared<std::promise<std::optional<core::Tensor>>>();
576 auto future = promise->get_future();
577 auto completed = std::make_shared<std::atomic_bool>(false);
578
579 auto finish = [promise, completed](std::optional<core::Tensor> result) mutable {
580 if (!completed->exchange(true)) {
581 promise->set_value(std::move(result));
582 }
583 };
584
585 const bool posted = viewer->postWork(vis::Visualizer::WorkItem{
586 .run =
587 [rotation,
588 translation,
589 width,
590 height,
591 fov_degrees,
592 readback,
593 background_color_override,
594 orthographic_override,
595 ortho_scale_override,
596 finish]() mutable {
597 finish(renderViewOnViewerThread(
598 rotation,
599 translation,
600 width,
601 height,

Callers 4

renderCurrentViewRgb8Function · 0.85
renderCurrentViewRgba8Function · 0.85
render_viewFunction · 0.85
render_view_u8Function · 0.85

Calls 8

renderViewOnViewerThreadFunction · 0.85
get_visualizerFunction · 0.85
moveFunction · 0.85
finishFunction · 0.85
isOnViewerThreadMethod · 0.45
acceptsPostedWorkMethod · 0.45
postWorkMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected