diff options
Diffstat (limited to 'source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c')
-rw-r--r-- | source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c | 586 |
1 files changed, 293 insertions, 293 deletions
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c index 4ad8eed6ddd..c8e4e93843a 100644 --- a/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c +++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c @@ -31,16 +31,16 @@ #include <math.h> -#define LRT_OTHER_RV(e, rv) ((rv) == (e)->v1 ? (e)->v2 : ((rv) == (e)->v2 ? (e)->v1 : NULL)) +#define LRT_OTHER_VERT(e, vt) ((vt) == (e)->v1 ? (e)->v2 : ((vt) == (e)->v2 ? (e)->v1 : NULL)) /* Get a connected line, only for lines who has the exact given vert, or (in the case of * intersection lines) who has a vert that has the exact same position. */ static LineartEdge *lineart_line_get_connected(LineartBoundingArea *ba, - LineartVert *rv, - LineartVert **new_rv, + LineartVert *vt, + LineartVert **new_vt, int match_flag) { - LISTBASE_FOREACH (LinkData *, lip, &ba->linked_lines) { + LISTBASE_FOREACH (LinkData *, lip, &ba->linked_edges) { LineartEdge *n_e = lip->data; if ((!(n_e->flags & LRT_EDGE_FLAG_ALL_TYPE)) || (n_e->flags & LRT_EDGE_FLAG_CHAIN_PICKED)) { @@ -51,18 +51,18 @@ static LineartEdge *lineart_line_get_connected(LineartBoundingArea *ba, continue; } - *new_rv = LRT_OTHER_RV(n_e, rv); - if (*new_rv) { + *new_vt = LRT_OTHER_VERT(n_e, vt); + if (*new_vt) { return n_e; } if (n_e->flags & LRT_EDGE_FLAG_INTERSECTION) { - if (rv->fbcoord[0] == n_e->v1->fbcoord[0] && rv->fbcoord[1] == n_e->v1->fbcoord[1]) { - *new_rv = LRT_OTHER_RV(n_e, n_e->v1); + if (vt->fbcoord[0] == n_e->v1->fbcoord[0] && vt->fbcoord[1] == n_e->v1->fbcoord[1]) { + *new_vt = LRT_OTHER_VERT(n_e, n_e->v1); return n_e; } - if (rv->fbcoord[0] == n_e->v2->fbcoord[0] && rv->fbcoord[1] == n_e->v2->fbcoord[1]) { - *new_rv = LRT_OTHER_RV(n_e, n_e->v2); + if (vt->fbcoord[0] == n_e->v2->fbcoord[0] && vt->fbcoord[1] == n_e->v2->fbcoord[1]) { + *new_vt = LRT_OTHER_VERT(n_e, n_e->v2); return n_e; } } @@ -71,33 +71,33 @@ static LineartEdge *lineart_line_get_connected(LineartBoundingArea *ba, return NULL; } -static LineartLineChain *lineart_chain_create(LineartRenderBuffer *rb) +static LineartEdgeChain *lineart_chain_create(LineartRenderBuffer *rb) { - LineartLineChain *rlc; - rlc = lineart_mem_acquire(&rb->render_data_pool, sizeof(LineartLineChain)); + LineartEdgeChain *ec; + ec = lineart_mem_acquire(&rb->render_data_pool, sizeof(LineartEdgeChain)); - BLI_addtail(&rb->chains, rlc); + BLI_addtail(&rb->chains, ec); - return rlc; + return ec; } -static bool lineart_point_overlapping(LineartLineChainItem *rlci, +static bool lineart_point_overlapping(LineartEdgeChainItem *eci, float x, float y, double threshold) { - if (!rlci) { + if (!eci) { return false; } - if (((rlci->pos[0] + threshold) >= x) && ((rlci->pos[0] - threshold) <= x) && - ((rlci->pos[1] + threshold) >= y) && ((rlci->pos[1] - threshold) <= y)) { + if (((eci->pos[0] + threshold) >= x) && ((eci->pos[0] - threshold) <= x) && + ((eci->pos[1] + threshold) >= y) && ((eci->pos[1] - threshold) <= y)) { return true; } return false; } -static LineartLineChainItem *lineart_chain_append_point(LineartRenderBuffer *rb, - LineartLineChain *rlc, +static LineartEdgeChainItem *lineart_chain_append_point(LineartRenderBuffer *rb, + LineartEdgeChain *ec, float *fbcoord, float *gpos, float *normal, @@ -106,35 +106,35 @@ static LineartLineChainItem *lineart_chain_append_point(LineartRenderBuffer *rb, unsigned char transparency_mask, size_t index) { - LineartLineChainItem *rlci; + LineartEdgeChainItem *eci; - if (lineart_point_overlapping(rlc->chain.last, fbcoord[0], fbcoord[1], 1e-5)) { + if (lineart_point_overlapping(ec->chain.last, fbcoord[0], fbcoord[1], 1e-5)) { /* Because the new chain point is overlapping, just replace the type and occlusion level of the * current point. This makes it so that the line to the point after this one has the correct * type and level. */ - LineartLineChainItem *old_rlci = rlc->chain.last; + LineartEdgeChainItem *old_rlci = ec->chain.last; old_rlci->line_type = type; old_rlci->occlusion = level; old_rlci->transparency_mask = transparency_mask; return old_rlci; } - rlci = lineart_mem_acquire(&rb->render_data_pool, sizeof(LineartLineChainItem)); + eci = lineart_mem_acquire(&rb->render_data_pool, sizeof(LineartEdgeChainItem)); - copy_v2_v2(rlci->pos, fbcoord); - copy_v3_v3(rlci->gpos, gpos); - rlci->index = index; - copy_v3_v3(rlci->normal, normal); - rlci->line_type = type & LRT_EDGE_FLAG_ALL_TYPE; - rlci->occlusion = level; - rlci->transparency_mask = transparency_mask; - BLI_addtail(&rlc->chain, rlci); + copy_v2_v2(eci->pos, fbcoord); + copy_v3_v3(eci->gpos, gpos); + eci->index = index; + copy_v3_v3(eci->normal, normal); + eci->line_type = type & LRT_EDGE_FLAG_ALL_TYPE; + eci->occlusion = level; + eci->transparency_mask = transparency_mask; + BLI_addtail(&ec->chain, eci); - return rlci; + return eci; } -static LineartLineChainItem *lineart_chain_prepend_point(LineartRenderBuffer *rb, - LineartLineChain *rlc, +static LineartEdgeChainItem *lineart_chain_prepend_point(LineartRenderBuffer *rb, + LineartEdgeChain *ec, float *fbcoord, float *gpos, float *normal, @@ -143,32 +143,32 @@ static LineartLineChainItem *lineart_chain_prepend_point(LineartRenderBuffer *rb unsigned char transparency_mask, size_t index) { - LineartLineChainItem *rlci; + LineartEdgeChainItem *eci; - if (lineart_point_overlapping(rlc->chain.first, fbcoord[0], fbcoord[1], 1e-5)) { - return rlc->chain.first; + if (lineart_point_overlapping(ec->chain.first, fbcoord[0], fbcoord[1], 1e-5)) { + return ec->chain.first; } - rlci = lineart_mem_acquire(&rb->render_data_pool, sizeof(LineartLineChainItem)); + eci = lineart_mem_acquire(&rb->render_data_pool, sizeof(LineartEdgeChainItem)); - copy_v2_v2(rlci->pos, fbcoord); - copy_v3_v3(rlci->gpos, gpos); - rlci->index = index; - copy_v3_v3(rlci->normal, normal); - rlci->line_type = type & LRT_EDGE_FLAG_ALL_TYPE; - rlci->occlusion = level; - rlci->transparency_mask = transparency_mask; - BLI_addhead(&rlc->chain, rlci); + copy_v2_v2(eci->pos, fbcoord); + copy_v3_v3(eci->gpos, gpos); + eci->index = index; + copy_v3_v3(eci->normal, normal); + eci->line_type = type & LRT_EDGE_FLAG_ALL_TYPE; + eci->occlusion = level; + eci->transparency_mask = transparency_mask; + BLI_addhead(&ec->chain, eci); - return rlci; + return eci; } void MOD_lineart_chain_feature_lines(LineartRenderBuffer *rb) { - LineartLineChain *rlc; - LineartLineChainItem *rlci; + LineartEdgeChain *ec; + LineartEdgeChainItem *eci; LineartBoundingArea *ba; - LineartLineSegment *rls; + LineartEdgeSegment *es; int last_occlusion; unsigned char last_transparency; /* Used when converting from double. */ @@ -192,14 +192,14 @@ void MOD_lineart_chain_feature_lines(LineartRenderBuffer *rb) e->flags |= LRT_EDGE_FLAG_CHAIN_PICKED; - rlc = lineart_chain_create(rb); + ec = lineart_chain_create(rb); /* One chain can only have one object_ref, * so we assign it based on the first segment we found. */ - rlc->object_ref = e->object_ref; + ec->object_ref = e->object_ref; LineartEdge *new_e = e; - LineartVert *new_rv; + LineartVert *new_vt; float N[3] = {0}; if (e->t1) { @@ -218,19 +218,19 @@ void MOD_lineart_chain_feature_lines(LineartRenderBuffer *rb) /* Step 1: grow left. */ ba = MOD_lineart_get_bounding_area(rb, e->v1->fbcoord[0], e->v1->fbcoord[1]); - new_rv = e->v1; - rls = e->segments.first; - VERT_COORD_TO_FLOAT(new_rv); + new_vt = e->v1; + es = e->segments.first; + VERT_COORD_TO_FLOAT(new_vt); lineart_chain_prepend_point(rb, - rlc, + ec, use_fbcoord, use_gpos, N, e->flags, - rls->occlusion, - rls->transparency_mask, + es->occlusion, + es->transparency_mask, e->v1_obindex); - while (ba && (new_e = lineart_line_get_connected(ba, new_rv, &new_rv, e->flags))) { + while (ba && (new_e = lineart_line_get_connected(ba, new_vt, &new_vt, e->flags))) { new_e->flags |= LRT_EDGE_FLAG_CHAIN_PICKED; if (new_e->t1 || new_e->t2) { @@ -248,41 +248,41 @@ void MOD_lineart_chain_feature_lines(LineartRenderBuffer *rb) normalize_v3(N); } - if (new_rv == new_e->v1) { - for (rls = new_e->segments.last; rls; rls = rls->prev) { + if (new_vt == new_e->v1) { + for (es = new_e->segments.last; es; es = es->prev) { double gpos[3], lpos[3]; double *lfb = new_e->v1->fbcoord, *rfb = new_e->v2->fbcoord; - double global_at = lfb[3] * rls->at / (rls->at * lfb[3] + (1 - rls->at) * rfb[3]); - interp_v3_v3v3_db(lpos, new_e->v1->fbcoord, new_e->v2->fbcoord, rls->at); + double global_at = lfb[3] * es->at / (es->at * lfb[3] + (1 - es->at) * rfb[3]); + interp_v3_v3v3_db(lpos, new_e->v1->fbcoord, new_e->v2->fbcoord, es->at); interp_v3_v3v3_db(gpos, new_e->v1->gloc, new_e->v2->gloc, global_at); POS_TO_FLOAT(lpos, gpos) lineart_chain_prepend_point(rb, - rlc, + ec, use_fbcoord, use_gpos, N, new_e->flags, - rls->occlusion, - rls->transparency_mask, + es->occlusion, + es->transparency_mask, new_e->v1_obindex); - last_occlusion = rls->occlusion; - last_transparency = rls->transparency_mask; + last_occlusion = es->occlusion; + last_transparency = es->transparency_mask; } } - else if (new_rv == new_e->v2) { - rls = new_e->segments.first; - last_occlusion = rls->occlusion; - last_transparency = rls->transparency_mask; - rls = rls->next; - for (; rls; rls = rls->next) { + else if (new_vt == new_e->v2) { + es = new_e->segments.first; + last_occlusion = es->occlusion; + last_transparency = es->transparency_mask; + es = es->next; + for (; es; es = es->next) { double gpos[3], lpos[3]; double *lfb = new_e->v1->fbcoord, *rfb = new_e->v2->fbcoord; - double global_at = lfb[3] * rls->at / (rls->at * lfb[3] + (1 - rls->at) * rfb[3]); - interp_v3_v3v3_db(lpos, new_e->v1->fbcoord, new_e->v2->fbcoord, rls->at); + double global_at = lfb[3] * es->at / (es->at * lfb[3] + (1 - es->at) * rfb[3]); + interp_v3_v3v3_db(lpos, new_e->v1->fbcoord, new_e->v2->fbcoord, es->at); interp_v3_v3v3_db(gpos, new_e->v1->gloc, new_e->v2->gloc, global_at); POS_TO_FLOAT(lpos, gpos) lineart_chain_prepend_point(rb, - rlc, + ec, use_fbcoord, use_gpos, N, @@ -290,12 +290,12 @@ void MOD_lineart_chain_feature_lines(LineartRenderBuffer *rb) last_occlusion, last_transparency, new_e->v2_obindex); - last_occlusion = rls->occlusion; - last_transparency = rls->transparency_mask; + last_occlusion = es->occlusion; + last_transparency = es->transparency_mask; } VERT_COORD_TO_FLOAT(new_e->v2); lineart_chain_prepend_point(rb, - rlc, + ec, use_fbcoord, use_gpos, N, @@ -304,7 +304,7 @@ void MOD_lineart_chain_feature_lines(LineartRenderBuffer *rb) last_transparency, new_e->v2_obindex); } - ba = MOD_lineart_get_bounding_area(rb, new_rv->fbcoord[0], new_rv->fbcoord[1]); + ba = MOD_lineart_get_bounding_area(rb, new_vt->fbcoord[0], new_vt->fbcoord[1]); } /* Restore normal value. */ @@ -324,31 +324,31 @@ void MOD_lineart_chain_feature_lines(LineartRenderBuffer *rb) } /* Step 2: Adding all cuts from the given line, so we can continue connecting the right side * of the line. */ - rls = e->segments.first; - last_occlusion = ((LineartLineSegment *)rls)->occlusion; - last_transparency = ((LineartLineSegment *)rls)->transparency_mask; - for (rls = rls->next; rls; rls = rls->next) { + es = e->segments.first; + last_occlusion = ((LineartEdgeSegment *)es)->occlusion; + last_transparency = ((LineartEdgeSegment *)es)->transparency_mask; + for (es = es->next; es; es = es->next) { double gpos[3], lpos[3]; double *lfb = e->v1->fbcoord, *rfb = e->v2->fbcoord; - double global_at = lfb[3] * rls->at / (rls->at * lfb[3] + (1 - rls->at) * rfb[3]); - interp_v3_v3v3_db(lpos, e->v1->fbcoord, e->v2->fbcoord, rls->at); + double global_at = lfb[3] * es->at / (es->at * lfb[3] + (1 - es->at) * rfb[3]); + interp_v3_v3v3_db(lpos, e->v1->fbcoord, e->v2->fbcoord, es->at); interp_v3_v3v3_db(gpos, e->v1->gloc, e->v2->gloc, global_at); POS_TO_FLOAT(lpos, gpos) lineart_chain_append_point(rb, - rlc, + ec, use_fbcoord, use_gpos, N, e->flags, - rls->occlusion, - rls->transparency_mask, + es->occlusion, + es->transparency_mask, e->v1_obindex); - last_occlusion = rls->occlusion; - last_transparency = rls->transparency_mask; + last_occlusion = es->occlusion; + last_transparency = es->transparency_mask; } VERT_COORD_TO_FLOAT(e->v2) lineart_chain_append_point(rb, - rlc, + ec, use_fbcoord, use_gpos, N, @@ -359,8 +359,8 @@ void MOD_lineart_chain_feature_lines(LineartRenderBuffer *rb) /* Step 3: grow right. */ ba = MOD_lineart_get_bounding_area(rb, e->v2->fbcoord[0], e->v2->fbcoord[1]); - new_rv = e->v2; - while (ba && (new_e = lineart_line_get_connected(ba, new_rv, &new_rv, e->flags))) { + new_vt = e->v2; + while (ba && (new_e = lineart_line_get_connected(ba, new_vt, &new_vt, e->flags))) { new_e->flags |= LRT_EDGE_FLAG_CHAIN_PICKED; if (new_e->t1 || new_e->t2) { @@ -379,27 +379,27 @@ void MOD_lineart_chain_feature_lines(LineartRenderBuffer *rb) } /* Fix leading vertex type. */ - rlci = rlc->chain.last; - rlci->line_type = new_e->flags & LRT_EDGE_FLAG_ALL_TYPE; + eci = ec->chain.last; + eci->line_type = new_e->flags & LRT_EDGE_FLAG_ALL_TYPE; - if (new_rv == new_e->v1) { - rls = new_e->segments.last; - last_occlusion = rls->occlusion; - last_transparency = rls->transparency_mask; + if (new_vt == new_e->v1) { + es = new_e->segments.last; + last_occlusion = es->occlusion; + last_transparency = es->transparency_mask; /* Fix leading vertex occlusion. */ - rlci->occlusion = last_occlusion; - rlci->transparency_mask = last_transparency; - for (rls = new_e->segments.last; rls; rls = rls->prev) { + eci->occlusion = last_occlusion; + eci->transparency_mask = last_transparency; + for (es = new_e->segments.last; es; es = es->prev) { double gpos[3], lpos[3]; double *lfb = new_e->v1->fbcoord, *rfb = new_e->v2->fbcoord; - double global_at = lfb[3] * rls->at / (rls->at * lfb[3] + (1 - rls->at) * rfb[3]); - interp_v3_v3v3_db(lpos, new_e->v1->fbcoord, new_e->v2->fbcoord, rls->at); + double global_at = lfb[3] * es->at / (es->at * lfb[3] + (1 - es->at) * rfb[3]); + interp_v3_v3v3_db(lpos, new_e->v1->fbcoord, new_e->v2->fbcoord, es->at); interp_v3_v3v3_db(gpos, new_e->v1->gloc, new_e->v2->gloc, global_at); - last_occlusion = rls->prev ? rls->prev->occlusion : last_occlusion; - last_transparency = rls->prev ? rls->prev->transparency_mask : last_transparency; + last_occlusion = es->prev ? es->prev->occlusion : last_occlusion; + last_transparency = es->prev ? es->prev->transparency_mask : last_transparency; POS_TO_FLOAT(lpos, gpos) lineart_chain_append_point(rb, - rlc, + ec, use_fbcoord, use_gpos, N, @@ -409,35 +409,35 @@ void MOD_lineart_chain_feature_lines(LineartRenderBuffer *rb) new_e->v1_obindex); } } - else if (new_rv == new_e->v2) { - rls = new_e->segments.first; - last_occlusion = rls->occlusion; - last_transparency = rls->transparency_mask; - rlci->occlusion = last_occlusion; - rlci->transparency_mask = last_transparency; - rls = rls->next; - for (; rls; rls = rls->next) { + else if (new_vt == new_e->v2) { + es = new_e->segments.first; + last_occlusion = es->occlusion; + last_transparency = es->transparency_mask; + eci->occlusion = last_occlusion; + eci->transparency_mask = last_transparency; + es = es->next; + for (; es; es = es->next) { double gpos[3], lpos[3]; double *lfb = new_e->v1->fbcoord, *rfb = new_e->v2->fbcoord; - double global_at = lfb[3] * rls->at / (rls->at * lfb[3] + (1 - rls->at) * rfb[3]); - interp_v3_v3v3_db(lpos, new_e->v1->fbcoord, new_e->v2->fbcoord, rls->at); + double global_at = lfb[3] * es->at / (es->at * lfb[3] + (1 - es->at) * rfb[3]); + interp_v3_v3v3_db(lpos, new_e->v1->fbcoord, new_e->v2->fbcoord, es->at); interp_v3_v3v3_db(gpos, new_e->v1->gloc, new_e->v2->gloc, global_at); POS_TO_FLOAT(lpos, gpos) lineart_chain_append_point(rb, - rlc, + ec, use_fbcoord, use_gpos, N, new_e->flags, - rls->occlusion, - rls->transparency_mask, + es->occlusion, + es->transparency_mask, new_e->v2_obindex); - last_occlusion = rls->occlusion; - last_transparency = rls->transparency_mask; + last_occlusion = es->occlusion; + last_transparency = es->transparency_mask; } VERT_COORD_TO_FLOAT(new_e->v2) lineart_chain_append_point(rb, - rlc, + ec, use_fbcoord, use_gpos, N, @@ -446,57 +446,57 @@ void MOD_lineart_chain_feature_lines(LineartRenderBuffer *rb) last_transparency, new_e->v2_obindex); } - ba = MOD_lineart_get_bounding_area(rb, new_rv->fbcoord[0], new_rv->fbcoord[1]); + ba = MOD_lineart_get_bounding_area(rb, new_vt->fbcoord[0], new_vt->fbcoord[1]); } if (rb->fuzzy_everything) { - rlc->type = LRT_EDGE_FLAG_CONTOUR; + ec->type = LRT_EDGE_FLAG_CONTOUR; } else { - rlc->type = (e->flags & LRT_EDGE_FLAG_ALL_TYPE); + ec->type = (e->flags & LRT_EDGE_FLAG_ALL_TYPE); } } LRT_ITER_ALL_LINES_END } -static LineartBoundingArea *lineart_bounding_area_get_rlci_recursive(LineartRenderBuffer *rb, - LineartBoundingArea *root, - LineartLineChainItem *rlci) +static LineartBoundingArea *lineart_bounding_area_get_eci_recursive(LineartRenderBuffer *rb, + LineartBoundingArea *root, + LineartEdgeChainItem *eci) { if (root->child == NULL) { return root; } LineartBoundingArea *ch = root->child; -#define IN_BOUND(ba, rlci) \ - ba.l <= rlci->pos[0] && ba.r >= rlci->pos[0] && ba.b <= rlci->pos[1] && ba.u >= rlci->pos[1] +#define IN_BOUND(ba, eci) \ + ba.l <= eci->pos[0] && ba.r >= eci->pos[0] && ba.b <= eci->pos[1] && ba.u >= eci->pos[1] - if (IN_BOUND(ch[0], rlci)) { - return lineart_bounding_area_get_rlci_recursive(rb, &ch[0], rlci); + if (IN_BOUND(ch[0], eci)) { + return lineart_bounding_area_get_eci_recursive(rb, &ch[0], eci); } - if (IN_BOUND(ch[1], rlci)) { - return lineart_bounding_area_get_rlci_recursive(rb, &ch[1], rlci); + if (IN_BOUND(ch[1], eci)) { + return lineart_bounding_area_get_eci_recursive(rb, &ch[1], eci); } - if (IN_BOUND(ch[2], rlci)) { - return lineart_bounding_area_get_rlci_recursive(rb, &ch[2], rlci); + if (IN_BOUND(ch[2], eci)) { + return lineart_bounding_area_get_eci_recursive(rb, &ch[2], eci); } - if (IN_BOUND(ch[3], rlci)) { - return lineart_bounding_area_get_rlci_recursive(rb, &ch[3], rlci); + if (IN_BOUND(ch[3], eci)) { + return lineart_bounding_area_get_eci_recursive(rb, &ch[3], eci); } #undef IN_BOUND return NULL; } static LineartBoundingArea *lineart_bounding_area_get_end_point(LineartRenderBuffer *rb, - LineartLineChainItem *rlci) + LineartEdgeChainItem *eci) { - if (!rlci) { + if (!eci) { return NULL; } - LineartBoundingArea *root = MOD_lineart_get_parent_bounding_area(rb, rlci->pos[0], rlci->pos[1]); + LineartBoundingArea *root = MOD_lineart_get_parent_bounding_area(rb, eci->pos[0], eci->pos[1]); if (root == NULL) { return NULL; } - return lineart_bounding_area_get_rlci_recursive(rb, root, rlci); + return lineart_bounding_area_get_eci_recursive(rb, root, eci); } /** @@ -507,61 +507,61 @@ static LineartBoundingArea *lineart_bounding_area_get_end_point(LineartRenderBuf */ static void lineart_bounding_area_link_point_recursive(LineartRenderBuffer *rb, LineartBoundingArea *root, - LineartLineChain *rlc, - LineartLineChainItem *rlci) + LineartEdgeChain *ec, + LineartEdgeChainItem *eci) { if (root->child == NULL) { LineartChainRegisterEntry *cre = lineart_list_append_pointer_pool_sized( - &root->linked_chains, &rb->render_data_pool, rlc, sizeof(LineartChainRegisterEntry)); + &root->linked_chains, &rb->render_data_pool, ec, sizeof(LineartChainRegisterEntry)); - cre->rlci = rlci; + cre->eci = eci; - if (rlci == rlc->chain.first) { + if (eci == ec->chain.first) { cre->is_left = 1; } } else { LineartBoundingArea *ch = root->child; -#define IN_BOUND(ba, rlci) \ - ba.l <= rlci->pos[0] && ba.r >= rlci->pos[0] && ba.b <= rlci->pos[1] && ba.u >= rlci->pos[1] +#define IN_BOUND(ba, eci) \ + ba.l <= eci->pos[0] && ba.r >= eci->pos[0] && ba.b <= eci->pos[1] && ba.u >= eci->pos[1] - if (IN_BOUND(ch[0], rlci)) { - lineart_bounding_area_link_point_recursive(rb, &ch[0], rlc, rlci); + if (IN_BOUND(ch[0], eci)) { + lineart_bounding_area_link_point_recursive(rb, &ch[0], ec, eci); } - else if (IN_BOUND(ch[1], rlci)) { - lineart_bounding_area_link_point_recursive(rb, &ch[1], rlc, rlci); + else if (IN_BOUND(ch[1], eci)) { + lineart_bounding_area_link_point_recursive(rb, &ch[1], ec, eci); } - else if (IN_BOUND(ch[2], rlci)) { - lineart_bounding_area_link_point_recursive(rb, &ch[2], rlc, rlci); + else if (IN_BOUND(ch[2], eci)) { + lineart_bounding_area_link_point_recursive(rb, &ch[2], ec, eci); } - else if (IN_BOUND(ch[3], rlci)) { - lineart_bounding_area_link_point_recursive(rb, &ch[3], rlc, rlci); + else if (IN_BOUND(ch[3], eci)) { + lineart_bounding_area_link_point_recursive(rb, &ch[3], ec, eci); } #undef IN_BOUND } } -static void lineart_bounding_area_link_chain(LineartRenderBuffer *rb, LineartLineChain *rlc) +static void lineart_bounding_area_link_chain(LineartRenderBuffer *rb, LineartEdgeChain *ec) { - LineartLineChainItem *pl = rlc->chain.first; - LineartLineChainItem *pr = rlc->chain.last; + LineartEdgeChainItem *pl = ec->chain.first; + LineartEdgeChainItem *pr = ec->chain.last; LineartBoundingArea *ba1 = MOD_lineart_get_parent_bounding_area(rb, pl->pos[0], pl->pos[1]); LineartBoundingArea *ba2 = MOD_lineart_get_parent_bounding_area(rb, pr->pos[0], pr->pos[1]); if (ba1) { - lineart_bounding_area_link_point_recursive(rb, ba1, rlc, pl); + lineart_bounding_area_link_point_recursive(rb, ba1, ec, pl); } if (ba2) { - lineart_bounding_area_link_point_recursive(rb, ba2, rlc, pr); + lineart_bounding_area_link_point_recursive(rb, ba2, ec, pr); } } void MOD_lineart_chain_split_for_fixed_occlusion(LineartRenderBuffer *rb) { - LineartLineChain *rlc, *new_rlc; - LineartLineChainItem *rlci, *next_rlci; + LineartEdgeChain *ec, *new_rlc; + LineartEdgeChainItem *eci, *next_rlci; ListBase swap = {0}; swap.first = rb->chains.first; @@ -569,59 +569,59 @@ void MOD_lineart_chain_split_for_fixed_occlusion(LineartRenderBuffer *rb) rb->chains.last = rb->chains.first = NULL; - while ((rlc = BLI_pophead(&swap)) != NULL) { - rlc->next = rlc->prev = NULL; - BLI_addtail(&rb->chains, rlc); - LineartLineChainItem *first_rlci = (LineartLineChainItem *)rlc->chain.first; + while ((ec = BLI_pophead(&swap)) != NULL) { + ec->next = ec->prev = NULL; + BLI_addtail(&rb->chains, ec); + LineartEdgeChainItem *first_rlci = (LineartEdgeChainItem *)ec->chain.first; int fixed_occ = first_rlci->occlusion; unsigned char fixed_mask = first_rlci->transparency_mask; - rlc->level = fixed_occ; - rlc->transparency_mask = fixed_mask; - for (rlci = first_rlci->next; rlci; rlci = next_rlci) { - next_rlci = rlci->next; - if (rlci->occlusion != fixed_occ || rlci->transparency_mask != fixed_mask) { + ec->level = fixed_occ; + ec->transparency_mask = fixed_mask; + for (eci = first_rlci->next; eci; eci = next_rlci) { + next_rlci = eci->next; + if (eci->occlusion != fixed_occ || eci->transparency_mask != fixed_mask) { if (next_rlci) { - if (lineart_point_overlapping(next_rlci, rlci->pos[0], rlci->pos[1], 1e-5)) { + if (lineart_point_overlapping(next_rlci, eci->pos[0], eci->pos[1], 1e-5)) { continue; } } else { /* Set the same occlusion level for the end vertex, so when further connection is needed * the backwards occlusion info is also correct. */ - rlci->occlusion = fixed_occ; - rlci->transparency_mask = fixed_mask; + eci->occlusion = fixed_occ; + eci->transparency_mask = fixed_mask; /* No need to split at the last point anyway. */ break; } new_rlc = lineart_chain_create(rb); - new_rlc->chain.first = rlci; - new_rlc->chain.last = rlc->chain.last; - rlc->chain.last = rlci->prev; - ((LineartLineChainItem *)rlc->chain.last)->next = 0; - rlci->prev = 0; + new_rlc->chain.first = eci; + new_rlc->chain.last = ec->chain.last; + ec->chain.last = eci->prev; + ((LineartEdgeChainItem *)ec->chain.last)->next = 0; + eci->prev = 0; /* End the previous one. */ lineart_chain_append_point(rb, - rlc, - rlci->pos, - rlci->gpos, - rlci->normal, - rlci->line_type, + ec, + eci->pos, + eci->gpos, + eci->normal, + eci->line_type, fixed_occ, fixed_mask, - rlci->index); - new_rlc->object_ref = rlc->object_ref; - new_rlc->type = rlc->type; - rlc = new_rlc; - fixed_occ = rlci->occlusion; - fixed_mask = rlci->transparency_mask; - rlc->level = fixed_occ; - rlc->transparency_mask = fixed_mask; + eci->index); + new_rlc->object_ref = ec->object_ref; + new_rlc->type = ec->type; + ec = new_rlc; + fixed_occ = eci->occlusion; + fixed_mask = eci->transparency_mask; + ec->level = fixed_occ; + ec->transparency_mask = fixed_mask; } } } - LISTBASE_FOREACH (LineartLineChain *, irlc, &rb->chains) { - lineart_bounding_area_link_chain(rb, irlc); + LISTBASE_FOREACH (LineartEdgeChain *, iec, &rb->chains) { + lineart_bounding_area_link_chain(rb, iec); } } @@ -629,12 +629,12 @@ void MOD_lineart_chain_split_for_fixed_occlusion(LineartRenderBuffer *rb) * Note: segment type (crease/material/contour...) is ambiguous after this. */ static void lineart_chain_connect(LineartRenderBuffer *UNUSED(rb), - LineartLineChain *onto, - LineartLineChain *sub, + LineartEdgeChain *onto, + LineartEdgeChain *sub, int reverse_1, int reverse_2) { - LineartLineChainItem *rlci; + LineartEdgeChainItem *eci; if (onto->type == LRT_EDGE_FLAG_INTERSECTION) { if (sub->object_ref) { onto->object_ref = sub->object_ref; @@ -650,38 +650,38 @@ static void lineart_chain_connect(LineartRenderBuffer *UNUSED(rb), if (reverse_2) { /* L--R R-L. */ BLI_listbase_reverse(&sub->chain); } - rlci = sub->chain.first; - if (lineart_point_overlapping(onto->chain.last, rlci->pos[0], rlci->pos[1], 1e-5)) { + eci = sub->chain.first; + if (lineart_point_overlapping(onto->chain.last, eci->pos[0], eci->pos[1], 1e-5)) { BLI_pophead(&sub->chain); if (sub->chain.first == NULL) { return; } } - ((LineartLineChainItem *)onto->chain.last)->next = sub->chain.first; - ((LineartLineChainItem *)sub->chain.first)->prev = onto->chain.last; + ((LineartEdgeChainItem *)onto->chain.last)->next = sub->chain.first; + ((LineartEdgeChainItem *)sub->chain.first)->prev = onto->chain.last; onto->chain.last = sub->chain.last; } else { /* L-R L--R. */ if (!reverse_2) { /* R-L L--R. */ BLI_listbase_reverse(&sub->chain); } - rlci = onto->chain.first; - if (lineart_point_overlapping(sub->chain.last, rlci->pos[0], rlci->pos[1], 1e-5)) { + eci = onto->chain.first; + if (lineart_point_overlapping(sub->chain.last, eci->pos[0], eci->pos[1], 1e-5)) { BLI_pophead(&onto->chain); if (onto->chain.first == NULL) { return; } } - ((LineartLineChainItem *)sub->chain.last)->next = onto->chain.first; - ((LineartLineChainItem *)onto->chain.first)->prev = sub->chain.last; + ((LineartEdgeChainItem *)sub->chain.last)->next = onto->chain.first; + ((LineartEdgeChainItem *)onto->chain.first)->prev = sub->chain.last; onto->chain.first = sub->chain.first; } } static LineartChainRegisterEntry *lineart_chain_get_closest_cre(LineartRenderBuffer *rb, LineartBoundingArea *ba, - LineartLineChain *rlc, - LineartLineChainItem *rlci, + LineartEdgeChain *ec, + LineartEdgeChainItem *eci, int occlusion, unsigned char transparency_mask, float dist, @@ -694,12 +694,12 @@ static LineartChainRegisterEntry *lineart_chain_get_closest_cre(LineartRenderBuf /* Keep using for loop because `cre` could be removed from the iteration before getting to the * next one. */ LISTBASE_FOREACH_MUTABLE (LineartChainRegisterEntry *, cre, &ba->linked_chains) { - if (cre->rlc->object_ref != rlc->object_ref) { + if (cre->ec->object_ref != ec->object_ref) { if (!rb->fuzzy_everything) { if (rb->fuzzy_intersections) { /* If none of those are intersection lines... */ - if ((!(cre->rlc->type & LRT_EDGE_FLAG_INTERSECTION)) && - (!(rlc->type & LRT_EDGE_FLAG_INTERSECTION))) { + if ((!(cre->ec->type & LRT_EDGE_FLAG_INTERSECTION)) && + (!(ec->type & LRT_EDGE_FLAG_INTERSECTION))) { continue; /* We don't want to chain along different objects at the moment. */ } } @@ -708,18 +708,18 @@ static LineartChainRegisterEntry *lineart_chain_get_closest_cre(LineartRenderBuf } } } - if (cre->rlc->picked || cre->picked) { + if (cre->ec->picked || cre->picked) { continue; } - if (cre->rlc == rlc || (!cre->rlc->chain.first) || (cre->rlc->level != occlusion) || - (cre->rlc->transparency_mask != transparency_mask)) { + if (cre->ec == ec || (!cre->ec->chain.first) || (cre->ec->level != occlusion) || + (cre->ec->transparency_mask != transparency_mask)) { continue; } if (!rb->fuzzy_everything) { - if (cre->rlc->type != rlc->type) { + if (cre->ec->type != ec->type) { if (rb->fuzzy_intersections) { - if (!(cre->rlc->type == LRT_EDGE_FLAG_INTERSECTION || - rlc->type == LRT_EDGE_FLAG_INTERSECTION)) { + if (!(cre->ec->type == LRT_EDGE_FLAG_INTERSECTION || + ec->type == LRT_EDGE_FLAG_INTERSECTION)) { continue; /* Fuzzy intersections but no intersection line found. */ } } @@ -729,7 +729,7 @@ static LineartChainRegisterEntry *lineart_chain_get_closest_cre(LineartRenderBuf } } - float new_len = len_v2v2(cre->rlci->pos, rlci->pos); + float new_len = len_v2v2(cre->eci->pos, eci->pos); if (new_len < dist) { closest_cre = cre; dist = new_len; @@ -748,7 +748,7 @@ static LineartChainRegisterEntry *lineart_chain_get_closest_cre(LineartRenderBuf LISTBASE_FOREACH (LinkData *, ld, list) { \ LineartBoundingArea *sba = (LineartBoundingArea *)ld->data; \ adjacent_closest = lineart_chain_get_closest_cre( \ - rb, sba, rlc, rlci, occlusion, transparency_mask, dist, &adjacent_new_len, ba); \ + rb, sba, ec, eci, occlusion, transparency_mask, dist, &adjacent_new_len, ba); \ if (adjacent_new_len < dist) { \ dist = adjacent_new_len; \ closest_cre = adjacent_closest; \ @@ -756,10 +756,10 @@ static LineartChainRegisterEntry *lineart_chain_get_closest_cre(LineartRenderBuf } \ } if (!caller_ba) { - LRT_TEST_ADJACENT_AREAS(rlci->pos[0] - ba->l, &ba->lp); - LRT_TEST_ADJACENT_AREAS(ba->r - rlci->pos[0], &ba->rp); - LRT_TEST_ADJACENT_AREAS(ba->u - rlci->pos[1], &ba->up); - LRT_TEST_ADJACENT_AREAS(rlci->pos[1] - ba->b, &ba->bp); + LRT_TEST_ADJACENT_AREAS(eci->pos[0] - ba->l, &ba->lp); + LRT_TEST_ADJACENT_AREAS(ba->r - eci->pos[0], &ba->rp); + LRT_TEST_ADJACENT_AREAS(ba->u - eci->pos[1], &ba->up); + LRT_TEST_ADJACENT_AREAS(eci->pos[1] - ba->b, &ba->bp); } if (result_new_len) { (*result_new_len) = dist; @@ -774,8 +774,8 @@ static LineartChainRegisterEntry *lineart_chain_get_closest_cre(LineartRenderBuf */ void MOD_lineart_chain_connect(LineartRenderBuffer *rb) { - LineartLineChain *rlc; - LineartLineChainItem *rlci_l, *rlci_r; + LineartEdgeChain *ec; + LineartEdgeChainItem *rlci_l, *rlci_r; LineartBoundingArea *ba_l, *ba_r; LineartChainRegisterEntry *closest_cre_l, *closest_cre_r, *closest_cre; float dist = rb->chaining_image_threshold; @@ -793,24 +793,24 @@ void MOD_lineart_chain_connect(LineartRenderBuffer *rb) rb->chains.last = rb->chains.first = NULL; - while ((rlc = BLI_pophead(&swap)) != NULL) { - rlc->next = rlc->prev = NULL; - if (rlc->picked) { + while ((ec = BLI_pophead(&swap)) != NULL) { + ec->next = ec->prev = NULL; + if (ec->picked) { continue; } - BLI_addtail(&rb->chains, rlc); + BLI_addtail(&rb->chains, ec); - occlusion = rlc->level; - transparency_mask = rlc->transparency_mask; + occlusion = ec->level; + transparency_mask = ec->transparency_mask; - rlci_l = rlc->chain.first; - rlci_r = rlc->chain.last; + rlci_l = ec->chain.first; + rlci_r = ec->chain.last; while ((ba_l = lineart_bounding_area_get_end_point(rb, rlci_l)) && (ba_r = lineart_bounding_area_get_end_point(rb, rlci_r))) { closest_cre_l = lineart_chain_get_closest_cre( - rb, ba_l, rlc, rlci_l, occlusion, transparency_mask, dist, &dist_l, NULL); + rb, ba_l, ec, rlci_l, occlusion, transparency_mask, dist, &dist_l, NULL); closest_cre_r = lineart_chain_get_closest_cre( - rb, ba_r, rlc, rlci_r, occlusion, transparency_mask, dist, &dist_r, NULL); + rb, ba_r, ec, rlci_r, occlusion, transparency_mask, dist, &dist_r, NULL); if (closest_cre_l && closest_cre_r) { if (dist_l < dist_r) { closest_cre = closest_cre_l; @@ -834,56 +834,56 @@ void MOD_lineart_chain_connect(LineartRenderBuffer *rb) break; } closest_cre->picked = 1; - closest_cre->rlc->picked = 1; + closest_cre->ec->picked = 1; if (closest_cre->is_left) { - lineart_chain_connect(rb, rlc, closest_cre->rlc, reverse_main, 0); + lineart_chain_connect(rb, ec, closest_cre->ec, reverse_main, 0); } else { - lineart_chain_connect(rb, rlc, closest_cre->rlc, reverse_main, 1); + lineart_chain_connect(rb, ec, closest_cre->ec, reverse_main, 1); } - BLI_remlink(&swap, closest_cre->rlc); - rlci_l = rlc->chain.first; - rlci_r = rlc->chain.last; + BLI_remlink(&swap, closest_cre->ec); + rlci_l = ec->chain.first; + rlci_r = ec->chain.last; } - rlc->picked = 1; + ec->picked = 1; } } /** * Length is in image space. */ -float MOD_lineart_chain_compute_length(LineartLineChain *rlc) +float MOD_lineart_chain_compute_length(LineartEdgeChain *ec) { - LineartLineChainItem *rlci; + LineartEdgeChainItem *eci; float offset_accum = 0; float dist; float last_point[2]; - rlci = rlc->chain.first; - copy_v2_v2(last_point, rlci->pos); - for (rlci = rlc->chain.first; rlci; rlci = rlci->next) { - dist = len_v2v2(rlci->pos, last_point); + eci = ec->chain.first; + copy_v2_v2(last_point, eci->pos); + for (eci = ec->chain.first; eci; eci = eci->next) { + dist = len_v2v2(eci->pos, last_point); offset_accum += dist; - copy_v2_v2(last_point, rlci->pos); + copy_v2_v2(last_point, eci->pos); } return offset_accum; } void MOD_lineart_chain_discard_short(LineartRenderBuffer *rb, const float threshold) { - LineartLineChain *rlc, *next_rlc; - for (rlc = rb->chains.first; rlc; rlc = next_rlc) { - next_rlc = rlc->next; - if (MOD_lineart_chain_compute_length(rlc) < threshold) { - BLI_remlink(&rb->chains, rlc); + LineartEdgeChain *ec, *next_rlc; + for (ec = rb->chains.first; ec; ec = next_rlc) { + next_rlc = ec->next; + if (MOD_lineart_chain_compute_length(ec) < threshold) { + BLI_remlink(&rb->chains, ec); } } } -int MOD_lineart_chain_count(const LineartLineChain *rlc) +int MOD_lineart_chain_count(const LineartEdgeChain *ec) { int count = 0; - LISTBASE_FOREACH (LineartLineChainItem *, rlci, &rlc->chain) { + LISTBASE_FOREACH (LineartEdgeChainItem *, eci, &ec->chain) { count++; } return count; @@ -894,8 +894,8 @@ void MOD_lineart_chain_clear_picked_flag(LineartRenderBuffer *rb) if (rb == NULL) { return; } - LISTBASE_FOREACH (LineartLineChain *, rlc, &rb->chains) { - rlc->picked = 0; + LISTBASE_FOREACH (LineartEdgeChain *, ec, &rb->chains) { + ec->picked = 0; } } @@ -905,8 +905,8 @@ void MOD_lineart_chain_clear_picked_flag(LineartRenderBuffer *rb) */ void MOD_lineart_chain_split_angle(LineartRenderBuffer *rb, float angle_threshold_rad) { - LineartLineChain *rlc, *new_rlc; - LineartLineChainItem *rlci, *next_rlci, *prev_rlci; + LineartEdgeChain *ec, *new_rlc; + LineartEdgeChainItem *eci, *next_rlci, *prev_rlci; ListBase swap = {0}; swap.first = rb->chains.first; @@ -914,43 +914,43 @@ void MOD_lineart_chain_split_angle(LineartRenderBuffer *rb, float angle_threshol rb->chains.last = rb->chains.first = NULL; - while ((rlc = BLI_pophead(&swap)) != NULL) { - rlc->next = rlc->prev = NULL; - BLI_addtail(&rb->chains, rlc); - LineartLineChainItem *first_rlci = (LineartLineChainItem *)rlc->chain.first; - for (rlci = first_rlci->next; rlci; rlci = next_rlci) { - next_rlci = rlci->next; - prev_rlci = rlci->prev; + while ((ec = BLI_pophead(&swap)) != NULL) { + ec->next = ec->prev = NULL; + BLI_addtail(&rb->chains, ec); + LineartEdgeChainItem *first_rlci = (LineartEdgeChainItem *)ec->chain.first; + for (eci = first_rlci->next; eci; eci = next_rlci) { + next_rlci = eci->next; + prev_rlci = eci->prev; float angle = M_PI; if (next_rlci && prev_rlci) { - angle = angle_v2v2v2(prev_rlci->pos, rlci->pos, next_rlci->pos); + angle = angle_v2v2v2(prev_rlci->pos, eci->pos, next_rlci->pos); } else { break; /* No need to split at the last point anyway.*/ } if (angle < angle_threshold_rad) { new_rlc = lineart_chain_create(rb); - new_rlc->chain.first = rlci; - new_rlc->chain.last = rlc->chain.last; - rlc->chain.last = rlci->prev; - ((LineartLineChainItem *)rlc->chain.last)->next = 0; - rlci->prev = 0; + new_rlc->chain.first = eci; + new_rlc->chain.last = ec->chain.last; + ec->chain.last = eci->prev; + ((LineartEdgeChainItem *)ec->chain.last)->next = 0; + eci->prev = 0; /* End the previous one. */ lineart_chain_append_point(rb, - rlc, - rlci->pos, - rlci->gpos, - rlci->normal, - rlci->line_type, - rlc->level, - rlci->transparency_mask, - rlci->index); - new_rlc->object_ref = rlc->object_ref; - new_rlc->type = rlc->type; - new_rlc->level = rlc->level; - new_rlc->transparency_mask = rlc->transparency_mask; - rlc = new_rlc; + ec, + eci->pos, + eci->gpos, + eci->normal, + eci->line_type, + ec->level, + eci->transparency_mask, + eci->index); + new_rlc->object_ref = ec->object_ref; + new_rlc->type = ec->type; + new_rlc->level = ec->level; + new_rlc->transparency_mask = ec->transparency_mask; + ec = new_rlc; } } } |