File: Features_detection_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 (118 lines) | stat: -rw-r--r-- 3,827 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
#include <QAction>
#include <QApplication>
#include <QMessageBox>
#include <QMainWindow>
#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/vcm_estimate_edges.h>

#include <CGAL/Timer.h>

#include "ui_Features_detection_plugin.h"
using namespace CGAL::Three;
class CGAL_Lab_features_detection_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* actionDetectFeatures;
public:
  QList<QAction*> actions() const { return QList<QAction*>() << actionDetectFeatures; }
  void init(QMainWindow* mainWindow, CGAL::Three::Scene_interface* scene_interface, Messages_interface*)
  {
    scene = scene_interface;
    actionDetectFeatures= new QAction(tr("VCM Features Estimation"), mainWindow);
    actionDetectFeatures->setProperty("subMenuName","Point Set Processing");
    actionDetectFeatures->setObjectName("actionDetectFeatures");
    autoConnectActions();
  }

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

public Q_SLOTS:
  void on_actionDetectFeatures_triggered();
private:
  Scene_interface* scene;
}; // end CGAL_Lab_features_detection_plugin

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

    float offsetRadius() const { return m_inputOffsetRadius->value(); }
    float convolveRadius() const { return m_inputConvolveRadius->value(); }
    float threshold() const { return m_inputFeaturesThreshold->value(); }
};

void CGAL_Lab_features_detection_plugin::on_actionDetectFeatures_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
    CGAL_Lab_features_detection_dialog dialog;
    if(!dialog.exec())
      return;

    QApplication::setOverrideCursor(Qt::WaitCursor);
    typedef std::array<double,6> Covariance;
    std::vector<Covariance> cov;

    std::cerr << "Compute VCM (offset_radius="
        << dialog.offsetRadius() << " and convolution radius=" << dialog.convolveRadius() << ")...\n";

    CGAL::Timer task_timer; task_timer.start();
    CGAL::compute_vcm(*points, cov, dialog.offsetRadius(), dialog.convolveRadius(),
                      points->parameters());
    task_timer.stop();
    std::cerr << "done: " << task_timer.time() << " seconds\n";

    Scene_points_with_normal_item* new_item = new Scene_points_with_normal_item();
    task_timer.reset(); task_timer.start();
    std::size_t i=0;
    std::cerr << "Select feature points (threshold=" << dialog.threshold() << ")...\n";
    for (Point_set::const_iterator it = points->begin(); it != points->end(); ++ it)
    {
      if (CGAL::vcm_is_on_feature_edge(cov[i], dialog.threshold()))
        new_item->point_set()->insert(points->point(*it));
      ++i;
    }
    task_timer.stop();
    std::cerr << "done: " << task_timer.time() << " seconds\n";

    if ( !new_item->point_set()->empty() )
    {
      new_item->setName(tr("Features of %1").arg(item->name()));
      new_item->setColor(Qt::red);
      scene->addItem(new_item);
      item->setVisible(false);
    }
    else
      delete new_item;
    QApplication::restoreOverrideCursor();
  }

}

#include "Features_detection_plugin.moc"