Replace try-catch with go_further()

This commit is contained in:
Mael Rouxel-Labbé 2023-10-13 10:59:29 +02:00
parent 91c679234b
commit 76aeec9805
1 changed files with 16 additions and 33 deletions

View File

@ -40,8 +40,8 @@ using Wrapper = CGAL::Alpha_wraps_3::internal::Alpha_wrapper_3<Oracle>;
// Here is the pipeline for the interruption box: // Here is the pipeline for the interruption box:
// - The main window is connected to a wrapping thread, which performs the wrapping. // - The main window is connected to a wrapping thread, which performs the wrapping.
// - The wrapping has a visitor, AW3_interrupter_visitor, which has a shared_ptr to a Boolean // - The wrapping has a visitor, AW3_interrupter_visitor, which has a shared_ptr to a Boolean
// - When the user clicks the box, the Boolean is switched to *false*, and the visitor throws // - When the user clicks the box, the Boolean is switched to *false*
// - The wrapping thread catches the exception, and creates the wip mesh // - The wrapping thread creates the wip mesh
// Here is the pipeline for the iterative visualization: // Here is the pipeline for the iterative visualization:
// - The main window is connected to a wrapping thread, which performs the wrapping. // - The main window is connected to a wrapping thread, which performs the wrapping.
@ -201,9 +201,6 @@ public:
} }
}; };
// Use a throw to get out of the AW3 refinement loop
class Out_of_patience_exception : public std::exception { };
template <typename BaseVisitor> template <typename BaseVisitor>
struct AW3_interrupter_visitor struct AW3_interrupter_visitor
: BaseVisitor : BaseVisitor
@ -215,15 +212,10 @@ struct AW3_interrupter_visitor
: BaseVisitor(base) : BaseVisitor(base)
{ } { }
// Only overload this one because it gives a better state of the wrap (for other visitor calls, template <typename Wrapper>
// we often get tetrahedral spikes because there are scaffolding gates in the queue) constexpr bool go_further(const Wrapper& wrapper)
template <typename Wrapper, typename Point>
void before_Steiner_point_insertion(const Wrapper& wrapper, const Point& p)
{ {
if(*should_stop) return !(*should_stop);
throw Out_of_patience_exception();
return BaseVisitor::before_Steiner_point_insertion(wrapper, p);
} }
}; };
@ -273,25 +265,14 @@ public:
QElapsedTimer elapsed_timer; QElapsedTimer elapsed_timer;
elapsed_timer.start(); elapsed_timer.start();
// try-catch because the stop visitor currently uses a throw wrapper(alpha, offset, wrap,
try CGAL::parameters::do_enforce_manifoldness(enforce_manifoldness)
{ .visitor(visitor));
wrapper(alpha, offset, wrap,
CGAL::parameters::do_enforce_manifoldness(enforce_manifoldness)
.visitor(visitor));
if(wrapper.queue().empty())
Q_EMIT done(this); Q_EMIT done(this);
} else
catch(const Out_of_patience_exception&)
{
if(enforce_manifoldness)
wrapper.make_manifold();
// extract the wrap in its current state
wrapper.extract_surface(wrap, CGAL::get(CGAL::vertex_point, wrap), !enforce_manifoldness);
Q_EMIT interrupted(this); Q_EMIT interrupted(this);
}
std::cout << "Wrapping took " << elapsed_timer.elapsed() / 1000. << "s" << std::endl; std::cout << "Wrapping took " << elapsed_timer.elapsed() / 1000. << "s" << std::endl;
} }
@ -761,10 +742,6 @@ public Q_SLOTS:
return; return;
} }
// Switch from 'wait' to 'busy'
QApplication::restoreOverrideCursor();
QApplication::setOverrideCursor(Qt::BusyCursor);
Q_FOREACH(int index, this->scene->selectionIndices()) Q_FOREACH(int index, this->scene->selectionIndices())
{ {
Scene_surface_mesh_item* sm_item = qobject_cast<Scene_surface_mesh_item*>(this->scene->item(index)); Scene_surface_mesh_item* sm_item = qobject_cast<Scene_surface_mesh_item*>(this->scene->item(index));
@ -824,6 +801,10 @@ public Q_SLOTS:
// Create message box with stop button // Create message box with stop button
if(use_message_box) if(use_message_box)
{ {
// Switch from 'wait' to 'busy'
QApplication::restoreOverrideCursor();
QApplication::setOverrideCursor(Qt::BusyCursor);
m_message_box = new QMessageBox(QMessageBox::NoIcon, m_message_box = new QMessageBox(QMessageBox::NoIcon,
"Wrapping", "Wrapping",
"Wrapping in progress...", "Wrapping in progress...",
@ -841,6 +822,8 @@ public Q_SLOTS:
} }
// Actual start // Actual start
QApplication::setOverrideCursor(Qt::WaitCursor);
wrapper_thread->start(); wrapper_thread->start();
CGAL::Three::Three::getMutex()->lock(); CGAL::Three::Three::getMutex()->lock();