84#define USE_SCANFILL_EDGE_WORKAROUND
86#define SPLINE_RESOL_CAP_PER_PIXEL 2
87#define SPLINE_RESOL_CAP_MIN 8
88#define SPLINE_RESOL_CAP_MAX 64
96#define SF_EDGE_IS_BOUNDARY 0xff
97#define SF_KEYINDEX_TEMP_ID uint(-1)
99#define TRI_TERMINATOR_ID uint(-1)
100#define TRI_VERT uint(-1)
105# define FACE_ASSERT(face, vert_max) \
108 BLI_assert(_t[0] < vert_max); \
109 BLI_assert(_t[1] < vert_max); \
110 BLI_assert(_t[2] < vert_max); \
111 BLI_assert(_t[3] < vert_max || _t[3] == TRI_VERT); \
112 UNUSED_VARS_NDEBUG(vert_max); \
117# define FACE_ASSERT(face, vert_max)
123 float r_p[2],
const float p[2],
const float cent[2],
const float angle,
const float asp[2])
130 r_p[0] = (p[0] - cent[0]) / asp[0];
131 r_p[1] = (p[1] - cent[1]) / asp[1];
134 p_new[0] = ((r_p[0] * c) - (r_p[1] * s)) * asp[0];
135 p_new[1] = ((r_p[0] * s) + (r_p[1] * c)) * asp[1];
138 r_p[0] = p_new[0] + cent[0];
139 r_p[1] = p_new[1] + cent[1];
148 const float co_xy[2],
151 const float co[3] = {co_xy[0], co_xy[1], co_z};
221 uint open_spline_index,
227 while (open_spline_index-- > 0) {
237 for (k = 0; k < vertex_total - 1; k++, j += 3) {
256 if (open_spline_ranges[open_spline_index].is_cyclic) {
257 *(face++) = vertex_offset + 0;
260 *(face++) = vertex_offset + 1;
265 *(face++) = vertex_offset + 0;
266 *(face++) = vertex_offset + 2;
272 uint midvidx = vertex_offset;
276 j = midvidx + (vertex_total * 3);
278 for (k = 0; k < vertex_total_cap_head - 2; k++, j++) {
279 *(face++) = midvidx + 0;
280 *(face++) = midvidx + 0;
287 j = vertex_offset + (vertex_total * 3);
290 *(face++) = midvidx + 0;
291 *(face++) = midvidx + 0;
292 *(face++) = midvidx + 1;
297 *(face++) = midvidx + 0;
298 *(face++) = midvidx + 0;
299 *(face++) = j + vertex_total_cap_head - 2;
300 *(face++) = midvidx + 2;
308 j = vertex_offset + (vertex_total * 3) + (vertex_total_cap_head - 1);
310 midvidx = vertex_offset + (vertex_total * 3) - 3;
312 for (k = 0; k < vertex_total_cap_tail - 2; k++, j++) {
321 j = vertex_offset + (vertex_total * 3) + (vertex_total_cap_head - 1);
324 *(face++) = midvidx + 0;
325 *(face++) = midvidx + 0;
327 *(face++) = midvidx + 1;
331 *(face++) = midvidx + 0;
332 *(face++) = midvidx + 0;
333 *(face++) = midvidx + 2;
334 *(face++) = j + vertex_total_cap_tail - 2;
350 mr_handle = MEM_new<MaskRasterHandle>(
"MaskRasterHandle");
360 for (
uint i = 0; i < layers_tot; i++,
layer++) {
362 if (
layer->face_array) {
363 MEM_delete(
layer->face_array);
366 if (
layer->face_coords) {
367 MEM_delete(
layer->face_coords);
370 if (
layer->buckets_face) {
373 for (bucket_index = 0; bucket_index < bucket_tot; bucket_index++) {
374 uint *face_index =
layer->buckets_face[bucket_index];
376 MEM_delete(face_index);
380 MEM_delete(
layer->buckets_face);
384 MEM_delete(mr_handle->
layers);
385 MEM_delete(mr_handle);
389 float (*diff_points)[2],
390 const uint tot_diff_point,
394 uint k_prev = tot_diff_point - 2;
395 uint k_curr = tot_diff_point - 1;
404 const float *co_prev;
405 const float *co_curr;
406 const float *co_next;
408 const float ofs_squared = ofs * ofs;
410 co_prev = diff_points[k_prev];
411 co_curr = diff_points[k_curr];
412 co_next = diff_points[k_next];
418 for (k = 0; k < tot_diff_point; k++) {
421 co_curr = diff_points[k_curr];
422 co_next = diff_points[k_next];
430 if ((do_test ==
false) ||
438 diff_feather_points[k][0] = diff_points[k][0] + (d[1] * ofs);
439 diff_feather_points[k][1] = diff_points[k][1] + (-d[0] * ofs);
463 const float *va[3] = {v1,
v2, v3};
464 for (
int i = 0; i < 3; i++) {
465 const float *a = va[i];
466 const float *
b = va[(i + 1) % 3];
467 const float *c = va[(i + 2) % 3];
469 float nx = -(
b[1] - a[1]);
470 float ny =
b[0] - a[0];
472 float d_c = nx * (c[0] - a[0]) + ny * (c[1] - a[1]);
475 float box_max = nx * (nx >= 0.0f ? xmax : xmin) - nx * a[0] + ny * (ny >= 0.0f ? ymax : ymin) -
477 float box_min = nx * (nx >= 0.0f ? xmin : xmax) - nx * a[0] + ny * (ny >= 0.0f ? ymin : ymax) -
480 if (box_max <
fminf(0.0f, d_c) || box_min >
fmaxf(0.0f, d_c)) {
492 const float bucket_size_x,
493 const float bucket_size_y)
495 const uint *face =
layer->face_array[face_index];
498 const float xmin =
layer->bounds.xmin + (bucket_size_x *
float(bucket_x));
499 const float ymin =
layer->bounds.ymin + (bucket_size_y *
float(bucket_y));
500 const float xmax = xmin + bucket_size_x;
501 const float ymax = ymin + bucket_size_y;
503 const float *v1 =
cos[face[0]];
504 const float *
v2 =
cos[face[1]];
505 const float *v3 =
cos[face[2]];
510 const float *v4 =
cos[face[3]];
530 layer->face_coords =
nullptr;
531 layer->face_array =
nullptr;
533 layer->buckets_x = 0;
534 layer->buckets_y = 0;
536 layer->buckets_xy_scalar[0] = 0.0f;
537 layer->buckets_xy_scalar[1] = 0.0f;
539 layer->buckets_face =
nullptr;
564 const float bucket_size_x = (bucket_dim_x +
FLT_EPSILON) /
float(
layer->buckets_x);
565 const float bucket_size_y = (bucket_dim_y +
FLT_EPSILON) /
float(
layer->buckets_y);
576 for (face_index = 0; face_index <
layer->face_tot; face_index++, face += 4) {
583 const float *v1 =
cos[face[0]];
584 const float *
v2 =
cos[face[1]];
585 const float *v3 =
cos[face[2]];
593 const float *v1 =
cos[face[0]];
594 const float *
v2 =
cos[face[1]];
595 const float *v3 =
cos[face[2]];
596 const float *v4 =
cos[face[3]];
605 if (!((xmax < 0.0f) || (ymax < 0.0f) || (xmin > 1.0f) || (ymin > 1.0f))) {
607 CLAMP(xmin, 0.0f, 1.0f);
608 CLAMP(ymin, 0.0f, 1.0f);
609 CLAMP(xmax, 0.0f, 1.0f);
610 CLAMP(ymax, 0.0f, 1.0f);
623 if (xi_min >=
layer->buckets_x) {
624 xi_min =
layer->buckets_x - 1;
626 if (xi_max >=
layer->buckets_x) {
627 xi_max =
layer->buckets_x - 1;
629 if (yi_min >=
layer->buckets_y) {
630 yi_min =
layer->buckets_y - 1;
632 if (yi_max >=
layer->buckets_y) {
633 yi_max =
layer->buckets_y - 1;
636 for (yi = yi_min; yi <= yi_max; yi++) {
637 uint bucket_index = (
layer->buckets_x * yi) + xi_min;
638 for (xi = xi_min; xi <= xi_max; xi++, bucket_index++) {
648 bucketstore_tot[bucket_index]++;
661 for (bucket_index = 0; bucket_index < bucket_tot; bucket_index++) {
662 if (bucketstore_tot[bucket_index]) {
666 buckets_face[bucket_index] = bucket;
668 for (bucket_node = bucketstore[bucket_index]; bucket_node;
669 bucket_node = bucket_node->
next)
677 buckets_face[bucket_index] =
nullptr;
681 layer->buckets_face = buckets_face;
684 MEM_delete(bucketstore);
685 MEM_delete(bucketstore_tot);
694 const rctf &default_bounds,
695 const float pixel_size,
696 const float asp_xy[2],
699 const bool do_aspect_correct,
700 const bool do_mask_aa,
701 const bool do_feather,
704 const float zvec[3] = {0.0f, 0.0f, -1.0f};
709 uint open_spline_index = 0;
718 uint tot_feather_quads = 0;
720#ifdef USE_SCANFILL_EDGE_WORKAROUND
721 uint tot_boundary_used = 0;
722 uint tot_boundary_found = 0;
726 open_spline_ranges = MEM_new_array<MaskRasterSplineInfo>(tot_splines, __func__);
734 float (*diff_points)[2];
737 float (*diff_feather_points)[2];
738 float (*diff_feather_points_flip)[2];
739 uint tot_diff_feather_points;
743 const uint resol = std::clamp(std::max(resol_a, resol_b), 4u, 512u);
749 &spline, resol,
false, &tot_diff_feather_points);
753 tot_diff_feather_points = 0;
754 diff_feather_points =
nullptr;
757 if (tot_diff_point > 3) {
763 if (do_aspect_correct) {
764 if (width != height) {
769 if (width < height) {
770 fp = &diff_points[0][0];
771 ffp = tot_diff_feather_points ? &diff_feather_points[0][0] :
nullptr;
775 fp = &diff_points[0][1];
776 ffp = tot_diff_feather_points ? &diff_feather_points[0][1] :
nullptr;
780 for (
uint i = 0; i < tot_diff_point; i++, fp += 2) {
781 (*fp) = (((*fp) - 0.5f) / asp) + 0.5f;
784 if (tot_diff_feather_points) {
785 for (
uint i = 0; i < tot_diff_feather_points; i++, ffp += 2) {
786 (*ffp) = (((*ffp) - 0.5f) / asp) + 0.5f;
793 if (do_mask_aa ==
true) {
794 if (do_feather ==
false) {
795 tot_diff_feather_points = tot_diff_point;
799 diff_feather_points, diff_points, tot_diff_point, pixel_size,
false);
804 diff_feather_points, diff_points, tot_diff_point, pixel_size,
true);
812 &spline, diff_feather_points, tot_diff_feather_points);
816 sf_vert_prev->
tmp.u = vert_num;
819 sf_vert_prev->
keyindex = vert_num + tot_diff_point;
823 for (j = 1; j < tot_diff_point; j++) {
825 sf_vert->
tmp.u = vert_num;
826 sf_vert->
keyindex = vert_num + tot_diff_point;
830 sf_vert = sf_vert_prev;
833 for (j = 0; j < tot_diff_point; j++) {
836#ifdef USE_SCANFILL_EDGE_WORKAROUND
837 if (diff_feather_points) {
844 sf_vert_prev = sf_vert;
845 sf_vert = sf_vert->
next;
848 if (diff_feather_points) {
849 BLI_assert(tot_diff_feather_points == tot_diff_point);
853 for (j = 0; j < tot_diff_feather_points; j++) {
859 tot_feather_quads += tot_diff_point;
864 if (diff_feather_points) {
868 "diff_feather_points_flip");
871 for (j = 0; j < tot_diff_point; j++) {
872 sub_v2_v2v2(co_diff, diff_points[j], diff_feather_points[j]);
873 add_v2_v2v2(diff_feather_points_flip[j], diff_points[j], co_diff);
877 &spline, diff_feather_points, tot_diff_feather_points);
879 &spline, diff_feather_points_flip, tot_diff_feather_points);
882 diff_feather_points_flip =
nullptr;
885 open_spline_ranges[open_spline_index].
vertex_offset = vert_num;
886 open_spline_ranges[open_spline_index].
vertex_total = tot_diff_point;
889 for (j = 0; j < tot_diff_point; j++) {
893 sf_vert->
tmp.u = vert_num;
899 sf_vert->
tmp.u = vert_num;
904 if (diff_feather_points_flip) {
906 &sf_ctx, diff_feather_points_flip[j], 1.0f);
910 sub_v2_v2v2(co_diff, diff_points[j], diff_feather_points[j]);
915 sf_vert->
tmp.u = vert_num;
919 tot_feather_quads += 2;
923 tot_feather_quads -= 2;
926 if (diff_feather_points_flip) {
927 MEM_delete(diff_feather_points_flip);
928 diff_feather_points_flip =
nullptr;
938 const float *fp_cent;
939 const float *fp_turn;
943 fp_cent = diff_points[0];
944 fp_turn = diff_feather_points[0];
946#define CALC_CAP_RESOL \
947 clampis_uint(uint(len_v2v2(fp_cent, fp_turn) / (pixel_size * SPLINE_RESOL_CAP_PER_PIXEL)), \
948 SPLINE_RESOL_CAP_MIN, \
949 SPLINE_RESOL_CAP_MAX)
954 for (k = 1; k < vertex_total_cap; k++) {
960 sf_vert->
tmp.u = vert_num;
964 tot_feather_quads += vertex_total_cap;
969 fp_cent = diff_points[tot_diff_point - 1];
970 fp_turn = diff_feather_points[tot_diff_point - 1];
975 for (k = 1; k < vertex_total_cap; k++) {
981 sf_vert->
tmp.u = vert_num;
985 tot_feather_quads += vertex_total_cap;
991 open_spline_ranges[open_spline_index].
is_cyclic = is_cyclic;
1001 MEM_delete(diff_points);
1004 if (diff_feather_points) {
1005 MEM_delete(diff_feather_points);
1010 uint(*face_array)[4], *face;
1015 int scanfill_flag = 0;
1017 bool is_isect =
false;
1018 ListBaseT<ScanFillVert> isect_remvertbase = {
nullptr,
nullptr};
1019 ListBaseT<ScanFillEdge> isect_remedgebase = {
nullptr,
nullptr};
1028 cos =
reinterpret_cast<float *
>(face_coords);
1029 for (sf_vert = sf_ctx.
fillvertbase.first(); sf_vert; sf_vert = sf_vert_next) {
1030 sf_vert_next = sf_vert->
next;
1055 face_coords,
sizeof(
float[3]) * (vert_num + sf_vert_tot_isect)));
1057 cos = (&face_coords[vert_num][0]);
1059 for (sf_vert = sf_ctx.
fillvertbase.first(); sf_vert; sf_vert = sf_vert->
next) {
1060 copy_v3_v3(cos, sf_vert->co);
1061 sf_vert->tmp.u = i++;
1065 vert_num += sf_vert_tot_isect;
1080 uint sf_edge_array_num = 0;
1081 if (tot_feather_quads) {
1082 const ListBaseT<ScanFillEdge> *lb_array[] = {&sf_ctx.
filledgebase, &isect_remedgebase};
1083 for (
int pass = 0; pass < 2; pass++) {
1086 sf_edge_array_num += 1;
1091 if (sf_edge_array_num > 0) {
1094 uint edge_index = 0;
1095 for (
int pass = 0; pass < 2; pass++) {
1098 sf_edge_array[edge_index++] = &sf_edge;
1116 size_t(sf_tri_tot) +
size_t(tot_feather_quads),
"maskrast_face_index");
1120 face =
reinterpret_cast<uint *
>(face_array);
1121 for (sf_tri = sf_ctx.
fillfacebase.first(); sf_tri; sf_tri = sf_tri->
next) {
1122 *(face++) = sf_tri->
v3->
tmp.u;
1123 *(face++) = sf_tri->
v2->
tmp.u;
1124 *(face++) = sf_tri->
v1->
tmp.u;
1136 if (sf_edge_array) {
1138 for (
uint i = 0; i < sf_edge_array_num; i++) {
1141 *(face++) = sf_edge->
v1->
tmp.u;
1142 *(face++) = sf_edge->
v2->
tmp.u;
1148#ifdef USE_SCANFILL_EDGE_WORKAROUND
1149 tot_boundary_found++;
1152 MEM_delete(sf_edge_array);
1155#ifdef USE_SCANFILL_EDGE_WORKAROUND
1156 if (tot_boundary_found != tot_boundary_used) {
1157 BLI_assert(tot_boundary_found < tot_boundary_used);
1163 open_spline_ranges, open_spline_index, face, vert_num);
1164 face += open_quad_num * 4;
1165 face_index += open_quad_num;
1168 MEM_delete(open_spline_ranges);
1172 "%u %u (%u %u), %u\n",
1174 sf_tri_tot + tot_feather_quads,
1177 tot_boundary_used - tot_boundary_found);
1180#ifdef USE_SCANFILL_EDGE_WORKAROUND
1181 BLI_assert(face_index + (tot_boundary_used - tot_boundary_found) ==
1182 sf_tri_tot + tot_feather_quads);
1184 BLI_assert(face_index == sf_tri_tot + tot_feather_quads);
1191#ifdef USE_SCANFILL_EDGE_WORKAROUND
1192 layer->face_tot = (sf_tri_tot + tot_feather_quads) -
1193 (tot_boundary_used - tot_boundary_found);
1195 layer->face_tot = (sf_tri_tot + tot_feather_quads);
1197 layer->face_coords = face_coords;
1198 layer->face_array = face_array;
1206 MEM_delete(face_coords);
1207 MEM_delete(face_array);
1223 const rctf &default_bounds,
1224 const float pixel_size,
1225 const float asp_xy[2],
1228 const bool do_aspect_correct,
1229 const bool do_mask_aa,
1230 const bool do_feather)
1233 struct FeatherRange {
1242 uint open_spline_index = 0;
1244 uint tot_feather_quads = 0;
1247 open_spline_ranges = MEM_new_array<MaskRasterSplineInfo>(tot_splines, __func__);
1265 float (*diff_points)[2];
1266 uint tot_diff_point;
1268 float (*diff_feather_points)[2];
1269 float (*diff_feather_points_flip)[2];
1270 uint tot_diff_feather_points;
1274 const uint resol = std::clamp(std::max(resol_a, resol_b), 4u, 512u);
1280 &spline, resol,
false, &tot_diff_feather_points);
1284 tot_diff_feather_points = 0;
1285 diff_feather_points =
nullptr;
1288 if (tot_diff_point > 3) {
1291 if (do_aspect_correct) {
1292 if (width != height) {
1297 if (width < height) {
1298 fp = &diff_points[0][0];
1299 ffp = tot_diff_feather_points ? &diff_feather_points[0][0] :
nullptr;
1303 fp = &diff_points[0][1];
1304 ffp = tot_diff_feather_points ? &diff_feather_points[0][1] :
nullptr;
1308 for (
uint i = 0; i < tot_diff_point; i++, fp += 2) {
1309 (*fp) = (((*fp) - 0.5f) / asp) + 0.5f;
1312 if (tot_diff_feather_points) {
1313 for (
uint i = 0; i < tot_diff_feather_points; i++, ffp += 2) {
1314 (*ffp) = (((*ffp) - 0.5f) / asp) + 0.5f;
1321 if (do_mask_aa ==
true) {
1322 if (do_feather ==
false) {
1323 tot_diff_feather_points = tot_diff_point;
1327 diff_feather_points, diff_points, tot_diff_point, pixel_size,
false);
1332 diff_feather_points, diff_points, tot_diff_point, pixel_size,
true);
1340 &spline, diff_feather_points, tot_diff_feather_points);
1344 int spline_vert_start = int(cdt_verts.
size());
1345 for (j = 0; j < tot_diff_point; j++) {
1346 cdt_verts.
append(
double2(diff_points[j][0], diff_points[j][1]));
1350 const int poly_num = int(tot_diff_point);
1351 cdt_face_offsets.
append(
int(cdt_face_vert_indices.
size()));
1353 cdt_face_vert_indices.
append(
int(spline_vert_start + i));
1357 if (diff_feather_points) {
1358 BLI_assert(tot_diff_feather_points == tot_diff_point);
1359 int feather_offset = int(feather_coords.
size());
1360 for (j = 0; j < tot_diff_feather_points; j++) {
1361 feather_coords.
append(
float2(diff_feather_points[j][0], diff_feather_points[j][1]));
1363 feather_ranges.
append({spline_vert_start, int(tot_diff_point), feather_offset});
1364 tot_feather_quads += tot_diff_point;
1369 if (diff_feather_points) {
1373 "diff_feather_points_flip");
1376 for (j = 0; j < tot_diff_point; j++) {
1377 sub_v2_v2v2(co_diff, diff_points[j], diff_feather_points[j]);
1378 add_v2_v2v2(diff_feather_points_flip[j], diff_points[j], co_diff);
1382 &spline, diff_feather_points, tot_diff_feather_points);
1384 &spline, diff_feather_points_flip, tot_diff_feather_points);
1387 diff_feather_points_flip =
nullptr;
1390 uint open_spline_vert_start =
uint(open_spline_verts.
size());
1391 open_spline_ranges[open_spline_index].
vertex_offset = open_spline_vert_start;
1392 open_spline_ranges[open_spline_index].
vertex_total = tot_diff_point;
1394 for (j = 0; j < tot_diff_point; j++) {
1396 open_spline_verts.
append(
float3(diff_points[j][0], diff_points[j][1], 0.0f));
1399 open_spline_verts.
append(
1400 float3(diff_feather_points[j][0], diff_feather_points[j][1], 1.0f));
1403 if (diff_feather_points_flip) {
1404 open_spline_verts.
append(
1405 float3(diff_feather_points_flip[j][0], diff_feather_points_flip[j][1], 1.0f));
1409 sub_v2_v2v2(co_diff, diff_points[j], diff_feather_points[j]);
1411 open_spline_verts.
append(
float3(co_diff[0], co_diff[1], 1.0f));
1414 tot_feather_quads += 2;
1418 tot_feather_quads -= 2;
1421 if (diff_feather_points_flip) {
1422 MEM_delete(diff_feather_points_flip);
1423 diff_feather_points_flip =
nullptr;
1433 const float *fp_cent;
1434 const float *fp_turn;
1438 fp_cent = diff_points[0];
1439 fp_turn = diff_feather_points[0];
1441#define CALC_CAP_RESOL \
1442 clampis_uint(uint(len_v2v2(fp_cent, fp_turn) / (pixel_size * SPLINE_RESOL_CAP_PER_PIXEL)), \
1443 SPLINE_RESOL_CAP_MIN, \
1444 SPLINE_RESOL_CAP_MAX)
1449 for (k = 1; k < vertex_total_cap; k++) {
1451 float co_feather[2];
1454 open_spline_verts.
append(
float3(co_feather[0], co_feather[1], 1.0f));
1456 tot_feather_quads += vertex_total_cap;
1461 fp_cent = diff_points[tot_diff_point - 1];
1462 fp_turn = diff_feather_points[tot_diff_point - 1];
1467 for (k = 1; k < vertex_total_cap; k++) {
1469 float co_feather[2];
1472 open_spline_verts.
append(
float3(co_feather[0], co_feather[1], 1.0f));
1474 tot_feather_quads += vertex_total_cap;
1480 open_spline_ranges[open_spline_index].
is_cyclic = is_cyclic;
1481 open_spline_index++;
1483#undef CALC_CAP_RESOL
1490 MEM_delete(diff_points);
1493 if (diff_feather_points) {
1494 MEM_delete(diff_feather_points);
1498 cdt_face_offsets.
append(
int(cdt_face_vert_indices.
size()));
1502 uint cdt_tri_num = 0;
1503 const uint feather_vert_num =
uint(feather_coords.
size());
1504 const uint open_spline_vert_num =
uint(open_spline_verts.
size());
1505 uint cdt_vert_num = 0;
1509 if (!cdt_face_vert_indices.
is_empty()) {
1510 const bool has_feather = !feather_ranges.
is_empty();
1530 const uint face_num = cdt_tri_num + tot_feather_quads;
1531 const uint vert_num = cdt_vert_num + feather_vert_num + open_spline_vert_num;
1536 if (face_num == 0) {
1537 MEM_delete(open_spline_ranges);
1541 uint(*face_array)[4], *face;
1542 float (*face_coords)[3];
1549 for (
uint i = 0; i < cdt_vert_num; i++) {
1555 for (
uint k = 0; k < feather_vert_num; k++) {
1557 float3(feather_coords[
int(k)][0], feather_coords[
int(k)][1], 1.0f));
1561 for (
uint i = 0; i < open_spline_vert_num; i++) {
1562 copy_v3_v3(face_coords[cdt_vert_num + feather_vert_num + i], open_spline_verts[
int(i)]);
1566 for (
uint i = 0; i < open_spline_index; i++) {
1567 open_spline_ranges[i].
vertex_offset += (cdt_vert_num + feather_vert_num);
1572 for (
uint i = 0; i < vert_num; i++) {
1579 face =
reinterpret_cast<uint *
>(face_array);
1582 for (
uint i = 0; i < cdt_tri_num; i++) {
1585 *(face++) =
uint(tri[0]);
1586 *(face++) =
uint(tri[1]);
1587 *(face++) =
uint(tri[2]);
1597 for (
int i = 0; i < int(
result.vert.size()); i++) {
1600 input_to_output[int(orig)] = i;
1605 for (
const FeatherRange &range : feather_ranges) {
1606 for (
int j = 0; j < range.vert_count; j++) {
1607 int j_next = (j + 1) % range.vert_count;
1608 int out_a = input_to_output[range.vert_start + j];
1609 int out_b = input_to_output[range.vert_start + j_next];
1613 *(face++) =
uint(out_a);
1614 *(face++) =
uint(out_b);
1615 *(face++) = cdt_vert_num +
uint(range.feather_offset + j_next);
1616 *(face++) = cdt_vert_num +
uint(range.feather_offset + j);
1625 open_spline_ranges, open_spline_index, face, vert_num);
1626 face += open_quad_num * 4;
1627 face_index += open_quad_num;
1630 MEM_delete(open_spline_ranges);
1636 layer->face_tot = face_num;
1637 layer->face_coords = face_coords;
1638 layer->face_array = face_array;
1646 MEM_delete(face_coords);
1647 MEM_delete(face_array);
1658 const bool do_aspect_correct,
1659 const bool do_mask_aa,
1660 const bool do_feather)
1662 const rctf default_bounds = {0.0f, 1.0f, 0.0f, 1.0f};
1663 const float pixel_size = 1.0f /
float(
min_ii(width, height));
1664 const float asp_xy[2] = {
1665 (do_aspect_correct && width > height) ?
float(height) /
float(width) : 1.0f,
1666 (do_aspect_correct && width < height) ?
float(width) /
float(height) : 1.0f};
1669 mr_handle->
layers = MEM_new_array<MaskRasterLayer>(mr_handle->
layers_tot,
"MaskRasterLayer");
1675 uint masklay_index = 0;
1697 if (sf_arena ==
nullptr) {
1728static float maskrasterize_layer_z_depth_tri(
const float pt[2],
1735 return (v1[2] *
w[0]) + (
v2[2] *
w[1]) + (v3[2] *
w[2]);
1740 const float pt[2],
const float v1[3],
const float v2[3],
const float v3[3],
const float v4[3])
1750 const float dist_orig,
1759 if ((
cos[0][2] < dist_orig) || (
cos[1][2] < dist_orig) || (
cos[2][2] < dist_orig)) {
1762 return maskrasterize_layer_z_depth_tri(xy,
cos[face[0]],
cos[face[1]],
cos[face[2]]);
1776 if ((
cos[0][2] < dist_orig) || (
cos[1][2] < dist_orig) || (
cos[2][2] < dist_orig) ||
1777 (
cos[3][2] < dist_orig))
1788 xy,
cos[face[0]],
cos[face[1]],
cos[face[2]],
cos[face[3]]);
1794 return maskrasterize_layer_z_depth_tri(xy,
cos[face[0]],
cos[face[1]],
cos[face[2]]);
1797 return maskrasterize_layer_z_depth_tri(xy,
cos[face[0]],
cos[face[2]],
cos[face[3]]);
1813 return uint((xy[0] -
layer->bounds.xmin) *
layer->buckets_xy_scalar[0]) +
1823 uint(*face_array)[4] =
layer->face_array;
1825 float best_dist = 1.0f;
1828 face_array[*face_index],
cos, best_dist, xy);
1829 if (test_dist < best_dist) {
1830 best_dist = test_dist;
1832 if (best_dist == 0.0f) {
1856 for (
uint i = 0; i < layers_tot; i++,
layer++) {
1863 switch (
layer->falloff) {
1866 value_layer = (3.0f * value_layer * value_layer -
1867 2.0f * value_layer * value_layer * value_layer);
1870 value_layer =
sqrtf(2.0f * value_layer - value_layer * value_layer);
1873 value_layer =
sqrtf(value_layer);
1876 value_layer = value_layer * value_layer;
1879 value_layer = value_layer * (2.0f - value_layer);
1888 value_layer *=
layer->alpha;
1896 value_layer = 1.0f - value_layer;
1899 switch (
layer->blend) {
1901 value += value_layer * (1.0f - value);
1904 value -= value_layer * value;
1907 value += value_layer;
1910 value -= value_layer;
1913 value =
max_ff(value, value_layer);
1916 value =
min_ff(value, value_layer);
1919 value *= value_layer;
1922 value = (value * (1.0f -
layer->alpha)) + (value_layer *
layer->alpha);
1925 value =
fabsf(value - value_layer);
1930 value += value_layer;
1936 CLAMP(value, 0.0f, 1.0f);
1958 float *buffer =
data->buffer;
1961 const float x_inv =
data->x_inv;
1962 const float x_px_ofs =
data->x_px_ofs;
1967 for (
uint x = 0;
x < width;
x++, i++) {
1968 xy[0] = (
float(
x) * x_inv) + x_px_ofs;
1981 const float x_inv = 1.0f /
float(width);
1982 const float y_inv = 1.0f /
float(height);
1985 data.mr_handle = mr_handle;
1988 data.x_px_ofs = x_inv * 0.5f;
1989 data.y_px_ofs = y_inv * 0.5f;
1991 data.buffer = buffer;
#define BLI_SCANFILL_ARENA_SIZE
#define CLOG_ERROR(clg_ref,...)
Read Blender memory allocation and freeing.
#define POINTER_AS_UINT(i)
#define UNUSED_VARS_NDEBUG(...)
#define POINTER_FROM_UINT(i)
#define MEM_SIZE_OPTIMAL(size)
#define MEM_realloc_uninitialized(vmemh, len)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
constexpr IndexRange()=default
void append(const T &value)
Span< T > as_span() const
#define SF_EDGE_IS_BOUNDARY
#define FACE_ASSERT(face, vert_max)
#define SF_KEYINDEX_TEMP_ID
#define TRI_TERMINATOR_ID
CDT_result< T > delaunay_2d_calc(const CDT_input< T > &input, CDT_output_type output_type)
MINLINE float min_ff(float a, float b)
BLI_INLINE uint clampis_uint(const uint v, const uint min, const uint max)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
bool BLI_rctf_isect_pt_v(const struct rctf *rect, const float xy[2])
BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings)
MaskRasterHandle * BKE_maskrasterize_handle_new()
MINLINE void copy_v3_v3(float r[3], const float a[3])
static uint maskrasterize_layer_fill_open_spline_feather_quads(const MaskRasterSplineInfo *open_spline_ranges, uint open_spline_index, uint *face, const uint vert_num)
static void layer_bucket_init(MaskRasterLayer *layer, const float pixel_size)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
static void layer_bucket_init_dummy(MaskRasterLayer *layer)
bool BLI_scanfill_calc_self_isect(ScanFillContext *sf_ctx, ListBaseT< ScanFillVert > *remvertbase, ListBaseT< ScanFillEdge > *remedgebase)
static void maskrasterize_layer_init_scanfill(MaskRasterHandle *mr_handle, MaskLayer *masklay, uint masklay_index, const rctf &default_bounds, const float pixel_size, const float asp_xy[2], const int width, const int height, const bool do_aspect_correct, const bool do_mask_aa, const bool do_feather, MemArena *sf_arena)
MINLINE void copy_v2_v2(float r[2], const float a[2])
static bool isect_aabb_tri_v2(const float xmin, const float ymin, const float xmax, const float ymax, const float v1[2], const float v2[2], const float v3[2])
float BKE_maskrasterize_handle_sample(MaskRasterHandle *mr_handle, const float xy[2])
@ CDT_INSIDE_WITH_HOLES_NONZERO
VecBase< double, 2 > double2
@ BLI_SCANFILL_CALC_POLYS
@ BLI_SCANFILL_CALC_HOLES
void BLI_linklist_prepend_arena(LinkNode **listp, void *ptr, struct MemArena *ma) ATTR_NONNULL(1
void BLI_rctf_do_minmax_v(struct rctf *rect, const float xy[2])
void void void BLI_movelisttolist(ListBase *dst, ListBase *src) ATTR_NONNULL(1
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE float normalize_v2(float n[2])
void BLI_task_parallel_range(int start, int stop, void *userdata, TaskParallelRangeFunc func, const TaskParallelSettings *settings)
ATTR_WARN_UNUSED_RESULT const BMVert * v
static bool layer_bucket_isect_test(const MaskRasterLayer *layer, uint face_index, const uint bucket_x, const uint bucket_y, const float bucket_size_x, const float bucket_size_y)
static float maskrasterize_layer_isect(const uint *face, float(*cos)[3], const float dist_orig, const float xy[2])
int isect_point_tri_v2(const float pt[2], const float v1[2], const float v2[2], const float v3[2])
BLI_INLINE uint layer_bucket_index_from_xy(MaskRasterLayer *layer, const float xy[2])
VecBase< float, 2 > float2
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height)
BMesh const char void * data
float(* BKE_mask_spline_feather_differentiated_points_with_resolution(MaskSpline *spline, unsigned int resol, bool do_feather_isect, unsigned int *r_tot_feather_point))[2]
void BLI_scanfill_begin_arena(ScanFillContext *sf_ctx, struct MemArena *arena)
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
static void maskrasterize_layer_init_from_mask_layer(MaskRasterLayer *layer, const MaskLayer *masklay)
struct ScanFillVert * BLI_scanfill_vert_add(ScanFillContext *sf_ctx, const float vec[3])
static ScanFillVert * scanfill_vert_add_v2_with_depth(ScanFillContext *sf_ctx, const float co_xy[2], const float co_z)
void BKE_mask_spline_feather_collapse_inner_loops(MaskSpline *spline, float(*feather_points)[2], unsigned int tot_feather_point)
void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, Mask *mask, int width, int height, bool do_aspect_correct, bool do_mask_aa, bool do_feather)
void barycentric_weights_v2_quad(const float v1[2], const float v2[2], const float v3[2], const float v4[2], const float co[2], float w[4])
@ MASK_BLEND_MERGE_SUBTRACT
void BKE_maskrasterize_handle_free(MaskRasterHandle *mr_handle)
@ MASK_SPLINE_NOINTERSECT
static float maskrasterize_layer_z_depth_quad(const float pt[2], const float v1[3], const float v2[3], const float v3[3], const float v4[3])
void BLI_rctf_init_minmax(struct rctf *rect)
static void maskrasterize_buffer_cb(void *__restrict userdata, const int y, const TaskParallelTLS *__restrict)
static float layer_bucket_depth_from_xy(MaskRasterLayer *layer, const float xy[2])
void BLI_rctf_union(struct rctf *rct_a, const struct rctf *rct_b)
struct ScanFillEdge * BLI_scanfill_edge_add(ScanFillContext *sf_ctx, struct ScanFillVert *v1, struct ScanFillVert *v2)
bool isect_point_tri_v2_cw(const float pt[2], const float v1[2], const float v2[2], const float v3[2])
void BLI_scanfill_end_arena(ScanFillContext *sf_ctx, struct MemArena *arena)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
static void maskrasterize_layer_init_cdt(MaskRasterHandle *mr_handle, MaskLayer *masklay, uint masklay_index, const rctf &default_bounds, const float pixel_size, const float asp_xy[2], const int width, const int height, const bool do_aspect_correct, const bool do_mask_aa, const bool do_feather)
unsigned int BKE_mask_spline_feather_resolution(MaskSpline *spline, int width, int height)
MINLINE float max_ff(float a, float b)
bool BLI_rctf_isect(const struct rctf *src1, const struct rctf *src2, struct rctf *dest)
@ MASK_LAYERFLAG_FILL_DISCRETE
@ MASK_LAYERFLAG_FILL_OVERLAP
static void maskrasterize_spline_differentiate_point_outset(float(*diff_feather_points)[2], float(*diff_points)[2], const uint tot_diff_point, const float ofs, const bool do_test)
unsigned int BLI_scanfill_calc_ex(ScanFillContext *sf_ctx, int flag, const float nor_proj[3])
void BKE_maskrasterize_buffer(MaskRasterHandle *mr_handle, unsigned int width, unsigned int height, float *buffer)
Rasterize a buffer from a single mask (threaded execution).
VecBase< float, 3 > float3
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
void barycentric_weights_v2(const float v1[2], const float v2[2], const float v3[2], const float co[2], float w[3])
MINLINE int min_ii(int a, int b)
static void rotate_point_v2(float r_p[2], const float p[2], const float cent[2], const float angle, const float asp[2])
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void BLI_memarena_free(MemArena *ma) ATTR_NONNULL(1)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax)
static constexpr int BUCKET_PIXELS_PER_CELL
float(* BKE_mask_spline_differentiate_with_resolution(MaskSpline *spline, unsigned int resol, unsigned int *r_tot_diff_point))[2]
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
MaskLayerBlendFlag blend_flag
MaskLayerVisibility visibility_flag
ListBaseT< MaskSpline > splines
MaskLayerFillSolverType fill_solver
float buckets_xy_scalar[2]
uint vertex_total_cap_tail
uint vertex_total_cap_head
MaskRasterHandle * mr_handle
ListBaseT< ScanFillFace > fillfacebase
ListBaseT< ScanFillEdge > filledgebase
ListBaseT< ScanFillVert > fillvertbase
union blender::ScanFillEdge::@262251053107234334274134243151221246013035300046 tmp
struct ScanFillFace * next
struct ScanFillVert * next
union blender::ScanFillVert::@124355022001164321030006076112165043115032300246 tmp