Blender V4.3
bmesh_region_match.cc File Reference
#include <cstring>
#include "BLI_alloca.h"
#include "BLI_ghash.h"
#include "BLI_linklist.h"
#include "BLI_linklist_stack.h"
#include "BLI_listbase.h"
#include "BLI_mempool.h"
#include "MEM_guardedalloc.h"
#include "bmesh.hh"
#include "tools/bmesh_region_match.hh"
#include "BLI_strict_flags.h"

Go to the source code of this file.

Classes

struct  UIDWalk
 
struct  UIDFaceStep
 
struct  UIDFaceStepItem
 

Macros

#define USE_WALKER_REUSE
 
#define USE_PIVOT_FASTMATCH
 
#define USE_PIVOT_SEARCH
 
#define PRIME_VERT_SMALL   7
 
#define PRIME_VERT_MID   43
 
#define PRIME_VERT_LARGE   1031
 
#define PRIME_FACE_SMALL   13
 
#define PRIME_FACE_MID   53
 
#define PRIME_VERT_SMALL   11
 
#define PRIME_FACE_SMALL   17
 
#define PRIME_FACE_LARGE   1013
 
#define PRIME_VERT_SMALL_A   7
 
#define PRIME_VERT_SMALL_B   13
 
#define PRIME_VERT_MID_A   103
 
#define PRIME_VERT_MID_B   131
 
#define PRIME_VERT_MID_A   23
 
#define PRIME_VERT_MID_B   31
 
#define PRIME_EDGE   7
 
#define PRIME_FACE   31
 
#define PRIME_LOOP   61
 

Functions

static BMFace ** bm_mesh_region_match_pair (UIDWalk *w_src, UIDWalk *w_dst, BMEdge *e_src, BMEdge *e_dst, const uint faces_src_region_len, const uint verts_src_region_len, uint *r_faces_result_len)
 
static void bm_face_array_visit (BMFace **faces, const uint faces_len, uint *r_verts_len, bool visit_faces)
 
int BM_mesh_region_match (BMesh *bm, BMFace **faces_region, uint faces_region_len, ListBase *r_face_regions)
 
Internal UIDFaceStep API
static int facestep_sort (const void *a, const void *b)
 
static bool bm_uidwalk_facestep_begin (UIDWalk *uidwalk, UIDFaceStep *fstep)
 
static void bm_uidwalk_facestep_end (UIDWalk *uidwalk, UIDFaceStep *fstep)
 
static void bm_uidwalk_facestep_free (UIDWalk *uidwalk, UIDFaceStep *fstep)
 

Internal UIDWalk API

#define PRIME_VERT_INIT   100003
 
typedef uintptr_t UID_Int
 
typedef intptr_t SUID_Int
 
BLI_INLINE bool bm_uidwalk_face_test (UIDWalk *uidwalk, BMFace *f)
 
BLI_INLINE bool bm_uidwalk_vert_lookup (UIDWalk *uidwalk, BMVert *v, UID_Int *r_uid)
 
BLI_INLINE bool bm_uidwalk_face_lookup (UIDWalk *uidwalk, BMFace *f, UID_Int *r_uid)
 
static uint ghashutil_bmelem_indexhash (const void *key)
 
static bool ghashutil_bmelem_indexcmp (const void *a, const void *b)
 
static GHashghash_bmelem_new_ex (const char *info, const uint nentries_reserve)
 
static GSetgset_bmelem_new_ex (const char *info, const uint nentries_reserve)
 
static GHashghash_bmelem_new (const char *info)
 
static GSetgset_bmelem_new (const char *info)
 
static void bm_uidwalk_init (UIDWalk *uidwalk, const uint faces_src_region_len, const uint verts_src_region_len)
 
static void bm_uidwalk_clear (UIDWalk *uidwalk)
 
static void bm_uidwalk_free (UIDWalk *uidwalk)
 
static UID_Int bm_uidwalk_calc_vert_uid (UIDWalk *uidwalk, BMVert *v)
 
