Skip to content

Commit b28f3c2

Browse files
committed
simplify reading attributes to glm
1 parent 47f7d56 commit b28f3c2

File tree

17 files changed

+106
-84
lines changed

17 files changed

+106
-84
lines changed

apps/ARAP/arap.cu

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ __global__ static void calc_edge_weights_mat(
3030
return;
3131
}
3232

33-
const vec3<T> p(coords(p_id, 0), coords(p_id, 1), coords(p_id, 2));
34-
const vec3<T> r(coords(r_id, 0), coords(r_id, 1), coords(r_id, 2));
35-
const vec3<T> q(coords(q_id, 0), coords(q_id, 1), coords(q_id, 2));
36-
const vec3<T> s(coords(s_id, 0), coords(s_id, 1), coords(s_id, 2));
33+
const vec3<T> p = coords.to_glm<3>(p_id);
34+
const vec3<T> r = coords.to_glm<3>(r_id);
35+
const vec3<T> q = coords.to_glm<3>(q_id);
36+
const vec3<T> s = coords.to_glm<3>(s_id);
3737

3838
// cotans[(v1, v2)] =np.dot(e1, e2) / np.linalg.norm(np.cross(e1, e2))
3939

apps/Delaunay/delaunay_rxmesh.cuh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ __global__ static void __launch_bounds__(blockThreads)
6767

6868
constexpr T PII = 3.14159265358979323f;
6969

70-
const vec3 V0(coords(v0, 0), coords(v0, 1), coords(v0, 2));
71-
const vec3 V1(coords(v1, 0), coords(v1, 1), coords(v1, 2));
72-
const vec3 V2(coords(v2, 0), coords(v2, 1), coords(v2, 2));
73-
const vec3 V3(coords(v3, 0), coords(v3, 1), coords(v3, 2));
70+
const vec3 V0 = coords.to_glm<3>(v0);
71+
const vec3 V1 = coords.to_glm<3>(v1);
72+
const vec3 V2 = coords.to_glm<3>(v2);
73+
const vec3 V3 = coords.to_glm<3>(v3);
7474

