Skip to content

Lab - add polylines to selection of edges #8411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 70 additions & 29 deletions Lab/demo/Lab/Plugins/IO/Polylines_io_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ class CGAL_Lab_polylines_io_plugin :

}
QString name() const override{ return "polylines_io_plugin"; }
QString nameFilters() const override{ return "Polylines files (*.polylines.txt);; CGAL Polylines files (*.cgal)"; }
QString nameFilters() const override
{
return "Polylines files (*.polylines.txt);; CGAL Polylines files (*.cgal);; Txt polylines files (*.txt)";
}
bool canLoad(QFileInfo fileinfo) const override;
QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true) override;

Expand Down Expand Up @@ -135,7 +138,9 @@ bool CGAL_Lab_polylines_io_plugin::canLoad(QFileInfo fileinfo) const{

QList<Scene_item*>
CGAL_Lab_polylines_io_plugin::
load(QFileInfo fileinfo, bool& ok, bool add_to_scene){
load(QFileInfo fileinfo, bool& ok, bool add_to_scene)
{
using Pt = Scene_polylines_item::Point_3;

// Open file
std::ifstream ifs(fileinfo.filePath().toUtf8());
Expand All @@ -158,42 +163,78 @@ load(QFileInfo fileinfo, bool& ok, bool add_to_scene){

std::list<std::vector<Scene_polylines_item::Point_3> > polylines;
QStringList polylines_metadata;

int counter = 0;
std::size_t n;
while(ifs >> n) {
++counter;
std::vector<Scene_polylines_item::Point_3> new_polyline;
polylines.push_back(new_polyline);
std::vector<Scene_polylines_item::Point_3>&polyline = polylines.back();
polyline.reserve(n);
while(n--){
Scene_polylines_item::Point_3 p;
ifs >> p;
polyline.push_back(p);
if(!ifs.good())

QString extension = fileinfo.completeSuffix();
if(extension == "polylines.txt" || extension == "cgal")
{
std::size_t n;
while(ifs >> n) {
++counter;
std::vector<Scene_polylines_item::Point_3> new_polyline;
polylines.push_back(new_polyline);
std::vector<Scene_polylines_item::Point_3>&polyline = polylines.back();
polyline.reserve(n);
while(n--){
Scene_polylines_item::Point_3 p;
ifs >> p;
polyline.push_back(p);
if(!ifs.good())
{
ok = false;
return QList<Scene_item*>();
}
}
std::string line_remainder;
std::getline(ifs, line_remainder);
QString metadata(line_remainder.c_str());
if(!metadata.isEmpty() && metadata[0].isSpace()) {
metadata.remove(0, 1);
}
polylines_metadata << metadata;
if(!metadata.isEmpty()) {
std::cerr << " (metadata: \"" << qPrintable(metadata) << "\")\n";
} else {
}
if(ifs.bad() || ifs.fail())
{
ok = false;
return QList<Scene_item*>();
}
}
std::string line_remainder;
std::getline(ifs, line_remainder);
QString metadata(line_remainder.c_str());
if(!metadata.isEmpty() && metadata[0].isSpace()) {
metadata.remove(0, 1);
}
polylines_metadata << metadata;
if(!metadata.isEmpty()) {
std::cerr << " (metadata: \"" << qPrintable(metadata) << "\")\n";
} else {
}
if(ifs.bad() || ifs.fail())
}
else if (extension == "txt")
{
std::string line;
while (std::getline(ifs, line))
{
ok = false;
return QList<Scene_item*>();
++counter;
//each line is : "x1, y1, z1, x2, y2, z2"
std::istringstream tokenizer(line);

std::array<std::string, 3> p_s; //point p as string
std::getline(tokenizer, p_s[0], ',');
std::getline(tokenizer, p_s[1], ',');
std::getline(tokenizer, p_s[2], ',');

std::array<std::string, 3> q_s; //point q as string
std::getline(tokenizer, q_s[0], ',');
std::getline(tokenizer, q_s[1], ',');
std::getline(tokenizer, q_s[2]);
if (tokenizer)
{
Pt p(std::stod(p_s[0]), std::stod(p_s[1]), std::stod(p_s[2]));
Pt q(std::stod(q_s[0]), std::stod(q_s[1]), std::stod(q_s[2]));
polylines.push_back({ p, q });
}
else
{
std::cerr << "Error reading line " << line << std::endl;
// There were fewer colons then expected in the line
}
}
}

if(counter == 0)
{
ok = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ cgal_lab_plugin(clip_polyhedron_plugin Clip_polyhedron_plugin
${clip_polyhedronUI_FILES})
target_link_libraries(
clip_polyhedron_plugin PUBLIC scene_surface_mesh_item scene_basic_objects
scene_selection_item
scene_movable_sm_item)

cgal_lab_plugin(point_set_from_vertices_plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
#include <QMessageBox>
#include "Scene_surface_mesh_item.h"
#include "Scene_plane_item.h"
#include "Scene_polyhedron_selection_item.h"
#include <CGAL/Three/Viewer_interface.h>
#include <CGAL/Three/Triangle_container.h>
#include <CGAL/Three/Three.h>
#include <CGAL/Three/CGAL_Lab_plugin_interface.h>
#include <CGAL/Three/CGAL_Lab_plugin_helper.h>
#include <CGAL/Three/Three.h>
#include <CGAL/Polygon_mesh_processing/clip.h>
#include <CGAL/Polygon_mesh_processing/corefinement.h>
#include "Plugins/AABB_tree/Scene_movable_sm_item.h"
#include <CGAL/Polygon_mesh_processing/transform.h>

Expand Down Expand Up @@ -79,22 +82,26 @@ class Scene_clipping_plane_item : public Scene_plane_item

class Q_DECL_EXPORT Clip_cgal_lab_plugin :
public QObject,
public CGAL::Three::CGAL_Lab_plugin_interface
public CGAL_Lab_plugin_helper
{
Q_OBJECT
Q_INTERFACES(CGAL::Three::CGAL_Lab_plugin_interface)
Q_PLUGIN_METADATA(IID "com.geometryfactory.CGALLab.PluginInterface/1.0")

public :
// Adds an action to the menu and configures the widget
void init(QMainWindow* mw,
CGAL::Three::Scene_interface* scene_interface,
Messages_interface* mi) {
Messages_interface* mi)
{
//get the references
this->scene = scene_interface;
this->mw = mw;
this->messages = mi;
plane = nullptr;
clipper_item = nullptr;
original_clipper = nullptr;

//creates and link the actions
actionClipPolyhedra = new QAction("Clip Polyhedra With Plane", mw);
actionClipPolyhedra->setProperty("subMenuName","Polygon Mesh Processing/Corefinement");
Expand Down Expand Up @@ -254,13 +261,13 @@ public Q_SLOTS:
if(sm_item)
{
CGAL::Polygon_mesh_processing::clip(*(sm_item->face_graph()),
plane->plane(),
CGAL::parameters::clip_volume(
ui_widget.close_checkBox->isChecked()).
throw_on_self_intersection(true).
use_compact_clipper(
!ui_widget.coplanarCheckBox->isChecked())
.allow_self_intersections(ui_widget.do_not_modify_CheckBox->isChecked()));
plane->plane(),
CGAL::parameters::clip_volume(
ui_widget.close_checkBox->isChecked()).
throw_on_self_intersection(true).
use_compact_clipper(
!ui_widget.coplanarCheckBox->isChecked())
.allow_self_intersections(ui_widget.do_not_modify_CheckBox->isChecked()));
}
}
catch(const CGAL::Polygon_mesh_processing::Corefinement::Self_intersection_exception&)
Expand Down Expand Up @@ -408,19 +415,79 @@ public Q_SLOTS:
{
if(sm_item)
{
try {
CGAL::Polygon_mesh_processing::clip(*(sm_item->face_graph()),
clipper,
CGAL::parameters::clip_volume(
ui_widget.close_checkBox->isChecked()).
throw_on_self_intersection(true).
use_compact_clipper(
!ui_widget.coplanarCheckBox->isChecked()),
CGAL::parameters::do_not_modify(ui_widget.do_not_modify_CheckBox->isChecked()));
Scene_polyhedron_selection_item* selection = nullptr;
for (int id : scene->selectionIndices())
{
Scene_polyhedron_selection_item* tmp
= qobject_cast<Scene_polyhedron_selection_item*>(scene->item(id));
if (tmp != nullptr && tmp->polyhedron_item() == sm_item)
{
selection = tmp;
break;
}
}
catch(const CGAL::Polygon_mesh_processing::Corefinement::Self_intersection_exception&)

if (selection == nullptr)
{
CGAL::Three::Three::warning(tr("The requested operation is not possible due to the presence of self-intersections in the region handled."));
try {
CGAL::Polygon_mesh_processing::clip(*(sm_item->face_graph()),
clipper,
CGAL::parameters::clip_volume(
ui_widget.close_checkBox->isChecked()).
throw_on_self_intersection(true).
use_compact_clipper(
!ui_widget.coplanarCheckBox->isChecked()),
CGAL::parameters::do_not_modify(ui_widget.do_not_modify_CheckBox->isChecked()));
}
catch(const CGAL::Polygon_mesh_processing::Corefinement::Self_intersection_exception&)
{
CGAL::Three::Three::warning(tr("The requested operation is not possible due to the presence of self-intersections in the region handled."));
}
}
else
{
SMesh* tm_out = new SMesh();
auto ecmap_out = tm_out->add_property_map<fg_edge_descriptor, bool>("ecmap", false).first;

try {
bool success = CGAL::Polygon_mesh_processing::corefine_and_compute_intersection(*(sm_item->face_graph()),
clipper,
*tm_out,
CGAL::parameters::edge_is_constrained_map(selection->constrained_edges_pmap()),
CGAL::parameters::default_values(),
CGAL::parameters::edge_is_constrained_map(ecmap_out));

if (!success)
CGAL::Three::Three::warning(tr("corefine_and_compute_intersection() did not fully succeed"));
}
catch (const CGAL::Polygon_mesh_processing::Corefinement::Self_intersection_exception&)
{
CGAL::Three::Three::warning(tr("The requested operation is not possible due to the presence of self-intersections in the region handled."));
}

Scene_surface_mesh_item* new_item = new Scene_surface_mesh_item(tm_out);
new_item->setName(QString("Clip_%1").arg(sm_item->name()));
new_item->setColor(sm_item->color());
new_item->setRenderingMode(sm_item->renderingMode());
new_item->setVisible(sm_item->visible());
CGAL::Three::Scene_interface::Item_id id1 = scene->addItem(new_item);
new_item->invalidateOpenGLBuffers();
scene->setSelectedItem(id1);

Scene_polyhedron_selection_item* new_selection = new Scene_polyhedron_selection_item(new_item, this->mw);
CGAL_assertion(new_selection->selected_edges.empty());
for (fg_edge_descriptor e : edges(*tm_out))
{
if(get(ecmap_out, e))
new_selection->selected_edges.insert(e);
}
new_selection->setName(QString("Clip_%1_selection").arg(sm_item->name()));
new_selection->setVisible(sm_item->visible());
new_selection->invalidateOpenGLBuffers();
scene->addItem(new_selection);

sm_item->setVisible(false);
selection->setVisible(false);
}
}
}
Expand Down
Loading