conquer3d 0.1.9__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- conquer3d-0.2.1/MANIFEST.in +1 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/PKG-INFO +4 -3
- {conquer3d-0.1.9 → conquer3d-0.2.1}/README.md +2 -1
- conquer3d-0.2.1/conquer3d/csrc/check.h +29 -0
- conquer3d-0.2.1/conquer3d/csrc/constants.h +26 -0
- conquer3d-0.2.1/conquer3d/csrc/data_structure/bvh.h +61 -0
- conquer3d-0.2.1/conquer3d/csrc/data_structure/gs_bvh.h +49 -0
- conquer3d-0.2.1/conquer3d/csrc/data_structure/kdtree.h +111 -0
- conquer3d-0.2.1/conquer3d/csrc/data_structure/pgs_bvh.h +40 -0
- conquer3d-0.2.1/conquer3d/csrc/data_structure/zcurve.h +30 -0
- conquer3d-0.2.1/conquer3d/csrc/maths/f2x2.h +90 -0
- conquer3d-0.2.1/conquer3d/csrc/maths/f3x1.h +82 -0
- conquer3d-0.2.1/conquer3d/csrc/maths/f3x3.h +118 -0
- conquer3d-0.2.1/conquer3d/csrc/maths/f3x4.h +28 -0
- conquer3d-0.2.1/conquer3d/csrc/maths/f4x1.h +75 -0
- conquer3d-0.2.1/conquer3d/csrc/maths/f4x4.h +130 -0
- conquer3d-0.2.1/conquer3d/csrc/maths/maths.h +11 -0
- conquer3d-0.2.1/conquer3d/csrc/maths/ops.h +20 -0
- conquer3d-0.2.1/conquer3d/csrc/primitive/aabb.h +154 -0
- conquer3d-0.2.1/conquer3d/csrc/primitive/gs.h +112 -0
- conquer3d-0.2.1/conquer3d/csrc/primitive/gs_math.cuh +204 -0
- conquer3d-0.2.1/conquer3d/csrc/primitive/pgs.h +71 -0
- conquer3d-0.2.1/conquer3d/csrc/primitive/pgs_math.cuh +100 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d.egg-info/PKG-INFO +4 -3
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d.egg-info/SOURCES.txt +21 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/pyproject.toml +5 -5
- {conquer3d-0.1.9 → conquer3d-0.2.1}/LICENSE +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/_C.pyi +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/_C.so +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/__init__.py +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/csrc/binds/data_structure/bvh.cpp +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/csrc/binds/data_structure/gs_bvh.cpp +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/csrc/binds/data_structure/kdtree.cpp +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/csrc/binds/data_structure/pgs_bvh.cpp +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/csrc/binds/primitive/gs.cpp +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/csrc/binds/primitive/pgs.cpp +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/csrc/data_structure/bvh.cu +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/csrc/data_structure/kdtree.cu +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/csrc/primitive/gs.cu +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/csrc/primitive/gs_aabb.cu +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/csrc/primitive/pgs.cu +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/csrc/primitive/pgs_aabb.cu +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/csrc/pybind.cpp +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/data_structure/__init__.py +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/primitive/__init__.py +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/primitive/gs.py +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d/primitive/pgs.py +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d.egg-info/dependency_links.txt +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d.egg-info/not-zip-safe +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d.egg-info/requires.txt +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/conquer3d.egg-info/top_level.txt +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/setup.cfg +0 -0
- {conquer3d-0.1.9 → conquer3d-0.2.1}/setup.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
recursive-include conquer3d/csrc *.h *.hpp *.cuh *.cpp *.cu
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: conquer3d
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Geometric Cuda Tool Box
|
|
5
5
|
Author-email: Do Hoang Khoi <khoido8899@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -9,7 +9,7 @@ Project-URL: Repository, https://github.com/KhoiDOO/conquer3d.git
|
|
|
9
9
|
Project-URL: Documentation, https://github.com/KhoiDOO/conquer3d#readme
|
|
10
10
|
Project-URL: Issues, https://github.com/KhoiDOO/conquer3d/issues
|
|
11
11
|
Keywords: geometry
|
|
12
|
-
Requires-Python: >=3.
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
License-File: LICENSE
|
|
15
15
|
Requires-Dist: torch>=2.0.0
|
|
@@ -58,8 +58,9 @@ pip install plotly open3d jupyter trimesh
|
|
|
58
58
|
# Development
|
|
59
59
|
```bash
|
|
60
60
|
pip install build twine
|
|
61
|
+
rm -rf dist
|
|
61
62
|
python -m build --sdist
|
|
62
|
-
twine upload dist/*
|
|
63
|
+
twine upload dist/* --verbose
|
|
63
64
|
```
|
|
64
65
|
|
|
65
66
|
# Reference
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#ifndef CHECK_H
|
|
2
|
+
#define CHECK_H
|
|
3
|
+
|
|
4
|
+
#include <cuda_runtime.h>
|
|
5
|
+
#include <stdio.h>
|
|
6
|
+
#include <stdint.h>
|
|
7
|
+
|
|
8
|
+
// Helper macros to check tensor properties
|
|
9
|
+
// These require <torch/extension.h> or <ATen/ATen.h> to be included in the translation unit
|
|
10
|
+
#define CHECK_CUDA(x) \
|
|
11
|
+
TORCH_CHECK((x).device().is_cuda(), #x " must be a CUDA tensor")
|
|
12
|
+
#define CHECK_CONTIGUOUS(x) \
|
|
13
|
+
TORCH_CHECK((x).is_contiguous(), #x " must be contiguous")
|
|
14
|
+
#define CHECK_INPUT(x) \
|
|
15
|
+
CHECK_CUDA(x); \
|
|
16
|
+
CHECK_CONTIGUOUS(x)
|
|
17
|
+
|
|
18
|
+
inline bool check_cuda_result(cudaError_t code, const char *file, int line)
|
|
19
|
+
{
|
|
20
|
+
if (code == cudaSuccess)
|
|
21
|
+
return true;
|
|
22
|
+
|
|
23
|
+
fprintf(stderr, "CUDA error %u: %s (%s:%d)\n", unsigned(code), cudaGetErrorString(code), file, line);
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
#define CUDA_CHECK(code) check_cuda_result((code), __FILE__, __LINE__)
|
|
28
|
+
|
|
29
|
+
#endif // CHECK_H
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#ifndef CONSTANTS_H
|
|
2
|
+
#define CONSTANTS_H
|
|
3
|
+
|
|
4
|
+
// ==========================================
|
|
5
|
+
// CUDA
|
|
6
|
+
// ==========================================
|
|
7
|
+
#define NTHREADS 256
|
|
8
|
+
|
|
9
|
+
// ==========================================
|
|
10
|
+
// KD-Tree
|
|
11
|
+
// ==========================================
|
|
12
|
+
#define MAX_K 32
|
|
13
|
+
|
|
14
|
+
// ==========================================
|
|
15
|
+
// BVH
|
|
16
|
+
// ==========================================
|
|
17
|
+
#define BVH_STACK_SIZE 64
|
|
18
|
+
#define BVH_MAX_CAPACITY 10000000
|
|
19
|
+
|
|
20
|
+
// ==========================================
|
|
21
|
+
// GAUSSIANS
|
|
22
|
+
// ==========================================
|
|
23
|
+
#define ISO 11.345
|
|
24
|
+
#define TOL 0.125
|
|
25
|
+
|
|
26
|
+
#endif // CONSTANTS_H
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#ifndef BVH_H
|
|
2
|
+
#define BVH_H
|
|
3
|
+
|
|
4
|
+
#include "../maths/maths.h"
|
|
5
|
+
#include "../constants.h"
|
|
6
|
+
#include "../primitive/aabb.h"
|
|
7
|
+
|
|
8
|
+
#include <torch/extension.h>
|
|
9
|
+
#include <cuda_runtime.h>
|
|
10
|
+
#include <cstdint>
|
|
11
|
+
|
|
12
|
+
class BVH
|
|
13
|
+
{
|
|
14
|
+
protected:
|
|
15
|
+
uint32_t num_objects;
|
|
16
|
+
uint32_t num_nodes; // Will always be 2N - 1
|
|
17
|
+
|
|
18
|
+
torch::Tensor aabb_mins; // Size: [2N - 1, 3]
|
|
19
|
+
torch::Tensor aabb_maxs; // Size: [2N - 1, 3]
|
|
20
|
+
torch::Tensor bvh_children; // Size: [2N - 1, 2] -> x = left_child, y = right_child
|
|
21
|
+
torch::Tensor bvh_parents; // Size: [2N - 1] -> index of parent node
|
|
22
|
+
torch::Tensor object_ids; // Size: [N] -> Maps the sorted leaf index back to the original Gaussian index
|
|
23
|
+
|
|
24
|
+
public:
|
|
25
|
+
BVH(const torch::Tensor &in_aabb_mins, const torch::Tensor &in_aabb_maxs);
|
|
26
|
+
|
|
27
|
+
std::tuple<torch::Tensor, torch::Tensor> query(
|
|
28
|
+
const torch::Tensor &query_aabb_mins,
|
|
29
|
+
const torch::Tensor &query_aabb_maxs);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
namespace bvh
|
|
33
|
+
{
|
|
34
|
+
__host__ void build(
|
|
35
|
+
const uint32_t num_objects,
|
|
36
|
+
const uint32_t num_nodes,
|
|
37
|
+
const float3 *__restrict__ in_aabb_mins, // Unsorted input
|
|
38
|
+
const float3 *__restrict__ in_aabb_maxs, // Unsorted input
|
|
39
|
+
float3 *__restrict__ bvh_aabb_mins, // Size 2N-1
|
|
40
|
+
float3 *__restrict__ bvh_aabb_maxs, // Size 2N-1
|
|
41
|
+
int2 *__restrict__ bvh_children, // Size 2N-1
|
|
42
|
+
int *__restrict__ bvh_parents, // Size 2N-1
|
|
43
|
+
int *__restrict__ object_ids // Size N
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
__host__ void query(
|
|
47
|
+
const uint32_t num_queries,
|
|
48
|
+
const uint32_t num_objects,
|
|
49
|
+
const float3 *__restrict__ query_mins,
|
|
50
|
+
const float3 *__restrict__ query_maxs,
|
|
51
|
+
const float3 *__restrict__ bvh_aabb_mins,
|
|
52
|
+
const float3 *__restrict__ bvh_aabb_maxs,
|
|
53
|
+
const int2 *__restrict__ bvh_children,
|
|
54
|
+
const int *__restrict__ object_ids,
|
|
55
|
+
int64_t *__restrict__ out_query_ids,
|
|
56
|
+
int64_t *__restrict__ out_object_ids,
|
|
57
|
+
int64_t *__restrict__ hit_counter,
|
|
58
|
+
const int64_t max_capacity);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
#endif // BVH_H
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#ifndef GS_BVH_H
|
|
2
|
+
#define GS_BVH_H
|
|
3
|
+
|
|
4
|
+
#include "bvh.h"
|
|
5
|
+
#include "../primitive/gs.h"
|
|
6
|
+
|
|
7
|
+
#include <variant>
|
|
8
|
+
|
|
9
|
+
class GSBVH : public BVH
|
|
10
|
+
{
|
|
11
|
+
public:
|
|
12
|
+
// Inherit the base constructor (this automatically builds the tree!)
|
|
13
|
+
using BVH::BVH;
|
|
14
|
+
using BVH::query;
|
|
15
|
+
|
|
16
|
+
// Add Gaussian-specific queries
|
|
17
|
+
std::tuple<torch::Tensor, torch::Tensor, torch::Tensor, std::optional<torch::Tensor>, std::optional<torch::Tensor>> query_voxel_pair(
|
|
18
|
+
const torch::Tensor &vx_aabb_mins,
|
|
19
|
+
const torch::Tensor &vx_aabb_maxs,
|
|
20
|
+
const torch::Tensor &means,
|
|
21
|
+
const torch::Tensor &covis,
|
|
22
|
+
const torch::Tensor &opacities,
|
|
23
|
+
const torch::Tensor &gs_aabb_mins,
|
|
24
|
+
const torch::Tensor &gs_aabb_maxs,
|
|
25
|
+
const torch::Tensor &contact_points,
|
|
26
|
+
const std::variant<float, torch::Tensor> &isos,
|
|
27
|
+
const float ar_threshold,
|
|
28
|
+
const float p_threshold,
|
|
29
|
+
const bool return_centroids,
|
|
30
|
+
const int64_t max_capacity);
|
|
31
|
+
|
|
32
|
+
std::tuple<torch::Tensor, torch::Tensor, torch::Tensor> query_edge_pair(
|
|
33
|
+
const torch::Tensor &edge_starts,
|
|
34
|
+
const torch::Tensor &edge_ends,
|
|
35
|
+
const torch::Tensor &means,
|
|
36
|
+
const torch::Tensor &covis,
|
|
37
|
+
const std::variant<float, torch::Tensor> &isos,
|
|
38
|
+
const int64_t max_capacity);
|
|
39
|
+
|
|
40
|
+
std::tuple<torch::Tensor, torch::Tensor> query_edge(
|
|
41
|
+
const torch::Tensor &edge_starts,
|
|
42
|
+
const torch::Tensor &edge_ends,
|
|
43
|
+
const torch::Tensor &means,
|
|
44
|
+
const torch::Tensor &opacities,
|
|
45
|
+
const torch::Tensor &covis,
|
|
46
|
+
const std::variant<float, torch::Tensor> &isos);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
#endif // GS_BVH_H
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#ifndef KDTREE_H
|
|
2
|
+
#define KDTREE_H
|
|
3
|
+
|
|
4
|
+
#include "../maths/maths.h"
|
|
5
|
+
#include "../constants.h"
|
|
6
|
+
|
|
7
|
+
#include <torch/extension.h>
|
|
8
|
+
#include <cuda_runtime.h>
|
|
9
|
+
#include <cstdint>
|
|
10
|
+
|
|
11
|
+
class KDTree {
|
|
12
|
+
private:
|
|
13
|
+
uint32_t num_points;
|
|
14
|
+
|
|
15
|
+
torch::Tensor points;
|
|
16
|
+
torch::Tensor oinds;
|
|
17
|
+
|
|
18
|
+
public:
|
|
19
|
+
KDTree(const torch::Tensor& points);
|
|
20
|
+
|
|
21
|
+
std::tuple<torch::Tensor, torch::Tensor> query(
|
|
22
|
+
const torch::Tensor& query_points,
|
|
23
|
+
const int k,
|
|
24
|
+
bool exclude_self=false
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
namespace kdtree {
|
|
29
|
+
void build(
|
|
30
|
+
const uint32_t num_points,
|
|
31
|
+
float3 *__restrict__ points,
|
|
32
|
+
int64_t *__restrict__ original_inds);
|
|
33
|
+
|
|
34
|
+
void query(
|
|
35
|
+
const uint32_t num_queries,
|
|
36
|
+
const uint32_t num_points,
|
|
37
|
+
const uint32_t k,
|
|
38
|
+
const float3 *__restrict__ query_points,
|
|
39
|
+
const float3 *__restrict__ tree_points,
|
|
40
|
+
const int64_t *__restrict__ tree_inds,
|
|
41
|
+
float *__restrict__ out_dists,
|
|
42
|
+
int64_t *__restrict__ out_inds);
|
|
43
|
+
|
|
44
|
+
__device__ __forceinline__ void push_pq(
|
|
45
|
+
float dist,
|
|
46
|
+
int64_t id,
|
|
47
|
+
float* best_dists,
|
|
48
|
+
int64_t* best_inds,
|
|
49
|
+
const int k)
|
|
50
|
+
{
|
|
51
|
+
if (dist >= best_dists[k - 1]) return;
|
|
52
|
+
int i = k - 2;
|
|
53
|
+
while (i >= 0 && best_dists[i] > dist) {
|
|
54
|
+
best_dists[i + 1] = best_dists[i];
|
|
55
|
+
best_inds[i + 1] = best_inds[i];
|
|
56
|
+
i--;
|
|
57
|
+
}
|
|
58
|
+
best_dists[i + 1] = dist;
|
|
59
|
+
best_inds[i + 1] = id;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
__device__ __forceinline__ void query_kdtree_loop(
|
|
63
|
+
const float3& qp,
|
|
64
|
+
const uint32_t num_points,
|
|
65
|
+
const float3* __restrict__ tree_points,
|
|
66
|
+
const int64_t* __restrict__ tree_inds,
|
|
67
|
+
const int k,
|
|
68
|
+
float* best_dists,
|
|
69
|
+
int64_t* best_inds)
|
|
70
|
+
{
|
|
71
|
+
int stack[64];
|
|
72
|
+
int stack_ptr = 0;
|
|
73
|
+
|
|
74
|
+
stack[stack_ptr++] = 0;
|
|
75
|
+
|
|
76
|
+
while (stack_ptr > 0) {
|
|
77
|
+
int curr = stack[--stack_ptr];
|
|
78
|
+
if (curr >= num_points) continue;
|
|
79
|
+
|
|
80
|
+
float3 p = tree_points[curr];
|
|
81
|
+
|
|
82
|
+
#ifdef __CUDA_ARCH__
|
|
83
|
+
int axis = (31 - __clz(curr + 1)) % 3;
|
|
84
|
+
#else
|
|
85
|
+
int axis = (31 - __builtin_clz((unsigned int)(curr + 1))) % 3;
|
|
86
|
+
#endif
|
|
87
|
+
|
|
88
|
+
float3 d = qp - p;
|
|
89
|
+
float dist_sq = maths::dot(d, d);
|
|
90
|
+
|
|
91
|
+
push_pq(dist_sq, tree_inds[curr], best_dists, best_inds, k);
|
|
92
|
+
|
|
93
|
+
float axis_dist = (axis == 0) ? d.x : ((axis == 1) ? d.y : d.z);
|
|
94
|
+
|
|
95
|
+
int left_child = 2 * curr + 1;
|
|
96
|
+
int right_child = 2 * curr + 2;
|
|
97
|
+
|
|
98
|
+
int near_child = (axis_dist <= 0) ? left_child : right_child;
|
|
99
|
+
int far_child = (axis_dist <= 0) ? right_child : left_child;
|
|
100
|
+
|
|
101
|
+
if (far_child < num_points && (axis_dist * axis_dist <= best_dists[k - 1])) {
|
|
102
|
+
stack[stack_ptr++] = far_child;
|
|
103
|
+
}
|
|
104
|
+
if (near_child < num_points) {
|
|
105
|
+
stack[stack_ptr++] = near_child;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
#endif // KDTREE_H
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#ifndef PGS_BVH_H
|
|
2
|
+
#define PGS_BVH_H
|
|
3
|
+
|
|
4
|
+
#include "bvh.h"
|
|
5
|
+
#include "../primitive/pgs.h"
|
|
6
|
+
|
|
7
|
+
#include <variant>
|
|
8
|
+
|
|
9
|
+
class PGSBVH : public BVH
|
|
10
|
+
{
|
|
11
|
+
public:
|
|
12
|
+
// Inherit the base constructor (this automatically builds the tree!)
|
|
13
|
+
using BVH::BVH;
|
|
14
|
+
using BVH::query;
|
|
15
|
+
|
|
16
|
+
// Add Gaussian-specific queries
|
|
17
|
+
std::tuple<torch::Tensor, torch::Tensor, torch::Tensor, std::optional<torch::Tensor>, std::optional<torch::Tensor>> query_voxel_pair(
|
|
18
|
+
const torch::Tensor &vx_aabb_mins,
|
|
19
|
+
const torch::Tensor &vx_aabb_maxs,
|
|
20
|
+
const torch::Tensor &means,
|
|
21
|
+
const torch::Tensor &normals,
|
|
22
|
+
const torch::Tensor &covis,
|
|
23
|
+
const torch::Tensor &gs_aabb_mins,
|
|
24
|
+
const torch::Tensor &gs_aabb_maxs,
|
|
25
|
+
const std::variant<float, torch::Tensor> &isos,
|
|
26
|
+
const bool return_centroids,
|
|
27
|
+
const bool return_centroid_densities,
|
|
28
|
+
const int64_t max_capacity);
|
|
29
|
+
|
|
30
|
+
std::tuple<torch::Tensor, torch::Tensor> query_edge(
|
|
31
|
+
const torch::Tensor &edge_starts,
|
|
32
|
+
const torch::Tensor &edge_ends,
|
|
33
|
+
const torch::Tensor &means,
|
|
34
|
+
const torch::Tensor &normals,
|
|
35
|
+
const torch::Tensor &opacities,
|
|
36
|
+
const torch::Tensor &covis,
|
|
37
|
+
const std::variant<float, torch::Tensor> &isos);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
#endif // PGS_BVH_H
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#ifndef ZCURVE_H
|
|
2
|
+
#define ZCURVE_H
|
|
3
|
+
|
|
4
|
+
#include "../maths/maths.h"
|
|
5
|
+
#include "cuda_runtime.h"
|
|
6
|
+
|
|
7
|
+
namespace zcurve
|
|
8
|
+
{
|
|
9
|
+
__device__ unsigned int expandBits(unsigned int v)
|
|
10
|
+
{
|
|
11
|
+
v = (v * 0x00010001u) & 0xFF0000FFu;
|
|
12
|
+
v = (v * 0x00000101u) & 0x0F00F00Fu;
|
|
13
|
+
v = (v * 0x00000011u) & 0xC30C30C3u;
|
|
14
|
+
v = (v * 0x00000005u) & 0x49249249u;
|
|
15
|
+
return v;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
__device__ unsigned int morton3D(float x, float y, float z)
|
|
19
|
+
{
|
|
20
|
+
x = min(max(x * 1024.0f, 0.0f), 1023.0f);
|
|
21
|
+
y = min(max(y * 1024.0f, 0.0f), 1023.0f);
|
|
22
|
+
z = min(max(z * 1024.0f, 0.0f), 1023.0f);
|
|
23
|
+
unsigned int xx = expandBits((unsigned int)x);
|
|
24
|
+
unsigned int yy = expandBits((unsigned int)y);
|
|
25
|
+
unsigned int zz = expandBits((unsigned int)z);
|
|
26
|
+
return xx * 4 + yy * 2 + zz;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
#endif // ZCURVE_H
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#ifndef F2X2_H
|
|
2
|
+
#define F2X2_H
|
|
3
|
+
|
|
4
|
+
#include "ops.h"
|
|
5
|
+
|
|
6
|
+
#include <stdint.h>
|
|
7
|
+
#include <cmath>
|
|
8
|
+
#include <vector_types.h>
|
|
9
|
+
#include <vector_functions.h>
|
|
10
|
+
#include <math_constants.h>
|
|
11
|
+
|
|
12
|
+
typedef struct
|
|
13
|
+
{
|
|
14
|
+
float m[2][2];
|
|
15
|
+
} float2x2;
|
|
16
|
+
|
|
17
|
+
static __inline__ __host__ __device__ float2x2 make_float2x2(
|
|
18
|
+
float a00, float a01,
|
|
19
|
+
float a10, float a11) {
|
|
20
|
+
float2x2 a;
|
|
21
|
+
a.m[0][0] = a00; a.m[0][1] = a01;
|
|
22
|
+
a.m[1][0] = a10; a.m[1][1] = a11;
|
|
23
|
+
return a;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// [2, 2] x [2, 2] = [2, 2]
|
|
27
|
+
static __inline__ __host__ __device__ float2x2 operator* (const float2x2& a, const float2x2& b)
|
|
28
|
+
{
|
|
29
|
+
float2x2 c;
|
|
30
|
+
|
|
31
|
+
c.m[0][0] = a.m[0][0] * b.m[0][0] + a.m[0][1] * b.m[1][0];
|
|
32
|
+
c.m[0][1] = a.m[0][0] * b.m[0][1] + a.m[0][1] * b.m[1][1];
|
|
33
|
+
c.m[1][0] = a.m[1][0] * b.m[0][0] + a.m[1][1] * b.m[1][0];
|
|
34
|
+
c.m[1][1] = a.m[1][0] * b.m[0][1] + a.m[1][1] * b.m[1][1];
|
|
35
|
+
|
|
36
|
+
return c;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// [2, 1]^T x [2, 2] = [2, 1]^T
|
|
40
|
+
static __inline__ __host__ __device__ float2 operator*(const float2& a, const float2x2& m) {
|
|
41
|
+
return make_float2(
|
|
42
|
+
a.x * m.m[0][0] + a.y * m.m[1][0],
|
|
43
|
+
a.x * m.m[0][1] + a.y * m.m[1][1]
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// [2, 2] x [2, 1] = [2, 1]
|
|
48
|
+
static __inline__ __host__ __device__ float2 operator*(const float2x2& m, const float2& a) {
|
|
49
|
+
return make_float2(
|
|
50
|
+
m.m[0][0] * a.x + m.m[0][1] * a.y,
|
|
51
|
+
m.m[1][0] * a.x + m.m[1][1] * a.y
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
namespace maths
|
|
56
|
+
{
|
|
57
|
+
static __inline__ __host__ __device__ float2x2 transpose(const float2x2& a) {
|
|
58
|
+
float2x2 b;
|
|
59
|
+
b.m[0][0] = a.m[0][0]; b.m[0][1] = a.m[1][0];
|
|
60
|
+
b.m[1][0] = a.m[0][1]; b.m[1][1] = a.m[1][1];
|
|
61
|
+
return b;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static __inline__ __host__ __device__ float det(const float2x2& a) {
|
|
65
|
+
return a.m[0][0] * a.m[1][1] - a.m[0][1] * a.m[1][0];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static inline __host__ __device__ void copy(float2x2 &a, float2x2 b) {
|
|
69
|
+
a.m[0][0] = b.m[0][0]; a.m[0][1] = b.m[0][1];
|
|
70
|
+
a.m[1][0] = b.m[1][0]; a.m[1][1] = b.m[1][1];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static __host__ __device__ __forceinline__ bool invert(const float2x2& m, float2x2& out_inv)
|
|
74
|
+
{
|
|
75
|
+
float det_val = m.m[0][0] * m.m[1][1] - m.m[0][1] * m.m[1][0];
|
|
76
|
+
|
|
77
|
+
if (fabsf(det_val) < 1e-8f) return false;
|
|
78
|
+
|
|
79
|
+
float inv_det = 1.0f / det_val;
|
|
80
|
+
|
|
81
|
+
out_inv.m[0][0] = m.m[1][1] * inv_det;
|
|
82
|
+
out_inv.m[0][1] = -m.m[0][1] * inv_det;
|
|
83
|
+
out_inv.m[1][0] = -m.m[1][0] * inv_det;
|
|
84
|
+
out_inv.m[1][1] = m.m[0][0] * inv_det;
|
|
85
|
+
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#endif // F2X2_H
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#ifndef F3x1_H
|
|
2
|
+
#define F3x1_H
|
|
3
|
+
|
|
4
|
+
#include "ops.h"
|
|
5
|
+
|
|
6
|
+
#include <stdint.h>
|
|
7
|
+
#include <cmath>
|
|
8
|
+
#include <vector_types.h>
|
|
9
|
+
#include <vector_functions.h>
|
|
10
|
+
#include <math_constants.h>
|
|
11
|
+
|
|
12
|
+
static inline __host__ __device__ float3 operator+(float3 a, float3 b) {
|
|
13
|
+
return make_float3(a.x + b.x, a.y + b.y, a.z + b.z);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static inline __host__ __device__ void operator+=(float3 &a, float3 b) {
|
|
17
|
+
a.x += b.x; a.y += b.y; a.z += b.z;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static inline __host__ __device__ float3 operator-(float3 a, float3 b) {
|
|
21
|
+
return make_float3(a.x - b.x, a.y - b.y, a.z - b.z);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static inline __host__ __device__ void operator-=(float3 &a, float3 b) {
|
|
25
|
+
a.x -= b.x; a.y -= b.y; a.z -= b.z;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static inline __host__ __device__ float3 operator*(float3 a, float b) {
|
|
29
|
+
return make_float3(a.x * b, a.y * b, a.z * b);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static inline __host__ __device__ float3 operator*(float b, float3 a) {
|
|
33
|
+
return make_float3(b * a.x, b * a.y, b * a.z);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static inline __host__ __device__ void operator*=(float3 &a, float b) {
|
|
37
|
+
a.x *= b; a.y *= b; a.z *= b;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static inline __host__ __device__ float3 operator/(float3 a, const float b) {
|
|
41
|
+
float inv = 1.0f / b;
|
|
42
|
+
return make_float3(a.x * inv, a.y * inv, a.z * inv);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static inline __host__ __device__ void operator/=(float3 &a, float b) {
|
|
46
|
+
float inv = 1.0f / b;
|
|
47
|
+
a.x *= inv; a.y *= inv; a.z *= inv;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
namespace maths
|
|
51
|
+
{
|
|
52
|
+
static inline __host__ __device__ float dot(float3 a, float3 b) {
|
|
53
|
+
return a.x * b.x + a.y * b.y + a.z * b.z;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static inline __host__ __device__ float dot2(float3 a) {
|
|
57
|
+
return dot(a, a);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static inline __host__ __device__ float norm(float3 a) {
|
|
61
|
+
return sqrtf(dot2(a));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static inline __host__ __device__ float3 cross(float3 a, float3 b) {
|
|
65
|
+
return make_float3(
|
|
66
|
+
a.y * b.z - a.z * b.y,
|
|
67
|
+
a.z * b.x - a.x * b.z,
|
|
68
|
+
a.x * b.y - a.y * b.x
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static inline __host__ __device__ float3 normalize(float3 v) {
|
|
73
|
+
float invLen = rsqrtf(dot2(v));
|
|
74
|
+
return v * invLen;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static inline __host__ __device__ bool equals(float3 a, float3 b) {
|
|
78
|
+
return a.x == b.x && a.y == b.y && a.z == b.z;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
#endif // F3x1_H
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#ifndef F3X3_H
|
|
2
|
+
#define F3X3_H
|
|
3
|
+
|
|
4
|
+
#include "f2x2.h"
|
|
5
|
+
#include "ops.h"
|
|
6
|
+
|
|
7
|
+
#include <stdint.h>
|
|
8
|
+
#include <cmath>
|
|
9
|
+
#include <vector_types.h>
|
|
10
|
+
#include <vector_functions.h>
|
|
11
|
+
#include <math_constants.h>
|
|
12
|
+
|
|
13
|
+
typedef struct
|
|
14
|
+
{
|
|
15
|
+
float m[3][3];
|
|
16
|
+
} float3x3;
|
|
17
|
+
|
|
18
|
+
static __inline__ __host__ __device__ float3x3 make_float3x3(
|
|
19
|
+
float a00, float a01, float a02,
|
|
20
|
+
float a10, float a11, float a12,
|
|
21
|
+
float a20, float a21, float a22) {
|
|
22
|
+
float3x3 a;
|
|
23
|
+
a.m[0][0] = a00; a.m[0][1] = a01; a.m[0][2] = a02;
|
|
24
|
+
a.m[1][0] = a10; a.m[1][1] = a11; a.m[1][2] = a12;
|
|
25
|
+
a.m[2][0] = a20; a.m[2][1] = a21; a.m[2][2] = a22;
|
|
26
|
+
return a;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// [3, 3] x [3, 3] = [3, 3]
|
|
30
|
+
static __inline__ __host__ __device__ float3x3 operator* (const float3x3& a, const float3x3& b)
|
|
31
|
+
{
|
|
32
|
+
float3x3 c;
|
|
33
|
+
|
|
34
|
+
c.m[0][0] = a.m[0][0] * b.m[0][0] + a.m[0][1] * b.m[1][0] + a.m[0][2] * b.m[2][0];
|
|
35
|
+
c.m[0][1] = a.m[0][0] * b.m[0][1] + a.m[0][1] * b.m[1][1] + a.m[0][2] * b.m[2][1];
|
|
36
|
+
c.m[0][2] = a.m[0][0] * b.m[0][2] + a.m[0][1] * b.m[1][2] + a.m[0][2] * b.m[2][2];
|
|
37
|
+
|
|
38
|
+
c.m[1][0] = a.m[1][0] * b.m[0][0] + a.m[1][1] * b.m[1][0] + a.m[1][2] * b.m[2][0];
|
|
39
|
+
c.m[1][1] = a.m[1][0] * b.m[0][1] + a.m[1][1] * b.m[1][1] + a.m[1][2] * b.m[2][1];
|
|
40
|
+
c.m[1][2] = a.m[1][0] * b.m[0][2] + a.m[1][1] * b.m[1][2] + a.m[1][2] * b.m[2][2];
|
|
41
|
+
|
|
42
|
+
c.m[2][0] = a.m[2][0] * b.m[0][0] + a.m[2][1] * b.m[1][0] + a.m[2][2] * b.m[2][0];
|
|
43
|
+
c.m[2][1] = a.m[2][0] * b.m[0][1] + a.m[2][1] * b.m[1][1] + a.m[2][2] * b.m[2][1];
|
|
44
|
+
c.m[2][2] = a.m[2][0] * b.m[0][2] + a.m[2][1] * b.m[1][2] + a.m[2][2] * b.m[2][2];
|
|
45
|
+
|
|
46
|
+
return c;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// [3, 1]^T x [3, 3] = [3, 1]^T
|
|
50
|
+
static __inline__ __host__ __device__ float3 operator*(const float3& a, const float3x3& m) {
|
|
51
|
+
return make_float3(
|
|
52
|
+
a.x * m.m[0][0] + a.y * m.m[1][0] + a.z * m.m[2][0],
|
|
53
|
+
a.x * m.m[0][1] + a.y * m.m[1][1] + a.z * m.m[2][1],
|
|
54
|
+
a.x * m.m[0][2] + a.y * m.m[1][2] + a.z * m.m[2][2]
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// [3, 3] x [3, 1] = [3, 1]
|
|
59
|
+
static __inline__ __host__ __device__ float3 operator*(const float3x3& m, const float3& a) {
|
|
60
|
+
return make_float3(
|
|
61
|
+
m.m[0][0] * a.x + m.m[0][1] * a.y + m.m[0][2] * a.z,
|
|
62
|
+
m.m[1][0] * a.x + m.m[1][1] * a.y + m.m[1][2] * a.z,
|
|
63
|
+
m.m[2][0] * a.x + m.m[2][1] * a.y + m.m[2][2] * a.z
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
namespace maths
|
|
68
|
+
{
|
|
69
|
+
static __inline__ __host__ __device__ float3x3 transpose(const float3x3& a) {
|
|
70
|
+
float3x3 b;
|
|
71
|
+
b.m[0][0] = a.m[0][0]; b.m[0][1] = a.m[1][0]; b.m[0][2] = a.m[2][0];
|
|
72
|
+
b.m[1][0] = a.m[0][1]; b.m[1][1] = a.m[1][1]; b.m[1][2] = a.m[2][1];
|
|
73
|
+
b.m[2][0] = a.m[0][2]; b.m[2][1] = a.m[1][2]; b.m[2][2] = a.m[2][2];
|
|
74
|
+
return b;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static __inline__ __host__ __device__ float det(const float3x3& a) {
|
|
78
|
+
return a.m[0][0] * (a.m[1][1] * a.m[2][2] - a.m[1][2] * a.m[2][1])
|
|
79
|
+
- a.m[0][1] * (a.m[1][0] * a.m[2][2] - a.m[1][2] * a.m[2][0])
|
|
80
|
+
+ a.m[0][2] * (a.m[1][0] * a.m[2][1] - a.m[1][1] * a.m[2][0]);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static inline __host__ __device__ void copy(float3x3 &a, float3x3 b) {
|
|
84
|
+
a.m[0][0] = b.m[0][0]; a.m[0][1] = b.m[0][1]; a.m[0][2] = b.m[0][2];
|
|
85
|
+
a.m[1][0] = b.m[1][0]; a.m[1][1] = b.m[1][1]; a.m[1][2] = b.m[1][2];
|
|
86
|
+
a.m[2][0] = b.m[2][0]; a.m[2][1] = b.m[2][1]; a.m[2][2] = b.m[2][2];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static __host__ __device__ __forceinline__ bool invert(const float3x3& m, float3x3& out_inv)
|
|
90
|
+
{
|
|
91
|
+
float a = m.m[0][0], b = m.m[0][1], c = m.m[0][2];
|
|
92
|
+
float d = m.m[1][0], e = m.m[1][1], f = m.m[1][2];
|
|
93
|
+
float g = m.m[2][0], h = m.m[2][1], i = m.m[2][2];
|
|
94
|
+
|
|
95
|
+
float A = e * i - f * h;
|
|
96
|
+
float B = f * g - d * i;
|
|
97
|
+
float C = d * h - e * g;
|
|
98
|
+
|
|
99
|
+
float det_val = a * A + b * B + c * C;
|
|
100
|
+
|
|
101
|
+
if (fabsf(det_val) < 1e-8f) return false;
|
|
102
|
+
|
|
103
|
+
float inv_det = 1.0f / det_val;
|
|
104
|
+
|
|
105
|
+
out_inv.m[0][0] = A * inv_det;
|
|
106
|
+
out_inv.m[0][1] = (c * h - b * i) * inv_det;
|
|
107
|
+
out_inv.m[0][2] = (b * f - c * e) * inv_det;
|
|
108
|
+
out_inv.m[1][0] = B * inv_det;
|
|
109
|
+
out_inv.m[1][1] = (a * i - c * g) * inv_det;
|
|
110
|
+
out_inv.m[1][2] = (c * d - a * f) * inv_det;
|
|
111
|
+
out_inv.m[2][0] = C * inv_det;
|
|
112
|
+
out_inv.m[2][1] = (b * g - a * h) * inv_det;
|
|
113
|
+
out_inv.m[2][2] = (a * e - b * d) * inv_det;
|
|
114
|
+
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
#endif // F3X3_H
|