-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_intersection_example.py
73 lines (48 loc) · 1.94 KB
/
test_intersection_example.py
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
import numpy as np
import pytest
from intersection_example import *
BREP_INPUTS = ['ellipsoid.brep']
@pytest.fixture(params=BREP_INPUTS)
def surface(request):
return read_brep(request.param)
@pytest.fixture
def points_and_vectors():
return generate_intersection_vectors(40., nxu=50, nxv=50)
@pytest.fixture
def lines(points_and_vectors):
return trimmed_curve_from_points(*points_and_vectors)
@pytest.fixture
def intersections(surface, lines, points_and_vectors):
return intersect(surface, lines, points_and_vectors)
def test_intersections(intersections):
_, isfailure, _ = intersections
assert not np.sum(isfailure)
def test_compare_intersection_points(intersections):
_, isfailure, xpts = intersections
xpts_expected = np.loadtxt('expected_points.csv', delimiter=',')
matching = np.all(np.isclose(xpts, xpts_expected), axis=1)
assert np.all(~matching == isfailure)
def test_plot_vtk(surface, points_and_vectors, intersections):
try:
times, isfailure, xpts = intersections
pts, vecs = points_and_vectors
write_vtk_output(surface, times, isfailure, xpts, pts, vecs)
except ImportError:
pytest.skip()
def test_plot_matplotlib(intersections, points_and_vectors):
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
times, isfailure, xpts = intersections
v = np.column_stack(points_and_vectors)
fig = plt.figure()
ax = fig.gca(projection='3d')
p = ax.scatter(*xpts.T, c=times, cmap='Blues')
bar = plt.colorbar(p)
bar.set_label('runtime $t/s$')
ax.plot(*xpts[isfailure].T, marker='o', color='r', ls='', alpha=0.8)
ax.quiver(*v[isfailure].T, color='r', alpha=0.8, pivot='tail', length=6.)
import OCC
plt.title('OCC Version: {}\nTime: {}, Failures: {}'.format(OCC.VERSION, np.sum(times), sum(isfailure)))
plt.savefig('result_{}.png'.format(OCC.VERSION))
if __name__ == "__main__":
pytest.main([__file__, '-sv'])