-
Notifications
You must be signed in to change notification settings - Fork 571
/
test_raster.py
52 lines (41 loc) · 1.56 KB
/
test_raster.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
try:
from . import generic as g
except BaseException:
import generic as g
class RasterTest(g.unittest.TestCase):
def test_rasterize(self):
p = g.get_mesh('2D/wrench.dxf')
origin = p.bounds[0]
pitch = p.extents.max() / 600
resolution = g.np.ceil(p.extents / pitch).astype(int)
# rasterize with filled
filled = p.rasterize(origin=origin,
pitch=pitch,
resolution=resolution,
fill=True,
width=None)
# rasterize just the outline
outline = p.rasterize(origin=origin,
pitch=pitch,
resolution=resolution,
fill=False,
width=2.0)
# rasterize both
both = p.rasterize(origin=origin,
pitch=pitch,
resolution=resolution,
fill=True,
width=2.0)
# count the number of filled pixels
fill_cnt = g.np.array(filled).sum()
both_cnt = g.np.array(both).sum()
outl_cnt = g.np.array(outline).sum()
# filled should have more than an outline
assert fill_cnt > outl_cnt
# filled+outline should have more than outline
assert both_cnt > outl_cnt
# filled+outline should have more than filled
assert both_cnt > fill_cnt
if __name__ == '__main__':
g.trimesh.util.attach_to_log()
g.unittest.main()