Merge pull request #5018 from maxGimeno/Demo-Add_simply_connected_polygon_generator-maxGimeno

Polyhedron Demo: Add an option to the polyline generator
This commit is contained in:
Laurent Rineau 2020-09-25 15:34:23 +02:00
commit ad93ce0175
2 changed files with 117 additions and 53 deletions

View File

@ -5,19 +5,37 @@
#include <QMessageBox> #include <QMessageBox>
#include <QBitmap> #include <QBitmap>
#include <QTabBar> #include <QTabBar>
#include <CGAL/boost/graph/helpers.h> #include <CGAL/boost/graph/helpers.h>
#include <CGAL/boost/graph/Euler_operations.h> #include <CGAL/boost/graph/Euler_operations.h>
#include <CGAL/subdivision_method_3.h>
#include <CGAL/Kernel_traits.h>
#include <CGAL/Polygon_mesh_processing/triangulate_hole.h>
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
#include <CGAL/Three/Scene_item.h> #include <CGAL/Three/Scene_item.h>
#include <CGAL/Three/Viewer_interface.h> #include <CGAL/Three/Viewer_interface.h>
#include <CGAL/Three/Polyhedron_demo_plugin_helper.h> #include <CGAL/Three/Polyhedron_demo_plugin_helper.h>
#include <CGAL/Three/Three.h>
#include "Scene_surface_mesh_item.h" #include "Scene_surface_mesh_item.h"
#include "Scene_points_with_normal_item.h" #include "Scene_points_with_normal_item.h"
#include "Scene_polylines_item.h" #include "Scene_polylines_item.h"
#include <CGAL/subdivision_method_3.h>
#include <CGAL/Kernel_traits.h>
#include <CGAL/Three/Three.h>
#include "ui_Basic_generator_widget.h" #include "ui_Basic_generator_widget.h"
struct Face : public std::array<int,3>
{
Face(int i, int j, int k)
{
(*this)[0] = i;
(*this)[1] = j;
(*this)[2] = k;
}
};
class GeneratorWidget : class GeneratorWidget :
public QDockWidget, public QDockWidget,
public Ui::BasicGenerator public Ui::BasicGenerator
@ -703,53 +721,85 @@ void Basic_generator_plugin::generateLines()
} }
Q_FOREACH(QString s, list) Q_FOREACH(QString s, list)
{ {
if(!s.isEmpty()) if(!s.isEmpty())
{
double res = s.toDouble(&ok);
if(!ok)
{ {
double res = s.toDouble(&ok); QMessageBox *msgBox = new QMessageBox;
if(!ok) msgBox->setWindowTitle("Error");
{ msgBox->setText("ERROR : Coordinates are invalid.");
QMessageBox *msgBox = new QMessageBox; msgBox->exec();
msgBox->setWindowTitle("Error"); break;
msgBox->setText("ERROR : Coordinates are invalid.");
msgBox->exec();
break;
}
else
{
coord[counter] = res;
counter++;
}
} }
if(!dock_widget->polygon_checkBox->isChecked() && counter == 3) else
{ {
Scene_polylines_item::Point_3 p(coord[0], coord[1], coord[2]); coord[counter] = res;
polyline.push_back(p); counter++;
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() && 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()) if(dock_widget->polygon_checkBox->isChecked())
{ {
polyline.push_back(polyline.front()); //polygon_2 are not closed. 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(); CGAL::Three::Three::CursorScopeGuard guard(Qt::WaitCursor);
Scene_polylines_item* item = new Scene_polylines_item(); QApplication::processEvents();
item->polylines = polylines; if(polyline.front() != polyline.back()) {
item->invalidateOpenGLBuffers(); polyline.push_back(polyline.front());
item->setName(dock_widget->name_lineEdit->text()); }
item->setColor(Qt::black); if(polyline.size() < 4) { // no triangle, skip it (needs at least 3 + 1 repeat)
item->setProperty("polylines metadata", polylines_metadata); QMessageBox::warning(mw, "Warning", "Needs at least 3 points to triangulate. Aborting.");
item->invalidateOpenGLBuffers(); return;
Scene_interface::Item_id id = scene->addItem(item); }
scene->setSelectedItem(id); std::vector<Face> 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 struct Point_generator

View File

@ -18,7 +18,7 @@
<item> <item>
<widget class="QTabWidget" name="selector_tabWidget"> <widget class="QTabWidget" name="selector_tabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>2</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="prismTab"> <widget class="QWidget" name="prismTab">
<attribute name="title"> <attribute name="title">
@ -31,7 +31,7 @@
<string/> <string/>
</property> </property>
<property name="pixmap"> <property name="pixmap">
<pixmap>:/cgal/Polyhedron_3/resources/prism.png</pixmap> <pixmap resource="../../Polyhedron_3.qrc">:/cgal/Polyhedron_3/resources/prism.png</pixmap>
</property> </property>
<property name="scaledContents"> <property name="scaledContents">
<bool>false</bool> <bool>false</bool>
@ -223,7 +223,7 @@ QGroupBox::title {
<string/> <string/>
</property> </property>
<property name="pixmap"> <property name="pixmap">
<pixmap>:/cgal/Polyhedron_3/resources/icosphere.png</pixmap> <pixmap resource="../../Polyhedron_3.qrc">:/cgal/Polyhedron_3/resources/icosphere.png</pixmap>
</property> </property>
</widget> </widget>
</item> </item>
@ -540,7 +540,7 @@ QGroupBox::title {
<string/> <string/>
</property> </property>
<property name="pixmap"> <property name="pixmap">
<pixmap>:/cgal/Polyhedron_3/resources/hexahedron.png</pixmap> <pixmap resource="../../Polyhedron_3.qrc">:/cgal/Polyhedron_3/resources/hexahedron.png</pixmap>
</property> </property>
<property name="scaledContents"> <property name="scaledContents">
<bool>false</bool> <bool>false</bool>
@ -750,7 +750,7 @@ QGroupBox::title {
<string/> <string/>
</property> </property>
<property name="pixmap"> <property name="pixmap">
<pixmap>:/cgal/Polyhedron_3/resources/tetrahedron.png</pixmap> <pixmap resource="../../Polyhedron_3.qrc">:/cgal/Polyhedron_3/resources/tetrahedron.png</pixmap>
</property> </property>
</widget> </widget>
</item> </item>
@ -881,7 +881,7 @@ QGroupBox::title {
<string/> <string/>
</property> </property>
<property name="pixmap"> <property name="pixmap">
<pixmap>:/cgal/Polyhedron_3/resources/grid.png</pixmap> <pixmap resource="../../Polyhedron_3.qrc">:/cgal/Polyhedron_3/resources/grid.png</pixmap>
</property> </property>
</widget> </widget>
</item> </item>
@ -1050,7 +1050,7 @@ QGroupBox::title {
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt; &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; } p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt; &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-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;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> &lt;p style=&quot;-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;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="overwriteMode"> <property name="overwriteMode">
<bool>false</bool> <bool>false</bool>
@ -1068,11 +1068,22 @@ p, li { white-space: pre-wrap; }
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_6"> <layout class="QVBoxLayout" name="verticalLayout_6">
<item> <item>
<widget class="QCheckBox" name="polygon_checkBox"> <layout class="QHBoxLayout" name="horizontalLayout_23">
<property name="text"> <item>
<string>From Polygon_2</string> <widget class="QCheckBox" name="polygon_checkBox">
</property> <property name="text">
</widget> <string>From Polygon_2</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="fill_checkBox">
<property name="text">
<string>Triangulate</string>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<widget class="QTextEdit" name="line_textEdit"> <widget class="QTextEdit" name="line_textEdit">
@ -1087,7 +1098,7 @@ p, li { white-space: pre-wrap; }
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt; &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; } p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt; &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-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;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> &lt;p style=&quot;-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;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="overwriteMode"> <property name="overwriteMode">
<bool>false</bool> <bool>false</bool>
@ -1172,6 +1183,9 @@ p, li { white-space: pre-wrap; }
<header>CGAL_double_edit.h</header> <header>CGAL_double_edit.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources/> <resources>
<include location="../../Polyhedron_3.qrc"/>
<include location="../../Polyhedron_3.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>