Subversion Repositories gelsvn

Rev

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

Rev 514 Rev 515
Line 10... Line 10...
10
 * ----------------------------------------------------------------------- */
10
 * ----------------------------------------------------------------------- */
11
 
11
 
12
#ifndef __HMESH_ATTRIBUTEVECTOR_H__
12
#ifndef __HMESH_ATTRIBUTEVECTOR_H__
13
#define __HMESH_ATTRIBUTEVECTOR_H__
13
#define __HMESH_ATTRIBUTEVECTOR_H__
14
 
14
 
-
 
15
//#include <cassert>
15
#include <vector>
16
#include <vector>
16
#include <map>
17
#include <map>
17
 
18
 
18
#include "Manifold.h"
19
#include "Manifold.h"
19
 
20
 
20
namespace HMesh
21
namespace HMesh
21
{
22
{
22
    // IndexRemap used for the cleanup function, whenever the manifold is cleaned
-
 
23
    typedef std::map<int, int> IndexRemap;
23
    class Manifold;
24
 
24
 
25
    template<typename ITEM, typename ITEMID>
25
    template<typename ITEM, typename ITEMID>
26
    class AttributeVector
26
    class AttributeVector
27
    {
27
    {
28
    public:
28
    public:
29
        AttributeVector(IndexType _size, ITEM item = ITEM());
29
        AttributeVector(IndexType _size = 0, ITEM item = ITEM());
30
 
30
 
31
        ITEMID add(const ITEM& item);
31
        ITEMID add(const ITEM& item);
32
 
32
 
33
        // 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.
34
        // 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.
Line 40... Line 40...
40
 
40
 
41
        void resize(IndexType _size, ITEM item = ITEM());
41
        void resize(IndexType _size, ITEM item = ITEM());
42
 
42
 
43
        IndexType size() const;
43
        IndexType size() const;
44
 
44
 
-
 
45
        void clear();
-
 
46
 
-
 
47
        void cleanup(const std::map<ITEMID, ITEMID>& map);
-
 
48
 
45
    private:
49
    private:
46
        std::vector<ITEM> items;
50
        std::vector<ITEM> items;
47
    };
51
    };
48
 
52
 
49
    template<typename ITEM>
53
    template<typename ITEM>
Line 74... Line 78...
74
    inline FaceAttributeVector<ITEM>::FaceAttributeVector(const Manifold& m, ITEM item) : AttributeVector<ITEM, FaceID>(m.no_faces(false), item){}
78
    inline FaceAttributeVector<ITEM>::FaceAttributeVector(const Manifold& m, ITEM item) : AttributeVector<ITEM, FaceID>(m.no_faces(false), item){}
75
 
79
 
76
    template<typename ITEM>
80
    template<typename ITEM>
77
    inline HalfEdgeAttributeVector<ITEM>::HalfEdgeAttributeVector(const Manifold& m, ITEM item) : AttributeVector<ITEM, HalfEdgeID>(m.no_halfedges(false), item){}
81
    inline HalfEdgeAttributeVector<ITEM>::HalfEdgeAttributeVector(const Manifold& m, ITEM item) : AttributeVector<ITEM, HalfEdgeID>(m.no_halfedges(false), item){}
78
 
82
 
-
 
83
 
79
    template<typename ITEM, typename ITEMID>
84
    template<typename ITEM, typename ITEMID>
80
    inline AttributeVector<ITEM, ITEMID>::AttributeVector(IndexType _size, ITEM item) : items(_size, item){}
85
    inline AttributeVector<ITEM, ITEMID>::AttributeVector(IndexType _size, ITEM item) : items(_size, item){}
81
 
86
 
82
    template<typename ITEM, typename ITEMID>
87
    template<typename ITEM, typename ITEMID>
-
 
88
    inline void AttributeVector<ITEM, ITEMID>::clear()
-
 
89
    { items.clear(); }
-
 
90
 
-
 
91
    template<typename ITEM, typename ITEMID>
-
 
92
    inline void AttributeVector<ITEM, ITEMID>::cleanup(const std::map<ITEMID, ITEMID>& remap)
-
 
93
    {
-
 
94
        std::vector<ITEM> new_items(remap.size());
-
 
95
        for(std::map<ITEMID, ITEMID>::const_iterator it = remap.begin(); it != remap.end(); ++it)
-
 
96
            //std::assert(it->second.index < remap.size());
-
 
97
            new_items[it->second.index] = items[it->first.index];
-
 
98
        std::swap(items, new_items);
-
 
99
    }
-
 
100
 
-
 
101
 
-
 
102
    template<typename ITEM, typename ITEMID>
83
    inline void AttributeVector<ITEM, ITEMID>::resize(IndexType _size, ITEM item)
103
    inline void AttributeVector<ITEM, ITEMID>::resize(IndexType _size, ITEM item)
84
    { items.resize(_size, item); }
104
    { items.resize(_size, item); }
85
 
105
 
86
    template<typename ITEM, typename ITEMID>
106
    template<typename ITEM, typename ITEMID>
87
    inline IndexType AttributeVector<ITEM, ITEMID>::size() const
107
    inline IndexType AttributeVector<ITEM, ITEMID>::size() const
Line 91... Line 111...
91
    inline ITEMID AttributeVector<ITEM, ITEMID>::add(const ITEM& item)
111
    inline ITEMID AttributeVector<ITEM, ITEMID>::add(const ITEM& item)
92
    { items.push_back(item); return items.size() - 1; }
112
    { items.push_back(item); return items.size() - 1; }
93
 
113
 
94
    template<typename ITEM, typename ITEMID>
114
    template<typename ITEM, typename ITEMID>
95
    inline const ITEM& AttributeVector<ITEM, ITEMID>::get(ITEMID id) const
115
    inline const ITEM& AttributeVector<ITEM, ITEMID>::get(ITEMID id) const
-
 
116
    { 
-
 
117
        //std::assert(id.index < items.size());
96
    { return items[id.idx()]; }
118
        return items[id.index]; 
-
 
119
    }
97
 
120
 
98
    template<typename ITEM, typename ITEMID>
121
    template<typename ITEM, typename ITEMID>
99
    inline ITEM& AttributeVector<ITEM, ITEMID>::get(ITEMID id)
122
    inline ITEM& AttributeVector<ITEM, ITEMID>::get(ITEMID id)
100
    {
123
    {
101
        if(items.size() < id.idx())
124
        if(items.size() < id.idx())
102
            items.resize(id.idx() + 1);
125
            items.resize(id.index + 1);
103
        return items[id.idx()]; 
126
        return items[id.index]; 
104
    }
127
    }
105
 
128
 
106
    template<typename ITEM, typename ITEMID>
129
    template<typename ITEM, typename ITEMID>
107
    inline const ITEM& AttributeVector<ITEM, ITEMID>::operator [](ITEMID id) const
130
    inline const ITEM& AttributeVector<ITEM, ITEMID>::operator [](ITEMID id) const
-
 
131
    { 
-
 
132
        //assert(id.index < items.size());
108
    { return items[id.idx()]; }
133
        return items[id.index]; 
-
 
134
    }
109
 
135
 
110
    template<typename ITEM, typename ITEMID>
136
    template<typename ITEM, typename ITEMID>
111
    inline ITEM& AttributeVector<ITEM, ITEMID>::operator [](ITEMID id)
137
    inline ITEM& AttributeVector<ITEM, ITEMID>::operator [](ITEMID id)
112
    {
138
    {
113
        if(items.size() < id.idx())
139
        if(items.size() < id.index)
114
            items.resize(id.idx() + 1);
140
            items.resize(id.index + 1);
115
        return items[id.idx()]; 
141
        return items[id.index]; 
116
    }
142
    }
117
}
143
}
118
 
144
 
119
#endif
145
#endif
120
 
146