Blender  V3.3
bmesh_edgesplit.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
9 #include "MEM_guardedalloc.h"
10 
11 #include "BLI_utildefines.h"
12 
13 #include "bmesh.h"
14 
15 #include "bmesh_edgesplit.h" /* own include */
16 
18  const bool use_verts,
19  const bool tag_only,
20  const bool copy_select)
21 {
22  BMIter iter;
23  BMEdge *e;
24 
25  bool use_ese = false;
26  GHash *ese_gh = NULL;
27 
28  if (copy_select && bm->selected.first) {
29  BMEditSelection *ese;
30 
31  ese_gh = BLI_ghash_ptr_new(__func__);
32  for (ese = bm->selected.first; ese; ese = ese->next) {
33  if (ese->htype != BM_FACE) {
34  BLI_ghash_insert(ese_gh, ese->ele, ese);
35  }
36  }
37 
38  use_ese = true;
39  }
40 
41  if (tag_only == false) {
42  BM_mesh_elem_hflag_enable_all(bm, BM_EDGE | (use_verts ? BM_VERT : 0), BM_ELEM_TAG, false);
43  }
44 
45  if (use_verts) {
46  /* prevent one edge having both verts unflagged
47  * we could alternately disable these edges, either way its a corner case.
48  *
49  * This is needed so we don't split off the edge but then none of its verts which
50  * would leave a duplicate edge.
51  */
52  BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
54  if (UNLIKELY(((BM_elem_flag_test(e->v1, BM_ELEM_TAG) == false) &&
55  (BM_elem_flag_test(e->v2, BM_ELEM_TAG) == false)))) {
58  }
59  }
60  }
61  }
62  else {
63  BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
67  }
68  }
69  }
70 
71  BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
73  uint i;
74  for (i = 0; i < 2; i++) {
75  BMVert *v = ((&e->v1)[i]);
78 
79  if (use_ese) {
80  BMVert **vtar;
81  int vtar_len;
82 
83  BM_vert_separate_hflag(bm, v, BM_ELEM_TAG, copy_select, &vtar, &vtar_len);
84 
85  /* first value is always in 'v' */
86  if (vtar_len > 1) {
87  BMEditSelection *ese = BLI_ghash_lookup(ese_gh, v);
88  BLI_assert(v == vtar[0]);
89  if (UNLIKELY(ese)) {
90  int j;
91  for (j = 1; j < vtar_len; j++) {
92  BLI_assert(v != vtar[j]);
94  }
95  }
96  }
97  MEM_freeN(vtar);
98  }
99  else {
100  BM_vert_separate_hflag(bm, v, BM_ELEM_TAG, copy_select, NULL, NULL);
101  }
102  }
103  }
104  }
105  }
106 
107 #ifndef NDEBUG
108  /* ensure we don't have any double edges! */
109  BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
112  }
113  }
114 #endif
115 
116  if (use_ese) {
117  BLI_ghash_free(ese_gh, NULL, NULL);
118  }
119 }
#define BLI_assert(a)
Definition: BLI_assert.h:46
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:734
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition: BLI_ghash.c:710
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:863
GHash * BLI_ghash_ptr_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
unsigned int uint
Definition: BLI_sys_types.h:67
#define UNLIKELY(x)
Read Guarded memory(de)allocation.
@ BM_FACE
Definition: bmesh_class.h:386
@ BM_VERT
Definition: bmesh_class.h:383
@ BM_EDGE
Definition: bmesh_class.h:384
@ BM_ELEM_TAG
Definition: bmesh_class.h:484
void BM_vert_separate_hflag(BMesh *bm, BMVert *v, const char hflag, const bool copy_select, BMVert ***r_vout, int *r_vout_len)
Definition: bmesh_core.c:2267
void BM_mesh_edgesplit(BMesh *bm, const bool use_verts, const bool tag_only, const bool copy_select)
#define BM_elem_flag_disable(ele, hflag)
Definition: bmesh_inline.h:15
#define BM_elem_flag_test(ele, hflag)
Definition: bmesh_inline.h:12
#define BM_elem_flag_enable(ele, hflag)
Definition: bmesh_inline.h:14
#define BM_ITER_MESH(ele, iter, bm, itype)
@ BM_EDGES_OF_MESH
ATTR_WARN_UNUSED_RESULT BMesh * bm
void BM_mesh_elem_hflag_enable_all(BMesh *bm, const char htype, const char hflag, const bool respecthide)
#define BM_select_history_store_after_notest(bm, ese_ref, ele)
BMEdge * BM_edge_find_double(BMEdge *e)
Definition: bmesh_query.c:1581
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
struct BMEditSelection * next
Definition: bmesh_marking.h:10
ListBase selected
Definition: bmesh_class.h:356
void * first
Definition: DNA_listBase.h:31