diff --git a/include/Algo/Topo/embedding.h b/include/Algo/Topo/embedding.h new file mode 100644 index 0000000000000000000000000000000000000000..4d87a985cbb1b702beeaec44de0516470e25357c --- /dev/null +++ b/include/Algo/Topo/embedding.h @@ -0,0 +1,133 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library 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 Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#ifndef __ALGO_TOPO_EMBEDDING__ +#define __ALGO_TOPO_EMBEDDING__ + +namespace CGoGN +{ + +namespace Algo +{ + +namespace Topo +{ + +/** +* Set the index of the associated cell to all the darts of an orbit +* @param orbit orbit to embed +* @param d a dart of the topological vertex +* @param em index of attribute to store as embedding +*/ +template +inline void setOrbitEmbedding(MAP& m, Cell c, unsigned int em) +{ + assert(m.template isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); + + m.foreach_dart_of_orbit(c, [&] (Dart d) { m.template setDartEmbedding(d, em); }); +} + +/** + * Set the index of the associated cell to all the darts of an orbit + * !!! WARNING !!! use only on freshly inserted darts (no unref is done on old embedding)!!! WARNING !!! + */ +template +inline void initOrbitEmbedding(MAP& m, Cell c, unsigned int em) +{ + assert(m.template isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); + + m.foreach_dart_of_orbit(c, [&] (Dart d) { m.template initDartEmbedding(d, em); }); +} + +/** +* Associate an new cell to all darts of an orbit +* @param orbit orbit to embed +* @param d a dart of the topological cell +* @return index of the attribute in table +*/ +template +inline unsigned int setOrbitEmbeddingOnNewCell(MAP& m, Cell c) +{ + assert(m.template isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); + + unsigned int em = m.template newCell(); + setOrbitEmbedding(m, c, em); + return em; +} + +/** + * Associate an new cell to all darts of an orbit + * !!! WARNING !!! use only on freshly inserted darts (no unref is done on old embedding)!!! WARNING !!! + */ +template +inline unsigned int initOrbitEmbeddingOnNewCell(MAP& m, Cell d) +{ + assert(m.template isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); + + unsigned int em = m.template newCell(); + initOrbitEmbedding(m, d, em); + return em; +} + +/** + * Copy the cell associated to a dart over an other dart + * @param orbit attribute orbit to use + * @param d the dart to overwrite (dest) + * @param e the dart to copy (src) + */ +template +inline void copyCellAttributes(MAP& m, Cell d, Cell e) +{ + assert(m.template isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); + + unsigned int dE = m.getEmbedding(d) ; + unsigned int eE = m.getEmbedding(e) ; + if(eE != EMBNULL) // if the source is NULL, nothing to copy + { + if(dE == EMBNULL) // if the dest is NULL, create a new cell + dE = setOrbitEmbeddingOnNewCell(m, d) ; + AttributeContainer& cont = m.template getAttributeContainer(); + cont.copyLine(dE, eE) ; // copy the data + } +} + +template +void boundaryMarkOrbit(MAP& m, Cell c) +{ + m.foreach_dart_of_orbit(c, [&] (Dart d) { m.template boundaryMark(d); }); +} + +template +void boundaryUnmarkOrbit(MAP& m, Cell c) +{ + m.foreach_dart_of_orbit(c, [&] (Dart d) { m.template boundaryUnmark(d); }); +} + +} // namespace Topo + +} // namespace Algo + +} // namespace CGoGN + +#endif