Subversion Repositories gelsvn

Rev

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

Rev 515 Rev 518
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 <cassert>
16
#include <vector>
16
#include <vector>
17
#include <map>
17
#include <map>
18
 
18
 
19
#include "Manifold.h"
-
 
20
 
-
 
21
namespace HMesh
19
namespace HMesh
22
{
20
{
23
    class Manifold;
21
    class Manifold;
24
 
22
 
25
    template<typename ITEM, typename ITEMID>
23
    template<typename ITEM, typename ITEMID>
26
    class AttributeVector
24
    class AttributeVector
27
    {
25
    {
28
    public:
26
    public:
29
        AttributeVector(IndexType _size = 0, ITEM item = ITEM());
27
        AttributeVector(size_t _size = 0, ITEM item = ITEM());
30
 
28
 
31
        ITEMID add(const ITEM& item);
29
        ITEMID add(const ITEM& item);
32
 
30
 
33
        // just returning should be ok; manifold and attribs should always be in sync.
31
        // 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.
32
        // const context means manifold and attribs should be const, hence in sync.
Line 36... Line 34...
36
        ITEM& get(ITEMID id);
34
        ITEM& get(ITEMID id);
37
 
35
 
38
        const ITEM& operator [](ITEMID id) const;
36
        const ITEM& operator [](ITEMID id) const;
39
        ITEM& operator [](ITEMID id);
37
        ITEM& operator [](ITEMID id);
40
 
38
 
41
        void resize(IndexType _size, ITEM item = ITEM());
39
        void resize(size_t _size, ITEM item = ITEM());
42
 
40
 
43
        IndexType size() const;
41
        size_t size() const;
44
 
42
 
45
        void clear();
43
        void clear();
46
 
44
 
47
        void cleanup(const std::map<ITEMID, ITEMID>& map);
45
        void cleanup(const std::map<ITEMID, ITEMID>& map);
48
 
46
 
Line 80... Line 78...
80
    template<typename ITEM>
78
    template<typename ITEM>
81
    inline HalfEdgeAttributeVector<ITEM>::HalfEdgeAttributeVector(const Manifold& m, ITEM item) : AttributeVector<ITEM, HalfEdgeID>(m.no_halfedges(false), item){}
79
    inline HalfEdgeAttributeVector<ITEM>::HalfEdgeAttributeVector(const Manifold& m, ITEM item) : AttributeVector<ITEM, HalfEdgeID>(m.no_halfedges(false), item){}
82
 
80
 
83
 
81
 
84
    template<typename ITEM, typename ITEMID>
82
    template<typename ITEM, typename ITEMID>
85
    inline AttributeVector<ITEM, ITEMID>::AttributeVector(IndexType _size, ITEM item) : items(_size, item){}
83
    inline AttributeVector<ITEM, ITEMID>::AttributeVector(size_t _size, ITEM item) : items(_size, item){}
86
 
84
 
87
    template<typename ITEM, typename ITEMID>
85
    template<typename ITEM, typename ITEMID>
88
    inline void AttributeVector<ITEM, ITEMID>::clear()
86
    inline void AttributeVector<ITEM, ITEMID>::clear()
89
    { items.clear(); }
87
    { items.clear(); }
90
 
88
 
91
    template<typename ITEM, typename ITEMID>
89
    template<typename ITEM, typename ITEMID>
92
    inline void AttributeVector<ITEM, ITEMID>::cleanup(const std::map<ITEMID, ITEMID>& remap)
90
    inline void AttributeVector<ITEM, ITEMID>::cleanup(const std::map<ITEMID, ITEMID>& remap)
93
    {
91
    {
94
        std::vector<ITEM> new_items(remap.size());
92
        std::vector<ITEM> new_items(remap.size());
95
        for(std::map<ITEMID, ITEMID>::const_iterator it = remap.begin(); it != remap.end(); ++it)
93
        for(std::map<ITEMID, ITEMID>::const_iterator it = remap.begin(); it != remap.end(); ++it){
96
            //std::assert(it->second.index < remap.size());
94
            assert(it->second.index < remap.size());
97
            new_items[it->second.index] = items[it->first.index];
95
            new_items[it->second.index] = items[it->first.index];
-
 
96
        }
98
        std::swap(items, new_items);
97
        std::swap(items, new_items);
99
    }
98
    }
100
 
99
 
101
 
100
 
102
    template<typename ITEM, typename ITEMID>
101
    template<typename ITEM, typename ITEMID>
103
    inline void AttributeVector<ITEM, ITEMID>::resize(IndexType _size, ITEM item)
102
    inline void AttributeVector<ITEM, ITEMID>::resize(size_t _size, ITEM item)
104
    { items.resize(_size, item); }
103
    { items.resize(_size, item); }
105
 
104
 
106
    template<typename ITEM, typename ITEMID>
105
    template<typename ITEM, typename ITEMID>
107
    inline IndexType AttributeVector<ITEM, ITEMID>::size() const
106
    inline size_t AttributeVector<ITEM, ITEMID>::size() const
108
    { return items.size(); }
107
    { return items.size(); }
109
 
108
 
110
    template<typename ITEM, typename ITEMID>
109
    template<typename ITEM, typename ITEMID>
111
    inline ITEMID AttributeVector<ITEM, ITEMID>::add(const ITEM& item)
110
    inline ITEMID AttributeVector<ITEM, ITEMID>::add(const ITEM& item)
112
    { items.push_back(item); return items.size() - 1; }
111
    { items.push_back(item); return items.size() - 1; }
113
 
112
 
114
    template<typename ITEM, typename ITEMID>
113
    template<typename ITEM, typename ITEMID>
115
    inline const ITEM& AttributeVector<ITEM, ITEMID>::get(ITEMID id) const
114
    inline const ITEM& AttributeVector<ITEM, ITEMID>::get(ITEMID id) const
116
    { 
115
    { 
117
        //std::assert(id.index < items.size());
116
        assert(id.index < items.size());
118
        return items[id.index]; 
117
        return items[id.index]; 
119
    }
118
    }
120
 
119
 
121
    template<typename ITEM, typename ITEMID>
120
    template<typename ITEM, typename ITEMID>
122
    inline ITEM& AttributeVector<ITEM, ITEMID>::get(ITEMID id)
121
    inline ITEM& AttributeVector<ITEM, ITEMID>::get(ITEMID id)
Line 127... Line 126...
127
    }
126
    }
128
 
127
 
129
    template<typename ITEM, typename ITEMID>
128
    template<typename ITEM, typename ITEMID>
130
    inline const ITEM& AttributeVector<ITEM, ITEMID>::operator [](ITEMID id) const
129
    inline const ITEM& AttributeVector<ITEM, ITEMID>::operator [](ITEMID id) const
131
    { 
130
    { 
132
        //assert(id.index < items.size());
131
        assert(id.index < items.size());
133
        return items[id.index]; 
132
        return items[id.index]; 
134
    }
133
    }
135
 
134
 
136
    template<typename ITEM, typename ITEMID>
135
    template<typename ITEM, typename ITEMID>
137
    inline ITEM& AttributeVector<ITEM, ITEMID>::operator [](ITEMID id)
136
    inline ITEM& AttributeVector<ITEM, ITEMID>::operator [](ITEMID id)