BMesh: select similar regions

Select operator that takes multiple selected face regions and
selects any number of matching regions (when they have distinguishing features to isolate them).

UI access next.
This commit is contained in:
Campbell Barton 2014-09-15 15:40:50 +10:00
parent a5159b5fba
commit 2f4e70702c
7 changed files with 1631 additions and 0 deletions

View File

@ -140,6 +140,8 @@ set(SRC
tools/bmesh_intersect.h
tools/bmesh_path.c
tools/bmesh_path.h
tools/bmesh_region_match.c
tools/bmesh_region_match.h
tools/bmesh_triangulate.c
tools/bmesh_triangulate.h
tools/bmesh_wireframe.c

View File

@ -41,6 +41,7 @@ extern "C" {
#include "tools/bmesh_edgenet.h"
#include "tools/bmesh_edgesplit.h"
#include "tools/bmesh_path.h"
#include "tools/bmesh_region_match.h"
#include "tools/bmesh_triangulate.h"
#ifdef __cplusplus

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,33 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifndef __BMESH_REGION_MATCH_H__
#define __BMESH_REGION_MATCH_H__
/** \file blender/bmesh/tools/bmesh_region_match.h
* \ingroup bmesh
*/
int BM_mesh_region_match(
BMesh *bm,
BMFace **faces_region, unsigned int faces_region_len,
ListBase *r_face_regions);
#endif /* __BMESH_REGION_MATCH_H__ */

View File

@ -66,6 +66,8 @@
#include "UI_resources.h"
#include "bmesh_tools.h"
#include "mesh_intern.h" /* own include */
/* use bmesh operator flags for a few operators */
@ -929,6 +931,96 @@ void MESH_OT_select_similar(wmOperatorType *ot)
}
/* -------------------------------------------------------------------- */
/* Select Similar Regions */
static int edbm_select_similar_region_exec(bContext *C, wmOperator *op)
{
Object *obedit = CTX_data_edit_object(C);
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
bool changed = false;
/* group vars */
int *groups_array;
int (*group_index)[2];
int group_tot;
int i;
if (bm->totfacesel < 2) {
BKE_report(op->reports, RPT_ERROR, "No face regions selected");
return OPERATOR_CANCELLED;
}
groups_array = MEM_mallocN(sizeof(*groups_array) * bm->totfacesel, __func__);
group_tot = BM_mesh_calc_face_groups(bm, groups_array, &group_index,
NULL, NULL,
BM_ELEM_SELECT, BM_VERT);
BM_mesh_elem_table_ensure(bm, BM_FACE);
for (i = 0; i < group_tot; i++) {
ListBase faces_regions;
int tot;
const int fg_sta = group_index[i][0];
const int fg_len = group_index[i][1];
int j;
BMFace **fg = MEM_mallocN(sizeof(*fg) * fg_len, __func__);
for (j = 0; j < fg_len; j++) {
fg[j] = BM_face_at_index(bm, groups_array[fg_sta + j]);
}
tot = BM_mesh_region_match(bm, fg, fg_len, &faces_regions);
MEM_freeN(fg);
if (tot) {
LinkData *link;
while ((link = BLI_pophead(&faces_regions))) {
BMFace *f, **faces = link->data;
unsigned int i = 0;
while ((f = faces[i++])) {
BM_face_select_set(bm, f, true);
}
MEM_freeN(faces);
MEM_freeN(link);
changed = true;
}
}
}
MEM_freeN(groups_array);
if (changed) {
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit);
}
else {
BKE_report(op->reports, RPT_WARNING, "No matching face regions found");
}
return OPERATOR_FINISHED;
}
void MESH_OT_select_similar_region(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Select Similar Regions";
ot->idname = "MESH_OT_select_similar_region";
ot->description = "Select similar face regions to the current selection";
/* api callbacks */
ot->exec = edbm_select_similar_region_exec;
ot->poll = ED_operator_editmesh;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/* **************** Mode Select *************** */
static int edbm_select_mode_exec(bContext *C, wmOperator *op)

View File

@ -137,6 +137,7 @@ void MESH_OT_rip_edge(struct wmOperatorType *ot);
/* *** editmesh_select.c *** */
void MESH_OT_select_similar(struct wmOperatorType *ot);
void MESH_OT_select_similar_region(struct wmOperatorType *ot);
void MESH_OT_select_mode(struct wmOperatorType *ot);
void MESH_OT_loop_multi_select(struct wmOperatorType *ot);
void MESH_OT_loop_select(struct wmOperatorType *ot);

View File

@ -130,6 +130,7 @@ void ED_operatortypes_mesh(void)
WM_operatortype_append(MESH_OT_edge_face_add);
WM_operatortype_append(MESH_OT_shortest_path_pick);
WM_operatortype_append(MESH_OT_select_similar);
WM_operatortype_append(MESH_OT_select_similar_region);
WM_operatortype_append(MESH_OT_select_mode);
WM_operatortype_append(MESH_OT_loop_multi_select);
WM_operatortype_append(MESH_OT_mark_seam);