Blender V5.3
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_array.hh"
16#include "BLI_heap.hh"
17#include "BLI_linklist.hh"
18#include "BLI_memarena.hh"
19
20/* only for defines */
21#include "BLI_polyfill_2d.hh"
23
24#include "bmesh.hh"
25
26#include "bmesh_triangulate.hh" /* own include */
27
28namespace blender {
29
34 BMFace *face,
35 const int quad_method,
36 const int ngon_method,
37 const bool use_tag,
38 BMOperator *op,
39 BMOpSlot *slot_facemap_out,
40 BMOpSlot *slot_facemap_double_out,
41
42 MemArena *pf_arena,
43 /* use for MOD_TRIANGULATE_NGON_BEAUTY only! */
44 Heap *pf_heap)
45{
46 int faces_array_tot = face->len - 3;
47 Array<BMFace *, BM_DEFAULT_NGON_STACK_SIZE> faces_array(faces_array_tot);
48 LinkNode *faces_double = nullptr;
49 BLI_assert(face->len > 3);
50
52 face,
53 faces_array.data(),
54 &faces_array_tot,
55 nullptr,
56 nullptr,
57 &faces_double,
58 quad_method,
59 ngon_method,
60 use_tag,
61 pf_arena,
62 pf_heap);
63
64 if (faces_array_tot) {
65 int i;
66 BMO_slot_map_elem_insert(op, slot_facemap_out, face, face);
67 for (i = 0; i < faces_array_tot; i++) {
68 BMO_slot_map_elem_insert(op, slot_facemap_out, faces_array[i], face);
69 }
70
71 while (faces_double) {
72 LinkNode *next = faces_double->next;
73 BMO_slot_map_elem_insert(op, slot_facemap_double_out, faces_double->link, face);
74 MEM_delete(faces_double);
75 faces_double = next;
76 }
77 }
78}
79
81 const int quad_method,
82 const int ngon_method,
83 const int min_vertices,
84 const bool tag_only,
85 BMOperator *op,
86 BMOpSlot *slot_facemap_out,
87 BMOpSlot *slot_facemap_double_out)
88{
89 BMIter iter;
90 BMFace *face;
91 MemArena *pf_arena;
92 Heap *pf_heap;
93
94 pf_arena = BLI_memarena_new(BLI_POLYFILL_ARENA_SIZE, __func__);
95
96 if (ngon_method == MOD_TRIANGULATE_NGON_BEAUTY) {
98 }
99 else {
100 pf_heap = nullptr;
101 }
102
103 if (slot_facemap_out) {
104 /* same as below but call: bm_face_triangulate_mapping() */
105 BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
106 if (face->len >= min_vertices) {
107 if (tag_only == false || BM_elem_flag_test(face, BM_ELEM_TAG)) {
109 face,
110 quad_method,
111 ngon_method,
112 tag_only,
113 op,
114 slot_facemap_out,
115 slot_facemap_double_out,
116 pf_arena,
117 pf_heap);
118 }
119 }
120 }
121 }
122 else {
123 LinkNode *faces_double = nullptr;
124
125 BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
126 if (face->len >= min_vertices) {
127 if (tag_only == false || BM_elem_flag_test(face, BM_ELEM_TAG)) {
129 face,
130 nullptr,
131 nullptr,
132 nullptr,
133 nullptr,
134 &faces_double,
135 quad_method,
136 ngon_method,
137 tag_only,
138 pf_arena,
139 pf_heap);
140 }
141 }
142 }
143
144 while (faces_double) {
145 LinkNode *next = faces_double->next;
146 BM_face_kill(bm, static_cast<BMFace *>(faces_double->link));
147 MEM_delete(faces_double);
148 faces_double = next;
149 }
150 }
151
152 BLI_memarena_free(pf_arena);
153
154 if (ngon_method == MOD_TRIANGULATE_NGON_BEAUTY) {
155 BLI_heap_free(pf_heap, nullptr);
156 }
157}
158
159} // namespace blender
A min-heap / priority queue ADT.
#define BLI_POLYFILL_ARENA_SIZE
#define BLI_POLYFILL_ALLOC_NGON_RESERVE
Read Blender memory allocation and freeing.
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
const T * data() const
Definition BLI_array.hh:323
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
Heap * BLI_heap_new_ex(unsigned int reserve_num) ATTR_WARN_UNUSED_RESULT
Definition BLI_heap.cc:173
MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
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)
BMESH TRIANGULATE FACE.
void BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp) ATTR_NONNULL(1)
Definition BLI_heap.cc:193
void BM_face_kill(BMesh *bm, BMFace *f)
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)
BLI_INLINE void BMO_slot_map_elem_insert(BMOperator *op, BMOpSlot *slot, const void *element, void *val)
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 BLI_memarena_free(MemArena *ma) ATTR_NONNULL(1)
struct LinkNode * next