static UID_Int bm_uidwalk_calc_face_uid (UIDWalk *uidwalk, BMFace *f)
 
static void bm_uidwalk_rehash_reserve (UIDWalk *uidwalk, uint rehash_store_len_new)
 
static void bm_uidwalk_rehash (UIDWalk *uidwalk)
 
static void bm_uidwalk_rehash_facelinks (UIDWalk *uidwalk, LinkNode *faces, const uint faces_len, const bool is_init)
 
static bool bm_vert_is_uid_connect (UIDWalk *uidwalk, BMVert *v)
 
static void bm_uidwalk_pass_add (UIDWalk *uidwalk, LinkNode *faces_pass, const uint faces_pass_len)
 
static int bm_face_len_cmp (const void *v1, const void *v2)
 
static uint bm_uidwalk_init_from_edge (UIDWalk *uidwalk, BMEdge *e)
 
BLI_INLINE intptr_t abs_intptr (intptr_t a)
 
static bool bm_edge_is_region_boundary (BMEdge *e)
 
static void bm_face_region_pivot_edge_use_best (GHash *gh, BMEdge *e_test, BMEdge **r_e_pivot_best, SUID_Int e_pivot_best_id[2])
 
static SUID_Int bm_face_region_vert_boundary_id (BMVert *v)
 
static SUID_Int bm_face_region_vert_pass_id (GHash *gh, BMVert *v)
 
static BMEdgebm_face_region_pivot_edge_find (BMFace **faces_region, uint faces_region_len, uint verts_region_len, uint *r_depth)
 

Fast Match

typedef uintptr_t UIDFashMatch
 
static UIDFashMatch bm_vert_fasthash_single (BMVert *v)
 
static UIDFashMatchbm_vert_fasthash_create (BMesh *bm, const uint depth)
 
static void bm_vert_fasthash_edge_order (const UIDFashMatch *fm, const BMEdge *e, UIDFashMatch e_fm[2])
 
static bool bm_vert_fasthash_edge_is_match (UIDFashMatch *fm, const BMEdge *e_a, const BMEdge *e_b)
 
static void bm_vert_fasthash_destroy (UIDFashMatch *fm)
 

Detailed Description

Given a contiguous region of faces, find multiple matching regions (based on topology) and return them.

Implementation:

  • Given a face region, find its topological center.
  • Compare this with other vertices surrounding geometry with this ones. (reduce the search space by creating a connectivity ID per vertex and only run comprehensive tests on those).
  • All hashes must be order independent so matching topology can be identified.
  • The term UID here doesn't mean each ID is initially unique. (uniqueness is improved by re-hashing with connected data).

Definition in file bmesh_region_match.cc.

Macro Definition Documentation

◆ PRIME_EDGE

#define PRIME_EDGE   7

Referenced by bm_vert_fasthash_single().

◆ PRIME_FACE

#define PRIME_FACE   31

Referenced by bm_vert_fasthash_single().

◆ PRIME_FACE_LARGE

#define PRIME_FACE_LARGE   1013

◆ PRIME_FACE_MID

#define PRIME_FACE_MID   53

◆ PRIME_FACE_SMALL [1/2]

#define PRIME_FACE_SMALL   13

◆ PRIME_FACE_SMALL [2/2]

#define PRIME_FACE_SMALL   17

◆ PRIME_LOOP

#define PRIME_LOOP   61

Referenced by bm_vert_fasthash_single().

◆ PRIME_VERT_INIT

#define PRIME_VERT_INIT   100003

Definition at line 61 of file bmesh_region_match.cc.

Referenced by bm_uidwalk_init_from_edge().

◆ PRIME_VERT_LARGE

#define PRIME_VERT_LARGE   1031

◆ PRIME_VERT_MID

#define PRIME_VERT_MID   43

◆ PRIME_VERT_MID_A [1/2]

#define PRIME_VERT_MID_A   103

◆ PRIME_VERT_MID_A [2/2]

#define PRIME_VERT_MID_A   23

◆ PRIME_VERT_MID_B [1/2]

