Page MenuHome
Paste P2849

Comb brush parallel reduce D14376
ActivePublic

Authored by Hans Goudey (HooglyBoogly) on Mar 23 2022, 5:01 PM.
const BrushPositionCandidate best_candidate = threading::parallel_reduce(
curves.curves_range(),
128,
BrushPositionCandidate(),
[&](IndexRange curves_range, const BrushPositionCandidate &init) {
BrushPositionCandidate result = init;
for (const int curve_i : curves_range) {
const IndexRange points = curves.range_for_curve(curve_i);
const int tot_segments = points.size() - 1;
for (const int segment_i : IndexRange(tot_segments)) {
const float3 &p1_cu = positions[points[segment_i]];
const float3 &p2_cu = positions[points[segment_i] + 1];
float2 p1_re, p2_re;
ED_view3d_project_float_v2_m4(&region, p1_cu, p1_re, projection.values);
ED_view3d_project_float_v2_m4(&region, p2_cu, p2_re, projection.values);
float2 closest_re;
const float lambda = closest_to_line_segment_v2(
closest_re, brush_pos_re, p1_re, p2_re);
const float3 closest_cu = math::interpolate(p1_cu, p2_cu, lambda);
const float depth_sq_cu = math::distance_squared(ray_start_cu, closest_cu);
if (depth_sq_cu > max_depth_sq_cu) {
continue;
}
const float distance_sq_re = math::distance_squared(brush_pos_re, closest_re);
BrushPositionCandidate candidate;
candidate.position_cu = closest_cu;
candidate.depth_sq_cu = depth_sq_cu;
candidate.distance_sq_re = distance_sq_re;
update_if_better(result, candidate);
}
}
return result;
},
[&](const BrushPositionCandidate &a, const BrushPositionCandidate &b) {
return is_better_candidate(a, b) ? b : a;
});

Event Timeline