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
@ -740,17 +758,49 @@ void Basic_generator_plugin::generateLines()
if(ok) if(ok)
{ {
dock_widget->line_textEdit->clear(); dock_widget->line_textEdit->clear();
if(dock_widget->fill_checkBox->isChecked())
{
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<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(); Scene_polylines_item* item = new Scene_polylines_item();
item->polylines = polylines; item->polylines = polylines;
item->invalidateOpenGLBuffers(); item->invalidateOpenGLBuffers();
item->setName(dock_widget->name_lineEdit->text()); item->setName(dock_widget->name_lineEdit->text());
item->setColor(Qt::black); item->setColor(Qt::black);
item->setProperty("polylines metadata", polylines_metadata); item->setProperty("polylines metadata", polylines_metadata);
item->invalidateOpenGLBuffers();
Scene_interface::Item_id id = scene->addItem(item); Scene_interface::Item_id id = scene->addItem(item);
scene->setSelectedItem(id); 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>
@ -1067,6 +1067,8 @@ p, li { white-space: pre-wrap; }
<string>Polyline</string> <string>Polyline</string>
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_6"> <layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_23">
<item> <item>
<widget class="QCheckBox" name="polygon_checkBox"> <widget class="QCheckBox" name="polygon_checkBox">
<property name="text"> <property name="text">
@ -1074,6 +1076,15 @@ p, li { white-space: pre-wrap; }
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="fill_checkBox">
<property name="text">
<string>Triangulate</string>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<widget class="QTextEdit" name="line_textEdit"> <widget class="QTextEdit" name="line_textEdit">
<property name="sizePolicy"> <property name="sizePolicy">
@ -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>