1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#include "config.h"
#include "Scene_points_with_normal_item.h"
#include <CGAL/Three/CGAL_Lab_plugin_helper.h>
#include <CGAL/Three/CGAL_Lab_plugin_interface.h>
#include <QObject>
#include <QAction>
#include <QMainWindow>
#include <QApplication>
#include <QtPlugin>
#include <QInputDialog>
#include <CGAL/jet_smooth_point_set.h>
#include "run_with_qprogressdialog.h"
// Concurrency
typedef CGAL::Parallel_if_available_tag Concurrency_tag;
struct Jet_smoothing_functor
: public Functor_with_signal_callback
{
Point_set* points;
const int nb_neighbors;
Jet_smoothing_functor (Point_set* points, const int nb_neighbors)
: points (points), nb_neighbors (nb_neighbors) { }
void operator()()
{
CGAL::jet_smooth_point_set<Concurrency_tag>(points->all_or_selection_if_not_empty(),
nb_neighbors,
points->parameters().
callback (*(this->callback())));
}
};
using namespace CGAL::Three;
class CGAL_Lab_point_set_smoothing_plugin :
public QObject,
public CGAL_Lab_plugin_helper
{
Q_OBJECT
Q_INTERFACES(CGAL::Three::CGAL_Lab_plugin_interface)
Q_PLUGIN_METADATA(IID "com.geometryfactory.CGALLab.PluginInterface/1.0")
QAction* actionJetSmoothing;
public:
void init(QMainWindow* mainWindow, CGAL::Three::Scene_interface* scene_interface, Messages_interface*) {
scene = scene_interface;
mw = mainWindow;
actionJetSmoothing = new QAction(tr("Jet Smoothing"), mainWindow);
actionJetSmoothing->setProperty("subMenuName","Point Set Processing");
actionJetSmoothing->setObjectName("actionJetSmoothing");
autoConnectActions();
}
QList<QAction*> actions() const {
return QList<QAction*>() << actionJetSmoothing;
}
bool applicable(QAction*) const {
return qobject_cast<Scene_points_with_normal_item*>(scene->item(scene->mainSelectionIndex()));
}
public Q_SLOTS:
void on_actionJetSmoothing_triggered();
}; // end CGAL_Lab_point_set_smoothing_plugin
void CGAL_Lab_point_set_smoothing_plugin::on_actionJetSmoothing_triggered()
{
const CGAL::Three::Scene_interface::Item_id index = scene->mainSelectionIndex();
Scene_points_with_normal_item* item =
qobject_cast<Scene_points_with_normal_item*>(scene->item(index));
if(item)
{
Point_set* points = item->point_set();
if(!points) return;
// Gets options
bool ok;
const unsigned int nb_neighbors =
QInputDialog::getInt((QWidget*)mw,
tr("Jet Smoothing"), // dialog title
tr("Number of neighbors:"), // field label
24, // default value = fast
6, // min
1000, // max
1, // step
&ok);
if(!ok) return;
QApplication::setOverrideCursor(Qt::BusyCursor);
QApplication::processEvents();
Jet_smoothing_functor functor (points, nb_neighbors);
run_with_qprogressdialog (functor, "Smoothing point set...", mw);
points->invalidate_bounds();
// update scene
item->invalidateOpenGLBuffers();
scene->itemChanged(index);
QApplication::restoreOverrideCursor();
}
}
#include "Point_set_smoothing_plugin.moc"
|