From 41702c944be33550264119a45b1132d8b0f8b871 Mon Sep 17 00:00:00 2001 From: ange-clement Date: Fri, 22 Sep 2023 16:05:50 +0200 Subject: [PATCH 01/13] Added clip box support for image items --- .../resources/no_interpolation_shader.frag | 10 ++++++++ .../resources/no_interpolation_shader.geom | 9 ++++++- .../resources/no_interpolation_shader.vert | 24 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Polyhedron/demo/Polyhedron/resources/no_interpolation_shader.frag b/Polyhedron/demo/Polyhedron/resources/no_interpolation_shader.frag index 904a0907c09..87d4736352e 100644 --- a/Polyhedron/demo/Polyhedron/resources/no_interpolation_shader.frag +++ b/Polyhedron/demo/Polyhedron/resources/no_interpolation_shader.frag @@ -7,6 +7,7 @@ in GS_OUT flat vec4 color[4]; vec2 uv; flat vec4 prob[4]; + float dist[6]; } fs_in; uniform bool is_two_side; @@ -15,11 +16,20 @@ uniform vec4 light_diff; uniform vec4 light_spec; uniform vec4 light_amb; uniform float spec_power ; +uniform bool is_clipbox_on; out vec4 out_color; void main(void) { + if(is_clipbox_on) + if(fs_in.dist[0]>0.0 || + fs_in.dist[1]>0.0 || + fs_in.dist[2]>0.0 || + fs_in.dist[3]>0.0 || + fs_in.dist[4]>0.0 || + fs_in.dist[5]>0.0) + discard; vec4 color; //find base color of pixel vec4 m1 = mix(fs_in.prob[0], fs_in.prob[1], fs_in.uv.y); diff --git a/Polyhedron/demo/Polyhedron/resources/no_interpolation_shader.geom b/Polyhedron/demo/Polyhedron/resources/no_interpolation_shader.geom index f1b664d07a9..663fe6c44a8 100644 --- a/Polyhedron/demo/Polyhedron/resources/no_interpolation_shader.geom +++ b/Polyhedron/demo/Polyhedron/resources/no_interpolation_shader.geom @@ -8,6 +8,7 @@ in VS_OUT vec4 fP; vec3 fN; vec4 out_color; + float dist[6]; } gs_in[4]; out GS_OUT @@ -17,6 +18,7 @@ out GS_OUT flat vec4 color[4]; vec2 uv; flat vec4 prob[4]; + float dist[6]; } gs_out; void main(void) @@ -25,19 +27,21 @@ void main(void) gs_out.fN = gs_in[0].fN; gs_out.fP = gs_in[0].fP; gs_out.uv = vec2(0.0, 0.0); - + gs_out.dist = gs_in[0].dist; EmitVertex(); gl_Position = gl_in[1].gl_Position; gs_out.fN = gs_in[1].fN; gs_out.fP = gs_in[1].fP; gs_out.uv = vec2(0.0, 1.0); + gs_out.dist = gs_in[1].dist; EmitVertex(); gl_Position = gl_in[3].gl_Position; gs_out.fN = gs_in[3].fN; gs_out.fP = gs_in[3].fP; gs_out.uv = vec2(1.0, 0.0); + gs_out.dist = gs_in[3].dist; // We're only writing the output color for the last // vertex here because they're flat attributes, @@ -67,18 +71,21 @@ void main(void) gs_out.fN = gs_in[1].fN; gs_out.fP = gs_in[1].fP; gs_out.uv = vec2(0.0, 1.0); + gs_out.dist = gs_in[1].dist; EmitVertex(); gl_Position = gl_in[2].gl_Position; gs_out.fN = gs_in[2].fN; gs_out.fP = gs_in[2].fP; gs_out.uv = vec2(1.0, 1.0); + gs_out.dist = gs_in[2].dist; EmitVertex(); gl_Position = gl_in[3].gl_Position; gs_out.fN = gs_in[3].fN; gs_out.fP = gs_in[3].fP; gs_out.uv = vec2(1.0, 0.0); + gs_out.dist = gs_in[3].dist; // Again, only write the output color for the last vertex gs_out.color[0] = gs_in[0].out_color; gs_out.color[1] = gs_in[1].out_color; diff --git a/Polyhedron/demo/Polyhedron/resources/no_interpolation_shader.vert b/Polyhedron/demo/Polyhedron/resources/no_interpolation_shader.vert index 727e4b07d9a..115e809f912 100644 --- a/Polyhedron/demo/Polyhedron/resources/no_interpolation_shader.vert +++ b/Polyhedron/demo/Polyhedron/resources/no_interpolation_shader.vert @@ -9,15 +9,39 @@ out VS_OUT vec4 fP; vec3 fN; vec4 out_color; + float dist[6]; }vs_out; uniform mat4 mvp_matrix; uniform mat4 mv_matrix; uniform mat4 norm_matrix; +uniform bool is_clipbox_on; +uniform mat4 clipbox1; +uniform mat4 clipbox2; + +void compute_distances(void) +{ + for(int i=0; i<3; ++i) + { + vs_out.dist[i]= + clipbox1[i][0]*vertex.x+ + clipbox1[i][1]*vertex.y+ + clipbox1[i][2]*vertex.z + + clipbox1[i][3]; + vs_out.dist[i+3]= + clipbox2[i][0]*vertex.x+ + clipbox2[i][1]*vertex.y+ + clipbox2[i][2]*vertex.z + + clipbox2[i][3]; + } +} + void main(void) { vs_out.out_color=colors; + if(is_clipbox_on) + compute_distances(); vs_out.fP = mv_matrix * vertex; vs_out.fN = mat3(norm_matrix)* normals; gl_Position = mvp_matrix * vertex; From 45f0c6665a29f2557545c1436731b45031d20dad Mon Sep 17 00:00:00 2001 From: ange-clement Date: Mon, 25 Sep 2023 10:50:29 +0200 Subject: [PATCH 02/13] Added clip support for tetrahedral meshes --- .../Polyhedron/resources/shader_c3t3.frag | 29 +++++++++++++++---- .../Polyhedron/resources/shader_c3t3.vert | 24 +++++++++++++++ .../resources/shader_c3t3_edges.frag | 10 +++++++ .../resources/shader_c3t3_edges.vert | 24 +++++++++++++++ 4 files changed, 82 insertions(+), 5 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/resources/shader_c3t3.frag b/Polyhedron/demo/Polyhedron/resources/shader_c3t3.frag index 27b255c5e1c..9408f3d5932 100644 --- a/Polyhedron/demo/Polyhedron/resources/shader_c3t3.frag +++ b/Polyhedron/demo/Polyhedron/resources/shader_c3t3.frag @@ -2,6 +2,7 @@ in vec4 color; in vec4 fP; in vec3 fN; +in float dist[6]; flat in vec2 subdomain_out; uniform vec4 light_pos; uniform vec4 light_diff; @@ -10,6 +11,7 @@ uniform vec4 light_amb; uniform float spec_power ; uniform int is_two_side; uniform bool is_selected; +uniform bool is_clipbox_on; uniform float near; uniform float far; uniform float width; @@ -28,7 +30,19 @@ float depth(float z) return (2 * near) / (far + near - z * (far - near)); } -void main(void) { +bool compute_clip_visibility() { + if(is_clipbox_on) + return dist[0]>0.0 || + dist[1]>0.0 || + dist[2]>0.0 || + dist[3]>0.0 || + dist[4]>0.0 || + dist[5]>0.0; + else + return false; +} + +bool compute_filtering_visibility() { if(is_filterable) { uint domain1 = uint(subdomain_out.x); @@ -37,10 +51,15 @@ void main(void) { uint i2 = domain2/25u; uint visible1 = uint(is_visible_bitset[i1]); uint visible2 = uint(is_visible_bitset[i2]); - if((visible1>>(domain1%25u))%2u == 0u && (visible2>>(domain2%25u))%2u == 0u) - { - discard; - } + return (visible1>>(domain1%25u))%2u == 0u && (visible2>>(domain2%25u))%2u == 0u; + } + else + return false; +} + +void main(void) { + if (compute_clip_visibility() || compute_filtering_visibility()) { + discard; } float d = depth(gl_FragCoord.z); float test = texture(sampler, vec2(gl_FragCoord.x/width, gl_FragCoord.y/height)).r; diff --git a/Polyhedron/demo/Polyhedron/resources/shader_c3t3.vert b/Polyhedron/demo/Polyhedron/resources/shader_c3t3.vert index 2298a14b15c..b7677129d66 100644 --- a/Polyhedron/demo/Polyhedron/resources/shader_c3t3.vert +++ b/Polyhedron/demo/Polyhedron/resources/shader_c3t3.vert @@ -12,13 +12,37 @@ uniform float shrink_factor; out vec4 fP; out vec3 fN; out vec4 color; +out float dist[6]; flat out vec2 subdomain_out; +uniform bool is_clipbox_on; +uniform mat4 clipbox1; +uniform mat4 clipbox2; uniform float point_size; + +void compute_distances(void) +{ + for(int i=0; i<3; ++i) + { + dist[i]= + clipbox1[i][0]*vertex.x+ + clipbox1[i][1]*vertex.y+ + clipbox1[i][2]*vertex.z + + clipbox1[i][3]; + dist[i+3]= + clipbox2[i][0]*vertex.x+ + clipbox2[i][1]*vertex.y+ + clipbox2[i][2]*vertex.z + + clipbox2[i][3]; + } +} + void main(void) { subdomain_out = subdomain_in; gl_PointSize = point_size; color = vec4(colors, vertex.x * cutplane.x + vertex.y * cutplane.y + vertex.z * cutplane.z + cutplane.w); + if(is_clipbox_on) + compute_distances(); fP = mv_matrix * vertex; mat3 norm_matrix_3; diff --git a/Polyhedron/demo/Polyhedron/resources/shader_c3t3_edges.frag b/Polyhedron/demo/Polyhedron/resources/shader_c3t3_edges.frag index c3fbb6bba00..d15d6e12512 100644 --- a/Polyhedron/demo/Polyhedron/resources/shader_c3t3_edges.frag +++ b/Polyhedron/demo/Polyhedron/resources/shader_c3t3_edges.frag @@ -1,12 +1,22 @@ #version 150 in vec4 color; +in float dist[6]; flat in vec2 subdomain_out; +uniform bool is_clipbox_on; uniform bool is_surface; uniform vec4 is_visible_bitset; uniform bool is_filterable; out vec4 out_color; void main(void) { + if(is_clipbox_on) + if(dist[0]>0.0 || + dist[1]>0.0 || + dist[2]>0.0 || + dist[3]>0.0 || + dist[4]>0.0 || + dist[5]>0.0) + discard; if(is_filterable) { uint domain1 = uint(subdomain_out.x); diff --git a/Polyhedron/demo/Polyhedron/resources/shader_c3t3_edges.vert b/Polyhedron/demo/Polyhedron/resources/shader_c3t3_edges.vert index 9d00649a829..60f51ff758a 100644 --- a/Polyhedron/demo/Polyhedron/resources/shader_c3t3_edges.vert +++ b/Polyhedron/demo/Polyhedron/resources/shader_c3t3_edges.vert @@ -5,12 +5,36 @@ in vec2 subdomain_in; uniform mat4 mvp_matrix; uniform vec4 cutplane; out vec4 color; +out float dist[6]; uniform float point_size; flat out vec2 subdomain_out; +uniform bool is_clipbox_on; +uniform mat4 clipbox1; +uniform mat4 clipbox2; + +void compute_distances(void) +{ + for(int i=0; i<3; ++i) + { + dist[i]= + clipbox1[i][0]*vertex.x+ + clipbox1[i][1]*vertex.y+ + clipbox1[i][2]*vertex.z + + clipbox1[i][3]; + dist[i+3]= + clipbox2[i][0]*vertex.x+ + clipbox2[i][1]*vertex.y+ + clipbox2[i][2]*vertex.z + + clipbox2[i][3]; + } +} + void main(void) { subdomain_out = subdomain_in; gl_PointSize = point_size; color = vec4(colors, vertex.x * cutplane.x + vertex.y * cutplane.y + vertex.z * cutplane.z + cutplane.w); + if(is_clipbox_on) + compute_distances(); gl_Position = mvp_matrix * vertex; } From eb5c2816d500d99ebc2974f255cce82e50a153fc Mon Sep 17 00:00:00 2001 From: ange-clement Date: Mon, 25 Sep 2023 11:55:28 +0200 Subject: [PATCH 03/13] Adapted clip button to a toggle behaviour --- .../Plugins/PCA/Clipping_box_plugin.cpp | 52 +++++++++++++++++-- .../demo/Polyhedron/Scene_image_item.cpp | 1 + 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp index 062e993b175..9753e4e2f11 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp @@ -64,10 +64,14 @@ public Q_SLOTS: void tab_change(); private: bool eventFilter(QObject *, QEvent *); + bool process_event_clip_box(QEvent *); + bool process_event_clip_orthographic(QEvent *); + void do_clip(bool); QAction* actionClipbox; ClipWidget* dock_widget; Scene_edit_box_item* item; bool shift_pressing; + bool clipping; Selection_visualizer* visualizer; }; // end Clipping_box_plugin @@ -96,6 +100,7 @@ void Clipping_box_plugin::init(QMainWindow* mainWindow, CGAL::Three::Scene_inter this, SLOT(connectNewViewer(QObject*))); visualizer = nullptr; shift_pressing = false; + clipping = false; } void Clipping_box_plugin::clipbox() @@ -148,6 +153,25 @@ void Clipping_box_plugin::enableAction() { } void Clipping_box_plugin::clip(bool b) +{ + clipping = b; + if (b) + { + Q_FOREACH(CGAL::QGLViewer* v, CGAL::QGLViewer::QGLViewerPool()) + { + v->installEventFilter(this); + } + } + else { + Q_FOREACH(CGAL::QGLViewer* v, CGAL::QGLViewer::QGLViewerPool()) + { + v->removeEventFilter(this); + } + } + do_clip(b); +} + +void Clipping_box_plugin::do_clip(bool b) { typedef CGAL::Epick Kernel; typedef CGAL::Polyhedron_3 Mesh; @@ -231,12 +255,20 @@ void Clipping_box_plugin::tab_change() } -bool Clipping_box_plugin::eventFilter(QObject *, QEvent *event) { - static QImage background; - if (dock_widget->isHidden() || !(dock_widget->isActiveWindow()) || dock_widget->tabWidget->currentIndex() != 1 - || (dock_widget->tabWidget->currentIndex() == 1 && !dock_widget->clipButton->isChecked())) +bool Clipping_box_plugin::process_event_clip_box(QEvent *event) +{ + if (event->type() == QEvent::MouseButtonRelease) + { +// item->itemChanged(); + do_clip(clipping); return false; + } + return false; +} +bool Clipping_box_plugin::process_event_clip_orthographic(QEvent *event) +{ + static QImage background; if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) { QKeyEvent *keyEvent = static_cast(event); @@ -359,4 +391,16 @@ bool Clipping_box_plugin::eventFilter(QObject *, QEvent *event) { } return false; } + +bool Clipping_box_plugin::eventFilter(QObject *, QEvent *event) { + if (dock_widget->isHidden() || !dock_widget->isActiveWindow()) + return false; + if (dock_widget->tabWidget->currentIndex() == 0 && dock_widget->pushButton->isChecked()) + return process_event_clip_box(event); + else if (dock_widget->tabWidget->currentIndex() == 1 && dock_widget->clipButton->isChecked()) + return process_event_clip_orthographic(event); + else + return false; + +} #include "Clipping_box_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene_image_item.cpp b/Polyhedron/demo/Polyhedron/Scene_image_item.cpp index bdcf80a5091..c5770c8adab 100644 --- a/Polyhedron/demo/Polyhedron/Scene_image_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_image_item.cpp @@ -756,6 +756,7 @@ void Scene_image_item::drawEdges(Viewer_interface *viewer) const getEdgeContainer(0)->setWidth(3.0f); } getEdgeContainer(0)->setColor(QColor(Qt::black)); + getEdgeContainer(0)->setClipping(false); viewer->glDepthRangef(0.00001f, 0.99999f); getEdgeContainer(0)->draw(viewer, true); viewer->glDepthRangef(0.0f, 1.0f); From 0c090b80e2fab579cec0fc116edcd9797c3fc459 Mon Sep 17 00:00:00 2001 From: ange-clement Date: Mon, 25 Sep 2023 17:13:56 +0200 Subject: [PATCH 04/13] Disabled tetrahedra clip plane when clipping box is active --- .../Polyhedron/Scene_triangulation_3_item.cpp | 100 +++++++++++++++++- .../Polyhedron/Scene_triangulation_3_item.h | 4 + 2 files changed, 100 insertions(+), 4 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp b/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp index 91e88fb6ae2..84f6daae430 100644 --- a/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp @@ -1,7 +1,9 @@ +#include "Scene.h" #include "config.h" #include "Scene_triangulation_3_item.h" #include "Scene_surface_mesh_item.h" #include "Scene_spheres_item.h" +#include "Plugins/PCA/Scene_edit_box_item.h" #include #include @@ -20,6 +22,7 @@ #include #include +#include #include #include #include @@ -179,7 +182,15 @@ public : QVector4D cp = cgal_plane_to_vector4d(plane); getEdgeContainer(0)->setPlane(cp); getEdgeContainer(0)->setColor(QColor(Qt::black)); - getEdgeContainer(0)->draw(viewer, true); + if (!cut_edges) { + bool clipping = getEdgeContainer(0)->getClipping(); + getEdgeContainer(0)->setClipping(false); + getEdgeContainer(0)->draw(viewer, true); + getEdgeContainer(0)->setClipping(clipping); + } + else { + getEdgeContainer(0)->draw(viewer, true); + } } @@ -278,6 +289,10 @@ public : m_alpha = a / 255.0f; redraw(); } + void setCutEdges(bool b) + { + cut_edges = b; + } private: //contains the data @@ -290,6 +305,8 @@ private: mutable bool is_fast; mutable QSlider* alphaSlider; mutable float m_alpha ; + + bool cut_edges; }; //end of class Scene_triangle_item @@ -436,6 +453,25 @@ struct Scene_triangulation_3_item_priv { Scene_spheres_item *spheres; std::vector tr_vertices; Scene_intersection_item *intersection; + void set_intersection_enabled(bool b) + { + if (intersection) + intersection->setVisible(b); + } + bool is_intersection_enabled() + { + if (intersection) + return intersection->visible(); + else + return false; + } + bool is_item_clip_box(int id) + { + if(dynamic_cast(CGAL::Three::Three::scene()->item(id))) + return true; + else + return false; + } bool spheres_are_shown; const Scene_item* data_item_; QPixmap histogram_; @@ -497,6 +533,7 @@ struct Scene_triangulation_3_item_priv { bool show_tetrahedra; bool is_aabb_tree_built; bool last_intersection; + bool cut_edges; void push_normal(std::vector& normals, const EPICK::Vector_3& n) const { @@ -550,6 +587,14 @@ void Scene_triangulation_3_item::common_constructor(bool display_elements) { v->installEventFilter(this); } + for(int i = 0, end = scene->numberOfEntries(); + i < end; ++i) + { + if (d->is_item_clip_box(i)) + d->set_intersection_enabled(false); + } + connect(static_cast(CGAL::Three::Three::scene()), SIGNAL(newItem(int)), this, SLOT(check_new_item(int))); + connect(static_cast(CGAL::Three::Three::scene()), SIGNAL(indexErased(Scene_interface::Item_id)), this, SLOT(check_deleted_item(Scene_interface::Item_id))); } Scene_triangulation_3_item::Scene_triangulation_3_item(bool display_elements) : Scene_group_item("unnamed") @@ -602,6 +647,20 @@ Scene_triangulation_3_item::data_item_destroyed() set_data_item(NULL); } +void +Scene_triangulation_3_item::check_new_item(int id) +{ + if (d->is_item_clip_box(id)) + d->set_intersection_enabled(false); +} + +void +Scene_triangulation_3_item::check_deleted_item(Scene_interface::Item_id id) +{ + if (d->is_item_clip_box(id)) + d->set_intersection_enabled(true); +} + const T3& Scene_triangulation_3_item::triangulation() const { return d->triangulation; @@ -913,6 +972,8 @@ Scene_triangulation_3_item_priv::compute_color_map(const QColor& c) Geom_traits::Plane_3 Scene_triangulation_3_item::plane(CGAL::qglviewer::Vec offset) const { + if (!d->is_intersection_enabled()) + return Geom_traits::Plane_3(1.0, 0.0, 0.0, std::numeric_limits::max()); const CGAL::qglviewer::Vec& pos = d->frame->position() - offset; const CGAL::qglviewer::Vec& n = d->frame->inverseTransformOf(CGAL::qglviewer::Vec(0.f, 0.f, 1.f)); @@ -1018,7 +1079,7 @@ void Scene_triangulation_3_item::draw(CGAL::Three::Viewer_interface* viewer) con d->spheres->setPlane(this->plane()); } } - if(d->is_grid_shown) + if(d->is_grid_shown && d->is_intersection_enabled()) { getEdgeContainer(Grid_edges)->setColor(QColor(Qt::black)); @@ -1026,7 +1087,11 @@ void Scene_triangulation_3_item::draw(CGAL::Three::Viewer_interface* viewer) con for (int i = 0; i<16; i++) f_mat.data()[i] = static_cast(d->frame->matrix()[i]); getEdgeContainer(Grid_edges)->setFrameMatrix(f_mat); + // always draw plane (disable clipping) + bool clipping = getEdgeContainer(Grid_edges)->getClipping(); + getEdgeContainer(Grid_edges)->setClipping(false); getEdgeContainer(Grid_edges)->draw(viewer, true); + getEdgeContainer(Grid_edges)->setClipping(clipping); } } @@ -1056,14 +1121,18 @@ void Scene_triangulation_3_item::drawEdges(CGAL::Three::Viewer_interface* viewer computeElements(); initializeBuffers(viewer); } - if(renderingMode() == Wireframe && d->is_grid_shown) + if(renderingMode() == Wireframe && d->is_grid_shown && d->is_intersection_enabled()) { getEdgeContainer(Grid_edges)->setColor(QColor(Qt::black)); QMatrix4x4 f_mat; for (int i = 0; i<16; i++) f_mat.data()[i] = static_cast(d->frame->matrix()[i]); getEdgeContainer(Grid_edges)->setFrameMatrix(f_mat); + // always draw plane (disable clipping) + bool clipping = getEdgeContainer(Grid_edges)->getClipping(); + getEdgeContainer(Grid_edges)->setClipping(false); getEdgeContainer(Grid_edges)->draw(viewer, true); + getEdgeContainer(Grid_edges)->setClipping(clipping); } QVector4D cp = cgal_plane_to_vector4d(this->plane()); @@ -1079,7 +1148,15 @@ void Scene_triangulation_3_item::drawEdges(CGAL::Three::Viewer_interface* viewer getEdgeContainer(T3_edges)->setPlane(cp); getEdgeContainer(T3_edges)->setIsSurface(is_surface()); getEdgeContainer(T3_edges)->setColor(QColor(Qt::black)); - getEdgeContainer(T3_edges)->draw(viewer, true); + if (!d->cut_edges) { + bool clipping = getEdgeContainer(T3_edges)->getClipping(); + getEdgeContainer(T3_edges)->setClipping(false); + getEdgeContainer(T3_edges)->draw(viewer, true); + getEdgeContainer(T3_edges)->setClipping(clipping); + } + else { + getEdgeContainer(T3_edges)->draw(viewer, true); + } if(d->show_tetrahedra){ if(!d->frame->isManipulated()) @@ -1217,6 +1294,14 @@ QMenu* Scene_triangulation_3_item::contextMenu() this, SLOT(show_spheres(bool))); } + QAction* actionToggleCutEdges = + menu->addAction(tr("Cut &edges")); + actionToggleCutEdges->setCheckable(true); + actionToggleCutEdges->setChecked(true); + actionToggleCutEdges->setObjectName("actionToggleCutEdges"); + connect(actionToggleCutEdges, SIGNAL(toggled(bool)), + this, SLOT(set_cut_edge(bool))); + menu->setProperty(prop_name, true); } return menu; @@ -2081,5 +2166,12 @@ void Scene_triangulation_3_item::computeIntersection() } } +void Scene_triangulation_3_item::set_cut_edge(bool b) +{ + d->cut_edges = b; + d->intersection->setCutEdges(b); + Q_EMIT redraw(); +} + #include "Scene_triangulation_3_item.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.h b/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.h index 8cd2b81bd12..33a2cd8f124 100644 --- a/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.h @@ -121,6 +121,9 @@ public: void data_item_destroyed(); + void check_new_item(int id); + void check_deleted_item(Scene_interface::Item_id id); + void reset_spheres(); void reset_intersection_item(); @@ -128,6 +131,7 @@ public: void show_grid(bool b); void show_spheres(bool b); void computeIntersection(); + void set_cut_edge(bool b); virtual QPixmap graphicalToolTip() const Q_DECL_OVERRIDE; From c5b2d4d00bfc1f11001f3a42aea122e4c3f02e45 Mon Sep 17 00:00:00 2001 From: ange-clement Date: Tue, 26 Sep 2023 10:12:22 +0200 Subject: [PATCH 05/13] Added reset button on clip box --- .../Plugins/PCA/Clipping_box_plugin.cpp | 6 +++ .../Plugins/PCA/Clipping_box_widget.ui | 37 +++++++++++++++++++ .../Plugins/PCA/Scene_edit_box_item.cpp | 21 +++++++++++ .../Plugins/PCA/Scene_edit_box_item.h | 1 + 4 files changed, 65 insertions(+) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp index 9753e4e2f11..251c461dd13 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp @@ -135,6 +135,12 @@ void Clipping_box_plugin::clipbox() }); connect(dock_widget->tabWidget, &QTabWidget::currentChanged, this, &Clipping_box_plugin::tab_change); + connect(dock_widget->resetButton, &QPushButton::clicked, + this, [this]() + { + item->reset(); + do_clip(true); + }); item->setName("Clipping box"); item->setRenderingMode(FlatPlusEdges); diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_widget.ui b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_widget.ui index 7c79e142124..e0a2709e2fa 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_widget.ui +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_widget.ui @@ -65,6 +65,43 @@ + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Reset + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp b/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp index 6dea656ae70..cca910c3776 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp @@ -251,6 +251,22 @@ struct Scene_edit_box_item_priv{ double applyX(int id, double x, double dirx); double applyY(int id, double y, double diry); double applyZ(int id, double z, double dirz); + void reset_vertices() + { + Scene_item::Bbox bb = scene->bbox(); + float eps = 1.e-6; + pool[0] = bb.xmin()-eps; pool[3] = bb.xmax()+eps; + pool[1] = bb.ymin()-eps; pool[4] = bb.ymax()+eps; + pool[2] = bb.zmin()-eps; pool[5] = bb.zmax()+eps; + double x=(bb.xmin()+bb.xmax())/2; + double y=(bb.ymin()+bb.ymax())/2; + double z=(bb.zmin()+bb.zmax())/2; + center_ = CGAL::qglviewer::Vec(x,y,z); + relative_center_ = CGAL::qglviewer::Vec(0,0,0); + const CGAL::qglviewer::Vec offset = static_cast(CGAL::QGLViewer::QGLViewerPool().first())->offset(); + frame->setPosition(center_+offset); + item->invalidateOpenGLBuffers(); + } const Scene_interface* scene; Scene_edit_box_item* item; QPoint picked_pixel; @@ -1307,3 +1323,8 @@ void Scene_edit_box_item::connectNewViewer(QObject *o) return; viewer->setMouseTracking(true); } + +void Scene_edit_box_item::reset() +{ + d->reset_vertices(); +} diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.h b/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.h index 4b95cc4fe73..4d898895565 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.h +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.h @@ -59,6 +59,7 @@ public Q_SLOTS: void highlight(CGAL::Three::Viewer_interface* viewer); void clearHL(); void connectNewViewer(QObject* o); + void reset(); protected: friend struct Scene_edit_box_item_priv; Scene_edit_box_item_priv* d; From 384e7fad3865710adbc8af4ecc9910fab86d7799 Mon Sep 17 00:00:00 2001 From: ange-clement Date: Tue, 26 Sep 2023 10:16:17 +0200 Subject: [PATCH 06/13] Added epsilon on clipping + try fix test undefined reference to Scene_edit_box_item --- .../demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp | 9 +++++---- .../demo/Polyhedron/Scene_triangulation_3_item.cpp | 1 - Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.h | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp b/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp index cca910c3776..91bcde149ba 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp @@ -99,9 +99,10 @@ struct Scene_edit_box_item_priv{ constraint.setRotationConstraintDirection(CGAL::qglviewer::Vec(.0,.0,.1)); frame->setConstraint(&constraint); //create the sphere model - pool[0] = bb.xmin(); pool[3] = bb.xmax(); - pool[1] = bb.ymin(); pool[4] = bb.ymax(); - pool[2] = bb.zmin(); pool[5] = bb.zmax(); + float eps = 1.e-3; + pool[0] = bb.xmin()-eps; pool[3] = bb.xmax()+eps; + pool[1] = bb.ymin()-eps; pool[4] = bb.ymax()+eps; + pool[2] = bb.zmin()-eps; pool[5] = bb.zmax()+eps; vertex_spheres.resize(0); normal_spheres.resize(0); @@ -254,7 +255,7 @@ struct Scene_edit_box_item_priv{ void reset_vertices() { Scene_item::Bbox bb = scene->bbox(); - float eps = 1.e-6; + float eps = 1.e-3; pool[0] = bb.xmin()-eps; pool[3] = bb.xmax()+eps; pool[1] = bb.ymin()-eps; pool[4] = bb.ymax()+eps; pool[2] = bb.zmin()-eps; pool[5] = bb.zmax()+eps; diff --git a/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp b/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp index 84f6daae430..7eee6f9c094 100644 --- a/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp @@ -3,7 +3,6 @@ #include "Scene_triangulation_3_item.h" #include "Scene_surface_mesh_item.h" #include "Scene_spheres_item.h" -#include "Plugins/PCA/Scene_edit_box_item.h" #include #include diff --git a/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.h b/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.h index 33a2cd8f124..89f0e38d3d9 100644 --- a/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.h @@ -2,6 +2,7 @@ #define SCENE_TRIANGULATION_3_ITEM_H #include "Scene_triangulation_3_item_config.h" +#include "Plugins/PCA/Scene_edit_box_item.h" #include "T3_type.h" #include From aa125fe1db50094568a95beb2026f780660cb4bb Mon Sep 17 00:00:00 2001 From: ange-clement Date: Tue, 26 Sep 2023 10:48:21 +0200 Subject: [PATCH 07/13] Quick fix : Made images draw surfaces even if they are inside --- Polyhedron/demo/Polyhedron/Scene_image_item.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Scene_image_item.cpp b/Polyhedron/demo/Polyhedron/Scene_image_item.cpp index bdcf80a5091..3a2847dfba9 100644 --- a/Polyhedron/demo/Polyhedron/Scene_image_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_image_item.cpp @@ -114,15 +114,7 @@ is_vertex_active(std::size_t i, std::size_t j, std::size_t k) const Word_type v7 = image_data(i , j , k-dz_); Word_type v8 = image_data(i , j , k ); - // don't draw interior vertices - if ( v1 != 0 && v2 != 0 && v3 != 0 && v4 != 0 && - v5 != 0 && v6 != 0 && v7 != 0 && v8 != 0 ) - { - return false; - } - - return ( v1 != 0 || v2 != 0 || v3 != 0 || v4 != 0 || - v5 != 0 || v6 != 0 || v7 != 0 || v8 != 0 ); + return v1 != v2 || v1 != v3 || v1 != v4 || v1 != v5 || v1 != v6 || v1 != v7 || v1 != v8; } template const QColor& From c8545e8f0605a82574810009082c809211a033e2 Mon Sep 17 00:00:00 2001 From: ange-clement Date: Tue, 26 Sep 2023 12:14:52 +0200 Subject: [PATCH 08/13] Add link to scene_edit_box_item + small fix of triangulation_3 cut plane --- Polyhedron/demo/Polyhedron/CMakeLists.txt | 2 +- Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp | 8 ++++---- Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.h | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/CMakeLists.txt b/Polyhedron/demo/Polyhedron/CMakeLists.txt index 325a670e809..ecab2ece7fd 100644 --- a/Polyhedron/demo/Polyhedron/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/CMakeLists.txt @@ -236,7 +236,7 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND) add_item(scene_c3t3_item Scene_c3t3_item.cpp) target_link_libraries( scene_c3t3_item PUBLIC scene_triangulation_3_item - scene_surface_mesh_item scene_polygon_soup_item + scene_surface_mesh_item scene_polygon_soup_item scene_edit_box_item scene_basic_objects ${TBB_LIBRARIES}) if(TARGET CGAL::TBB_support) diff --git a/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp b/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp index 7eee6f9c094..04d0d44c58e 100644 --- a/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp @@ -3,6 +3,7 @@ #include "Scene_triangulation_3_item.h" #include "Scene_surface_mesh_item.h" #include "Scene_spheres_item.h" +#include "Plugins/PCA/Scene_edit_box_item.h" #include #include @@ -456,13 +457,11 @@ struct Scene_triangulation_3_item_priv { { if (intersection) intersection->setVisible(b); + cut_plane_enabled = b; } bool is_intersection_enabled() { - if (intersection) - return intersection->visible(); - else - return false; + return cut_plane_enabled; } bool is_item_clip_box(int id) { @@ -530,6 +529,7 @@ struct Scene_triangulation_3_item_priv { boost::dynamic_bitset<> visible_subdomain; std::bitset<24> bs[4] = {16777215, 16777215, 16777215, 16777215}; bool show_tetrahedra; + bool cut_plane_enabled; bool is_aabb_tree_built; bool last_intersection; bool cut_edges; diff --git a/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.h b/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.h index 89f0e38d3d9..33a2cd8f124 100644 --- a/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.h @@ -2,7 +2,6 @@ #define SCENE_TRIANGULATION_3_ITEM_H #include "Scene_triangulation_3_item_config.h" -#include "Plugins/PCA/Scene_edit_box_item.h" #include "T3_type.h" #include From 031594e0db5a22777728a103708455a28245360c Mon Sep 17 00:00:00 2001 From: ange-clement Date: Tue, 26 Sep 2023 12:23:52 +0200 Subject: [PATCH 09/13] Replaced Q_FOREACH with c++11 for each --- .../demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp index 251c461dd13..a2dd4f79139 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp @@ -163,13 +163,13 @@ void Clipping_box_plugin::clip(bool b) clipping = b; if (b) { - Q_FOREACH(CGAL::QGLViewer* v, CGAL::QGLViewer::QGLViewerPool()) + for(CGAL::QGLViewer* v : CGAL::QGLViewer::QGLViewerPool()) { v->installEventFilter(this); } } else { - Q_FOREACH(CGAL::QGLViewer* v, CGAL::QGLViewer::QGLViewerPool()) + for(CGAL::QGLViewer* v : CGAL::QGLViewer::QGLViewerPool()) { v->removeEventFilter(this); } From 98ba8b68e3c1e4487a6ae0f6dd7d9ee7202e4cbd Mon Sep 17 00:00:00 2001 From: ange-clement Date: Tue, 26 Sep 2023 12:38:34 +0200 Subject: [PATCH 10/13] Fix wrong linkage --- Polyhedron/demo/Polyhedron/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/CMakeLists.txt b/Polyhedron/demo/Polyhedron/CMakeLists.txt index ecab2ece7fd..85c60468859 100644 --- a/Polyhedron/demo/Polyhedron/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/CMakeLists.txt @@ -231,12 +231,12 @@ if(CGAL_Qt5_FOUND AND Qt5_FOUND) endmacro(add_item) add_item(scene_triangulation_3_item Scene_triangulation_3_item.cpp) - target_link_libraries(scene_triangulation_3_item PUBLIC scene_basic_objects) + target_link_libraries(scene_triangulation_3_item PUBLIC scene_basic_objects scene_edit_box_item) add_item(scene_c3t3_item Scene_c3t3_item.cpp) target_link_libraries( scene_c3t3_item PUBLIC scene_triangulation_3_item - scene_surface_mesh_item scene_polygon_soup_item scene_edit_box_item + scene_surface_mesh_item scene_polygon_soup_item scene_basic_objects ${TBB_LIBRARIES}) if(TARGET CGAL::TBB_support) From 92cb998499571334451c7b6483e8d06f9d819d3d Mon Sep 17 00:00:00 2001 From: ange-clement Date: Mon, 2 Oct 2023 13:16:28 +0200 Subject: [PATCH 11/13] Diabled "Alpha slider" on edit box --- .../Plugins/PCA/Scene_edit_box_item.cpp | 15 +++++++++++++++ .../Polyhedron/Plugins/PCA/Scene_edit_box_item.h | 1 + 2 files changed, 16 insertions(+) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp b/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp index 91bcde149ba..b007fc61282 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp @@ -281,6 +281,7 @@ struct Scene_edit_box_item_priv{ Scene_edit_box_item::Scene_edit_box_item() { d = nullptr; + contextMenu(); } Scene_edit_box_item::Scene_edit_box_item(const Scene_interface *scene_interface) { @@ -311,12 +312,26 @@ Scene_edit_box_item::Scene_edit_box_item(const Scene_interface *scene_interface) : Vi::PROGRAM_NO_SELECTION, false)); } + contextMenu(); } QString Scene_edit_box_item::toolTip() const { return QString(); } + +QMenu* Scene_edit_box_item::contextMenu() +{ + // diasable "Alpha slider" in menu + QMenu* resMenu = Scene_item::contextMenu(); + bool prop = property("menu_changed").toBool(); + if(!prop) + { + setProperty("menu_changed", true); + } + return resMenu; +} + void Scene_edit_box_item::drawSpheres(Viewer_interface *viewer, const QMatrix4x4 f_matrix ) const { GLdouble d_mat[16]; diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.h b/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.h index 4d898895565..0d99b9ce08e 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.h +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.h @@ -33,6 +33,7 @@ class SCENE_EDIT_BOX_ITEM_EXPORT Scene_edit_box_item: } QString toolTip() const; + QMenu* contextMenu(); bool eventFilter(QObject *, QEvent *); // Indicate if rendering mode is supported From 857de8b11082f463b3f9a46fd80a52150872738f Mon Sep 17 00:00:00 2001 From: ange-clement Date: Wed, 4 Oct 2023 11:21:02 +0200 Subject: [PATCH 12/13] Fixed warning --- .../demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp b/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp index b007fc61282..78493723e31 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp @@ -99,7 +99,7 @@ struct Scene_edit_box_item_priv{ constraint.setRotationConstraintDirection(CGAL::qglviewer::Vec(.0,.0,.1)); frame->setConstraint(&constraint); //create the sphere model - float eps = 1.e-3; + double eps = 1.e-3; pool[0] = bb.xmin()-eps; pool[3] = bb.xmax()+eps; pool[1] = bb.ymin()-eps; pool[4] = bb.ymax()+eps; pool[2] = bb.zmin()-eps; pool[5] = bb.zmax()+eps; @@ -255,7 +255,7 @@ struct Scene_edit_box_item_priv{ void reset_vertices() { Scene_item::Bbox bb = scene->bbox(); - float eps = 1.e-3; + double eps = 1.e-3; pool[0] = bb.xmin()-eps; pool[3] = bb.xmax()+eps; pool[1] = bb.ymin()-eps; pool[4] = bb.ymax()+eps; pool[2] = bb.zmin()-eps; pool[5] = bb.zmax()+eps; From a5d44aa80888df5450faf1f8b7c5a7e6e8efd9b4 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 6 Oct 2023 14:27:55 +0200 Subject: [PATCH 13/13] fix the random appearance of clip plane For the `Scene_c3t3_item` (and probably `Scene_triangulation_item` as well) most of the time the clip plane was not shown. This is because of Boolean data member `cut_plane_enabled` that was not initialized. --- Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp b/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp index 04d0d44c58e..610d29fd014 100644 --- a/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_triangulation_3_item.cpp @@ -576,6 +576,7 @@ void Scene_triangulation_3_item::common_constructor(bool display_elements) d->is_grid_shown = display_elements; d->show_tetrahedra = display_elements; + d->cut_plane_enabled = display_elements; d->last_intersection = !d->show_tetrahedra; setTriangleContainer(T3_faces, new Tc(Vi::PROGRAM_C3T3, false));