BMesh Walker: typecheck args for walker->begin()

This commit is contained in:
Campbell Barton 2014-05-23 17:05:57 +10:00
parent 90449f9950
commit d82cd4d5ef
3 changed files with 37 additions and 24 deletions

View File

@ -60,6 +60,8 @@
void *BMW_begin(BMWalker *walker, void *start)
{
BLI_assert(((BMHeader *)start)->htype & walker->begin_htype);
walker->begin(walker, start);
return BMW_current_state(walker) ? walker->step(walker) : NULL;
@ -100,6 +102,7 @@ void BMW_init(BMWalker *walker, BMesh *bm, int type,
}
if (type != BMW_CUSTOM) {
walker->begin_htype = bm_walker_types[type]->begin_htype;
walker->begin = bm_walker_types[type]->begin;
walker->yield = bm_walker_types[type]->yield;
walker->step = bm_walker_types[type]->step;

View File

@ -27,8 +27,6 @@
* \ingroup bmesh
*/
#include "BLI_ghash.h"
/*
* NOTE: do NOT modify topology while walking a mesh!
*/
@ -45,6 +43,7 @@ typedef enum {
/*Walkers*/
typedef struct BMWalker {
char begin_htype; /* only for validating input */
void (*begin) (struct BMWalker *walker, void *start);
void *(*step) (struct BMWalker *walker);
void *(*yield) (struct BMWalker *walker);
@ -67,8 +66,8 @@ typedef struct BMWalker {
BMWFlag flag;
GSet *visit_set;
GSet *visit_set_alt;
struct GSet *visit_set;
struct GSet *visit_set_alt;
int depth;
} BMWalker;
@ -108,34 +107,15 @@ void BMW_reset(BMWalker *walker);
*/
enum {
/* walk over connected geometry. can restrict to a search flag,
* or not, it's optional.
*
* takes a vert as an argument, and spits out edges, restrict flag acts
* on the edges as well. */
BMW_SHELL,
/*walk over an edge loop. search flag doesn't do anything.*/
BMW_LOOP,
BMW_FACELOOP,
BMW_EDGERING,
BMW_EDGEBOUNDARY,
/* #define BMW_RING 2 */
/* walk over uv islands; takes a loop as input. restrict flag
* restricts the walking to loops whose vert has restrict flag set as a
* tool flag.
*
* the flag parameter to BMW_init maps to a loop customdata layer index.
*/
/* BMW_RING, */
BMW_LOOPDATA_ISLAND,
/* walk over an island of flagged faces. note, that this doesn't work on
* non-manifold geometry. it might be better to rewrite this to extract
* boundary info from the island walker, rather then directly walking
* over the boundary. raises an error if it encounters nonmanifold
* geometry. */
BMW_ISLANDBOUND,
/* walk over all faces in an island of tool flagged faces. */
BMW_ISLAND,
/* walk from a vertex to all connected vertices. */
BMW_CONNECTED_VERTEX,
/* end of array index enum vals */

View File

@ -93,6 +93,9 @@ static bool bmw_mask_check_face(BMWalker *walker, BMFace *f)
* Starts at a vertex on the mesh and walks over the 'shell' it belongs
* to via visiting connected edges.
*
* takes an edge or vertex as an argument, and spits out edges,
* restrict flag acts on the edges as well.
*
* \todo Add restriction flag/callback for wire edges.
*/
static void bmw_ShellWalker_visitEdge(BMWalker *walker, BMEdge *e)
@ -143,6 +146,8 @@ static void bmw_ShellWalker_begin(BMWalker *walker, void *data)
bmw_ShellWalker_visitEdge(walker, e);
break;
}
default:
BLI_assert(0);
}
}
@ -224,6 +229,9 @@ static void *bmw_ShellWalker_step(BMWalker *walker)
* \{
*
* Similar to shell walker, but visits vertices instead of edges.
*
* Walk from a vertex to all connected vertices.
*
*/
static void bmw_ConnectedVertexWalker_visitVertex(BMWalker *walker, BMVert *v)
{
@ -286,6 +294,11 @@ static void *bmw_ConnectedVertexWalker_step(BMWalker *walker)
*
* Starts at a edge on the mesh and walks over the boundary of an island it belongs to.
*
* \note that this doesn't work on non-manifold geometry.
* it might be better to rewrite this to extract
* boundary info from the island walker, rather then directly walking
* over the boundary. raises an error if it encounters nonmanifold geometry.
*
* \todo Add restriction flag/callback for wire edges.
*/
static void bmw_IslandboundWalker_begin(BMWalker *walker, void *data)
@ -456,6 +469,7 @@ static void *bmw_IslandWalker_step(BMWalker *walker)
* \{
*
* Starts at a tool-flagged edge and walks over the edge loop
*
*/
/* utility function to see if an edge is apart of an ngon boundary */
@ -1066,6 +1080,13 @@ static void *bmw_EdgeboundaryWalker_step(BMWalker *walker)
/** \name UV Edge Walker
*
* walk over uv islands; takes a loop as input. restrict flag
* restricts the walking to loops whose vert has restrict flag set as a
* tool flag.
*
* the flag parameter to BMW_init maps to a loop customdata layer index.
*
* \{ */
static void bmw_UVEdgeWalker_begin(BMWalker *walker, void *data)
@ -1155,6 +1176,7 @@ static void *bmw_UVEdgeWalker_step(BMWalker *walker)
static BMWalker bmw_ShellWalker_Type = {
BM_VERT | BM_EDGE,
bmw_ShellWalker_begin,
bmw_ShellWalker_step,
bmw_ShellWalker_yield,
@ -1164,6 +1186,7 @@ static BMWalker bmw_ShellWalker_Type = {
};
static BMWalker bmw_IslandboundWalker_Type = {
BM_LOOP,
bmw_IslandboundWalker_begin,
bmw_IslandboundWalker_step,
bmw_IslandboundWalker_yield,
@ -1173,6 +1196,7 @@ static BMWalker bmw_IslandboundWalker_Type = {
};
static BMWalker bmw_IslandWalker_Type = {
BM_FACE,
bmw_IslandWalker_begin,
bmw_IslandWalker_step,
bmw_IslandWalker_yield,
@ -1182,6 +1206,7 @@ static BMWalker bmw_IslandWalker_Type = {
};
static BMWalker bmw_LoopWalker_Type = {
BM_EDGE,
bmw_LoopWalker_begin,
bmw_LoopWalker_step,
bmw_LoopWalker_yield,
@ -1191,6 +1216,7 @@ static BMWalker bmw_LoopWalker_Type = {
};
static BMWalker bmw_FaceLoopWalker_Type = {
BM_EDGE,
bmw_FaceLoopWalker_begin,
bmw_FaceLoopWalker_step,
bmw_FaceLoopWalker_yield,
@ -1200,6 +1226,7 @@ static BMWalker bmw_FaceLoopWalker_Type = {
};
static BMWalker bmw_EdgeringWalker_Type = {
BM_EDGE,
bmw_EdgeringWalker_begin,
bmw_EdgeringWalker_step,
bmw_EdgeringWalker_yield,
@ -1209,6 +1236,7 @@ static BMWalker bmw_EdgeringWalker_Type = {
};
static BMWalker bmw_EdgeboundaryWalker_Type = {
BM_EDGE,
bmw_EdgeboundaryWalker_begin,
bmw_EdgeboundaryWalker_step,
bmw_EdgeboundaryWalker_yield,
@ -1218,6 +1246,7 @@ static BMWalker bmw_EdgeboundaryWalker_Type = {
};
static BMWalker bmw_UVEdgeWalker_Type = {
BM_LOOP,
bmw_UVEdgeWalker_begin,
bmw_UVEdgeWalker_step,
bmw_UVEdgeWalker_yield,
@ -1227,6 +1256,7 @@ static BMWalker bmw_UVEdgeWalker_Type = {
};
static BMWalker bmw_ConnectedVertexWalker_Type = {
BM_VERT,
bmw_ConnectedVertexWalker_begin,
bmw_ConnectedVertexWalker_step,
bmw_ConnectedVertexWalker_yield,