#define PRIME_VERT_MID_B   131

◆ PRIME_VERT_MID_B [2/2]

#define PRIME_VERT_MID_B   31

◆ PRIME_VERT_SMALL [1/2]

#define PRIME_VERT_SMALL   7

◆ PRIME_VERT_SMALL [2/2]

#define PRIME_VERT_SMALL   11

◆ PRIME_VERT_SMALL_A

#define PRIME_VERT_SMALL_A   7

◆ PRIME_VERT_SMALL_B

#define PRIME_VERT_SMALL_B   13

◆ USE_PIVOT_FASTMATCH

#define USE_PIVOT_FASTMATCH

Definition at line 42 of file bmesh_region_match.cc.

◆ USE_PIVOT_SEARCH

#define USE_PIVOT_SEARCH

Definition at line 45 of file bmesh_region_match.cc.

◆ USE_WALKER_REUSE

#define USE_WALKER_REUSE

Definition at line 37 of file bmesh_region_match.cc.

Referenced by BM_mesh_region_match().

Typedef Documentation

◆ SUID_Int

typedef intptr_t SUID_Int

Definition at line 905 of file bmesh_region_match.cc.

◆ UID_Int

typedef uintptr_t UID_Int

Definition at line 63 of file bmesh_region_match.cc.

◆ UIDFashMatch

Definition at line 1230 of file bmesh_region_match.cc.

Function Documentation

◆ abs_intptr()

◆ bm_edge_is_region_boundary()

static bool bm_edge_is_region_boundary ( BMEdge * e)
static

◆ bm_face_array_visit()

static void bm_face_array_visit ( BMFace ** faces,
const uint faces_len,
uint * r_verts_len,
bool visit_faces )
static

Tag as visited, avoid re-use.

Definition at line 866 of file bmesh_region_match.cc.

References BM_elem_flag_enable, BM_elem_flag_test, BM_ELEM_TAG, BM_FACE_FIRST_LOOP, BMLoop::e, BMLoop::next, and BMLoop::v.

Referenced by BM_mesh_region_match().

◆ bm_face_len_cmp()

static int bm_face_len_cmp ( const void * v1,
const void * v2 )
static

Definition at line 539 of file bmesh_region_match.cc.

References BMFace::len, and v2.

Referenced by bm_uidwalk_init_from_edge().

◆ bm_face_region_pivot_edge_find()

static BMEdge * bm_face_region_pivot_edge_find ( BMFace ** faces_region,
uint faces_region_len,
uint verts_region_len,
uint * r_depth )
static

◆ bm_face_region_pivot_edge_use_best()

static void bm_face_region_pivot_edge_use_best ( GHash * gh,
BMEdge * e_test,
BMEdge ** r_e_pivot_best,
SUID_Int e_pivot_best_id[2] )
static

Definition at line 927 of file bmesh_region_match.cc.

References BLI_ghash_lookup(), BMEdge::v1, and BMEdge::v2.

Referenced by bm_face_region_pivot_edge_find().

◆ bm_face_region_vert_boundary_id()

◆ bm_face_region_vert_pass_id()

static SUID_Int bm_face_region_vert_pass_id ( GHash * gh,
BMVert * v )
static

◆ BM_mesh_region_match()

◆ bm_mesh_region_match_pair()

◆ bm_uidwalk_calc_face_uid()

◆ bm_uidwalk_calc_vert_uid()

◆ bm_uidwalk_clear()

◆ bm_uidwalk_face_lookup()

BLI_INLINE bool bm_uidwalk_face_lookup ( UIDWalk * uidwalk,
BMFace * f,
UID_Int * r_uid )

◆ bm_uidwalk_face_test()

BLI_INLINE bool bm_uidwalk_face_test ( UIDWalk * uidwalk,
BMFace * f )

◆ bm_uidwalk_facestep_begin()

◆ bm_uidwalk_facestep_end()

static void bm_uidwalk_facestep_end ( UIDWalk * uidwalk,
UIDFaceStep * fstep )
static

