Blender V5.3
lineart_chain.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_listbase.hh"
10#include "BLI_math_geom_c.hh"
11
12#include "MOD_lineart.hh"
13
14#include "lineart_intern.hh"
15
16#include <algorithm> /* For `min/max`. */
17#include <cmath>
18
19namespace blender {
20
21#define LRT_OTHER_VERT(e, vt) ((vt) == (e)->v1 ? (e)->v2 : ((vt) == (e)->v2 ? (e)->v1 : nullptr))
22
23struct Object;
24
25/* Get a connected line, only for lines who has the exact given vert, or (in the case of
26 * intersection lines) who has a vert that has the exact same position. */
28 LineartVert *vt,
29 LineartVert **new_vt,
30 int match_flag,
31 uint8_t match_isec_mask,
32 Object *match_isec_object)
33{
34 for (int i = 0; i < ba->line_count; i++) {
35 LineartEdge *n_e = ba->linked_lines[i];
36
39 {
40 continue;
41 }
42
43 if (match_flag && ((n_e->flags & MOD_LINEART_EDGE_FLAG_ALL_TYPE) & match_flag) == 0) {
44 continue;
45 }
46
47 if (n_e->intersection_mask != match_isec_mask) {
48 continue;
49 }
50
51 *new_vt = LRT_OTHER_VERT(n_e, vt);
52 if (*new_vt) {
53 return n_e;
54 }
55
57 if (n_e->object_ref != match_isec_object) {
58 continue;
59 }
60 if (vt->fbcoord[0] == n_e->v1->fbcoord[0] && vt->fbcoord[1] == n_e->v1->fbcoord[1]) {
61 *new_vt = LRT_OTHER_VERT(n_e, n_e->v1);
62 return n_e;
63 }
64 if (vt->fbcoord[0] == n_e->v2->fbcoord[0] && vt->fbcoord[1] == n_e->v2->fbcoord[1]) {
65 *new_vt = LRT_OTHER_VERT(n_e, n_e->v2);
66 return n_e;
67 }
68 }
69 }
70
71 return nullptr;
72}
73
75{
77 ec = static_cast<LineartEdgeChain *>(
79
80 BLI_addtail(&ld->chains, ec);
81
82 return ec;
83}
84
86 float x,
87 float y,
88 double threshold)
89{
90 if (!eci) {
91 return false;
92 }
93 if (((eci->pos[0] + threshold) >= x) && ((eci->pos[0] - threshold) <= x) &&
94 ((eci->pos[1] + threshold) >= y) && ((eci->pos[1] - threshold) <= y))
95 {
96 return true;
97 }
98 return false;
99}
100
103 float fbcoord[4],
104 float gpos[3],
105 float normal[3],
106 uint8_t type,
107 int level,
108 uint8_t material_mask_bits,
109 uint32_t shadow_mask_bits,
110 size_t index)
111{
113
114 if (lineart_point_overlapping(ec->chain.last(), fbcoord[0], fbcoord[1], 1e-5)) {
115 /* Because the new chain point is overlapping, just replace the type and occlusion level of the
116 * current point. This makes it so that the line to the point after this one has the correct
117 * type and level. */
118 LineartEdgeChainItem *old_eci = ec->chain.last();
119 old_eci->line_type = type;
120 old_eci->occlusion = level;
121 old_eci->material_mask_bits = material_mask_bits;
122 old_eci->shadow_mask_bits = shadow_mask_bits;
123 return old_eci;
124 }
125
126 eci = static_cast<LineartEdgeChainItem *>(
128
129 copy_v4_v4(eci->pos, fbcoord);
130 copy_v3_v3(eci->gpos, gpos);
131 eci->index = index;
132 copy_v3_v3(eci->normal, normal);
134 eci->occlusion = level;
135 eci->material_mask_bits = material_mask_bits;
136 eci->shadow_mask_bits = shadow_mask_bits;
137 BLI_addtail(&ec->chain, eci);
138
139 return eci;
140}
141
144 float fbcoord[4],
145 float gpos[3],
146 float normal[3],
147 uint8_t type,
148 int level,
149 uint8_t material_mask_bits,
150 uint32_t shadow_mask_bits,
151 size_t index)
152{
154
155 if (lineart_point_overlapping(ec->chain.first(), fbcoord[0], fbcoord[1], 1e-5)) {
156 return ec->chain.first();
157 }
158
159 eci = static_cast<LineartEdgeChainItem *>(
161
162 copy_v4_v4(eci->pos, fbcoord);
163 copy_v3_v3(eci->gpos, gpos);
164 eci->index = index;
165 copy_v3_v3(eci->normal, normal);
167 eci->occlusion = level;
168 eci->material_mask_bits = material_mask_bits;
169 eci->shadow_mask_bits = shadow_mask_bits;
170 BLI_addhead(&ec->chain, eci);
171
172 return eci;
173}
174
176{
181 int last_occlusion;
182 uint8_t last_transparency;
183 uint32_t last_shadow;
184 /* Used when converting from double. */
185 float use_fbcoord[4];
186 float use_gpos[3];
187
188#define VERT_COORD_TO_FLOAT(a) \
189 copy_v4fl_v4db(use_fbcoord, (a)->fbcoord); \
190 copy_v3fl_v3db(use_gpos, (a)->gloc);
191
192#define POS_TO_FLOAT(lpos, gpos) \
193 copy_v3fl_v3db(use_fbcoord, lpos); \
194 copy_v3fl_v3db(use_gpos, gpos);
195
197 {
198 if (!(e->flags & MOD_LINEART_EDGE_FLAG_ALL_TYPE) ||
200 {
202 continue;
203 }
204
206
207 ec = lineart_chain_create(ld);
208
209 /* One chain can only have one object_ref and intersection_mask,
210 * so we assign them based on the first segment we found. */
211 ec->object_ref = e->object_ref;
212 ec->intersection_mask = e->intersection_mask;
213
214 LineartEdge *new_e;
215 LineartVert *new_vt;
216 float N[3] = {0};
217
219 /* We do not have actual target triangle reference for projected shadow lines, so the normal
220 * is unavailable at this point. In which case we set that to (0,0,1). */
221 N[0] = 1.0f;
222 }
223 else {
224 if (e->t1) {
225 N[0] += e->t1->gn[0];
226 N[1] += e->t1->gn[1];
227 N[2] += e->t1->gn[2];
228 }
229 if (e->t2) {
230 N[0] += e->t2->gn[0];
231 N[1] += e->t2->gn[1];
232 N[2] += e->t2->gn[2];
233 }
234 if (e->t1 || e->t2) {
236 }
237 }
238
239 /* Step 1: grow left. */
240 ba = MOD_lineart_get_bounding_area(ld, e->v1->fbcoord[0], e->v1->fbcoord[1]);
241 new_vt = e->v1;
242 es = e->segments.first();
243 VERT_COORD_TO_FLOAT(new_vt);
245 ec,
246 use_fbcoord,
247 use_gpos,
248 N,
249 e->flags,
250 es->occlusion,
253 e->v1->index);
254 while (ba && (new_e = lineart_line_get_connected(
255 ba, new_vt, &new_vt, e->flags, ec->intersection_mask, ec->object_ref)))
256 {
258
259 if (new_e->t1 || new_e->t2) {
260 zero_v3(N);
261 if (new_e->t1) {
262 N[0] += new_e->t1->gn[0];
263 N[1] += new_e->t1->gn[1];
264 N[2] += new_e->t1->gn[2];
265 }
266 if (new_e->t2) {
267 N[0] += new_e->t2->gn[0];
268 N[1] += new_e->t2->gn[1];
269 N[2] += new_e->t2->gn[2];
270 }
272 }
273
274 if (new_vt == new_e->v1) {
275 for (LineartEdgeSegment &es : new_e->segments.items_reversed()) {
276 double gpos[3], lpos[3];
277 double *lfb = new_e->v1->fbcoord, *rfb = new_e->v2->fbcoord;
278 double global_at = lfb[3] * es.ratio / (es.ratio * lfb[3] + (1 - es.ratio) * rfb[3]);
279 interp_v3_v3v3_db(lpos, new_e->v1->fbcoord, new_e->v2->fbcoord, es.ratio);
280 interp_v3_v3v3_db(gpos, new_e->v1->gloc, new_e->v2->gloc, global_at);
281 use_fbcoord[3] = interpf(new_e->v2->fbcoord[3], new_e->v1->fbcoord[3], global_at);
282 POS_TO_FLOAT(lpos, gpos)
284 ec,
285 use_fbcoord,
286 use_gpos,
287 N,
288 new_e->flags,
289 es.occlusion,
292 new_e->v1->index);
293 last_occlusion = es.occlusion;
294 last_transparency = es.material_mask_bits;
295 last_shadow = es.shadow_mask_bits;
296 }
297 }
298 else if (new_vt == new_e->v2) {
299 es = new_e->segments.first();
300 last_occlusion = es->occlusion;
301 last_transparency = es->material_mask_bits;
302 last_shadow = es->shadow_mask_bits;
303 es = es->next;
304 for (; es; es = es->next) {
305 double gpos[3], lpos[3];
306 double *lfb = new_e->v1->fbcoord, *rfb = new_e->v2->fbcoord;
307 double global_at = lfb[3] * es->ratio / (es->ratio * lfb[3] + (1 - es->ratio) * rfb[3]);
308 interp_v3_v3v3_db(lpos, new_e->v1->fbcoord, new_e->v2->fbcoord, es->ratio);
309 interp_v3_v3v3_db(gpos, new_e->v1->gloc, new_e->v2->gloc, global_at);
310 use_fbcoord[3] = interpf(new_e->v2->fbcoord[3], new_e->v1->fbcoord[3], global_at);
311 POS_TO_FLOAT(lpos, gpos)
313 ec,
314 use_fbcoord,
315 use_gpos,
316 N,
317 new_e->flags,
318 last_occlusion,
319 last_transparency,
320 last_shadow,
321 new_e->v2->index);
322 last_occlusion = es->occlusion;
323 last_transparency = es->material_mask_bits;
324 last_shadow = es->shadow_mask_bits;
325 }
326 VERT_COORD_TO_FLOAT(new_e->v2);
328 ec,
329 use_fbcoord,
330 use_gpos,
331 N,
332 new_e->flags,
333 last_occlusion,
334 last_transparency,
335 last_shadow,
336 new_e->v2->index);
337 }
338 ba = MOD_lineart_get_bounding_area(ld, new_vt->fbcoord[0], new_vt->fbcoord[1]);
339 }
340
341 /* Restore normal value. */
342 if (e->t1 || e->t2) {
343 zero_v3(N);
344 if (e->t1) {
345 N[0] += e->t1->gn[0];
346 N[1] += e->t1->gn[1];
347 N[2] += e->t1->gn[2];
348 }
349 if (e->t2) {
350 N[0] += e->t2->gn[0];
351 N[1] += e->t2->gn[1];
352 N[2] += e->t2->gn[2];
353 }
355 }
356 /* Step 2: Adding all cuts from the given line, so we can continue connecting the right side
357 * of the line. */
358 es = e->segments.first();
359 last_occlusion = es->occlusion;
360 last_transparency = es->material_mask_bits;
361 last_shadow = es->shadow_mask_bits;
362 for (es = es->next; es; es = es->next) {
363 double gpos[3], lpos[3];
364 double *lfb = e->v1->fbcoord, *rfb = e->v2->fbcoord;
365 double global_at = lfb[3] * es->ratio / (es->ratio * lfb[3] + (1 - es->ratio) * rfb[3]);
366 interp_v3_v3v3_db(lpos, e->v1->fbcoord, e->v2->fbcoord, es->ratio);
367 interp_v3_v3v3_db(gpos, e->v1->gloc, e->v2->gloc, global_at);
368 use_fbcoord[3] = interpf(e->v2->fbcoord[3], e->v1->fbcoord[3], global_at);
369 POS_TO_FLOAT(lpos, gpos)
371 ec,
372 use_fbcoord,
373 use_gpos,
374 N,
375 e->flags,
376 es->occlusion,
379 e->v1->index);
380 last_occlusion = es->occlusion;
381 last_transparency = es->material_mask_bits;
382 last_shadow = es->shadow_mask_bits;
383 }
386 ec,
387 use_fbcoord,
388 use_gpos,
389 N,
390 e->flags,
391 last_occlusion,
392 last_transparency,
393 last_shadow,
394 e->v2->index);
395
396 /* Step 3: grow right. */
397 ba = MOD_lineart_get_bounding_area(ld, e->v2->fbcoord[0], e->v2->fbcoord[1]);
398 new_vt = e->v2;
399 while (ba && (new_e = lineart_line_get_connected(
400 ba, new_vt, &new_vt, e->flags, ec->intersection_mask, ec->object_ref)))
401 {
403
404 if (new_e->t1 || new_e->t2) {
405 zero_v3(N);
406 if (new_e->t1) {
407 N[0] += new_e->t1->gn[0];
408 N[1] += new_e->t1->gn[1];
409 N[2] += new_e->t1->gn[2];
410 }
411 if (new_e->t2) {
412 N[0] += new_e->t2->gn[0];
413 N[1] += new_e->t2->gn[1];
414 N[2] += new_e->t2->gn[2];
415 }
417 }
418
419 /* Fix leading vertex type. */
420 eci = ec->chain.last();
422
423 if (new_vt == new_e->v1) {
424 es = new_e->segments.last();
425 last_occlusion = es->occlusion;
426 last_transparency = es->material_mask_bits;
427 last_shadow = es->shadow_mask_bits;
428 /* Fix leading vertex occlusion. */
429 eci->occlusion = last_occlusion;
430 eci->material_mask_bits = last_transparency;
431 eci->shadow_mask_bits = last_shadow;
432 for (LineartEdgeSegment &es : new_e->segments.items_reversed()) {
433 double gpos[3], lpos[3];
434 double *lfb = new_e->v1->fbcoord, *rfb = new_e->v2->fbcoord;
435 double global_at = lfb[3] * es.ratio / (es.ratio * lfb[3] + (1 - es.ratio) * rfb[3]);
436 interp_v3_v3v3_db(lpos, new_e->v1->fbcoord, new_e->v2->fbcoord, es.ratio);
437 interp_v3_v3v3_db(gpos, new_e->v1->gloc, new_e->v2->gloc, global_at);
438 use_fbcoord[3] = interpf(new_e->v2->fbcoord[3], new_e->v1->fbcoord[3], global_at);
439 last_occlusion = es.prev ? es.prev->occlusion : last_occlusion;
440 last_transparency = es.prev ? es.prev->material_mask_bits : last_transparency;
441 last_shadow = es.prev ? es.prev->shadow_mask_bits : last_shadow;
442 POS_TO_FLOAT(lpos, gpos)
444 ec,
445 use_fbcoord,
446 use_gpos,
447 N,
448 new_e->flags,
449 last_occlusion,
450 last_transparency,
451 last_shadow,
452 new_e->v1->index);
453 }
454 }
455 else if (new_vt == new_e->v2) {
456 es = new_e->segments.first();
457 last_occlusion = es->occlusion;
458 last_transparency = es->material_mask_bits;
459 last_shadow = es->shadow_mask_bits;
460 eci->occlusion = last_occlusion;
461 eci->material_mask_bits = last_transparency;
462 eci->shadow_mask_bits = last_shadow;
463 es = es->next;
464 for (; es; es = es->next) {
465 double gpos[3], lpos[3];
466 double *lfb = new_e->v1->fbcoord, *rfb = new_e->v2->fbcoord;
467 double global_at = lfb[3] * es->ratio / (es->ratio * lfb[3] + (1 - es->ratio) * rfb[3]);
468 interp_v3_v3v3_db(lpos, new_e->v1->fbcoord, new_e->v2->fbcoord, es->ratio);
469 interp_v3_v3v3_db(gpos, new_e->v1->gloc, new_e->v2->gloc, global_at);
470 use_fbcoord[3] = interpf(new_e->v2->fbcoord[3], new_e->v1->fbcoord[3], global_at);
471 POS_TO_FLOAT(lpos, gpos)
473 ec,
474 use_fbcoord,
475 use_gpos,
476 N,
477 new_e->flags,
478 es->occlusion,
481 new_e->v2->index);
482 last_occlusion = es->occlusion;
483 last_transparency = es->material_mask_bits;
484 last_shadow = es->shadow_mask_bits;
485 }
486 VERT_COORD_TO_FLOAT(new_e->v2)
488 ec,
489 use_fbcoord,
490 use_gpos,
491 N,
492 new_e->flags,
493 last_occlusion,
494 last_transparency,
495 last_shadow,
496 new_e->v2->index);
497 }
498 ba = MOD_lineart_get_bounding_area(ld, new_vt->fbcoord[0], new_vt->fbcoord[1]);
499 }
500 if (ld->conf.fuzzy_everything) {
502 }
503 else {
504 ec->type = (e->flags & MOD_LINEART_EDGE_FLAG_ALL_TYPE);
505 }
506 }
508}
509
513{
514 if (root->child == nullptr) {
515 return root;
516 }
517
518 LineartBoundingArea *ch = root->child;
519#define IN_BOUND(ba, eci) \
520 ba.l <= eci->pos[0] && ba.r >= eci->pos[0] && ba.b <= eci->pos[1] && ba.u >= eci->pos[1]
521
522 if (IN_BOUND(ch[0], eci)) {
523 return lineart_bounding_area_get_eci_recursive(ld, &ch[0], eci);
524 }
525 if (IN_BOUND(ch[1], eci)) {
526 return lineart_bounding_area_get_eci_recursive(ld, &ch[1], eci);
527 }
528 if (IN_BOUND(ch[2], eci)) {
529 return lineart_bounding_area_get_eci_recursive(ld, &ch[2], eci);
530 }
531 if (IN_BOUND(ch[3], eci)) {
532 return lineart_bounding_area_get_eci_recursive(ld, &ch[3], eci);
533 }
534#undef IN_BOUND
535 return nullptr;
536}
537
540{
541 if (!eci) {
542 return nullptr;
543 }
545 if (root == nullptr) {
546 return nullptr;
547 }
548 return lineart_bounding_area_get_eci_recursive(ld, root, eci);
549}
550
561{
562 if (root->child == nullptr) {
566
567 cre->eci = eci;
568
569 if (eci == ec->chain.first()) {
570 cre->is_left = 1;
571 }
572 }
573 else {
574 LineartBoundingArea *ch = root->child;
575
576#define IN_BOUND(ba, eci) \
577 ba.l <= eci->pos[0] && ba.r >= eci->pos[0] && ba.b <= eci->pos[1] && ba.u >= eci->pos[1]
578
579 if (IN_BOUND(ch[0], eci)) {
581 }
582 else if (IN_BOUND(ch[1], eci)) {
584 }
585 else if (IN_BOUND(ch[2], eci)) {
587 }
588 else if (IN_BOUND(ch[3], eci)) {
590 }
591
592#undef IN_BOUND
593 }
594}
595
597{
598 LineartEdgeChainItem *pl = ec->chain.first();
599 LineartEdgeChainItem *pr = ec->chain.last();
602
603 if (ba1) {
605 }
606 if (ba2) {
608 }
609}
610
612 LineartEdgeChainItem *last_matching_eci,
613 float distance_threshold,
614 bool preserve_details,
615 LineartEdgeChainItem **r_next_eci)
616{
617 float dist_accum = 0;
618
619 int fixed_occ = last_matching_eci->occlusion;
620 uint8_t fixed_mask = last_matching_eci->material_mask_bits;
621 uint32_t fixed_shadow = last_matching_eci->shadow_mask_bits;
622
623 LineartEdgeChainItem *can_skip_to = nullptr;
624 LineartEdgeChainItem *last_eci = last_matching_eci;
625 for (LineartEdgeChainItem *eci = last_matching_eci->next; eci; eci = eci->next) {
626 dist_accum += len_v2v2(last_eci->pos, eci->pos);
627 if (dist_accum > distance_threshold) {
628 break;
629 }
630 last_eci = eci;
631 /* The reason for this is because we don't want visible segments to be "skipped" into
632 * connecting with invisible segments. */
633 if (eci->occlusion < fixed_occ) {
634 break;
635 }
636 if (eci->material_mask_bits == fixed_mask && eci->occlusion == fixed_occ &&
637 eci->shadow_mask_bits == fixed_shadow)
638 {
639 can_skip_to = eci;
640 }
641 }
642 if (can_skip_to) {
643 /* Either mark all in-between segments with the same occlusion and mask or delete those
644 * different ones. */
645 LineartEdgeChainItem *next_eci;
646 for (LineartEdgeChainItem *eci = last_matching_eci->next; eci != can_skip_to; eci = next_eci) {
647 next_eci = eci->next;
648 if (eci->material_mask_bits == fixed_mask && eci->occlusion == fixed_occ &&
649 eci->shadow_mask_bits == fixed_shadow)
650 {
651 continue;
652 }
653 if (preserve_details) {
654 eci->material_mask_bits = fixed_mask;
655 eci->occlusion = fixed_occ;
656 eci->shadow_mask_bits = fixed_shadow;
657 }
658 else {
659 BLI_remlink(&ec->chain, eci);
660 }
661 }
662 *r_next_eci = can_skip_to;
663 return true;
664 }
665 return false;
666}
667
669{
670 LineartEdgeChainItem *eci, *next_eci;
671 ListBaseT<void> swap = {nullptr};
672
673 swap.first_ = ld->chains.first_;
674 swap.last_ = ld->chains.last();
675
676 ld->chains.last_ = ld->chains.first_ = nullptr;
677
678 int loop_id = 0;
679 while (LineartEdgeChain *ec = static_cast<LineartEdgeChain *>(BLI_pophead(&swap))) {
680 ec->next = ec->prev = nullptr;
681 BLI_addtail(&ld->chains, ec);
682
683 ec->loop_id = loop_id;
684 loop_id++;
685
686 LineartEdgeChainItem *first_eci = ec->chain.first();
687 int fixed_occ = first_eci->occlusion;
688 uint8_t fixed_mask = first_eci->material_mask_bits;
689 uint32_t fixed_shadow = first_eci->shadow_mask_bits;
690 ec->level = fixed_occ;
691 ec->material_mask_bits = fixed_mask;
692 ec->shadow_mask_bits = fixed_shadow;
693 for (eci = first_eci->next; eci; eci = next_eci) {
694 next_eci = eci->next;
695 if (eci->occlusion != fixed_occ || eci->material_mask_bits != fixed_mask ||
696 eci->shadow_mask_bits != fixed_shadow)
697 {
698 if (next_eci) {
699 if (lineart_point_overlapping(next_eci, eci->pos[0], eci->pos[1], 1e-5)) {
700 continue;
701 }
703 eci->prev,
706 &next_eci))
707 {
708 continue;
709 }
710 }
711 else {
712 /* Set the same occlusion level for the end vertex, so when further connection is needed
713 * the backwards occlusion info is also correct. */
714 eci->occlusion = fixed_occ;
715 eci->shadow_mask_bits = fixed_shadow;
716 eci->material_mask_bits = fixed_mask;
717 /* No need to split at the last point anyway. */
718 break;
719 }
721 new_ec->chain.first_ = eci;
722 new_ec->chain.last_ = ec->chain.last();
723 new_ec->loop_id = loop_id;
724 ec->chain.last_ = eci->prev;
725 (ec->chain.last())->next = nullptr;
726 eci->prev = nullptr;
727
728 /* End the previous one. */
730 ec,
731 eci->pos,
732 eci->gpos,
733 eci->normal,
734 eci->line_type,
735 fixed_occ,
736 fixed_mask,
737 fixed_shadow,
738 eci->index);
739 new_ec->object_ref = ec->object_ref;
740 new_ec->type = ec->type;
741 new_ec->intersection_mask = ec->intersection_mask;
742 ec = new_ec;
743 fixed_occ = eci->occlusion;
744 fixed_mask = eci->material_mask_bits;
745 fixed_shadow = eci->shadow_mask_bits;
746 ec->level = fixed_occ;
747 ec->material_mask_bits = fixed_mask;
748 ec->shadow_mask_bits = fixed_shadow;
749 }
750 }
751 }
752
754
755 for (LineartEdgeChain &iec : ld->chains) {
757 }
758}
759
764 LineartEdgeChain *onto,
765 LineartEdgeChain *sub,
766 int reverse_1,
767 int reverse_2)
768{
773 }
774 if (sub->object_ref) {
775 onto->object_ref = sub->object_ref;
776 }
777 }
778 else if (sub->type == MOD_LINEART_EDGE_FLAG_INTERSECTION) {
781 }
782 }
783 if (!reverse_1) { /* L--R L-R. */
784 if (reverse_2) { /* L--R R-L. */
786 }
787 eci = sub->chain.first();
788 if (lineart_point_overlapping(onto->chain.last(), eci->pos[0], eci->pos[1], 1e-5)) {
789 BLI_pophead(&sub->chain);
790 if (sub->chain.first() == nullptr) {
791 return;
792 }
793 }
794 (onto->chain.last())->next = sub->chain.first();
795 (sub->chain.first())->prev = onto->chain.last();
796 onto->chain.last_ = sub->chain.last();
797 }
798 else { /* L-R L--R. */
799 if (!reverse_2) { /* R-L L--R. */
801 }
802 eci = onto->chain.first();
803 if (lineart_point_overlapping(sub->chain.last(), eci->pos[0], eci->pos[1], 1e-5)) {
804 BLI_pophead(&onto->chain);
805 if (onto->chain.first() == nullptr) {
806 return;
807 }
808 }
809 (sub->chain.last())->next = onto->chain.first();
810 (onto->chain.first())->prev = sub->chain.last();
811 onto->chain.first_ = sub->chain.first_;
812 }
813}
814
819 int occlusion,
820 uint8_t material_mask_bits,
821 uint8_t isec_mask,
822 uint32_t shadow_mask,
823 int loop_id,
824 float dist,
825 float *result_new_len,
826 LineartBoundingArea *caller_ba)
827{
828
829 LineartChainRegisterEntry *closest_cre = nullptr;
830
831 /* Keep using for loop because `cre` could be removed from the iteration before getting to the
832 * next one. */
833 for (LineartChainRegisterEntry &cre : ba->linked_chains.items_mutable()) {
834 if (cre.ec->object_ref != ec->object_ref) {
835 if (!ld->conf.fuzzy_everything) {
836 if (ld->conf.fuzzy_intersections) {
837 /* If none of those are intersection lines... */
838 if (!(cre.ec->type & MOD_LINEART_EDGE_FLAG_INTERSECTION) &&
840 {
841 continue; /* We don't want to chain along different objects at the moment. */
842 }
843 }
844 else {
845 continue;
846 }
847 }
848 }
849 if (cre.ec->picked || cre.picked) {
850 continue;
851 }
852 if (cre.ec == ec || (!cre.ec->chain.first()) || (cre.ec->level != occlusion) ||
853 (cre.ec->material_mask_bits != material_mask_bits) ||
854 (cre.ec->intersection_mask != isec_mask) || (cre.ec->shadow_mask_bits != shadow_mask))
855 {
856 continue;
857 }
858 if (!ld->conf.fuzzy_everything) {
859 if (cre.ec->type != ec->type) {
860 if (ld->conf.fuzzy_intersections) {
861 if (!(cre.ec->type == MOD_LINEART_EDGE_FLAG_INTERSECTION ||
863 {
864 continue; /* Fuzzy intersections but no intersection line found. */
865 }
866 }
867 else { /* Line type different but no fuzzy. */
868 continue;
869 }
870 }
871 }
872
873 float new_len = ld->conf.use_geometry_space_chain ? len_v3v3(cre.eci->gpos, eci->gpos) :
874 len_v2v2(cre.eci->pos, eci->pos);
875 /* Even if the vertex is not from the same contour loop, we try to chain it still if the
876 * distance is small enough. This way we can better chain smaller loops and smooth them out
877 * later. */
878 if (((cre.ec->loop_id == loop_id) && (new_len < dist)) ||
879 ((cre.ec->loop_id != loop_id) && (new_len < dist / 10)))
880 {
881 closest_cre = &cre;
882 dist = new_len;
883 if (result_new_len) {
884 (*result_new_len) = new_len;
885 }
886 }
887 }
888
889 /* We want a closer point anyway. So using modified dist is fine. */
890 float adjacent_new_len = dist;
891 LineartChainRegisterEntry *adjacent_closest;
892
893#define LRT_TEST_ADJACENT_AREAS(dist_to, list) \
894 if (dist_to < dist && dist_to > 0) { \
895 for (LinkData &link : list) { \
896 LineartBoundingArea *sba = (LineartBoundingArea *)link.data; \
897 adjacent_closest = lineart_chain_get_closest_cre(ld, \
898 sba, \
899 ec, \
900 eci, \
901 occlusion, \
902 material_mask_bits, \
903 isec_mask, \
904 shadow_mask, \
905 loop_id, \
906 dist, \
907 &adjacent_new_len, \
908 ba); \
909 if (adjacent_new_len < dist) { \
910 dist = adjacent_new_len; \
911 closest_cre = adjacent_closest; \
912 } \
913 } \
914 }
915 if (!caller_ba) {
916 LRT_TEST_ADJACENT_AREAS(eci->pos[0] - ba->l, ba->lp);
917 LRT_TEST_ADJACENT_AREAS(ba->r - eci->pos[0], ba->rp);
918 LRT_TEST_ADJACENT_AREAS(ba->u - eci->pos[1], ba->up);
919 LRT_TEST_ADJACENT_AREAS(eci->pos[1] - ba->b, ba->bp);
920 }
921 if (result_new_len) {
922 (*result_new_len) = dist;
923 }
924 return closest_cre;
925}
926
928{
929 LineartEdgeChainItem *eci_l, *eci_r;
930 LineartBoundingArea *ba_l, *ba_r;
931 LineartChainRegisterEntry *closest_cre_l, *closest_cre_r, *closest_cre;
932 float dist = ld->conf.chaining_image_threshold;
933 float dist_l, dist_r;
934 int reverse_main, loop_id;
935 uint8_t occlusion, material_mask_bits, isec_mask;
936 uint32_t shadow_mask;
937 ListBaseT<void> swap = {nullptr};
938
939 if (ld->conf.chaining_image_threshold < 0.0001) {
940 return;
941 }
942
943 swap.first_ = ld->chains.first_;
944 swap.last_ = ld->chains.last();
945
946 ld->chains.last_ = ld->chains.first_ = nullptr;
947
948 while (LineartEdgeChain *ec = static_cast<LineartEdgeChain *>(BLI_pophead(&swap))) {
949 ec->next = ec->prev = nullptr;
950 if (ec->picked || ec->chain.first() == ec->chain.last()) {
951 continue;
952 }
953 BLI_addtail(&ld->chains, ec);
954 loop_id = ec->loop_id;
955
956 if (ec->type == MOD_LINEART_EDGE_FLAG_LOOSE && (!ld->conf.use_loose_edge_chain)) {
957 continue;
958 }
959
960 occlusion = ec->level;
961 material_mask_bits = ec->material_mask_bits;
962 isec_mask = ec->intersection_mask;
963 shadow_mask = ec->shadow_mask_bits;
964
965 eci_l = ec->chain.first();
966 eci_r = ec->chain.last();
967 while ((ba_l = lineart_bounding_area_get_end_point(ld, eci_l)) &&
968 (ba_r = lineart_bounding_area_get_end_point(ld, eci_r)))
969 {
970 closest_cre_l = lineart_chain_get_closest_cre(ld,
971 ba_l,
972 ec,
973 eci_l,
974 occlusion,
975 material_mask_bits,
976 isec_mask,
977 shadow_mask,
978 loop_id,
979 dist,
980 &dist_l,
981 nullptr);
982 closest_cre_r = lineart_chain_get_closest_cre(ld,
983 ba_r,
984 ec,
985 eci_r,
986 occlusion,
987 material_mask_bits,
988 isec_mask,
989 shadow_mask,
990 loop_id,
991 dist,
992 &dist_r,
993 nullptr);
994 if (closest_cre_l && closest_cre_r) {
995 if (dist_l < dist_r) {
996 closest_cre = closest_cre_l;
997 reverse_main = 1;
998 }
999 else {
1000 closest_cre = closest_cre_r;
1001 reverse_main = 0;
1002 }
1003 }
1004 else if (closest_cre_l) {
1005 closest_cre = closest_cre_l;
1006 reverse_main = 1;
1007 }
1008 else if (closest_cre_r) {
1009 closest_cre = closest_cre_r;
1010 BLI_remlink(&ba_r->linked_chains, closest_cre_r);
1011 reverse_main = 0;
1012 }
1013 else {
1014 break;
1015 }
1016 closest_cre->picked = 1;
1017 closest_cre->ec->picked = 1;
1018 if (closest_cre->is_left) {
1019 lineart_chain_connect(ld, ec, closest_cre->ec, reverse_main, 0);
1020 }
1021 else {
1022 lineart_chain_connect(ld, ec, closest_cre->ec, reverse_main, 1);
1023 }
1024 BLI_remlink(&swap, closest_cre->ec);
1025 eci_l = ec->chain.first();
1026 eci_r = ec->chain.last();
1027 }
1028 ec->picked = 1;
1029 }
1030}
1031
1033{
1035 float offset_accum = 0;
1036 float dist;
1037 float last_point[2];
1038
1039 eci = ec->chain.first();
1040 if (!eci) {
1041 return 0;
1042 }
1043 copy_v2_v2(last_point, eci->pos);
1044 for (LineartEdgeChainItem &eci : ec->chain) {
1045 dist = len_v2v2(eci.pos, last_point);
1046 offset_accum += dist;
1047 copy_v2_v2(last_point, eci.pos);
1048 }
1049 return offset_accum;
1050}
1051
1053 const float threshold,
1054 uint8_t max_occlusion)
1055{
1056 LineartEdgeChain *ec, *next_ec;
1057 for (ec = ld->chains.first(); ec; ec = next_ec) {
1058 next_ec = ec->next;
1059 if (ec->level > max_occlusion || MOD_lineart_chain_compute_length(ec) < threshold) {
1060 BLI_remlink(&ld->chains, ec);
1061 }
1062 }
1063}
1064
1066{
1067 return ec->chain.count();
1068}
1069
1071{
1072 if (lc == nullptr) {
1073 return;
1074 }
1075 for (LineartEdgeChain &ec : lc->chains) {
1076 ec.picked = 0;
1077 }
1078}
1079
1080LineartElementLinkNode *lineart_find_matching_eln_obj(ListBaseT<LineartElementLinkNode> *elns,
1081 Object *ob)
1082{
1083 for (LineartElementLinkNode &eln : *elns) {
1084 if (eln.object_ref == ob) {
1085 return &eln;
1086 }
1087 }
1088 return nullptr;
1089}
1090
1092{
1093 for (LineartEdgeChain &ec : ld->chains) {
1094 if (ELEM(ec.type,
1098 {
1099 continue;
1100 }
1102 ec.object_ref);
1103 BLI_assert(eln != nullptr);
1104 if (eln) [[likely]] {
1105 for (LineartEdgeChainItem &eci : ec.chain) {
1106 if (eci.index > eln->global_index_offset) {
1107 eci.index -= eln->global_index_offset;
1108 }
1109 }
1110 }
1111 }
1112}
1113
1114void MOD_lineart_smooth_chains(LineartData *ld, float tolerance)
1115{
1116 for (LineartEdgeChain &ec : ld->chains) {
1117 /* Go through the chain two times, once from each direction. */
1118 for (int times = 0; times < 2; times++) {
1119 for (LineartEdgeChainItem *eci = ec.chain.first(), *next_eci = eci->next; eci;
1120 eci = next_eci)
1121 {
1122 LineartEdgeChainItem *eci2, *eci3, *eci4;
1123
1124 if (!(eci2 = eci->next) || !(eci3 = eci2->next)) {
1125 /* Not enough points to simplify. */
1126 next_eci = eci->next;
1127 continue;
1128 }
1129 /* No need to care for different line types/occlusion and so on, because at this stage they
1130 * are all the same within a chain.
1131 *
1132 * We need to simplify a chain from this:
1133 * 1-----------2
1134 * 3-----------4
1135 * to this:
1136 * 1-----------2--_
1137 * `--4 */
1138
1139 /* If p3 is within the p1-p2 segment of a width of "tolerance", in other words, p3 is
1140 * approximately on the segment of p1-p2. */
1141 if (dist_to_line_segment_v2(eci3->pos, eci->pos, eci2->pos) < tolerance) {
1142 float vec2[2], vec3[2], v2n[2], ratio, len2;
1143 sub_v2_v2v2(vec2, eci2->pos, eci->pos);
1144 sub_v2_v2v2(vec3, eci3->pos, eci->pos);
1145 normalize_v2_v2(v2n, vec2);
1146 ratio = dot_v2v2(v2n, vec3);
1147 len2 = len_v2(vec2);
1148 /* Because this smoothing applies on geometries of different scales in the same scene,
1149 * some small scale features (e.g. the "tails" on the inner ring of a torus geometry)
1150 * could be completely erased if the tolerance value is set for accommodating the entire
1151 * scene. Those situations typically result in (ratio << 0), looks like this:
1152 * 1---2
1153 * 3-------------------------------4
1154 * (this sort of long zigzag obviously are "features" that can't be erased)
1155 * setting a ratio of -10 turned out to be a reasonable threshold in tests. */
1156 if (ratio < len2 && ratio > -len2 * 10) {
1157 /* We only remove p3 if p4 is on the extension of p1->p2. */
1158 if ((eci4 = eci3->next) &&
1159 (dist_to_line_v2(eci4->pos, eci->pos, eci2->pos) < tolerance))
1160 {
1161 BLI_remlink(&ec.chain, eci3);
1162 next_eci = eci;
1163 continue;
1164 }
1165 if (!eci4) {
1166 /* See if the last segment's direction is reversed, if so remove that.
1167 * Basically we don't need to preserve p3 if the entire chain looked like this:
1168 * ...----1----3===2 */
1169 if (len_v2(vec2) > len_v2(vec3)) {
1170 BLI_remlink(&ec.chain, eci3);
1171 }
1172 next_eci = nullptr;
1173 continue;
1174 }
1175 }
1176 }
1177 next_eci = eci->next;
1178 }
1180 }
1181 }
1182}
1183
1185 LineartEdgeChainItem *eci_inside,
1186 LineartEdgeChainItem *eci_outside)
1187{
1188 float isec[2];
1189 /* l: left, r: right, b: bottom, u: top. */
1190 float ref_lu[2] = {-1.0f, 1.0f}, ref_lb[2] = {-1.0f, -1.0f}, ref_ru[2] = {1.0f, 1.0f},
1191 ref_rb[2] = {1.0f, -1.0f};
1192 bool found = false;
1193 LineartEdgeChainItem *eci2 = eci_outside, *eci1 = eci_inside;
1194 if (eci2->pos[0] < -1.0f) {
1195 found = (isect_seg_seg_v2_point(eci1->pos, eci2->pos, ref_lu, ref_lb, isec) > 0);
1196 }
1197 if (!found && eci2->pos[0] > 1.0f) {
1198 found = (isect_seg_seg_v2_point(eci1->pos, eci2->pos, ref_ru, ref_rb, isec) > 0);
1199 }
1200 if (!found && eci2->pos[1] < -1.0f) {
1201 found = (isect_seg_seg_v2_point(eci1->pos, eci2->pos, ref_lb, ref_rb, isec) > 0);
1202 }
1203 if (!found && eci2->pos[1] > 1.0f) {
1204 found = (isect_seg_seg_v2_point(eci1->pos, eci2->pos, ref_lu, ref_ru, isec) > 0);
1205 }
1206
1207 if (!found) [[unlikely]] {
1208 return nullptr;
1209 }
1210
1211 float ratio = (fabs(eci2->pos[0] - eci1->pos[0]) > fabs(eci2->pos[1] - eci1->pos[1])) ?
1212 ratiof(eci1->pos[0], eci2->pos[0], isec[0]) :
1213 ratiof(eci1->pos[1], eci2->pos[1], isec[1]);
1214 float gratio = eci1->pos[3] * ratio / (ratio * eci1->pos[3] + (1 - ratio) * eci2->pos[3]);
1215
1216 LineartEdgeChainItem *eci = static_cast<LineartEdgeChainItem *>(
1218 memcpy(eci, eci1, sizeof(LineartEdgeChainItem));
1219 interp_v3_v3v3(eci->gpos, eci1->gpos, eci2->gpos, gratio);
1220 interp_v3_v3v3(eci->pos, eci1->pos, eci2->pos, ratio);
1221 eci->pos[3] = interpf(eci2->pos[3], eci1->pos[3], gratio);
1222 eci->next = eci->prev = nullptr;
1223 return eci;
1224}
1225
1226#define LRT_ECI_INSIDE(eci) \
1227 ((eci)->pos[0] >= -1.0f && (eci)->pos[0] <= 1.0f && (eci)->pos[1] >= -1.0f && \
1228 (eci)->pos[1] <= 1.0f)
1229
1231{
1232 LineartEdgeChainItem *eci, *next_eci, *prev_eci, *new_eci;
1233 bool is_inside, new_inside;
1234 ListBaseT<void> swap = {nullptr};
1235 swap.first_ = ld->chains.first_;
1236 swap.last_ = ld->chains.last();
1237
1238 ld->chains.last_ = ld->chains.first_ = nullptr;
1239 while (LineartEdgeChain *ec = static_cast<LineartEdgeChain *>(BLI_pophead(&swap))) {
1240 bool ec_added = false;
1241 LineartEdgeChainItem *first_eci = ec->chain.first();
1242 is_inside = LRT_ECI_INSIDE(first_eci) ? true : false;
1243 if (!is_inside) {
1244 ec->picked = 1;
1245 }
1246 for (eci = first_eci->next; eci; eci = next_eci) {
1247 next_eci = eci->next;
1248 prev_eci = eci->prev;
1249
1250 /* We only need to do something if the edge crossed from outside to the inside or from inside
1251 * to the outside. */
1252 if ((new_inside = LRT_ECI_INSIDE(eci)) != is_inside) {
1253 if (new_inside == false) {
1254 /* Stroke goes out. */
1255 new_eci = lineart_chain_create_crossing_point(ld, prev_eci, eci);
1256
1257 LineartEdgeChain *new_ec = static_cast<LineartEdgeChain *>(
1259 memcpy(new_ec, ec, sizeof(LineartEdgeChain));
1260 new_ec->chain.first_ = next_eci;
1261 eci->prev = nullptr;
1262 prev_eci->next = nullptr;
1263 ec->chain.last_ = prev_eci;
1264 BLI_addtail(&ec->chain, new_eci);
1265 BLI_addtail(&ld->chains, ec);
1266 ec_added = true;
1267 ec = new_ec;
1268
1269 next_eci = eci->next;
1270 is_inside = new_inside;
1271 continue;
1272 }
1273 /* Stroke comes in. */
1274 new_eci = lineart_chain_create_crossing_point(ld, eci, prev_eci);
1275
1276 ec->chain.first_ = eci;
1277 eci->prev = nullptr;
1278
1279 BLI_addhead(&ec->chain, new_eci);
1280
1281 ec_added = false;
1282
1283 next_eci = eci->next;
1284 is_inside = new_inside;
1285 continue;
1286 }
1287 }
1288
1289 if ((!ec_added) && is_inside) {
1290 BLI_addtail(&ld->chains, ec);
1291 }
1292 }
1293}
1294
1295void MOD_lineart_chain_split_angle(LineartData *ld, float angle_threshold_rad)
1296{
1297 LineartEdgeChainItem *eci, *next_eci, *prev_eci;
1298 ListBaseT<void> swap = {nullptr};
1299
1300 swap.first_ = ld->chains.first_;
1301 swap.last_ = ld->chains.last();
1302
1303 ld->chains.last_ = ld->chains.first_ = nullptr;
1304
1305 while (LineartEdgeChain *ec = static_cast<LineartEdgeChain *>(BLI_pophead(&swap))) {
1306 ec->next = ec->prev = nullptr;
1307 BLI_addtail(&ld->chains, ec);
1308 LineartEdgeChainItem *first_eci = ec->chain.first();
1309 for (eci = first_eci->next; eci; eci = next_eci) {
1310 next_eci = eci->next;
1311 prev_eci = eci->prev;
1312 float angle = M_PI;
1313 if (next_eci && prev_eci) {
1314 angle = angle_v2v2v2(prev_eci->pos, eci->pos, next_eci->pos);
1315 }
1316 else {
1317 break; /* No need to split at the last point anyway. */
1318 }
1319 if (angle < angle_threshold_rad) {
1320 LineartEdgeChain *new_ec;
1321 new_ec = lineart_chain_create(ld);
1322 new_ec->chain.first_ = eci;
1323 new_ec->chain.last_ = ec->chain.last();
1324 ec->chain.last_ = eci->prev;
1325 (ec->chain.last())->next = nullptr;
1326 eci->prev = nullptr;
1327
1328 /* End the previous one. */
1330 ec,
1331 eci->pos,
1332 eci->gpos,
1333 eci->normal,
1334 eci->line_type,
1335 ec->level,
1336 eci->material_mask_bits,
1337 eci->shadow_mask_bits,
1338 eci->index);
1339 new_ec->object_ref = ec->object_ref;
1340 new_ec->type = ec->type;
1341 new_ec->level = ec->level;
1342 new_ec->loop_id = ec->loop_id;
1343 new_ec->intersection_mask = ec->intersection_mask;
1344 new_ec->material_mask_bits = ec->material_mask_bits;
1345 new_ec->shadow_mask_bits = ec->shadow_mask_bits;
1346 ec = new_ec;
1347 }
1348 }
1349 }
1350}
1351
1352void MOD_lineart_chain_offset_towards_camera(LineartData *ld, float dist, bool use_custom_camera)
1353{
1354 float dir[3];
1355 float cam[3];
1356 float view[3];
1357 float view_clamp[3];
1358
1359 if (use_custom_camera) {
1360 copy_v3fl_v3db(cam, ld->conf.camera_pos);
1361 }
1362 else {
1364 }
1365
1366 if (ld->conf.cam_is_persp) {
1367 for (LineartEdgeChain &ec : ld->chains) {
1368 for (LineartEdgeChainItem &eci : ec.chain) {
1369 sub_v3_v3v3(dir, cam, eci.gpos);
1370 float orig_len = len_v3(dir);
1371 normalize_v3(dir);
1372 mul_v3_fl(dir, std::min<float>(dist, orig_len - ld->conf.near_clip));
1373 add_v3_v3(eci.gpos, dir);
1374 }
1375 }
1376 }
1377 else {
1378 copy_v3fl_v3db(view, ld->conf.view_vector);
1379 for (LineartEdgeChain &ec : ld->chains) {
1380 for (LineartEdgeChainItem &eci : ec.chain) {
1381 sub_v3_v3v3(dir, cam, eci.gpos);
1382 float len_lim = dot_v3v3(view, dir) - ld->conf.near_clip;
1383 normalize_v3_v3(view_clamp, view);
1384 mul_v3_fl(view_clamp, std::min(dist, len_lim));
1385 add_v3_v3(eci.gpos, view_clamp);
1386 }
1387 }
1388 }
1389}
1390
1392{
1393 for (LineartEdgeChain &ec : ld->chains) {
1396 {
1399 target);
1400 if (!eln) {
1401 continue;
1402 }
1403 ec.silhouette_backdrop = static_cast<Object *>(eln->object_ref);
1404 }
1405 }
1406}
1407
1408} // namespace blender
#define M_PI
#define MOD_LINEART_EDGE_FLAG_ALL_TYPE
#define DBL_EDGE_LIM
#define LRT_OBINDEX_HIGHER
#define LRT_SHADOW_SILHOUETTE_ERASED_GROUP
#define ELEM(...)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
#define POS_TO_FLOAT(lpos, gpos)
#define LRT_ECI_INSIDE(eci)
#define VERT_COORD_TO_FLOAT(a)
#define LRT_OTHER_VERT(e, vt)
#define LRT_TEST_ADJACENT_AREAS(dist_to, list)
#define IN_BOUND(ba, eci)
#define LRT_ITER_ALL_LINES_END
#define LRT_ITER_ALL_LINES_NEXT
#define LRT_ITER_ALL_LINES_BEGIN
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
Definition math_dual.h:241
#define N
BMesh Iterators.
float dist_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2])
Definition math_geom.cc:316
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void MOD_lineart_smooth_chains(LineartData *ld, float tolerance)
static LineartEdge * lineart_line_get_connected(LineartBoundingArea *ba, LineartVert *vt, LineartVert **new_vt, int match_flag, uint8_t match_isec_mask, Object *match_isec_object)
LineartBoundingArea * MOD_lineart_get_parent_bounding_area(LineartData *ld, double x, double y)
MINLINE void copy_v3_v3(float r[3], const float a[3])
float angle_v2v2v2(const float a[2], const float b[2], const float c[2]) ATTR_WARN_UNUSED_RESULT
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
MINLINE void copy_v2_v2(float r[2], const float a[2])
LineartElementLinkNode * lineart_find_matching_eln_obj(ListBaseT< LineartElementLinkNode > *elns, Object *ob)
static LineartEdgeChain * lineart_chain_create(LineartData *ld)
int isect_seg_seg_v2_point(const float v0[2], const float v1[2], const float v2[2], const float v3[2], float r_vi[2])
void MOD_lineart_chain_feature_lines(LineartData *ld)
void * lineart_list_append_pointer_pool_sized(ListBase *h, struct LineartStaticMemPool *smp, void *data, int size)
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
static LineartEdgeChainItem * lineart_chain_prepend_point(LineartData *ld, LineartEdgeChain *ec, float fbcoord[4], float gpos[3], float normal[3], uint8_t type, int level, uint8_t material_mask_bits, uint32_t shadow_mask_bits, size_t index)
void MOD_lineart_chain_offset_towards_camera(LineartData *ld, float dist, bool use_custom_camera)
static bool lineart_point_overlapping(LineartEdgeChainItem *eci, float x, float y, double threshold)
void MOD_lineart_finalize_chains(LineartData *ld)
void MOD_lineart_chain_clip_at_border(LineartData *ld)
MINLINE void mul_v3_fl(float r[3], float f)
int MOD_lineart_chain_count(const LineartEdgeChain *ec)
void * BLI_pophead(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:259
void MOD_lineart_chain_clear_picked_flag(LineartCache *lc)
unsigned int uint32_t
Definition BKE_text.h:81
static bool lineart_chain_fix_ambiguous_segments(LineartEdgeChain *ec, LineartEdgeChainItem *last_matching_eci, float distance_threshold, bool preserve_details, LineartEdgeChainItem **r_next_eci)
void MOD_lineart_chain_split_for_fixed_occlusion(LineartData *ld)
static LineartBoundingArea * lineart_bounding_area_get_end_point(LineartData *ld, LineartEdgeChainItem *eci)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
float dist_to_line_v2(const float p[2], const float l1[2], const float l2[2])
Definition math_geom.cc:302
static LineartChainRegisterEntry * lineart_chain_get_closest_cre(LineartData *ld, LineartBoundingArea *ba, LineartEdgeChain *ec, LineartEdgeChainItem *eci, int occlusion, uint8_t material_mask_bits, uint8_t isec_mask, uint32_t shadow_mask, int loop_id, float dist, float *result_new_len, LineartBoundingArea *caller_ba)
void MOD_lineart_chain_split_angle(LineartData *ld, float angle_threshold_rad)
unsigned char uint8_t
Definition BKE_text.h:79
void MOD_lineart_chain_connect(LineartData *ld)
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
void void void void void void void BLI_listbase_reverse(ListBase *lb) ATTR_NONNULL(1)
Definition listbase.cc:850
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void zero_v3(float r[3])
MINLINE float dot_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v3fl_v3db(float r[3], const double a[3])
LineartBoundingArea * MOD_lineart_get_bounding_area(LineartData *ld, double x, double y)
MINLINE float normalize_v3_v3(float r[3], const float a[3])
@ MOD_LINEART_EDGE_FLAG_PROJECTED_SHADOW
@ MOD_LINEART_EDGE_FLAG_LOOSE
@ MOD_LINEART_EDGE_FLAG_CHAIN_PICKED
@ MOD_LINEART_EDGE_FLAG_INTERSECTION
@ MOD_LINEART_EDGE_FLAG_LIGHT_CONTOUR
@ MOD_LINEART_EDGE_FLAG_CONTOUR
MINLINE float normalize_v3(float n[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
void interp_v3_v3v3_db(double target[3], const double a[3], const double b[3], double t)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void * lineart_mem_acquire(struct LineartStaticMemPool *smp, size_t size)
static void lineart_bounding_area_link_chain(LineartData *ld, LineartEdgeChain *ec)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
MINLINE float ratiof(float min, float max, float pos)
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
float MOD_lineart_chain_compute_length(LineartEdgeChain *ec)
static LineartEdgeChainItem * lineart_chain_append_point(LineartData *ld, LineartEdgeChain *ec, float fbcoord[4], float gpos[3], float normal[3], uint8_t type, int level, uint8_t material_mask_bits, uint32_t shadow_mask_bits, size_t index)
static void lineart_bounding_area_link_point_recursive(LineartData *ld, LineartBoundingArea *root, LineartEdgeChain *ec, LineartEdgeChainItem *eci)
MINLINE float interpf(float target, float origin, float t)
void MOD_lineart_chain_find_silhouette_backdrop_objects(LineartData *ld)
static LineartEdgeChainItem * lineart_chain_create_crossing_point(LineartData *ld, LineartEdgeChainItem *eci_inside, LineartEdgeChainItem *eci_outside)
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE float len_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
void MOD_lineart_chain_discard_unused(LineartData *ld, const float threshold, uint8_t max_occlusion)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
static void lineart_chain_connect(LineartData *, LineartEdgeChain *onto, LineartEdgeChain *sub, int reverse_1, int reverse_2)
MINLINE float normalize_v2_v2(float r[2], const float a[2])
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
static LineartBoundingArea * lineart_bounding_area_get_eci_recursive(LineartData *ld, LineartBoundingArea *root, LineartEdgeChainItem *eci)
LineartElementLinkNode * lineart_find_matching_eln(ListBaseT< LineartElementLinkNode > *shadow_elns, int obindex)
#define swap(a, b)
Definition sort.cc:61
ListBaseT< LinkData > bp
LineartBoundingArea * child
ListBaseT< LinkData > lp
ListBaseT< LinkData > up
ListBaseT< LineartChainRegisterEntry > linked_chains
ListBaseT< LinkData > rp
ListBaseT< LineartEdgeChain > chains
ListBaseT< LineartElementLinkNode > vertex_buffer_pointers
ListBaseT< LineartElementLinkNode > line_buffer_pointers
LineartStaticMemPool * chain_data_pool
struct blender::LineartData::_geom geom
struct blender::LineartData::_conf conf
ListBaseT< LineartEdgeChain > chains
LineartEdgeChainItem * prev
LineartEdgeChainItem * next
ListBaseT< LineartEdgeChainItem > chain
LineartEdgeChain * next
LineartEdgeSegment * next
LineartEdgeSegment * prev
ListBaseT< LineartEdgeSegment > segments
LineartTriangle * t1
LineartTriangle * t2