Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bmesh_walkers.h « intern « bmesh « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9ea9e332c5fbbfbe3ef80f272b91786951837e82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * ***** 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.
 *
 * Contributor(s): Joseph Eagar.
 *
 * ***** END GPL LICENSE BLOCK *****
 */

#ifndef __BMESH_WALKERS_H__
#define __BMESH_WALKERS_H__

/** \file blender/bmesh/intern/bmesh_walkers.h
 *  \ingroup bmesh
 */

#include "BLI_ghash.h"

/*
 * NOTE: do NOT modify topology while walking a mesh!
 */

typedef enum {
	BMW_DEPTH_FIRST,
	BMW_BREADTH_FIRST
} BMWOrder;

/*Walkers*/
typedef struct BMWalker {
	void  (*begin) (struct BMWalker *walker, void *start);
	void *(*step)  (struct BMWalker *walker);
	void *(*yield) (struct BMWalker *walker);
	int structsize;
	BMWOrder order;
	int valid_mask;

	/* runtime */
	int layer;

	BMesh *bm;
	BLI_mempool *worklist;
	ListBase states;

	/* these masks are to be tested against elements BMO_elem_flag_test() */
	short mask_vert;
	short mask_edge;
	short mask_loop;
	short mask_face;

	GHash *visithash;
	int depth;
} BMWalker;

/* define to make BMW_init more clear */
#define BMW_MASK_NOP 0

/* initialize a walker.  searchmask restricts some (not all) walkers to
 * elements with a specific tool flag set.  flags is specific to each walker.*/
void BMW_init(struct BMWalker *walker, BMesh *bm, int type,
              short mask_vert, short mask_edge, short mask_loop, short mask_face,
              int layer);
void *BMW_begin(BMWalker *walker, void *start);
void *BMW_step(struct BMWalker *walker);
void  BMW_end(struct BMWalker *walker);
int   BMW_current_depth(BMWalker *walker);

/*these are used by custom walkers*/
void *BMW_current_state(BMWalker *walker);
void *BMW_state_add(BMWalker *walker);
void  BMW_state_remove(BMWalker *walker);
void *BMW_walk(BMWalker *walker);
void  BMW_reset(BMWalker *walker);

/*
 * example of usage, walking over an island of tool flagged faces:
 *
 * BMWalker walker;
 * BMFace *f;
 *
 * BMW_init(&walker, bm, BMW_ISLAND, SOME_OP_FLAG);
 * f = BMW_begin(&walker, some_start_face);
 * for (; f; f = BMW_step(&walker))
 * {
 *     //do something with f
 * }
 * BMW_end(&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,
	/* #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_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 encouters 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 */

	/* do not intitialze function pointers and struct size in BMW_init */
	BMW_CUSTOM,
	BMW_MAXWALKERS
};

/* use with BMW_init, so as not to confuse with restrict flags */
#define BMW_NIL_LAY  0

#endif /* __BMESH_WALKERS_H__ */