diff --git a/src/libslic3r/GCode/SeamPlacer.cpp b/src/libslic3r/GCode/SeamPlacer.cpp index a9f8dd803..6def921de 100644 --- a/src/libslic3r/GCode/SeamPlacer.cpp +++ b/src/libslic3r/GCode/SeamPlacer.cpp @@ -323,8 +323,7 @@ struct GlobalModelInfo { float calculate_point_visibility(const Vec3f &position) const { std::vector 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); diff --git a/src/libslic3r/GCode/SeamPlacer.hpp b/src/libslic3r/GCode/SeamPlacer.hpp index c432668a3..0a38e9a66 100644 --- a/src/libslic3r/GCode/SeamPlacer.hpp +++ b/src/libslic3r/GCode/SeamPlacer.hpp @@ -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. diff --git a/src/libslic3r/TriangleSetSampling.cpp b/src/libslic3r/TriangleSetSampling.cpp index 36022d8e3..30f9a9b40 100644 --- a/src/libslic3r/TriangleSetSampling.cpp +++ b/src/libslic3r/TriangleSetSampling.cpp @@ -7,7 +7,7 @@ namespace Slic3r { TriangleSetSamples sample_its_uniform_parallel(size_t samples_count, const indexed_triangle_set &triangle_set) { - std::vector triangles_area(triangle_set.indices.size()); + std::vector triangles_area(triangle_set.indices.size()); tbb::parallel_for(tbb::blocked_range(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 area_sum_to_triangle_idx; + std::map 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 fdistribution; + std::uniform_real_distribution 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 random_samples(samples_count); + std::vector 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 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()];