Blender V5.0
bmesh_triangulate.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "DNA_modifier_types.h" /* for MOD_TRIANGULATE_NGON_BEAUTY only */
12
13#include "MEM_guardedalloc.h"
14
15#include "BLI_alloca.h"
16#include "BLI_heap.h"
17#include "BLI_linklist.h"
18#include "BLI_memarena.h"
19
20/* only for defines */
21#include "BLI_polyfill_2d.h"
23
24#include "bmesh.hh"
25
26#include "bmesh_triangulate.hh" /* own include */
27
32 BMFace *face,
33 const int quad_method,
34 const int ngon_method,
35 const bool use_tag,
36 BMOperator *op,
37 BMOpSlot *slot_facemap_out,
38 BMOpSlot *slot_facemap_double_out,
39
40 MemArena *pf_arena,
41 /* use for MOD_TRIANGULATE_NGON_BEAUTY only! */
42 Heap *pf_heap)
43{
44 int faces_array_tot = face->len - 3;
45 BMFace **faces_array = BLI_array_alloca(faces_array, faces_array_tot);
46 LinkNode *faces_double = nullptr;
47 BLI_assert(face->len > 3);
48
50 face,
51 faces_array,
52 &faces_array_tot,
53 nullptr,
54 nullptr,
55 &faces_double,
56 quad_method,
57 ngon_method,
58 use_tag,
59 pf_arena,
60 pf_heap);
61
62 if (faces_array_tot) {
63 int i;
64 BMO_slot_map_elem_insert(op, slot_facemap_out, face, face);
65 for (i = 0; i < faces_array_tot; i++) {
66 BMO_slot_map_elem_insert(op, slot_facemap_out, faces_array[i], face);
67 }
68
69 while (faces_double) {
70 LinkNode *next = faces_double->next;
71 BMO_slot_map_elem_insert(op, slot_facemap_double_out, faces_double->link, face);
72 MEM_freeN(faces_double);
73 faces_double = next;
74 }
75 }
76}
77
79 const int quad_method,
80 const int ngon_method,
81 const int min_vertices,
82 const bool tag_only,
83 BMOperator *op,
84 BMOpSlot *slot_facemap_out,
85 BMOpSlot *slot_facemap_double_out)
86{
87 BMIter iter;
88 BMFace *face;
89 MemArena *pf_arena;
90 Heap *pf_heap;
91
92 pf_arena = BLI_memarena_new(BLI_POLYFILL_ARENA_SIZE, __func__);
93
94 if (ngon_method == MOD_TRIANGULATE_NGON_BEAUTY) {
96 }
97 else {
98 pf_heap = nullptr;
99 }
100
101 if (slot_facemap_out) {
102 /* same as below but call: bm_face_triangulate_mapping() */
103 BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
104 if (face->len >= min_vertices) {
105 if (tag_only == false || BM_elem_flag_test(face, BM_ELEM_TAG)) {
107 face,
108 quad_method,
109 ngon_method,
110 tag_only,
111 op,
112 slot_facemap_out,
113 slot_facemap_double_out,
114 pf_arena,
115 pf_heap);
116 }
117 }
118 }
119 }
120 else {
121 LinkNode *faces_double = nullptr;
122
123 BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
124 if (face->len >= min_vertices) {
125 if (tag_only == false || BM_elem_flag_test(face, BM_ELEM_TAG)) {
127 face,
128 nullptr,
129 nullptr,
130 nullptr,
131 nullptr,
132 &faces_double,
133 quad_method,
134 ngon_method,
135 tag_only,
136 pf_arena,
137 pf_heap);
138 }
139 }
140 }
141
142 while (faces_double) {
143 LinkNode *next = faces_double->next;
144 BM_face_kill(bm, static_cast<BMFace *>(faces_double->link));
145 MEM_freeN(faces_double);
146 faces_double = next;
147 }
148 }
149
150 BLI_memarena_free(pf_arena);
151
152 if (ngon_method == MOD_TRIANGULATE_NGON_BEAUTY) {
153 BLI_heap_free(pf_heap, nullptr);
154 }
155}
#define BLI_array_alloca(arr, realsize)
Definition BLI_alloca.h:18
#define BLI_assert(a)
Definition BLI_assert.h:46
A min-heap / priority queue ADT.
void BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp) ATTR_NONNULL(1)
Definition BLI_heap.cc:191
Heap * BLI_heap_new_ex(unsigned int reserve_num) ATTR_WARN_UNUSED_RESULT
Definition BLI_heap.cc:171
MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
void BLI_memarena_free(MemArena *ma) ATTR_NONNULL(1)
#define BLI_POLYFILL_ARENA_SIZE
#define BLI_POLYFILL_ALLOC_NGON_RESERVE
@ MOD_TRIANGULATE_NGON_BEAUTY
Read Guarded memory(de)allocation.
@ BM_ELEM_TAG
void BM_face_kill(BMesh *bm, BMFace *f)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
@ BM_FACES_OF_MESH
BMesh * bm
BLI_INLINE void BMO_slot_map_elem_insert(BMOperator *op, BMOpSlot *slot, const void *element, void *val)
void BM_face_triangulate(BMesh *bm, BMFace *f, BMFace **r_faces_new, int *r_faces_new_tot, BMEdge **r_edges_new, int *r_edges_new_tot, LinkNode **r_faces_double, const int quad_method, const int ngon_method, const bool use_tag, MemArena *pf_arena, Heap *pf_heap)
void BM_mesh_triangulate(BMesh *bm, const int quad_method, const int ngon_method, const int min_vertices, const bool tag_only, BMOperator *op, BMOpSlot *slot_facemap_out, BMOpSlot *slot_facemap_double_out)
static void bm_face_triangulate_mapping(BMesh *bm, BMFace *face, const int quad_method, const int ngon_method, const bool use_tag, BMOperator *op, BMOpSlot *slot_facemap_out, BMOpSlot *slot_facemap_double_out, MemArena *pf_arena, Heap *pf_heap)
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
static ulong * next
void * link
struct LinkNode * next
i
Definition text_draw.cc:230