Merge pull request #7970 from MaelRL/CGAL-Demo_bugs-GF

Fix some demo bugs
This commit is contained in:
Laurent Rineau 2024-01-24 16:01:52 +01:00
commit a70e9202f2
14 changed files with 47 additions and 37 deletions

View File

@ -1102,7 +1102,7 @@ void MainWindow::open(QString filename)
if ( dfs_it==default_plugin_selection.end() ) if ( dfs_it==default_plugin_selection.end() )
{ {
// collect all io_plugins and offer them to load if the file extension match one name filter // collect all io_plugins and offer them to load if the file extension match one name filter
// also collect all available plugin in case of a no extension match // also collect all available plugins in case of a no extension match
for(CGAL::Three::Polyhedron_demo_io_plugin_interface* io_plugin : io_plugins) { for(CGAL::Three::Polyhedron_demo_io_plugin_interface* io_plugin : io_plugins) {
if ( file_matches_filter(io_plugin->loadNameFilters(), filename.toLower()) ) if ( file_matches_filter(io_plugin->loadNameFilters(), filename.toLower()) )
{ {

View File

@ -85,7 +85,7 @@ Polyhedron_demo_gocad_plugin::load(QFileInfo fileinfo, bool& ok, bool add_to_sce
t.stop(); t.stop();
std::cerr << "Reading took " << t.time() << " sec." << std::endl; std::cerr << "Reading took " << t.time() << " sec." << std::endl;
if(name_and_color.first.size() == 0){ if(name_and_color.first.size() == 0){
item->setName(fileinfo.baseName()); item->setName(fileinfo.completeBaseName());
} else { } else {
item->setName(name_and_color.first.c_str()); item->setName(name_and_color.first.c_str());
} }
@ -121,7 +121,7 @@ save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
std::ofstream out(fileinfo.filePath().toUtf8()); std::ofstream out(fileinfo.filePath().toUtf8());
out.precision (std::numeric_limits<double>::digits10 + 2); out.precision (std::numeric_limits<double>::digits10 + 2);
SMesh* poly = const_cast<SMesh*>(sm_item->polyhedron()); SMesh* poly = const_cast<SMesh*>(sm_item->polyhedron());
CGAL::IO::write_GOCAD(out, qPrintable(fileinfo.baseName()), *poly); CGAL::IO::write_GOCAD(out, qPrintable(fileinfo.completeBaseName()), *poly);
items.pop_front(); items.pop_front();
return true; return true;

View File

@ -57,7 +57,7 @@ load(QFileInfo fileinfo, bool& ok, bool add_to_scene) {
// Try to read .nef3 in a polyhedron // Try to read .nef3 in a polyhedron
Scene_nef_polyhedron_item* item = new Scene_nef_polyhedron_item(); Scene_nef_polyhedron_item* item = new Scene_nef_polyhedron_item();
item->setName(fileinfo.baseName()); item->setName(fileinfo.completeBaseName());
if(fileinfo.size() == 0) if(fileinfo.size() == 0)
{ {
CGAL::Three::Three::warning( tr("The file you are trying to load is empty.")); CGAL::Three::Three::warning( tr("The file you are trying to load is empty."));

View File

@ -215,7 +215,7 @@ Polyhedron_demo_off_plugin::load_obj(QFileInfo fileinfo) {
return nullptr; return nullptr;
} }
Scene_surface_mesh_item* item = new Scene_surface_mesh_item(); Scene_surface_mesh_item* item = new Scene_surface_mesh_item();
item->setName(fileinfo.baseName()); item->setName(fileinfo.completeBaseName());
if(item->load_obj(in)) if(item->load_obj(in))
return item; return item;
//if not polygonmesh load in soup //if not polygonmesh load in soup

View File

@ -50,7 +50,7 @@ load(QFileInfo fileinfo, bool& ok, bool add_to_scene){
return QList<Scene_item*>()<<item; return QList<Scene_item*>()<<item;
} }
item->setName(fileinfo.baseName()); item->setName(fileinfo.completeBaseName());
ok = true; ok = true;
if(add_to_scene) if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item); CGAL::Three::Three::scene()->addItem(item);

View File

@ -201,7 +201,7 @@ load(QFileInfo fileinfo, bool& ok, bool add_to_scene){
} }
Scene_polylines_item* item = new Scene_polylines_item; Scene_polylines_item* item = new Scene_polylines_item;
item->polylines = polylines; item->polylines = polylines;
item->setName(fileinfo.baseName()); item->setName(fileinfo.completeBaseName());
item->setColor(Qt::black); item->setColor(Qt::black);
item->setProperty("polylines metadata", polylines_metadata); item->setProperty("polylines metadata", polylines_metadata);
std::cerr << "Number of polylines in item: " << item->polylines.size() << std::endl; std::cerr << "Number of polylines in item: " << item->polylines.size() << std::endl;

View File

@ -348,7 +348,7 @@ public:
|| (is_polygon_mesh && is_polyline) || (is_polygon_mesh && is_polyline)
|| (is_c3t3 && is_polyline) ) || (is_c3t3 && is_polyline) )
{ {
group = new Scene_group_item(fileinfo.baseName()); group = new Scene_group_item(fileinfo.completeBaseName());
} }
if(is_polygon_mesh) if(is_polygon_mesh)
@ -372,12 +372,12 @@ public:
if(poly_item) { if(poly_item) {
if(group) if(group)
{ {
poly_item->setName(QString("%1_faces").arg(fileinfo.baseName())); poly_item->setName(QString("%1_faces").arg(fileinfo.completeBaseName()));
CGAL::Three::Three::scene()->addItem(poly_item); CGAL::Three::Three::scene()->addItem(poly_item);
CGAL::Three::Three::scene()->changeGroup(poly_item, group); CGAL::Three::Three::scene()->changeGroup(poly_item, group);
} }
else{ else{
poly_item->setName(fileinfo.baseName()); poly_item->setName(fileinfo.completeBaseName());
ok = true; ok = true;
if(add_to_scene) if(add_to_scene)
CGAL::Three::Three::scene()->addItem(poly_item); CGAL::Three::Three::scene()->addItem(poly_item);
@ -484,12 +484,12 @@ public:
c3t3_item->resetCutPlane(); c3t3_item->resetCutPlane();
if(group) if(group)
{ {
c3t3_item->setName(QString("%1_tetrahedra").arg(fileinfo.baseName())); c3t3_item->setName(QString("%1_tetrahedra").arg(fileinfo.completeBaseName()));
CGAL::Three::Three::scene()->addItem(c3t3_item); CGAL::Three::Three::scene()->addItem(c3t3_item);
CGAL::Three::Three::scene()->changeGroup(c3t3_item, group); CGAL::Three::Three::scene()->changeGroup(c3t3_item, group);
} }
else{ else{
c3t3_item->setName(fileinfo.baseName()); c3t3_item->setName(fileinfo.completeBaseName());
ok = true; ok = true;
if(add_to_scene) if(add_to_scene)
CGAL::Three::Three::scene()->addItem(c3t3_item); CGAL::Three::Three::scene()->addItem(c3t3_item);
@ -506,12 +506,12 @@ public:
polyline_item->polylines.push_back(segment); polyline_item->polylines.push_back(segment);
if(group) if(group)
{ {
polyline_item->setName(QString("%1_lines").arg(fileinfo.baseName())); polyline_item->setName(QString("%1_lines").arg(fileinfo.completeBaseName()));
CGAL::Three::Three::scene()->addItem(polyline_item); CGAL::Three::Three::scene()->addItem(polyline_item);
CGAL::Three::Three::scene()->changeGroup(polyline_item, group); CGAL::Three::Three::scene()->changeGroup(polyline_item, group);
} }
else{ else{
polyline_item->setName(fileinfo.baseName()); polyline_item->setName(fileinfo.completeBaseName());
ok = true; ok = true;
if(add_to_scene) if(add_to_scene)
CGAL::Three::Three::scene()->addItem(polyline_item); CGAL::Three::Three::scene()->addItem(polyline_item);
@ -537,7 +537,7 @@ public:
double* p = data->GetPoint(i); double* p = data->GetPoint(i);
point_item->point_set()->insert(Point_3(p[0], p[1], p[2])); point_item->point_set()->insert(Point_3(p[0], p[1], p[2]));
} }
point_item->setName(fileinfo.baseName()); point_item->setName(fileinfo.completeBaseName());
ok = true; ok = true;
if(add_to_scene) if(add_to_scene)
CGAL::Three::Three::scene()->addItem(point_item); CGAL::Three::Three::scene()->addItem(point_item);

View File

@ -64,7 +64,7 @@ load(QFileInfo fileinfo, bool& ok, bool add_to_scene) {
Scene_polylines_item* item = new Scene_polylines_item; Scene_polylines_item* item = new Scene_polylines_item;
item->polylines = polylines; item->polylines = polylines;
item->setName(fileinfo.baseName()); item->setName(fileinfo.completeBaseName());
item->setColor(Qt::black); item->setColor(Qt::black);
std::cerr << "Number of polylines in item: " << item->polylines.size() << std::endl; std::cerr << "Number of polylines in item: " << item->polylines.size() << std::endl;
item->invalidateOpenGLBuffers(); item->invalidateOpenGLBuffers();

View File

@ -96,7 +96,7 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(
} }
if(fileinfo.suffix().toLower() == "cgal") if(fileinfo.suffix().toLower() == "cgal")
{ {
item->setName(fileinfo.baseName()); item->setName(fileinfo.completeBaseName());
if(item->load_binary(in)) { if(item->load_binary(in)) {
if(add_to_scene){ if(add_to_scene){
@ -134,7 +134,7 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(
in.open(fileinfo.filePath().toUtf8(), std::ios_base::in);//not binary in.open(fileinfo.filePath().toUtf8(), std::ios_base::in);//not binary
CGAL_assertion(!(!in)); CGAL_assertion(!(!in));
item->setName(fileinfo.baseName()); item->setName(fileinfo.completeBaseName());
item->set_valid(false); item->set_valid(false);
if(CGAL::SMDS_3::build_triangulation_from_file(in, item->c3t3().triangulation(), if(CGAL::SMDS_3::build_triangulation_from_file(in, item->c3t3().triangulation(),
@ -165,7 +165,7 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(
CGAL_assertion(!(!in)); CGAL_assertion(!(!in));
} }
item->setName(fileinfo.baseName()); item->setName(fileinfo.completeBaseName());
if (CGAL::IO::read_AVIZO_TETRA(in, item->c3t3().triangulation())) if (CGAL::IO::read_AVIZO_TETRA(in, item->c3t3().triangulation()))
{ {

View File

@ -387,7 +387,7 @@ save(const Scene_c3t3_item& c3t3_item, const QFileInfo& fileInfo)
rib_file.precision(8); rib_file.precision(8);
// Header // Header
QString basename = fileInfo.baseName(); QString basename = fileInfo.completeBaseName();
write_header(qPrintable(basename), rib_file); write_header(qPrintable(basename), rib_file);
// Lights // Lights

View File

@ -1356,7 +1356,7 @@ Io_image_plugin::load(QFileInfo fileinfo, bool& ok, bool add_to_scene)
{ {
//Create planes //Create planes
image_item = new Scene_image_item(image,0, true); image_item = new Scene_image_item(image,0, true);
image_item->setName(fileinfo.baseName()); image_item->setName(fileinfo.completeBaseName());
msgBox.setText("Planes created : 0/3"); msgBox.setText("Planes created : 0/3");
msgBox.setStandardButtons(QMessageBox::NoButton); msgBox.setStandardButtons(QMessageBox::NoButton);
msgBox.show(); msgBox.show();
@ -1367,7 +1367,7 @@ Io_image_plugin::load(QFileInfo fileinfo, bool& ok, bool add_to_scene)
{ {
image_item = new Scene_image_item(image,voxel_scale, false); image_item = new Scene_image_item(image,voxel_scale, false);
} }
image_item->setName(fileinfo.baseName()); image_item->setName(fileinfo.completeBaseName());
if(add_to_scene) if(add_to_scene)
CGAL::Three::Three::scene()->addItem(image_item); CGAL::Three::Three::scene()->addItem(image_item);
@ -1456,7 +1456,7 @@ bool Io_image_plugin::loadDirectory(const QString& dirname,
{ {
// Create planes // Create planes
image_item = new Scene_image_item(image,125, true); image_item = new Scene_image_item(image,125, true);
image_item->setName(fileinfo.baseName()); image_item->setName(fileinfo.completeBaseName());
msgBox.setText("Planes created : 0/3"); msgBox.setText("Planes created : 0/3");
msgBox.setStandardButtons(QMessageBox::NoButton); msgBox.setStandardButtons(QMessageBox::NoButton);
msgBox.show(); msgBox.show();
@ -1470,7 +1470,7 @@ bool Io_image_plugin::loadDirectory(const QString& dirname,
int voxel_scale = ui.precisionList->currentIndex() + 1; int voxel_scale = ui.precisionList->currentIndex() + 1;
image_item = new Scene_image_item(image,voxel_scale, false); image_item = new Scene_image_item(image,voxel_scale, false);
image_item->setName(fileinfo.baseName()); image_item->setName(fileinfo.completeBaseName());
scene->addItem(image_item); scene->addItem(image_item);
} }
} }

View File

@ -182,8 +182,7 @@ void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveIsolatedVertices_t
if (poly_item) if (poly_item)
{ {
std::size_t nbv = std::size_t nbv =
CGAL::Polygon_mesh_processing::remove_isolated_vertices( CGAL::Polygon_mesh_processing::remove_isolated_vertices(*poly_item->polyhedron());
*poly_item->polyhedron());
CGAL::Three::Three::information(tr(" %1 isolated vertices have been removed.") CGAL::Three::Three::information(tr(" %1 isolated vertices have been removed.")
.arg(nbv)); .arg(nbv));
poly_item->setNbIsolatedvertices(0); poly_item->setNbIsolatedvertices(0);
@ -369,13 +368,16 @@ void Polyhedron_demo_repair_polyhedron_plugin::on_actionSnapBorders_triggered()
template <typename Item> template <typename Item>
void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveDegenerateFaces_triggered(Scene_interface::Item_id index) void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveDegenerateFaces_triggered(Scene_interface::Item_id index)
{ {
Item* poly_item = Item* poly_item = qobject_cast<Item*>(scene->item(index));
qobject_cast<Item*>(scene->item(index));
if (poly_item) if (poly_item)
{ {
if(! CGAL::is_triangle_mesh(*poly_item->polyhedron())) {
CGAL::Three::Three::error(QString("The mesh must have triangle faces"));
return;
}
std::size_t nbv = faces(*poly_item->polyhedron()).size(); std::size_t nbv = faces(*poly_item->polyhedron()).size();
CGAL::Polygon_mesh_processing::remove_degenerate_faces( CGAL::Polygon_mesh_processing::remove_degenerate_faces(*poly_item->polyhedron());
*poly_item->polyhedron());
nbv -= faces(*poly_item->polyhedron()).size(); nbv -= faces(*poly_item->polyhedron()).size();
poly_item->invalidateOpenGLBuffers(); poly_item->invalidateOpenGLBuffers();
Q_EMIT poly_item->itemChanged(); Q_EMIT poly_item->itemChanged();
@ -395,10 +397,14 @@ void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveDegenerateFaces_tr
template <typename Item> template <typename Item>
void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveSelfIntersections_triggered(Scene_interface::Item_id index) void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveSelfIntersections_triggered(Scene_interface::Item_id index)
{ {
Item* poly_item = Item* poly_item = qobject_cast<Item*>(scene->item(index));
qobject_cast<Item*>(scene->item(index));
if (poly_item) if (poly_item)
{ {
if(! CGAL::is_triangle_mesh(*poly_item->polyhedron())) {
CGAL::Three::Three::error(QString("The mesh must have triangle faces"));
return;
}
bool solved = bool solved =
CGAL::Polygon_mesh_processing::experimental::remove_self_intersections( CGAL::Polygon_mesh_processing::experimental::remove_self_intersections(
*poly_item->polyhedron(), CGAL::parameters::preserve_genus(false)); *poly_item->polyhedron(), CGAL::parameters::preserve_genus(false));
@ -420,10 +426,10 @@ void Polyhedron_demo_repair_polyhedron_plugin::on_actionRemoveSelfIntersections_
template <typename Item> template <typename Item>
void Polyhedron_demo_repair_polyhedron_plugin::on_actionAutorefine_triggered(Scene_interface::Item_id index) void Polyhedron_demo_repair_polyhedron_plugin::on_actionAutorefine_triggered(Scene_interface::Item_id index)
{ {
Item* poly_item = Item* poly_item = qobject_cast<Item*>(scene->item(index));
qobject_cast<Item*>(scene->item(index));
if (poly_item) if (poly_item)
{ {
CGAL::Polygon_mesh_processing::triangulate_faces(*poly_item->polyhedron());
try{ try{
CGAL::Polygon_mesh_processing::experimental::autorefine(*poly_item->polyhedron()); CGAL::Polygon_mesh_processing::experimental::autorefine(*poly_item->polyhedron());
} }
@ -519,10 +525,10 @@ void Polyhedron_demo_repair_polyhedron_plugin::on_actionNewAutorefine_triggered(
template <typename Item> template <typename Item>
void Polyhedron_demo_repair_polyhedron_plugin::on_actionAutorefineAndRMSelfIntersections_triggered(Scene_interface::Item_id index) void Polyhedron_demo_repair_polyhedron_plugin::on_actionAutorefineAndRMSelfIntersections_triggered(Scene_interface::Item_id index)
{ {
Item* poly_item = Item* poly_item = qobject_cast<Item*>(scene->item(index));
qobject_cast<Item*>(scene->item(index));
if (poly_item) if (poly_item)
{ {
CGAL::Polygon_mesh_processing::triangulate_faces(*poly_item->polyhedron());
try{ try{
bool solved = bool solved =
CGAL::Polygon_mesh_processing::experimental:: CGAL::Polygon_mesh_processing::experimental::

View File

@ -111,7 +111,7 @@ public:
ok = false; ok = false;
return QList<Scene_item*>(); return QList<Scene_item*>();
} }
item->setName(fileinfo.baseName()); item->setName(fileinfo.completeBaseName());
ok = true; ok = true;
if(add_to_scene) if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item); CGAL::Three::Three::scene()->addItem(item);

View File

@ -107,6 +107,10 @@ public:
ui_widget.projection_checkBox->setChecked(true); ui_widget.projection_checkBox->setChecked(true);
ui_widget.area_smoothing_checkBox->setChecked(false); ui_widget.area_smoothing_checkBox->setChecked(false);
#ifndef CGAL_PMP_USE_CERES_SOLVER
ui_widget.area_smoothing_checkBox->setDisabled(true);
#endif
ui_widget.flip_checkBox->setChecked(true);
ui_widget.flip_checkBox->setDisabled(true); ui_widget.flip_checkBox->setDisabled(true);
} }