7575
// find the angle between S, M, Q vertices (i.e., angle at M)
7676
auto angle_between_three_vertices = [](const vec3& S,

apps/Delaunay/mcf_rxmesh_kernel.cuh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ edge_cotan_weight(const rxmesh::VertexHandle& p_id,
2020
// q and s composes the diamond around p-r
2121
using namespace rxmesh;
2222

23-
const vec3<T> p(X(p_id, 0), X(p_id, 1), X(p_id, 2));
24-
const vec3<T> r(X(r_id, 0), X(r_id, 1), X(r_id, 2));
25-
const vec3<T> q(X(q_id, 0), X(q_id, 1), X(q_id, 2));
26-
const vec3<T> s(X(s_id, 0), X(s_id, 1), X(s_id, 2));
23+
const vec3<T> p = X.to_glm<3>(p_id);
24+
const vec3<T> r = X.to_glm<3>(r_id);
25+
const vec3<T> q = X.to_glm<3>(q_id);
26+
const vec3<T> s = X.to_glm<3>(s_id);
2727

2828
return edge_cotan_weight(p, r, q, s);
2929
}
@@ -42,9 +42,9 @@ partial_voronoi_area(const rxmesh::VertexHandle& p_id, // center
4242
// the triangle p->q->r (oriented ccw)
4343
using namespace rxmesh;
4444

45-
const vec3<T> p(X(p_id, 0), X(p_id, 1), X(p_id, 2));
46-
const vec3<T> q(X(q_id, 0), X(q_id, 1), X(q_id, 2));
47-
const vec3<T> r(X(r_id, 0), X(r_id, 1), X(r_id, 2));
45+
const vec3<T> p = X.to_glm<3>(p_id);
46+
const vec3<T> q = X.to_glm<3>(q_id);
47+
const vec3<T> r = X.to_glm<3>(r_id);
4848

4949
return partial_voronoi_area(p, q, r);
5050
}

apps/GaussianCurvature/gaussian_curvature_kernel.cuh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ __global__ static void compute_gaussian_curvature(
1717

1818
auto gc_lambda = [&](FaceHandle face_id, VertexIterator& fv) {
1919
// get the face's three vertices coordinates
20-
vec3<T> c0(coords(fv[0], 0), coords(fv[0], 1), coords(fv[0], 2));
21-
vec3<T> c1(coords(fv[1], 0), coords(fv[1], 1), coords(fv[1], 2));
22-
vec3<T> c2(coords(fv[2], 0), coords(fv[2], 1), coords(fv[2], 2));
20+
const vec3<T> c0 = coords.to_glm<3>(fv[0]);
21+
const vec3<T> c1 = coords.to_glm<3>(fv[1]);
22+
const vec3<T> c2 = coords.to_glm<3>(fv[2]);
2323

2424
// the three edges length
2525
vec3<T> l(glm::distance2(c0, c1),

apps/Geodesic/geodesic_kernel.cuh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ __device__ __inline__ T update_step(
1818
const T infinity_val)
1919
{
2020
using namespace rxmesh;
21-
const vec3<T> v0(coords(v0_id, 0), coords(v0_id, 1), coords(v0_id, 2));
22-
const vec3<T> v1(coords(v1_id, 0), coords(v1_id, 1), coords(v1_id, 2));
23-
const vec3<T> v2(coords(v2_id, 0), coords(v2_id, 1), coords(v2_id, 2));
21+
const vec3<T> v0 = coords.to_glm<3>(v0_id);
22+
const vec3<T> v1 = coords.to_glm<3>(v1_id);
23+
const vec3<T> v2 = coords.to_glm<3>(v2_id);
24+
2425
const vec3<T> x0 = v1 - v0;
2526
const vec3<T> x1 = v2 - v0;
2627

apps/MCF/mcf_kernels.cuh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ edge_cotan_weight(const rxmesh::VertexHandle& p_id,
2020
// q and s composes the diamond around p-r
2121
using namespace rxmesh;
2222

23-
const vec3<T> p(X(p_id, 0), X(p_id, 1), X(p_id, 2));
24-
const vec3<T> r(X(r_id, 0), X(r_id, 1), X(r_id, 2));
25-
const vec3<T> q(X(q_id, 0), X(q_id, 1), X(q_id, 2));
26-
const vec3<T> s(X(s_id, 0), X(s_id, 1), X(s_id, 2));
23+
const vec3<T> p = X.to_glm<3>(p_id);
24+
const vec3<T> r = X.to_glm<3>(r_id);
25+
const vec3<T> q = X.to_glm<3>(q_id);
26+
const vec3<T> s = X.to_glm<3>(s_id);
2727

2828
return edge_cotan_weight(p, r, q, s);
2929
}
@@ -42,9 +42,9 @@ partial_voronoi_area(const rxmesh::VertexHandle& p_id, // center
4242
// the triangle p->q->r (oriented ccw)
4343
using namespace rxmesh;
4444

45-
const vec3<T> p(X(p_id, 0), X(p_id, 1), X(p_id, 2));
46-
const vec3<T> q(X(q_id, 0), X(q_id, 1), X(q_id, 2));
47-
const vec3<T> r(X(r_id, 0), X(r_id, 1), X(r_id, 2));
45+
const vec3<T> p = X.to_glm<3>(p_id);
46+
const vec3<T> q = X.to_glm<3>(q_id);
47+
const vec3<T> r = X.to_glm<3>(r_id);
4848

4949
return partial_voronoi_area(p, q, r);
5050
}

apps/Remesh/collapse.cuh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ __global__ static void __launch_bounds__(blockThreads)
7979
v2 == v3) {
8080
return;
8181
}
82-
const vec3<T> p0(coords(v0, 0), coords(v0, 1), coords(v0, 2));
83-
const vec3<T> p1(coords(v1, 0), coords(v1, 1), coords(v1, 2));
82+
const vec3<T> p0 = coords.to_glm<3>(v0);
83+
const vec3<T> p1 = coords.to_glm<3>(v1);
8484
const T edge_len_sq = glm::distance2(p0, p1);
8585

8686
if (edge_len_sq < low_edge_len_sq) {
@@ -124,8 +124,8 @@ __global__ static void __launch_bounds__(blockThreads)
124124

125125
cavity.get_vertices(src, v0, v1);
126126

127-
const vec3<T> p0(coords(v0, 0), coords(v0, 1), coords(v0, 2));
128-
const vec3<T> p1(coords(v1, 0), coords(v1, 1), coords(v1, 2));
127+
const vec3<T> p0 = coords.to_glm<3>(v0);
128+
const vec3<T> p1 = coords.to_glm<3>(v1);
129129

130130
const vec3<T> new_p((p0[0] + p1[0]) * T(0.5),
131131
(p0[1] + p1[1]) * T(0.5),
@@ -139,8 +139,7 @@ __global__ static void __launch_bounds__(blockThreads)
139139

140140
const VertexHandle vvv = cavity.get_cavity_vertex(c, i);
141141

142-
const vec3<T> vp(
143-
coords(vvv, 0), coords(vvv, 1), coords(vvv, 2));
142+
const vec3<T> vp = coords.to_glm<3>(vvv);
144143

145144
const T edge_len_sq = glm::distance2(vp, new_p);
146145

@@ -300,9 +299,10 @@ __global__ static void __launch_bounds__(blockThreads)
300299
return;
301300
}
302301

303-
const vec3<T> p0(coords(v0, 0), coords(v0, 1), coords(v0, 2));
304-
const vec3<T> p1(coords(v1, 0), coords(v1, 1), coords(v1, 2));
305-
const T edge_len_sq = glm::distance2(p0, p1);
302+
const vec3<T> p0 = coords.to_glm<3>(v0);
303+
const vec3<T> p1 = coords.to_glm<3>(v1);
304+
305+
const T edge_len_sq = glm::distance2(p0, p1);
306306

307307
if (edge_len_sq < low_edge_len_sq) {
308308

@@ -391,8 +391,8 @@ __global__ static void __launch_bounds__(blockThreads)
391391

392392
cavity.get_vertices(src, v0, v1);
393393

394-
const vec3<T> p0(coords(v0, 0), coords(v0, 1), coords(v0, 2));
395-
const vec3<T> p1(coords(v1, 0), coords(v1, 1), coords(v1, 2));
394+
const vec3<T> p0 = coords.to_glm<3>(v0);
395+
const vec3<T> p1 = coords.to_glm<3>(v1);
396396

397397
const vec3<T> new_p((p0[0] + p1[0]) * T(0.5),
398398
(p0[1] + p1[1]) * T(0.5),
@@ -404,8 +404,7 @@ __global__ static void __launch_bounds__(blockThreads)
404404
for (uint16_t i = 0; i < size; ++i) {
405405
const VertexHandle vvv = cavity.get_cavity_vertex(c, i);
406406

407-
const vec3<T> vp(
408-
coords(vvv, 0), coords(vvv, 1), coords(vvv, 2));
407+
const vec3<T> vp = coords.to_glm<3>(vvv);
409408

410409
const T edge_len_sq = glm::distance2(vp, new_p);
411410
if (edge_len_sq > high_edge_len_sq) {

apps/Remesh/smoothing.cuh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ __global__ static void __launch_bounds__(blockThreads)
2222
return;
2323
}
2424

25-
const vec3<T> v(coords(v_id, 0), coords(v_id, 1), coords(v_id, 2));
25+
const vec3<T> v = coords.to_glm<3>(v_id);
2626

2727
// compute both vertex normal and the new position
2828
// the new position is the average of the one-ring
@@ -33,7 +33,8 @@ __global__ static void __launch_bounds__(blockThreads)
3333

3434
// this is the last vertex in the one-ring (before r_id)
3535
VertexHandle q_id = iter.back();
36-
vec3<T> q(coords(q_id, 0), coords(q_id, 1), coords(q_id, 2));
36+
37+
vec3<T> q = coords.to_glm<3>(q_id);
3738

3839
vec3<T> new_v(0.0, 0.0, 0.0);
3940
vec3<T> v_normal(0.0, 0.0, 0.0);
@@ -44,7 +45,7 @@ __global__ static void __launch_bounds__(blockThreads)
4445
// the current one ring vertex
4546
const VertexHandle r_id = iter[i];
4647

47-
const vec3<T> r(coords(r_id, 0), coords(r_id, 1), coords(r_id, 2));
48+
const vec3<T> r = coords.to_glm<3>(r_id);
4849

4950
vec3<T> c = glm::cross(q - v, r - v);
5051

apps/Remesh/split.cuh

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ __global__ static void edge_split(rxmesh::Context context,
5959
edge_status(eh) = SKIP;
6060
return;
6161
}
62-
const vec3<T> pa(coords(va, 0), coords(va, 1), coords(va, 2));
63-
const vec3<T> pb(coords(vb, 0), coords(vb, 1), coords(vb, 2));
62+
const vec3<T> pa = coords.to_glm<3>(va);
63+
const vec3<T> pb = coords.to_glm<3>(vb);
6464

6565
const T edge_len = glm::distance2(pa, pb);
6666

6767
if (edge_len > high_edge_len_sq) {
6868

6969
vec3<T> p_new = (pa + pb) * T(0.5);
7070

71-
vec3<T> pc(coords(vc, 0), coords(vc, 1), coords(vc, 2));
72-
vec3<T> pd(coords(vd, 0), coords(vd, 1), coords(vd, 2));
71+
vec3<T> pc = coords.to_glm<3>(vc);
72+
vec3<T> pd = coords.to_glm<3>(vd);
7373

7474
T min_new_edge_len = std::numeric_limits<T>::max();
7575

@@ -124,14 +124,13 @@ __global__ static void edge_split(rxmesh::Context context,
124124

125125
#ifndef NDEBUG
126126
// sanity check: we don't introduce small edges
127-
const vec3<T> p_new(
128-
coords(new_v, 0), coords(new_v, 1), coords(new_v, 2));
127+
const vec3<T> p_new = coords.to_glm<3>(new_v);
129128

130129
for (int i = 0; i < 4; ++i) {
131130

132131
const VertexHandle v = cavity.get_cavity_vertex(c, i);
133132

134-
const vec3<T> p(coords(v, 0), coords(v, 1), coords(v, 2));
133+
const vec3<T> p = coords.to_glm<3>(v);
135134

136135
assert(glm::distance2(p_new, p) >= low_edge_len_sq);
137136
}
@@ -241,19 +240,19 @@ inline void split_long_edges(rxmesh::RXMeshDynamic& rx,
241240
high_edge_len_sq,
242241
low_edge_len_sq,
243242
d_buffer);
244-
243+
245244
timers.stop("Split");
246245

247246
timers.start("SplitCleanup");
248-
rx.cleanup();
247+
rx.cleanup();
249248
timers.stop("SplitCleanup");
250249

251250
timers.start("SplitSlice");
252-
rx.slice_patches(*coords, *edge_status);
251+
rx.slice_patches(*coords, *edge_status);
253252
timers.stop("SplitSlice");
254253

255254
timers.start("SplitCleanup");
256-
rx.cleanup();
255+
rx.cleanup();
257256
timers.stop("SplitCleanup");
258257

259258
bool show = false;

apps/Remesh/util.cuh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ __global__ static void stats_kernel(const rxmesh::Context context,
2929
ShmemAllocator shrd_alloc;
3030

3131
auto compute_edge_len = [&](const EdgeHandle eh, const VertexIterator& ev) {
32-
const vec3<T> v0(coords(ev[0], 0), coords(ev[0], 1), coords(ev[0], 2));
33-
const vec3<T> v1(coords(ev[1], 0), coords(ev[1], 1), coords(ev[1], 2));
32+
const vec3<T> v0 = coords.to_glm<3>(ev[0]);
33+
const vec3<T> v1 = coords.to_glm<3>(ev[1]);
3434

3535
T len = glm::distance(v0, v1);
3636

0 commit comments

Comments
 (0)