Merged changes in the trunk up to revision 54110.
[blender.git] / source / blender / bmesh / operators / bmo_similar.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Joseph Eagar, Campbell Barton
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/bmesh/operators/bmo_similar.c
24  *  \ingroup bmesh
25  *
26  * bmesh operators to select based on
27  * comparisons with the existing selection.
28  */
29
30 #include "MEM_guardedalloc.h"
31
32 #include "DNA_object_types.h"
33 #include "DNA_meshdata_types.h"
34
35 #include "BLI_math.h"
36
37 #include "BKE_customdata.h"
38 #include "BKE_deform.h"
39
40 #include "bmesh.h"
41
42 #include "intern/bmesh_operators_private.h"  /* own include */
43
44 /* in fact these could all be the same */
45
46 /*
47  * extra face data (computed data)
48  */
49 typedef struct SimSel_FaceExt {
50         BMFace  *f;             /* the face */
51         float    c[3];          /* center */
52         union {
53                 float   area;       /* area */
54                 float   perim;      /* perimeter */
55                 float   d;          /* 4th component of plane (the first three being the normal) */
56                 struct Image *t;    /* image pointer */
57         };
58 } SimSel_FaceExt;
59
60 static int bm_sel_similar_cmp_fl(const float delta, const float thresh, const int compare)
61 {
62         switch (compare) {
63                 case SIM_CMP_EQ:
64                         return (fabsf(delta) <= thresh);
65                 case SIM_CMP_GT:
66                         return ((delta + thresh) >= 0.0f);
67                 case SIM_CMP_LT:
68                         return ((delta - thresh) <= 0.0f);
69                 default:
70                         BLI_assert(0);
71                         return 0;
72         }
73 }
74
75 static int bm_sel_similar_cmp_i(const int delta, const int compare)
76 {
77         switch (compare) {
78                 case SIM_CMP_EQ:
79                         return (delta == 0);
80                 case SIM_CMP_GT:
81                         return (delta > 0);
82                 case SIM_CMP_LT:
83                         return (delta < 0);
84                 default:
85                         BLI_assert(0);
86                         return 0;
87         }
88 }
89
90 /*
91  * Select similar faces, the choices are in the enum in source/blender/bmesh/bmesh_operators.h
92  * We select either similar faces based on material, image, area, perimeter, normal, or the coplanar faces
93  */
94 void bmo_similar_faces_exec(BMesh *bm, BMOperator *op)
95 {
96 #define FACE_MARK       1
97
98         BMIter fm_iter;
99         BMFace *fs, *fm;
100         BMOIter fs_iter;
101         int num_sels = 0, num_total = 0, i = 0, idx = 0;
102         float angle = 0.0f;
103         SimSel_FaceExt *f_ext = NULL;
104         int *indices = NULL;
105         float t_no[3];  /* temporary normal */
106         const int type = BMO_slot_int_get(op->slots_in, "type");
107         const float thresh = BMO_slot_float_get(op->slots_in, "thresh");
108         const float thresh_radians = thresh * (float)M_PI;
109         const int compare = BMO_slot_int_get(op->slots_in, "compare");
110
111         /* initial_elem - other_elem */
112         float delta_fl;
113         int   delta_i;
114
115         num_total = BM_mesh_elem_count(bm, BM_FACE);
116
117         /*
118          * The first thing to do is to iterate through all the the selected items and mark them since
119          * they will be in the selection anyway.
120          * This will increase performance, (especially when the number of originally selected faces is high)
121          * so the overall complexity will be less than $O(mn)$ where is the total number of selected faces,
122          * and n is the total number of faces
123          */
124         BMO_ITER (fs, &fs_iter, op->slots_in, "faces", BM_FACE) {
125                 if (!BMO_elem_flag_test(bm, fs, FACE_MARK)) {   /* is this really needed ? */
126                         BMO_elem_flag_enable(bm, fs, FACE_MARK);
127                         num_sels++;
128                 }
129         }
130
131         /* allocate memory for the selected faces indices and for all temporary faces */
132         indices = (int *)MEM_callocN(sizeof(int) * num_sels, "face indices util.c");
133         f_ext = (SimSel_FaceExt *)MEM_callocN(sizeof(SimSel_FaceExt) * num_total, "f_ext util.c");
134
135         /* loop through all the faces and fill the faces/indices structure */
136         BM_ITER_MESH (fm, &fm_iter, bm, BM_FACES_OF_MESH) {
137                 f_ext[i].f = fm;
138                 if (BMO_elem_flag_test(bm, fm, FACE_MARK)) {
139                         indices[idx] = i;
140                         idx++;
141                 }
142                 i++;
143         }
144
145         /*
146          * Save us some computation burden: In case of perimeter/area/coplanar selection we compute
147          * only once.
148          */
149         if (type == SIMFACE_PERIMETER || type == SIMFACE_AREA || type == SIMFACE_COPLANAR || type == SIMFACE_IMAGE) {
150                 for (i = 0; i < num_total; i++) {
151                         switch (type) {
152                                 case SIMFACE_PERIMETER:
153                                         /* set the perimeter */
154                                         f_ext[i].perim = BM_face_calc_perimeter(f_ext[i].f);
155                                         break;
156
157                                 case SIMFACE_COPLANAR:
158                                         /* compute the center of the polygon */
159                                         BM_face_calc_center_mean(f_ext[i].f, f_ext[i].c);
160
161                                         /* normalize the polygon normal */
162                                         copy_v3_v3(t_no, f_ext[i].f->no);
163                                         normalize_v3(t_no);
164
165                                         /* compute the plane distance */
166                                         f_ext[i].d = dot_v3v3(t_no, f_ext[i].c);
167                                         break;
168
169                                 case SIMFACE_AREA:
170                                         f_ext[i].area = BM_face_calc_area(f_ext[i].f);
171                                         break;
172
173                                 case SIMFACE_IMAGE:
174                                         f_ext[i].t = NULL;
175                                         if (CustomData_has_layer(&(bm->pdata), CD_MTEXPOLY)) {
176                                                 MTexPoly *mtpoly = CustomData_bmesh_get(&bm->pdata, f_ext[i].f->head.data, CD_MTEXPOLY);
177                                                 f_ext[i].t = mtpoly->tpage;
178                                         }
179                                         break;
180                         }
181                 }
182         }
183
184         /* now select the rest (if any) */
185         for (i = 0; i < num_total; i++) {
186                 fm = f_ext[i].f;
187                 if (!BMO_elem_flag_test(bm, fm, FACE_MARK) && !BM_elem_flag_test(fm, BM_ELEM_HIDDEN)) {
188                         bool cont = true;
189                         for (idx = 0; idx < num_sels && cont == true; idx++) {
190                                 fs = f_ext[indices[idx]].f;
191                                 switch (type) {
192                                         case SIMFACE_MATERIAL:
193                                                 if (fm->mat_nr == fs->mat_nr) {
194                                                         BMO_elem_flag_enable(bm, fm, FACE_MARK);
195                                                         cont = false;
196                                                 }
197                                                 break;
198
199                                         case SIMFACE_IMAGE:
200                                                 if (f_ext[i].t == f_ext[indices[idx]].t) {
201                                                         BMO_elem_flag_enable(bm, fm, FACE_MARK);
202                                                         cont = false;
203                                                 }
204                                                 break;
205
206                                         case SIMFACE_NORMAL:
207                                                 angle = angle_normalized_v3v3(fs->no, fm->no);  /* if the angle between the normals -> 0 */
208                                                 if (angle <= thresh_radians) {
209                                                         BMO_elem_flag_enable(bm, fm, FACE_MARK);
210                                                         cont = false;
211                                                 }
212                                                 break;
213
214                                         case SIMFACE_COPLANAR:
215                                                 angle = angle_normalized_v3v3(fs->no, fm->no); /* angle -> 0 */
216                                                 if (angle <= thresh_radians) { /* and dot product difference -> 0 */
217                                                         delta_fl = f_ext[i].d - f_ext[indices[idx]].d;
218                                                         if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
219                                                                 BMO_elem_flag_enable(bm, fm, FACE_MARK);
220                                                                 cont = false;
221                                                         }
222                                                 }
223                                                 break;
224
225                                         case SIMFACE_AREA:
226                                                 delta_fl = f_ext[i].area - f_ext[indices[idx]].area;
227                                                 if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
228                                                         BMO_elem_flag_enable(bm, fm, FACE_MARK);
229                                                         cont = false;
230                                                 }
231                                                 break;
232
233                                         case SIMFACE_SIDES:
234                                                 delta_i = fm->len - fs->len;
235                                                 if (bm_sel_similar_cmp_i(delta_i, compare)) {
236                                                         BMO_elem_flag_enable(bm, fm, FACE_MARK);
237                                                         cont = false;
238                                                 }
239                                                 break;
240
241                                         case SIMFACE_PERIMETER:
242                                                 delta_fl = f_ext[i].perim - f_ext[indices[idx]].perim;
243                                                 if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
244                                                         BMO_elem_flag_enable(bm, fm, FACE_MARK);
245                                                         cont = false;
246                                                 }
247                                                 break;
248 #ifdef WITH_FREESTYLE
249                                         case SIMFACE_FREESTYLE:
250                                                 if (BM_elem_flag_test(fm, BM_ELEM_FREESTYLE) == BM_elem_flag_test(fs, BM_ELEM_FREESTYLE)) {
251                                                         BMO_elem_flag_enable(bm, fm, FACE_MARK);
252                                                         cont = FALSE;
253                                                 }
254                                                 break;
255 #endif
256                                         default:
257                                                 BLI_assert(0);
258                                 }
259                         }
260                 }
261         }
262
263         MEM_freeN(f_ext);
264         MEM_freeN(indices);
265
266         /* transfer all marked faces to the output slot */
267         BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "faces.out", BM_FACE, FACE_MARK);
268 #undef FACE_MARK
269 }
270
271 /**************************************************************************** *
272  * Similar Edges
273  **************************************************************************** */
274
275 /*
276  * extra edge information
277  */
278 typedef struct SimSel_EdgeExt {
279         BMEdge *e;
280         union {
281                 float dir[3];
282                 float angle;            /* angle between the face */
283         };
284
285         union {
286                 float length;           /* edge length */
287                 int   faces;            /* faces count */
288         };
289 } SimSel_EdgeExt;
290
291 /*
292  * select similar edges: the choices are in the enum in source/blender/bmesh/bmesh_operators.h
293  * choices are length, direction, face, ...
294  */
295 void bmo_similar_edges_exec(BMesh *bm, BMOperator *op)
296 {
297 #define EDGE_MARK       1
298
299         BMOIter es_iter;        /* selected edges iterator */
300         BMIter e_iter;          /* mesh edges iterator */
301         BMEdge *es;             /* selected edge */
302         BMEdge *e;              /* mesh edge */
303         int idx = 0, i = 0 /* , f = 0 */;
304         int *indices = NULL;
305         SimSel_EdgeExt *e_ext = NULL;
306         // float *angles = NULL;
307         float angle;
308
309         int num_sels = 0, num_total = 0;
310         const int type = BMO_slot_int_get(op->slots_in, "type");
311         const float thresh = BMO_slot_float_get(op->slots_in, "thresh");
312         const int compare = BMO_slot_int_get(op->slots_in, "compare");
313
314         /* initial_elem - other_elem */
315         float delta_fl;
316         int   delta_i;
317
318         /* sanity checks that the data we need is available */
319         switch (type) {
320                 case SIMEDGE_CREASE:
321                         if (!CustomData_has_layer(&bm->edata, CD_CREASE)) {
322                                 return;
323                         }
324                         break;
325                 case SIMEDGE_BEVEL:
326                         if (!CustomData_has_layer(&bm->edata, CD_BWEIGHT)) {
327                                 return;
328                         }
329                         break;
330         }
331
332         num_total = BM_mesh_elem_count(bm, BM_EDGE);
333
334         /* iterate through all selected edges and mark them */
335         BMO_ITER (es, &es_iter, op->slots_in, "edges", BM_EDGE) {
336                 BMO_elem_flag_enable(bm, es, EDGE_MARK);
337                 num_sels++;
338         }
339
340         /* allocate memory for the selected edges indices and for all temporary edges */
341         indices = (int *)MEM_callocN(sizeof(int) * num_sels, __func__);
342         e_ext = (SimSel_EdgeExt *)MEM_callocN(sizeof(SimSel_EdgeExt) * num_total, __func__);
343
344         /* loop through all the edges and fill the edges/indices structure */
345         BM_ITER_MESH (e, &e_iter, bm, BM_EDGES_OF_MESH) {
346                 e_ext[i].e = e;
347                 if (BMO_elem_flag_test(bm, e, EDGE_MARK)) {
348                         indices[idx] = i;
349                         idx++;
350                 }
351                 i++;
352         }
353
354         /* save us some computation time by doing heavy computation once */
355         if (type == SIMEDGE_LENGTH || type == SIMEDGE_FACE || type == SIMEDGE_DIR || type == SIMEDGE_FACE_ANGLE) {
356                 for (i = 0; i < num_total; i++) {
357                         switch (type) {
358                                 case SIMEDGE_LENGTH:    /* compute the length of the edge */
359                                         e_ext[i].length = len_v3v3(e_ext[i].e->v1->co, e_ext[i].e->v2->co);
360                                         break;
361
362                                 case SIMEDGE_DIR:               /* compute the direction */
363                                         sub_v3_v3v3(e_ext[i].dir, e_ext[i].e->v1->co, e_ext[i].e->v2->co);
364                                         normalize_v3(e_ext[i].dir);
365                                         break;
366
367                                 case SIMEDGE_FACE:              /* count the faces around the edge */
368                                         e_ext[i].faces = BM_edge_face_count(e_ext[i].e);
369                                         break;
370
371                                 case SIMEDGE_FACE_ANGLE:
372                                         e_ext[i].faces = BM_edge_face_count(e_ext[i].e);
373                                         if (e_ext[i].faces == 2)
374                                                 e_ext[i].angle = BM_edge_calc_face_angle(e_ext[i].e);
375                                         break;
376                         }
377                 }
378         }
379
380         /* select the edges if any */
381         for (i = 0; i < num_total; i++) {
382                 e = e_ext[i].e;
383                 if (!BMO_elem_flag_test(bm, e, EDGE_MARK) && !BM_elem_flag_test(e, BM_ELEM_HIDDEN)) {
384                         bool cont = true;
385                         for (idx = 0; idx < num_sels && cont == true; idx++) {
386                                 es = e_ext[indices[idx]].e;
387                                 switch (type) {
388                                         case SIMEDGE_LENGTH:
389                                                 delta_fl = e_ext[i].length - e_ext[indices[idx]].length;
390                                                 if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
391                                                         BMO_elem_flag_enable(bm, e, EDGE_MARK);
392                                                         cont = false;
393                                                 }
394                                                 break;
395
396                                         case SIMEDGE_DIR:
397                                                 /* compute the angle between the two edges */
398                                                 angle = angle_normalized_v3v3(e_ext[i].dir, e_ext[indices[idx]].dir);
399
400                                                 if (angle > (float)(M_PI / 2.0)) /* use the smallest angle between the edges */
401                                                         angle = fabsf(angle - (float)M_PI);
402
403                                                 if (angle / (float)(M_PI / 2.0) <= thresh) {
404                                                         BMO_elem_flag_enable(bm, e, EDGE_MARK);
405                                                         cont = false;
406                                                 }
407                                                 break;
408
409                                         case SIMEDGE_FACE:
410                                                 delta_i = e_ext[i].faces - e_ext[indices[idx]].faces;
411                                                 if (bm_sel_similar_cmp_i(delta_i, compare)) {
412                                                         BMO_elem_flag_enable(bm, e, EDGE_MARK);
413                                                         cont = false;
414                                                 }
415                                                 break;
416
417                                         case SIMEDGE_FACE_ANGLE:
418                                                 if (e_ext[i].faces == 2) {
419                                                         if (e_ext[indices[idx]].faces == 2) {
420                                                                 if (fabsf(e_ext[i].angle - e_ext[indices[idx]].angle) <= thresh) {
421                                                                         BMO_elem_flag_enable(bm, e, EDGE_MARK);
422                                                                         cont = false;
423                                                                 }
424                                                         }
425                                                 }
426                                                 else {
427                                                         cont = false;
428                                                 }
429                                                 break;
430
431                                         case SIMEDGE_CREASE:
432                                                 {
433                                                         float *c1, *c2;
434
435                                                         c1 = CustomData_bmesh_get(&bm->edata, e->head.data, CD_CREASE);
436                                                         c2 = CustomData_bmesh_get(&bm->edata, es->head.data, CD_CREASE);
437                                                         delta_fl = *c1 - *c2;
438
439                                                         if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
440                                                                 BMO_elem_flag_enable(bm, e, EDGE_MARK);
441                                                                 cont = false;
442                                                         }
443                                                 }
444                                                 break;
445
446                                         case SIMEDGE_BEVEL:
447                                                 {
448                                                         float *c1, *c2;
449
450                                                         c1 = CustomData_bmesh_get(&bm->edata, e->head.data, CD_BWEIGHT);
451                                                         c2 = CustomData_bmesh_get(&bm->edata, es->head.data, CD_BWEIGHT);
452                                                         delta_fl = *c1 - *c2;
453
454                                                         if (bm_sel_similar_cmp_fl(delta_fl, thresh, compare)) {
455                                                                 BMO_elem_flag_enable(bm, e, EDGE_MARK);
456                                                                 cont = false;
457                                                         }
458                                                 }
459                                                 break;
460
461                                         case SIMEDGE_SEAM:
462                                                 if (BM_elem_flag_test(e, BM_ELEM_SEAM) == BM_elem_flag_test(es, BM_ELEM_SEAM)) {
463                                                         BMO_elem_flag_enable(bm, e, EDGE_MARK);
464                                                         cont = false;
465                                                 }
466                                                 break;
467
468                                         case SIMEDGE_SHARP:
469                                                 if (BM_elem_flag_test(e, BM_ELEM_SMOOTH) == BM_elem_flag_test(es, BM_ELEM_SMOOTH)) {
470                                                         BMO_elem_flag_enable(bm, e, EDGE_MARK);
471                                                         cont = false;
472                                                 }
473                                                 break;
474 #ifdef WITH_FREESTYLE
475                                         case SIMEDGE_FREESTYLE:
476                                                 if (BM_elem_flag_test(e, BM_ELEM_FREESTYLE) == BM_elem_flag_test(es, BM_ELEM_FREESTYLE)) {
477                                                         BMO_elem_flag_enable(bm, e, EDGE_MARK);
478                                                         cont = FALSE;
479                                                 }
480                                                 break;
481 #endif
482                                         default:
483                                                 BLI_assert(0);
484                                 }
485                         }
486                 }
487         }
488
489         MEM_freeN(e_ext);
490         MEM_freeN(indices);
491
492         /* transfer all marked edges to the output slot */
493         BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "edges.out", BM_EDGE, EDGE_MARK);
494
495 #undef EDGE_MARK
496 }
497
498 /**************************************************************************** *
499  * Similar Vertices
500  **************************************************************************** */
501
502 typedef struct SimSel_VertExt {
503         BMVert *v;
504         union {
505                 int num_faces; /* adjacent faces */
506                 int num_edges; /* adjacent edges */
507                 MDeformVert *dvert; /* deform vertex */
508         };
509 } SimSel_VertExt;
510
511 /*
512  * select similar vertices: the choices are in the enum in source/blender/bmesh/bmesh_operators.h
513  * choices are normal, face, vertex group...
514  */
515 void bmo_similar_verts_exec(BMesh *bm, BMOperator *op)
516 {
517 #define VERT_MARK       1
518
519         BMOIter vs_iter;        /* selected verts iterator */
520         BMIter v_iter;          /* mesh verts iterator */
521         BMVert *vs;             /* selected vertex */
522         BMVert *v;                      /* mesh vertex */
523         SimSel_VertExt *v_ext = NULL;
524         int *indices = NULL;
525         int num_total = 0, num_sels = 0, i = 0, idx = 0;
526         const int type = BMO_slot_int_get(op->slots_in, "type");
527         const float thresh = BMO_slot_float_get(op->slots_in, "thresh");
528         const float thresh_radians = thresh * (float)M_PI;
529         const int compare = BMO_slot_int_get(op->slots_in, "compare");
530
531         /* initial_elem - other_elem */
532 //      float delta_fl;
533         int   delta_i;
534
535         num_total = BM_mesh_elem_count(bm, BM_VERT);
536
537         /* iterate through all selected edges and mark them */
538         BMO_ITER (vs, &vs_iter, op->slots_in, "verts", BM_VERT) {
539                 BMO_elem_flag_enable(bm, vs, VERT_MARK);
540                 num_sels++;
541         }
542
543         /* allocate memory for the selected vertices indices and for all temporary vertices */
544         indices = (int *)MEM_mallocN(sizeof(int) * num_sels, "vertex indices");
545         v_ext = (SimSel_VertExt *)MEM_mallocN(sizeof(SimSel_VertExt) * num_total, "vertex extra");
546
547         /* loop through all the vertices and fill the vertices/indices structure */
548         BM_ITER_MESH (v, &v_iter, bm, BM_VERTS_OF_MESH) {
549                 v_ext[i].v = v;
550                 if (BMO_elem_flag_test(bm, v, VERT_MARK)) {
551                         indices[idx] = i;
552                         idx++;
553                 }
554
555                 switch (type) {
556                         case SIMVERT_FACE:
557                                 /* calling BM_vert_face_count every time is time consumming, so call it only once per vertex */
558                                 v_ext[i].num_faces = BM_vert_face_count(v);
559                                 break;
560
561                         case SIMVERT_VGROUP:
562                                 if (CustomData_has_layer(&(bm->vdata), CD_MDEFORMVERT)) {
563                                         v_ext[i].dvert = CustomData_bmesh_get(&bm->vdata, v_ext[i].v->head.data, CD_MDEFORMVERT);
564                                 }
565                                 else {
566                                         v_ext[i].dvert = NULL;
567                                 }
568                                 break;
569                         case SIMVERT_EDGE:
570                                 v_ext[i].num_edges = BM_vert_edge_count(v);
571                                 break;
572                 }
573
574                 i++;
575         }
576
577         /* select the vertices if any */
578         for (i = 0; i < num_total; i++) {
579                 v = v_ext[i].v;
580                 if (!BMO_elem_flag_test(bm, v, VERT_MARK) && !BM_elem_flag_test(v, BM_ELEM_HIDDEN)) {
581                         bool cont = true;
582                         for (idx = 0; idx < num_sels && cont == true; idx++) {
583                                 vs = v_ext[indices[idx]].v;
584                                 switch (type) {
585                                         case SIMVERT_NORMAL:
586                                                 /* compare the angle between the normals */
587                                                 if (angle_normalized_v3v3(v->no, vs->no) <= thresh_radians) {
588                                                         BMO_elem_flag_enable(bm, v, VERT_MARK);
589                                                         cont = false;
590                                                 }
591                                                 break;
592                                         case SIMVERT_FACE:
593                                                 /* number of adjacent faces */
594                                                 delta_i = v_ext[i].num_faces - v_ext[indices[idx]].num_faces;
595                                                 if (bm_sel_similar_cmp_i(delta_i, compare)) {
596                                                         BMO_elem_flag_enable(bm, v, VERT_MARK);
597                                                         cont = false;
598                                                 }
599                                                 break;
600
601                                         case SIMVERT_VGROUP:
602                                                 if (v_ext[i].dvert != NULL && v_ext[indices[idx]].dvert != NULL) {
603                                                         if (defvert_find_shared(v_ext[i].dvert, v_ext[indices[idx]].dvert) != -1) {
604                                                                 BMO_elem_flag_enable(bm, v, VERT_MARK);
605                                                                 cont = false;
606                                                         }
607                                                 }
608                                                 break;
609                                         case SIMVERT_EDGE:
610                                                 /* number of adjacent edges */
611                                                 delta_i = v_ext[i].num_edges - v_ext[indices[idx]].num_edges;
612                                                 if (bm_sel_similar_cmp_i(delta_i, compare)) {
613                                                         BMO_elem_flag_enable(bm, v, VERT_MARK);
614                                                         cont = false;
615                                                 }
616                                                 break;
617                                         default:
618                                                 BLI_assert(0);
619                                 }
620                         }
621                 }
622         }
623
624         MEM_freeN(indices);
625         MEM_freeN(v_ext);
626
627         BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "verts.out", BM_VERT, VERT_MARK);
628
629 #undef VERT_MARK
630 }