Skip to content

Commit

Permalink
simplify reading attributes to glm
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahdhn committed Oct 9, 2024
1 parent 47f7d56 commit b28f3c2
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 84 deletions.
8 changes: 4 additions & 4 deletions apps/ARAP/arap.cu
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ __global__ static void calc_edge_weights_mat(
return;
}

const vec3<T> p(coords(p_id, 0), coords(p_id, 1), coords(p_id, 2));
const vec3<T> r(coords(r_id, 0), coords(r_id, 1), coords(r_id, 2));
const vec3<T> q(coords(q_id, 0), coords(q_id, 1), coords(q_id, 2));
const vec3<T> s(coords(s_id, 0), coords(s_id, 1), coords(s_id, 2));
const vec3<T> p = coords.to_glm<3>(p_id);
const vec3<T> r = coords.to_glm<3>(r_id);
const vec3<T> q = coords.to_glm<3>(q_id);
const vec3<T> s = coords.to_glm<3>(s_id);

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

Expand Down
8 changes: 4 additions & 4 deletions apps/Delaunay/delaunay_rxmesh.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ __global__ static void __launch_bounds__(blockThreads)

constexpr T PII = 3.14159265358979323f;

const vec3 V0(coords(v0, 0), coords(v0, 1), coords(v0, 2));
const vec3 V1(coords(v1, 0), coords(v1, 1), coords(v1, 2));
const vec3 V2(coords(v2, 0), coords(v2, 1), coords(v2, 2));
const vec3 V3(coords(v3, 0), coords(v3, 1), coords(v3, 2));
const vec3 V0 = coords.to_glm<3>(v0);
const vec3 V1 = coords.to_glm<3>(v1);
const vec3 V2 = coords.to_glm<3>(v2);
const vec3 V3 = coords.to_glm<3>(v3);

