Spaces:
Running
on
Zero
Running
on
Zero
Upload ./hy3dgen/texgen/custom_rasterizer/lib/custom_rasterizer_kernel/rasterizer.h with huggingface_hub
Browse files
hy3dgen/texgen/custom_rasterizer/lib/custom_rasterizer_kernel/rasterizer.h
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#ifndef RASTERIZER_H_
|
2 |
+
#define RASTERIZER_H_
|
3 |
+
|
4 |
+
#include <torch/extension.h>
|
5 |
+
#include <vector>
|
6 |
+
#include <ATen/ATen.h>
|
7 |
+
#include <ATen/cuda/CUDAContext.h> // For CUDA context
|
8 |
+
|
9 |
+
#define INT64 unsigned long long
|
10 |
+
#define MAXINT 2147483647
|
11 |
+
|
12 |
+
__host__ __device__ inline float calculateSignedArea2(float* a, float* b, float* c) {
|
13 |
+
return ((c[0] - a[0]) * (b[1] - a[1]) - (b[0] - a[0]) * (c[1] - a[1]));
|
14 |
+
}
|
15 |
+
|
16 |
+
__host__ __device__ inline void calculateBarycentricCoordinate(float* a, float* b, float* c, float* p,
|
17 |
+
float* barycentric)
|
18 |
+
{
|
19 |
+
float beta_tri = calculateSignedArea2(a, p, c);
|
20 |
+
float gamma_tri = calculateSignedArea2(a, b, p);
|
21 |
+
float area = calculateSignedArea2(a, b, c);
|
22 |
+
if (area == 0) {
|
23 |
+
barycentric[0] = -1.0;
|
24 |
+
barycentric[1] = -1.0;
|
25 |
+
barycentric[2] = -1.0;
|
26 |
+
return;
|
27 |
+
}
|
28 |
+
float tri_inv = 1.0 / area;
|
29 |
+
float beta = beta_tri * tri_inv;
|
30 |
+
float gamma = gamma_tri * tri_inv;
|
31 |
+
float alpha = 1.0 - beta - gamma;
|
32 |
+
barycentric[0] = alpha;
|
33 |
+
barycentric[1] = beta;
|
34 |
+
barycentric[2] = gamma;
|
35 |
+
}
|
36 |
+
|
37 |
+
__host__ __device__ inline bool isBarycentricCoordInBounds(float* barycentricCoord) {
|
38 |
+
return barycentricCoord[0] >= 0.0 && barycentricCoord[0] <= 1.0 &&
|
39 |
+
barycentricCoord[1] >= 0.0 && barycentricCoord[1] <= 1.0 &&
|
40 |
+
barycentricCoord[2] >= 0.0 && barycentricCoord[2] <= 1.0;
|
41 |
+
}
|
42 |
+
|
43 |
+
std::vector<torch::Tensor> rasterize_image_gpu(torch::Tensor V, torch::Tensor F, torch::Tensor D,
|
44 |
+
int width, int height, float occlusion_truncation, int use_depth_prior);
|
45 |
+
|
46 |
+
std::vector<std::vector<torch::Tensor>> build_hierarchy(std::vector<torch::Tensor> view_layer_positions, std::vector<torch::Tensor> view_layer_normals, int num_level, int resolution);
|
47 |
+
|
48 |
+
std::vector<std::vector<torch::Tensor>> build_hierarchy_with_feat(
|
49 |
+
std::vector<torch::Tensor> view_layer_positions,
|
50 |
+
std::vector<torch::Tensor> view_layer_normals,
|
51 |
+
std::vector<torch::Tensor> view_layer_feats,
|
52 |
+
int num_level, int resolution);
|
53 |
+
|
54 |
+
#endif
|