FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SimpleBVH/tests/tests.cpp at main · geometryprocessing/SimpleBVH · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
geometryprocessing
/
SimpleBVH
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
23
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
SimpleBVH
/
tests
/
tests.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
158 lines (133 loc) · 3.78 KB
Breadcrumbs
SimpleBVH
/
tests
/
tests.cpp
Copy path
File metadata and controls
158 lines (133 loc) · 3.78 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#
include
<
SimpleBVH/BVH.hpp
>
#
include
<
catch2/catch_test_macros.hpp
>
#
include
<
iostream
>
#
include
<
fstream
>
using
namespace
SimpleBVH
;
using
namespace
Eigen
;
TEST_CASE
(
"
test_tree
"
,
"
[tests]
"
)
{
Eigen::MatrixXd
pts
(
4
,
3
);
//
clang-format off
pts <<
0
,
0
,
0
,
3
,
0
,
0
,
0
,
3
,
0
,
0
,
3
,
3
;
//
clang-format on
Eigen::MatrixXi
tri
(
4
,
3
);
//
clang-format off
tri <<
0
,
1
,
2
,
0
,
1
,
3
,
0
,
2
,
3
,
1
,
2
,
3
;
//
clang-format on
SimpleBVH::
BVH
bvh;
bvh.
init
(pts, tri,
1e-10
);
std::vector<
unsigned
int
> pairs;
bvh.
intersect_box
(
pts.
colwise
().
minCoeff
(), pts.
colwise
().
maxCoeff
(), pairs);
CHECK
(pairs.
size
() == tri.
rows
());
}
TEST_CASE
(
"
test_distance
"
,
"
[tests]
"
)
{
Eigen::MatrixXd
pts
(
4
,
3
);
//
clang-format off
pts <<
0
,
0
,
0
,
3
,
0
,
0
,
0
,
3
,
0
,
0
,
3
,
3
;
//
clang-format on
Eigen::MatrixXi
edges
(
7
,
2
);
//
clang-format off
edges <<
0
,
1
,
1
,
2
,
2
,
0
,
1
,
3
,
3
,
0
,
2
,
3
,
1
,
3
;
//
clang-format on
SimpleBVH::
BVH
bvh;
Vector3d nearest_point;
double
sq_dist;
bvh.
init
(pts, edges,
1e-10
);
bvh.
nearest_facet
(
Eigen::Vector3d
(-
1
, -
1
, -
1
), nearest_point, sq_dist);
CHECK
(pts.
row
(
0
) == nearest_point.
transpose
());
}
TEST_CASE
(
"
test_distance_2d
"
,
"
[tests]
"
)
{
Eigen::MatrixXd
pts
(
4
,
2
);
//
clang-format off
pts <<
0
,
0
,
3
,
0
,
0
,
3
,
0
,
3
;
//
clang-format on
Eigen::MatrixXi
edges
(
7
,
2
);
//
clang-format off
edges <<
0
,
1
,
1
,
2
,
2
,
0
,
1
,
3
,
3
,
0
,
2
,
3
,
1
,
3
;
//
clang-format on
SimpleBVH::
BVH
bvh;
Vector2d nearest_point;
double
sq_dist;
bvh.
init
(pts, edges,
1e-10
);
bvh.
nearest_facet
(
Vector2d
(-
1
, -
1
), nearest_point, sq_dist);
CHECK
(pts.
row
(
0
) == nearest_point.
transpose
());
}
TEST_CASE
(
"
test_distance_3d
"
,
"
[tests]
"
)
{
MatrixXd vertices;
MatrixXi facets;
std::string root =
BVH_ROOT_PATH
;
std::string mesh_filename = root +
"
/bunny.off
"
;
std::ifstream
in
(mesh_filename);
std::string token;
in >> token;
int
nv, nf, ne;
in >> nv >> nf >> ne;
vertices.
resize
(nv,
3
);
facets.
resize
(nf,
3
);
for
(
int
i =
0
; i < nv; ++i) {
in >>
vertices
(i,
0
) >>
vertices
(i,
1
) >>
vertices
(i,
2
);
}
for
(
int
i =
0
; i < nf; ++i) {
int
s;
in >> s >>
facets
(i,
0
) >>
facets
(i,
1
) >>
facets
(i,
2
);
assert
(s ==
3
);
}
Vector3d min = vertices.
colwise
().
minCoeff
();
Vector3d max = vertices.
colwise
().
maxCoeff
();
MatrixXd pts =
MatrixXd::Random
(
100
,
3
);
for
(
int
d =
0
; d <
3
; ++d) {
pts.
col
(d).
array
() +=
1
;
pts.
col
(d) *= (
max
(d) -
min
(d)) /
2
;
pts.
col
(d).
array
() +=
min
(d);
}
//
MatrixXd pts(1, 3);
//
pts << 0.2, -0.2, 0.4;
SimpleBVH::
BVH
bvh;
bvh.
init
(vertices, facets,
1e-10
);
std::ofstream
out
(
"
res.obj
"
);
Vector3d nearest_point;
double
sq_dist;
for
(
int
i =
0
; i < pts.
rows
(); ++i) {
bvh.
nearest_facet
(pts.
row
(i), nearest_point, sq_dist);
out <<
"
v
"
<<
pts
(i,
0
) <<
"
"
<<
pts
(i,
1
) <<
"
"
<<
pts
(i,
2
)
<<
"
\n
"
;
out <<
"
v
"
<<
nearest_point
(
0
) <<
"
"
<<
nearest_point
(
1
) <<
"
"
<<
nearest_point
(
2
) <<
"
\n
"
;
out <<
"
l
"
<<
2
* i +
1
<<
"
"
<<
2
* i +
2
<<
"
\n\n
"
;
}
//
std::ofstream out1("res1.obj");
//
for (int i = 0; i < vertices.rows(); ++i) {
//
out1 << "v " << vertices(i, 0) << " " << vertices(i, 1) << " "
//
<< vertices(i, 2) << "\n";
//
}
//
out1 << "f " << facets(66, 0) + 1 << " " << facets(66, 1) + 1 << " "
//
<< facets(66, 2) + 1 << "\n";
}
Back
|
FazBrowse Home
|
New Git URL