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

bmesh_iterators_inline.h « intern « bmesh « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d3e18b97acb8650620e80dd5bd14efbaea53d110 (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
 * ***** 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, Geoffrey Bantle, Campbell Barton
 *
 * ***** END GPL LICENSE BLOCK *****
 */

/** \file blender/bmesh/intern/bmesh_iterators_inline.h
 *  \ingroup bmesh
 *
 * BMesh inline iterator functions.
 */

#ifndef __BMESH_ITERATORS_INLINE_H__
#define __BMESH_ITERATORS_INLINE_H__

/* inline here optimizes out the switch statement when called with
 * constant values (which is very common), nicer for loop-in-loop situations */

/**
 * \brief Iterator Step
 *
 * Calls an iterators step function to return the next element.
 */
BLI_INLINE void *BM_iter_step(BMIter *iter)
{
	return iter->step(iter);
}


/**
 * \brief Iterator Init
 *
 * Takes a bmesh iterator structure and fills
 * it with the appropriate function pointers based
 * upon its type.
 */
BLI_INLINE bool BM_iter_init(BMIter *iter, BMesh *bm, const char itype, void *data)
{
	/* int argtype; */
	iter->itype = itype;

	/* inlining optimizes out this switch when called with the defined type */
	switch ((BMIterType)itype) {
		case BM_VERTS_OF_MESH:
			BLI_assert(bm != NULL);
			BLI_assert(data == NULL);
			iter->begin = (BMIter__begin_cb)bmiter__elem_of_mesh_begin;
			iter->step  = (BMIter__step_cb)bmiter__elem_of_mesh_step;
			iter->data.elem_of_mesh.pooliter.pool = bm->vpool;
			break;
		case BM_EDGES_OF_MESH:
			BLI_assert(bm != NULL);
			BLI_assert(data == NULL);
			iter->begin = (BMIter__begin_cb)bmiter__elem_of_mesh_begin;
			iter->step  = (BMIter__step_cb)bmiter__elem_of_mesh_step;
			iter->data.elem_of_mesh.pooliter.pool = bm->epool;
			break;
		case BM_FACES_OF_MESH:
			BLI_assert(bm != NULL);
			BLI_assert(data == NULL);
			iter->begin = (BMIter__begin_cb)bmiter__elem_of_mesh_begin;
			iter->step  = (BMIter__step_cb)bmiter__elem_of_mesh_step;
			iter->data.elem_of_mesh.pooliter.pool = bm->fpool;
			break;
		case BM_EDGES_OF_VERT:
			BLI_assert(data != NULL);
			BLI_assert(((BMElem *)data)->head.htype == BM_VERT);
			iter->begin = (BMIter__begin_cb)bmiter__edge_of_vert_begin;
			iter->step  = (BMIter__step_cb)bmiter__edge_of_vert_step;
			iter->data.edge_of_vert.vdata = (BMVert *)data;
			break;
		case BM_FACES_OF_VERT:
			BLI_assert(data != NULL);
			BLI_assert(((BMElem *)data)->head.htype == BM_VERT);
			iter->begin = (BMIter__begin_cb)bmiter__face_of_vert_begin;
			iter->step  = (BMIter__step_cb)bmiter__face_of_vert_step;
			iter->data.face_of_vert.vdata = (BMVert *)data;
			break;
		case BM_LOOPS_OF_VERT:
			BLI_assert(data != NULL);
			BLI_assert(((BMElem *)data)->head.htype == BM_VERT);
			iter->begin = (BMIter__begin_cb)bmiter__loop_of_vert_begin;
			iter->step  = (BMIter__step_cb)bmiter__loop_of_vert_step;
			iter->data.loop_of_vert.vdata = (BMVert *)data;
			break;
		case BM_VERTS_OF_EDGE:
			BLI_assert(data != NULL);
			BLI_assert(((BMElem *)data)->head.htype == BM_EDGE);
			iter->begin = (BMIter__begin_cb)bmiter__vert_of_edge_begin;
			iter->step  = (BMIter__step_cb)bmiter__vert_of_edge_step;
			iter->data.vert_of_edge.edata = (BMEdge *)data;
			break;
		case BM_FACES_OF_EDGE:
			BLI_assert(data != NULL);
			BLI_assert(((BMElem *)data)->head.htype == BM_EDGE);
			iter->begin = (BMIter__begin_cb)bmiter__face_of_edge_begin;
			iter->step  = (BMIter__step_cb)bmiter__face_of_edge_step;
			iter->data.face_of_edge.edata = (BMEdge *)data;
			break;
		case BM_VERTS_OF_FACE:
			BLI_assert(data != NULL);
			BLI_assert(((BMElem *)data)->head.htype == BM_FACE);
			iter->begin = (BMIter__begin_cb)bmiter__vert_of_face_begin;
			iter->step  = (BMIter__step_cb)bmiter__vert_of_face_step;
			iter->data.vert_of_face.pdata = (BMFace *)data;
			break;
		case BM_EDGES_OF_FACE:
			BLI_assert(data != NULL);
			BLI_assert(((BMElem *)data)->head.htype == BM_FACE);
			iter->begin = (BMIter__begin_cb)bmiter__edge_of_face_begin;
			iter->step  = (BMIter__step_cb)bmiter__edge_of_face_step;
			iter->data.edge_of_face.pdata = (BMFace *)data;
			break;
		case BM_LOOPS_OF_FACE:
			BLI_assert(data != NULL);
			BLI_assert(((BMElem *)data)->head.htype == BM_FACE);
			iter->begin = (BMIter__begin_cb)bmiter__loop_of_face_begin;
			iter->step  = (BMIter__step_cb)bmiter__loop_of_face_step;
			iter->data.loop_of_face.pdata = (BMFace *)data;
			break;
		case BM_LOOPS_OF_LOOP:
			BLI_assert(data != NULL);
			BLI_assert(((BMElem *)data)->head.htype == BM_LOOP);
			iter->begin = (BMIter__begin_cb)bmiter__loop_of_loop_begin;
			iter->step  = (BMIter__step_cb)bmiter__loop_of_loop_step;
			iter->data.loop_of_loop.ldata = (BMLoop *)data;
			break;
		case BM_LOOPS_OF_EDGE:
			BLI_assert(data != NULL);
			BLI_assert(((BMElem *)data)->head.htype == BM_EDGE);
			iter->begin = (BMIter__begin_cb)bmiter__loop_of_edge_begin;
			iter->step  = (BMIter__step_cb)bmiter__loop_of_edge_step;
			iter->data.loop_of_edge.edata = (BMEdge *)data;
			break;
		default:
			/* should never happen */
			BLI_assert(0);
			return false;
			break;
	}
	
	iter->begin(iter);

	return true;
}

/**
 * \brief Iterator New
 *
 * Takes a bmesh iterator structure and fills
 * it with the appropriate function pointers based
 * upon its type and then calls BMeshIter_step()
 * to return the first element of the iterator.
 *
 */
BLI_INLINE void *BM_iter_new(BMIter *iter, BMesh *bm, const char itype, void *data)
{
	if (LIKELY(BM_iter_init(iter, bm, itype, data))) {
		return BM_iter_step(iter);
	}
	else {
		return NULL;
	}
}

#endif /* __BMESH_ITERATORS_INLINE_H__ */