Rev 514 | Rev 518 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
/* ----------------------------------------------------------------------- *
* This file is part of GEL, www.imm.dtu.dk/GEL
* Copyright (C) the authors (see AUTHORS.txt) and DTU Informatics
*
* Principal authors:
* Christian Thode Larsen (thode2d@gmail.com)
* J. Andreas Baerentzen (jab@imm.dtu.dk)
*
* See LICENSE.txt for licensing information
* ----------------------------------------------------------------------- */
#ifndef __HMESH_ATTRIBUTEVECTOR_H__
#define __HMESH_ATTRIBUTEVECTOR_H__
//#include <cassert>
#include <vector>
#include <map>
#include "Manifold.h"
namespace HMesh
{
class Manifold;
template<typename ITEM, typename ITEMID>
class AttributeVector
{
public:
AttributeVector(IndexType _size = 0, ITEM item = ITEM());
ITEMID add(const ITEM& item);
// just returning should be ok; manifold and attribs should always be in sync.
// const context means manifold and attribs should be const, hence in sync.
const ITEM& get(ITEMID id) const;
ITEM& get(ITEMID id);
const ITEM& operator [](ITEMID id) const;
ITEM& operator [](ITEMID id);
void resize(IndexType _size, ITEM item = ITEM());
IndexType size() const;
void clear();
void cleanup(const std::map<ITEMID, ITEMID>& map);
private:
std::vector<ITEM> items;
};
template<typename ITEM>
class VertexAttributeVector : public AttributeVector<ITEM, VertexID>
{
public:
VertexAttributeVector(const Manifold& m, ITEM item = ITEM());
};
template<typename ITEM>
class FaceAttributeVector : public AttributeVector<ITEM, FaceID>
{
public:
FaceAttributeVector(const Manifold& m, ITEM item = ITEM());
};
template<typename ITEM>
class HalfEdgeAttributeVector : public AttributeVector<ITEM, HalfEdgeID>
{
public:
HalfEdgeAttributeVector(const Manifold& m, ITEM item = ITEM());
};
template<typename ITEM>
inline VertexAttributeVector<ITEM>::VertexAttributeVector(const Manifold& m, ITEM item) : AttributeVector<ITEM, VertexID>(m.no_vertices(false), item){}
template<typename ITEM>
inline FaceAttributeVector<ITEM>::FaceAttributeVector(const Manifold& m, ITEM item) : AttributeVector<ITEM, FaceID>(m.no_faces(false), item){}
template<typename ITEM>
inline HalfEdgeAttributeVector<ITEM>::HalfEdgeAttributeVector(const Manifold& m, ITEM item) : AttributeVector<ITEM, HalfEdgeID>(m.no_halfedges(false), item){}
template<typename ITEM, typename ITEMID>
inline AttributeVector<ITEM, ITEMID>::AttributeVector(IndexType _size, ITEM item) : items(_size, item){}
template<typename ITEM, typename ITEMID>
inline void AttributeVector<ITEM, ITEMID>::clear()
{ items.clear(); }
template<typename ITEM, typename ITEMID>
inline void AttributeVector<ITEM, ITEMID>::cleanup(const std::map<ITEMID, ITEMID>& remap)
{
std::vector<ITEM> new_items(remap.size());
for(std::map<ITEMID, ITEMID>::const_iterator it = remap.begin(); it != remap.end(); ++it)
//std::assert(it->second.index < remap.size());
new_items[it->second.index] = items[it->first.index];
std::swap(items, new_items);
}
template<typename ITEM, typename ITEMID>
inline void AttributeVector<ITEM, ITEMID>::resize(IndexType _size, ITEM item)
{ items.resize(_size, item); }
template<typename ITEM, typename ITEMID>
inline IndexType AttributeVector<ITEM, ITEMID>::size() const
{ return items.size(); }
template<typename ITEM, typename ITEMID>
inline ITEMID AttributeVector<ITEM, ITEMID>::add(const ITEM& item)
{ items.push_back(item); return items.size() - 1; }
template<typename ITEM, typename ITEMID>
inline const ITEM& AttributeVector<ITEM, ITEMID>::get(ITEMID id) const
{
//std::assert(id.index < items.size());
return items[id.index];
}
template<typename ITEM, typename ITEMID>
inline ITEM& AttributeVector<ITEM, ITEMID>::get(ITEMID id)
{
if(items.size() < id.idx())
items.resize(id.index + 1);
return items[id.index];
}
template<typename ITEM, typename ITEMID>
inline const ITEM& AttributeVector<ITEM, ITEMID>::operator [](ITEMID id) const
{
//assert(id.index < items.size());
return items[id.index];
}
template<typename ITEM, typename ITEMID>
inline ITEM& AttributeVector<ITEM, ITEMID>::operator [](ITEMID id)
{
if(items.size() < id.index)
items.resize(id.index + 1);
return items[id.index];
}
}
#endif
Generated by GNU Enscript 1.6.6.