diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Basic_generator_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PCA/Basic_generator_plugin.cpp index 672e4fb0f7a..d6025740c6a 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Basic_generator_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Basic_generator_plugin.cpp @@ -5,19 +5,37 @@ #include #include #include + #include #include + +#include +#include + +#include +#include + #include #include #include +#include + #include "Scene_surface_mesh_item.h" #include "Scene_points_with_normal_item.h" #include "Scene_polylines_item.h" -#include -#include -#include + #include "ui_Basic_generator_widget.h" +struct Face : public std::array +{ + Face(int i, int j, int k) + { + (*this)[0] = i; + (*this)[1] = j; + (*this)[2] = k; + } +}; + class GeneratorWidget : public QDockWidget, public Ui::BasicGenerator @@ -703,53 +721,85 @@ void Basic_generator_plugin::generateLines() } Q_FOREACH(QString s, list) { - if(!s.isEmpty()) + if(!s.isEmpty()) + { + double res = s.toDouble(&ok); + if(!ok) { - double res = s.toDouble(&ok); - if(!ok) - { - QMessageBox *msgBox = new QMessageBox; - msgBox->setWindowTitle("Error"); - msgBox->setText("ERROR : Coordinates are invalid."); - msgBox->exec(); - break; - } - else - { - coord[counter] = res; - counter++; - } + QMessageBox *msgBox = new QMessageBox; + msgBox->setWindowTitle("Error"); + msgBox->setText("ERROR : Coordinates are invalid."); + msgBox->exec(); + break; } - if(!dock_widget->polygon_checkBox->isChecked() && counter == 3) + else { - Scene_polylines_item::Point_3 p(coord[0], coord[1], coord[2]); - polyline.push_back(p); - counter =0; - } - else if(dock_widget->polygon_checkBox->isChecked() && counter == 2) - { - Scene_polylines_item::Point_3 p(coord[0], coord[1], 0); - polyline.push_back(p); - counter = 0; + coord[counter] = res; + counter++; } + } + if(!dock_widget->polygon_checkBox->isChecked() && counter == 3) + { + Scene_polylines_item::Point_3 p(coord[0], coord[1], coord[2]); + polyline.push_back(p); + counter =0; + } + else if(dock_widget->polygon_checkBox->isChecked() && counter == 2) + { + Scene_polylines_item::Point_3 p(coord[0], coord[1], 0); + polyline.push_back(p); + counter = 0; + } } if(dock_widget->polygon_checkBox->isChecked()) { polyline.push_back(polyline.front()); //polygon_2 are not closed. } - if(ok) + if(ok) + { + dock_widget->line_textEdit->clear(); + if(dock_widget->fill_checkBox->isChecked()) { - dock_widget->line_textEdit->clear(); - Scene_polylines_item* item = new Scene_polylines_item(); - item->polylines = polylines; - item->invalidateOpenGLBuffers(); - item->setName(dock_widget->name_lineEdit->text()); - item->setColor(Qt::black); - item->setProperty("polylines metadata", polylines_metadata); - item->invalidateOpenGLBuffers(); - Scene_interface::Item_id id = scene->addItem(item); - scene->setSelectedItem(id); + CGAL::Three::Three::CursorScopeGuard guard(Qt::WaitCursor); + QApplication::processEvents(); + if(polyline.front() != polyline.back()) { + polyline.push_back(polyline.front()); + } + if(polyline.size() < 4) { // no triangle, skip it (needs at least 3 + 1 repeat) + QMessageBox::warning(mw, "Warning", "Needs at least 3 points to triangulate. Aborting."); + return; + } + std::vector patch; + CGAL::Polygon_mesh_processing::triangulate_hole_polyline(polyline, + std::back_inserter(patch), + CGAL::Polygon_mesh_processing::parameters::use_delaunay_triangulation(true)); + + if(patch.empty()) { + QMessageBox::warning(mw, "Warning", "Triangulation failed."); + return; + } + SMesh* poly = new SMesh; + CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(polyline, + patch, + *poly); + + Scene_surface_mesh_item* poly_item = new Scene_surface_mesh_item(poly); + poly_item->setName(dock_widget->name_lineEdit->text()); + poly_item->setRenderingMode(FlatPlusEdges); + scene->setSelectedItem(scene->addItem(poly_item)); } + else + { + Scene_polylines_item* item = new Scene_polylines_item(); + item->polylines = polylines; + item->invalidateOpenGLBuffers(); + item->setName(dock_widget->name_lineEdit->text()); + item->setColor(Qt::black); + item->setProperty("polylines metadata", polylines_metadata); + Scene_interface::Item_id id = scene->addItem(item); + scene->setSelectedItem(id); + } + } } struct Point_generator diff --git a/Polyhedron/demo/Polyhedron/Plugins/PCA/Basic_generator_widget.ui b/Polyhedron/demo/Polyhedron/Plugins/PCA/Basic_generator_widget.ui index 865622d53a5..5d276e0149d 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PCA/Basic_generator_widget.ui +++ b/Polyhedron/demo/Polyhedron/Plugins/PCA/Basic_generator_widget.ui @@ -18,7 +18,7 @@ - 2 + 0 @@ -31,7 +31,7 @@ - :/cgal/Polyhedron_3/resources/prism.png + :/cgal/Polyhedron_3/resources/prism.png false @@ -223,7 +223,7 @@ QGroupBox::title { - :/cgal/Polyhedron_3/resources/icosphere.png + :/cgal/Polyhedron_3/resources/icosphere.png @@ -540,7 +540,7 @@ QGroupBox::title { - :/cgal/Polyhedron_3/resources/hexahedron.png + :/cgal/Polyhedron_3/resources/hexahedron.png false @@ -750,7 +750,7 @@ QGroupBox::title { - :/cgal/Polyhedron_3/resources/tetrahedron.png + :/cgal/Polyhedron_3/resources/tetrahedron.png @@ -881,7 +881,7 @@ QGroupBox::title { - :/cgal/Polyhedron_3/resources/grid.png + :/cgal/Polyhedron_3/resources/grid.png @@ -1050,7 +1050,7 @@ QGroupBox::title { <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:10pt;"><br /></p></body></html> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"><br /></p></body></html> false @@ -1068,11 +1068,22 @@ p, li { white-space: pre-wrap; } - - - From Polygon_2 - - + + + + + From Polygon_2 + + + + + + + Triangulate + + + + @@ -1087,7 +1098,7 @@ p, li { white-space: pre-wrap; } <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:10pt;"><br /></p></body></html> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"><br /></p></body></html> false @@ -1172,6 +1183,9 @@ p, li { white-space: pre-wrap; }
CGAL_double_edit.h
- + + + +