File: Point_set_wlop_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 (173 lines) | stat: -rw-r--r-- 5,570 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#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 <CGAL/wlop_simplify_and_regularize_point_set.h>
#include <CGAL/compute_average_spacing.h>
#include <CGAL/Timer.h>
#include <CGAL/Memory_sizer.h>

#include <QObject>
#include <QAction>
#include <QMainWindow>
#include <QApplication>
#include <QtPlugin>
#include <QMessageBox>

#include "run_with_qprogressdialog.h"

#include "ui_Point_set_wlop_plugin.h"

// Concurrency
typedef CGAL::Parallel_if_available_tag Concurrency_tag;

struct Compute_average_spacing_functor
  : public Functor_with_signal_callback
{
  Point_set* points;
  const int nb_neighbors;
  std::shared_ptr<double> result;

  Compute_average_spacing_functor (Point_set* points, const int nb_neighbors)
    : points (points), nb_neighbors (nb_neighbors), result (new double(0)) { }

  void operator()()
  {
    *result = CGAL::compute_average_spacing<Concurrency_tag>(
      points->all_or_selection_if_not_empty(),
      nb_neighbors,
      points->parameters().
      callback (*(this->callback())));
  }
};

struct Wlop_functor
  : public Functor_with_signal_callback
{
  Point_set* points;
  double select_percentage;
  double neighbor_radius;
  Scene_points_with_normal_item* new_item;

  Wlop_functor (Point_set* points, double select_percentage, double neighbor_radius,
                Scene_points_with_normal_item* new_item)
    : points (points), select_percentage (select_percentage)
    , neighbor_radius (neighbor_radius), new_item (new_item)
  { }

  void operator()()
  {
    CGAL::wlop_simplify_and_regularize_point_set<Concurrency_tag>
      (points->all_or_selection_if_not_empty(),
       new_item->point_set()->point_back_inserter(),
       points->parameters().
       select_percentage (select_percentage).
       neighbor_radius (neighbor_radius).
       callback (*(this->callback())));
  }
};


using namespace CGAL::Three;
class CGAL_Lab_point_set_wlop_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* actionSimplifyAndRegularize;

public:
  void init(QMainWindow* mainWindow, CGAL::Three::Scene_interface* scene_interface, Messages_interface*) {
    scene = scene_interface;
    mw = mainWindow;
    actionSimplifyAndRegularize = new QAction(tr("WLOP Simplification and Regularization Selection"), mainWindow);
    actionSimplifyAndRegularize->setProperty("subMenuName","Point Set Processing");
    actionSimplifyAndRegularize->setObjectName("actionSimplifyAndRegularize");
    autoConnectActions();
  }

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

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

public Q_SLOTS:
  void on_actionSimplifyAndRegularize_triggered();

}; // end CGAL_Lab_point_set_wlop_plugin

class Point_set_demo_point_set_wlop_simplification_and_regularization_dialog : public QDialog, private Ui::WLOPRegularizationAndSimplificationDialog
{
  Q_OBJECT
  public:
    Point_set_demo_point_set_wlop_simplification_and_regularization_dialog(QWidget * /*parent*/ = nullptr)
    {
      setupUi(this);
    }

    double retainedPercentage() const { return m_retainedPercentage->value(); }
    double neighborhoodRadius() const { return m_neighborhoodRadius->value(); }
};

void CGAL_Lab_point_set_wlop_plugin::on_actionSimplifyAndRegularize_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)
  {
    // Gets point set
    Point_set* points = item->point_set();
    if(points == nullptr)
        return;

    // Gets options
    Point_set_demo_point_set_wlop_simplification_and_regularization_dialog dialog;
    if(!dialog.exec())
      return;

    QApplication::setOverrideCursor(Qt::BusyCursor);

    CGAL::Timer task_timer; task_timer.start();

    std::cerr << "Point cloud simplification and regularization by WLOP ("
              << dialog.retainedPercentage () << "% retained points, neighborhood radius = "
              << dialog.neighborhoodRadius() <<" * average spacing)...\n";

    // Computes average spacing
    Compute_average_spacing_functor functor_as (points, 6);
    run_with_qprogressdialog (functor_as, "WLOP: computing average spacing...", mw);
    double average_spacing = *functor_as.result;

    Scene_points_with_normal_item* new_item
      = new Scene_points_with_normal_item();
    new_item->setName (tr("%1 (WLOP processed)").arg(item->name()));
    new_item->setVisible(true);
    item->setVisible(false);
    scene->addItem(new_item);

    Wlop_functor functor (points, dialog.retainedPercentage(),
                          dialog.neighborhoodRadius() * average_spacing, new_item);
    run_with_qprogressdialog (functor, "WLOP simplification and regularization...", mw);

    std::size_t memory = CGAL::Memory_sizer().virtual_size();
    std::cerr << "Simplification and regularization: "
              << new_item->point_set ()->size () << " point(s) created ("
              << task_timer.time() << " seconds, "
              << (memory>>20) << " Mb allocated)"
              << std::endl;

    QApplication::restoreOverrideCursor();
  }
}

#include "Point_set_wlop_plugin.moc"