mirror of https://github.com/CGAL/cgal
Merge pull request #8291 from sloriot/Lab-improve_gen_polylines
Improve generation of polylines
This commit is contained in:
commit
afb78c35be
|
|
@ -732,29 +732,30 @@ void Basic_generator_plugin::generateLines()
|
|||
{
|
||||
QString text = dock_widget->line_textEdit->toPlainText();
|
||||
std::list<std::vector<Scene_polylines_item::Point_3> > polylines;
|
||||
polylines.resize(polylines.size()+1);
|
||||
std::vector<Scene_polylines_item::Point_3>& polyline = *(polylines.rbegin());
|
||||
QStringList polylines_metadata;
|
||||
|
||||
QStringList list = text.split(QRegularExpression("\\s+"), CGAL_QT_SKIP_EMPTY_PARTS);
|
||||
int counter = 0;
|
||||
auto read_polyline = [&polylines](const QStringList& list, bool is_2d, bool is_closed)
|
||||
{
|
||||
int counter = -1;
|
||||
double coord[3];
|
||||
bool ok = true;
|
||||
if (list.isEmpty()) return;
|
||||
if(!dock_widget->polygon_checkBox->isChecked() && list.size()%3!=0){
|
||||
|
||||
if(!is_2d && list.size()%3!=0){
|
||||
QMessageBox *msgBox = new QMessageBox;
|
||||
msgBox->setWindowTitle("Error");
|
||||
msgBox->setText("ERROR : Input should consists of triplets.");
|
||||
msgBox->exec();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
else if(dock_widget->polygon_checkBox->isChecked()&& list.size()%2!=0){
|
||||
else if(is_2d && list.size()%2!=0){
|
||||
QMessageBox *msgBox = new QMessageBox;
|
||||
msgBox->setWindowTitle("Error");
|
||||
msgBox->setText("ERROR : Input should consists of pairs.");
|
||||
msgBox->exec();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
polylines.back().reserve(list.size()+(is_closed?1:0));
|
||||
|
||||
for(QString s : list)
|
||||
{
|
||||
if(!s.isEmpty())
|
||||
|
|
@ -766,45 +767,81 @@ void Basic_generator_plugin::generateLines()
|
|||
msgBox->setWindowTitle("Error");
|
||||
msgBox->setText("ERROR : Coordinates are invalid.");
|
||||
msgBox->exec();
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
coord[counter] = res;
|
||||
counter++;
|
||||
coord[++counter] = res;
|
||||
}
|
||||
}
|
||||
if(!dock_widget->polygon_checkBox->isChecked() && counter == 3)
|
||||
if(!is_2d && counter == 2)
|
||||
{
|
||||
Scene_polylines_item::Point_3 p(coord[0], coord[1], coord[2]);
|
||||
polyline.push_back(p);
|
||||
counter =0;
|
||||
polylines.back().push_back(p);
|
||||
counter=-1;
|
||||
}
|
||||
else if(dock_widget->polygon_checkBox->isChecked() && counter == 2)
|
||||
else if(is_2d && counter == 1)
|
||||
{
|
||||
Scene_polylines_item::Point_3 p(coord[0], coord[1], 0);
|
||||
polyline.push_back(p);
|
||||
counter = 0;
|
||||
polylines.back().push_back(p);
|
||||
counter=-1;
|
||||
}
|
||||
}
|
||||
if(dock_widget->polygon_checkBox->isChecked())
|
||||
if(is_closed)
|
||||
{
|
||||
polyline.push_back(polyline.front()); //polygon_2 are not closed.
|
||||
if (polylines.back().back()!=polylines.back().front())
|
||||
polylines.back().push_back(polylines.back().front()); //close if not already closed
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const bool is_2d = dock_widget->dim2_checkBox->isChecked();
|
||||
const bool is_closed = dock_widget->polygon_checkBox->isChecked();
|
||||
const bool shall_fill = is_closed && dock_widget->fill_checkBox->isChecked();
|
||||
const bool oneperline = dock_widget->oneperline_checkBox->isChecked();
|
||||
|
||||
bool ok = true;
|
||||
if (oneperline)
|
||||
{
|
||||
QStringList poly_list = text.split(QRegularExpression("\\n"), CGAL_QT_SKIP_EMPTY_PARTS);
|
||||
if (poly_list.empty()) return;
|
||||
|
||||
for(const QString& qs : poly_list)
|
||||
{
|
||||
QStringList list = qs.split(QRegularExpression("\\s+"), CGAL_QT_SKIP_EMPTY_PARTS);
|
||||
if (list.isEmpty()) continue;
|
||||
polylines.emplace_back();
|
||||
ok = read_polyline(list, is_2d, is_closed);
|
||||
if (!ok) return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QStringList list = text.split(QRegularExpression("\\s+"), CGAL_QT_SKIP_EMPTY_PARTS);
|
||||
if (list.isEmpty()) return;
|
||||
polylines.emplace_back();
|
||||
ok = read_polyline(list, is_2d, is_closed);
|
||||
if (!ok) return;
|
||||
}
|
||||
|
||||
if(ok)
|
||||
{
|
||||
dock_widget->line_textEdit->clear();
|
||||
if(dock_widget->fill_checkBox->isChecked())
|
||||
if(shall_fill)
|
||||
{
|
||||
CGAL::Three::Three::CursorScopeGuard guard(Qt::WaitCursor);
|
||||
QApplication::processEvents();
|
||||
if(polyline.front() != polyline.back()) {
|
||||
polyline.push_back(polyline.front());
|
||||
}
|
||||
|
||||
SMesh* poly = new SMesh;
|
||||
for (const auto& polyline : polylines)
|
||||
{
|
||||
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.");
|
||||
delete poly;
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<Face> patch;
|
||||
CGAL::Polygon_mesh_processing::triangulate_hole_polyline(polyline,
|
||||
std::back_inserter(patch),
|
||||
|
|
@ -814,10 +851,11 @@ void Basic_generator_plugin::generateLines()
|
|||
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());
|
||||
|
|
@ -831,6 +869,7 @@ void Basic_generator_plugin::generateLines()
|
|||
item->invalidateOpenGLBuffers();
|
||||
item->setName(dock_widget->name_lineEdit->text());
|
||||
item->setColor(Qt::black);
|
||||
QStringList polylines_metadata;
|
||||
item->setProperty("polylines metadata", polylines_metadata);
|
||||
Scene_interface::Item_id id = scene->addItem(item);
|
||||
scene->setSelectedItem(id);
|
||||
|
|
|
|||
|
|
@ -1101,20 +1101,37 @@ li.checked::marker { content: "\2612"; }
|
|||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_23">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="dim2_checkBox">
|
||||
<property name="text">
|
||||
<string>2D</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="polygon_checkBox">
|
||||
<property name="text">
|
||||
<string>From Polygon_2</string>
|
||||
<string>Polygon(s)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="fill_checkBox">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Triangulate</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="oneperline_checkBox">
|
||||
<property name="text">
|
||||
<string>One Per Line</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
|
@ -1222,5 +1239,22 @@ li.checked::marker { content: "\2612"; }
|
|||
<include location="../../CGALlab.qrc"/>
|
||||
<include location="../../CGALlab.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>polygon_checkBox</sender>
|
||||
<signal>stateChanged(int)</signal>
|
||||
<receiver>fill_checkBox</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>190</x>
|
||||
<y>83</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>534</x>
|
||||
<y>83</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
|
|
|
|||
Loading…
Reference in New Issue