attribmap.hpp 4.21 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
*                                                                              *
* 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.           *
*                                                                              *
20
* Web site: http://cgogn.u-strasbg.fr/                                         *
Pierre Kraemer's avatar
Pierre Kraemer committed
21 22 23 24 25 26 27 28 29 30 31 32
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{

template <typename T>
inline AttributeHandler<T> AttribMap::addAttribute(unsigned int orbit, const std::string& nameAttr)
{
	if(!isOrbitEmbedded(orbit))
		addEmbedding(orbit) ;
33
	AttributeMultiVector<T>* amv = m_attribs[orbit].addAttribute<T>(nameAttr) ;
34
	return AttributeHandler<T>(this, amv) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
35 36 37 38 39 40
}

template <typename T>
inline bool AttribMap::removeAttribute(AttributeHandler<T>& attr)
{
	assert(attr.isValid() || !"Invalid attribute handler") ;
41
	return m_attribs[attr.getOrbit()].removeAttribute<T>(attr.getIndex()) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
42 43 44 45 46
}

template <typename T>
inline AttributeHandler<T> AttribMap::getAttribute(unsigned int orbit, const std::string& nameAttr)
{
47 48
	AttributeMultiVector<T>* amv = m_attribs[orbit].getDataVector<T>(nameAttr) ;
	return AttributeHandler<T>(this, amv) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
49 50 51 52 53 54
}

template <typename T>
inline bool AttribMap::swapAttributes(AttributeHandler<T>& attr1, AttributeHandler<T>& attr2)
{
	assert((attr1.isValid() && attr2.isValid()) || !"Invalid attribute handler") ;
55 56 57 58
	assert(attr1.getOrbit() == attr2.getOrbit() || !"Cannot swap attributes of different orbits") ;
	unsigned int orbit = attr1.getOrbit() ;
	unsigned int index1 = attr1.getIndex() ;
	unsigned int index2 = attr2.getIndex() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
59 60 61 62 63 64 65 66 67
	if(index1 != index2)
		return m_attribs[orbit].swapAttributes(index1, index2) ;
	return false ;
}

template <typename T>
inline bool AttribMap::copyAttribute(AttributeHandler<T>& dst, AttributeHandler<T>& src)
{
	assert((dst.isValid() && src.isValid()) || !"Invalid attribute handler") ;
68 69 70 71
	unsigned int orbit = dst.getOrbit() ;
	assert(orbit == src.getOrbit() || !"Cannot copy attributes of different orbits") ;
	unsigned int index_dst = dst.getIndex() ;
	unsigned int index_src = src.getIndex() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85
	if(index_dst != index_src)
		return m_attribs[orbit].copyAttribute(index_dst, index_src) ;
	return false ;
}

inline unsigned int AttribMap::getNbCells(unsigned int orbit)
{
	return this->m_attribs[orbit].size() ;
}

/****************************************
 *  TOPOLOGICAL ATTRIBUTES MANAGEMENT   *
 ****************************************/

86
inline AttributeMultiVector<Dart>* AttribMap::addRelation(const std::string& name)
Pierre Kraemer's avatar
Pierre Kraemer committed
87
{
88
	AttributeContainer& cont = m_attribs[DART] ;
89
	AttributeMultiVector<Dart>* amv = cont.addAttribute<Dart>(name) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
90 91 92

	// 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))
93
		amv->operator[](i) = i ;
Pierre Kraemer's avatar
Pierre Kraemer committed
94

95
	return amv ;
Pierre Kraemer's avatar
Pierre Kraemer committed
96 97 98
}

} // namespace CGoGN