// find the angle between S, M, Q vertices (i.e., angle at M)
auto angle_between_three_vertices = [](const vec3& S,
Expand Down
14 changes: 7 additions & 7 deletions apps/Delaunay/mcf_rxmesh_kernel.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ edge_cotan_weight(const rxmesh::VertexHandle& p_id,
// q and s composes the diamond around p-r
using namespace rxmesh;

const vec3<T> p(X(p_id, 0), X(p_id, 1), X(p_id, 2));
const vec3<T> r(X(r_id, 0), X(r_id, 1), X(r_id, 2));
const vec3<T> q(X(q_id, 0), X(q_id, 1), X(q_id, 2));
const vec3<T> s(X(s_id, 0), X(s_id, 1), X(s_id, 2));
const vec3<T> p = X.to_glm<3>(p_id);
const vec3<T> r = X.to_glm<3>(r_id);
const vec3<T> q = X.to_glm<3>(q_id);
const vec3<T> s = X.to_glm<3>(s_id);

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

const vec3<T> p(X(p_id, 0), X(p_id, 1), X(p_id, 2));
const vec3<T> q(X(q_id, 0), X(q_id, 1), X(q_id, 2));
const vec3<T> r(X(r_id, 0), X(r_id, 1), X(r_id, 2));
const vec3<T> p = X.to_glm<3>(p_id);
const vec3<T> q = X.to_glm<3>(q_id);
const vec3<T> r = X.to_glm<3>(r_id);

return partial_voronoi_area(p, q, r);
}
Expand Down
6 changes: 3 additions & 3 deletions apps/GaussianCurvature/gaussian_curvature_kernel.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ __global__ static void compute_gaussian_curvature(

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

// the three edges length
vec3<T> l(glm::distance2(c0, c1),
Expand Down
7 changes: 4 additions & 3 deletions apps/Geodesic/geodesic_kernel.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ __device__ __inline__ T update_step(
const T infinity_val)
{
using namespace rxmesh;
const vec3<T> v0(coords(v0_id, 0), coords(v0_id, 1), coords(v0_id, 2));
const vec3<T> v1(coords(v1_id, 0), coords(v1_id, 1), coords(v1_id, 2));
const vec3<T> v2(coords(v2_id, 0), coords(v2_id, 1), coords(v2_id, 2));
const vec3<T> v0 = coords.to_glm<3>(v0_id);
const vec3<T> v1 = coords.to_glm<3>(v1_id);
const vec3<T> v2 = coords.to_glm<3>(v2_id);

const vec3<T> x0 = v1 - v0;
const vec3<T> x1 = v2 - v0;

Expand Down
14 changes: 7 additions & 7 deletions apps/MCF/mcf_kernels.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ edge_cotan_weight(const rxmesh::VertexHandle& p_id,
// q and s composes the diamond around p-r
using namespace rxmesh;

const vec3<T> p(X(p_id, 0), X(p_id, 1), X(p_id, 2));
const vec3<T> r(X(r_id, 0), X(r_id, 1), X(r_id, 2));
const vec3<T> q(X(q_id, 0), X(q_id, 1), X(q_id, 2));
const vec3<T> s(X(s_id, 0), X(s_id, 1), X(s_id, 2));
const vec3<T> p = X.to_glm<3>(p_id);
const vec3<T> r = X.to_glm<3>(r_id);
const vec3<T> q = X.to_glm<3>(q_id);
const vec3<T> s = X.to_glm<3>(s_id);

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

const vec3<T> p(X(p_id, 0), X(p_id, 1), X(p_id, 2));
const vec3<T> q(X(q_id, 0), X(q_id, 1), X(q_id, 2));
const vec3<T> r(X(r_id, 0), X(r_id, 1), X(r_id, 2));
const vec3<T> p = X.to_glm<3>(p_id);
const vec3<T> q = X.to_glm<3>(q_id);
const vec3<T> r = X.to_glm<3>(r_id);

return partial_voronoi_area(p, q, r);
}
Expand Down
25 changes: 12 additions & 13 deletions apps/Remesh/collapse.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ __global__ static void __launch_bounds__(blockThreads)
v2 == v3) {
return;
}
const vec3<T> p0(coords(v0, 0), coords(v0, 1), coords(v0, 2));
const vec3<T> p1(coords(v1, 0), coords(v1, 1), coords(v1, 2));
const vec3<T> p0 = coords.to_glm<3>(v0);
const vec3<T> p1 = coords.to_glm<3>(v1);
const T edge_len_sq = glm::distance2(p0, p1);

if (edge_len_sq < low_edge_len_sq) {
Expand Down Expand Up @@ -124,8 +124,8 @@ __global__ static void __launch_bounds__(blockThreads)

cavity.get_vertices(src, v0, v1);

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

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

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

const vec3<T> vp(
coords(vvv, 0), coords(vvv, 1), coords(vvv, 2));
const vec3<T> vp = coords.to_glm<3>(vvv);

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

Expand Down Expand Up @@ -300,9 +299,10 @@ __global__ static void __launch_bounds__(blockThreads)
return;
}

const vec3<T> p0(coords(v0, 0), coords(v0, 1), coords(v0, 2));
const vec3<T> p1(coords(v1, 0), coords(v1, 1), coords(v1, 2));
const T edge_len_sq = glm::distance2(p0, p1);
const vec3<T> p0 = coords.to_glm<3>(v0);
const vec3<T> p1 = coords.to_glm<3>(v1);

const T edge_len_sq = glm::distance2(p0, p1);

if (edge_len_sq < low_edge_len_sq) {

Expand Down Expand Up @@ -391,8 +391,8 @@ __global__ static void __launch_bounds__(blockThreads)

cavity.get_vertices(src, v0, v1);

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

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

const vec3<T> vp(
coords(vvv, 0), coords(vvv, 1), coords(vvv, 2));
const vec3<T> vp = coords.to_glm<3>(vvv);

const T edge_len_sq = glm::distance2(vp, new_p);
if (edge_len_sq > high_edge_len_sq) {
Expand Down
7 changes: 4 additions & 3 deletions apps/Remesh/smoothing.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ __global__ static void __launch_bounds__(blockThreads)
return;
}

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

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

// this is the last vertex in the one-ring (before r_id)
VertexHandle q_id = iter.back();
vec3<T> q(coords(q_id, 0), coords(q_id, 1), coords(q_id, 2));

vec3<T> q = coords.to_glm<3>(q_id);

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

const vec3<T> r(coords(r_id, 0), coords(r_id, 1), coords(r_id, 2));
const vec3<T> r = coords.to_glm<3>(r_id);

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

Expand Down
21 changes: 10 additions & 11 deletions apps/Remesh/split.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ __global__ static void edge_split(rxmesh::Context context,
edge_status(eh) = SKIP;
return;
}
const vec3<T> pa(coords(va, 0), coords(va, 1), coords(va, 2));
const vec3<T> pb(coords(vb, 0), coords(vb, 1), coords(vb, 2));
const vec3<T> pa = coords.to_glm<3>(va);
const vec3<T> pb = coords.to_glm<3>(vb);

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

if (edge_len > high_edge_len_sq) {

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

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

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

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

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

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

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

const vec3<T> p(coords(v, 0), coords(v, 1), coords(v, 2));
const vec3<T> p = coords.to_glm<3>(v);

assert(glm::distance2(p_new, p) >= low_edge_len_sq);
}
Expand Down Expand Up @@ -241,19 +240,19 @@ inline void split_long_edges(rxmesh::RXMeshDynamic& rx,
high_edge_len_sq,
low_edge_len_sq,
d_buffer);

timers.stop("Split");

timers.start("SplitCleanup");
rx.cleanup();
rx.cleanup();
timers.stop("SplitCleanup");

timers.start("SplitSlice");
rx.slice_patches(*coords, *edge_status);
rx.slice_patches(*coords, *edge_status);
timers.stop("SplitSlice");

timers.start("SplitCleanup");
rx.cleanup();
rx.cleanup();
timers.stop("SplitCleanup");

bool show = false;
Expand Down
4 changes: 2 additions & 2 deletions apps/Remesh/util.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ __global__ static void stats_kernel(const rxmesh::Context context,
ShmemAllocator shrd_alloc;

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

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

Expand Down
8 changes: 4 additions & 4 deletions apps/SCP/scp.cu
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ __global__ static void conformal_energy(const Context context,
assert(p.is_valid() && q.is_valid());
assert(o0.is_valid() || o1.is_valid());

const vec3<float> P(coord(p, 0), coord(p, 1), coord(p, 2));
const vec3<float> Q(coord(q, 0), coord(q, 1), coord(q, 2));
const vec3<float> P = coord.to_glm<3>(p);
const vec3<float> Q = coord.to_glm<3>(q);

float coef = 0;

if (o0.is_valid()) {
const vec3<float> O0(coord(o0, 0), coord(o0, 1), coord(o0, 2));
const vec3<float> O0 = coord.to_glm<3>(o0);
coef += weight(P, Q, O0);
}
if (o1.is_valid()) {
const vec3<float> O1(coord(o1, 0), coord(o1, 1), coord(o1, 2));
const vec3<float> O1 = coord.to_glm<3>(o1);
coef += weight(P, Q, O1);
}

Expand Down
12 changes: 6 additions & 6 deletions apps/SECHistogram/sec_kernels.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ __global__ static void sec(rxmesh::Context context,
const VertexHandle v0 = iter[0];
const VertexHandle v1 = iter[1];

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

T len2 = logf(glm::distance2(p0, p1));

Expand Down Expand Up @@ -170,8 +170,8 @@ __global__ static void compute_min_max_cost(
const VertexHandle v0 = iter[0];
const VertexHandle v1 = iter[1];

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

T len2 = logf(glm::distance2(p0, p1));

Expand All @@ -198,8 +198,8 @@ __global__ static void populate_histogram(
const VertexHandle v0 = iter[0];
const VertexHandle v1 = iter[1];

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

T len2 = logf(glm::distance2(p0, p1));

Expand Down
2 changes: 1 addition & 1 deletion apps/VertexNormal/vertex_normal.cu
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void vertex_normal_rxmesh(rxmesh::RXMeshStatic& rx,
// Verify
v_normals->move(rxmesh::DEVICE, rxmesh::HOST);

rx.for_each_vertex(HOST, [&](const VertexHandle& vh) {
rx.for_each_vertex(HOST, [&](const VertexHandle& vh) {
uint32_t v_id = rx.map_to_global(vh);

for (uint32_t i = 0; i < 3; ++i) {
Expand Down
6 changes: 3 additions & 3 deletions apps/VertexNormal/vertex_normal_kernel.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ __global__ static void compute_vertex_normal(const rxmesh::Context context,
using namespace rxmesh;
auto vn_lambda = [&](FaceHandle face_id, VertexIterator& fv) {
// get the face's three vertices coordinates
vec3<T> c0(coords(fv[0], 0), coords(fv[0], 1), coords(fv[0], 2));
vec3<T> c1(coords(fv[1], 0), coords(fv[1], 1), coords(fv[1], 2));
vec3<T> c2(coords(fv[2], 0), coords(fv[2], 1), coords(fv[2], 2));
vec3<T> c0 = coords.to_glm<3>(fv[0]);
vec3<T> c1 = coords.to_glm<3>(fv[1]);
vec3<T> c2 = coords.to_glm<3>(fv[2]);

// compute the face normal
vec3<T> n = cross(c1 - c0, c2 - c0);
Expand Down
8 changes: 4 additions & 4 deletions apps/XPBD/xpbd.cu
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ void __global__ init_edges(const Context context,
auto v0 = iter[0];
auto v1 = iter[1];

const glm::fvec3 x0(x(v0, 0), x(v0, 1), x(v0, 2));
const glm::fvec3 x1(x(v1, 0), x(v1, 1), x(v1, 2));
const glm::fvec3 x0 = x.to_glm<3>(v0);
const glm::fvec3 x1 = x.to_glm<3>(v1);

rest_len(eh, 0) = glm::length(x0 - x1);
};
Expand Down Expand Up @@ -49,8 +49,8 @@ void __global__ solve_stretch(const Context context,
auto v0 = iter[0];
auto v1 = iter[1];

const glm::fvec3 x0(new_x(v0, 0), new_x(v0, 1), new_x(v0, 2));
const glm::fvec3 x1(new_x(v1, 0), new_x(v1, 1), new_x(v1, 2));
const glm::fvec3 x0 = new_x.to_glm<3>(v0);
const glm::fvec3 x1 = new_x.to_glm<3>(v1);

const float w1(invM(v0, 0)), w2(invM(v1, 0));

Expand Down
Loading

0 comments on commit b28f3c2

Please sign in to comment.