Blender  V2.93
bmo_beautify.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
24 #include "BLI_math.h"
25 
26 #include "MEM_guardedalloc.h"
27 
28 #include "bmesh.h"
29 #include "bmesh_tools.h"
31 
32 #define ELE_NEW 1
33 #define FACE_MARK 2
34 
36 {
37  BMIter iter;
38  BMOIter siter;
39  BMFace *f;
40  BMEdge *e;
41  const bool use_restrict_tag = BMO_slot_bool_get(op->slots_in, "use_restrict_tag");
42  const short flag =
43  ((use_restrict_tag ? VERT_RESTRICT_TAG : 0) |
44  /* Enable to avoid iterative edge rotation to cause the direction of faces to flip. */
46  const short method = (short)BMO_slot_int_get(op->slots_in, "method");
47 
48  BMEdge **edge_array;
49  int edge_array_len = 0;
50  BMO_ITER (f, &siter, op->slots_in, "faces", BM_FACE) {
51  if (f->len == 3) {
53  }
54  }
55 
56  BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
58  }
59 
60  /* will over alloc if some edges can't be rotated */
61  edge_array = MEM_mallocN(
62  sizeof(*edge_array) * (size_t)BMO_slot_buffer_count(op->slots_in, "edges"), __func__);
63 
64  BMO_ITER (e, &siter, op->slots_in, "edges", BM_EDGE) {
65 
66  /* edge is manifold and can be rotated */
67  if (BM_edge_rotate_check(e) &&
68  /* faces are tagged */
69  BMO_face_flag_test(bm, e->l->f, FACE_MARK) &&
70  BMO_face_flag_test(bm, e->l->radial_next->f, FACE_MARK)) {
71  edge_array[edge_array_len] = e;
72  edge_array_len++;
73  }
74  }
75 
77  bm, edge_array, edge_array_len, flag, method, ELE_NEW, FACE_MARK | ELE_NEW);
78 
79  MEM_freeN(edge_array);
80 
82 }
Read Guarded memory(de)allocation.
void BM_mesh_beautify_fill(BMesh *bm, BMEdge **edge_array, const int edge_array_len, const short flag, const short method, const short oflag_edge, const short oflag_face)
@ EDGE_RESTRICT_DEGENERATE
@ VERT_RESTRICT_TAG
@ BM_FACE
Definition: bmesh_class.h:386
@ BM_EDGE
Definition: bmesh_class.h:384
@ BM_ELEM_TAG
Definition: bmesh_class.h:484
#define BM_elem_flag_disable(ele, hflag)
Definition: bmesh_inline.h:29
#define BM_ITER_MESH(ele, iter, bm, itype)
@ BM_EDGES_OF_MESH
ATTR_WARN_UNUSED_RESULT BMesh * bm
bool BM_edge_rotate_check(BMEdge *e)
Check if Rotate Edge is OK.
Definition: bmesh_mods.c:834
#define BMO_face_flag_enable(bm, e, oflag)
#define BMO_ITER(ele, iter, slot_args, slot_name, restrict_flag)
int BMO_slot_buffer_count(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
int BMO_slot_int_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
#define BMO_face_flag_test(bm, e, oflag)
void BMO_slot_buffer_from_enabled_flag(BMesh *bm, BMOperator *op, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, const char htype, const short oflag)
bool BMO_slot_bool_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
#define ELE_NEW
Definition: bmo_beautify.c:32
#define FACE_MARK
Definition: bmo_beautify.c:33
void bmo_beautify_fill_exec(BMesh *bm, BMOperator *op)
Definition: bmo_beautify.c:35
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
int len
Definition: bmesh_class.h:279
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]