vcglib/vcg/complex/foreach.h

212 lines
5.6 KiB
C
Raw Normal View History

2017-08-30 15:57:50 +02:00
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
* Copyright(C) 2004-2017 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* 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 (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
#ifndef VCG__FOREACH_H
#define VCG__FOREACH_H
#ifndef __VCG_MESH
#error "This file should not be included alone. It is automatically included by complex.h"
#endif
namespace vcg {
namespace tri {
/** \addtogroup trimesh
@{
*/
template <class MeshType>
inline void ForEachFacePos(MeshType &m, std::function<void (typename face::Pos<typename MeshType::FaceType> &)> action)
{
typedef typename face::Pos<typename MeshType::FaceType> PosType;
for(auto fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD())
{
for(int i=0;i<3;++i)
{
PosType pi(&*fi,i);
action(pi);
}
}
}
/**
* ForEachFace Helper
* to traverse all the faces of a mesh you can simply write something like:
*
* ForEachFace(m, [&](const FaceType &f){
* MakeSomethingWithFace(f);
* });
*
*/
2017-08-30 15:57:50 +02:00
template <class MeshType>
inline void ForEachFace(const MeshType &m, std::function<void (const typename MeshType::FaceType &)> action)
{
if(m.fn == (int) m.face.size())
{
for(auto fi=m.face.begin();fi!=m.face.end();++fi) {
action(*fi);
}
}
else
{
2017-08-30 15:57:50 +02:00
for(auto fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD())
{
action(*fi);
}
}
2017-08-30 15:57:50 +02:00
}
template <class MeshType>
2017-09-18 11:25:02 +02:00
inline void ForEachFace(MeshType &m, std::function<void (typename MeshType::FaceType &)> action)
2017-08-30 15:57:50 +02:00
{
if(m.fn == (int) m.face.size())
{
for(auto fi=m.face.begin();fi!=m.face.end();++fi) {
action(*fi);
}
}
else
{
2017-08-30 15:57:50 +02:00
for(auto fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD())
{
action(*fi);
}
}
2017-08-30 15:57:50 +02:00
}
/**
* ForEachVertex Helper
* to traverse all the vertexes of a mesh you can simply write something like:
*
* ForEachVertex(m, [&](const VertexType &v){
* MakeSomethingWithVertex(v);
* });
*
*/
2017-08-30 15:57:50 +02:00
template <class MeshType>
inline void ForEachVertex(MeshType &m, std::function<void (typename MeshType::VertexType &)> action)
2017-08-30 15:57:50 +02:00
{
if(m.vn == (int) m.vert.size())
{
for(auto vi=m.vert.begin();vi!=m.vert.end();++vi) {
action(*vi);
}
}
else
{
for(auto vi=m.vert.begin();vi!=m.vert.end();++vi)
if(!(*vi).IsD())
{
action(*vi);
}
}
2017-08-30 15:57:50 +02:00
}
2017-09-05 00:36:53 +02:00
/**
* ForEachEdge Helper
* to traverse all the vertexes of a mesh you can simply write something like:
*
* ForEachEdge(m, [&](const EdgeType &e){
* MakeSomethingWithEdge(e);
* });
*
*/
template <class MeshType>
inline void ForEachEdge(MeshType &m, std::function<void (typename MeshType::EdgeType &)> action)
{
if(m.en == (int) m.edge.size())
{
for(auto ei=m.edge.begin();ei!=m.edge.end();++ei) {
action(*ei);
}
}
else
{
for(auto ei=m.edge.begin();ei!=m.edge.end();++ei)
if(!(*ei).IsD())
{
action(*ei);
}
}
}
2017-08-30 15:57:50 +02:00
/**
* ForEachTetra Helper
* to traverse all the tetras of a mesh you can simply write something like:
*
* ForEachTetra(m, [&](const TetraType &t){
* MakeSomethingWithTetra(t);
* });
*
*/
template <class MeshType>
inline void ForEachTetra(const MeshType &m, std::function<void (const typename MeshType::TetraType &)> action)
{
if(m.tn == (int) m.tetra.size())
{
2018-05-09 17:14:16 +02:00
for(auto ti = m.tetra.begin(); ti != m.tetra.end(); ++ti) {
action(*ti);
}
}
else
{
for(auto ti = m.tetra.begin(); ti != m.tetra.end(); ++ti)
if(!(*ti).IsD())
{
action(*ti);
}
}
}
2017-08-30 15:57:50 +02:00
template <class MeshType>
inline void ForEachTetra(MeshType &m, std::function<void (typename MeshType::TetraType &)> action)
{
if(m.tn == (int) m.tetra.size())
{
for(auto ti = m.tetra.begin(); ti != m.tetra.end(); ++ti) {
action(*ti);
}
}
else
{
for(auto ti = m.tetra.begin(); ti != m.tetra.end(); ++ti)
if(!(*ti).IsD())
{
action(*ti);
}
}
}
2017-08-30 15:57:50 +02:00
/** @} */ // end doxygen group trimesh
} // end namespace tri
} // end namespace vcg
#endif // VCG__FOREACH_H