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 |
|
512 |
s042372 |
43 |
private:
|
|
|
44 |
std::vector<ITEM> items;
|
|
|
45 |
};
|
511 |
s042372 |
46 |
|
512 |
s042372 |
47 |
template<typename ITEM>
|
|
|
48 |
class VertexAttributeVector : public AttributeVector<ITEM, VertexID>
|
|
|
49 |
{
|
|
|
50 |
public:
|
|
|
51 |
VertexAttributeVector(const Manifold& m, ITEM item = ITEM());
|
|
|
52 |
};
|
511 |
s042372 |
53 |
|
512 |
s042372 |
54 |
template<typename ITEM>
|
|
|
55 |
class FaceAttributeVector : public AttributeVector<ITEM, FaceID>
|
|
|
56 |
{
|
|
|
57 |
public:
|
|
|
58 |
FaceAttributeVector(const Manifold& m, ITEM item = ITEM());
|
|
|
59 |
};
|
511 |
s042372 |
60 |
|
512 |
s042372 |
61 |
template<typename ITEM>
|
|
|
62 |
class HalfEdgeAttributeVector : public AttributeVector<ITEM, HalfEdgeID>
|
|
|
63 |
{
|
|
|
64 |
public:
|
|
|
65 |
HalfEdgeAttributeVector(const Manifold& m, ITEM item = ITEM());
|
|
|
66 |
};
|
511 |
s042372 |
67 |
|
512 |
s042372 |
68 |
template<typename ITEM>
|
|
|
69 |
inline VertexAttributeVector<ITEM>::VertexAttributeVector(const Manifold& m, ITEM item) : AttributeVector<ITEM, VertexID>(m.no_vertices(false), item){}
|
511 |
s042372 |
70 |
|
512 |
s042372 |
71 |
template<typename ITEM>
|
|
|
72 |
inline FaceAttributeVector<ITEM>::FaceAttributeVector(const Manifold& m, ITEM item) : AttributeVector<ITEM, FaceID>(m.no_faces(false), item){}
|
511 |
s042372 |
73 |
|
512 |
s042372 |
74 |
template<typename ITEM>
|
|
|
75 |
inline HalfEdgeAttributeVector<ITEM>::HalfEdgeAttributeVector(const Manifold& m, ITEM item) : AttributeVector<ITEM, HalfEdgeID>(m.no_halfedges(false), item){}
|
511 |
s042372 |
76 |
|
512 |
s042372 |
77 |
template<typename ITEM, typename ITEMID>
|
|
|
78 |
inline AttributeVector<ITEM, ITEMID>::AttributeVector(IndexType _size, ITEM item) : items(_size, item){}
|
511 |
s042372 |
79 |
|
512 |
s042372 |
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>
|
|
|
89 |
inline const ITEM& AttributeVector<ITEM, ITEMID>::get(ITEMID id) const
|
511 |
s042372 |
90 |
{ return items[id.idx()]; }
|
|
|
91 |
|
512 |
s042372 |
92 |
template<typename ITEM, typename ITEMID>
|
511 |
s042372 |
93 |
inline ITEM& AttributeVector<ITEM, ITEMID>::get(ITEMID id)
|
|
|
94 |
{
|
512 |
s042372 |
95 |
if(items.size() < id.idx())
|
|
|
96 |
items.resize(id.idx() + 1);
|
|
|
97 |
return items[id.idx()];
|
511 |
s042372 |
98 |
}
|
512 |
s042372 |
99 |
|
|
|
100 |
template<typename ITEM, typename ITEMID>
|
|
|
101 |
inline const ITEM& AttributeVector<ITEM, ITEMID>::operator [](ITEMID id) const
|
511 |
s042372 |
102 |
{ return items[id.idx()]; }
|
|
|
103 |
|
512 |
s042372 |
104 |
template<typename ITEM, typename ITEMID>
|
511 |
s042372 |
105 |
inline ITEM& AttributeVector<ITEM, ITEMID>::operator [](ITEMID id)
|
|
|
106 |
{
|
512 |
s042372 |
107 |
if(items.size() < id.idx())
|
|
|
108 |
items.resize(id.idx() + 1);
|
|
|
109 |
return items[id.idx()];
|
511 |
s042372 |
110 |
}
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
#endif
|