mirror of https://github.com/CGAL/cgal
Merge pull request #3799 from maxGimeno/Demo-Select_only_in_clipped_zone-GF
Polyhedron Demo: Only Select in the clipped zone
This commit is contained in:
commit
d27c222e54
|
|
@ -70,17 +70,21 @@ void Clipping_box_plugin::init(QMainWindow* mainWindow, CGAL::Three::Scene_inter
|
|||
scene = scene_interface;
|
||||
mw = mainWindow;
|
||||
actionClipbox = new QAction(tr("Create Clipping Box"), mainWindow);
|
||||
connect(actionClipbox, SIGNAL(triggered()),
|
||||
this, SLOT(clipbox()));
|
||||
|
||||
dock_widget = new ClipWidget("Clip box", mw);
|
||||
dock_widget->setVisible(false); // do not show at the beginning
|
||||
addDockWidget(dock_widget);
|
||||
|
||||
|
||||
connect(actionClipbox, &QAction::triggered,
|
||||
this, [this](){
|
||||
dock_widget->show();
|
||||
dock_widget->raise();
|
||||
tab_change();
|
||||
});
|
||||
connect(dock_widget->pushButton, SIGNAL(toggled(bool)),
|
||||
this, SLOT(clip(bool)));
|
||||
|
||||
CGAL::QGLViewer* viewer = *CGAL::QGLViewer::QGLViewerPool().begin();
|
||||
viewer->installEventFilter(this);
|
||||
item = NULL;
|
||||
visualizer = NULL;
|
||||
shift_pressing = false;
|
||||
|
|
@ -95,10 +99,11 @@ void Clipping_box_plugin::clipbox()
|
|||
return;
|
||||
}
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
dock_widget->show();
|
||||
dock_widget->raise();
|
||||
if(!item)
|
||||
{
|
||||
item = new Scene_edit_box_item(scene);
|
||||
CGAL::QGLViewer::QGLViewerPool().first()->installEventFilter(item);
|
||||
}
|
||||
connect(item, SIGNAL(destroyed()),
|
||||
this, SLOT(enableAction()));
|
||||
connect(item, &Scene_edit_box_item::aboutToBeDestroyed,
|
||||
|
|
@ -111,7 +116,7 @@ void Clipping_box_plugin::clipbox()
|
|||
this, [this](){
|
||||
dock_widget->unclipButton->setDisabled(true);
|
||||
CGAL::Three::Viewer_interface* viewer = static_cast<CGAL::Three::Viewer_interface*>(
|
||||
*CGAL::QGLViewer::QGLViewerPool().begin());
|
||||
CGAL::QGLViewer::QGLViewerPool().first());
|
||||
viewer->disableClippingBox();
|
||||
viewer->update();
|
||||
});
|
||||
|
|
@ -119,8 +124,6 @@ void Clipping_box_plugin::clipbox()
|
|||
this, &Clipping_box_plugin::tab_change);
|
||||
item->setName("Clipping box");
|
||||
item->setRenderingMode(FlatPlusEdges);
|
||||
CGAL::QGLViewer* viewer = *CGAL::QGLViewer::QGLViewerPool().begin();
|
||||
viewer->installEventFilter(item);
|
||||
scene->addItem(item);
|
||||
actionClipbox->setEnabled(false);
|
||||
|
||||
|
|
@ -196,6 +199,12 @@ void Clipping_box_plugin::tab_change()
|
|||
item = NULL;
|
||||
}
|
||||
action->setChecked(true);
|
||||
CGAL::QGLViewer* viewer = *CGAL::QGLViewer::QGLViewerPool().begin();
|
||||
connect(dock_widget->clipButton, &QPushButton::toggled,
|
||||
this, [this, viewer](){
|
||||
viewer->setFocus();
|
||||
viewer->installEventFilter(this);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -207,7 +216,8 @@ 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)
|
||||
if (dock_widget->isHidden() || !(dock_widget->isActiveWindow()) || dock_widget->tabWidget->currentIndex() != 1
|
||||
|| (dock_widget->tabWidget->currentIndex() == 1 && !dock_widget->clipButton->isChecked()))
|
||||
return false;
|
||||
|
||||
if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease)
|
||||
|
|
@ -317,6 +327,7 @@ bool Clipping_box_plugin::eventFilter(QObject *, QEvent *event) {
|
|||
|
||||
viewer->enableClippingBox(planes);
|
||||
dock_widget->unclipButton->setEnabled(true);
|
||||
dock_widget->clipButton->setChecked(false);
|
||||
visualizer = NULL;
|
||||
QApplication::restoreOverrideCursor();
|
||||
static_cast<CGAL::Three::Viewer_interface*>(viewer)->set2DSelectionMode(false);
|
||||
|
|
|
|||
|
|
@ -100,6 +100,16 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="clipButton">
|
||||
<property name="text">
|
||||
<string>Clip</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="unclipButton">
|
||||
<property name="enabled">
|
||||
|
|
@ -141,11 +151,22 @@
|
|||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Info: SHIFT+Click to clip.</string>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Info: SHIFT+Click to clip</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>While "Clip" is toggled.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ class Selection_test {
|
|||
const CGAL::qglviewer::Vec offset;
|
||||
Scene_edit_box_item* edit_box;
|
||||
Selection_visualizer* visualizer;
|
||||
QVector4D* clipbox;
|
||||
const Ui::PointSetSelection& ui_widget;
|
||||
|
||||
|
||||
|
|
@ -69,6 +70,7 @@ public:
|
|||
const CGAL::qglviewer::Vec offset,
|
||||
Scene_edit_box_item* edit_box,
|
||||
Selection_visualizer* visualizer,
|
||||
QVector4D* clipbox,
|
||||
const Ui::PointSetSelection& ui_widget)
|
||||
: point_set (point_set)
|
||||
, selected (selected)
|
||||
|
|
@ -76,6 +78,7 @@ public:
|
|||
, offset (offset)
|
||||
, edit_box (edit_box)
|
||||
, visualizer (visualizer)
|
||||
, clipbox (clipbox)
|
||||
, ui_widget (ui_widget)
|
||||
{
|
||||
}
|
||||
|
|
@ -91,8 +94,15 @@ public:
|
|||
void apply (std::size_t i) const
|
||||
{
|
||||
Point_set::Index idx = *(point_set->begin() + i);
|
||||
|
||||
const Kernel::Point_3& p = point_set->point (idx);
|
||||
|
||||
// Points outside clipbox are not affected
|
||||
if (!is_inside_clipbox (p))
|
||||
{
|
||||
selected[idx] = point_set->is_selected (point_set->begin() + i);
|
||||
return;
|
||||
}
|
||||
|
||||
CGAL::qglviewer::Vec vp (p.x (), p.y (), p.z ());
|
||||
bool now_selected = false;
|
||||
if(!ui_widget.box->isChecked())
|
||||
|
|
@ -127,6 +137,22 @@ public:
|
|||
selected[idx] = (already_selected && !now_selected);
|
||||
}
|
||||
}
|
||||
|
||||
bool is_inside_clipbox (const Kernel::Point_3& p) const
|
||||
{
|
||||
if(!static_cast<CGAL::Three::Viewer_interface*>(CGAL::QGLViewer::QGLViewerPool().first())->isClipping())
|
||||
return true;
|
||||
|
||||
double x = p.x(), y = p.y(), z = p.z();
|
||||
|
||||
return !(clipbox[0][0]*x+clipbox[0][1]*y+clipbox[0][2]*z+clipbox[0][3]>0 ||
|
||||
clipbox[1][0]*x+clipbox[1][1]*y+clipbox[1][2]*z+clipbox[1][3]>0 ||
|
||||
clipbox[2][0]*x+clipbox[2][1]*y+clipbox[2][2]*z+clipbox[2][3]>0 ||
|
||||
clipbox[3][0]*x+clipbox[3][1]*y+clipbox[3][2]*z+clipbox[3][3]>0 ||
|
||||
clipbox[4][0]*x+clipbox[4][1]*y+clipbox[4][2]*z+clipbox[4][3]>0 ||
|
||||
clipbox[5][0]*x+clipbox[5][1]*y+clipbox[5][2]*z+clipbox[5][3]>0);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -568,6 +594,7 @@ protected:
|
|||
}
|
||||
|
||||
protected Q_SLOTS:
|
||||
|
||||
void select_points()
|
||||
{
|
||||
Scene_points_with_normal_item* point_set_item = getSelectedItem<Scene_points_with_normal_item>();
|
||||
|
|
@ -590,7 +617,9 @@ protected Q_SLOTS:
|
|||
bool* selected_bitmap = new bool[points->size()]; // std::vector<bool> is not thread safe
|
||||
|
||||
Selection_test selection_test (points, selected_bitmap,
|
||||
camera, offset, edit_box, visualizer, ui_widget);
|
||||
camera, offset, edit_box, visualizer,
|
||||
static_cast<CGAL::Three::Viewer_interface*>(viewer)->clipBox(),
|
||||
ui_widget);
|
||||
#ifdef CGAL_LINKED_WITH_TBB
|
||||
tbb::parallel_for(tbb::blocked_range<size_t>(0, points->size()),
|
||||
selection_test);
|
||||
|
|
|
|||
|
|
@ -1683,5 +1683,15 @@ void Viewer::setGlPointSize(const GLfloat &p) { d->gl_point_size = p; }
|
|||
|
||||
const GLfloat& Viewer::getGlPointSize() const { return d->gl_point_size; }
|
||||
|
||||
QVector4D* Viewer::clipBox() const
|
||||
{
|
||||
return d->clipbox;
|
||||
}
|
||||
|
||||
bool Viewer::isClipping() const
|
||||
{
|
||||
return d->clipping;
|
||||
}
|
||||
|
||||
#include "Viewer.moc"
|
||||
|
||||
|
|
|
|||
|
|
@ -154,6 +154,8 @@ public:
|
|||
float total_pass()Q_DECL_OVERRIDE;
|
||||
const GLfloat& getGlPointSize()const Q_DECL_OVERRIDE;
|
||||
void setGlPointSize(const GLfloat& p) Q_DECL_OVERRIDE;
|
||||
QVector4D* clipBox() const Q_DECL_OVERRIDE;
|
||||
bool isClipping() const Q_DECL_OVERRIDE;
|
||||
}; // end class Viewer
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -276,6 +276,8 @@ public:
|
|||
virtual int currentPass()const = 0;
|
||||
virtual bool isDepthWriting()const = 0;
|
||||
virtual QOpenGLFramebufferObject* depthPeelingFbo() = 0;
|
||||
virtual QVector4D* clipBox() const =0;
|
||||
virtual bool isClipping() const = 0;
|
||||
}; // end class Viewer_interface
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue