/******************************************************************************* * 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_BASIC__ #define __ALGO_TOPO_BASIC__ #include "Topology/generic/attributeHandler.h" #include "Topology/generic/traversor/traversorCell.h" namespace CGoGN { namespace Algo { namespace Topo { template unsigned int getNbOrbits(const MAP& map) { unsigned int cpt = 0; foreach_cell(map, [&] (Dart) { ++cpt; }, true); return cpt; } template unsigned int getNbOrbits(const MAP& map, unsigned int orbit) { switch(orbit) { case DART: return getNbOrbits(map); case VERTEX: return getNbOrbits(map); case EDGE: return getNbOrbits(map); case FACE: return getNbOrbits(map); case VOLUME: return getNbOrbits(map); case VERTEX1: return getNbOrbits(map); case EDGE1: return getNbOrbits(map); case VERTEX2: return getNbOrbits(map); case EDGE2: return getNbOrbits(map); case FACE2: return getNbOrbits(map); default: assert(!"Cells of this dimension are not handled"); break; } return 0; } /** * Traverse the map and embed all orbits of the given dimension with a new cell * @param realloc if true -> all the orbits are embedded on new cells, if false -> already embedded orbits are not impacted */ template void initAllOrbitsEmbedding(MAP& map, bool realloc = false) { if(!map.template isOrbitEmbedded()) map.template addEmbedding() ; foreach_cell(map, [&] (Dart d) { if(realloc || map.template getEmbedding(d) == EMBNULL) map.template setOrbitEmbeddingOnNewCell(d) ; }); } /** * use the given attribute to store the indices of the cells of the corresponding orbit * @return the number of cells of the orbit */ template unsigned int computeIndexCells(MAP& map, AttributeHandler& idx) { AttributeContainer& cont = map.template getAttributeContainer(); unsigned int cpt = 0 ; for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i)) idx[i] = cpt++ ; return cpt ; } /** * ensure that each embedding is pointed by only one orbit */ template void bijectiveOrbitEmbedding(MAP& map) { if(!map.template isOrbitEmbedded()) map.template addEmbedding() ; AttributeHandler counter = map.template addAttribute("tmpCounter") ; counter.setAllValues(int(0)) ; foreach_cell(map, [&] (Dart d) { unsigned int emb = map.template getEmbedding(d) ; if (emb != EMBNULL) { if (counter[d] > 0) { unsigned int newEmb = map.template setOrbitEmbeddingOnNewCell(d) ; map.template copyCell(newEmb, emb) ; } counter[d]++ ; } }, true); map.removeAttribute(counter) ; } } // namespace Topo } // namespace Algo } // namespace CGoGN #endif