From 3b54dc2f923533f58864ac7e4e2acc619235c37a Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 15 Oct 2019 15:33:45 +0200 Subject: [PATCH] WIP Replace all double spin box. Remove resetRampButton as it hase become useless at some point. --- .../demo/Polyhedron/CGAL_double_edit.cpp | 29 +++++++++-- Polyhedron/demo/Polyhedron/CGAL_double_edit.h | 10 +++- .../Classification/Classification_plugin.cpp | 24 ++++----- .../Classification/Cluster_classification.cpp | 2 +- .../Point_set_item_classification.cpp | 2 +- .../Surface_mesh_item_classification.cpp | 2 +- .../Plugins/Display/Display_property.ui | 49 ++++++------------- .../Display/Display_property_plugin.cpp | 26 ---------- .../Point_set/Point_set_selection_plugin.cpp | 18 +++---- 9 files changed, 69 insertions(+), 93 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/CGAL_double_edit.cpp b/Polyhedron/demo/Polyhedron/CGAL_double_edit.cpp index 5536cafdd7d..5878b1ac3fe 100644 --- a/Polyhedron/demo/Polyhedron/CGAL_double_edit.cpp +++ b/Polyhedron/demo/Polyhedron/CGAL_double_edit.cpp @@ -2,13 +2,36 @@ #include - DoubleEdit::DoubleEdit(QWidget* parent = nullptr) - : QLineEdit(parent) + DoubleEdit::DoubleEdit(QWidget *parent) + : QLineEdit() { - QDoubleValidator* validator = new QDoubleValidator(parent); + validator = new QDoubleValidator(this); validator->setLocale(QLocale::C); this->setValidator(validator); } + DoubleEdit::~DoubleEdit() + { + delete validator; + } + double DoubleEdit::value() const + { + return this->text().toDouble(); + } + + void DoubleEdit::setValue(double d) + { + this->setText(tr("%1").arg(d)); + } + + void DoubleEdit::setMinimum(double d) + { + this->validator->setBottom(d); + } + + void DoubleEdit::setMaximum(double d) + { + this->validator->setTop(d); + } #include "CGAL_double_edit.moc" diff --git a/Polyhedron/demo/Polyhedron/CGAL_double_edit.h b/Polyhedron/demo/Polyhedron/CGAL_double_edit.h index eb458dae263..11794728757 100644 --- a/Polyhedron/demo/Polyhedron/CGAL_double_edit.h +++ b/Polyhedron/demo/Polyhedron/CGAL_double_edit.h @@ -12,11 +12,19 @@ # define CGAL_DOUBLE_EDIT_EXPORT Q_DECL_IMPORT #endif +class QDoubleValidator; class CGAL_DOUBLE_EDIT_EXPORT DoubleEdit : public QLineEdit { Q_OBJECT public: - DoubleEdit(QWidget *parent); + DoubleEdit(QWidget* parent = nullptr); + ~DoubleEdit(); + double value() const; + void setValue(double d); + void setMinimum(double d); + void setMaximum(double d); +private: + QDoubleValidator* validator; }; #endif // CGAL_DOUBLE_EDIT_H diff --git a/Polyhedron/demo/Polyhedron/Plugins/Classification/Classification_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Classification/Classification_plugin.cpp index b02c0e2f14d..d561a3d5323 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Classification/Classification_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Classification/Classification_plugin.cpp @@ -38,7 +38,7 @@ #include #include #include -#include +#include "CGAL_double_edit.h" #include #include @@ -619,17 +619,14 @@ public Q_SLOTS: scales->setRange (1, 99); scales->setValue (5); - QDoubleSpinBox* voxel_size = dialog.add ("Voxel size (0 for automatic):"); - voxel_size->setRange (0.0, 10000.0); - voxel_size->setValue (0.0); - voxel_size->setSingleStep (0.01); + DoubleEdit* voxel_size = dialog.add ("Voxel size (0 for automatic):"); if (dialog.exec() != QDialog::Accepted) return; QApplication::setOverrideCursor(Qt::WaitCursor); - float vsize = float(voxel_size->value()); + float vsize = float(voxel_size->text().toDouble()); if (vsize == 0.f) vsize = -1.f; // auto value @@ -921,10 +918,9 @@ public Q_SLOTS: subdivisions->setRange (1, 9999); subdivisions->setValue (16); - QDoubleSpinBox* smoothing = dialog.add ("Regularization weight: "); - smoothing->setRange (0.0, 100.0); - smoothing->setValue (0.5); - smoothing->setSingleStep (0.1); + DoubleEdit* smoothing = dialog.add ("Regularization weight: "); + + smoothing->setText(tr("%1").arg(0.5)); if (dialog.exec() != QDialog::Accepted) return; @@ -932,7 +928,7 @@ public Q_SLOTS: QApplication::setOverrideCursor(Qt::WaitCursor); CGAL::Real_timer t; t.start(); - run (classif, 2, std::size_t(subdivisions->value()), smoothing->value()); + run (classif, 2, std::size_t(subdivisions->value()), smoothing->text().toDouble()); t.stop(); std::cerr << "Graph Cut classification computed in " << t.time() << " second(s)" << std::endl; QApplication::restoreOverrideCursor(); @@ -1371,10 +1367,8 @@ public Q_SLOTS: QSpinBox* trials = dialog.add ("Number of trials: ", "trials"); trials->setRange (1, 99999); trials->setValue (500); - QDoubleSpinBox* rate = dialog.add ("Learning rate: ", "learning_rate"); - rate->setRange (0.00001, 10000.0); - rate->setValue (0.001); - rate->setDecimals (5); + DoubleEdit* rate = dialog.add ("Learning rate: ", "learning_rate"); + rate->setText(tr("%1").arg(0.001)); QSpinBox* batch = dialog.add ("Batch size: ", "batch_size"); batch->setRange (1, 2000000000); batch->setValue (1000); diff --git a/Polyhedron/demo/Polyhedron/Plugins/Classification/Cluster_classification.cpp b/Polyhedron/demo/Polyhedron/Plugins/Classification/Cluster_classification.cpp index d962e2f491d..2db5ec4b353 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Classification/Cluster_classification.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Classification/Cluster_classification.cpp @@ -910,7 +910,7 @@ void Cluster_classification::train(int classifier, const QMultipleInputDialog& d m_neural_network->train (training, dialog.get("restart")->isChecked(), dialog.get("trials")->value(), - dialog.get("learning_rate")->value(), + dialog.get("learning_rate")->value(), dialog.get("batch_size")->value(), hidden_layers); diff --git a/Polyhedron/demo/Polyhedron/Plugins/Classification/Point_set_item_classification.cpp b/Polyhedron/demo/Polyhedron/Plugins/Classification/Point_set_item_classification.cpp index aee56b923e6..feb5779e208 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Classification/Point_set_item_classification.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Classification/Point_set_item_classification.cpp @@ -800,7 +800,7 @@ void Point_set_item_classification::train(int classifier, const QMultipleInputDi m_neural_network->train (training, dialog.get("restart")->isChecked(), dialog.get("trials")->value(), - dialog.get("learning_rate")->value(), + dialog.get("learning_rate")->value(), dialog.get("batch_size")->value(), hidden_layers); diff --git a/Polyhedron/demo/Polyhedron/Plugins/Classification/Surface_mesh_item_classification.cpp b/Polyhedron/demo/Polyhedron/Plugins/Classification/Surface_mesh_item_classification.cpp index bdd3adbf9c5..2c032b631f9 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Classification/Surface_mesh_item_classification.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Classification/Surface_mesh_item_classification.cpp @@ -366,7 +366,7 @@ void Surface_mesh_item_classification::train (int classifier, const QMultipleInp m_neural_network->train (training, dialog.get("restart")->isChecked(), dialog.get("trials")->value(), - dialog.get("learning_rate")->value(), + dialog.get("learning_rate")->value(), dialog.get("batch_size")->value(), hidden_layers); diff --git a/Polyhedron/demo/Polyhedron/Plugins/Display/Display_property.ui b/Polyhedron/demo/Polyhedron/Plugins/Display/Display_property.ui index 2513e099a25..d79b215e714 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Display/Display_property.ui +++ b/Polyhedron/demo/Polyhedron/Plugins/Display/Display_property.ui @@ -110,44 +110,18 @@ - - - - - - 2.000000000000000 + + + 0,00 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Compute Ramp Extremas - - - Reset - - - false - - - - + + + 2,00 + + @@ -223,6 +197,13 @@ + + + DoubleEdit + QLineEdit +
CGAL_double_edit.h
+
+
diff --git a/Polyhedron/demo/Polyhedron/Plugins/Display/Display_property_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Display/Display_property_plugin.cpp index 71ffd20d3df..df09bc33f2d 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Display/Display_property_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Display/Display_property_plugin.cpp @@ -443,9 +443,6 @@ public: connect(dock_widget->deleteButton, &QPushButton::clicked, this, &DisplayPropertyPlugin::delete_group); - connect(dock_widget->resetButton, &QPushButton::pressed, - this, &DisplayPropertyPlugin::resetRampExtremas); - dock_widget->zoomToMaxButton->setEnabled(false); dock_widget->zoomToMinButton->setEnabled(false); Scene* scene_obj =static_cast(scene); @@ -464,29 +461,6 @@ private Q_SLOTS: dock_widget->raise(); } } - void resetRampExtremas() - { - Scene_surface_mesh_item* item = - qobject_cast(scene->item(scene->mainSelectionIndex())); - if(!item) - return; - QApplication::setOverrideCursor(Qt::WaitCursor); - item->face_graph()->collect_garbage(); - bool ok; - switch(dock_widget->propertyBox->currentIndex()) - { - case 0: - ok = resetAngles(item); - break; - default: - ok = resetScaledJacobian(item); - break; - } - QApplication::restoreOverrideCursor(); - if(!ok) - QMessageBox::warning(mw, "Error", "You must first run colorize once to initialize the values."); - } - void colorize() { Scene_heat_item* h_item = nullptr; diff --git a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_selection_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_selection_plugin.cpp index ebff326b116..45740cc84e3 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_selection_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_selection_plugin.cpp @@ -32,7 +32,7 @@ #include #include -#include +#include "CGAL_double_edit.h" #include #include @@ -821,19 +821,15 @@ protected Q_SLOTS: return; QMultipleInputDialog dialog ("Region Selection Parameters", mw); - QDoubleSpinBox* epsilon = dialog.add ("Epsilon: "); - epsilon->setRange (0.00001, 1000000.); - epsilon->setDecimals (5); + DoubleEdit* epsilon = dialog.add ("Epsilon: "); if (rg_epsilon < 0.) rg_epsilon = (std::max)(0.00001, 0.005 * scene->len_diagonal()); - epsilon->setValue (rg_epsilon); + epsilon->setText(tr("%1").arg(rg_epsilon)); - QDoubleSpinBox* cluster_epsilon = dialog.add ("Cluster epsilon: "); - cluster_epsilon->setRange (0.00001, 1000000.); - cluster_epsilon->setDecimals (5); + DoubleEdit* cluster_epsilon = dialog.add ("Cluster epsilon: "); if (rg_cluster_epsilon < 0.) rg_cluster_epsilon = (std::max)(0.00001, 0.03 * scene->len_diagonal()); - cluster_epsilon->setValue (rg_cluster_epsilon); + cluster_epsilon->setText(tr("%1").arg(rg_cluster_epsilon)); QSpinBox* normal_threshold = dialog.add ("Normal threshold: "); normal_threshold->setRange (0, 90); @@ -842,8 +838,8 @@ protected Q_SLOTS: if (dialog.exec()) { - rg_epsilon = epsilon->value(); - rg_cluster_epsilon = cluster_epsilon->value(); + rg_epsilon = epsilon->text().toDouble(); + rg_cluster_epsilon = cluster_epsilon->text().toDouble(); rg_normal_threshold = normal_threshold->value(); } }