From 8a5d15fb37a2686d7af5cfd644720e627d154a3c Mon Sep 17 00:00:00 2001 From: Lionel Untereiner Date: Fri, 27 Sep 2019 16:19:49 +0200 Subject: [PATCH] [volume render] ADD hexa grid specific view with clipping topo using i, j , k volumes attributes --- .../plugins/volume_render/map_parameters.h | 112 +++++- .../plugins/volume_render/volume_render.cpp | 40 ++- .../plugins/volume_render/volume_render.h | 3 + .../plugins/volume_render/volume_render.ui | 326 +++++++++--------- .../volume_render/volume_render_dock_tab.cpp | 91 ++++- .../volume_render/volume_render_dock_tab.h | 8 + 6 files changed, 401 insertions(+), 179 deletions(-) diff --git a/schnapps/plugins/volume_render/map_parameters.h b/schnapps/plugins/volume_render/map_parameters.h index 2ee6a2d..c457a49 100644 --- a/schnapps/plugins/volume_render/map_parameters.h +++ b/schnapps/plugins/volume_render/map_parameters.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #ifdef USE_TRANSPARENCY @@ -68,6 +69,7 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters render_topology_(false), render_color_per_volumes_(false), apply_clipping_plane_(false), + apply_grid_clipping_plane_(false), clipping_plane_initialized_(false), vertex_color_(190, 85, 168), edge_color_(0, 0, 0), @@ -77,6 +79,9 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters volume_explode_factor_(0.8f), use_transparency_(false), transparency_factor_(127), + clipping_x_(0), + clipping_y_(0), + clipping_z_(0), color_map_(cgogn::ColorMapType::INFERNO) { initialize_gl(); @@ -91,6 +96,7 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters inline bool render_topology() const { return render_topology_; } inline bool render_color_per_volume() const { return render_color_per_volumes_; } inline bool apply_clipping_plane() const { return apply_clipping_plane_; } + inline bool apply_grid_clipping_plane() const { return apply_grid_clipping_plane_; } inline const QColor& vertex_color() const { return vertex_color_; } inline const QColor& edge_color() const { return edge_color_; } inline const QColor& face_color() const { return face_color_; } @@ -118,6 +124,9 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters update_volume_drawer(); if(render_topology_) update_topo_drawer(); + + if(apply_grid_clipping_plane_) + update_hexa_drawer(); } else position_vbo_ = nullptr; @@ -172,9 +181,6 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters color_map_ = cgogn::color_map_type(color_map.toStdString()); render_color_per_volumes_ = true; - - std::cout << std::boolalpha << recompute << std::endl; - if(recompute) update_volume_color_attribute(true); } @@ -203,6 +209,10 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters topo_drawer_->set_explode_volume(vef); if (render_topology_) update_topo_drawer(); + + hexa_drawer_rend_->set_explode_volume(volume_explode_factor_); + if(apply_grid_clipping_plane_) + update_hexa_drawer(); } void set_transparency_enabled(bool b) @@ -246,6 +256,7 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters #ifdef USE_TRANSPARENCY volume_transparency_drawer_rend_->set_clipping_plane(QVector4D(0, 0, 0, 0)); #endif + hexa_drawer_rend_->set_clipping_plane(QVector4D(0, 0, 0, 0)); } } @@ -271,6 +282,57 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters #ifdef USE_TRANSPARENCY volume_transparency_drawer_rend_->set_clipping_plane(QVector4D(z_axis[0], z_axis[1], z_axis[2], d)); #endif + hexa_drawer_rend_->set_clipping_plane(QVector4D(z_axis[0], z_axis[1], z_axis[2], d)); + } + + void set_apply_grid_clipping_plane(bool b) + { + apply_grid_clipping_plane_ = b; + if(apply_grid_clipping_plane_) + update_hexa_drawer(); + } + + void set_clipping_plane(int x, int y, int z) + { + clipping_x_ = x; + clipping_y_ = y; + clipping_z_ = z; + + hexa_drawer_rend_->set_clipping_plane_topo(QVector3D(clipping_x_, clipping_y_, clipping_z_)); + } + + void update_hexa_drawer() + { + if (position_vbo_) + { + const CMap3::VertexAttribute& pos_attr = mh_->map()->get_attribute(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; + } + + auto i_ = mh_->map()->get_attribute("i"); + auto j_ = mh_->map()->get_attribute("j"); + auto k_ = mh_->map()->get_attribute("k"); + + if(volume_attribute_.isEmpty()) + { + qreal r, g, b; + face_color_.getRgbF(&r, &g, &b); + cgogn::rendering::FakeAttribute fake_color(VEC3(r, g, b)); + hexa_drawer_->update_face(*mh_->map(),pos_attr, fake_color, i_, j_, k_); + hexa_drawer_->update_edge(*mh_->map(),pos_attr,i_, j_, k_); + } + else + { + QString color_attribute = volume_attribute_ + "_color"; + const CMap3::VolumeAttribute& color_attr = mh_->map()->get_attribute(color_attribute.toStdString()); + hexa_drawer_->update_face(*mh_->map(), pos_attr, color_attr, i_, j_, k_); + hexa_drawer_->update_edge(*mh_->map(), pos_attr, i_, j_, k_); + } + } } void update_topo_drawer() @@ -342,16 +404,23 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters } - if(mh_->filtered()) - { - //volume_drawer_color_->update_edge(*mh_->map(), *mh_->filter(), pos_attr); - volume_drawer_color_->update_face(*mh_->map(), *mh_->filter(), pos_attr, color_attr); - } - else - { - //volume_drawer_color_->update_edge(*mh_->map(), pos_attr); - volume_drawer_color_->update_face(*mh_->map(), pos_attr, color_attr); - } + if(apply_grid_clipping_plane_) + { + update_hexa_drawer(); + } + else + { + if(mh_->filtered()) + { + //volume_drawer_color_->update_edge(*mh_->map(), *mh_->filter(), pos_attr); + volume_drawer_color_->update_face(*mh_->map(), *mh_->filter(), pos_attr, color_attr); + } + else + { + //volume_drawer_color_->update_edge(*mh_->map(), pos_attr); + volume_drawer_color_->update_face(*mh_->map(), pos_attr, color_attr); + } + } } } @@ -372,9 +441,6 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters { QString color_attribute = volume_attribute_ + "_color"; - - std::cout << volume_attribute_.toStdString() << std::endl; - auto color_attr = mh_->map()->get_attribute(color_attribute.toStdString()); if(!color_attr.is_valid()) @@ -656,6 +722,12 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters frame_manip_ = cgogn::make_unique(); + hexa_drawer_ = cgogn::make_unique(); + hexa_drawer_rend_ = hexa_drawer_->generate_renderer(); + + hexa_drawer_rend_->set_explode_volume(volume_explode_factor_); + hexa_drawer_rend_->set_clipping_plane_topo(QVector3D(clipping_x_, clipping_y_, clipping_z_)); + set_position_vbo(position_vbo_); set_vertex_color(vertex_color_); set_edge_color(edge_color_); @@ -686,6 +758,9 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters std::unique_ptr volume_drawer_color_; std::unique_ptr volume_drawer_color_rend_; + std::unique_ptr hexa_drawer_; + std::unique_ptr hexa_drawer_rend_; + cgogn::rendering::VBO* position_vbo_; bool render_vertices_; bool render_edges_; @@ -693,6 +768,7 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters bool render_topology_; bool render_color_per_volumes_; bool apply_clipping_plane_; + bool apply_grid_clipping_plane_; bool clipping_plane_initialized_; QColor vertex_color_; QColor edge_color_; @@ -703,6 +779,10 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters bool use_transparency_; int32 transparency_factor_; + int32 clipping_x_; + int32 clipping_y_; + int32 clipping_z_; + QString volume_attribute_; cgogn::ColorMapType color_map_; }; diff --git a/schnapps/plugins/volume_render/volume_render.cpp b/schnapps/plugins/volume_render/volume_render.cpp index c0b3040..764eb29 100644 --- a/schnapps/plugins/volume_render/volume_render.cpp +++ b/schnapps/plugins/volume_render/volume_render.cpp @@ -65,6 +65,7 @@ MapParameters& Plugin_VolumeRender::parameters(View* view, CMap3Handler* mh) MapParameters& p = view_param_set[mh]; p.mh_ = mh; p.set_vertex_base_size(mh->bb_diagonal_size() / (2.0f * std::sqrt(mh->map()->nb_cells()))); + return p; } else @@ -165,16 +166,21 @@ void Plugin_VolumeRender::draw_object(View* view, Object *o, const QMatrix4x4& p if(p.render_color_per_volumes_) { 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_color_rend_->draw_faces(proj, mv); + p.set_volume_explode_factor(0.995f); + if(p.apply_grid_clipping_plane_) + p.hexa_drawer_rend_->draw_faces(proj, mv); + else if (!p.use_transparency_ && p.volume_drawer_rend_) + p.volume_drawer_color_rend_->draw_faces(proj, mv); } else { 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); + + if(p.apply_grid_clipping_plane_) + p.hexa_drawer_rend_->draw_faces(proj, mv); + else if (!p.use_transparency_ && p.volume_drawer_rend_) + p.volume_drawer_rend_->draw_faces(proj, mv); } } } @@ -574,6 +580,18 @@ void Plugin_VolumeRender::set_apply_clipping_plane(View* view, CMap3Handler* mh, } } +void Plugin_VolumeRender::set_apply_grid_clipping_plane(View* view, CMap3Handler* mh, bool b, bool update_dock_tab) +{ + if (view && view->is_linked_to_plugin(this) && mh && mh->is_linked_to_view(view)) + { + MapParameters& p = parameters(view, mh); + p.set_apply_grid_clipping_plane(b); + if (update_dock_tab && view->is_selected_view() && dock_tab_->selected_map() == mh) + dock_tab_->set_apply_grid_clipping_plane(b); + view->update(); + } +} + void Plugin_VolumeRender::set_vertex_color(View* view, CMap3Handler* mh, const QColor& color, bool update_dock_tab) { if (view && view->is_linked_to_plugin(this) && mh && mh->is_linked_to_view(view)) @@ -668,6 +686,18 @@ void Plugin_VolumeRender::set_transparency_factor(View* view, CMap3Handler* mh, } } +void Plugin_VolumeRender::set_grid_clipping_plane(View* view, CMap3Handler* mh, int32 x, int32 y, int32 z, bool update_dock_tab) +{ + if (view && view->is_linked_to_plugin(this) && mh && mh->is_linked_to_view(view)) + { + MapParameters& p = parameters(view, mh); + p.set_clipping_plane(x,y,z); + if (update_dock_tab && view->is_selected_view() && dock_tab_->selected_map() == mh) + dock_tab_->set_grid_clipping_plane(x,y,z); + view->update(); + } +} + } // 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 efaeba8..44da05b 100644 --- a/schnapps/plugins/volume_render/volume_render.h +++ b/schnapps/plugins/volume_render/volume_render.h @@ -122,6 +122,7 @@ public slots: void set_render_faces(View* view, CMap3Handler* mh, bool b, bool update_dock_tab); void set_render_topology(View* view, CMap3Handler* mh, bool b, bool update_dock_tab); void set_apply_clipping_plane(View* view, CMap3Handler* mh, bool b, bool update_dock_tab); + void set_apply_grid_clipping_plane(View* view, CMap3Handler* mh, bool b, bool update_dock_tab); void set_vertex_color(View* view, CMap3Handler* mh, const QColor& color, bool update_dock_tab); void set_edge_color(View* view, CMap3Handler* mh, const QColor& color, bool update_dock_tab); void set_face_color(View* view, CMap3Handler* mh, const QColor& color, bool update_dock_tab); @@ -130,6 +131,8 @@ public slots: void set_transparency_enabled(View* view, CMap3Handler* mh, bool b, bool update_dock_tab); void set_transparency_factor(View* view, CMap3Handler* mh, int32 tf, bool update_dock_tab); + void set_grid_clipping_plane(View* view, CMap3Handler* mh, int32 x, int32 y, int32 z, bool update_dock_tab); + private: VolumeRender_DockTab* dock_tab_; diff --git a/schnapps/plugins/volume_render/volume_render.ui b/schnapps/plugins/volume_render/volume_render.ui index 8e9a57a..3be1dd8 100644 --- a/schnapps/plugins/volume_render/volume_render.ui +++ b/schnapps/plugins/volume_render/volume_render.ui @@ -8,51 +8,20 @@ 0 0 330 - 916 + 1047 Form - - - - Qt::Horizontal + + + + use transparency - - - - - - Qt::Horizontal - - - - - - - Min - - - - - - - - - - Max - - - - - - - - @@ -68,50 +37,99 @@ - - + + + + true + - auto update min/max + clipping plane + + + false + + + false - - - - - 0 - 0 - + + + + render vertices - + + + + + + Qt::Horizontal + + + + + + + + + Z direction: + + + + + + + Qt::Horizontal + + + + + + + + + + + - 16777215 - 32 + 96 + 0 - Color + Position : - - - - - 0 - 0 - - - + + + + + + Y direction: + + + + + + + 1000 + + + Qt::Horizontal + + + + - - - - QAbstractItemView::SingleSelection + + + + Scalar: - + @@ -130,33 +148,45 @@ - - - - - 96 - 0 - - + + - Position : + render faces + + + true - - - - 254 - - - 127 - + + + + + Qt::Horizontal - + + + + + + X direction: + + + + + + + Qt::Horizontal + + + + + + 50 @@ -166,17 +196,50 @@ - + + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + + 16777215 + 32 + + + + Color + + + + render edges - - - - + @@ -209,15 +272,8 @@ - - - - use transparency - - - - + 0 @@ -235,91 +291,47 @@ - - - - true - + + - clipping plane - - - false + Colormap: - - + + - 10 - - - 1 - - - Qt::Horizontal - - - - - - - render faces - - - true + 254 - - - - - - render vertices + + 127 - - - - - - - Qt::Horizontal - - - - Expansion: + + + + QAbstractItemView::SingleSelection - + render topology - - - - Scalar: - - - - - + + - Colormap: + grid clipping plane - - - - - - Qt::Horizontal + + false diff --git a/schnapps/plugins/volume_render/volume_render_dock_tab.cpp b/schnapps/plugins/volume_render/volume_render_dock_tab.cpp index 2c3db7c..514a85b 100644 --- a/schnapps/plugins/volume_render/volume_render_dock_tab.cpp +++ b/schnapps/plugins/volume_render/volume_render_dock_tab.cpp @@ -54,6 +54,7 @@ VolumeRender_DockTab::VolumeRender_DockTab(SCHNApps* s, Plugin_VolumeRender* p) connect(check_renderFaces, SIGNAL(toggled(bool)), this, SLOT(render_faces_changed(bool))); 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(check_gridClippingPlane, SIGNAL(toggled(bool)), this, SLOT(apply_grid_clipping_plane_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))); @@ -65,6 +66,10 @@ 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())); + connect(slider_clippingPlaneX, SIGNAL(valueChanged(int)), this, SLOT(clipping_plane_x_changed(int))); + connect(slider_clippingPlaneY, SIGNAL(valueChanged(int)), this, SLOT(clipping_plane_y_changed(int))); + connect(slider_clippingPlaneZ, SIGNAL(valueChanged(int)), this, SLOT(clipping_plane_z_changed(int))); + check_useTransparency->setChecked(false); slider_transparency->setDisabled(true); #ifdef USE_TRANSPARENCY @@ -169,6 +174,12 @@ void VolumeRender_DockTab::apply_clipping_plane_changed(bool b) plugin_->set_apply_clipping_plane(schnapps_->selected_view(), selected_map_, b, false); } +void VolumeRender_DockTab::apply_grid_clipping_plane_changed(bool b) +{ + if (!updating_ui_ && selected_map_) + plugin_->set_apply_grid_clipping_plane(schnapps_->selected_view(), selected_map_, b, false); +} + void VolumeRender_DockTab::vertex_scale_factor_changed(int i) { if (!updating_ui_) @@ -200,6 +211,33 @@ void VolumeRender_DockTab::transparency_factor_changed(int n) #endif } +void VolumeRender_DockTab::clipping_plane_x_changed(int i) +{ + if (!updating_ui_) + plugin_->set_grid_clipping_plane(schnapps_->selected_view(), selected_map_, + i, + slider_clippingPlaneY->value(), + slider_clippingPlaneZ->value(), false); +} + +void VolumeRender_DockTab::clipping_plane_y_changed(int i) +{ + if (!updating_ui_) + plugin_->set_grid_clipping_plane(schnapps_->selected_view(), selected_map_, + slider_clippingPlaneX->value(), + i, + slider_clippingPlaneZ->value(), false); +} + +void VolumeRender_DockTab::clipping_plane_z_changed(int i) +{ + if (!updating_ui_) + plugin_->set_grid_clipping_plane(schnapps_->selected_view(), selected_map_, + slider_clippingPlaneX->value(), + slider_clippingPlaneY->value(), + i, false); +} + void VolumeRender_DockTab::selected_volume_scalar_changed() { QList currentItems = list_scalarAttribute->selectedItems(); @@ -377,7 +415,6 @@ void VolumeRender_DockTab::selected_map_vbo_removed(cgogn::rendering::VBO* vbo) void VolumeRender_DockTab::selected_map_attribute_added(cgogn::Orbit o, QString name) { updating_ui_ = true; - std::cout << name.toStdString() << std::endl; // if (o == CMap3::Vertex::ORBIT) // combo_positionAttribute->addItem(name); if (o == CMap3::Volume::ORBIT) @@ -455,6 +492,13 @@ void VolumeRender_DockTab::set_apply_clipping_plane(bool b) updating_ui_ = false; } +void VolumeRender_DockTab::set_apply_grid_clipping_plane(bool b) +{ + updating_ui_ = true; + check_gridClippingPlane->setChecked(b); + updating_ui_ = false; +} + void VolumeRender_DockTab::set_vertex_color(const QColor& color) { updating_ui_ = true; @@ -508,6 +552,15 @@ void VolumeRender_DockTab::set_transparency_factor(int tf) updating_ui_ = false; } +void VolumeRender_DockTab::set_grid_clipping_plane(int x, int y, int z) +{ + updating_ui_ = true; + slider_clippingPlaneX->setValue(x); + slider_clippingPlaneY->setValue(y); + slider_clippingPlaneZ->setValue(z); + updating_ui_ = false; +} + void VolumeRender_DockTab::refresh_ui() { CMap3Handler* mh = selected_map_; @@ -578,7 +631,43 @@ void VolumeRender_DockTab::refresh_ui() #endif check_clippingPlane->setChecked(p.apply_clipping_plane()); + check_clippingPlane->setChecked(p.apply_grid_clipping_plane()); + + auto i_ = mh->map()->get_attribute("i"); + auto j_ = mh->map()->get_attribute("j"); + auto k_ = mh->map()->get_attribute("k"); + slider_clippingPlaneX->setValue(0); + slider_clippingPlaneY->setValue(0); + slider_clippingPlaneZ->setValue(0); + + uint32 mx; + if(i_.is_valid()) + { + slider_clippingPlaneX->setEnabled(true); + mx = std::numeric_limits::lowest(); + for(auto el : i_) + mx = std::max(mx, el); + slider_clippingPlaneX->setRange(0, mx); + } + + if(j_.is_valid()) + { + slider_clippingPlaneY->setEnabled(true); + mx = std::numeric_limits::lowest(); + for(auto el : j_) + mx = std::max(mx, el); + slider_clippingPlaneY->setRange(0, mx); + } + + if(k_.is_valid()) + { + slider_clippingPlaneZ->setEnabled(true); + mx = std::numeric_limits::lowest(); + for(auto el : k_) + mx = std::max(mx, el); + slider_clippingPlaneZ->setRange(0, mx); + } 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 287d006..c782c44 100644 --- a/schnapps/plugins/volume_render/volume_render_dock_tab.h +++ b/schnapps/plugins/volume_render/volume_render_dock_tab.h @@ -93,11 +93,16 @@ private slots: void render_faces_changed(bool b); void render_topology_changed(bool b); void apply_clipping_plane_changed(bool b); + void apply_grid_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 clipping_plane_x_changed(int i); + void clipping_plane_y_changed(int i); + void clipping_plane_z_changed(int i); + void selected_volume_scalar_changed(); void color_map_changed(int i); void vertex_color_clicked(); @@ -132,6 +137,7 @@ private slots: void set_render_faces(bool b); void set_render_topology(bool b); void set_apply_clipping_plane(bool b); + void set_apply_grid_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); @@ -140,6 +146,8 @@ private slots: void set_transparency_enabled(bool b); void set_transparency_factor(int tf); + void set_grid_clipping_plane(int x, int y, int z); + CMap3Handler* selected_map() { return selected_map_; } void refresh_ui();