Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahdhn committed Jan 9, 2025
1 parent 73d6780 commit 439e87c
Show file tree
Hide file tree
Showing 5 changed files with 357 additions and 19 deletions.
25 changes: 23 additions & 2 deletions apps/SurfaceTracking/collapser.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <Eigen/Dense>

#include "rxmesh/cavity_manager.cuh"
#include "rxmesh/cavity_manager2.cuh"
#include "rxmesh/query.cuh"

#include "rxmesh/geometry_util.cuh"
Expand All @@ -27,7 +27,7 @@ edge_collapse(rxmesh::Context context,
using namespace rxmesh;
auto block = cooperative_groups::this_thread_block();
ShmemAllocator shrd_alloc;
CavityManager<blockThreads, CavityOp::EV> cavity(
CavityManager2<blockThreads, CavityOp::EV> cavity(
block, context, shrd_alloc, true);

const uint32_t pid = cavity.patch_id();
Expand Down Expand Up @@ -194,6 +194,18 @@ edge_collapse(rxmesh::Context context,
const vec3<T> p0(position(v0, 0), position(v0, 1), position(v0, 2));
const vec3<T> p1(position(v1, 0), position(v1, 1), position(v1, 2));

assert(!isnan(new_p[0]));
assert(!isnan(new_p[1]));
assert(!isnan(new_p[2]));

assert(!isnan(p0[0]));
assert(!isnan(p0[1]));
assert(!isnan(p0[2]));

assert(!isnan(p1[0]));
assert(!isnan(p1[1]));
assert(!isnan(p1[2]));

// check if the new triangles will be bad i.e., will have normal
// inversion, will have tiny area, will have bad angles
bool is_bad = false;
Expand All @@ -213,6 +225,15 @@ edge_collapse(rxmesh::Context context,
const vec3<T> pj(
position(vj, 0), position(vj, 1), position(vj, 2));

assert(!isnan(pi[0]));
assert(!isnan(pi[1]));
assert(!isnan(pi[2]));

assert(!isnan(pj[0]));
assert(!isnan(pj[1]));
assert(!isnan(pj[2]));


// the new triangle will be pi-pj-new_p

const vec3<T> n_new = tri_normal(pi, pj, new_p);
Expand Down
31 changes: 26 additions & 5 deletions apps/SurfaceTracking/flipper.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <Eigen/Dense>

#include "rxmesh/cavity_manager.cuh"
#include "rxmesh/cavity_manager2.cuh"
#include "rxmesh/query.cuh"

#include "link_condition.cuh"
Expand All @@ -13,7 +13,8 @@ __global__ static void // __launch_bounds__(blockThreads)
classify_vertex(const rxmesh::Context context,
const rxmesh::VertexAttribute<T> position,
const rxmesh::VertexAttribute<int8_t> is_vertex_bd,
rxmesh::VertexAttribute<int8_t> vertex_rank)
rxmesh::VertexAttribute<int8_t> vertex_rank,
int* d_buffer)
{
// Compute rank of the quadric metric tensor at a vertex Determine the rank
// of the primary space at the given vertex(see Jiao07)
Expand Down Expand Up @@ -47,12 +48,32 @@ classify_vertex(const rxmesh::Context context,

const VertexHandle rh = iter[i];

assert(vh != qh);
assert(rh != qh);
assert(vh != rh);

const vec3<T> r(position(rh, 0), position(rh, 1), position(rh, 2));

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

assert(glm::length(c) > std::numeric_limits<T>::min());
// assert(glm::length(c) > std::numeric_limits<T>::min());

if (!(glm::length(c) > std::numeric_limits<T>::min())) {
printf(
"\n p = %u, q=(%f, %f, %f), v=(%f, %f, %f), r=(%f, %f, %f)",
vh.patch_id(),
q[0],
q[1],
q[2],
v[0],
v[1],
v[2],
r[0],
r[1],
r[2]);
d_buffer[0] = 1;
}

const vec3<T> n = glm::normalize(c);

Expand All @@ -71,7 +92,7 @@ classify_vertex(const rxmesh::Context context,

// eigen decomp
Eigen::SelfAdjointEigenSolver<Eigen::Matrix<T, 3, 3>> eigen_solver(A);
assert(eigen_solver.info() == Eigen::Success);
// assert(eigen_solver.info() == Eigen::Success);
Eigen::Matrix<T, 3, 1> eigenvalues = eigen_solver.eigenvalues();

int8_t rank = 0;
Expand Down Expand Up @@ -111,7 +132,7 @@ edge_flip(rxmesh::Context context,

ShmemAllocator shrd_alloc;

CavityManager<blockThreads, CavityOp::E> cavity(
CavityManager2<blockThreads, CavityOp::E> cavity(
block, context, shrd_alloc, false, false);


Expand Down
12 changes: 11 additions & 1 deletion apps/SurfaceTracking/smoother.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <Eigen/Dense>

#include "rxmesh/cavity_manager.cuh"
#include "rxmesh/query.cuh"


Expand Down Expand Up @@ -46,6 +45,10 @@ null_space_smooth_vertex(const rxmesh::Context context,

const VertexHandle rh = iter[i];

assert(vh != qh);
assert(rh != qh);
assert(vh != rh);

const vec3<T> r(current_position(rh, 0),
current_position(rh, 1),
current_position(rh, 2));
Expand Down Expand Up @@ -79,6 +82,9 @@ null_space_smooth_vertex(const rxmesh::Context context,
eigenvalues[1] = eigen_solver.eigenvalues().real()[1];
eigenvalues[2] = eigen_solver.eigenvalues().real()[2];

assert(eigenvalues[0] <= eigenvalues[1]);
assert(eigenvalues[1] <= eigenvalues[2]);

// compute basis for null space
Eigen::Matrix<T, 3, 3> tt;
tt << 0, 0, 0, 0, 0, 0, 0, 0, 0;
Expand Down Expand Up @@ -145,8 +151,12 @@ null_space_smooth_vertex(const rxmesh::Context context,
p = r;
}


assert(sum_areas > std::numeric_limits<T>::min());

t = null_space_projection * t;
t /= sum_areas;


new_position(vh, 0) = v[0] + t(0);
new_position(vh, 1) = v[1] + t(1);
Expand Down
33 changes: 30 additions & 3 deletions apps/SurfaceTracking/splitter.cuh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "rxmesh/cavity_manager.cuh"
#include "rxmesh/cavity_manager2.cuh"
#include "rxmesh/query.cuh"

enum class EdgeSplitPredicate
Expand All @@ -14,7 +14,7 @@ enum class EdgeSplitPredicate
template <typename T, uint32_t blockThreads>
__global__ static void //__launch_bounds__(blockThreads)
split_edges(rxmesh::Context context,
const rxmesh::VertexAttribute<T> position,
rxmesh::VertexAttribute<T> position,
rxmesh::EdgeAttribute<EdgeStatus> edge_status,
rxmesh::VertexAttribute<int8_t> is_vertex_bd,
rxmesh::EdgeAttribute<int8_t> is_edge_bd,
Expand All @@ -30,7 +30,7 @@ split_edges(rxmesh::Context context,

ShmemAllocator shrd_alloc;

CavityManager<blockThreads, CavityOp::E> cavity(
CavityManager2<blockThreads, CavityOp::E> cavity(
block, context, shrd_alloc, true, false);


Expand Down Expand Up @@ -95,6 +95,17 @@ split_edges(rxmesh::Context context,
const vec3<T> vd(
position(dh, 0), position(dh, 1), position(dh, 2));

bool is_zero = (va[0] == 0 && va[1] == 0 && va[2] == 0 &&
vb[0] == 0 && vb[1] == 0 && vb[2] == 0);
if (is_zero) {
printf("\n ah.is_valid()= %d, bh.is_valid()= %d",
ah.is_valid(),
bh.is_valid());
}


assert(!is_zero);


// test the predicate
if (split_it) {
Expand Down Expand Up @@ -200,13 +211,29 @@ split_edges(rxmesh::Context context,

if (new_v.is_valid()) {

assert(!(position(v0, 0) == 0 && position(v0, 1) == 0 &&
position(v0, 2) == 0 && position(v1, 0) == 0 &&
position(v1, 1) == 0 && position(v1, 2) == 0));

position(new_v, 0) =
T(0.5) * (position(v0, 0) + position(v1, 0));
position(new_v, 1) =
T(0.5) * (position(v0, 1) + position(v1, 1));
position(new_v, 2) =
T(0.5) * (position(v0, 2) + position(v1, 2));

assert(!isnan(position(v0, 0)));
assert(!isnan(position(v0, 1)));
assert(!isnan(position(v0, 2)));

assert(!isnan(position(v1, 0)));
assert(!isnan(position(v1, 1)));
assert(!isnan(position(v1, 2)));

assert(!isnan(position(new_v, 0)));
assert(!isnan(position(new_v, 1)));
assert(!isnan(position(new_v, 2)));

DEdgeHandle e0 =
cavity.add_edge(new_v, cavity.get_cavity_vertex(c, 0));
const DEdgeHandle e_init = e0;
Expand Down
Loading

0 comments on commit 439e87c

Please sign in to comment.