/******************************************************************************* * 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 * * * *******************************************************************************/ #include "Topology/generic/dartmarker.h" #include "Topology/generic/traversor/traversorCell.h" #include "Topology/generic/traversor/traversorFactory.h" namespace CGoGN { /**************************************** * DARTS MANAGEMENT * ****************************************/ inline Dart GenericMap::newDart() { unsigned int di = m_attribs[DART].insertLine(); // insert a new dart line for(unsigned int i = 0; i < NB_ORBITS; ++i) { if (m_embeddings[i]) // set all its embeddings (*m_embeddings[i])[di] = EMBNULL ; // to EMBNULL } return Dart::create(di) ; } inline void GenericMap::deleteDartLine(unsigned int index) { m_attribs[DART].removeLine(index) ; // free the dart line for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit) { if (m_embeddings[orbit]) // for each embedded orbit { unsigned int emb = (*m_embeddings[orbit])[index] ; // get the embedding of the dart if(emb != EMBNULL) m_attribs[orbit].unrefLine(emb); // and unref the corresponding line } } } inline unsigned int GenericMap::copyDartLine(unsigned int index) { unsigned int newindex = m_attribs[DART].insertLine() ; // create a new dart line m_attribs[DART].copyLine(newindex, index) ; // copy the given dart line for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit) { if (m_embeddings[orbit]) { unsigned int emb = (*m_embeddings[orbit])[newindex] ; // add a ref to the cells pointed if(emb != EMBNULL) // by the new dart line m_attribs[orbit].refLine(emb) ; } } return newindex ; } //inline bool GenericMap::isDartValid(Dart d) //{ // return !d.isNil() && m_attribs[DART].used(dartIndex(d)) ; //} /**************************************** * EMBEDDING MANAGEMENT * ****************************************/ template inline bool GenericMap::isOrbitEmbedded() const { return (ORBIT == DART) || (m_embeddings[ORBIT] != NULL) ; } inline bool GenericMap::isOrbitEmbedded(unsigned int orbit) const { return (orbit == DART) || (m_embeddings[orbit] != NULL) ; } template inline unsigned int GenericMap::newCell() { assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); return m_attribs[ORBIT].insertLine(); } template inline void GenericMap::copyCell(unsigned int i, unsigned int j) { assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); m_attribs[ORBIT].copyLine(i, j) ; } template inline void GenericMap::initCell(unsigned int i) { assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); m_attribs[ORBIT].initLine(i) ; } /**************************************** * ATTRIBUTES CONTAINERS MANAGEMENT * ****************************************/ inline unsigned int GenericMap::getNbCells(unsigned int orbit) { return m_attribs[orbit].size() ; } template inline AttributeContainer& GenericMap::getAttributeContainer() { return m_attribs[ORBIT] ; } template inline const AttributeContainer& GenericMap::getAttributeContainer() const { return m_attribs[ORBIT] ; } inline AttributeContainer& GenericMap::getAttributeContainer(unsigned int orbit) { return m_attribs[orbit] ; } inline const AttributeContainer& GenericMap::getAttributeContainer(unsigned int orbit) const { return m_attribs[orbit] ; } inline AttributeMultiVectorGen* GenericMap::getAttributeVectorGen(unsigned int orbit, const std::string& nameAttr) { return m_attribs[orbit].getVirtualDataVector(nameAttr) ; } template AttributeMultiVector* GenericMap::askMarkVector() { assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded") ; // boost::mutex::scoped_lock lockMV(m_MarkerStorageMutex[ORBIT]); if (!m_markVectors_free[ORBIT].empty()) { AttributeMultiVector* amv = m_markVectors_free[ORBIT].back(); m_markVectors_free[ORBIT].pop_back(); return amv; } //else add attribute AttributeMultiVector* amv = m_attribs[ORBIT].addAttribute("") ; std::cout << "ADD ATTRIBUTE"<< std::endl; return amv; } template inline void GenericMap::releaseMarkVector(AttributeMultiVector* amv) { assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded") ; // boost::mutex::scoped_lock lockMV(m_MarkerStorageMutex[ORBIT]); m_markVectors_free[ORBIT].push_back(amv); } template inline AttributeMultiVector* GenericMap::getEmbeddingAttributeVector() { return m_embeddings[ORBIT] ; } template bool GenericMap::registerAttribute(const std::string &nameType) { RegisteredBaseAttribute* ra = new RegisteredAttribute; if (ra == NULL) { CGoGNerr << "Erreur enregistrement attribut" << CGoGNendl; return false; } ra->setTypeName(nameType); m_attributes_registry_map->insert(std::pair(nameType,ra)); return true; } /**************************************** * EMBEDDING ATTRIBUTES MANAGEMENT * ****************************************/ template void GenericMap::addEmbedding() { if (!isOrbitEmbedded()) { std::ostringstream oss; oss << "EMB_" << ORBIT; AttributeContainer& dartCont = m_attribs[DART] ; AttributeMultiVector* amv = dartCont.addAttribute(oss.str()) ; m_embeddings[ORBIT] = amv ; // set new embedding to EMBNULL for all the darts of the map for(unsigned int i = dartCont.begin(); i < dartCont.end(); dartCont.next(i)) (*amv)[i] = EMBNULL ; } } /**************************************** * ORBITS TRAVERSALS * ****************************************/ /**************************************** * TOPOLOGICAL ATTRIBUTES MANAGEMENT * ****************************************/ inline AttributeMultiVector* GenericMap::addRelation(const std::string& name) { AttributeContainer& cont = m_attribs[DART] ; AttributeMultiVector* amv = cont.addAttribute(name) ; // set new relation to fix point for all the darts of the map for(unsigned int i = cont.begin(); i < cont.end(); cont.next(i)) (*amv)[i] = Dart(i) ; return amv ; } inline AttributeMultiVector* GenericMap::getRelation(const std::string& name) { AttributeContainer& cont = m_attribs[DART] ; AttributeMultiVector* amv = cont.getDataVector(cont.getAttributeIndex(name)) ; return amv ; } } //namespace CGoGN