File: test_curvature.py

package info (click to toggle)
trimesh 4.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 33,416 kB
  • sloc: python: 35,596; makefile: 96; javascript: 85; sh: 38
file content (48 lines) | stat: -rw-r--r-- 1,728 bytes parent folder | download
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
try:
    from . import generic as g
except BaseException:
    import generic as g


class CurvatureTest(g.unittest.TestCase):
    def test_gaussian_curvature(self):
        for radius in g.np.linspace(0.25, 2.0, 10):
            m = g.trimesh.creation.icosphere(radius=radius)

            gauss = g.trimesh.curvature.discrete_gaussian_curvature_measure(
                mesh=m, points=m.vertices, radius=radius * 2.0
            ) / (4 * g.np.pi)
            assert g.np.allclose(gauss, 1.0, atol=0.01)

        # a torus should have approximately half its vertices with positive
        # curvature, and half with negative
        t = g.get_mesh("torus.STL")
        gauss = g.trimesh.curvature.discrete_gaussian_curvature_measure(
            mesh=t, points=t.vertices, radius=1.0
        )
        ratio = float((gauss < 0.0).sum()) / float(len(gauss))
        assert g.np.isclose(ratio, 0.5, atol=0.2)

    def test_mean_curvature(self):
        m = g.trimesh.creation.icosphere()
        mean = g.trimesh.curvature.discrete_mean_curvature_measure(m, m.vertices, 2.0) / (
            4 * g.np.pi
        )
        # Check mean curvature for unit sphere is 1.0
        assert g.np.allclose(mean, 1.0, atol=0.01)

    def test_vertex_defect(self):
        # a subdivided box will only have corners and planar regions
        # so all vertex defects should be 0 or 90 degrees
        m = g.trimesh.primitives.Box().subdivide()
        assert g.np.logical_or(
            g.np.isclose(m.vertex_defects, 0.0),
            g.np.isclose(m.vertex_defects, g.np.pi / 2.0),
        ).all()

        assert len(m.vertex_defects) == len(m.vertices)


if __name__ == "__main__":
    g.trimesh.util.attach_to_log()
    g.unittest.main()