diff --git a/schnapps/plugins/surface_render/surface_render.cpp b/schnapps/plugins/surface_render/surface_render.cpp index c3d3724..0be5e6c 100644 --- a/schnapps/plugins/surface_render/surface_render.cpp +++ b/schnapps/plugins/surface_render/surface_render.cpp @@ -39,6 +39,10 @@ namespace plugin_surface_render MapParameters& Plugin_SurfaceRender::get_parameters(View* view, MapHandlerGen* map) { + cgogn_message_assert(view, "Try to access parameters for null view"); + cgogn_message_assert(map, "Try to access parameters for null map"); + cgogn_message_assert(map->dimension() == 2, "Try to access parameters for map with dimension other than 2"); + view->makeCurrent(); auto& view_param_set = parameter_set_[view]; @@ -240,9 +244,9 @@ void Plugin_SurfaceRender::add_linked_map(View* view, MapHandlerGen *map) { if (map->dimension() == 2) { - set_position_vbo(view, map, map->get_vbo(setting_auto_load_position_attribute_), false); - set_normal_vbo(view, map, map->get_vbo(setting_auto_load_normal_attribute_), false); - set_color_vbo(view, map, map->get_vbo(setting_auto_load_color_attribute_), false); + set_position_vbo(view, map, map->get_vbo(setting_auto_load_position_attribute_), true); + set_normal_vbo(view, map, map->get_vbo(setting_auto_load_normal_attribute_), true); + set_color_vbo(view, map, map->get_vbo(setting_auto_load_color_attribute_), true); #ifdef USE_TRANSPARENCY MapParameters& p = get_parameters(view, map); @@ -298,11 +302,11 @@ void Plugin_SurfaceRender::linked_map_vbo_added(cgogn::rendering::VBO* vbo) { MapParameters& p = view_param_set[map]; if (!p.position_vbo_ && vbo_name == setting_auto_load_position_attribute_) - this->set_position_vbo(it.first, map, vbo, true); + set_position_vbo(it.first, map, vbo, true); if (!p.normal_vbo_ && vbo_name == setting_auto_load_normal_attribute_) - this->set_normal_vbo(it.first, map, vbo, true); + set_normal_vbo(it.first, map, vbo, true); if (!p.color_vbo_ && vbo_name == setting_auto_load_color_attribute_) - this->set_color_vbo(it.first, map, vbo, true); + set_color_vbo(it.first, map, vbo, true); } } @@ -324,11 +328,11 @@ void Plugin_SurfaceRender::linked_map_vbo_removed(cgogn::rendering::VBO* vbo) { MapParameters& p = view_param_set[map]; if (p.position_vbo_ == vbo) - this->set_position_vbo(it.first, map, nullptr, true); + set_position_vbo(it.first, map, nullptr, true); if (p.normal_vbo_ == vbo) - this->set_normal_vbo(it.first, map, nullptr, true); + set_normal_vbo(it.first, map, nullptr, true); if (p.color_vbo_ == vbo) - this->set_color_vbo(it.first, map, nullptr, true); + set_color_vbo(it.first, map, nullptr, true); } } @@ -359,7 +363,7 @@ void Plugin_SurfaceRender::linked_map_bb_changed() void Plugin_SurfaceRender::viewer_initialized() { View* view = dynamic_cast(sender()); - if (view && (parameter_set_.count(view) > 0)) + if (view && parameter_set_.count(view) > 0) { auto& view_param_set = parameter_set_[view]; for (auto& p : view_param_set) diff --git a/schnapps/plugins/surface_render/surface_render.h b/schnapps/plugins/surface_render/surface_render.h index 761aa73..5ea403f 100644 --- a/schnapps/plugins/surface_render/surface_render.h +++ b/schnapps/plugins/surface_render/surface_render.h @@ -75,7 +75,7 @@ class SCHNAPPS_PLUGIN_SURFACE_RENDER_API Plugin_SurfaceRender : public PluginInt void mouseRelease(View*, QMouseEvent*) override {} void mouseMove(View*, QMouseEvent*) override {} void wheelEvent(View*, QWheelEvent*) override {} - void resizeGL(View* /*view*/, int /*width*/, int /*height*/) override {} + void resizeGL(View*, int, int) override {} void view_linked(View*) override; void view_unlinked(View*) override; diff --git a/schnapps/plugins/surface_render/surface_render.ui b/schnapps/plugins/surface_render/surface_render.ui index 4e042d8..49632b7 100644 --- a/schnapps/plugins/surface_render/surface_render.ui +++ b/schnapps/plugins/surface_render/surface_render.ui @@ -7,7 +7,7 @@ 0 0 - 232 + 246 600 @@ -15,94 +15,12 @@ Form - - - - - - render faces - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 16777215 - 32 - - - - Front Color - - - - - - - - - - - render edges - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 16777215 - 32 - - - - Color - - - - + + + + Position : + + @@ -111,10 +29,46 @@ - + + + + Color : + + + + - + + + + + 0 + 0 + + + + + 16777215 + 32 + + + + Color + + + + + + + 50 + + + Qt::Horizontal + + + + render boundary @@ -124,7 +78,34 @@ - + + + + Qt::Horizontal + + + + + + + use transparency + + + + + + + 254 + + + 127 + + + Qt::Horizontal + + + + Qt::Vertical @@ -137,103 +118,60 @@ - - + + + + + 0 + 0 + + + + + 16777215 + 32 + + - Position : + Color - - - - - - Phong - - - group_faceStyle - - - - - - - Flat - - - true - - - group_faceStyle - - - - - - - - 0 - 0 - - - - - 16777215 - 32 - - - - Front n Back - - - - + + + + + 0 + 0 + + + + + 16777215 + 32 + + + + Front Color + + - - - - - - render vertices - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - + + + + + 0 + 0 + + - - - - 0 - 0 - - - - - 16777215 - 32 - - - - Color - - + + - select VBO - + - + - + @@ -248,30 +186,10 @@ - - - - Qt::Horizontal - - - - - - - 254 - - - 127 - - - Qt::Horizontal - - - - - + + - + 0 0 @@ -283,94 +201,100 @@ - - - - 50 + + + + render edges - - Qt::Horizontal + + + + + + render faces + + + true - - + + - Color : + double sided + + + true - - + + + + render vertices + + + + + + + Phong + + + group_faceStyle + + + + + - + 0 0 - - - - select VBO - - - + + + 16777215 + 32 + + + + Back Color + - - - - - - double sided - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 16777215 - 32 - - - - Back Color - - - - + + + + Flat + + + true + + + group_faceStyle + + - - - - - - use transparency - - - - + + + + + 0 + 0 + + + + + 16777215 + 32 + + + + Front n Back + + diff --git a/schnapps/plugins/surface_render/surface_render_dock_tab.cpp b/schnapps/plugins/surface_render/surface_render_dock_tab.cpp index 937ffe5..5530bc1 100644 --- a/schnapps/plugins/surface_render/surface_render_dock_tab.cpp +++ b/schnapps/plugins/surface_render/surface_render_dock_tab.cpp @@ -50,12 +50,12 @@ SurfaceRender_DockTab::SurfaceRender_DockTab(SCHNApps* s, Plugin_SurfaceRender* connect(combo_normalVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(normal_vbo_changed(int))); connect(combo_colorVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(color_vbo_changed(int))); connect(check_renderVertices, SIGNAL(toggled(bool)), this, SLOT(render_vertices_changed(bool))); - connect(slider_vertexScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(vertex_scale_factor_changed(int))); connect(check_renderEdges, SIGNAL(toggled(bool)), this, SLOT(render_edges_changed(bool))); connect(check_renderFaces, SIGNAL(toggled(bool)), this, SLOT(render_faces_changed(bool))); connect(check_renderBackFaces, SIGNAL(toggled(bool)), this, SLOT(render_backfaces_changed(bool))); connect(group_faceStyle, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(face_style_changed(QAbstractButton*))); connect(check_renderBoundary, SIGNAL(toggled(bool)), this, SLOT(render_boundary_changed(bool))); + connect(slider_vertexScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(vertex_scale_factor_changed(int))); color_dial_ = new QColorDialog(front_color_, nullptr); connect(vertexColorButton, SIGNAL(clicked()), this, SLOT(vertex_color_clicked())); @@ -87,8 +87,8 @@ SurfaceRender_DockTab::SurfaceRender_DockTab(SCHNApps* s, Plugin_SurfaceRender* SurfaceRender_DockTab::~SurfaceRender_DockTab() { - disconnect(schnapps_, SIGNAL(selected_view_changed(View*, View*)), this, SLOT(update_ui())); - disconnect(schnapps_, SIGNAL(selected_map_changed(MapHandlerGen*, MapHandlerGen*)), this, SLOT(update_ui())); + disconnect(schnapps_, SIGNAL(selected_view_changed(View*, View*)), this, SLOT(selected_view_changed(View*, View*))); + disconnect(schnapps_, SIGNAL(selected_map_changed(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selected_map_changed(MapHandlerGen*, MapHandlerGen*))); } /*****************************************************************************/ @@ -174,6 +174,25 @@ void SurfaceRender_DockTab::render_boundary_changed(bool b) plugin_->set_render_boundary(schnapps_->get_selected_view(), schnapps_->get_selected_map(), b, false); } +void SurfaceRender_DockTab::transparency_enabled_changed(bool b) +{ +#ifdef USE_TRANSPARENCY + if (!updating_ui_) + { + plugin_->set_transparency_enabled(schnapps_->get_selected_view(), schnapps_->get_selected_map(), b, false); + update_after_use_transparency_changed(); + } +#endif +} + +void SurfaceRender_DockTab::transparency_factor_changed(int n) +{ +#ifdef USE_TRANSPARENCY + if (!updating_ui_) + plugin_->set_transparency_factor(schnapps_->get_selected_view(), schnapps_->get_selected_map(), n, false); +#endif +} + void SurfaceRender_DockTab::vertex_color_clicked() { current_color_dial_ = 1; @@ -256,25 +275,6 @@ void SurfaceRender_DockTab::color_selected() } } -void SurfaceRender_DockTab::transparency_enabled_changed(bool b) -{ -#ifdef USE_TRANSPARENCY - if (!updating_ui_) - { - plugin_->set_transparency_enabled(schnapps_->get_selected_view(), schnapps_->get_selected_map(), b, false); - update_after_use_transparency_changed(); - } -#endif -} - -void SurfaceRender_DockTab::transparency_factor_changed(int n) -{ -#ifdef USE_TRANSPARENCY - if (!updating_ui_) - plugin_->set_transparency_factor(schnapps_->get_selected_view(), schnapps_->get_selected_map(), n, false); -#endif -} - /*****************************************************************************/ // slots called from SCHNApps signals /*****************************************************************************/ diff --git a/schnapps/plugins/surface_render_scalar/map_parameters.h b/schnapps/plugins/surface_render_scalar/map_parameters.h index a8f9713..6d6796a 100644 --- a/schnapps/plugins/surface_render_scalar/map_parameters.h +++ b/schnapps/plugins/surface_render_scalar/map_parameters.h @@ -44,6 +44,7 @@ struct SCHNAPPS_PLUGIN_SURFACE_RENDER_SCALAR_API MapParameters friend class Plugin_SurfaceRenderScalar; MapParameters() : + map_(nullptr), position_vbo_(nullptr), scalar_vbo_(nullptr), color_map_(cgogn::rendering::ShaderScalarPerVertex::BWR), diff --git a/schnapps/plugins/surface_render_scalar/surface_render_scalar.cpp b/schnapps/plugins/surface_render_scalar/surface_render_scalar.cpp index b48a623..a59aa15 100644 --- a/schnapps/plugins/surface_render_scalar/surface_render_scalar.cpp +++ b/schnapps/plugins/surface_render_scalar/surface_render_scalar.cpp @@ -143,7 +143,7 @@ void Plugin_SurfaceRenderScalar::add_linked_map(View* view, MapHandlerGen *map) { if (map->dimension() == 2) { - set_position_vbo(view, map, map->get_vbo(setting_auto_load_position_attribute_), false); + set_position_vbo(view, map, map->get_vbo(setting_auto_load_position_attribute_), true); connect(map, SIGNAL(vbo_added(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_added(cgogn::rendering::VBO*)), Qt::UniqueConnection); connect(map, SIGNAL(vbo_removed(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_removed(cgogn::rendering::VBO*)), Qt::UniqueConnection); @@ -189,7 +189,7 @@ void Plugin_SurfaceRenderScalar::linked_map_vbo_added(cgogn::rendering::VBO* vbo { const MapParameters& p = view_param_set[map]; if (!p.position_vbo_ && vbo_name == setting_auto_load_position_attribute_) - this->set_position_vbo(it.first, map, vbo, true); + set_position_vbo(it.first, map, vbo, true); } } @@ -211,9 +211,9 @@ void Plugin_SurfaceRenderScalar::linked_map_vbo_removed(cgogn::rendering::VBO* v { MapParameters& p = view_param_set[map]; if (p.position_vbo_ == vbo) - this->set_position_vbo(it.first, map, nullptr, true); + set_position_vbo(it.first, map, nullptr, true); if (p.scalar_vbo_ == vbo) - this->set_scalar_vbo(it.first, map, nullptr, true); + set_scalar_vbo(it.first, map, nullptr, true); } } @@ -239,12 +239,11 @@ void Plugin_SurfaceRenderScalar::linked_map_attribute_changed(cgogn::Orbit orbit if (view_param_set.count(map) > 0ul) { MapParameters& p = view_param_set[map]; - cgogn::rendering::VBO* vbo = p.get_scalar_vbo(); - if (vbo && QString::fromStdString(vbo->name()) == attribute_name && p.auto_update_min_max_) + if (p.scalar_vbo_ && QString::fromStdString(p.scalar_vbo_->name()) == attribute_name && p.auto_update_min_max_) { p.update_min_max(); - this->set_scalar_min(it.first, map, p.get_scalar_min(), true); - this->set_scalar_max(it.first, map, p.get_scalar_max(), true); + set_scalar_min(it.first, map, p.get_scalar_min(), true); + set_scalar_max(it.first, map, p.get_scalar_max(), true); } } } diff --git a/schnapps/plugins/surface_render_scalar/surface_render_scalar.h b/schnapps/plugins/surface_render_scalar/surface_render_scalar.h index 00bfed0..59b6f3d 100644 --- a/schnapps/plugins/surface_render_scalar/surface_render_scalar.h +++ b/schnapps/plugins/surface_render_scalar/surface_render_scalar.h @@ -74,7 +74,7 @@ class SCHNAPPS_PLUGIN_SURFACE_RENDER_SCALAR_API Plugin_SurfaceRenderScalar : pub void mouseRelease(View*, QMouseEvent*) override {} void mouseMove(View*, QMouseEvent*) override {} void wheelEvent(View*, QWheelEvent*) override {} - void resizeGL(View* /*view*/, int /*width*/, int /*height*/) override {} + void resizeGL(View*, int, int) override {} void view_linked(View*) override; void view_unlinked(View*) override; diff --git a/schnapps/plugins/surface_render_scalar/surface_render_scalar_dock_tab.cpp b/schnapps/plugins/surface_render_scalar/surface_render_scalar_dock_tab.cpp index 915ea51..2611532 100644 --- a/schnapps/plugins/surface_render_scalar/surface_render_scalar_dock_tab.cpp +++ b/schnapps/plugins/surface_render_scalar/surface_render_scalar_dock_tab.cpp @@ -68,8 +68,8 @@ SurfaceRenderScalar_DockTab::SurfaceRenderScalar_DockTab(SCHNApps* s, Plugin_Sur SurfaceRenderScalar_DockTab::~SurfaceRenderScalar_DockTab() { - disconnect(schnapps_, SIGNAL(selected_view_changed(View*, View*)), this, SLOT(update_ui())); - disconnect(schnapps_, SIGNAL(selected_map_changed(MapHandlerGen*, MapHandlerGen*)), this, SLOT(update_ui())); + disconnect(schnapps_, SIGNAL(selected_view_changed(View*, View*)), this, SLOT(selected_view_changed(View*, View*))); + disconnect(schnapps_, SIGNAL(selected_map_changed(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selected_map_changed(MapHandlerGen*, MapHandlerGen*))); } /*****************************************************************************/ diff --git a/schnapps/plugins/surface_render_vector/map_parameters.h b/schnapps/plugins/surface_render_vector/map_parameters.h index 193c5ee..49ddbe9 100644 --- a/schnapps/plugins/surface_render_vector/map_parameters.h +++ b/schnapps/plugins/surface_render_vector/map_parameters.h @@ -43,7 +43,9 @@ struct SCHNAPPS_PLUGIN_SURFACE_RENDER_VECTOR_API MapParameters { friend class Plugin_SurfaceRenderVector; - MapParameters() : position_vbo_(nullptr) + MapParameters() : + map_(nullptr), + position_vbo_(nullptr) { initialize_gl(); } diff --git a/schnapps/plugins/surface_render_vector/surface_render_vector.cpp b/schnapps/plugins/surface_render_vector/surface_render_vector.cpp index 0644176..d587b55 100644 --- a/schnapps/plugins/surface_render_vector/surface_render_vector.cpp +++ b/schnapps/plugins/surface_render_vector/surface_render_vector.cpp @@ -140,7 +140,7 @@ void Plugin_SurfaceRenderVector::add_linked_map(View* view, MapHandlerGen *map) { if (map->dimension() == 2) { - set_position_vbo(view, map, map->get_vbo(setting_auto_load_position_attribute_), false); + set_position_vbo(view, map, map->get_vbo(setting_auto_load_position_attribute_), true); connect(map, SIGNAL(vbo_added(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_added(cgogn::rendering::VBO*)), Qt::UniqueConnection); connect(map, SIGNAL(vbo_removed(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_removed(cgogn::rendering::VBO*)), Qt::UniqueConnection); @@ -184,7 +184,7 @@ void Plugin_SurfaceRenderVector::linked_map_vbo_added(cgogn::rendering::VBO* vbo { MapParameters& p = view_param_set[map]; if (!p.position_vbo_ && vbo_name == setting_auto_load_position_attribute_) - this->set_position_vbo(it.first, map, vbo, true); + set_position_vbo(it.first, map, vbo, true); } } @@ -206,9 +206,9 @@ void Plugin_SurfaceRenderVector::linked_map_vbo_removed(cgogn::rendering::VBO* v { MapParameters& p = view_param_set[map]; if (p.position_vbo_ == vbo) - this->set_position_vbo(it.first, map, nullptr, true); + set_position_vbo(it.first, map, nullptr, true); if (p.get_vector_vbo_index(vbo) != UINT32_MAX) - this->remove_vector_vbo(it.first, map, vbo, true); + remove_vector_vbo(it.first, map, vbo, true); } } @@ -228,7 +228,7 @@ void Plugin_SurfaceRenderVector::linked_map_bb_changed() { MapParameters& p = view_param_set[map]; for (uint32 i = 0, size = p.vector_scale_factor_list_.size(); i < size; ++i) - this->set_vector_scale_factor(it.first, map, p.get_vector_vbo(i), p.vector_scale_factor_list_[i], true); + set_vector_scale_factor(it.first, map, p.get_vector_vbo(i), p.vector_scale_factor_list_[i], true); } } diff --git a/schnapps/plugins/surface_render_vector/surface_render_vector.h b/schnapps/plugins/surface_render_vector/surface_render_vector.h index eb7b132..d03bb6f 100644 --- a/schnapps/plugins/surface_render_vector/surface_render_vector.h +++ b/schnapps/plugins/surface_render_vector/surface_render_vector.h @@ -76,7 +76,7 @@ class SCHNAPPS_PLUGIN_SURFACE_RENDER_VECTOR_API Plugin_SurfaceRenderVector : pub void mouseRelease(View*, QMouseEvent*) override {} void mouseMove(View*, QMouseEvent*) override {} void wheelEvent(View*, QWheelEvent*) override {} - void resizeGL(View* /*view*/, int /*width*/, int /*height*/) override {} + void resizeGL(View*, int, int) override {} void view_linked(View*) override; void view_unlinked(View*) override; diff --git a/schnapps/plugins/surface_render_vector/surface_render_vector_dock_tab.cpp b/schnapps/plugins/surface_render_vector/surface_render_vector_dock_tab.cpp index 4909531..1c271a4 100644 --- a/schnapps/plugins/surface_render_vector/surface_render_vector_dock_tab.cpp +++ b/schnapps/plugins/surface_render_vector/surface_render_vector_dock_tab.cpp @@ -64,8 +64,8 @@ SurfaceRenderVector_DockTab::SurfaceRenderVector_DockTab(SCHNApps* s, Plugin_Sur SurfaceRenderVector_DockTab::~SurfaceRenderVector_DockTab() { - disconnect(schnapps_, SIGNAL(selected_view_changed(View*, View*)), this, SLOT(update_ui())); - disconnect(schnapps_, SIGNAL(selected_map_changed(MapHandlerGen*, MapHandlerGen*)), this, SLOT(update_ui())); + disconnect(schnapps_, SIGNAL(selected_view_changed(View*, View*)), this, SLOT(selected_view_changed(View*, View*))); + disconnect(schnapps_, SIGNAL(selected_map_changed(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selected_map_changed(MapHandlerGen*, MapHandlerGen*))); } /*****************************************************************************/ diff --git a/schnapps/plugins/volume_render/CMakeLists.txt b/schnapps/plugins/volume_render/CMakeLists.txt index 2ef9d08..dc62e72 100644 --- a/schnapps/plugins/volume_render/CMakeLists.txt +++ b/schnapps/plugins/volume_render/CMakeLists.txt @@ -9,6 +9,7 @@ find_package(QOGLViewer REQUIRED) set(HEADER_FILES dll.h + map_parameters.h volume_render.h volume_render_dock_tab.h ) diff --git a/schnapps/plugins/volume_render/map_parameters.h b/schnapps/plugins/volume_render/map_parameters.h new file mode 100644 index 0000000..c1339a5 --- /dev/null +++ b/schnapps/plugins/volume_render/map_parameters.h @@ -0,0 +1,351 @@ +/******************************************************************************* +* SCHNApps * +* Copyright (C) 2015, IGG Group, ICube, University of Strasbourg, France * +* * +* This library 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 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library 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 this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#ifndef SCHNAPPS_PLUGIN_VOLUME_RENDER_MAP_PARAMETERS_H_ +#define SCHNAPPS_PLUGIN_VOLUME_RENDER_MAP_PARAMETERS_H_ + +#include "dll.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#ifdef USE_TRANSPARENCY +#include +#endif + +namespace schnapps +{ + +namespace plugin_volume_render +{ + +class Plugin_VolumeRender; + +struct SCHNAPPS_PLUGIN_VOLUME_RENDER_API MapParameters +{ + friend class Plugin_VolumeRender; + + MapParameters() : + #ifdef USE_TRANSPARENCY + volume_transparency_drawer_(nullptr), + volume_transparency_drawer_rend_(nullptr), + #endif + position_vbo_(nullptr), + render_vertices_(false), + render_edges_(false), + render_faces_(true), + render_topology_(false), + apply_clipping_plane_(false), + clipping_plane_initialized_(false), + vertex_color_(190, 85, 168), + edge_color_(0, 0, 0), + face_color_(85, 168, 190), + vertex_scale_factor_(1), + vertex_base_size_(1), + volume_explode_factor_(0.8f), + use_transparency_(false), + transparency_factor_(127) + { + initialize_gl(); + } + + CGOGN_NOT_COPYABLE_NOR_MOVABLE(MapParameters); + + inline cgogn::rendering::VBO* get_position_vbo() const { return position_vbo_; } + inline bool get_render_vertices() const { return render_vertices_; } + inline bool get_render_edges() const { return render_edges_; } + inline bool get_render_faces() const { return render_faces_; } + inline bool get_render_topology() const { return render_topology_; } + inline bool get_apply_clipping_plane() const { return apply_clipping_plane_; } + inline const QColor& get_vertex_color() const { return vertex_color_; } + inline const QColor& get_edge_color() const { return edge_color_; } + inline const QColor& get_face_color() const { return face_color_; } + inline float32 get_vertex_base_size() const { return vertex_base_size_; } + inline float32 get_vertex_scale_factor() const { return vertex_scale_factor_; } + inline float32 get_volume_explode_factor() const { return volume_explode_factor_; } + inline bool get_transparency_enabled() const { return use_transparency_; } + inline int32 get_transparency_factor() const { return transparency_factor_; } + +#ifdef USE_TRANSPARENCY + inline cgogn::rendering::VolumeTransparencyDrawer::Renderer* get_transp_drawer_rend() + { + return volume_transparency_drawer_rend_.get(); + } +#endif + +private: + + void set_position_vbo(cgogn::rendering::VBO* v) + { + position_vbo_ = v; + if (position_vbo_ && position_vbo_->vector_dimension() == 3) + { + shader_simple_color_param_->set_position_vbo(position_vbo_); + shader_point_sprite_param_->set_position_vbo(position_vbo_); + update_volume_drawer(); + update_topo_drawer(); + } + else + position_vbo_ = nullptr; + } + + void set_render_vertices(bool b) { render_vertices_ = b; } + + void set_render_edges(bool b) { render_edges_ = b; } + + void set_render_faces(bool b) { render_faces_ = b; } + + void set_render_topology(bool b) + { + render_topology_ = b; + if (render_topology_) + update_topo_drawer(); + } + + void set_vertex_color(const QColor& c) + { + vertex_color_ = c; + shader_point_sprite_param_->color_ = vertex_color_; + } + + void set_edge_color(const QColor& c) + { + edge_color_ = c; + shader_simple_color_param_->color_ = edge_color_; + volume_drawer_rend_->set_edge_color(c); + } + + void set_face_color(const QColor& c) + { + face_color_ = c; + volume_drawer_rend_->set_face_color(face_color_); +#ifdef USE_TRANSPARENCY + face_color_.setAlpha(transparency_factor_); + volume_transparency_drawer_rend_->set_color(face_color_); +#endif + } + + void set_vertex_base_size(float32 bs) + { + vertex_base_size_ = bs; + shader_point_sprite_param_->size_ = vertex_base_size_ * vertex_scale_factor_; + } + + void set_vertex_scale_factor(float32 sf) + { + vertex_scale_factor_ = sf; + shader_point_sprite_param_->size_ = vertex_base_size_ * vertex_scale_factor_; + } + + void set_volume_explode_factor(float32 vef) + { + volume_explode_factor_ = vef; + volume_drawer_rend_->set_explode_volume(vef); +#ifdef USE_TRANSPARENCY + volume_transparency_drawer_rend_->set_explode_volume(vef); +#endif + topo_drawer_->set_explode_volume(vef); + if (render_topology_) + update_topo_drawer(); + } + + void set_transparency_enabled(bool b) + { +#ifdef USE_TRANSPARENCY + use_transparency_ = b; + if (use_transparency_) + { + transparency_factor_ = transparency_factor_ % 255; + face_color_.setAlpha(transparency_factor_); + } + else + face_color_.setAlpha(255); + set_face_color(face_color_); +#endif + } + + void set_transparency_factor(int32 n) + { +#ifdef USE_TRANSPARENCY + n = n % 255; + transparency_factor_ = n; + if (use_transparency_) + { + face_color_.setAlpha(n); + volume_transparency_drawer_rend_->set_color(face_color_); + } +#endif + } + + void set_apply_clipping_plane(bool b) + { + apply_clipping_plane_ = b; + if (apply_clipping_plane_) + update_clipping_plane(); + else + { + volume_drawer_rend_->set_clipping_plane(QVector4D(0, 0, 0, 0)); + topo_drawer_rend_->set_clipping_plane(QVector4D(0, 0, 0, 0)); +#ifdef USE_TRANSPARENCY + volume_transparency_drawer_rend_->set_clipping_plane(QVector4D(0, 0, 0, 0)); +#endif + } + } + + void update_clipping_plane() + { + if (!clipping_plane_initialized_) + { + clipping_plane_initialized_ = true; + frame_manip_->set_size(map_->get_bb_diagonal_size() / 12.0f); + frame_manip_->set_position(map_->get_bb().max()); + frame_manip_->z_plane_param(QColor(200, 200, 200), 0.0f, 0.0f, 3.0f); + } + + VEC3F position; + frame_manip_->get_position(position); + VEC3F z_axis; + frame_manip_->get_axis(cgogn::rendering::FrameManipulator::Zt, z_axis); + float32 d = -(position.dot(z_axis)); + + volume_drawer_rend_->set_clipping_plane(QVector4D(z_axis[0], z_axis[1], z_axis[2], d)); + topo_drawer_rend_->set_clipping_plane(QVector4D(z_axis[0], z_axis[1], z_axis[2], d)); +#ifdef USE_TRANSPARENCY + volume_transparency_drawer_rend_->set_clipping_plane(QVector4D(z_axis[0], z_axis[1], z_axis[2], d)); +#endif + } + + void update_topo_drawer() + { + if (position_vbo_) + { + const CMap3::VertexAttribute& pos_attr = map_->get_attribute(QString::fromStdString(position_vbo_->name())); + if (!pos_attr.is_valid()) + { + cgogn_log_warning("plugin_volume_render|MapParameters::update_topo_drawer") << "The attribute \"" << position_vbo_->name() << "\" is not valid. Its data should be of type " << cgogn::name_of_type(VEC3()) << "."; + position_vbo_ = nullptr; + return; + } + + topo_drawer_->update(*map_->get_map(), pos_attr); + } + } + + void update_volume_drawer() + { + if (position_vbo_) + { + const CMap3::VertexAttribute& pos_attr = map_->get_attribute(QString::fromStdString(position_vbo_->name())); + if (!pos_attr.is_valid()) + { + cgogn_log_warning("plugin_volume_render|MapParameters::update_volume_drawer") << "The attribute \"" << position_vbo_->name() << "\" is not valid. Its data should be of type " << cgogn::name_of_type(VEC3()) << "."; + position_vbo_ = nullptr; + return; + } + volume_drawer_->update_edge(*map_->get_map(), pos_attr); + volume_drawer_->update_face(*map_->get_map(), pos_attr); +#ifdef USE_TRANSPARENCY + volume_transparency_drawer_->update_face(*map_->get_map(), pos_attr); +#endif + } + } + + void initialize_gl() + { + shader_simple_color_param_ = cgogn::rendering::ShaderSimpleColor::generate_param(); + shader_simple_color_param_->color_ = edge_color_; + + shader_point_sprite_param_ = cgogn::rendering::ShaderPointSprite::generate_param(); + shader_point_sprite_param_->color_ = vertex_color_; + shader_point_sprite_param_->size_ = vertex_base_size_ * vertex_scale_factor_; + + volume_drawer_ = cgogn::make_unique(); + volume_drawer_rend_ = volume_drawer_->generate_renderer(); + + topo_drawer_ = cgogn::make_unique(); + topo_drawer_rend_ = topo_drawer_->generate_renderer(); + +#ifdef USE_TRANSPARENCY + volume_transparency_drawer_ = cgogn::make_unique(); + volume_transparency_drawer_rend_ = volume_transparency_drawer_->generate_renderer(); + volume_transparency_drawer_rend_->set_explode_volume(volume_explode_factor_); + volume_transparency_drawer_rend_->set_lighted(true); +#endif + + frame_manip_ = cgogn::make_unique(); + + set_position_vbo(position_vbo_); + set_vertex_color(vertex_color_); + set_edge_color(edge_color_); + set_face_color(face_color_); + set_vertex_scale_factor(vertex_scale_factor_); + set_vertex_base_size(vertex_base_size_); + set_volume_explode_factor(volume_explode_factor_); + set_transparency_factor(transparency_factor_); + } + + MapHandler* map_; + + std::unique_ptr shader_simple_color_param_; + std::unique_ptr shader_point_sprite_param_; +#ifdef USE_TRANSPARENCY + std::unique_ptr volume_transparency_drawer_; + std::unique_ptr volume_transparency_drawer_rend_; +#endif + + std::unique_ptr volume_drawer_; + std::unique_ptr volume_drawer_rend_; + + std::unique_ptr topo_drawer_; + std::unique_ptr topo_drawer_rend_; + + std::unique_ptr frame_manip_; + + cgogn::rendering::VBO* position_vbo_; + bool render_vertices_; + bool render_edges_; + bool render_faces_; + bool render_topology_; + bool apply_clipping_plane_; + bool clipping_plane_initialized_; + QColor vertex_color_; + QColor edge_color_; + QColor face_color_; + float32 vertex_scale_factor_; + float32 vertex_base_size_; + float32 volume_explode_factor_; + bool use_transparency_; + int32 transparency_factor_; +}; + +} // namespace plugin_volume_render + +} // namespace schnapps + +#endif // SCHNAPPS_PLUGIN_VOLUME_RENDER_MAP_PARAMETERS_H_ diff --git a/schnapps/plugins/volume_render/volume_render.cpp b/schnapps/plugins/volume_render/volume_render.cpp index 80af1d8..1b154f3 100644 --- a/schnapps/plugins/volume_render/volume_render.cpp +++ b/schnapps/plugins/volume_render/volume_render.cpp @@ -1,9 +1,7 @@ /******************************************************************************* * SCHNApps * * Copyright (C) 2015, IGG Group, ICube, University of Strasbourg, France * -* Plugin Volume Render * -* Author Etienne Schmitt (etienne.schmitt@inria.fr) Inria/Mimesis * -* Inspired by the surface render plugin * +* * * This library 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 2.1 of the License, or (at your * @@ -23,15 +21,16 @@ * * *******************************************************************************/ -#include "volume_render.h" +#include #include #include +#ifdef USE_TRANSPARENCY #include +#endif #include - namespace schnapps { @@ -40,6 +39,10 @@ namespace plugin_volume_render MapParameters& Plugin_VolumeRender::get_parameters(View* view, MapHandlerGen* map) { + cgogn_message_assert(view, "Try to access parameters for null view"); + cgogn_message_assert(map, "Try to access parameters for null map"); + cgogn_message_assert(map->dimension() == 3, "Try to access parameters for map with dimension other than 3"); + view->makeCurrent(); auto& view_param_set = parameter_set_[view]; @@ -47,19 +50,30 @@ MapParameters& Plugin_VolumeRender::get_parameters(View* view, MapHandlerGen* ma { MapParameters& p = view_param_set[map]; p.map_ = static_cast*>(map); - if (map->get_bb().is_initialized()) - { - p.set_vertex_base_size(map->get_bb_diagonal_size() / (2.0f * std::sqrt(float32(map->nb_cells(Edge_Cell))))); - p.frame_manip_->set_size(map->get_bb_diagonal_size() / 12.0f); - p.frame_manip_->set_position(map->get_bb().max()); - p.frame_manip_->z_plane_param(QColor(200,200,200), 0.0f, 0.0f, 3.0f); - } + p.set_vertex_base_size(map->get_bb_diagonal_size() / (2.0f * std::sqrt(float32(map->nb_cells(Edge_Cell))))); return p; } else return view_param_set[map]; } +bool Plugin_VolumeRender::check_docktab_activation() +{ + MapHandlerGen* map = schnapps_->get_selected_map(); + View* view = schnapps_->get_selected_view(); + + if (view && view->is_linked_to_plugin(this) && map && map->is_linked_to_view(view) && map->dimension() == 3) + { + schnapps_->enable_plugin_tab_widgets(this); + return true; + } + else + { + schnapps_->disable_plugin_tab_widgets(this); + return false; + } +} + bool Plugin_VolumeRender::enable() { if (get_setting("Auto enable on selected view").isValid()) @@ -75,12 +89,8 @@ bool Plugin_VolumeRender::enable() dock_tab_ = new VolumeRender_DockTab(this->schnapps_, this); schnapps_->add_plugin_dock_tab(this, dock_tab_, "Volume Render"); - connect(schnapps_, SIGNAL(selected_view_changed(View*, View*)), this, SLOT(update_dock_tab())); - connect(schnapps_, SIGNAL(selected_map_changed(MapHandlerGen*, MapHandlerGen*)), this, SLOT(update_dock_tab())); connect(schnapps_, SIGNAL(plugin_enabled(Plugin*)), this, SLOT(enable_on_selected_view(Plugin*))); - update_dock_tab(); - #ifdef USE_TRANSPARENCY plugin_transparency_ = reinterpret_cast(schnapps_->enable_plugin("surface_render_transp")); #endif @@ -93,8 +103,6 @@ void Plugin_VolumeRender::disable() schnapps_->remove_plugin_dock_tab(this, dock_tab_); delete dock_tab_; - disconnect(schnapps_, SIGNAL(selected_view_changed(View*, View*)), this, SLOT(update_dock_tab())); - disconnect(schnapps_, SIGNAL(selected_map_changed(MapHandlerGen*, MapHandlerGen*)), this, SLOT(update_dock_tab())); disconnect(schnapps_, SIGNAL(plugin_enabled(Plugin*)), this, SLOT(enable_on_selected_view(Plugin*))); } @@ -108,13 +116,12 @@ void Plugin_VolumeRender::draw_map(View* view, MapHandlerGen* map, const QMatrix if (map->is_selected_map() && p.apply_clipping_plane_) p.frame_manip_->draw(true, true, proj, mv, view); - if (p.render_topology_) - if (p.topo_drawer_rend_) - p.topo_drawer_rend_->draw(proj,mv,view); + if (p.render_topology_ && p.topo_drawer_rend_) + p.topo_drawer_rend_->draw(proj, mv, view); if (p.render_vertices_) { - if (p.get_position_vbo()) + if (p.position_vbo_) { p.shader_point_sprite_param_->bind(proj, mv); map->draw(cgogn::rendering::POINTS); @@ -124,12 +131,10 @@ void Plugin_VolumeRender::draw_map(View* view, MapHandlerGen* map, const QMatrix if (p.render_edges_) { - if (p.get_position_vbo()) + if (p.position_vbo_) { - if(p.volume_drawer_rend_) - { + if (p.volume_drawer_rend_) p.volume_drawer_rend_->draw_edges(proj, mv, view); - } else { p.shader_simple_color_param_->bind(proj, mv); @@ -141,9 +146,9 @@ void Plugin_VolumeRender::draw_map(View* view, MapHandlerGen* map, const QMatrix if (p.render_faces_) { - if (p.get_position_vbo()) + if (p.position_vbo_) { - if (p.render_edges_ && (p.volume_explode_factor_>0.995f)) + if (p.render_edges_ && p.volume_explode_factor_ > 0.995f) p.set_volume_explode_factor(0.995f); if (!p.use_transparency_ && p.volume_drawer_rend_) p.volume_drawer_rend_->draw_faces(proj, mv, view); @@ -194,170 +199,153 @@ void Plugin_VolumeRender::mouseMove(View* view, QMouseEvent* event) { bool local_manip = event->buttons() & Qt::LeftButton; p.frame_manip_->drag(local_manip, event->x(), event->y()); - p.set_apply_clipping_plane(true); + p.update_clipping_plane(); view->update(); } } } - void Plugin_VolumeRender::view_linked(View* view) { #ifdef USE_TRANSPARENCY view->link_plugin(plugin_transparency_); #endif - update_dock_tab(); - connection_map_linked_[view] = connect(view, &View::map_linked, [=] (MapHandlerGen* m) { this->map_linked(view,m);}); - connection_map_unlinked_[view] = connect(view, &View::map_unlinked, [=] (MapHandlerGen* m) { map_unlinked(view,m);}); + if (check_docktab_activation()) + dock_tab_->refresh_ui(); + + connect(view, SIGNAL(map_linked(MapHandlerGen*)), this, SLOT(map_linked(MapHandlerGen*))); + connect(view, SIGNAL(map_unlinked(MapHandlerGen*)), this, SLOT(map_unlinked(MapHandlerGen*))); connect(view, SIGNAL(viewerInitialized()), this, SLOT(viewer_initialized())); - for (MapHandlerGen* map : view->get_linked_maps()) { map_linked(view,map); } + for (MapHandlerGen* map : view->get_linked_maps()) { add_linked_map(view, map); } } void Plugin_VolumeRender::view_unlinked(View* view) { - update_dock_tab(); + if (check_docktab_activation()) + dock_tab_->refresh_ui(); - disconnect(connection_map_linked_[view]); - connection_map_linked_.erase(view); - disconnect(connection_map_unlinked_[view]); - connection_map_unlinked_.erase(view); + disconnect(view, SIGNAL(map_linked(MapHandlerGen*)), this, SLOT(map_linked(MapHandlerGen*))); + disconnect(view, SIGNAL(map_unlinked(MapHandlerGen*)), this, SLOT(map_unlinked(MapHandlerGen*))); disconnect(view, SIGNAL(viewerInitialized()), this, SLOT(viewer_initialized())); - for (MapHandlerGen* map : view->get_linked_maps()) { map_unlinked(view,map); } - - parameter_set_.erase(view); + for (MapHandlerGen* map : view->get_linked_maps()) { remove_linked_map(view, map); } } -void Plugin_VolumeRender::connectivity_changed(MapHandlerGen* map) +void Plugin_VolumeRender::map_linked(MapHandlerGen *map) { - for (auto& it : parameter_set_) - { - std::map& view_param_set = it.second; - if (view_param_set.count(map) > 0ul) - { - MapParameters& p = view_param_set[map]; - CMap3Handler* mh3 = static_cast(map); - if (!p.position_vbo_) return; - auto pos_attr = mh3->get_attribute(QString::fromStdString(p.position_vbo_->name())); - if (pos_attr.is_valid()) - { - if (!p.use_transparency_) - { - p.volume_drawer_->update_face(*mh3->get_map(), pos_attr); - p.volume_drawer_->update_edge(*mh3->get_map(), pos_attr); - } -#ifdef USE_TRANSPARENCY - else - p.volume_transparency_drawer_->update_face(*mh3->get_map(), pos_attr); -#endif - p.topo_drawer_->update(*mh3->get_map(),pos_attr); - } - } - } + View* view = static_cast(sender()); + add_linked_map(view, map); } -void Plugin_VolumeRender::map_linked(View* view, MapHandlerGen* map) +void Plugin_VolumeRender::add_linked_map(View* view, MapHandlerGen* map) { - update_dock_tab(); - if (map->dimension() == 3) { - set_position_vbo(view->get_name(), map->get_name(), setting_auto_load_position_attribute_); - MapParameters& p = get_parameters(view, map); + set_position_vbo(view, map, map->get_vbo(setting_auto_load_position_attribute_), true); + #ifdef USE_TRANSPARENCY + MapParameters& p = get_parameters(view, map); if (p.use_transparency_) - plugin_surface_render_transp::add_tr_vol(plugin_transparency_,view,map,p.get_transp_drawer_rend()); + plugin_surface_render_transp::add_tr_vol(plugin_transparency_, view, map, p.get_transp_drawer_rend()); #endif + connect(map, SIGNAL(vbo_added(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_added(cgogn::rendering::VBO*)), Qt::UniqueConnection); connect(map, SIGNAL(vbo_removed(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_removed(cgogn::rendering::VBO*)), Qt::UniqueConnection); connect(map, SIGNAL(bb_changed()), this, SLOT(linked_map_bb_changed()), Qt::UniqueConnection); connect(map, SIGNAL(connectivity_changed()), this, SLOT(linked_map_connectivity_changed()), Qt::UniqueConnection); - connect(map, SIGNAL(attribute_changed(cgogn::Orbit,QString)), this, SLOT(linked_attribute_changed(cgogn::Orbit,QString)), Qt::UniqueConnection); + connect(map, SIGNAL(attribute_changed(cgogn::Orbit, const QString&)), this, SLOT(linked_map_attribute_changed(cgogn::Orbit, const QString&)), Qt::UniqueConnection); + + if (check_docktab_activation()) + dock_tab_->refresh_ui(); } } -void Plugin_VolumeRender::map_unlinked(View* view, MapHandlerGen* map) +void Plugin_VolumeRender::map_unlinked(MapHandlerGen *map) { - update_dock_tab(); + View* view = static_cast(sender()); + remove_linked_map(view, map); +} +void Plugin_VolumeRender::remove_linked_map(View* view, MapHandlerGen* map) +{ if (map->dimension() == 3) { disconnect(map, SIGNAL(vbo_added(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_added(cgogn::rendering::VBO*))); disconnect(map, SIGNAL(vbo_removed(cgogn::rendering::VBO*)), this, SLOT(linked_map_vbo_removed(cgogn::rendering::VBO*))); disconnect(map, SIGNAL(bb_changed()), this, SLOT(linked_map_bb_changed())); disconnect(map, SIGNAL(connectivity_changed()), this, SLOT(linked_map_connectivity_changed())); - disconnect(map, SIGNAL(attribute_changed(cgogn::Orbit,QString)), this, SLOT(linked_attribute_changed(cgogn::Orbit,QString))); + disconnect(map, SIGNAL(attribute_changed(cgogn::Orbit, const QString&)), this, SLOT(linked_map_attribute_changed(cgogn::Orbit, const QString&))); - MapParameters& p = get_parameters(view, map); #ifdef USE_TRANSPARENCY + MapParameters& p = get_parameters(view, map); if (p.use_transparency_) - plugin_surface_render_transp::remove_tr_vol(plugin_transparency_,view,map,p.get_transp_drawer_rend()); + plugin_surface_render_transp::remove_tr_vol(plugin_transparency_, view, map, p.get_transp_drawer_rend()); #endif + + if (check_docktab_activation()) + dock_tab_->refresh_ui(); } } void Plugin_VolumeRender::linked_map_vbo_added(cgogn::rendering::VBO* vbo) { - MapHandlerGen* map = dynamic_cast(sender()); - - if (map && map->is_selected_map()) + if (vbo->vector_dimension() == 3) { - if (vbo->vector_dimension() == 3) + MapHandlerGen* map = dynamic_cast(sender()); + + const QString vbo_name = QString::fromStdString(vbo->name()); + for (auto& it : parameter_set_) { - const QString vbo_name = QString::fromStdString(vbo->name()); - dock_tab_->add_position_vbo(vbo_name); - View* view = schnapps_->get_selected_view(); - if (view) + std::map& view_param_set = it.second; + if (view_param_set.count(map) > 0ul) { - if (!get_parameters(view, map).get_position_vbo() && vbo_name == setting_auto_load_position_attribute_) - set_position_vbo(view->get_name(), map->get_name(), vbo_name); + MapParameters& p = view_param_set[map]; + if (!p.position_vbo_ && vbo_name == setting_auto_load_position_attribute_) + set_position_vbo(it.first, map, vbo, true); } } + + for (View* view : map->get_linked_views()) + view->update(); } } void Plugin_VolumeRender::linked_map_vbo_removed(cgogn::rendering::VBO* vbo) { - MapHandlerGen* map = dynamic_cast(sender()); - - if (map->is_selected_map()) + if (vbo->vector_dimension() == 3) { - if (vbo->vector_dimension() == 3) - dock_tab_->remove_position_vbo(QString::fromStdString(vbo->name())); - } + MapHandlerGen* map = dynamic_cast(sender()); - for (auto& it : parameter_set_) - { - std::map& view_param_set = it.second; - if (view_param_set.count(map) > 0ul) + for (auto& it : parameter_set_) { - MapParameters& p = view_param_set[map]; - if (p.get_position_vbo() == vbo) - p.set_position_vbo(nullptr); + std::map& view_param_set = it.second; + if (view_param_set.count(map) > 0ul) + { + MapParameters& p = view_param_set[map]; + if (p.position_vbo_ == vbo) + set_position_vbo(it.first, map, nullptr, true); + } } - } - for (View* view : map->get_linked_views()) - view->update(); + for (View* view : map->get_linked_views()) + view->update(); + } } void Plugin_VolumeRender::linked_map_bb_changed() { MapHandlerGen* map = dynamic_cast(sender()); - if (!map) - return; const uint32 nbe = map->nb_cells(Edge_Cell); - for (auto& it : parameter_set_) { std::map& view_param_set = it.second; if (view_param_set.count(map) > 0ul) { MapParameters& p = view_param_set[map]; - p.set_vertex_base_size(map->get_bb_diagonal_size() / (2.0f * std::sqrt(float(nbe)))); + p.set_vertex_base_size(map->get_bb_diagonal_size() / (2 * std::sqrt(nbe))); p.frame_manip_->set_size(map->get_bb_diagonal_size() / 12.0f); } } @@ -366,7 +354,6 @@ void Plugin_VolumeRender::linked_map_bb_changed() void Plugin_VolumeRender::linked_map_connectivity_changed() { MapHandlerGen* map = dynamic_cast(sender()); - if (!map) return; for (auto& it : parameter_set_) { @@ -374,54 +361,55 @@ void Plugin_VolumeRender::linked_map_connectivity_changed() if (view_param_set.count(map) > 0ul) { MapParameters& p = view_param_set[map]; - CMap3Handler* mh3 = static_cast(map); - map->update_vbo(QString::fromStdString(p.position_vbo_->name())); - auto pos_attr = mh3->get_attribute(QString::fromStdString(p.position_vbo_->name())); - if (pos_attr.is_valid()) - { - if (!p.use_transparency_) - { - p.volume_drawer_->update_edge(*mh3->get_map(), pos_attr); - p.volume_drawer_->update_face(*mh3->get_map(), pos_attr); - } -#ifdef USE_TRANSPARENCY - else { - p.volume_transparency_drawer_->update_face(*mh3->get_map(), pos_attr); - } -#endif - p.topo_drawer_->update(*mh3->get_map(),pos_attr); - } + if (p.position_vbo_) + p.update_volume_drawer(); } } } -void Plugin_VolumeRender::linked_attribute_changed(cgogn::Orbit, QString) +void Plugin_VolumeRender::linked_map_attribute_changed(cgogn::Orbit orbit, const QString& attribute_name) { - MapHandlerGen* map = dynamic_cast(sender()); - if (map) - this->connectivity_changed(map); + if (orbit == CMap3::Vertex::ORBIT) + { + MapHandlerGen* map = static_cast(sender()); + + for (auto& it : parameter_set_) + { + std::map& view_param_set = it.second; + if (view_param_set.count(map) > 0ul) + { + MapParameters& p = view_param_set[map]; + if (p.position_vbo_ && QString::fromStdString(p.position_vbo_->name()) == attribute_name) + p.update_volume_drawer(); + } + } + + for (View* view : map->get_linked_views()) + view->update(); + } } void Plugin_VolumeRender::viewer_initialized() { View* view = dynamic_cast(sender()); - if (view && (this->parameter_set_.count(view) > 0)) + if (view && parameter_set_.count(view) > 0) { auto& view_param_set = parameter_set_[view]; for (auto & p : view_param_set) { - MapParameters& mp = p.second; MapHandlerGen* map = p.first; + MapParameters& mp = p.second; #ifdef USE_TRANSPARENCY - plugin_surface_render_transp::remove_tr_vol(plugin_transparency_, view, map, mp.get_transp_drawer_rend()); + if (mp.use_transparency_) + plugin_surface_render_transp::remove_tr_vol(plugin_transparency_, view, map, mp.get_transp_drawer_rend()); #endif mp.initialize_gl(); #ifdef USE_TRANSPARENCY - plugin_surface_render_transp::add_tr_vol(plugin_transparency_, view, map, mp.get_transp_drawer_rend()); + if (mp.use_transparency_) + plugin_surface_render_transp::add_tr_vol(plugin_transparency_, view, map, mp.get_transp_drawer_rend()); #endif } } - update_dock_tab(); } void Plugin_VolumeRender::enable_on_selected_view(Plugin* p) @@ -430,253 +418,185 @@ void Plugin_VolumeRender::enable_on_selected_view(Plugin* p) schnapps_->get_selected_view()->link_plugin(this); } -void Plugin_VolumeRender::update_dock_tab() +/******************************************************************************/ +/* PUBLIC INTERFACE */ +/******************************************************************************/ + +void Plugin_VolumeRender::set_position_vbo(View* view, MapHandlerGen* map, cgogn::rendering::VBO* vbo, bool update_dock_tab) { - MapHandlerGen* map = schnapps_->get_selected_map(); - View* view = schnapps_->get_selected_view(); - if (view->is_linked_to_plugin(this) && map && map->is_linked_to_view(view) && map->dimension() == 3 && map->get_bb().is_initialized()) + if (view && view->is_linked_to_plugin(this) && map && map->is_linked_to_view(view) && map->dimension() == 3) { - schnapps_->enable_plugin_tab_widgets(this); - const MapParameters& p = get_parameters(view, map); - dock_tab_->update_map_parameters(map, p); + MapParameters& p = get_parameters(view, map); + p.set_position_vbo(vbo); + if (update_dock_tab && view->is_selected_view() && map->is_selected_map()) + dock_tab_->set_position_vbo(vbo); + view->update(); } - else - schnapps_->disable_plugin_tab_widgets(this); } -/******************************************************************************/ -/* PUBLIC INTERFACE */ -/******************************************************************************/ - -void Plugin_VolumeRender::set_render_vertices(View* view, MapHandlerGen* map, bool b) +void Plugin_VolumeRender::set_render_vertices(View* view, MapHandlerGen* map, bool b, bool update_dock_tab) { if (view && view->is_linked_to_plugin(this) && map && map->is_linked_to_view(view) && map->dimension() == 3) { MapParameters& p = get_parameters(view, map); p.render_vertices_ = b; - if (view->is_selected_view() && map->is_selected_map()) - dock_tab_->update_map_parameters(map, p); + if (update_dock_tab && view->is_selected_view() && map->is_selected_map()) + dock_tab_->set_render_vertices(b); view->update(); } } -void Plugin_VolumeRender::set_render_edges(View* view, MapHandlerGen* map, bool b) +void Plugin_VolumeRender::set_render_edges(View* view, MapHandlerGen* map, bool b, bool update_dock_tab) { if (view && view->is_linked_to_plugin(this) && map && map->is_linked_to_view(view) && map->dimension() == 3) { MapParameters& p = get_parameters(view, map); p.render_edges_ = b; - if (view->is_selected_view() && map->is_selected_map()) - dock_tab_->update_map_parameters(map, p); + if (update_dock_tab && view->is_selected_view() && map->is_selected_map()) + dock_tab_->set_render_edges(b); view->update(); } } -void Plugin_VolumeRender::set_render_faces(View* view, MapHandlerGen* map, bool b) +void Plugin_VolumeRender::set_render_faces(View* view, MapHandlerGen* map, bool b, bool update_dock_tab) { if (view && view->is_linked_to_plugin(this) && map && map->is_linked_to_view(view) && map->dimension() == 3) { MapParameters& p = get_parameters(view, map); p.render_faces_ = b; - if (view->is_selected_view() && map->is_selected_map()) - dock_tab_->update_map_parameters(map, p); +#ifdef USE_TRANSPARENCY + if (p.use_transparency_) + { + if (b) + plugin_surface_render_transp::add_tr_vol(plugin_transparency_, view, map, p.get_transp_drawer_rend()); + else + plugin_surface_render_transp::remove_tr_vol(plugin_transparency_, view, map, p.get_transp_drawer_rend()); + } +#endif + if (update_dock_tab && view->is_selected_view() && map->is_selected_map()) + dock_tab_->set_render_faces(b); view->update(); } } -void Plugin_VolumeRender::set_render_boundary(View* view, MapHandlerGen* map, bool b) +void Plugin_VolumeRender::set_render_topology(View* view, MapHandlerGen* map, bool b, bool update_dock_tab) { if (view && view->is_linked_to_plugin(this) && map && map->is_linked_to_view(view) && map->dimension() == 3) { MapParameters& p = get_parameters(view, map); - p.render_boundary_ = b; - if (view->is_selected_view() && map->is_selected_map()) - dock_tab_->update_map_parameters(map, p); + p.set_render_topology(b); + if (update_dock_tab && view->is_selected_view() && map->is_selected_map()) + dock_tab_->set_render_topology(b); view->update(); } } -void Plugin_VolumeRender::set_position_vbo(View* view, MapHandlerGen* map, cgogn::rendering::VBO* vbo) +void Plugin_VolumeRender::set_apply_clipping_plane(View* view, MapHandlerGen* map, bool b, bool update_dock_tab) { if (view && view->is_linked_to_plugin(this) && map && map->is_linked_to_view(view) && map->dimension() == 3) { MapParameters& p = get_parameters(view, map); - p.set_position_vbo(vbo); - if (view->is_selected_view() && map->is_selected_map()) - dock_tab_->update_map_parameters(map, p); + p.set_apply_clipping_plane(b); + if (update_dock_tab && view->is_selected_view() && map->is_selected_map()) + dock_tab_->set_apply_clipping_plane(b); view->update(); } } -void Plugin_VolumeRender::set_vertex_color(View* view, MapHandlerGen* map, const QColor& color) +void Plugin_VolumeRender::set_vertex_color(View* view, MapHandlerGen* map, const QColor& color, bool update_dock_tab) { if (view && view->is_linked_to_plugin(this) && map && map->is_linked_to_view(view) && map->dimension() == 3) { MapParameters& p = get_parameters(view, map); p.set_vertex_color(color); - if (view->is_selected_view() && map->is_selected_map()) - dock_tab_->update_map_parameters(map, p); + if (update_dock_tab && view->is_selected_view() && map->is_selected_map()) + dock_tab_->set_vertex_color(color); view->update(); } } -void Plugin_VolumeRender::set_edge_color(View* view, MapHandlerGen* map, const QColor& color) +void Plugin_VolumeRender::set_edge_color(View* view, MapHandlerGen* map, const QColor& color, bool update_dock_tab) { if (view && view->is_linked_to_plugin(this) && map && map->is_linked_to_view(view) && map->dimension() == 3) { MapParameters& p = get_parameters(view, map); p.set_edge_color(color); - if (view->is_selected_view() && map->is_selected_map()) - dock_tab_->update_map_parameters(map, p); + if (update_dock_tab && view->is_selected_view() && map->is_selected_map()) + dock_tab_->set_edge_color(color); view->update(); } } -void Plugin_VolumeRender::set_face_color(View* view, MapHandlerGen* map, const QColor& color) +void Plugin_VolumeRender::set_face_color(View* view, MapHandlerGen* map, const QColor& color, bool update_dock_tab) { if (view && view->is_linked_to_plugin(this) && map && map->is_linked_to_view(view) && map->dimension() == 3) { MapParameters& p = get_parameters(view, map); p.set_face_color(color); p.set_transparency_factor(p.get_transparency_factor()); - if (view->is_selected_view() && map->is_selected_map()) - dock_tab_->update_map_parameters(map, p); + if (update_dock_tab && view->is_selected_view() && map->is_selected_map()) + dock_tab_->set_face_color(color); view->update(); } } -void Plugin_VolumeRender::set_vertex_scale_factor(View* view, MapHandlerGen* map, float32 sf) +void Plugin_VolumeRender::set_vertex_scale_factor(View* view, MapHandlerGen* map, float32 sf, bool update_dock_tab) { if (view && view->is_linked_to_plugin(this) && map && map->is_linked_to_view(view) && map->dimension() == 3) { MapParameters& p = get_parameters(view, map); p.set_vertex_scale_factor(sf); - if (view->is_selected_view() && map->is_selected_map()) - dock_tab_->update_map_parameters(map, p); + if (update_dock_tab && view->is_selected_view() && map->is_selected_map()) + dock_tab_->set_vertex_scale_factor(sf); view->update(); } } -void Plugin_VolumeRender::set_volume_explode_factor(View* view, MapHandlerGen* map, float32 vef) +void Plugin_VolumeRender::set_volume_explode_factor(View* view, MapHandlerGen* map, float32 vef, bool update_dock_tab) { if (view && view->is_linked_to_plugin(this) && map && map->is_linked_to_view(view) && map->dimension() == 3) { MapParameters& p = get_parameters(view, map); p.set_volume_explode_factor(vef); - if (view->is_selected_view() && map->is_selected_map()) - dock_tab_->update_map_parameters(map, p); + if (update_dock_tab && view->is_selected_view() && map->is_selected_map()) + dock_tab_->set_volume_explode_factor(vef); view->update(); } } -void Plugin_VolumeRender::set_apply_clipping_plane(View* view, MapHandlerGen* map, bool b) +void Plugin_VolumeRender::set_transparency_enabled(View* view, MapHandlerGen* map, bool b, bool update_dock_tab) { if (view && view->is_linked_to_plugin(this) && map && map->is_linked_to_view(view) && map->dimension() == 3) { MapParameters& p = get_parameters(view, map); - p.apply_clipping_plane_ = b; - if (view->is_selected_view() && map->is_selected_map()) - dock_tab_->update_map_parameters(map, p); - view->update(); - } -} - -MapParameters::MapParameters() : - position_vbo_(nullptr), - plane_clipping_(0., 0., 0., 0.), + p.set_transparency_enabled(b); #ifdef USE_TRANSPARENCY - volume_transparency_drawer_(nullptr), - volume_transparency_drawer_rend_(nullptr), -#endif - apply_clipping_plane_(false), - render_vertices_(false), - render_edges_(false), - render_faces_(true), - render_boundary_(false), - render_topology_(false), - use_transparency_(false) -{ - transparency_factor_ = 127; - vertex_color_ = QColor(190, 85, 168); - edge_color_ = QColor(0, 0, 0); - face_color_ = QColor(85, 168, 190); - volume_explode_factor_ = 0.8f; - vertex_scale_factor_ = 1; - vertex_base_size_ = 1; - - initialize_gl(); -} - -void MapParameters::set_position_vbo(cgogn::rendering::VBO* v) -{ - auto old = position_vbo_; - position_vbo_ = v; - if (position_vbo_ && position_vbo_->vector_dimension() == 3) - { - shader_simple_color_param_->set_position_vbo(position_vbo_); - shader_point_sprite_param_->set_position_vbo(position_vbo_); - - auto pos_attr = map_->get_attribute(QString::fromStdString(position_vbo_->name())); - if (pos_attr.is_valid()) + if (p.render_faces_) { - if (!use_transparency_) - { - volume_drawer_->update_face(*map_->get_map(), pos_attr); - volume_drawer_->update_edge(*map_->get_map(), pos_attr); - } -#ifdef USE_TRANSPARENCY - else { - volume_transparency_drawer_->update_face(*map_->get_map(), pos_attr); - } -#endif - topo_drawer_->update(*map_->get_map(),pos_attr); + if (b) + plugin_surface_render_transp::add_tr_vol(plugin_transparency_, view, map, p.get_transp_drawer_rend()); + else + plugin_surface_render_transp::remove_tr_vol(plugin_transparency_, view, map, p.get_transp_drawer_rend()); } - } else - position_vbo_ = old; +#endif + if (update_dock_tab && view->is_selected_view() && map->is_selected_map()) + dock_tab_->set_transparency_enabled(b); + view->update(); + } } -void MapParameters::initialize_gl() +void Plugin_VolumeRender::set_transparency_factor(View* view, MapHandlerGen* map, int32 tf, bool update_dock_tab) { - shader_simple_color_param_ = cgogn::rendering::ShaderSimpleColor::generate_param(); - shader_simple_color_param_->color_ = edge_color_; - - shader_point_sprite_param_ = cgogn::rendering::ShaderPointSprite::generate_param(); - shader_point_sprite_param_->color_ = vertex_color_; - shader_point_sprite_param_->size_ = vertex_base_size_ * vertex_scale_factor_; - - volume_drawer_ = cgogn::make_unique(); - volume_drawer_rend_ = volume_drawer_->generate_renderer(); - - topo_drawer_ = cgogn::make_unique(); - topo_drawer_rend_ = topo_drawer_->generate_renderer(); - - -#ifdef USE_TRANSPARENCY + if (view && view->is_linked_to_plugin(this) && map && map->is_linked_to_view(view) && map->dimension() == 3) { -// if (volume_transparency_drawer_ == nullptr) - volume_transparency_drawer_ = cgogn::make_unique(); - volume_transparency_drawer_rend_ = volume_transparency_drawer_->generate_renderer(); - volume_transparency_drawer_rend_->set_explode_volume(volume_explode_factor_); - volume_transparency_drawer_rend_->set_lighted(true); + MapParameters& p = get_parameters(view, map); + p.set_transparency_factor(tf); + if (update_dock_tab && view->is_selected_view() && map->is_selected_map()) + dock_tab_->set_transparency_factor(tf); + view->update(); } -#endif - frame_manip_ = cgogn::make_unique(); - - volume_drawer_rend_->set_explode_volume(volume_explode_factor_); - topo_drawer_->set_explode_volume(volume_explode_factor_); - - set_transparency_factor(transparency_factor_); - set_vertex_color(vertex_color_); - set_edge_color(edge_color_); - set_face_color(face_color_); - set_volume_explode_factor(volume_explode_factor_); - set_vertex_scale_factor(vertex_scale_factor_); - set_vertex_base_size(vertex_base_size_); - - set_position_vbo(position_vbo_); } - } // namespace plugin_volume_render } // namespace schnapps diff --git a/schnapps/plugins/volume_render/volume_render.h b/schnapps/plugins/volume_render/volume_render.h index b56ee00..619fc52 100644 --- a/schnapps/plugins/volume_render/volume_render.h +++ b/schnapps/plugins/volume_render/volume_render.h @@ -1,9 +1,7 @@ /******************************************************************************* * SCHNApps * * Copyright (C) 2015, IGG Group, ICube, University of Strasbourg, France * -* Plugin Volume Render * -* Author Etienne Schmitt (etienne.schmitt@inria.fr) Inria/Mimesis * -* Inspired by the surface render plugin * +* * * This library 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 2.1 of the License, or (at your * @@ -27,220 +25,26 @@ #define SCHNAPPS_PLUGIN_VOLUME_RENDER_H_ #include "dll.h" - -#include -#include - #include #include #include #include -#include +#include -#include -#include -#include -#include -#include -#include -#ifdef USE_TRANSPARENCY -#include -#endif +#include + +#include +#include namespace schnapps { -class MapHandlerGen; -class Plugin_VolumeRender; - namespace plugin_volume_render { -struct SCHNAPPS_PLUGIN_VOLUME_RENDER_API MapParameters -{ - friend class Plugin_VolumeRender; - - MapParameters(); - - cgogn::rendering::VBO* get_position_vbo() const { return position_vbo_; } - void set_position_vbo(cgogn::rendering::VBO* v); - - const QColor& get_vertex_color() const { return vertex_color_; } - void set_vertex_color(const QColor& c) - { - vertex_color_ = c; - shader_point_sprite_param_->color_ = vertex_color_; - } - - const QColor& get_edge_color() const { return edge_color_; } - void set_edge_color(const QColor& c) - { - edge_color_ = c; - shader_simple_color_param_->color_ = edge_color_; - volume_drawer_rend_->set_edge_color(c); - } - - const QColor& get_face_color() const { return face_color_; } - - void set_face_color(const QColor& c) - { - face_color_ = c; - volume_drawer_rend_->set_face_color(face_color_); -#ifdef USE_TRANSPARENCY - face_color_.setAlpha(transparency_factor_); - volume_transparency_drawer_rend_->set_color(face_color_); -#endif - } - - float32 get_vertex_base_size() const { return vertex_base_size_; } - void set_vertex_base_size(float32 bs) - { - vertex_base_size_ = bs; - shader_point_sprite_param_->size_ = vertex_base_size_ * vertex_scale_factor_; - } - - float32 get_vertex_scale_factor() const { return vertex_scale_factor_; } - void set_vertex_scale_factor(float32 sf) - { - vertex_scale_factor_ = sf; - shader_point_sprite_param_->size_ = vertex_base_size_ * vertex_scale_factor_; - } - - float32 get_volume_explode_factor() const { return volume_explode_factor_; } - void set_volume_explode_factor(float32 vef) - { - volume_explode_factor_ = vef; - volume_drawer_rend_->set_explode_volume(vef); -#ifdef USE_TRANSPARENCY - volume_transparency_drawer_rend_->set_explode_volume(vef); -#endif - topo_drawer_->set_explode_volume(vef); - if (!position_vbo_) return; - auto pos_attr = map_->get_attribute(QString::fromStdString(position_vbo_->name())); - if (pos_attr.is_valid()) - topo_drawer_->update(*map_->get_map(),pos_attr); - } - - int32 get_transparency_factor() const { return transparency_factor_; } - void set_transparency_factor(int32 n) - { -#ifdef USE_TRANSPARENCY - n = n % 255; - transparency_factor_ = n; - if (use_transparency_) - { - face_color_.setAlpha(n); - volume_transparency_drawer_rend_->set_color(face_color_); - } -#endif - } - - inline void set_transparency_enabled(bool b) - { - use_transparency_ = b; - if (b) - { - transparency_factor_ = transparency_factor_ % 255; - face_color_.setAlpha(transparency_factor_); - } - else - face_color_.setAlpha(255); - set_face_color(face_color_); - } - - bool get_apply_clipping_plane() const { return apply_clipping_plane_; } - void set_apply_clipping_plane(bool b) - { - apply_clipping_plane_ = b; - if (b) - { - VEC3F position; - VEC3F axis_z; - frame_manip_->get_position(position); - frame_manip_->get_axis(cgogn::rendering::FrameManipulator::Zt, axis_z); - float32 d = -(position.dot(axis_z)); - volume_drawer_rend_->set_clipping_plane(QVector4D(axis_z[0], axis_z[1], axis_z[2], d)); - topo_drawer_rend_->set_clipping_plane(QVector4D(axis_z[0], axis_z[1], axis_z[2], d)); -#ifdef USE_TRANSPARENCY - volume_transparency_drawer_rend_->set_clipping_plane(QVector4D(axis_z[0], axis_z[1], axis_z[2], d)); -#endif - } - else - { - volume_drawer_rend_->set_clipping_plane(QVector4D(0, 0, 0, 0)); - topo_drawer_rend_->set_clipping_plane(QVector4D(0, 0, 0, 0)); -#ifdef USE_TRANSPARENCY - volume_transparency_drawer_rend_->set_clipping_plane(QVector4D(0, 0, 0, 0)); -#endif - } - } - - void plane_clip_from_frame() - { - VEC3F position; - VEC3F axis_z; - frame_manip_->get_position(position); - frame_manip_->get_axis(cgogn::rendering::FrameManipulator::Zt,axis_z); - const float d = -(position.dot(axis_z)); - plane_clipping_ = QVector4D(axis_z[0],axis_z[1],axis_z[2],d); - } - -#ifdef USE_TRANSPARENCY - cgogn::rendering::VolumeTransparencyDrawer::Renderer* get_transp_drawer_rend() - { - return volume_transparency_drawer_rend_.get(); - } -#endif - -private: - - void initialize_gl(); - - MapHandler* map_; - - std::unique_ptr shader_simple_color_param_; - std::unique_ptr shader_point_sprite_param_; - - cgogn::rendering::VBO* position_vbo_; - - QColor vertex_color_; - QColor edge_color_; - QColor face_color_; - - float32 vertex_scale_factor_; - float32 vertex_base_size_; - - float32 volume_explode_factor_; - int32 transparency_factor_; - QVector4D plane_clipping_; - -#ifdef USE_TRANSPARENCY - std::unique_ptr volume_transparency_drawer_; - std::unique_ptr volume_transparency_drawer_rend_; -#endif - - std::unique_ptr volume_drawer_; - std::unique_ptr volume_drawer_rend_; - - std::unique_ptr topo_drawer_; - std::unique_ptr topo_drawer_rend_; - - std::unique_ptr frame_manip_; - bool apply_clipping_plane_; - -public: - - bool render_vertices_; - bool render_edges_; - bool render_faces_; - bool render_boundary_; - bool render_topology_; - bool use_transparency_; -}; - /** -* @brief Plugin for surface rendering +* @brief Plugin for volume rendering */ class SCHNAPPS_PLUGIN_VOLUME_RENDER_API Plugin_VolumeRender : public PluginInteraction { @@ -248,22 +52,21 @@ class SCHNAPPS_PLUGIN_VOLUME_RENDER_API Plugin_VolumeRender : public PluginInter Q_PLUGIN_METADATA(IID "SCHNApps.Plugin") Q_INTERFACES(schnapps::Plugin) - friend class VolumeRender_DockTab; - public: inline Plugin_VolumeRender() {} - ~Plugin_VolumeRender() {} - -private: + ~Plugin_VolumeRender() override {} MapParameters& get_parameters(View* view, MapHandlerGen* map); + bool check_docktab_activation(); + +private: bool enable() override; void disable() override; - inline void draw(View*, const QMatrix4x4& /*proj*/, const QMatrix4x4& /*mv*/) override {} + inline void draw(View*, const QMatrix4x4&, const QMatrix4x4&) override {} void draw_map(View* view, MapHandlerGen* map, const QMatrix4x4& proj, const QMatrix4x4& mv) override; inline void keyPress(View*, QKeyEvent*) override {} @@ -272,15 +75,21 @@ class SCHNAPPS_PLUGIN_VOLUME_RENDER_API Plugin_VolumeRender : public PluginInter void mouseRelease(View*, QMouseEvent*) override; void mouseMove(View*, QMouseEvent*) override; inline void wheelEvent(View*, QWheelEvent*) override {} - void resizeGL(View* view, int width, int height) override {} + void resizeGL(View*, int, int) override {} void view_linked(View*) override; void view_unlinked(View*) override; - void connectivity_changed(MapHandlerGen* mh); +private slots: + + // slots called from View signals + void map_linked(MapHandlerGen* map); + void map_unlinked(MapHandlerGen* map); + +private: - void map_linked(View* view, MapHandlerGen* map); - void map_unlinked(View* view, MapHandlerGen* map); + void add_linked_map(View* view, MapHandlerGen* map); + void remove_linked_map(View* view, MapHandlerGen* map); private slots: @@ -289,81 +98,27 @@ private slots: void linked_map_vbo_removed(cgogn::rendering::VBO* vbo); void linked_map_bb_changed(); void linked_map_connectivity_changed(); - void linked_attribute_changed(cgogn::Orbit,QString); + void linked_map_attribute_changed(cgogn::Orbit orbit, const QString& attribute_name); + void viewer_initialized(); - void enable_on_selected_view(Plugin* p); - void update_dock_tab(); + void enable_on_selected_view(Plugin* p); public slots: - void set_render_vertices(View* view, MapHandlerGen* map, bool b); - inline void set_render_vertices(const QString& view_name, const QString& map_name, bool b) - { - set_render_vertices(schnapps_->get_view(view_name), schnapps_->get_map(map_name), b); - } - - void set_render_edges(View* view, MapHandlerGen* map, bool b); - inline void set_render_edges(const QString& view_name, const QString& map_name, bool b) - { - set_render_edges(schnapps_->get_view(view_name), schnapps_->get_map(map_name), b); - } - - void set_render_faces(View* view, MapHandlerGen* map, bool b); - inline void set_render_faces(const QString& view_name, const QString& map_name, bool b) - { - set_render_faces(schnapps_->get_view(view_name), schnapps_->get_map(map_name), b); - } - - void set_render_boundary(View* view, MapHandlerGen* map, bool b); - inline void set_render_boundary(const QString& view_name, const QString& map_name, bool b) - { - set_render_boundary(schnapps_->get_view(view_name), schnapps_->get_map(map_name), b); - } - - void set_position_vbo(View* view, MapHandlerGen* map, cgogn::rendering::VBO* vbo); - inline void set_position_vbo(const QString& view_name, const QString& map_name, const QString& vbo_name) - { - MapHandlerGen* map = schnapps_->get_map(map_name); - if (map) - set_position_vbo(schnapps_->get_view(view_name), map, map->get_vbo(vbo_name)); - } - - void set_vertex_color(View* view, MapHandlerGen* map, const QColor& color); - inline void set_vertex_color(const QString& view_name, const QString& map_name, const QColor& color) - { - set_vertex_color(schnapps_->get_view(view_name), schnapps_->get_map(map_name), color); - } - - void set_edge_color(View* view, MapHandlerGen* map, const QColor& color); - inline void set_edge_color(const QString& view_name, const QString& map_name, const QColor& color) - { - set_edge_color(schnapps_->get_view(view_name), schnapps_->get_map(map_name), color); - } - - void set_face_color(View* view, MapHandlerGen* map, const QColor& color); - inline void set_face_color(const QString& view_name, const QString& map_name, const QColor& color) - { - set_face_color(schnapps_->get_view(view_name), schnapps_->get_map(map_name), color); - } - - void set_vertex_scale_factor(View* view, MapHandlerGen* map, float32 sf); - void set_vertex_scale_factor(const QString& view_name, const QString& map_name, float32 sf) - { - set_vertex_scale_factor(schnapps_->get_view(view_name), schnapps_->get_map(map_name), sf); - } - - void set_volume_explode_factor(View* view, MapHandlerGen* map, float32 vef); - void set_volume_explode_factor(const QString& view_name, const QString& map_name, float32 vef) - { - set_volume_explode_factor(schnapps_->get_view(view_name), schnapps_->get_map(map_name), vef); - } - - void set_apply_clipping_plane(View* view, MapHandlerGen* map, bool b); - void set_apply_clipping_plane(const QString& view_name, const QString& map_name, bool b) - { - set_apply_clipping_plane(schnapps_->get_view(view_name), schnapps_->get_map(map_name), b); - } + void set_position_vbo(View* view, MapHandlerGen* map, cgogn::rendering::VBO* vbo, bool update_dock_tab); + void set_render_vertices(View* view, MapHandlerGen* map, bool b, bool update_dock_tab); + void set_render_edges(View* view, MapHandlerGen* map, bool b, bool update_dock_tab); + void set_render_faces(View* view, MapHandlerGen* map, bool b, bool update_dock_tab); + void set_render_topology(View* view, MapHandlerGen* map, bool b, bool update_dock_tab); + void set_apply_clipping_plane(View* view, MapHandlerGen* map, bool b, bool update_dock_tab); + void set_vertex_color(View* view, MapHandlerGen* map, const QColor& color, bool update_dock_tab); + void set_edge_color(View* view, MapHandlerGen* map, const QColor& color, bool update_dock_tab); + void set_face_color(View* view, MapHandlerGen* map, const QColor& color, bool update_dock_tab); + void set_vertex_scale_factor(View* view, MapHandlerGen* map, float32 sf, bool update_dock_tab); + void set_volume_explode_factor(View* view, MapHandlerGen* map, float32 vef, bool update_dock_tab); + void set_transparency_enabled(View* view, MapHandlerGen* map, bool b, bool update_dock_tab); + void set_transparency_factor(View* view, MapHandlerGen* map, int32 tf, bool update_dock_tab); private: @@ -376,9 +131,6 @@ public slots: #ifdef USE_TRANSPARENCY PluginInteraction* plugin_transparency_; #endif - - std::map connection_map_linked_; - std::map connection_map_unlinked_; }; } // namespace plugin_volume_render diff --git a/schnapps/plugins/volume_render/volume_render.ui b/schnapps/plugins/volume_render/volume_render.ui index f987bca..271c357 100644 --- a/schnapps/plugins/volume_render/volume_render.ui +++ b/schnapps/plugins/volume_render/volume_render.ui @@ -7,94 +7,73 @@ 0 0 - 278 + 240 600 Form - - - - - - - - 96 - 0 - - - - position vbo : - - - + + + + + + 96 + 0 + + + + Position : + + + + + + + + 0 + 0 + + - - - - 0 - 0 - - - - - - select VBO - - - - + + - select VBO - + - + - + - - - - - - render vertices - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 16777215 - 32 - - - - Color - - - - + + + + render vertices + + - - + + + + + 0 + 0 + + + + + 16777215 + 32 + + + + Color + + + + + 50 @@ -103,239 +82,87 @@ - - - - Qt::Horizontal + + + + render edges - - - - - - render edges - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 16777215 - 32 - - - - Color - - - - + + + + + 0 + 0 + + + + + 16777215 + 32 + + + + Color + + - - - - - - render faces - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 16777215 - 32 - - - - - - - - - 255 - 0 - 0 - - - - - - - 0 - 255 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 170 - 0 - 255 - - - - - - - - - 255 - 0 - 0 - - - - - - - 0 - 255 - 0 - - - - - - - 255 - 255 - 255 - - - - - - - 170 - 0 - 255 - - - - - - - - - 143 - 146 - 147 - - - - - - - 0 - 255 - 0 - - - - - - - 170 - 0 - 255 - - - - - - - 170 - 0 - 255 - - - - - - - - Color - - - - + + + + render faces + + + true + + - + + + + + 0 + 0 + + + + + 16777215 + 32 + + + + Color + + + + + + + render topology + + + + Qt::Horizontal - + - explod volume factor + Volume explode factor Qt::AlignCenter - - + + 0 @@ -346,28 +173,28 @@ 100 - 100 + 80 Qt::Horizontal - + Qt::Horizontal - - + + - use transparency rendering + use transparency - + 254 @@ -380,24 +207,14 @@ - + Qt::Horizontal - - - - render boundary - - - true - - - - + true @@ -410,14 +227,7 @@ - - - - render topology - - - - + Qt::Vertical diff --git a/schnapps/plugins/volume_render/volume_render_dock_tab.cpp b/schnapps/plugins/volume_render/volume_render_dock_tab.cpp index 55b7d6f..fd14d9c 100644 --- a/schnapps/plugins/volume_render/volume_render_dock_tab.cpp +++ b/schnapps/plugins/volume_render/volume_render_dock_tab.cpp @@ -1,9 +1,7 @@ /******************************************************************************* * SCHNApps * * Copyright (C) 2015, IGG Group, ICube, University of Strasbourg, France * -* Plugin Volume Render * -* Author Etienne Schmitt (etienne.schmitt@inria.fr) Inria/Mimesis * -* Inspired by the surface render plugin * +* * * This library 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 2.1 of the License, or (at your * @@ -23,11 +21,12 @@ * * *******************************************************************************/ -#include "volume_render_dock_tab.h" -#include "volume_render.h" +#include +#include +#ifdef USE_TRANSPARENCY #include - +#endif #include #include @@ -49,13 +48,12 @@ VolumeRender_DockTab::VolumeRender_DockTab(SCHNApps* s, Plugin_VolumeRender* p) connect(combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(position_vbo_changed(int))); connect(check_renderVertices, SIGNAL(toggled(bool)), this, SLOT(render_vertices_changed(bool))); - connect(slider_verticesScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(vertices_scale_factor_changed(int))); connect(check_renderEdges, SIGNAL(toggled(bool)), this, SLOT(render_edges_changed(bool))); connect(check_renderFaces, SIGNAL(toggled(bool)), this, SLOT(render_faces_changed(bool))); - connect(check_renderBoundary, SIGNAL(toggled(bool)), this, SLOT(render_boundary_changed(bool))); - connect(sliderExplodeVolumes, SIGNAL(valueChanged(int)), this, SLOT(explode_volumes_changed(int))); + connect(check_renderTopology, SIGNAL(toggled(bool)), this, SLOT(render_topology_changed(bool))); connect(check_clippingPlane, SIGNAL(toggled(bool)), this, SLOT(apply_clipping_plane_changed(bool))); - connect(topologyRender_checkBox, SIGNAL(toggled(bool)), this, SLOT(render_topology_changed(bool))); + connect(slider_vertexScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(vertex_scale_factor_changed(int))); + connect(slider_volumeExplodeFactor, SIGNAL(valueChanged(int)), this, SLOT(volume_explode_factor_changed(int))); color_dial_ = new QColorDialog(face_color_, nullptr); connect(vertexColorButton, SIGNAL(clicked()), this, SLOT(vertex_color_clicked())); @@ -63,205 +61,105 @@ VolumeRender_DockTab::VolumeRender_DockTab(SCHNApps* s, Plugin_VolumeRender* p) connect(faceColorButton, SIGNAL(clicked()), this, SLOT(face_color_clicked())); connect(color_dial_, SIGNAL(accepted()), this, SLOT(color_selected())); - checkBox_transparency->setChecked(false); + check_useTransparency->setChecked(false); slider_transparency->setDisabled(true); #ifdef USE_TRANSPARENCY + connect(check_useTransparency, SIGNAL(toggled(bool)), this, SLOT(transparency_enabled_changed(bool))); connect(slider_transparency, SIGNAL(valueChanged(int)), this, SLOT(transparency_factor_changed(int))); - connect(checkBox_transparency, SIGNAL(toggled(bool)), this, SLOT(transparency_rendering_changed(bool))); #else - checkBox_transparency->setDisabled(true); + check_useTransparency->setDisabled(true); #endif -} + selected_map_ = schnapps_->get_selected_map(); + if (selected_map_) + { + connect(selected_map_, SIGNAL(vbo_added(cgogn::rendering::VBO*)), this, SLOT(selected_map_vbo_added(cgogn::rendering::VBO*))); + connect(selected_map_, SIGNAL(vbo_removed(cgogn::rendering::VBO*)), this, SLOT(selected_map_vbo_removed(cgogn::rendering::VBO*))); + } + connect(schnapps_, SIGNAL(selected_view_changed(View*, View*)), this, SLOT(selected_view_changed(View*, View*))); + connect(schnapps_, SIGNAL(selected_map_changed(MapHandlerGen*, MapHandlerGen*)), this, SLOT(selected_map_changed(MapHandlerGen*, MapHandlerGen*))); +} +VolumeRender_DockTab::~VolumeRender_DockTab() +{ + disconnect(schnapps_, SIGNAL(selected_view_changed(View*, View*)), this, SLOT(update_ui())); + disconnect(schnapps_, SIGNAL(selected_map_changed(MapHandlerGen*, MapHandlerGen*)), this, SLOT(update_ui())); +} +/*****************************************************************************/ +// slots called from UI signals +/*****************************************************************************/ void VolumeRender_DockTab::position_vbo_changed(int index) { if (!updating_ui_) { - View* view = schnapps_->get_selected_view(); MapHandlerGen* map = schnapps_->get_selected_map(); - if (view && map) - { - MapParameters& p = plugin_->get_parameters(view, map); - p.set_position_vbo(map->get_vbo(combo_positionVBO->currentText())); - view->update(); - } + if (map) + plugin_->set_position_vbo(schnapps_->get_selected_view(), map, map->get_vbo(combo_positionVBO->currentText()), false); } } void VolumeRender_DockTab::render_vertices_changed(bool b) { if (!updating_ui_) - { - View* view = schnapps_->get_selected_view(); - MapHandlerGen* map = schnapps_->get_selected_map(); - if (view && map) - { - MapParameters& p = plugin_->get_parameters(view, map); - p.render_vertices_ = b; - view->update(); - } - } -} - -void VolumeRender_DockTab::vertices_scale_factor_changed(int i) -{ - if (!updating_ui_) - { - View* view = schnapps_->get_selected_view(); - MapHandlerGen* map = schnapps_->get_selected_map(); - if (view && map) - { - MapParameters& p = plugin_->get_parameters(view, map); - p.set_vertex_scale_factor(i / 50.0); - view->update(); - } - } + plugin_->set_render_vertices(schnapps_->get_selected_view(), schnapps_->get_selected_map(), b, false); } void VolumeRender_DockTab::render_edges_changed(bool b) { if (!updating_ui_) - { - View* view = schnapps_->get_selected_view(); - MapHandlerGen* map = schnapps_->get_selected_map(); - if (view && map) - { - MapParameters& p = plugin_->get_parameters(view, map); - p.render_edges_ = b; - view->update(); - } - } + plugin_->set_render_edges(schnapps_->get_selected_view(), schnapps_->get_selected_map(), b, false); } void VolumeRender_DockTab::render_faces_changed(bool b) { if (!updating_ui_) - { - this->sliderExplodeVolumes->setEnabled(b); - this->labelExplodVolumes->setEnabled(b); - View* view = schnapps_->get_selected_view(); - MapHandlerGen* map = schnapps_->get_selected_map(); - if (view && map) - { - MapParameters& p = plugin_->get_parameters(view, map); - p.render_faces_ = b; - view->update(); -#ifdef USE_TRANSPARENCY - if (p.use_transparency_) - { - if (b) - plugin_surface_render_transp::add_tr_vol(plugin_->plugin_transparency_, view, map, p.get_transp_drawer_rend()); - else - plugin_surface_render_transp::remove_tr_vol(plugin_->plugin_transparency_, view, map, p.get_transp_drawer_rend()); - } -#endif - } - } + plugin_->set_render_faces(schnapps_->get_selected_view(), schnapps_->get_selected_map(), b, false); } -void VolumeRender_DockTab::transparency_rendering_changed(bool b) +void VolumeRender_DockTab::render_topology_changed(bool b) { -#ifdef USE_TRANSPARENCY if (!updating_ui_) - { - slider_transparency->setEnabled(b); - View* view = schnapps_->get_selected_view(); - MapHandlerGen* map = schnapps_->get_selected_map(); - if (view && map) - { - MapParameters& p = plugin_->get_parameters(view, map); - p.set_transparency_enabled(b); - plugin_->connectivity_changed(map); - if (p.render_faces_) - { - if (b) - plugin_surface_render_transp::add_tr_vol(plugin_->plugin_transparency_, view, map, p.get_transp_drawer_rend()); - else - plugin_surface_render_transp::remove_tr_vol(plugin_->plugin_transparency_, view, map, p.get_transp_drawer_rend()); - } - view->update(); - } - } -#endif + plugin_->set_render_topology(schnapps_->get_selected_view(), schnapps_->get_selected_map(), b, false); } -void VolumeRender_DockTab::render_boundary_changed(bool b) +void VolumeRender_DockTab::apply_clipping_plane_changed(bool b) { if (!updating_ui_) - { - View* view = schnapps_->get_selected_view(); - MapHandlerGen* map = schnapps_->get_selected_map(); - if (view && map) - { - MapParameters& p = plugin_->get_parameters(view, map); - p.render_boundary_ = b; - view->update(); - } - } + plugin_->set_apply_clipping_plane(schnapps_->get_selected_view(), schnapps_->get_selected_map(), b, false); } -void VolumeRender_DockTab::explode_volumes_changed(int fact) +void VolumeRender_DockTab::vertex_scale_factor_changed(int i) { if (!updating_ui_) - { - View* view = schnapps_->get_selected_view(); - MapHandlerGen* map = schnapps_->get_selected_map(); - if (view && map) - { - MapParameters& p = plugin_->get_parameters(view, map); - p.set_volume_explode_factor(float32(fact) / 100.0f); - view->update(); - } - } + plugin_->set_vertex_scale_factor(schnapps_->get_selected_view(), schnapps_->get_selected_map(), i / 50.0, false); } -void VolumeRender_DockTab::apply_clipping_plane_changed(bool b) +void VolumeRender_DockTab::volume_explode_factor_changed(int i) { if (!updating_ui_) - { - View* view = schnapps_->get_selected_view(); - MapHandlerGen* map = schnapps_->get_selected_map(); - if (view && map) - { - MapParameters& p = plugin_->get_parameters(view, map); - p.set_apply_clipping_plane(b); - view->update(); - } - } + plugin_->set_volume_explode_factor(schnapps_->get_selected_view(), schnapps_->get_selected_map(), i / 100.0, false); } -void VolumeRender_DockTab::render_topology_changed(bool b) +void VolumeRender_DockTab::transparency_enabled_changed(bool b) { +#ifdef USE_TRANSPARENCY if (!updating_ui_) { - View* view = schnapps_->get_selected_view(); - MapHandlerGen* map = schnapps_->get_selected_map(); - if (view && map) - { - MapParameters& p = plugin_->get_parameters(view, map); - p.render_topology_ = b; - view->update(); - } + plugin_->set_transparency_enabled(schnapps_->get_selected_view(), schnapps_->get_selected_map(), b, false); + update_after_use_transparency_changed(); } +#endif } void VolumeRender_DockTab::transparency_factor_changed(int n) { +#ifdef USE_TRANSPARENCY if (!updating_ui_) - { - View* view = schnapps_->get_selected_view(); - MapHandlerGen* map = schnapps_->get_selected_map(); - if (view && map) - { - MapParameters& p = plugin_->get_parameters(view, map); - p.set_transparency_factor(n); - view->update(); - } - } + plugin_->set_transparency_factor(schnapps_->get_selected_view(), schnapps_->get_selected_map(), n, false); +#endif } void VolumeRender_DockTab::vertex_color_clicked() @@ -297,68 +195,194 @@ void VolumeRender_DockTab::color_selected() { vertex_color_ = col; vertexColorButton->setStyleSheet("QPushButton { background-color:" + col.name() + "}"); - if (view && map) - { - MapParameters& p = plugin_->get_parameters(view, map); - p.set_vertex_color(vertex_color_); - view->update(); - } + plugin_->set_vertex_color(view, map, vertex_color_, false); } if (current_color_dial_ == 2) { edge_color_ = col; edgeColorButton->setStyleSheet("QPushButton { background-color:" + col.name() + "}"); - if (view && map) - { - MapParameters& p = plugin_->get_parameters(view, map); - p.set_edge_color(edge_color_); - view->update(); - } + plugin_->set_edge_color(view, map, edge_color_, false); } if (current_color_dial_ == 3) { face_color_ = col; faceColorButton->setStyleSheet("QPushButton { background-color:" + col.name() + "}"); - if (view && map) - { - MapParameters& p = plugin_->get_parameters(view, map); - p.set_face_color(face_color_); - view->update(); - } + plugin_->set_face_color(view, map, edge_color_, false); } } -void VolumeRender_DockTab::add_position_vbo(QString name) +/*****************************************************************************/ +// slots called from SCHNApps signals +/*****************************************************************************/ + +void VolumeRender_DockTab::selected_view_changed(View* old, View* cur) +{ + if (plugin_->check_docktab_activation()) + refresh_ui(); +} + +void VolumeRender_DockTab::selected_map_changed(MapHandlerGen* old, MapHandlerGen* cur) +{ + if (selected_map_) + { + disconnect(selected_map_, SIGNAL(vbo_added(cgogn::rendering::VBO*)), this, SLOT(selected_map_vbo_added(cgogn::rendering::VBO*))); + disconnect(selected_map_, SIGNAL(vbo_removed(cgogn::rendering::VBO*)), this, SLOT(selected_map_vbo_removed(cgogn::rendering::VBO*))); + } + selected_map_ = cur; + connect(selected_map_, SIGNAL(vbo_added(cgogn::rendering::VBO*)), this, SLOT(selected_map_vbo_added(cgogn::rendering::VBO*)), Qt::UniqueConnection); + connect(selected_map_, SIGNAL(vbo_removed(cgogn::rendering::VBO*)), this, SLOT(selected_map_vbo_removed(cgogn::rendering::VBO*)), Qt::UniqueConnection); + + if (plugin_->check_docktab_activation()) + refresh_ui(); +} + +/*****************************************************************************/ +// slots called from MapHandlerGen signals +/*****************************************************************************/ + +void VolumeRender_DockTab::selected_map_vbo_added(cgogn::rendering::VBO* vbo) +{ + const QString vbo_name = QString::fromStdString(vbo->name()); + if (vbo->vector_dimension() == 3) + combo_positionVBO->addItem(vbo_name); +} + +void VolumeRender_DockTab::selected_map_vbo_removed(cgogn::rendering::VBO* vbo) +{ + const QString vbo_name = QString::fromStdString(vbo->name()); + if (vbo->vector_dimension() == 3) + { + int index = combo_positionVBO->findText(vbo_name); + if (index > 0) + combo_positionVBO->removeItem(index); + } +} + +/*****************************************************************************/ +// methods used to update the UI from the plugin +/*****************************************************************************/ + +void VolumeRender_DockTab::set_position_vbo(cgogn::rendering::VBO* vbo) { updating_ui_ = true; - combo_positionVBO->addItem(name); + if (vbo && vbo->vector_dimension() == 3) + { + const QString vbo_name = QString::fromStdString(vbo->name()); + int index = combo_positionVBO->findText(vbo_name); + if (index > 0) + combo_positionVBO->setCurrentIndex(index); + } + else + combo_positionVBO->setCurrentIndex(0); updating_ui_ = false; } -void VolumeRender_DockTab::remove_position_vbo(QString name) +void VolumeRender_DockTab::set_render_vertices(bool b) { updating_ui_ = true; - int curIndex = combo_positionVBO->currentIndex(); - int index = combo_positionVBO->findText(name, Qt::MatchExactly); - if (curIndex == index) - combo_positionVBO->setCurrentIndex(0); - combo_positionVBO->removeItem(index); + check_renderVertices->setChecked(b); + updating_ui_ = false; +} + +void VolumeRender_DockTab::set_render_edges(bool b) +{ + updating_ui_ = true; + check_renderEdges->setChecked(b); + updating_ui_ = false; +} + +void VolumeRender_DockTab::set_render_faces(bool b) +{ + updating_ui_ = true; + check_renderFaces->setChecked(b); + updating_ui_ = false; +} + +void VolumeRender_DockTab::set_render_topology(bool b) +{ + updating_ui_ = true; + check_renderTopology->setChecked(b); updating_ui_ = false; } -void VolumeRender_DockTab::update_map_parameters(MapHandlerGen* map, const MapParameters& p) +void VolumeRender_DockTab::set_apply_clipping_plane(bool b) { - if (!map) + updating_ui_ = true; + check_clippingPlane->setChecked(b); + updating_ui_ = false; +} + +void VolumeRender_DockTab::set_vertex_color(const QColor& color) +{ + updating_ui_ = true; + vertex_color_ = color; + vertexColorButton->setStyleSheet("QPushButton { background-color:" + color.name() + "}"); + updating_ui_ = false; +} + +void VolumeRender_DockTab::set_edge_color(const QColor& color) +{ + updating_ui_ = true; + edge_color_ = color; + edgeColorButton->setStyleSheet("QPushButton { background-color:" + color.name() + "}"); + updating_ui_ = false; +} + +void VolumeRender_DockTab::set_face_color(const QColor& color) +{ + updating_ui_ = true; + face_color_ = color; + faceColorButton->setStyleSheet("QPushButton { background-color:" + color.name() + "}"); + updating_ui_ = false; +} + +void VolumeRender_DockTab::set_vertex_scale_factor(float sf) +{ + updating_ui_ = true; + slider_vertexScaleFactor->setSliderPosition(sf * 50.0); + updating_ui_ = false; +} + +void VolumeRender_DockTab::set_volume_explode_factor(float sf) +{ + updating_ui_ = true; + slider_volumeExplodeFactor->setSliderPosition(sf * 50.0); + updating_ui_ = false; +} + +void VolumeRender_DockTab::set_transparency_enabled(bool b) +{ + updating_ui_ = true; + check_useTransparency->setChecked(b); + update_after_use_transparency_changed(); + updating_ui_ = false; +} + +void VolumeRender_DockTab::set_transparency_factor(int tf) +{ + updating_ui_ = true; + slider_transparency->setValue(tf); + updating_ui_ = false; +} + +void VolumeRender_DockTab::refresh_ui() +{ + MapHandlerGen* map = schnapps_->get_selected_map(); + View* view = schnapps_->get_selected_view(); + + if (!map || !view) return; + const MapParameters& p = plugin_->get_parameters(view, map); + updating_ui_ = true; combo_positionVBO->clear(); combo_positionVBO->addItem("- select VBO -"); - unsigned int i = 1; + uint32 i = 1; for (const auto& vbo_it : map->get_vbo_set()) { auto& vbo = vbo_it.second; @@ -372,17 +396,12 @@ void VolumeRender_DockTab::update_map_parameters(MapHandlerGen* map, const MapPa } } - check_renderVertices->setChecked(p.render_vertices_); - slider_verticesScaleFactor->setSliderPosition(p.get_vertex_scale_factor() * 50.0); - check_renderEdges->setChecked(p.render_edges_); - check_renderFaces->setChecked(p.render_faces_); - check_renderBoundary->setChecked(p.render_boundary_); - sliderExplodeVolumes->setValue(std::round(100.0f*p.get_volume_explode_factor())); - topologyRender_checkBox->setChecked(p.render_topology_); - - checkBox_transparency->setChecked(p.use_transparency_); - slider_transparency->setValue(p.get_transparency_factor()); - slider_transparency->setEnabled(p.use_transparency_); + check_renderVertices->setChecked(p.get_render_vertices()); + slider_vertexScaleFactor->setSliderPosition(p.get_vertex_scale_factor() * 50.0); + check_renderEdges->setChecked(p.get_render_edges()); + check_renderFaces->setChecked(p.get_render_faces()); + slider_volumeExplodeFactor->setValue(std::round(p.get_volume_explode_factor() * 100.0)); + check_renderTopology->setChecked(p.get_render_topology()); vertex_color_ = p.get_vertex_color(); vertexColorButton->setStyleSheet("QPushButton { background-color:" + vertex_color_.name() + " }"); @@ -393,6 +412,33 @@ void VolumeRender_DockTab::update_map_parameters(MapHandlerGen* map, const MapPa face_color_ = p.get_face_color(); faceColorButton->setStyleSheet("QPushButton { background-color:" + face_color_.name() + " }"); +#ifdef USE_TRANSPARENCY + check_useTransparency->setChecked(p.get_transparency_enabled()); + slider_transparency->setValue(p.get_transparency_factor()); + slider_transparency->setEnabled(p.get_transparency_enabled()); +#endif + + check_clippingPlane->setChecked(p.get_apply_clipping_plane()); + + updating_ui_ = false; +} + +/*****************************************************************************/ +// internal UI cascading updates +/*****************************************************************************/ + +void VolumeRender_DockTab::update_after_use_transparency_changed() +{ + updating_ui_ = true; + MapHandlerGen* map = schnapps_->get_selected_map(); + View* view = schnapps_->get_selected_view(); + + const MapParameters& p = plugin_->get_parameters(view, map); + + slider_transparency->setEnabled(p.get_transparency_enabled()); + if (p.get_transparency_enabled()) + slider_transparency->setValue(p.get_transparency_factor()); + updating_ui_ = false; } diff --git a/schnapps/plugins/volume_render/volume_render_dock_tab.h b/schnapps/plugins/volume_render/volume_render_dock_tab.h index 5739e0e..21fa0ff 100644 --- a/schnapps/plugins/volume_render/volume_render_dock_tab.h +++ b/schnapps/plugins/volume_render/volume_render_dock_tab.h @@ -1,9 +1,7 @@ /******************************************************************************* * SCHNApps * * Copyright (C) 2015, IGG Group, ICube, University of Strasbourg, France * -* Plugin Volume Render * -* Author Etienne Schmitt (etienne.schmitt@inria.fr) Inria/Mimesis * -* Inspired by the surface render plugin * +* * * This library 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 2.1 of the License, or (at your * @@ -31,70 +29,97 @@ #include +namespace cgogn { namespace rendering { class VBO; } } + namespace schnapps { class SCHNApps; +class View; class MapHandlerGen; namespace plugin_volume_render { class Plugin_VolumeRender; -struct MapParameters; class SCHNAPPS_PLUGIN_VOLUME_RENDER_API VolumeRender_DockTab : public QWidget, public Ui::VolumeRender_TabWidget { Q_OBJECT - friend class Plugin_VolumeRender; - public: VolumeRender_DockTab(SCHNApps* s, Plugin_VolumeRender* p); + ~VolumeRender_DockTab() override; private: SCHNApps* schnapps_; Plugin_VolumeRender* plugin_; + MapHandlerGen* selected_map_; + bool updating_ui_; + QColorDialog* color_dial_; int current_color_dial_; - QColor vertex_color_; QColor edge_color_; QColor face_color_; - bool updating_ui_; - private slots: + // slots called from UI signals void position_vbo_changed(int index); void render_vertices_changed(bool b); - void vertices_scale_factor_changed(int i); void render_edges_changed(bool b); void render_faces_changed(bool b); - void render_boundary_changed(bool b); - void explode_volumes_changed(int i); - void apply_clipping_plane_changed(bool b); void render_topology_changed(bool b); + void apply_clipping_plane_changed(bool b); + void vertex_scale_factor_changed(int i); + void volume_explode_factor_changed(int i); + void transparency_enabled_changed(bool b); void transparency_factor_changed(int n); - void transparency_rendering_changed(bool b); void vertex_color_clicked(); void edge_color_clicked(); void face_color_clicked(); void color_selected(); -private: + // slots called from SCHNApps signals + void selected_view_changed(View* old, View* cur); + void selected_map_changed(MapHandlerGen* old, MapHandlerGen* cur); + + // slots called from MapHandlerGen signals + void selected_map_vbo_added(cgogn::rendering::VBO* vbo); + void selected_map_vbo_removed(cgogn::rendering::VBO* vbo); + +public: + + // methods used to update the UI from the plugin + void set_position_vbo(cgogn::rendering::VBO* vbo); + void set_render_vertices(bool b); + void set_render_edges(bool b); + void set_render_faces(bool b); + void set_render_topology(bool b); + void set_apply_clipping_plane(bool b); + void set_vertex_color(const QColor& color); + void set_edge_color(const QColor& color); + void set_face_color(const QColor& color); + void set_vertex_scale_factor(float sf); + void set_volume_explode_factor(float vef); + void set_transparency_enabled(bool b); + void set_transparency_factor(int tf); + + void refresh_ui(); - void add_position_vbo(QString name); - void remove_position_vbo(QString name); +private: - void update_map_parameters(MapHandlerGen* map, const MapParameters& p); + // internal UI cascading updates + void update_after_use_transparency_changed(); }; } // namespace plugin_volume_render + } // namespace schnapps #endif // SCHNAPPS_PLUGIN_VOLUME_RENDER_DOCK_TAB_H_