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 164 165 166 167 168 169 170 171 172 173 174
|
/************************************************************************
*
* Copyright (C) 2020-2025 IRCAD France
* Copyright (C) 2020 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 "module/viz/sample/mesh.hpp"
#include <core/com/slots.hxx>
#include <service/op.hpp>
#include <ui/__/registry.hpp>
#include <ui/qt/container/widget.hpp>
namespace sight::module::viz::sample
{
const core::com::slots::key_t mesh::UPDATE_CAM_POSITION_SLOT = "update_cam_position";
static const core::com::slots::key_t UPDATE_CAM_TRANSFORM_SLOT = "update_cam_transform";
const core::com::signals::key_t mesh::CAM_UPDATED_SIG = "cam_updated";
//------------------------------------------------------------------------------
mesh::mesh() noexcept
{
new_slot(UPDATE_CAM_POSITION_SLOT, &mesh::update_cam_position, this);
new_slot(UPDATE_CAM_TRANSFORM_SLOT, &mesh::update_cam_transform, this);
new_signal<cam_updated_signal_t>(CAM_UPDATED_SIG);
}
//------------------------------------------------------------------------------
void mesh::configuring()
{
this->sight::ui::service::initialize();
}
//------------------------------------------------------------------------------
void mesh::starting()
{
this->sight::ui::service::create();
auto qt_container = std::dynamic_pointer_cast<sight::ui::qt::container::widget>(this->get_container());
const auto generic_scene_id = this->get_id() + "-genericScene";
sight::ui::registry::register_sid_container(generic_scene_id, qt_container);
auto mesh = m_mesh.lock();
// create and register the render service
// create the frame configuration
service::config_t render_config;
render_config.put("scene.background.<xmlattr>.color", "#36393E");
render_config.put("scene.layer.<xmlattr>.id", "default");
render_config.put("scene.layer.<xmlattr>.order", "1");
service::config_t interactor_cfg;
interactor_cfg.put("<xmlattr>.uid", this->get_id() + "interactorAdaptor");
service::config_t negato_cfg;
negato_cfg.put("<xmlattr>.uid", this->get_id() + "meshAdaptor");
service::config_t camera_cfg;
camera_cfg.put("<xmlattr>.uid", this->get_id() + "cameraAdaptor");
render_config.add_child("scene.layer.adaptor", interactor_cfg);
render_config.add_child("scene.layer.adaptor", negato_cfg);
render_config.add_child("scene.layer.adaptor", camera_cfg);
m_render_srv = sight::service::add("sight::viz::scene3d::render");
m_render_srv->set_config(render_config);
m_render_srv->set_id(generic_scene_id);
m_render_srv->configure();
service::config_t interactor_config;
m_interactor_srv = sight::service::add("sight::module::viz::scene3d::adaptor::trackball_camera");
m_interactor_srv->set_id(this->get_id() + "interactorAdaptor");
m_interactor_srv->configure();
service::config_t mesh_cfg;
mesh_cfg.put("config.<xmlattr>.autoresetcamera", true);
m_mesh_srv = sight::service::add("sight::module::viz::scene3d::adaptor::mesh");
m_mesh_srv->set_config(mesh_cfg);
m_mesh_srv->set_input(std::const_pointer_cast<data::object>(mesh->get_const_sptr()), "mesh", true);
m_mesh_srv->set_id(this->get_id() + "meshAdaptor");
m_mesh_srv->configure();
m_camera_transform = std::make_shared<data::matrix4>();
m_connections.connect(
m_camera_transform,
data::object::MODIFIED_SIG,
this->get_sptr(),
UPDATE_CAM_TRANSFORM_SLOT
);
m_camera_srv = sight::service::add("sight::module::viz::scene3d::adaptor::camera");
m_camera_srv->set_inout(m_camera_transform->get_sptr(), "transform", true);
m_camera_srv->set_id(this->get_id() + "cameraAdaptor");
m_camera_srv->configure();
m_render_srv->start().wait();
m_interactor_srv->start().wait();
m_camera_srv->start().wait();
m_mesh_srv->start().wait();
}
//------------------------------------------------------------------------------
void mesh::updating()
{
}
//------------------------------------------------------------------------------
void mesh::stopping()
{
m_camera_srv->stop().wait();
m_mesh_srv->stop().wait();
m_interactor_srv->stop().wait();
m_render_srv->stop().wait();
sight::ui::registry::unregister_sid_container(this->get_id() + "-genericScene");
sight::service::remove(m_camera_srv);
sight::service::remove(m_mesh_srv);
sight::service::remove(m_interactor_srv);
sight::service::remove(m_render_srv);
m_camera_srv.reset();
m_mesh_srv.reset();
m_interactor_srv.reset();
m_render_srv.reset();
m_connections.disconnect();
m_camera_transform.reset();
this->destroy();
}
//------------------------------------------------------------------------------
void mesh::update_cam_position(data::matrix4::sptr _transform)
{
m_camera_transform->shallow_copy(_transform);
m_camera_srv->slot("transform")->async_run();
}
//------------------------------------------------------------------------------
void mesh::update_cam_transform()
{
this->async_emit(this, CAM_UPDATED_SIG, m_camera_transform);
}
//------------------------------------------------------------------------------
} // namespace sight::module::viz::sample.
|