From b52734115a2eb7c04c395d1fc01f10378ba4436f Mon Sep 17 00:00:00 2001 From: Paolo Cignoni Date: Wed, 30 Aug 2017 15:57:50 +0200 Subject: [PATCH] Added first version of foreach helpers --- vcg/complex/complex.h | 1 + vcg/complex/foreach.h | 90 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 vcg/complex/foreach.h diff --git a/vcg/complex/complex.h b/vcg/complex/complex.h index 65ec404c..082fd9aa 100644 --- a/vcg/complex/complex.h +++ b/vcg/complex/complex.h @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include diff --git a/vcg/complex/foreach.h b/vcg/complex/foreach.h new file mode 100644 index 00000000..c43c4eb9 --- /dev/null +++ b/vcg/complex/foreach.h @@ -0,0 +1,90 @@ +/**************************************************************************** +* 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 +inline void ForEachFacePos(MeshType &m, std::function &)> action) +{ + typedef typename face::Pos 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); + } + } +} + +template +inline void ForEachFace(const MeshType &m, std::function action) +{ + for(auto fi=m.face.begin();fi!=m.face.end();++fi) + if(!(*fi).IsD()) + { + action(*fi); + } +} + +template +inline void ForEachFace(MeshType &m, std::function action) +{ + for(auto fi=m.face.begin();fi!=m.face.end();++fi) + if(!(*fi).IsD()) + { + action(*fi); + } +} + + +template +inline void forEachVertex(MeshType &m, std::function action) +{ + for(auto fi=m.face.begin();fi!=m.face.end();++fi) + if(!(*fi).IsD()) + { + action(*fi); + } +} + + + +/** @} */ // end doxygen group trimesh +} // end namespace tri +} // end namespace vcg + +#endif // VCG__FOREACH_H