Subversion Repositories gelsvn

Rev

Rev 512 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
511 s042372 1
/*
2
* Written by Christian Thode Larsen 2009-2010
3
* Contact: thode2d@gmail.com
4
* Based on original work by J. Andreas Baerentzen
5
* Inspired by OpenMesh (www.openmesh.org)
6
*/
7
 
8
#ifndef __HMESH_ATTRIBUTEVECTOR_H__
9
#define __HMESH_ATTRIBUTEVECTOR_H__
10
 
11
#include <vector>
12
#include <map>
13
 
14
#include "Manifold.h"
15
 
16
namespace HMesh
17
{
18
	// IndexRemap used for the cleanup function, whenever the manifold is cleaned
19
    typedef std::map<int, int> IndexRemap;
20
 
21
	template<typename ITEM, typename ITEMID>
22
	class AttributeVector
23
	{
24
	public:
25
		AttributeVector(IndexType _size, ITEM item = ITEM());
26
 
27
		ITEMID add(const ITEM& item);
28
 
29
        // just returning should be ok; manifold and attribs should always be in sync.
30
        // const context means manifold and attribs should be const, hence in sync.
31
        const ITEM& get(ITEMID id) const;
32
        ITEM& get(ITEMID id);
33
 
34
		const ITEM& operator [](ITEMID id) const;
35
		ITEM& operator [](ITEMID id);
36
 
37
		void resize(IndexType _size, ITEM item = ITEM());
38
 
39
	private:
40
		std::vector<ITEM> items;
41
	};
42
 
43
	template<typename ITEM>
44
	class VertexAttributeVector : public AttributeVector<ITEM, VertexID>
45
	{
46
	public:
47
		VertexAttributeVector(const Manifold& m, ITEM item = ITEM());
48
	};
49
 
50
	template<typename ITEM>
51
	class FaceAttributeVector : public AttributeVector<ITEM, FaceID>
52
	{
53
	public:
54
		FaceAttributeVector(const Manifold& m, ITEM item = ITEM());
55
	};
56
 
57
	template<typename ITEM>
58
	class HalfEdgeAttributeVector : public AttributeVector<ITEM, HalfEdgeID>
59
	{
60
	public:
61
		HalfEdgeAttributeVector(const Manifold& m, ITEM item = ITEM());
62
	};
63
 
64
	template<typename ITEM>
65
	inline VertexAttributeVector<ITEM>::VertexAttributeVector(const Manifold& m, ITEM item) : AttributeVector<ITEM, VertexID>(m.no_vertices(false), item){}
66
 
67
	template<typename ITEM>
68
	inline FaceAttributeVector<ITEM>::FaceAttributeVector(const Manifold& m, ITEM item) : AttributeVector<ITEM, FaceID>(m.no_faces(false), item){}
69
 
70
	template<typename ITEM>
71
	inline HalfEdgeAttributeVector<ITEM>::HalfEdgeAttributeVector(const Manifold& m, ITEM item) : AttributeVector<ITEM, HalfEdgeID>(m.no_halfedges(false), item){}
72
 
73
	template<typename ITEM, typename ITEMID>
74
	inline AttributeVector<ITEM, ITEMID>::AttributeVector(IndexType _size, ITEM item) : items(_size, item){}
75
 
76
	template<typename ITEM, typename ITEMID>
77
	inline void AttributeVector<ITEM, ITEMID>::resize(IndexType _size, ITEM item)
78
	{ items.resize(_size, item); }
79
 
80
	template<typename ITEM, typename ITEMID>
81
	inline ITEMID AttributeVector<ITEM, ITEMID>::add(const ITEM& item)
82
	{ items.push_back(item); return items.size() - 1; }
83
 
84
	template<typename ITEM, typename ITEMID>
85
	inline const ITEM& AttributeVector<ITEM, ITEMID>::get(ITEMID id) const
86
    { return items[id.idx()]; }
87
 
88
	template<typename ITEM, typename ITEMID>
89
    inline ITEM& AttributeVector<ITEM, ITEMID>::get(ITEMID id)
90
    {
91
		if(items.size() < id.idx())
92
			items.resize(id.idx() + 1);
93
		return items[id.idx()]; 
94
    }
95
 
96
	template<typename ITEM, typename ITEMID>
97
	inline const ITEM& AttributeVector<ITEM, ITEMID>::operator [](ITEMID id) const
98
    { return items[id.idx()]; }
99
 
100
	template<typename ITEM, typename ITEMID>
101
    inline ITEM& AttributeVector<ITEM, ITEMID>::operator [](ITEMID id)
102
    {
103
		if(items.size() < id.idx())
104
			items.resize(id.idx() + 1);
105
		return items[id.idx()]; 
106
    }
107
}
108
 
109
#endif