◆ bm_uidwalk_facestep_free()

◆ bm_uidwalk_free()

◆ bm_uidwalk_init()

◆ bm_uidwalk_init_from_edge()

◆ bm_uidwalk_pass_add()

◆ bm_uidwalk_rehash()

static void bm_uidwalk_rehash ( UIDWalk * uidwalk)
static

◆ bm_uidwalk_rehash_facelinks()

static void bm_uidwalk_rehash_facelinks ( UIDWalk * uidwalk,
LinkNode * faces,
const uint faces_len,
const bool is_init )
static

◆ bm_uidwalk_rehash_reserve()

static void bm_uidwalk_rehash_reserve ( UIDWalk * uidwalk,
uint rehash_store_len_new )
static

◆ bm_uidwalk_vert_lookup()

BLI_INLINE bool bm_uidwalk_vert_lookup ( UIDWalk * uidwalk,
BMVert * v,
UID_Int * r_uid )

◆ bm_vert_fasthash_create()

static UIDFashMatch * bm_vert_fasthash_create ( BMesh * bm,
const uint depth )
static

◆ bm_vert_fasthash_destroy()

static void bm_vert_fasthash_destroy ( UIDFashMatch * fm)
static

Definition at line 1320 of file bmesh_region_match.cc.

References MEM_freeN().

Referenced by BM_mesh_region_match().

◆ bm_vert_fasthash_edge_is_match()

static bool bm_vert_fasthash_edge_is_match ( UIDFashMatch * fm,
const BMEdge * e_a,
const BMEdge * e_b )
static

Definition at line 1309 of file bmesh_region_match.cc.

References bm_vert_fasthash_edge_order().

Referenced by BM_mesh_region_match().

◆ bm_vert_fasthash_edge_order()

static void bm_vert_fasthash_edge_order ( const UIDFashMatch * fm,
const BMEdge * e,
UIDFashMatch e_fm[2] )
static

Definition at line 1297 of file bmesh_region_match.cc.

References BM_elem_index_get, and e.

Referenced by bm_vert_fasthash_edge_is_match().

◆ bm_vert_fasthash_single()

static UIDFashMatch bm_vert_fasthash_single ( BMVert * v)
static

◆ bm_vert_is_uid_connect()

static bool bm_vert_is_uid_connect ( UIDWalk * uidwalk,
BMVert * v )
static

◆ facestep_sort()

static int facestep_sort ( const void * a,
const void * b )
static

Definition at line 606 of file bmesh_region_match.cc.

References b, and UIDFaceStepItem::uid.

Referenced by bm_uidwalk_facestep_begin().

◆ ghash_bmelem_new()

static GHash * ghash_bmelem_new ( const char * info)
static

Definition at line 176 of file bmesh_region_match.cc.

References ghash_bmelem_new_ex().

Referenced by bm_uidwalk_init().

◆ ghash_bmelem_new_ex()

static GHash * ghash_bmelem_new_ex ( const char * info,
const uint nentries_reserve )
static

◆ ghashutil_bmelem_indexcmp()

static bool ghashutil_bmelem_indexcmp ( const void * a,
const void * b )
static

Definition at line 158 of file bmesh_region_match.cc.

References b, BLI_assert, and BM_elem_index_get.

Referenced by ghash_bmelem_new_ex(), and gset_bmelem_new_ex().

◆ ghashutil_bmelem_indexhash()

static uint ghashutil_bmelem_indexhash ( const void * key)
static

Definition at line 152 of file bmesh_region_match.cc.

References BM_elem_index_get.

Referenced by ghash_bmelem_new_ex(), and gset_bmelem_new_ex().

◆ gset_bmelem_new()

static GSet * gset_bmelem_new ( const char * info)
static

Definition at line 181 of file bmesh_region_match.cc.

References gset_bmelem_new_ex().

Referenced by bm_uidwalk_init().

◆ gset_bmelem_new_ex()

static GSet * gset_bmelem_new_ex ( const char * info,
const uint nentries_reserve )
static