2012-02-19 18:31:04 +00:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bmesh
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
|
|
|
|
|
2012-02-29 06:55:10 +00:00
|
|
|
/**
|
|
|
|
|
* \brief BMesh Iterators
|
2012-02-19 18:31:04 +00:00
|
|
|
*
|
|
|
|
|
* The functions and structures in this file
|
|
|
|
|
* provide a unified method for iterating over
|
|
|
|
|
* the elements of a mesh and answering simple
|
|
|
|
|
* adjacency queries. Tool authors should use
|
|
|
|
|
* the iterators provided in this file instead
|
|
|
|
|
* of inspecting the structure directly.
|
2012-03-03 20:19:11 +00:00
|
|
|
*/
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2013-09-01 15:01:15 +00:00
|
|
|
#include "BLI_compiler_attrs.h"
|
2012-02-19 18:31:04 +00:00
|
|
|
#include "BLI_mempool.h"
|
|
|
|
|
|
|
|
|
|
/* Defines for passing to BM_iter_new.
|
|
|
|
|
*
|
|
|
|
|
* "OF" can be substituted for "around"
|
|
|
|
|
* so BM_VERTS_OF_FACE means "vertices
|
|
|
|
|
* around a face."
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* these iterator over all elements of a specific
|
2012-02-24 05:56:06 +00:00
|
|
|
* type in the mesh.
|
|
|
|
|
*
|
2012-02-29 06:55:10 +00:00
|
|
|
* be sure to keep 'bm_iter_itype_htype_map' in sync with any changes
|
|
|
|
|
*/
|
2012-02-22 11:31:07 +00:00
|
|
|
typedef enum BMIterType {
|
|
|
|
|
BM_VERTS_OF_MESH = 1,
|
|
|
|
|
BM_EDGES_OF_MESH = 2,
|
|
|
|
|
BM_FACES_OF_MESH = 3,
|
|
|
|
|
/* these are topological iterators. */
|
|
|
|
|
BM_EDGES_OF_VERT = 4,
|
|
|
|
|
BM_FACES_OF_VERT = 5,
|
|
|
|
|
BM_LOOPS_OF_VERT = 6,
|
|
|
|
|
BM_VERTS_OF_EDGE = 7, /* just v1, v2: added so py can use generalized sequencer wrapper */
|
|
|
|
|
BM_FACES_OF_EDGE = 8,
|
|
|
|
|
BM_VERTS_OF_FACE = 9,
|
|
|
|
|
BM_EDGES_OF_FACE = 10,
|
|
|
|
|
BM_LOOPS_OF_FACE = 11,
|
|
|
|
|
/* returns elements from all boundaries, and returns
|
|
|
|
|
* the first element at the end to flag that we're entering
|
|
|
|
|
* a different face hole boundary*/
|
2015-11-19 16:08:40 +11:00
|
|
|
// BM_ALL_LOOPS_OF_FACE = 12,
|
2012-02-22 11:31:07 +00:00
|
|
|
/* iterate through loops around this loop, which are fetched
|
|
|
|
|
* from the other faces in the radial cycle surrounding the
|
|
|
|
|
* input loop's edge.*/
|
2015-11-19 16:08:40 +11:00
|
|
|
BM_LOOPS_OF_LOOP = 12,
|
2019-01-15 23:57:49 +11:00
|
|
|
BM_LOOPS_OF_EDGE = 13,
|
2012-02-22 11:31:07 +00:00
|
|
|
} BMIterType;
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2015-11-19 16:08:40 +11:00
|
|
|
#define BM_ITYPE_MAX 14
|
2012-02-24 05:56:06 +00:00
|
|
|
|
|
|
|
|
/* the iterator htype for each iterator */
|
|
|
|
|
extern const char bm_iter_itype_htype_map[BM_ITYPE_MAX];
|
|
|
|
|
|
2012-04-19 12:45:56 +00:00
|
|
|
#define BM_ITER_MESH(ele, iter, bm, itype) \
|
2014-12-08 10:54:56 +01:00
|
|
|
for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, bm, itype, NULL); ele; \
|
|
|
|
|
BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_step(iter))
|
2012-04-19 12:45:56 +00:00
|
|
|
|
|
|
|
|
#define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar) \
|
2014-12-08 10:54:56 +01:00
|
|
|
for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, bm, itype, NULL), indexvar = 0; ele; \
|
|
|
|
|
BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_step(iter), (indexvar)++)
|
2012-04-19 12:45:56 +00:00
|
|
|
|
2013-10-03 07:06:56 +00:00
|
|
|
/* a version of BM_ITER_MESH which keeps the next item in storage
|
2020-09-30 20:09:02 +10:00
|
|
|
* so we can delete the current item, see bug T36923. */
|
2013-10-03 07:06:56 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
# define BM_ITER_MESH_MUTABLE(ele, ele_next, iter, bm, itype) \
|
2014-12-08 10:54:56 +01:00
|
|
|
for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, bm, itype, NULL); \
|
|
|
|
|
ele ? ((void)((iter)->count = BM_iter_mesh_count(itype, bm)), \
|
|
|
|
|
(void)(ele_next = BM_iter_step(iter)), \
|
|
|
|
|
1) : \
|
|
|
|
|
0; \
|
|
|
|
|
BM_CHECK_TYPE_ELEM_ASSIGN(ele) = ele_next)
|
2013-10-03 07:06:56 +00:00
|
|
|
#else
|
|
|
|
|
# define BM_ITER_MESH_MUTABLE(ele, ele_next, iter, bm, itype) \
|
2014-12-08 10:54:56 +01:00
|
|
|
for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, bm, itype, NULL); \
|
|
|
|
|
ele ? ((BM_CHECK_TYPE_ELEM_ASSIGN(ele_next) = BM_iter_step(iter)), 1) : 0; \
|
|
|
|
|
ele = ele_next)
|
2013-10-03 07:06:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
2012-04-19 12:45:56 +00:00
|
|
|
#define BM_ITER_ELEM(ele, iter, data, itype) \
|
2014-12-08 10:54:56 +01:00
|
|
|
for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, NULL, itype, data); ele; \
|
|
|
|
|
BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_step(iter))
|
2012-04-19 12:45:56 +00:00
|
|
|
|
2012-04-19 13:47:58 +00:00
|
|
|
#define BM_ITER_ELEM_INDEX(ele, iter, data, itype, indexvar) \
|
2014-12-08 10:54:56 +01:00
|
|
|
for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, NULL, itype, data), indexvar = 0; ele; \
|
|
|
|
|
BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_step(iter), (indexvar)++)
|
2012-04-19 12:45:56 +00:00
|
|
|
|
2013-05-25 09:46:28 +00:00
|
|
|
/* iterator type structs */
|
2014-09-24 14:55:30 +10:00
|
|
|
struct BMIter__elem_of_mesh {
|
2013-05-25 09:46:28 +00:00
|
|
|
BLI_mempool_iter pooliter;
|
|
|
|
|
};
|
|
|
|
|
struct BMIter__edge_of_vert {
|
|
|
|
|
BMVert *vdata;
|
|
|
|
|
BMEdge *e_first, *e_next;
|
|
|
|
|
};
|
|
|
|
|
struct BMIter__face_of_vert {
|
|
|
|
|
BMVert *vdata;
|
|
|
|
|
BMLoop *l_first, *l_next;
|
|
|
|
|
BMEdge *e_first, *e_next;
|
|
|
|
|
};
|
|
|
|
|
struct BMIter__loop_of_vert {
|
|
|
|
|
BMVert *vdata;
|
|
|
|
|
BMLoop *l_first, *l_next;
|
|
|
|
|
BMEdge *e_first, *e_next;
|
|
|
|
|
};
|
|
|
|
|
struct BMIter__loop_of_edge {
|
|
|
|
|
BMEdge *edata;
|
|
|
|
|
BMLoop *l_first, *l_next;
|
|
|
|
|
};
|
|
|
|
|
struct BMIter__loop_of_loop {
|
|
|
|
|
BMLoop *ldata;
|
|
|
|
|
BMLoop *l_first, *l_next;
|
|
|
|
|
};
|
|
|
|
|
struct BMIter__face_of_edge {
|
|
|
|
|
BMEdge *edata;
|
|
|
|
|
BMLoop *l_first, *l_next;
|
|
|
|
|
};
|
|
|
|
|
struct BMIter__vert_of_edge {
|
|
|
|
|
BMEdge *edata;
|
|
|
|
|
};
|
|
|
|
|
struct BMIter__vert_of_face {
|
|
|
|
|
BMFace *pdata;
|
|
|
|
|
BMLoop *l_first, *l_next;
|
|
|
|
|
};
|
|
|
|
|
struct BMIter__edge_of_face {
|
|
|
|
|
BMFace *pdata;
|
|
|
|
|
BMLoop *l_first, *l_next;
|
|
|
|
|
};
|
|
|
|
|
struct BMIter__loop_of_face {
|
|
|
|
|
BMFace *pdata;
|
|
|
|
|
BMLoop *l_first, *l_next;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef void (*BMIter__begin_cb)(void *);
|
|
|
|
|
typedef void *(*BMIter__step_cb)(void *);
|
|
|
|
|
|
2012-02-29 06:55:10 +00:00
|
|
|
/* Iterator Structure */
|
2012-10-20 10:11:26 +00:00
|
|
|
/* note: some of these vars are not used,
|
2013-06-25 22:58:23 +00:00
|
|
|
* so they have been commented to save stack space since this struct is used all over */
|
2012-02-19 18:31:04 +00:00
|
|
|
typedef struct BMIter {
|
2013-05-25 09:46:28 +00:00
|
|
|
/* keep union first */
|
2012-02-19 18:31:04 +00:00
|
|
|
union {
|
2014-09-24 14:55:30 +10:00
|
|
|
struct BMIter__elem_of_mesh elem_of_mesh;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-05-25 09:46:28 +00:00
|
|
|
struct BMIter__edge_of_vert edge_of_vert;
|
|
|
|
|
struct BMIter__face_of_vert face_of_vert;
|
|
|
|
|
struct BMIter__loop_of_vert loop_of_vert;
|
|
|
|
|
struct BMIter__loop_of_edge loop_of_edge;
|
|
|
|
|
struct BMIter__loop_of_loop loop_of_loop;
|
|
|
|
|
struct BMIter__face_of_edge face_of_edge;
|
|
|
|
|
struct BMIter__vert_of_edge vert_of_edge;
|
|
|
|
|
struct BMIter__vert_of_face vert_of_face;
|
|
|
|
|
struct BMIter__edge_of_face edge_of_face;
|
|
|
|
|
struct BMIter__loop_of_face loop_of_face;
|
|
|
|
|
} data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-05-25 09:46:28 +00:00
|
|
|
BMIter__begin_cb begin;
|
|
|
|
|
BMIter__step_cb step;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-10-16 16:04:12 +00:00
|
|
|
int count; /* note, only some iterators set this, don't rely on it */
|
2012-02-19 18:31:04 +00:00
|
|
|
char itype;
|
|
|
|
|
} BMIter;
|
|
|
|
|
|
2013-09-01 15:01:15 +00:00
|
|
|
void *BM_iter_at_index(BMesh *bm, const char itype, void *data, int index) ATTR_WARN_UNUSED_RESULT;
|
2012-09-11 06:12:48 +00:00
|
|
|
int BM_iter_as_array(BMesh *bm, const char itype, void *data, void **array, const int len);
|
2015-04-25 20:15:20 +10:00
|
|
|
void *BM_iter_as_arrayN(BMesh *bm,
|
|
|
|
|
const char itype,
|
|
|
|
|
void *data,
|
|
|
|
|
int *r_len,
|
|
|
|
|
void **stack_array,
|
|
|
|
|
int stack_array_size) ATTR_WARN_UNUSED_RESULT;
|
|
|
|
|
int BMO_iter_as_array(BMOpSlot slot_args[BMO_OP_MAX_SLOTS],
|
|
|
|
|
const char *slot_name,
|
|
|
|
|
const char restrictmask,
|
|
|
|
|
void **array,
|
|
|
|
|
const int len);
|
|
|
|
|
void *BMO_iter_as_arrayN(BMOpSlot slot_args[BMO_OP_MAX_SLOTS],
|
|
|
|
|
const char *slot_name,
|
|
|
|
|
const char restrictmask,
|
|
|
|
|
int *r_len,
|
|
|
|
|
/* optional args to avoid an alloc (normally stack array) */
|
|
|
|
|
void **stack_array,
|
|
|
|
|
int stack_array_size);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-06 04:49:21 +10:00
|
|
|
int BM_iter_mesh_bitmap_from_filter(const char itype,
|
|
|
|
|
BMesh *bm,
|
2017-05-06 14:18:31 +10:00
|
|
|
uint *bitmap,
|
2016-05-06 04:49:21 +10:00
|
|
|
bool (*test_fn)(BMElem *, void *user_data),
|
|
|
|
|
void *user_data);
|
|
|
|
|
int BM_iter_mesh_bitmap_from_filter_tessface(BMesh *bm,
|
2017-05-06 14:18:31 +10:00
|
|
|
uint *bitmap,
|
2016-05-06 04:49:21 +10:00
|
|
|
bool (*test_fn)(BMFace *, void *user_data),
|
|
|
|
|
void *user_data);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-14 16:42:43 +00:00
|
|
|
int BM_iter_elem_count_flag(const char itype, void *data, const char hflag, const bool value);
|
2013-03-27 10:14:09 +00:00
|
|
|
int BMO_iter_elem_count_flag(
|
|
|
|
|
BMesh *bm, const char itype, void *data, const short oflag, const bool value);
|
2014-11-03 08:30:33 +01:00
|
|
|
int BM_iter_mesh_count(const char itype, BMesh *bm);
|
2013-01-14 16:42:43 +00:00
|
|
|
int BM_iter_mesh_count_flag(const char itype, BMesh *bm, const char hflag, const bool value);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
|
/* private for bmesh_iterators_inline.c */
|
2013-05-25 09:46:28 +00:00
|
|
|
|
|
|
|
|
#define BMITER_CB_DEF(name) \
|
|
|
|
|
struct BMIter__##name; \
|
|
|
|
|
void bmiter__##name##_begin(struct BMIter__##name *iter); \
|
|
|
|
|
void *bmiter__##name##_step(struct BMIter__##name *iter)
|
|
|
|
|
|
2014-09-24 14:55:30 +10:00
|
|
|
BMITER_CB_DEF(elem_of_mesh);
|
2013-05-25 09:46:28 +00:00
|
|
|
BMITER_CB_DEF(edge_of_vert);
|
|
|
|
|
BMITER_CB_DEF(face_of_vert);
|
|
|
|
|
BMITER_CB_DEF(loop_of_vert);
|
|
|
|
|
BMITER_CB_DEF(loop_of_edge);
|
|
|
|
|
BMITER_CB_DEF(loop_of_loop);
|
|
|
|
|
BMITER_CB_DEF(face_of_edge);
|
|
|
|
|
BMITER_CB_DEF(vert_of_edge);
|
|
|
|
|
BMITER_CB_DEF(vert_of_face);
|
|
|
|
|
BMITER_CB_DEF(edge_of_face);
|
|
|
|
|
BMITER_CB_DEF(loop_of_face);
|
|
|
|
|
|
|
|
|
|
#undef BMITER_CB_DEF
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-03-24 01:24:58 +00:00
|
|
|
#include "intern/bmesh_iterators_inline.h"
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2014-09-25 14:14:52 +10:00
|
|
|
#define BM_ITER_CHECK_TYPE_DATA(data) \
|
|
|
|
|
CHECK_TYPE_ANY(data, void *, BMFace *, BMEdge *, BMVert *, BMLoop *, BMElem *)
|
|
|
|
|
|
|
|
|
|
#define BM_iter_new(iter, bm, itype, data) \
|
|
|
|
|
(BM_ITER_CHECK_TYPE_DATA(data), BM_iter_new(iter, bm, itype, data))
|
|
|
|
|
#define BM_iter_init(iter, bm, itype, data) \
|
|
|
|
|
(BM_ITER_CHECK_TYPE_DATA(data), BM_iter_init(iter, bm, itype, data))
|