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