Blender V4.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
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#include "BLI_utildefines.h"
20
21/* only for defines */
22#include "BLI_polyfill_2d.h"
24
25#include "bmesh.hh"
26
27#include "bmesh_triangulate.hh" /* own include */
28
33 BMFace *face,
34 const int quad_method,
35 const int ngon_method,
36 const bool use_tag,
37 BMOperator *op,
38 BMOpSlot *slot_facemap_out,
39 BMOpSlot *slot_facemap_double_out,
40
41 MemArena *pf_arena,
42 /* use for MOD_TRIANGULATE_NGON_BEAUTY only! */
43 Heap *pf_heap)
44{
45 int faces_array_tot = face->len - 3;
46 BMFace **faces_array = BLI_array_alloca(faces_array, faces_array_tot);
47 LinkNode *faces_double = nullptr;
48 BLI_assert(face->len > 3);
49
51 face,
52 faces_array,
53 &faces_array_tot,
54 nullptr,
55 nullptr,
56 &faces_double,
57 quad_method,
58 ngon_method,
59 use_tag,
60 pf_arena,
61 pf_heap);
62
63 if (faces_array_tot) {
64 int i;
65 BMO_slot_map_elem_insert(op, slot_facemap_out, face, face);
66 for (i = 0; i < faces_array_tot; i++) {
67 BMO_slot_map_elem_insert(op, slot_facemap_out, faces_array[i], face);
68 }
69
70 while (faces_double) {
71 LinkNode *next = faces_double->next;
72 BMO_slot_map_elem_insert(op, slot_facemap_double_out, faces_double->link, face);
73 MEM_freeN(faces_double);
74 faces_double = next;
75 }
76 }
77}
78
80 const int quad_method,
81 const int ngon_method,
82 const int min_vertices,
83 const bool tag_only,
84 BMOperator *op,
85 BMOpSlot *slot_facemap_out,
86 BMOpSlot *slot_facemap_double_out)
87{
88 BMIter iter;
89 BMFace *face;
90 MemArena *pf_arena;
91 Heap *pf_heap;
92
93 pf_arena = BLI_memarena_new(BLI_POLYFILL_ARENA_SIZE, __func__);
94
95 if (ngon_method == MOD_TRIANGULATE_NGON_BEAUTY) {
97 }
98 else {
99 pf_heap = nullptr;
100 }
101
102 if (slot_facemap_out) {
103 /* same as below but call: bm_face_triangulate_mapping() */
104 BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
105 if (face->len >= min_vertices) {
106 if (tag_only == false || BM_elem_flag_test(face, BM_ELEM_TAG)) {
108 face,
109 quad_method,
110 ngon_method,
111 tag_only,
112 op,
113 slot_facemap_out,
114 slot_facemap_double_out,
115 pf_arena,
116 pf_heap);
117 }
118 }
119 }
120 }
121 else {
122 LinkNode *faces_double = nullptr;
123
124 BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
125 if (face->len >= min_vertices) {
126 if (tag_only == false || BM_elem_flag_test(face, BM_ELEM_TAG)) {
128 face,
129 nullptr,
130 nullptr,
131 nullptr,
132 nullptr,
133 &faces_double,
134 quad_method,
135 ngon_method,
136 tag_only,
137 pf_arena,
138 pf_heap);
139 }
140 }
141 }
142
143 while (faces_double) {
144 LinkNode *next = faces_double->next;
145 BM_face_kill(bm, static_cast<BMFace *>(faces_double->link));
146 MEM_freeN(faces_double);
147 faces_double = next;
148 }
149 }
150
151 BLI_memarena_free(pf_arena);
152
153 if (ngon_method == MOD_TRIANGULATE_NGON_BEAUTY) {
154 BLI_heap_free(pf_heap, nullptr);
155 }
156}
#define BLI_array_alloca(arr, realsize)
Definition BLI_alloca.h:25
#define BLI_assert(a)
Definition BLI_assert.h:50
A min-heap / priority queue ADT.
void BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp) ATTR_NONNULL(1)
Definition BLI_heap.c:192
Heap * BLI_heap_new_ex(unsigned int reserve_num) ATTR_WARN_UNUSED_RESULT
Definition BLI_heap.c:172
void BLI_memarena_free(struct MemArena *ma) ATTR_NONNULL(1)
struct MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
#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
ATTR_WARN_UNUSED_RESULT 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:105
static ulong * next
void * link
struct LinkNode * next