Fix of #7112 (Default color sometimes appeared between two multi-material painted areas)

This commit is contained in:
Lukáš Hejl 2021-10-29 12:24:15 +02:00
parent 3eb4ae309a
commit 54b0ee6a4a

View File

@ -432,44 +432,57 @@ static std::vector<ColoredLine> filter_colorized_polygon(std::vector<ColoredLine
return total_length; return total_length;
}; };
for (size_t pair_idx = 1; pair_idx < segments.size(); ++pair_idx) { if (segments.size() >= 2)
int color0 = new_lines[segments[pair_idx - 1].first].color; for (size_t curr_idx = 0; curr_idx < segments.size(); ++curr_idx) {
int color1 = new_lines[segments[pair_idx - 0].first].color; size_t next_idx = next_idx_modulo(curr_idx, segments.size());
assert(curr_idx != next_idx);
double seg0l = segment_length(segments[pair_idx - 1]); int color0 = new_lines[segments[curr_idx].first].color;
double seg1l = segment_length(segments[pair_idx - 0]); int color1 = new_lines[segments[next_idx].first].color;
if (color0 != color1 && seg0l >= scale_(0.1) && seg1l <= scale_(0.2)) { double seg0l = segment_length(segments[curr_idx]);
for (size_t seg_start_idx = segments[pair_idx].first; seg_start_idx != segments[pair_idx].second; seg_start_idx = (seg_start_idx + 1 < new_lines.size()) ? seg_start_idx + 1 : 0) double seg1l = segment_length(segments[next_idx]);
new_lines[seg_start_idx].color = color0;
new_lines[segments[pair_idx].second].color = color0; if (color0 != color1 && seg0l >= scale_(0.1) && seg1l <= scale_(0.2)) {
for (size_t seg_start_idx = segments[next_idx].first; seg_start_idx != segments[next_idx].second; seg_start_idx = (seg_start_idx + 1 < new_lines.size()) ? seg_start_idx + 1 : 0)
new_lines[seg_start_idx].color = color0;
new_lines[segments[next_idx].second].color = color0;
}
} }
}
segments = get_segments(new_lines); segments = get_segments(new_lines);
for (size_t pair_idx = 1; pair_idx < segments.size(); ++pair_idx) { if (segments.size() >= 2)
int color0 = new_lines[segments[pair_idx - 1].first].color; for (size_t curr_idx = 0; curr_idx < segments.size(); ++curr_idx) {
int color1 = new_lines[segments[pair_idx - 0].first].color; size_t next_idx = next_idx_modulo(curr_idx, segments.size());
double seg1l = segment_length(segments[pair_idx - 0]); assert(curr_idx != next_idx);
if (color0 >= 1 && color0 != color1 && seg1l <= scale_(0.2)) { int color0 = new_lines[segments[curr_idx].first].color;
for (size_t seg_start_idx = segments[pair_idx].first; seg_start_idx != segments[pair_idx].second; seg_start_idx = (seg_start_idx + 1 < new_lines.size()) ? seg_start_idx + 1 : 0) int color1 = new_lines[segments[next_idx].first].color;
new_lines[seg_start_idx].color = color0; double seg1l = segment_length(segments[next_idx]);
new_lines[segments[pair_idx].second].color = color0;
if (color0 >= 1 && color0 != color1 && seg1l <= scale_(0.2)) {
for (size_t seg_start_idx = segments[next_idx].first; seg_start_idx != segments[next_idx].second; seg_start_idx = (seg_start_idx + 1 < new_lines.size()) ? seg_start_idx + 1 : 0)
new_lines[seg_start_idx].color = color0;
new_lines[segments[next_idx].second].color = color0;
}
} }
}
for (size_t pair_idx = 2; pair_idx < segments.size(); ++pair_idx) { segments = get_segments(new_lines);
int color0 = new_lines[segments[pair_idx - 2].first].color; if (segments.size() >= 3)
int color1 = new_lines[segments[pair_idx - 1].first].color; for (size_t curr_idx = 0; curr_idx < segments.size(); ++curr_idx) {
int color2 = new_lines[segments[pair_idx - 0].first].color; size_t next_idx = next_idx_modulo(curr_idx, segments.size());
size_t next_next_idx = next_idx_modulo(next_idx, segments.size());
if (color0 > 0 && color0 == color2 && color0 != color1 && segment_length(segments[pair_idx - 1]) <= scale_(0.5)) { int color0 = new_lines[segments[curr_idx].first].color;
for (size_t seg_start_idx = segments[pair_idx].first; seg_start_idx != segments[pair_idx].second; seg_start_idx = (seg_start_idx + 1 < new_lines.size()) ? seg_start_idx + 1 : 0) int color1 = new_lines[segments[next_idx].first].color;
new_lines[seg_start_idx].color = color0; int color2 = new_lines[segments[next_next_idx].first].color;
new_lines[segments[pair_idx].second].color = color0;
if (color0 > 0 && color0 == color2 && color0 != color1 && segment_length(segments[next_idx]) <= scale_(0.5)) {
for (size_t seg_start_idx = segments[next_next_idx].first; seg_start_idx != segments[next_next_idx].second; seg_start_idx = (seg_start_idx + 1 < new_lines.size()) ? seg_start_idx + 1 : 0)
new_lines[seg_start_idx].color = color0;
new_lines[segments[next_next_idx].second].color = color0;
}
} }
}
return std::move(new_lines); return std::move(new_lines);
} }