$darkmode
VCG Library
foreach.h
1 /****************************************************************************
2 * VCGLib o o *
3 * Visual and Computer Graphics Library o o *
4 * _ O _ *
5 * Copyright(C) 2004-2017 \/)\/ *
6 * Visual Computing Lab /\/| *
7 * ISTI - Italian National Research Council | *
8 * \ *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
20 * for more details. *
21 * *
22 ****************************************************************************/
23 
24 #ifndef VCG__FOREACH_H
25 #define VCG__FOREACH_H
26 
27 #include <vcg/simplex/face/pos.h>
28 
29 namespace vcg {
30 namespace tri {
35 template <class MeshType, typename Callable>
36 inline void ForEachFacePos(const MeshType &m, Callable action)
37 {
38  typedef typename face::Pos<typename MeshType::FaceType> PosType;
39 
40  for(auto fi=m.face.begin();fi!=m.face.end();++fi)
41  if(!(*fi).IsD())
42  {
43  for(int i=0;i<3;++i)
44  {
45  PosType pi(&*fi,i);
46  action(pi);
47  }
48  }
49 }
50 
51 template <class MeshType, typename Callable>
52 inline void ForEachFacePos(MeshType &m, Callable action)
53 {
54  typedef typename face::Pos<typename MeshType::FaceType> PosType;
55 
56  for(auto fi=m.face.begin();fi!=m.face.end();++fi)
57  if(!(*fi).IsD())
58  {
59  for(int i=0;i<3;++i)
60  {
61  PosType pi(&*fi,i);
62  action(pi);
63  }
64  }
65 }
66 
77 template <class MeshType, typename Callable>
78 inline void ForEachFace(const MeshType &m, Callable action)
79 {
80  if(m.fn == (int) m.face.size())
81  {
82  for(auto fi=m.face.begin();fi!=m.face.end();++fi) {
83  action(*fi);
84  }
85  }
86  else
87  {
88  for(auto fi=m.face.begin();fi!=m.face.end();++fi)
89  if(!(*fi).IsD())
90  {
91  action(*fi);
92  }
93  }
94 }
95 
96 template <class MeshType, typename Callable>
97 inline void ForEachFace(MeshType &m, Callable action)
98 {
99  if(m.fn == (int) m.face.size())
100  {
101  for(auto fi=m.face.begin();fi!=m.face.end();++fi) {
102  action(*fi);
103  }
104  }
105  else
106  {
107  for(auto fi=m.face.begin();fi!=m.face.end();++fi)
108  if(!(*fi).IsD())
109  {
110  action(*fi);
111  }
112  }
113 }
114 
125 template <class MeshType, typename Callable>
126 inline void ForEachVertex(const MeshType &m, Callable action)
127 {
128  if(m.vn == (int) m.vert.size())
129  {
130  for(auto vi=m.vert.begin();vi!=m.vert.end();++vi) {
131  action(*vi);
132  }
133  }
134  else
135  {
136  for(auto vi=m.vert.begin();vi!=m.vert.end();++vi)
137  if(!(*vi).IsD())
138  {
139  action(*vi);
140  }
141  }
142 }
143 
144 template <class MeshType, typename Callable>
145 inline void ForEachVertex(MeshType &m, Callable action)
146 {
147  if(m.vn == (int) m.vert.size())
148  {
149  for(auto vi=m.vert.begin();vi!=m.vert.end();++vi) {
150  action(*vi);
151  }
152  }
153  else
154  {
155  for(auto vi=m.vert.begin();vi!=m.vert.end();++vi)
156  if(!(*vi).IsD())
157  {
158  action(*vi);
159  }
160  }
161 }
162 
173 template <class MeshType, typename Callable>
174 inline void ForEachHEdge(const MeshType &m, Callable action)
175 {
176  if(m.hn == (int) m.hedge.size())
177  {
178  for(auto hei=m.hedge.begin();hei!=m.hedge.end();++hei) {
179  action(*hei);
180  }
181  }
182  else
183  {
184  for(auto hei=m.hedge.begin();hei!=m.hedge.end();++hei)
185  if(!(*hei).IsD())
186  {
187  action(*hei);
188  }
189  }
190 }
191 
192 template <class MeshType, typename Callable>
193 inline void ForEachHEdge(MeshType &m, Callable action)
194 {
195  if(m.hn == (int) m.hedge.size())
196  {
197  for(auto hei=m.hedge.begin();hei!=m.hedge.end();++hei) {
198  action(*hei);
199  }
200  }
201  else
202  {
203  for(auto hei=m.hedge.begin();hei!=m.hedge.end();++hei)
204  if(!(*hei).IsD())
205  {
206  action(*hei);
207  }
208  }
209 }
210 
221 template <class MeshType, typename Callable>
222 inline void ForEachEdge(const MeshType &m, Callable action)
223 {
224  if(m.en == (int) m.edge.size())
225  {
226  for(auto ei=m.edge.begin();ei!=m.edge.end();++ei) {
227  action(*ei);
228  }
229  }
230  else
231  {
232  for(auto ei=m.edge.begin();ei!=m.edge.end();++ei)
233  if(!(*ei).IsD())
234  {
235  action(*ei);
236  }
237  }
238 }
239 
240 template <class MeshType, typename Callable>
241 inline void ForEachEdge(MeshType &m, Callable action)
242 {
243  if(m.en == (int) m.edge.size())
244  {
245  for(auto ei=m.edge.begin();ei!=m.edge.end();++ei) {
246  action(*ei);
247  }
248  }
249  else
250  {
251  for(auto ei=m.edge.begin();ei!=m.edge.end();++ei)
252  if(!(*ei).IsD())
253  {
254  action(*ei);
255  }
256  }
257 }
258 
269 template <class MeshType, typename Callable>
270 inline void ForEachTetra(const MeshType &m, Callable action)
271 {
272  if(m.tn == (int) m.tetra.size())
273  {
274  for(auto ti = m.tetra.begin(); ti != m.tetra.end(); ++ti) {
275  action(*ti);
276  }
277  }
278  else
279  {
280  for(auto ti = m.tetra.begin(); ti != m.tetra.end(); ++ti)
281  if(!(*ti).IsD())
282  {
283  action(*ti);
284  }
285  }
286 }
287 
288 template <class MeshType, typename Callable>
289 inline void ForEachTetra(MeshType &m, Callable action)
290 {
291  if(m.tn == (int) m.tetra.size())
292  {
293  for(auto ti = m.tetra.begin(); ti != m.tetra.end(); ++ti) {
294  action(*ti);
295  }
296  }
297  else
298  {
299  for(auto ti = m.tetra.begin(); ti != m.tetra.end(); ++ti)
300  if(!(*ti).IsD())
301  {
302  action(*ti);
303  }
304  }
305 }
306  // end doxygen group trimesh
308 } // end namespace tri
309 } // end namespace vcg
310 
311 #endif // VCG__FOREACH_H
void ForEachTetra(const MeshType &m, Callable action)
Definition: foreach.h:270
void ForEachEdge(const MeshType &m, Callable action)
Definition: foreach.h:222
void ForEachFace(const MeshType &m, Callable action)
Definition: foreach.h:78
void ForEachVertex(const MeshType &m, Callable action)
Definition: foreach.h:126
void ForEachHEdge(const MeshType &m, Callable action)
Definition: foreach.h:174
Definition: namespaces.dox:6