Skip to content

Commit 4e9ef8c

Browse files
committed
massive refactor and add TOG impl reference
1 parent 1bf4460 commit 4e9ef8c

File tree

15 files changed

+264
-210
lines changed

15 files changed

+264
-210
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Published in [ACM Transactions on Graphics (TOG)](https://dl.acm.org/doi/abs/10.
5252

5353
## 📝 Change History
5454

55+
- (2025.02.28) Added a [reference branch and a Docker image of our TOG paper](#-technical-materials).
5556
- (2025.2.26) Added Floating Point-Rounding Errors in ACCD in [hindsight](./articles/hindsight.md).
5657
- (2025.2.7) Updated the [trapped example](./examples/trapped.ipynb) [[Video]](https://drive.google.com/file/d/1Qek0e0qBNWPlBb1hSOZ6o_e2Cqf5rGst/view) with squishy balls.
5758
- (2025.1.8) Added a [domino example](./examples/domino.ipynb) [[Video]](https://drive.google.com/file/d/1N9y8eZrjSQhAUhKwiO9w8jW_T18zPnYf/view).
@@ -64,7 +65,6 @@ Published in [ACM Transactions on Graphics (TOG)](https://dl.acm.org/doi/abs/10.
6465
- (2024.12.18) Added a [hindsight](./articles/hindsight.md) noting that the tilt angle was not $30^\circ$, but rather $26.57^\circ$
6566
- (2024.12.16) Removed thrust dependencies to fix runtime errors for the driver version `560.94` [[Issue Link]](https://github.com/st-tech/ppf-contact-solver/issues/1)
6667

67-
6868
## 🎓 Technical Materials
6969

7070
- 🎥 Main video [[Video]](https://drive.google.com/file/d/1OzPbUoqddUYDvXMvRnUHH7kz0nZhmt7K/view?usp=drive_link)
@@ -75,6 +75,20 @@ Published in [ACM Transactions on Graphics (TOG)](https://dl.acm.org/doi/abs/10.
7575
- 🤖 Supplementary scripts [[Directory]](https://drive.google.com/drive/folders/13CO068xLkd6ZSxsqtJQdNadgMrbbfSug?usp=drive_link)
7676
- 🔍 Singular-value eigenanalysis [[Markdown]](./articles/eigensys.md)
7777

78+
#### 📌 Reference Implementation
79+
80+
The main branch is undergoing frequent updates and may introduce breaking 🚧 changes relative to the paper.
81+
✨ Although the latest version offers a superior experience, we have created a new branch, ```sigasia-2024```, to retain consistency with the paper.
82+
83+
- 🛠️ Only maintenance updates are planned for this branch.
84+
- 🚫 All algorithmic changes listed in this [[Markdown]](./articles/bug.md) are excluded from this branch.
85+
86+
- 📦 We also provide a pre-compiled Docker image: ```ghcr.io/st-tech/ppf-contact-solver-compiled-sigasia-2024:latest``` of this branch.
87+
88+
- 🌐 [Template Link for vast.ai](https://cloud.vast.ai/?ref_id=85288&creator_id=85288&name=ppf-contact-solver-sigasia-2024).
89+
90+
- 🌐 [Template Link for RunPods](https://runpod.io/console/deploy?template=ooqpniuixi&ref=bhy3csxy)
91+
7892
## ⚡️ Requirements
7993

8094
- 🔥 A modern NVIDIA GPU (Turing or newer)

src/args.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ pub struct Args {
165165
#[clap(long, default_value_t = 0.01)]
166166
pub ccd_reduction: f32,
167167

168+
// Name: Maximum Search Direction Velocity
169+
// Recommended Range: 5 m/s to 50 m/s
170+
// Description:
171+
// This parameter defines the maximum allowable search direction magnitude
172+
// during optimization processes. It helps in controlling the step size
173+
// and ensuring stability.
174+
#[clap(long, default_value_t = 10.0)]
175+
pub max_search_dir_vel: f32,
176+
168177
// Name: Epsilon for Eigenvalue Analysis
169178
// Recommended Range: 1e-3 to 1e-2
170179
// Description:

src/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ pub fn make_param(args: &Args) -> data::ParamSet {
346346
line_search_max_t: args.line_search_max_t,
347347
ccd_tol: args.contact_ghat,
348348
ccd_reduction: args.ccd_reduction,
349+
max_search_dir_vel: args.max_search_dir_vel,
349350
eiganalysis_eps: args.eiganalysis_eps,
350351
friction: args.friction,
351352
friction_eps: args.friction_eps,

src/bvh.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,34 @@ fn subdivide(mut obj: Vec<(Aabb, usize)>, node: &mut Vec<Node>) -> Node {
8989
let mean = compute_mean(obj.iter().map(|(aabb, _)| aabb));
9090
let var = compute_var(obj.iter().map(|(aabb, _)| aabb), mean);
9191
let (dim, _) = var.argmax();
92-
obj.sort_by(|a, b| {
92+
let mut left_obj = Vec::new();
93+
let mut right_obj = Vec::new();
94+
let mut deferred = Vec::new();
95+
obj.iter().for_each(|&e| {
96+
if e.0.max[dim] < mean[dim] {
97+
left_obj.push(e);
98+
} else if e.0.min[dim] > mean[dim] {
99+
right_obj.push(e);
100+
} else {
101+
deferred.push(e);
102+
}
103+
});
104+
deferred.sort_by(|a, b| {
93105
let a = a.0.min[dim] + a.0.max[dim];
94106
let b = b.0.min[dim] + b.0.max[dim];
95107
a.partial_cmp(&b).unwrap()
96108
});
97-
let obj_len = obj.len();
98-
let left_obj = Vec::from_iter(obj.drain(..obj_len / 2));
99-
let right_obj = obj;
109+
let deffered_len = deferred.len();
110+
if deffered_len == 1 {
111+
if left_obj.len() < right_obj.len() {
112+
left_obj.push(deferred.pop().unwrap());
113+
} else {
114+
right_obj.push(deferred.pop().unwrap());
115+
}
116+
} else if deffered_len > 0 {
117+
left_obj.extend(deferred.drain(..deffered_len / 2));
118+
right_obj.extend(deferred);
119+
}
100120
let (left_node, right_node) = (subdivide(left_obj, node), subdivide(right_obj, node));
101121
let left_index = node.len();
102122
node.push(left_node);

src/cpp/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CPP_FLAGS=-O3 -std=c++1z -Wall -Wno-unused-function -Wno-unused-function -Wno-st
1414
EIGEN_PATH=/usr/include/eigen3
1515
EIGSYS_PATH=../../eigsys
1616

17-
BASE_DIRS=main vec utility csrmat contact aabb energy eigenanalysis barrier strainlimiting solver
17+
BASE_DIRS=main vec utility csrmat contact energy eigenanalysis barrier strainlimiting solver
1818
CUDA_FILES=$(foreach dir,$(BASE_DIRS),$(dir)/$(dir).cu)
1919
CPP_FILES=$(foreach dir,$(BASE_DIRS),$(dir)/$(dir).cpp)
2020
SIMPLELOG_FILES=simplelog/SimpleLog.cpp

src/cpp/aabb/aabb.cu

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/cpp/aabb/aabb.hpp

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/cpp/contact/aabb.hpp

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// File: aabb.hpp
2+
// Author: Ryoichi Ando ([email protected])
3+
// License: Apache v2.0
4+
5+
#ifndef AABB_DEF_HPP
6+
#define AABB_DEF_HPP
7+
8+
#include "../data.hpp"
9+
10+
#define AABB_MAX_QUERY 128
11+
12+
namespace aabb {
13+
14+
__device__ AABB join(const AABB &a, const AABB &b) {
15+
return {Vec3f(std::min(a.min[0], b.min[0]), std::min(a.min[1], b.min[1]),
16+
std::min(a.min[2], b.min[2])),
17+
Vec3f(std::max(a.max[0], b.max[0]), std::max(a.max[1], b.max[1]),
18+
std::max(a.max[2], b.max[2]))};
19+
}
20+
21+
__device__ AABB make(const Vec3f &x0, const Vec3f &x1, const Vec3f &x2,
22+
float margin) {
23+
AABB result = {Vec3f(std::min(x0[0], std::min(x1[0], x2[0])),
24+
std::min(x0[1], std::min(x1[1], x2[1])),
25+
std::min(x0[2], std::min(x1[2], x2[2]))),
26+
Vec3f(std::max(x0[0], std::max(x1[0], x2[0])),
27+
std::max(x0[1], std::max(x1[1], x2[1])),
28+
std::max(x0[2], std::max(x1[2], x2[2])))};
29+
if (margin) {
30+
for (unsigned i = 0; i < 3; ++i) {
31+
result.min[i] -= margin;
32+
result.max[i] += margin;
33+
}
34+
}
35+
return result;
36+
}
37+
38+
__device__ AABB make(const Vec3f &x0, const Vec3f &x1, float margin) {
39+
AABB result = {Vec3f(std::min(x0[0], x1[0]), std::min(x0[1], x1[1]),
40+
std::min(x0[2], x1[2])),
41+
Vec3f(std::max(x0[0], x1[0]), std::max(x0[1], x1[1]),
42+
std::max(x0[2], x1[2]))};
43+
if (margin) {
44+
for (unsigned i = 0; i < 3; ++i) {
45+
result.min[i] -= margin;
46+
result.max[i] += margin;
47+
}
48+
}
49+
return result;
50+
}
51+
52+
__device__ AABB make(const Vec3f &x, float margin) {
53+
return {
54+
x - Vec3f(margin, margin, margin),
55+
x + Vec3f(margin, margin, margin),
56+
};
57+
}
58+
59+
__device__ bool overlap(const AABB &a, const AABB &b) {
60+
return (a.min[0] <= b.max[0] && a.max[0] >= b.min[0]) &&
61+
(a.min[1] <= b.max[1] && a.max[1] >= b.min[1]) &&
62+
(a.min[2] <= b.max[2] && a.max[2] >= b.min[2]);
63+
}
64+
65+
template <typename F, typename T>
66+
__device__ static unsigned query(const BVH &bvh, Vec<AABB> aabb, F op,
67+
T query) {
68+
unsigned stack[AABB_MAX_QUERY];
69+
unsigned count = 0;
70+
unsigned head = 0;
71+
if (bvh.node.size) {
72+
stack[head++] = bvh.node.size - 1;
73+
while (head) {
74+
unsigned index = stack[--head];
75+
if (op.test(aabb[index], query)) {
76+
if (bvh.node[index][1] == 0) {
77+
unsigned leaf_index = bvh.node[index][0] - 1;
78+
if (op.test(aabb[index], query)) {
79+
if (op(leaf_index)) {
80+
count++;
81+
}
82+
}
83+
} else {
84+
if (head + 2 >= AABB_MAX_QUERY) {
85+
printf("stack overflow!\n");
86+
assert(false);
87+
break;
88+
} else {
89+
stack[head++] = bvh.node[index][0] - 1;
90+
stack[head++] = bvh.node[index][1] - 1;
91+
}
92+
}
93+
}
94+
}
95+
}
96+
return count;
97+
}
98+
99+
} // namespace aabb
100+
101+
#endif

src/cpp/contact/accd.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
#ifndef ACCD_HPP
66
#define ACCD_HPP
77

8-
#include "../math/distance.hpp"
8+
#include "distance.hpp"
99
#include <cassert>
1010

1111
namespace accd {
1212

13-
template <class T> __device__ void centerize(SMat<T, 3, 4> &x) {
14-
SVec<T, 3> mov = SVec<T, 3>::Zero();
13+
template <class T> __device__ void centerize(Mat3x4<T> &x) {
14+
Vec3f mov = Vec3f::Zero();
1515
T scale(0.25f);
1616
for (int k = 0; k < 4; k++) {
1717
mov += scale * x.col(k);

0 commit comments

Comments
 (0)