File: Register_point_sets_plugin.cpp

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (228 lines) | stat: -rw-r--r-- 7,138 bytes parent folder | download | duplicates (3)
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#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>

#ifdef CGAL_LINKED_WITH_OPENGR
#define CGAL_OPENGR_VERBOSE
#include <CGAL/OpenGR/register_point_sets.h>
#endif

#ifdef CGAL_LINKED_WITH_POINTMATCHER
#include <CGAL/pointmatcher/register_point_sets.h>
#endif

#include <sstream>

#include <CGAL/Timer.h>
#include <CGAL/Memory_sizer.h>

#include <QObject>
#include <QAction>
#include <QMainWindow>
#include <QApplication>
#include <QtPlugin>
#include <QInputDialog>
#include <QMessageBox>
#include <QRadioButton>
#include <QLabel>
#include <QSpinBox>
#include <QDoubleSpinBox>

#include "ui_Register_point_sets_plugin.h"


using namespace CGAL::Three;


class Point_set_demo_register_dialog : public QDialog, private Ui::RegisterPointSetsDialog
{
  Q_OBJECT
public:
  Point_set_demo_register_dialog(const std::vector<Scene_points_with_normal_item*>& items,
                                 QWidget* /*parent*/ = nullptr)
  {
    setupUi(this);

    for (std::size_t i = 0; i < items.size(); ++ i)
    {
      QRadioButton* button = new QRadioButton(items[i]->name().toStdString().c_str(), this);
      buttons.push_back (button);
      pointSets->addRow (button);
      if (i == 0)
        button->setChecked(true);
    }

#ifndef CGAL_LINKED_WITH_OPENGR
    coarseRegistration->setText("Coarse registration (disabled, requires OpenGR)");
    coarseRegistration->setChecked(false);
    coarseRegistration->setEnabled(false);
    opengr_frame->setEnabled(false);
#endif
#ifndef CGAL_LINKED_WITH_POINTMATCHER
    fineRegistration->setText("Fine registration (disabled, requires libpointmatcher)");
    fineRegistration->setChecked(false);
    fineRegistration->setEnabled(false);
    pointmatcher_frame->setEnabled(false);
#endif
  }

  std::size_t ref_index() const
  {
    for (std::size_t i = 0; i < buttons.size(); ++ i)
      if (buttons[i]->isChecked())
        return i;
    return std::size_t(-1);
  }

  bool coarse_registration() const { return coarseRegistration->isChecked(); }
  bool fine_registration() const { return fineRegistration->isChecked(); }

  int nb_samples() const { return numberOfSamplesSpinBox->value(); }
  double accuracy() const { return accuracyDoubleSpinBox->value(); }
  double overlap() const { return double(overlapSpinBox->value()) / 100.0; }
  int max_time() const { return maximumRunningTimeSpinBox->value(); }

  std::string pointmatcher_config() const { return config->toPlainText().toStdString(); }

private:

  std::vector<QRadioButton*> buttons;

};



class CGAL_Lab_register_point_sets_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")

private:
  QAction* actionRegisterPointSets;

public:
  void init(QMainWindow* mainWindow, CGAL::Three::Scene_interface* scene_interface, Messages_interface*) {
    scene = scene_interface;
    mw = mainWindow;
    actionRegisterPointSets = new QAction(tr("Register point sets"), mainWindow);
    actionRegisterPointSets->setObjectName("actionRegisterPointSets");
    connect(actionRegisterPointSets, SIGNAL(triggered()), this, SLOT(on_actionRegisterPointSets_triggered()));
  }

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

  bool applicable(QAction*) const {
    return get_point_set_items().size() >= 2;
  }

  std::vector<Scene_points_with_normal_item*> get_point_set_items() const
  {
    std::vector<Scene_points_with_normal_item*> items;

    for(int index : scene->selectionIndices())
    {
      Scene_points_with_normal_item* item =
        qobject_cast<Scene_points_with_normal_item*>(scene->item(index));
      if(item && item->point_set()->has_normal_map())
        items.push_back (item);
    }

    return items;
  }

public Q_SLOTS:
  void on_actionRegisterPointSets_triggered();
private :
  Scene_interface *scene;
}; // end CGAL_Lab_register_point_sets_plugin

void CGAL_Lab_register_point_sets_plugin::on_actionRegisterPointSets_triggered()
{
  std::vector<Scene_points_with_normal_item*> items = get_point_set_items();

  Point_set_demo_register_dialog dialog(items);
  if(!dialog.exec())
    return;

  QApplication::setOverrideCursor(Qt::WaitCursor);

  std::size_t ref = dialog.ref_index();

  for (std::size_t i = 0; i < items.size(); ++ i)
  {
    if (i == ref)
      continue;

    std::cerr << "Registering " << items[i]->name().toStdString() << " with " << items[ref]->name().toStdString() << std::endl;

    Point_set& ps1 = *(items[ref]->point_set());
    Point_set& ps2 = *(items[i]->point_set());

#ifdef CGAL_LINKED_WITH_OPENGR
    if (dialog.coarse_registration())
    {
      std::cerr << "* Coarse registration:" << std::endl;
      CGAL::Timer task_timer; task_timer.start();
      double score =
        CGAL::OpenGR::register_point_sets(ps1, ps2,
                                          CGAL::parameters::point_map(ps1.point_map())
                                          .normal_map(ps1.normal_map())
                                          .number_of_samples(dialog.nb_samples())
                                          .maximum_running_time(dialog.max_time())
                                          .accuracy(dialog.accuracy())
                                          .overlap(dialog.overlap()),
                                          CGAL::parameters::point_map(ps2.point_map())
                                          .normal_map(ps2.normal_map()));

      std::size_t memory = CGAL::Memory_sizer().virtual_size();
      std::cerr << " -> Registration score = " << score << " ("
                << task_timer.time() << " seconds, "
                << (memory>>20) << " Mb allocated)"
                << std::endl;
    }
#endif
#ifdef CGAL_LINKED_WITH_POINTMATCHER
    if (dialog.fine_registration())
    {
      std::cerr << "* Fine registration: " << std::endl;

      std::istringstream ss (dialog.pointmatcher_config());

      CGAL::Timer task_timer; task_timer.start();
      if (CGAL::pointmatcher::register_point_sets(ps1, ps2,
                                            CGAL::parameters::point_map(ps1.point_map())
                                            .normal_map(ps1.normal_map())
                                            .pointmatcher_config(&ss),
                                            CGAL::parameters::point_map(ps2.point_map())
                                            .normal_map(ps2.normal_map())))
        std::cerr << " -> Success";
      else
        std::cerr << " -> Failure";

      std::size_t memory = CGAL::Memory_sizer().virtual_size();
      std::cerr << " ("
                << task_timer.time() << " seconds, "
                << (memory>>20) << " Mb allocated)"
                << std::endl;
    }
#endif

  }

  for (std::size_t i = 0; i < items.size(); ++ i)
  {
    items[i]->invalidateOpenGLBuffers();
    scene->itemChanged(items[i]);
  }

  QApplication::restoreOverrideCursor();
}


#include "Register_point_sets_plugin.moc"