5
5
#include " ../../../util/const.h"
6
6
#include " mesh_analyzer.h"
7
7
8
+ __device__ int get_subdivision_count (float area, int threshold) {
9
+ float unit = area;
10
+ int count = 1 ;
11
+ while (unit > threshold) {
12
+ unit /= 4 ;
13
+ count *= 4 ;
14
+ }
15
+ return count;
16
+ }
17
+
8
18
template <typename ShaderType>
9
19
__global__ void analyze_faces (DrawCallBaseArgs args, ModelDrawCallArgs model_args, const Image image, int threshold, bool *face_mask, int n_faces, int *new_virtual_faces) {
10
20
int position = blockIdx .x * blockDim .x + threadIdx .x ;
@@ -21,7 +31,7 @@ __global__ void analyze_faces(DrawCallBaseArgs args, ModelDrawCallArgs model_arg
21
31
if (pts[0 ].y ==pts[1 ].y && pts[0 ].y ==pts[2 ].y ) return ;
22
32
23
33
glm::vec2 bboxmin{float (image.width -1 ), float (image.height -1 )};
24
- glm::vec2 bboxmax{0 ., 0 .};
34
+ glm::vec2 bboxmax{0.01 , 0.01 };
25
35
glm::vec2 clamp{float (image.width -1 ), float (image.height -1 )};
26
36
for (auto &pt : pts) {
27
37
bboxmin.x = max (0 .0f , min (bboxmin.x , pt.x ));
@@ -31,9 +41,11 @@ __global__ void analyze_faces(DrawCallBaseArgs args, ModelDrawCallArgs model_arg
31
41
bboxmax.y = min (clamp.y , max (bboxmax.y , pt.y ));
32
42
}
33
43
34
- float area = (bboxmax.x - pts[0 ].x ) * (bboxmax.y - pts[0 ].y );
44
+
45
+ float area = (bboxmax.x - bboxmin.x ) * (bboxmax.y - bboxmin.y );
35
46
if (area > threshold) {
36
- atomicAdd (new_virtual_faces, ceil (area / (float )threshold));
47
+ auto count = get_subdivision_count (area, threshold);
48
+ atomicAdd (new_virtual_faces, count);
37
49
face_mask[position] = true ;
38
50
}
39
51
}
0 commit comments