File: Point_set_interference_plugin.cpp

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (107 lines) | stat: -rw-r--r-- 3,180 bytes parent folder | download | duplicates (2)
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
//local includes
#include "Scene_points_with_normal_item.h"
//CGAL includes
#include <CGAL/compute_average_spacing.h>
#include <CGAL/Three/CGAL_Lab_plugin_interface.h>
#include <CGAL/point_generators_3.h>
#include <CGAL/function_objects.h>
#include <CGAL/Three/Scene_interface.h>

//Qt includes
#include <QList>
#include <QAction>
#include <QApplication>
#include <QWidget>
#include <QInputDialog>
#include <QMainWindow>

using namespace CGAL::Three;

typedef CGAL::Parallel_if_available_tag Concurrency_tag;

class  Point_set_interference_plugin:
    public QObject,
    public CGAL_Lab_plugin_interface
{

  Q_OBJECT
  Q_INTERFACES(CGAL::Three::CGAL_Lab_plugin_interface)
  Q_PLUGIN_METADATA(IID "com.geometryfactory.CGALLab.PluginInterface/1.0")

public:
  bool applicable(QAction *) const
  {
    return qobject_cast<Scene_points_with_normal_item*>(scene->item(scene->mainSelectionIndex()));
  }

  QList<QAction*> actions() const
  {
    return actions_;
  }

  void init(QMainWindow *mainWindow, Scene_interface * si, Messages_interface *)
  {
    scene = si;
    mw = mainWindow;

    QAction *actionAddNoise = new QAction(QString("Add Noise"), mw);
    if(actionAddNoise)
    {
      actionAddNoise->setProperty("subMenuName", "Point Set Processing");
      connect(actionAddNoise, SIGNAL(triggered()),
              this, SLOT(on_actionAddNoise_triggered()));
      actions_ << actionAddNoise;
    }
  }
private Q_SLOTS:
  void on_actionAddNoise_triggered()
  {
    Scene_points_with_normal_item* item = qobject_cast<Scene_points_with_normal_item*>(scene->item(scene->mainSelectionIndex()));
    if(!item)
      return;
    bool ok = false;
    Qt::WindowFlags flags = Qt::Dialog;
    flags |= Qt::CustomizeWindowHint;
    flags |= Qt::WindowCloseButtonHint;

    Point_set* points = item->point_set();
    if(points == nullptr)
      return;

    double average_spacing = CGAL::compute_average_spacing<Concurrency_tag>(
      points->all_or_selection_if_not_empty(),
      6 /* knn = 1 ring */,
      points->parameters());

    const double max_dist =
        QInputDialog::getDouble((QWidget*)mw,
                                tr("Add Noise"),
                                tr("Please choose the maximum radius in which the points will be moved. (default = average spacing)"),
                                average_spacing,
                                0,
                                100*average_spacing,
                                4,
                                &ok,
                                flags);
    if(!ok) return;
    QApplication::setOverrideCursor(Qt::WaitCursor);
    QApplication::processEvents();
    CGAL::Random_points_in_sphere_3<Kernel::Point_3> generator(max_dist);

    for(Point_set::iterator psit = points->begin_or_selection_begin(); psit != points->end(); ++psit)
    {
      points->point(*psit) = points->point(*psit) + (*generator - CGAL::ORIGIN);
      ++generator;
    }
    item->invalidateOpenGLBuffers();
    item->itemChanged();
    QApplication::restoreOverrideCursor();
  }
private:
  Scene_interface *scene;
  QList<QAction*> actions_;
  QMainWindow *mw;

};

#include "Point_set_interference_plugin.moc"