Performance improvements

This commit is contained in:
PavelMikus 2022-05-27 13:15:29 +02:00 committed by Lukas Matena
parent a4201321e8
commit c23d1488c9
3 changed files with 22 additions and 20 deletions

View File

@ -323,8 +323,7 @@ struct GlobalModelInfo {
float calculate_point_visibility(const Vec3f &position) const {
std::vector<size_t> points = find_nearby_points(mesh_samples_tree, position, mesh_samples_radius);
if (points.empty()) {
size_t idx = find_closest_point(mesh_samples_tree, position);
return mesh_samples_visibility[idx];
return 1.0f;
}
float total_weight = 0;
@ -622,18 +621,22 @@ void compute_global_occlusion(GlobalModelInfo &result, const PrintObject *po) {
result.mesh_samples_tree = KDTreeIndirect<3, float, CoordinateFunctor>(result.mesh_samples_coordinate_functor,
result.mesh_samples.positions.size());
result.mesh_samples_radius = sqrt(
4.0f * (result.mesh_samples.total_area / SeamPlacer::raycasting_visibility_samples_count) / PI);
10.0f * (result.mesh_samples.total_area / SeamPlacer::raycasting_visibility_samples_count) / PI);
BOOST_LOG_TRIVIAL(debug)
<< "SeamPlacer: Compute visiblity sample points: end; mesh_sample_radius: " << result.mesh_samples_radius;
<< "SeamPlacer: Compute visiblity sample points: end";
BOOST_LOG_TRIVIAL(debug)
<< "SeamPlacer:build AABB tree: start";
<< "SeamPlacer: Mesh sample raidus: " << result.mesh_samples_radius;
BOOST_LOG_TRIVIAL(debug)
<< "SeamPlacer: build AABB tree: start";
auto raycasting_tree = AABBTreeIndirect::build_aabb_tree_over_indexed_triangle_set(triangle_set.vertices,
triangle_set.indices);
BOOST_LOG_TRIVIAL(debug)
<< "SeamPlacer:build AABB tree: end";
<< "SeamPlacer: build AABB tree: end";
result.mesh_samples_visibility = raycast_visibility(raycasting_tree, triangle_set, result.mesh_samples,
negative_volumes_start_index);

View File

@ -122,7 +122,7 @@ struct PrintObjectSeamData
class SeamPlacer {
public:
// Number of samples generated on the mesh. There are sqr_rays_per_sample_point*sqr_rays_per_sample_point rays casted from each samples
static constexpr size_t raycasting_visibility_samples_count = 40000;
static constexpr size_t raycasting_visibility_samples_count = 25000;
//square of number of rays per sample point
static constexpr size_t sqr_rays_per_sample_point = 8;
@ -135,7 +135,7 @@ public:
// determines angle importance compared to visibility ( neutral value is 1.0f. )
static constexpr float angle_importance = 0.6f;
static constexpr float angle_importance = 0.5f;
// 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;
@ -144,7 +144,7 @@ public:
// When searching for seam clusters for alignment:
// following value describes, how much worse score can point have and still be picked into seam cluster instead of original seam point on the same layer
static constexpr float seam_align_score_tolerance = 0.27f;
static constexpr float seam_align_score_tolerance = 0.3f;
// seam_align_tolerable_dist - if next layer closes point is too far away, break string
static constexpr float seam_align_tolerable_dist = 1.0f;
// if the seam of the current layer is too far away, and the closest seam candidate is not very good, layer is skipped.

View File

@ -7,7 +7,7 @@
namespace Slic3r {
TriangleSetSamples sample_its_uniform_parallel(size_t samples_count, const indexed_triangle_set &triangle_set) {
std::vector<float> triangles_area(triangle_set.indices.size());
std::vector<double> triangles_area(triangle_set.indices.size());
tbb::parallel_for(tbb::blocked_range<size_t>(0, triangle_set.indices.size()),
[&triangle_set, &triangles_area](
@ -16,28 +16,27 @@ TriangleSetSamples sample_its_uniform_parallel(size_t samples_count, const index
const Vec3f &a = triangle_set.vertices[triangle_set.indices[t_idx].x()];
const Vec3f &b = triangle_set.vertices[triangle_set.indices[t_idx].y()];
const Vec3f &c = triangle_set.vertices[triangle_set.indices[t_idx].z()];
float area = 0.5f * (b - a).cross(c - a).norm();
double area = double(0.5 * (b - a).cross(c - a).norm());
triangles_area[t_idx] = area;
}
});
std::map<float, size_t> area_sum_to_triangle_idx;
std::map<double, size_t> area_sum_to_triangle_idx;
float area_sum = 0;
for (size_t t_idx = 0; t_idx < triangles_area.size(); ++t_idx) {
area_sum += triangles_area[t_idx];
area_sum_to_triangle_idx[area_sum] = t_idx;
}
std::random_device rnd_device;
std::mt19937 mersenne_engine { rnd_device() };
std::mt19937_64 mersenne_engine { };
// random numbers on interval [0, 1)
std::uniform_real_distribution<float> fdistribution;
std::uniform_real_distribution<double> fdistribution;
auto get_random = [&fdistribution, &mersenne_engine]() {
return Vec3f { fdistribution(mersenne_engine), fdistribution(mersenne_engine), fdistribution(mersenne_engine) };
return Vec3d { fdistribution(mersenne_engine), fdistribution(mersenne_engine), fdistribution(mersenne_engine) };
};
std::vector<Vec3f> random_samples(samples_count);
std::vector<Vec3d> random_samples(samples_count);
std::generate(random_samples.begin(), random_samples.end(), get_random);
TriangleSetSamples result;
@ -50,11 +49,11 @@ TriangleSetSamples sample_its_uniform_parallel(size_t samples_count, const index
[&triangle_set, &area_sum_to_triangle_idx, &area_sum, &random_samples, &result](
tbb::blocked_range<size_t> r) {
for (size_t s_idx = r.begin(); s_idx < r.end(); ++s_idx) {
float t_sample = random_samples[s_idx].x() * area_sum;
double t_sample = random_samples[s_idx].x() * area_sum;
size_t t_idx = area_sum_to_triangle_idx.upper_bound(t_sample)->second;
float sq_u = std::sqrt(random_samples[s_idx].y());
float v = random_samples[s_idx].z();
double sq_u = std::sqrt(random_samples[s_idx].y());
double v = random_samples[s_idx].z();
Vec3f A = triangle_set.vertices[triangle_set.indices[t_idx].x()];
Vec3f B = triangle_set.vertices[triangle_set.indices[t_idx].y()];