From fe10859e655a3ba0cd68467ee2a033d3d60b3a6b Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 27 Jul 2018 16:05:41 +0200 Subject: [PATCH] Add an action to Affine_transformation_plugin that duplicates a selected item on a grid --- .../Plugins/PCA/Affine_transform_plugin.cpp | 103 +++++++- .../Polyhedron/Plugins/PCA/CMakeLists.txt | 2 +- .../Plugins/PCA/MeshOnGrid_dialog.ui | 229 ++++++++++++++++++ 3 files changed, 326 insertions(+), 8 deletions(-) create mode 100644 Polyhedron/demo/Polyhedron/Plugins/PCA/MeshOnGrid_dialog.ui diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Affine_transform_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PCA/Affine_transform_plugin.cpp index 0d7445f7796..37c5e692017 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Affine_transform_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Affine_transform_plugin.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #ifdef CGAL_USE_SURFACE_MESH #include "Scene_surface_mesh_item.h" #else @@ -19,11 +20,13 @@ #include #include #include +#include #include #include #include #include "ui_Transformation_widget.h" +#include "ui_MeshOnGrid_dialog.h" #ifdef CGAL_USE_SURFACE_MESH typedef Scene_surface_mesh_item Facegraph_item; #else @@ -173,15 +176,21 @@ public: Polyhedron_demo_affine_transform_plugin():started(false){} QList actions() const { - return QList() << actionTransformPolyhedron; + return QList() << actionTransformPolyhedron + << actionMeshOnGrid; } - bool applicable(QAction*) const { - return qobject_cast(scene->item(scene->mainSelectionIndex())) - || qobject_cast(scene->item(scene->mainSelectionIndex())) + bool applicable(QAction* a) const { + if(a == actionMeshOnGrid) + { + return qobject_cast(scene->item(scene->mainSelectionIndex())); + } + else + return qobject_cast(scene->item(scene->mainSelectionIndex())) + || qobject_cast(scene->item(scene->mainSelectionIndex())) #ifdef CGAL_USE_SURFACE_MESH - || qobject_cast(scene->item(scene->mainSelectionIndex())) - || qobject_cast(scene->item(scene->mainSelectionIndex())) + || qobject_cast(scene->item(scene->mainSelectionIndex())) + || qobject_cast(scene->item(scene->mainSelectionIndex())) #endif ; } @@ -196,6 +205,16 @@ public: mw = _mw; this->scene = scene_interface; + actionMeshOnGrid = new QAction( + #ifdef CGAL_USE_SURFACE_MESH + tr("Create a Grid of Surface Meshes") + #else + tr("Create a Grid of Polyhedra") + #endif + , mw); + if(actionMeshOnGrid) { + connect(actionMeshOnGrid, SIGNAL(triggered()),this, SLOT(grid())); + } actionTransformPolyhedron = new QAction( #ifdef CGAL_USE_SURFACE_MESH @@ -259,10 +278,10 @@ public: } private: - QDockWidget* dock_widget; Ui::TransformationWidget ui; QAction* actionTransformPolyhedron; + QAction* actionMeshOnGrid; Scene_facegraph_transform_item* transform_item; Scene_transform_point_set_item* transform_points_item; CGAL::Three::Scene_interface::Item_id tr_item_index; @@ -306,6 +325,7 @@ private: template void normalize(Item*); public Q_SLOTS: + void grid(); void go(); void transformed_killed(); @@ -388,6 +408,75 @@ public Q_SLOTS: }; // end class Polyhedron_demo_affine_transform_plugin +class GridDialog : + public QDialog, + public Ui::GridDialog +{ + Q_OBJECT +public: + GridDialog(QWidget* =0) + { + setupUi(this); + } +}; + +void Polyhedron_demo_affine_transform_plugin::grid() +{ + Facegraph_item* item = + qobject_cast(scene->item(scene->mainSelectionIndex())); + if(!item) + return; + + + FaceGraph m = *item->face_graph(); + + Scene_item::Bbox b = item->bbox(); + + + double x_t(CGAL::sqrt(CGAL::squared_distance(Kernel::Point_3(b.min(0), b.min(1), b.min(2)), + Kernel::Point_3(b.max(0), b.min(1), b.min(2))))), + y_t(CGAL::sqrt(CGAL::squared_distance(Kernel::Point_3(b.min(0), b.min(1), b.min(2)), + Kernel::Point_3(b.min(0), b.max(1), b.min(2))))), + z_t(CGAL::sqrt(CGAL::squared_distance(Kernel::Point_3(b.min(0), b.min(1), b.min(2)), + Kernel::Point_3(b.min(0), b.min(1), b.max(2))))); + + GridDialog dialog(mw); + dialog.x_space_doubleSpinBox->setValue(x_t); + dialog.y_space_doubleSpinBox->setValue(y_t); + dialog.z_space_doubleSpinBox->setValue(z_t); + if(!dialog.exec()) + return; + QApplication::setOverrideCursor(Qt::WaitCursor); + int i_max=dialog.x_spinBox->value(), + j_max=dialog.y_spinBox->value(), + k_max=dialog.z_spinBox->value(); + x_t = dialog.x_space_doubleSpinBox->value(); + y_t = dialog.y_space_doubleSpinBox->value(); + z_t = dialog.z_space_doubleSpinBox->value(); + + for(int i = 0; i < i_max; ++i) + { + for(int j = 0; j< j_max; ++j) + { + for(int k = 0; k< k_max; ++k) + { + FaceGraph e; + CGAL::copy_face_graph(m,e); + + Kernel::Aff_transformation_3 trans(CGAL::TRANSLATION, Kernel::Vector_3(i*x_t,j*y_t,k*z_t)); + CGAL::Polygon_mesh_processing::transform(trans, e); + Facegraph_item* t_item = new Facegraph_item(e); + t_item->setName(tr("%1 %2%3%4") + .arg(item->name()) + .arg(i) + .arg(j) + .arg(k)); + scene->addItem(t_item); + } + } + } + QApplication::restoreOverrideCursor(); +} void Polyhedron_demo_affine_transform_plugin::go(){ if (!started){ Scene_item* item = scene->item(scene->mainSelectionIndex()); diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/CMakeLists.txt b/Polyhedron/demo/Polyhedron/Plugins/PCA/CMakeLists.txt index 978cbfa2c0b..43974e0709e 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/CMakeLists.txt @@ -2,7 +2,7 @@ include( polyhedron_demo_macros ) polyhedron_demo_plugin(pca_plugin Pca_plugin) target_link_libraries(pca_plugin PUBLIC scene_polyhedron_item scene_surface_mesh_item scene_points_with_normal_item scene_basic_objects) -qt5_wrap_ui( transformUI_FILES Transformation_widget.ui ) +qt5_wrap_ui( transformUI_FILES Transformation_widget.ui MeshOnGrid_dialog.ui) polyhedron_demo_plugin(affine_transform_plugin Affine_transform_plugin ${transformUI_FILES}) target_link_libraries(affine_transform_plugin PUBLIC scene_polyhedron_item scene_polyhedron_transform_item scene_points_with_normal_item) diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/MeshOnGrid_dialog.ui b/Polyhedron/demo/Polyhedron/Plugins/PCA/MeshOnGrid_dialog.ui new file mode 100644 index 00000000000..3613737b207 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/MeshOnGrid_dialog.ui @@ -0,0 +1,229 @@ + + + GridDialog + + + + 0 + 0 + 227 + 486 + + + + + 0 + 0 + + + + Dialog + + + + + + Along X + + + + + + 99999999999999999475366575191804932315794610450682175621941694731908308538307845136842752.000000000000000 + + + + + + + Spacing: + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Number of items : + + + + + + + 999 + + + 2 + + + + + + + + + + Along Y + + + + + + 99999999999999999475366575191804932315794610450682175621941694731908308538307845136842752.000000000000000 + + + + + + + Spacing: + + + + + + + 999 + + + 2 + + + + + + + Number of items : + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Along Z + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 99999999999999999475366575191804932315794610450682175621941694731908308538307845136842752.000000000000000 + + + + + + + Number of items : + + + + + + + Spacing: + + + + + + + 999 + + + 2 + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + GridDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + GridDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +