optimize embedding computation

fix seed of random generators
set high angle importance for nearest mode
This commit is contained in:
PavelMikus 2022-06-06 17:30:02 +02:00 committed by Lukas Matena
parent 13ac7a24d8
commit c09781d61d
4 changed files with 19 additions and 11 deletions

View File

@ -687,8 +687,10 @@ void gather_enforcers_blockers(GlobalModelInfo &result, const PrintObject *po) {
struct SeamComparator {
SeamPosition setup;
float angle_importance;
SeamComparator(SeamPosition setup) :
setup(setup) {
angle_importance = setup == spNearest ? SeamPlacer::angle_importance_nearest : SeamPlacer::angle_importance_aligned;
}
// Standard comparator, must respect the requirements of comparators (e.g. give same result on same inputs) for sorting usage
@ -734,10 +736,10 @@ struct SeamComparator {
// the penalites are kept close to range [0-1.x] however, it should not be relied upon
float penalty_a = a.visibility +
SeamPlacer::angle_importance * compute_angle_penalty(a.local_ccw_angle)
angle_importance * compute_angle_penalty(a.local_ccw_angle)
+ distance_penalty_a;
float penalty_b = b.visibility +
SeamPlacer::angle_importance * compute_angle_penalty(b.local_ccw_angle)
angle_importance * compute_angle_penalty(b.local_ccw_angle)
+ distance_penalty_b;
return penalty_a < penalty_b;
@ -791,9 +793,9 @@ struct SeamComparator {
}
float penalty_a = a.visibility
+ SeamPlacer::angle_importance * compute_angle_penalty(a.local_ccw_angle);
+ angle_importance * compute_angle_penalty(a.local_ccw_angle);
float penalty_b = b.visibility +
SeamPlacer::angle_importance * compute_angle_penalty(b.local_ccw_angle);
angle_importance * compute_angle_penalty(b.local_ccw_angle);
return penalty_a <= penalty_b || penalty_a - penalty_b < SeamPlacer::seam_align_score_tolerance;
}
@ -1071,9 +1073,14 @@ void SeamPlacer::calculate_overhangs_and_layer_embedding(const PrintObject *po)
}
for (size_t layer_idx = r.begin(); layer_idx < r.end(); ++layer_idx) {
bool layer_has_multiple_loops =
layers[layer_idx].points[0].perimeter.end_index
< layers[layer_idx].points.size() - 1;
size_t regions_with_perimeter = 0;
for (const LayerRegion *region : po->layers()[layer_idx]->regions()) {
if (region->perimeters.entities.size() > 0) {
regions_with_perimeter++;
}
};
bool should_compute_layer_embedding = regions_with_perimeter > 1;
layers[layer_idx].points[0].perimeter.end_index < layers[layer_idx].points.size() - 1;
std::unique_ptr<PerimeterDistancer> current_layer_distancer = std::make_unique<PerimeterDistancer>(po->layers()[layer_idx]);
for (SeamCandidate &perimeter_point : layers[layer_idx].points) {
@ -1082,7 +1089,7 @@ void SeamPlacer::calculate_overhangs_and_layer_embedding(const PrintObject *po)
perimeter_point.overhang = prev_layer_distancer->distance_from_perimeter(point);
}
if (layer_has_multiple_loops) { // search for embedded perimeter points (points hidden inside the print ,e.g. multimaterial join, best position for seam)
if (should_compute_layer_embedding) { // search for embedded perimeter points (points hidden inside the print ,e.g. multimaterial join, best position for seam)
perimeter_point.embedded_distance = current_layer_distancer->distance_from_perimeter(point);
}
}

View File

@ -133,7 +133,8 @@ public:
static constexpr float overhang_distance_tolerance_factor = 0.5f;
// determines angle importance compared to visibility ( neutral value is 1.0f. )
static constexpr float angle_importance = 0.6f;
static constexpr float angle_importance_aligned = 0.6f;
static constexpr float angle_importance_nearest = 2.0f; // use much higher angle importance for nearest mode, to combat the visiblity info noise
// If enforcer or blocker is closer to the seam candidate than this limit, the seam candidate is set to Blocker or Enforcer
static constexpr float enforcer_blocker_distance_tolerance = 0.35f;

View File

@ -79,7 +79,7 @@ void its_short_edge_collpase(indexed_triangle_set &mesh, size_t target_triangle_
}
};
std::mt19937_64 generator { }; // default constant seed! so that results are deterministic
std::mt19937_64 generator { 27644437 };// default constant seed! so that results are deterministic
std::vector<size_t> face_indices(mesh.indices.size());
for (size_t idx = 0; idx < face_indices.size(); ++idx) {
face_indices[idx] = idx;

View File

@ -28,7 +28,7 @@ TriangleSetSamples sample_its_uniform_parallel(size_t samples_count, const index
area_sum_to_triangle_idx[area_sum] = t_idx;
}
std::mt19937_64 mersenne_engine { };
std::mt19937_64 mersenne_engine { 27644437 };
// random numbers on interval [0, 1)
std::uniform_real_distribution<double> fdistribution;