SimpleFastOpenAtomicVisualiser
Loading...
Searching...
No Matches
trixel.h
Go to the documentation of this file.
1#ifndef TRIXEL_H
2#define TRIXEL_H
3
4#include <triangle.h>
5
10const uint32_t NULL_ID = std::numeric_limits<uint32_t>::max();
11
17template <class T>
18class Trixel: public Triangle<T>
19{
20public:
21
27 : Triangle<T>(), ID(""), parent(NULL_ID), children(std::vector<uint32_t>(4,NULL_ID))
28 {};
29
41 (
42 std::string id,
43 vec3<T> x,
44 vec3<T> y,
45 vec3<T> z,
46 uint32_t parent = NULL_ID,
47 std::vector<uint32_t> children = std::vector<uint32_t>(4,NULL_ID)
48 )
49 : Triangle<T>(x, y, z), ID(id), parent(parent), children(children)
50 {};
51
57 std::string getID() const
58 {
59 return ID;
60 }
61
68 {
69 parent = p;
70 }
71
77 void setChildren(std::vector<uint32_t> & c)
78 {
79 if (c.size() == children.size())
80 {
81 for (uint32_t i = 0; i < c.size(); i++)
82 {
83 children[i] = c[i];
84 }
85 }
86 }
87
93 const std::vector<uint32_t> & getChildren() const
94 {
95 return children;
96 }
97
98private:
99
100 std::string ID;
101 uint32_t parent;
102 std::vector<uint32_t> children;
103
104};
105
114template <class T>
115std::array<Trixel<T>, 4> subdivideTrixel(Trixel<T> & trix)
116{
117 std::array<vec3<T>, 3> v = trix.getVertices();
118 vec3<T> w0 = vec3<T> (0.0);
119 vec3<T> w1 = vec3<T> (0.0);
120 vec3<T> w2 = vec3<T> (0.0);
121
122 w0[0] = v[2][0]+v[1][0];
123 w0[1] = v[2][1]+v[1][1];
124 w0[2] = v[2][2]+v[1][2];
125
126 w1[0] = v[2][0]+v[0][0];
127 w1[1] = v[2][1]+v[0][1];
128 w1[2] = v[2][2]+v[0][2];
129
130 w2[0] = v[1][0]+v[0][0];
131 w2[1] = v[1][1]+v[0][1];
132 w2[2] = v[1][2]+v[0][2];
133
134 T n0 = std::sqrt(w0[0]*w0[0]+w0[1]*w0[1]+w0[2]*w0[2]);
135 T n1 = std::sqrt(w1[0]*w1[0]+w1[1]*w1[1]+w1[2]*w1[2]);
136 T n2 = std::sqrt(w2[0]*w2[0]+w2[1]*w2[1]+w2[2]*w2[2]);
137
138 w0[0] = w0[0]/n0;
139 w0[1] = w0[1]/n0;
140 w0[2] = w0[2]/n0;
141
142 w1[0] = w1[0]/n1;
143 w1[1] = w1[1]/n1;
144 w1[2] = w1[2]/n1;
145
146 w2[0] = w2[0]/n2;
147 w2[1] = w2[1]/n2;
148 w2[2] = w2[2]/n2;
149
150 vec3<T> v0 {v[0][0],v[0][1],v[0][2]};
151 vec3<T> v1 {v[1][0],v[1][1],v[1][2]};
152 vec3<T> v2 {v[2][0],v[2][1],v[2][2]};
153
154 std::string id = trix.getID();
155
156 Trixel<T> T1(id+"0",v0,vec3<T> (w2),vec3<T> (w1));
157 Trixel<T> T2(id+"1",v1,vec3<T> (w0),vec3<T> (w2));
158 Trixel<T> T3(id+"2",v2,vec3<T> (w1),vec3<T> (w0));
159 Trixel<T> T4(id+"3",vec3<T> (w0),vec3<T> (w1),vec3<T> (w2));
160 std::array<Trixel<T>, 4> u {T1,T2,T3,T4};
161 return u;
162}
163
164#endif /* TRIXEL_H */
A 3D triangle.
Definition triangle.h:24
vec3< T > z
Definition triangle.h:95
vec3< T > y
Definition triangle.h:94
vec3< T > x
Definition triangle.h:93
A triangular pixel of a hierarchical triangular mesh.
Definition trixel.h:19
Trixel()
Construct a new empty Trixel.
Definition trixel.h:26
void setParent(uint32_t &p)
Set the Trixel's parent Trixel.
Definition trixel.h:67
const std::vector< uint32_t > & getChildren() const
Get the Trixel's children.
Definition trixel.h:93
Trixel(std::string id, vec3< T > x, vec3< T > y, vec3< T > z, uint32_t parent=NULL_ID, std::vector< uint32_t > children=std::vector< uint32_t >(4, NULL_ID))
Construct a new Trixel.
Definition trixel.h:41
std::string getID() const
Return the Trixel's id.
Definition trixel.h:57
void setChildren(std::vector< uint32_t > &c)
Set the Trixel's children.
Definition trixel.h:77
glm::vec< L, float, glm::qualifier::highp > vec
Definition commandLine.h:214
const uint32_t NULL_ID
The null Trixel identity.
Definition trixel.h:10
std::array< Trixel< T >, 4 > subdivideTrixel(Trixel< T > &trix)
Subdivide a Trixel.
Definition trixel.h:115