File: stereo_selector.cpp

package info (click to toggle)
sight 25.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 42,184 kB
  • sloc: cpp: 289,476; xml: 17,257; ansic: 9,878; python: 1,379; sh: 144; makefile: 33
file content (163 lines) | stat: -rw-r--r-- 4,679 bytes parent folder | download | duplicates (2)
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/************************************************************************
 *
 * Copyright (C) 2014-2025 IRCAD France
 * Copyright (C) 2014-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_selector.hpp"

#include <core/com/slots.hxx>

#include <data/map.hpp>

#include <service/macros.hpp>
#include <service/registry.hpp>

#include <ui/qt/container/widget.hpp>

#include <viz/scene3d/render.hpp>

#include <OGRE/OgreCompositorManager.h>
#include <OGRE/OgreResource.h>
#include <OGRE/OgreResourceManager.h>

#include <QHBoxLayout>
#include <QWidget>

namespace sight::module::ui::viz
{

//------------------------------------------------------------------------------

stereo_selector::stereo_selector() noexcept =
    default;

//------------------------------------------------------------------------------

stereo_selector::~stereo_selector() noexcept =
    default;

//------------------------------------------------------------------------------

void stereo_selector::starting()
{
    this->create();

    auto qt_container = std::dynamic_pointer_cast<sight::ui::qt::container::widget>(
        this->get_container()
    );

    m_layers_box = new QComboBox();
    m_mode_box   = new QComboBox();

    auto* layout = new QHBoxLayout();
    layout->addWidget(m_layers_box);
    layout->addWidget(m_mode_box);

    qt_container->set_layout(layout);

    this->refresh_renderers();

    m_mode_box->addItem("Mono");
    m_mode_box->addItem("Stereo 5 views");
    m_mode_box->addItem("Stereo 8 views");

    auto layer = m_current_layer.lock();
    if(layer)
    {
        m_mode_box->setCurrentIndex(static_cast<int>(m_current_layer.lock()->get_stereo_mode()));
    }

    QObject::connect(m_layers_box, SIGNAL(activated(int)), this, SLOT(on_selected_layer_item(int)));
    QObject::connect(m_mode_box, SIGNAL(activated(int)), this, SLOT(on_selected_mode_item(int)));
}

//------------------------------------------------------------------------------

void stereo_selector::stopping()
{
    this->destroy();
}

//------------------------------------------------------------------------------

void stereo_selector::configuring()
{
    this->initialize();
}

//------------------------------------------------------------------------------

void stereo_selector::updating()
{
}

//--------------------------------------------------------------------------C---

void stereo_selector::on_selected_layer_item(int _index)
{
    // Update the current layer
    m_current_layer = m_layers[static_cast<std::size_t>(_index)];
}

//------------------------------------------------------------------------------

void stereo_selector::on_selected_mode_item(int _index)
{
    using sight::viz::scene3d::compositor::core;
    m_current_layer.lock()->set_stereo_mode(
        _index == 1 ? core::stereo_mode_t::autostereo_5
                    : _index == 2 ? core::stereo_mode_t::autostereo_8
                                  : core::stereo_mode_t::none
    );
}

//------------------------------------------------------------------------------

void stereo_selector::refresh_renderers()
{
    m_layers_box->clear();

    // Fill layer box with all enabled layers
    const auto renderers = sight::service::get_services("sight::viz::scene3d::render");

    for(const auto& srv : renderers)
    {
        auto render = std::dynamic_pointer_cast<sight::viz::scene3d::render>(srv);

        for(auto& layer_map : render->get_layers())
        {
            const std::string& id = layer_map.first;
            if(id != sight::viz::scene3d::render::render::layer::BACKGROUND)
            {
                m_layers_box->addItem(QString::fromStdString(id));
                m_layers.push_back(layer_map.second);
            }
        }
    }

    if(!m_layers.empty())
    {
        m_current_layer = m_layers[0];
    }
}

//------------------------------------------------------------------------------

} // namespace sight::module::ui::viz