Skip to content

Commit

Permalink
Merge pull request CGAL#7737 from ange-clement/Polyhedron-demo-Clippi…
Browse files Browse the repository at this point in the history
…ng-box-more-support-aclement

Polyhedron demo : Add clip box plugin support for more items
  • Loading branch information
lrineau committed Oct 5, 2023
2 parents 8ac6756 + 857de8b commit 6f1fa46
Show file tree
Hide file tree
Showing 15 changed files with 359 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Polyhedron/demo/Polyhedron/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ 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(
Expand Down
58 changes: 54 additions & 4 deletions Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -130,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);

Expand All @@ -148,6 +159,25 @@ void Clipping_box_plugin::enableAction() {
}

void Clipping_box_plugin::clip(bool b)
{
clipping = b;
if (b)
{
for(CGAL::QGLViewer* v : CGAL::QGLViewer::QGLViewerPool())
{
v->installEventFilter(this);
}
}
else {
for(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<Kernel> Mesh;
Expand Down Expand Up @@ -231,12 +261,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<QKeyEvent*>(event);
Expand Down Expand Up @@ -359,4 +397,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"
37 changes: 37 additions & 0 deletions Polyhedron/demo/Polyhedron/Plugins/PCA/Clipping_box_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,43 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="resetButton">
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
Expand Down
43 changes: 40 additions & 3 deletions Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
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;

vertex_spheres.resize(0);
normal_spheres.resize(0);
Expand Down Expand Up @@ -251,6 +252,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();
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;
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::Three::Viewer_interface*>(CGAL::QGLViewer::QGLViewerPool().first())->offset();
frame->setPosition(center_+offset);
item->invalidateOpenGLBuffers();
}
const Scene_interface* scene;
Scene_edit_box_item* item;
QPoint picked_pixel;
Expand All @@ -264,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)
{
Expand Down Expand Up @@ -294,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];
Expand Down Expand Up @@ -1307,3 +1339,8 @@ void Scene_edit_box_item::connectNewViewer(QObject *o)
return;
viewer->setMouseTracking(true);
}

void Scene_edit_box_item::reset()
{
d->reset_vertices();
}
2 changes: 2 additions & 0 deletions Polyhedron/demo/Polyhedron/Plugins/PCA/Scene_edit_box_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,6 +60,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;
Expand Down
11 changes: 2 additions & 9 deletions Polyhedron/demo/Polyhedron/Scene_image_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename Word_type>
const QColor&
Expand Down Expand Up @@ -756,6 +748,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);
Expand Down
Loading

0 comments on commit 6f1fa46

Please sign in to comment.