1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/************************************************************************
*
* Copyright (C) 2018-2023 IRCAD France
* Copyright (C) 2018-2019 IHU Strasbourg
*
* This file is part of Sight.
*
* Sight is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Sight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sight. If not, see <https://www.gnu.org/licenses/>.
*
***********************************************************************/
#include "stereo_toggler.hpp"
#include <viz/scene3d/compositor/core.hpp>
#include <viz/scene3d/render.hpp>
namespace sight::module::ui::viz
{
static const core::com::signals::key_t STEREO_ACTIVE_SIG = "stereoActive";
//------------------------------------------------------------------------------
stereo_toggler::stereo_toggler() :
m_stereo_active_sig(new_signal<stereo_active_sig_t>(STEREO_ACTIVE_SIG))
{
}
//------------------------------------------------------------------------------
stereo_toggler::~stereo_toggler()
= default;
//------------------------------------------------------------------------------
void stereo_toggler::configuring()
{
this->initialize();
const config_t config = this->get_config().get_child("config.<xmlattr>");
m_layer_id = config.get<std::string>("layer");
SIGHT_ASSERT("Empty layer ID.", !m_layer_id.empty());
const std::string stereo_mode = config.get<std::string>("stereoMode", "");
if(stereo_mode == "interlaced")
{
m_stereo_mode = stereo_mode_t::stereo;
}
else if(stereo_mode == "AutoStereo5")
{
m_stereo_mode = stereo_mode_t::autostereo_5;
}
else if(stereo_mode == "AutoStereo8")
{
m_stereo_mode = stereo_mode_t::autostereo_8;
}
else
{
SIGHT_ERROR("Unknown stereo mode: '" + stereo_mode + "'. stereo_toggler will do nothing.");
}
}
//------------------------------------------------------------------------------
void stereo_toggler::starting()
{
this->action_service_starting();
}
//------------------------------------------------------------------------------
void stereo_toggler::updating()
{
if(this->confirm_action())
{
const auto renderers = sight::service::get_services("sight::viz::scene3d::render");
const bool enable_stereo = this->checked() && this->enabled();
const auto stereo_mode = enable_stereo ? m_stereo_mode : stereo_mode_t::none;
for(const auto& srv : renderers)
{
auto render_srv = std::dynamic_pointer_cast<sight::viz::scene3d::render>(srv);
auto layer_map = render_srv->get_layers();
auto layer_it = layer_map.find(m_layer_id);
if(layer_it != layer_map.end())
{
auto& layer = layer_it->second;
layer->set_stereo_mode(stereo_mode);
layer->request_render();
}
else
{
SIGHT_WARN("No layer named '" + m_layer_id + "' in render service '" + render_srv->get_id() + "'.");
}
}
m_stereo_active_sig->async_emit(enable_stereo);
}
}
//------------------------------------------------------------------------------
void stereo_toggler::stopping()
{
this->action_service_stopping();
}
//------------------------------------------------------------------------------
} // namespace sight::module::ui::viz
|