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;
|
scene = scene_interface;
|
||||||
mw = mainWindow;
|
mw = mainWindow;
|
||||||
actionClipbox = new QAction(tr("Create Clipping Box"), 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 = new ClipWidget("Clip box", mw);
|
||||||
dock_widget->setVisible(false); // do not show at the beginning
|
dock_widget->setVisible(false); // do not show at the beginning
|
||||||
addDockWidget(dock_widget);
|
addDockWidget(dock_widget);
|
||||||
|
|
||||||
|
|
||||||
|
connect(actionClipbox, &QAction::triggered,
|
||||||
|
this, [this](){
|
||||||
|
dock_widget->show();
|
||||||
|
dock_widget->raise();
|
||||||
|
tab_change();
|
||||||
|
});
|
||||||
connect(dock_widget->pushButton, SIGNAL(toggled(bool)),
|
connect(dock_widget->pushButton, SIGNAL(toggled(bool)),
|
||||||
this, SLOT(clip(bool)));
|
this, SLOT(clip(bool)));
|
||||||
|
|
||||||
CGAL::QGLViewer* viewer = *CGAL::QGLViewer::QGLViewerPool().begin();
|
|
||||||
viewer->installEventFilter(this);
|
|
||||||
item = NULL;
|
item = NULL;
|
||||||
visualizer = NULL;
|
visualizer = NULL;
|
||||||
shift_pressing = false;
|
shift_pressing = false;
|
||||||
|
|
@ -95,10 +99,11 @@ void Clipping_box_plugin::clipbox()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
dock_widget->show();
|
|
||||||
dock_widget->raise();
|
|
||||||
if(!item)
|
if(!item)
|
||||||
|
{
|
||||||
item = new Scene_edit_box_item(scene);
|
item = new Scene_edit_box_item(scene);
|
||||||
|
CGAL::QGLViewer::QGLViewerPool().first()->installEventFilter(item);
|
||||||
|
}
|
||||||
connect(item, SIGNAL(destroyed()),
|
connect(item, SIGNAL(destroyed()),
|
||||||
this, SLOT(enableAction()));
|
this, SLOT(enableAction()));
|
||||||
connect(item, &Scene_edit_box_item::aboutToBeDestroyed,
|
connect(item, &Scene_edit_box_item::aboutToBeDestroyed,
|
||||||
|
|
@ -111,7 +116,7 @@ void Clipping_box_plugin::clipbox()
|
||||||
this, [this](){
|
this, [this](){
|
||||||
dock_widget->unclipButton->setDisabled(true);
|
dock_widget->unclipButton->setDisabled(true);
|
||||||
CGAL::Three::Viewer_interface* viewer = static_cast<CGAL::Three::Viewer_interface*>(
|
CGAL::Three::Viewer_interface* viewer = static_cast<CGAL::Three::Viewer_interface*>(
|
||||||
*CGAL::QGLViewer::QGLViewerPool().begin());
|
CGAL::QGLViewer::QGLViewerPool().first());
|
||||||
viewer->disableClippingBox();
|
viewer->disableClippingBox();
|
||||||
viewer->update();
|
viewer->update();
|
||||||
});
|
});
|
||||||
|
|
@ -119,8 +124,6 @@ void Clipping_box_plugin::clipbox()
|
||||||
this, &Clipping_box_plugin::tab_change);
|
this, &Clipping_box_plugin::tab_change);
|
||||||
item->setName("Clipping box");
|
item->setName("Clipping box");
|
||||||
item->setRenderingMode(FlatPlusEdges);
|
item->setRenderingMode(FlatPlusEdges);
|
||||||
CGAL::QGLViewer* viewer = *CGAL::QGLViewer::QGLViewerPool().begin();
|
|
||||||
viewer->installEventFilter(item);
|
|
||||||
scene->addItem(item);
|
scene->addItem(item);
|
||||||
actionClipbox->setEnabled(false);
|
actionClipbox->setEnabled(false);
|
||||||
|
|
||||||
|
|
@ -196,6 +199,12 @@ void Clipping_box_plugin::tab_change()
|
||||||
item = NULL;
|
item = NULL;
|
||||||
}
|
}
|
||||||
action->setChecked(true);
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -207,7 +216,8 @@ void Clipping_box_plugin::tab_change()
|
||||||
|
|
||||||
bool Clipping_box_plugin::eventFilter(QObject *, QEvent *event) {
|
bool Clipping_box_plugin::eventFilter(QObject *, QEvent *event) {
|
||||||
static QImage background;
|
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;
|
return false;
|
||||||
|
|
||||||
if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease)
|
if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease)
|
||||||
|
|
@ -317,6 +327,7 @@ bool Clipping_box_plugin::eventFilter(QObject *, QEvent *event) {
|
||||||
|
|
||||||
viewer->enableClippingBox(planes);
|
viewer->enableClippingBox(planes);
|
||||||
dock_widget->unclipButton->setEnabled(true);
|
dock_widget->unclipButton->setEnabled(true);
|
||||||
|
dock_widget->clipButton->setChecked(false);
|
||||||
visualizer = NULL;
|
visualizer = NULL;
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
static_cast<CGAL::Three::Viewer_interface*>(viewer)->set2DSelectionMode(false);
|
static_cast<CGAL::Three::Viewer_interface*>(viewer)->set2DSelectionMode(false);
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,16 @@
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="clipButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Clip</string>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="unclipButton">
|
<widget class="QPushButton" name="unclipButton">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
|
|
@ -141,11 +151,22 @@
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label">
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
<property name="text">
|
<item>
|
||||||
<string>Info: SHIFT+Click to clip.</string>
|
<widget class="QLabel" name="label">
|
||||||
</property>
|
<property name="text">
|
||||||
</widget>
|
<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>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ class Selection_test {
|
||||||
const CGAL::qglviewer::Vec offset;
|
const CGAL::qglviewer::Vec offset;
|
||||||
Scene_edit_box_item* edit_box;
|
Scene_edit_box_item* edit_box;
|
||||||
Selection_visualizer* visualizer;
|
Selection_visualizer* visualizer;
|
||||||
|
QVector4D* clipbox;
|
||||||
const Ui::PointSetSelection& ui_widget;
|
const Ui::PointSetSelection& ui_widget;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -69,6 +70,7 @@ public:
|
||||||
const CGAL::qglviewer::Vec offset,
|
const CGAL::qglviewer::Vec offset,
|
||||||
Scene_edit_box_item* edit_box,
|
Scene_edit_box_item* edit_box,
|
||||||
Selection_visualizer* visualizer,
|
Selection_visualizer* visualizer,
|
||||||
|
QVector4D* clipbox,
|
||||||
const Ui::PointSetSelection& ui_widget)
|
const Ui::PointSetSelection& ui_widget)
|
||||||
: point_set (point_set)
|
: point_set (point_set)
|
||||||
, selected (selected)
|
, selected (selected)
|
||||||
|
|
@ -76,6 +78,7 @@ public:
|
||||||
, offset (offset)
|
, offset (offset)
|
||||||
, edit_box (edit_box)
|
, edit_box (edit_box)
|
||||||
, visualizer (visualizer)
|
, visualizer (visualizer)
|
||||||
|
, clipbox (clipbox)
|
||||||
, ui_widget (ui_widget)
|
, ui_widget (ui_widget)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -91,8 +94,15 @@ public:
|
||||||
void apply (std::size_t i) const
|
void apply (std::size_t i) const
|
||||||
{
|
{
|
||||||
Point_set::Index idx = *(point_set->begin() + i);
|
Point_set::Index idx = *(point_set->begin() + i);
|
||||||
|
|
||||||
const Kernel::Point_3& p = point_set->point (idx);
|
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 ());
|
CGAL::qglviewer::Vec vp (p.x (), p.y (), p.z ());
|
||||||
bool now_selected = false;
|
bool now_selected = false;
|
||||||
if(!ui_widget.box->isChecked())
|
if(!ui_widget.box->isChecked())
|
||||||
|
|
@ -127,6 +137,22 @@ public:
|
||||||
selected[idx] = (already_selected && !now_selected);
|
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:
|
protected Q_SLOTS:
|
||||||
|
|
||||||
void select_points()
|
void select_points()
|
||||||
{
|
{
|
||||||
Scene_points_with_normal_item* point_set_item = getSelectedItem<Scene_points_with_normal_item>();
|
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
|
bool* selected_bitmap = new bool[points->size()]; // std::vector<bool> is not thread safe
|
||||||
|
|
||||||
Selection_test selection_test (points, selected_bitmap,
|
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
|
#ifdef CGAL_LINKED_WITH_TBB
|
||||||
tbb::parallel_for(tbb::blocked_range<size_t>(0, points->size()),
|
tbb::parallel_for(tbb::blocked_range<size_t>(0, points->size()),
|
||||||
selection_test);
|
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; }
|
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"
|
#include "Viewer.moc"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,8 @@ public:
|
||||||
float total_pass()Q_DECL_OVERRIDE;
|
float total_pass()Q_DECL_OVERRIDE;
|
||||||
const GLfloat& getGlPointSize()const Q_DECL_OVERRIDE;
|
const GLfloat& getGlPointSize()const Q_DECL_OVERRIDE;
|
||||||
void setGlPointSize(const GLfloat& p) 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
|
}; // end class Viewer
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -276,6 +276,8 @@ public:
|
||||||
virtual int currentPass()const = 0;
|
virtual int currentPass()const = 0;
|
||||||
virtual bool isDepthWriting()const = 0;
|
virtual bool isDepthWriting()const = 0;
|
||||||
virtual QOpenGLFramebufferObject* depthPeelingFbo() = 0;
|
virtual QOpenGLFramebufferObject* depthPeelingFbo() = 0;
|
||||||
|
virtual QVector4D* clipBox() const =0;
|
||||||
|
virtual bool isClipping() const = 0;
|
||||||
}; // end class Viewer_interface
|
}; // end class Viewer_interface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue