512 |
s042372 |
1 |
/* ----------------------------------------------------------------------- *
|
572 |
jab |
2 |
* This file is part of GEL, http://www.imm.dtu.dk/GEL
|
|
|
3 |
* Copyright (C) the authors and DTU Informatics
|
|
|
4 |
* For license and list of authors, see ../../doc/intro.pdf
|
512 |
s042372 |
5 |
* ----------------------------------------------------------------------- */
|
511 |
s042372 |
6 |
|
578 |
jab |
7 |
/**
|
|
|
8 |
@file AttributeVector.h
|
|
|
9 |
Contains an abstract class template for attribute vectors for HMesh entities.
|
|
|
10 |
Also contains templates for attribute vectors for concrete entities.
|
|
|
11 |
*/
|
|
|
12 |
|
511 |
s042372 |
13 |
#ifndef __HMESH_ATTRIBUTEVECTOR_H__
|
|
|
14 |
#define __HMESH_ATTRIBUTEVECTOR_H__
|
|
|
15 |
|
518 |
s042372 |
16 |
#include <cassert>
|
511 |
s042372 |
17 |
#include <vector>
|
|
|
18 |
#include <map>
|
|
|
19 |
|
636 |
khor |
20 |
namespace HMesh
|
511 |
s042372 |
21 |
{
|
587 |
jab |
22 |
/** Abstract class for HMesh entity attribute vectors. This class is used for storing all attributes
|
|
|
23 |
associated with any type of mesh entity - be it Vertex, HalfEdge, or Face. Also the position attribute
|
|
|
24 |
is stored in an AttributeVector class.
|
|
|
25 |
*/
|
512 |
s042372 |
26 |
template<typename ITEM, typename ITEMID>
|
|
|
27 |
class AttributeVector
|
|
|
28 |
{
|
|
|
29 |
public:
|
520 |
s042372 |
30 |
/// Construct from optional size and item (size should be identical to number of entities in associated container
|
518 |
s042372 |
31 |
AttributeVector(size_t _size = 0, ITEM item = ITEM());
|
511 |
s042372 |
32 |
|
522 |
s042372 |
33 |
/// Add an item
|
520 |
s042372 |
34 |
// ITEMID add(const ITEM& item);
|
511 |
s042372 |
35 |
|
520 |
s042372 |
36 |
/// const reference to item given by ID
|
511 |
s042372 |
37 |
const ITEM& get(ITEMID id) const;
|
520 |
s042372 |
38 |
|
|
|
39 |
/// reference to item given by ID
|
511 |
s042372 |
40 |
ITEM& get(ITEMID id);
|
|
|
41 |
|
520 |
s042372 |
42 |
/// const reference to item given by ID
|
512 |
s042372 |
43 |
const ITEM& operator [](ITEMID id) const;
|
520 |
s042372 |
44 |
|
|
|
45 |
/// reference to item given by ID
|
512 |
s042372 |
46 |
ITEM& operator [](ITEMID id);
|
511 |
s042372 |
47 |
|
522 |
s042372 |
48 |
/// resize the vector (may be necessary if associated container size grows)
|
518 |
s042372 |
49 |
void resize(size_t _size, ITEM item = ITEM());
|
511 |
s042372 |
50 |
|
520 |
s042372 |
51 |
/// number of attribute items in vector
|
518 |
s042372 |
52 |
size_t size() const;
|
514 |
s042372 |
53 |
|
520 |
s042372 |
54 |
/// clear the vector
|
515 |
s042372 |
55 |
void clear();
|
|
|
56 |
|
520 |
s042372 |
57 |
/// clenup unused items from the vector, given by remap from associated container
|
515 |
s042372 |
58 |
void cleanup(const std::map<ITEMID, ITEMID>& map);
|
|
|
59 |
|
512 |
s042372 |
60 |
private:
|
|
|
61 |
std::vector<ITEM> items;
|
|
|
62 |
};
|
511 |
s042372 |
63 |
|
512 |
s042372 |
64 |
template<typename ITEM>
|
|
|
65 |
class VertexAttributeVector : public AttributeVector<ITEM, VertexID>
|
|
|
66 |
{
|
|
|
67 |
public:
|
519 |
s042372 |
68 |
VertexAttributeVector(size_t _size = 0, ITEM item = ITEM());
|
636 |
khor |
69 |
//VertexAttributeVector& operator=(const VertexAttributeVector&);
|
|
|
70 |
//VertexAttributeVector(const VertexAttributeVector& a);
|
|
|
71 |
//VertexAttributeVector& operator=(VertexAttributeVector&&);
|
|
|
72 |
VertexAttributeVector(VertexAttributeVector&& a) : AttributeVector<ITEM, VertexID>(std::move(a)){};
|
512 |
s042372 |
73 |
};
|
511 |
s042372 |
74 |
|
512 |
s042372 |
75 |
template<typename ITEM>
|
|
|
76 |
class FaceAttributeVector : public AttributeVector<ITEM, FaceID>
|
|
|
77 |
{
|
|
|
78 |
public:
|
519 |
s042372 |
79 |
FaceAttributeVector(size_t _size = 0, ITEM item = ITEM());
|
636 |
khor |
80 |
//FaceAttributeVector& operator=(const FaceAttributeVector&);
|
|
|
81 |
//FaceAttributeVector(const FaceAttributeVector&);
|
|
|
82 |
//FaceAttributeVector& operator=(FaceAttributeVector&&);
|
|
|
83 |
FaceAttributeVector(FaceAttributeVector&& a) : AttributeVector<ITEM, VertexID>(std::move(a)){};
|
512 |
s042372 |
84 |
};
|
511 |
s042372 |
85 |
|
512 |
s042372 |
86 |
template<typename ITEM>
|
|
|
87 |
class HalfEdgeAttributeVector : public AttributeVector<ITEM, HalfEdgeID>
|
|
|
88 |
{
|
|
|
89 |
public:
|
519 |
s042372 |
90 |
HalfEdgeAttributeVector(size_t _size = 0, ITEM item = ITEM());
|
636 |
khor |
91 |
//HalfEdgeAttributeVector& operator=(const HalfEdgeAttributeVector&);
|
|
|
92 |
//HalfEdgeAttributeVector(const HalfEdgeAttributeVector&);
|
|
|
93 |
//HalfEdgeAttributeVector& operator=(HalfEdgeAttributeVector&&);
|
|
|
94 |
HalfEdgeAttributeVector(HalfEdgeAttributeVector&& a) : AttributeVector<ITEM, VertexID>(std::move(a)){};
|
631 |
janba |
95 |
|
|
|
96 |
|
512 |
s042372 |
97 |
};
|
511 |
s042372 |
98 |
|
512 |
s042372 |
99 |
template<typename ITEM>
|
519 |
s042372 |
100 |
inline VertexAttributeVector<ITEM>::VertexAttributeVector(size_t _size, ITEM item) : AttributeVector<ITEM, VertexID>(_size, item){}
|
511 |
s042372 |
101 |
|
512 |
s042372 |
102 |
template<typename ITEM>
|
519 |
s042372 |
103 |
inline FaceAttributeVector<ITEM>::FaceAttributeVector(size_t _size, ITEM item) : AttributeVector<ITEM, FaceID>(_size, item){}
|
511 |
s042372 |
104 |
|
512 |
s042372 |
105 |
template<typename ITEM>
|
519 |
s042372 |
106 |
inline HalfEdgeAttributeVector<ITEM>::HalfEdgeAttributeVector(size_t _size, ITEM item) : AttributeVector<ITEM, HalfEdgeID>(_size, item){}
|
511 |
s042372 |
107 |
|
515 |
s042372 |
108 |
|
512 |
s042372 |
109 |
template<typename ITEM, typename ITEMID>
|
518 |
s042372 |
110 |
inline AttributeVector<ITEM, ITEMID>::AttributeVector(size_t _size, ITEM item) : items(_size, item){}
|
511 |
s042372 |
111 |
|
512 |
s042372 |
112 |
template<typename ITEM, typename ITEMID>
|
515 |
s042372 |
113 |
inline void AttributeVector<ITEM, ITEMID>::clear()
|
|
|
114 |
{ items.clear(); }
|
|
|
115 |
|
|
|
116 |
template<typename ITEM, typename ITEMID>
|
|
|
117 |
inline void AttributeVector<ITEM, ITEMID>::cleanup(const std::map<ITEMID, ITEMID>& remap)
|
|
|
118 |
{
|
|
|
119 |
std::vector<ITEM> new_items(remap.size());
|
526 |
jab |
120 |
for(typename std::map<ITEMID, ITEMID>::const_iterator it = remap.begin(); it != remap.end(); ++it){
|
518 |
s042372 |
121 |
assert(it->second.index < remap.size());
|
515 |
s042372 |
122 |
new_items[it->second.index] = items[it->first.index];
|
518 |
s042372 |
123 |
}
|
515 |
s042372 |
124 |
std::swap(items, new_items);
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
|
|
|
128 |
template<typename ITEM, typename ITEMID>
|
518 |
s042372 |
129 |
inline void AttributeVector<ITEM, ITEMID>::resize(size_t _size, ITEM item)
|
512 |
s042372 |
130 |
{ items.resize(_size, item); }
|
|
|
131 |
|
|
|
132 |
template<typename ITEM, typename ITEMID>
|
518 |
s042372 |
133 |
inline size_t AttributeVector<ITEM, ITEMID>::size() const
|
514 |
s042372 |
134 |
{ return items.size(); }
|
|
|
135 |
|
520 |
s042372 |
136 |
// just returning should be ok; manifold and attribs should always be in sync.
|
|
|
137 |
// const context means manifold and attribs should be const, hence in sync.
|
512 |
s042372 |
138 |
template<typename ITEM, typename ITEMID>
|
|
|
139 |
inline const ITEM& AttributeVector<ITEM, ITEMID>::get(ITEMID id) const
|
515 |
s042372 |
140 |
{
|
518 |
s042372 |
141 |
assert(id.index < items.size());
|
515 |
s042372 |
142 |
return items[id.index];
|
|
|
143 |
}
|
511 |
s042372 |
144 |
|
512 |
s042372 |
145 |
template<typename ITEM, typename ITEMID>
|
511 |
s042372 |
146 |
inline ITEM& AttributeVector<ITEM, ITEMID>::get(ITEMID id)
|
|
|
147 |
{
|
522 |
s042372 |
148 |
if(id.index >= items.size())
|
515 |
s042372 |
149 |
items.resize(id.index + 1);
|
|
|
150 |
return items[id.index];
|
511 |
s042372 |
151 |
}
|
512 |
s042372 |
152 |
|
|
|
153 |
template<typename ITEM, typename ITEMID>
|
|
|
154 |
inline const ITEM& AttributeVector<ITEM, ITEMID>::operator [](ITEMID id) const
|
515 |
s042372 |
155 |
{
|
518 |
s042372 |
156 |
assert(id.index < items.size());
|
515 |
s042372 |
157 |
return items[id.index];
|
|
|
158 |
}
|
511 |
s042372 |
159 |
|
512 |
s042372 |
160 |
template<typename ITEM, typename ITEMID>
|
511 |
s042372 |
161 |
inline ITEM& AttributeVector<ITEM, ITEMID>::operator [](ITEMID id)
|
|
|
162 |
{
|
522 |
s042372 |
163 |
if(id.index >= items.size())
|
515 |
s042372 |
164 |
items.resize(id.index + 1);
|
|
|
165 |
return items[id.index];
|
511 |
s042372 |
166 |
}
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
#endif
|