ENH: boost is_support_necessary's performance

1. Parallelize the majority of overhang detection, leaving only a small
part of sharp tail detection as sequential. This strategy makes
is_support_necessary 10 times faster.
2. Use the overlaps function to detect overlapping, instead of using
intersection().empty()
3. Control the max recursion depth to prevent crashing due to too deep
recursion.

Jira: STUDIO-2445, STUDIO-2458
Change-Id: I35283da3e4a22d7afe251b804ce30b90a9d754df
(cherry picked from commit 1a6fedd1a0c82906f1807234ea1b816247ca6fd7)
This commit is contained in:
arthur.tang 2023-03-14 17:04:42 +08:00 committed by Lane.Wei
parent 6f298ac6f1
commit 6c489808a7
5 changed files with 280 additions and 325 deletions

View file

@ -460,9 +460,20 @@ void PrintObject::generate_support_material()
m_print->throw_if_canceled();
} else {
// BBS: pop a warning if objects have significant amount of overhangs but support material is not enabled
m_print->set_status(50, L("Checking support necessity"));
typedef std::chrono::high_resolution_clock clock_;
typedef std::chrono::duration<double, std::ratio<1> > second_;
std::chrono::time_point<clock_> t0{ clock_::now() };
SupportNecessaryType sntype = this->is_support_necessary();
double duration{ std::chrono::duration_cast<second_>(clock_::now() - t0).count() };
BOOST_LOG_TRIVIAL(info) << std::fixed << std::setprecision(0)
<< "is_support_necessary took " << (duration / 60) << " minutes and "
<< std::setprecision(3)
<< std::fmod(duration, 60.0) << " seconds." << std::endl;
if (sntype != NoNeedSupp) {
m_print->set_status(50, L("Checking support necessity"));
if (sntype == SharpTail) {
std::string warning_message = format(L("It seems object %s has completely floating regions. Please re-orient the object or enable support generation."),
this->model_object()->name);
@ -2655,7 +2666,7 @@ SupportNecessaryType PrintObject::is_support_necessary()
#else
TreeSupport tree_support(*this, m_slicing_params);
tree_support.support_type = SupportType::stTreeAuto; // need to set support type to fully utilize the power of feature detection
tree_support.detect_overhangs();
tree_support.detect_overhangs(true);
this->clear_support_layers();
if (tree_support.has_sharp_tails)
return SharpTail;