Subversion Repositories gelsvn

Rev

Rev 511 | Rev 514 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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