mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 21:05:56 +08:00
Performance improvements
This commit is contained in:
parent
a4201321e8
commit
c23d1488c9
@ -323,8 +323,7 @@ struct GlobalModelInfo {
|
|||||||
float calculate_point_visibility(const Vec3f &position) const {
|
float calculate_point_visibility(const Vec3f &position) const {
|
||||||
std::vector<size_t> points = find_nearby_points(mesh_samples_tree, position, mesh_samples_radius);
|
std::vector<size_t> points = find_nearby_points(mesh_samples_tree, position, mesh_samples_radius);
|
||||||
if (points.empty()) {
|
if (points.empty()) {
|
||||||
size_t idx = find_closest_point(mesh_samples_tree, position);
|
return 1.0f;
|
||||||
return mesh_samples_visibility[idx];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float total_weight = 0;
|
float total_weight = 0;
|
||||||
@ -622,10 +621,14 @@ 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_tree = KDTreeIndirect<3, float, CoordinateFunctor>(result.mesh_samples_coordinate_functor,
|
||||||
result.mesh_samples.positions.size());
|
result.mesh_samples.positions.size());
|
||||||
result.mesh_samples_radius = sqrt(
|
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)
|
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: Mesh sample raidus: " << result.mesh_samples_radius;
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(debug)
|
BOOST_LOG_TRIVIAL(debug)
|
||||||
<< "SeamPlacer: build AABB tree: start";
|
<< "SeamPlacer: build AABB tree: start";
|
||||||
|
@ -122,7 +122,7 @@ struct PrintObjectSeamData
|
|||||||
class SeamPlacer {
|
class SeamPlacer {
|
||||||
public:
|
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
|
// 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
|
//square of number of rays per sample point
|
||||||
static constexpr size_t sqr_rays_per_sample_point = 8;
|
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. )
|
// 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
|
// 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;
|
static constexpr float enforcer_blocker_distance_tolerance = 0.35f;
|
||||||
@ -144,7 +144,7 @@ public:
|
|||||||
|
|
||||||
// When searching for seam clusters for alignment:
|
// 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
|
// 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
|
// seam_align_tolerable_dist - if next layer closes point is too far away, break string
|
||||||
static constexpr float seam_align_tolerable_dist = 1.0f;
|
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.
|
// if the seam of the current layer is too far away, and the closest seam candidate is not very good, layer is skipped.
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
TriangleSetSamples sample_its_uniform_parallel(size_t samples_count, const indexed_triangle_set &triangle_set) {
|
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()),
|
tbb::parallel_for(tbb::blocked_range<size_t>(0, triangle_set.indices.size()),
|
||||||
[&triangle_set, &triangles_area](
|
[&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 &a = triangle_set.vertices[triangle_set.indices[t_idx].x()];
|
||||||
const Vec3f &b = triangle_set.vertices[triangle_set.indices[t_idx].y()];
|
const Vec3f &b = triangle_set.vertices[triangle_set.indices[t_idx].y()];
|
||||||
const Vec3f &c = triangle_set.vertices[triangle_set.indices[t_idx].z()];
|
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;
|
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;
|
float area_sum = 0;
|
||||||
for (size_t t_idx = 0; t_idx < triangles_area.size(); ++t_idx) {
|
for (size_t t_idx = 0; t_idx < triangles_area.size(); ++t_idx) {
|
||||||
area_sum += triangles_area[t_idx];
|
area_sum += triangles_area[t_idx];
|
||||||
area_sum_to_triangle_idx[area_sum] = t_idx;
|
area_sum_to_triangle_idx[area_sum] = t_idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::random_device rnd_device;
|
std::mt19937_64 mersenne_engine { };
|
||||||
std::mt19937 mersenne_engine { rnd_device() };
|
|
||||||
// random numbers on interval [0, 1)
|
// random numbers on interval [0, 1)
|
||||||
std::uniform_real_distribution<float> fdistribution;
|
std::uniform_real_distribution<double> fdistribution;
|
||||||
|
|
||||||
auto get_random = [&fdistribution, &mersenne_engine]() {
|
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);
|
std::generate(random_samples.begin(), random_samples.end(), get_random);
|
||||||
|
|
||||||
TriangleSetSamples result;
|
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](
|
[&triangle_set, &area_sum_to_triangle_idx, &area_sum, &random_samples, &result](
|
||||||
tbb::blocked_range<size_t> r) {
|
tbb::blocked_range<size_t> r) {
|
||||||
for (size_t s_idx = r.begin(); s_idx < r.end(); ++s_idx) {
|
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;
|
size_t t_idx = area_sum_to_triangle_idx.upper_bound(t_sample)->second;
|
||||||
|
|
||||||
float sq_u = std::sqrt(random_samples[s_idx].y());
|
double sq_u = std::sqrt(random_samples[s_idx].y());
|
||||||
float v = random_samples[s_idx].z();
|
double v = random_samples[s_idx].z();
|
||||||
|
|
||||||
Vec3f A = triangle_set.vertices[triangle_set.indices[t_idx].x()];
|
Vec3f A = triangle_set.vertices[triangle_set.indices[t_idx].x()];
|
||||||
Vec3f B = triangle_set.vertices[triangle_set.indices[t_idx].y()];
|
Vec3f B = triangle_set.vertices[triangle_set.indices[t_idx].y()];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user