test_trimesh_others.py 4.51 KB
Newer Older
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
import unittest
import openmesh

from math import pi, fabs

class Others(unittest.TestCase):

    def setUp(self):
        self.mesh = openmesh.TriMesh()
        self.vhandle = []
    
    def test_is_estimated_feature_edge(self):
        # Add some vertices
        self.vhandle.append(self.mesh.add_vertex(openmesh.Vec3d(0, 0, 0)))
        self.vhandle.append(self.mesh.add_vertex(openmesh.Vec3d(0, 1, 0)))
        self.vhandle.append(self.mesh.add_vertex(openmesh.Vec3d(1, 1, 0)))
        self.vhandle.append(self.mesh.add_vertex(openmesh.Vec3d(0, 0, 1)))

        # Add four faces
        face_vhandles = []

        face_vhandles.append(self.vhandle[0])
        face_vhandles.append(self.vhandle[1])
        face_vhandles.append(self.vhandle[2])
        self.mesh.add_face(face_vhandles)

        face_vhandles = []

        face_vhandles.append(self.vhandle[0])
        face_vhandles.append(self.vhandle[2])
        face_vhandles.append(self.vhandle[3])
        self.mesh.add_face(face_vhandles)

        face_vhandles = []

        face_vhandles.append(self.vhandle[2])
        face_vhandles.append(self.vhandle[1])
        face_vhandles.append(self.vhandle[3])
        self.mesh.add_face(face_vhandles)

        face_vhandles = []

        face_vhandles.append(self.vhandle[3])
        face_vhandles.append(self.vhandle[1])
        face_vhandles.append(self.vhandle[0])
        self.mesh.add_face(face_vhandles)

        # ===============================================
        # Setup complete
        # ===============================================


        # Check one Request only vertex normals
        # Face normals are required for vertex and halfedge normals, so
        # that prevent access to non existing properties are in place

        self.mesh.request_vertex_normals()
        self.mesh.request_halfedge_normals()
        self.mesh.request_face_normals()

        # Automatically compute all normals
        # As only vertex normals are requested and no face normals, this will compute nothing.
        self.mesh.update_normals()

        he = self.mesh.halfedges().__next__()

        self.assertTrue(self.mesh.is_estimated_feature_edge(he, 0.0))
        self.assertTrue(self.mesh.is_estimated_feature_edge(he, 0.125 * pi))
        self.assertTrue(self.mesh.is_estimated_feature_edge(he, 0.250 * pi))
        self.assertTrue(self.mesh.is_estimated_feature_edge(he, 0.375 * pi))
        self.assertTrue(self.mesh.is_estimated_feature_edge(he, 0.500 * pi))
        self.assertFalse(self.mesh.is_estimated_feature_edge(he, 0.625 * pi))
        self.assertFalse(self.mesh.is_estimated_feature_edge(he, 0.750 * pi))
        self.assertFalse(self.mesh.is_estimated_feature_edge(he, 0.875 * pi))
        self.assertFalse(self.mesh.is_estimated_feature_edge(he, 1.000 * pi))

    def test_is_estimated_feature_edge(self):
        # Test setup:
        #  1 -- 2
        #  |  / |
        #  | /  |
        #  0 -- 3

        # Add some vertices
        self.vhandle.append(self.mesh.add_vertex(openmesh.Vec3d(0, 0, 0)))
        self.vhandle.append(self.mesh.add_vertex(openmesh.Vec3d(0, 1, 0)))
        self.vhandle.append(self.mesh.add_vertex(openmesh.Vec3d(1, 1, 0)))
        self.vhandle.append(self.mesh.add_vertex(openmesh.Vec3d(1, 0, 0)))

        # Add two faces
        face_vhandles = []

        face_vhandles.append(self.vhandle[0])
        face_vhandles.append(self.vhandle[1])
        face_vhandles.append(self.vhandle[2])
        self.mesh.add_face(face_vhandles)

        face_vhandles = []

        face_vhandles.append(self.vhandle[0])
        face_vhandles.append(self.vhandle[2])
        face_vhandles.append(self.vhandle[3])
        self.mesh.add_face(face_vhandles)

        # ===============================================
        # Setup complete
        # ===============================================

        he = self.mesh.halfedge_handle(4)

        self.assertEqual(self.mesh.to_vertex_handle(he).idx(), 0)
        self.assertEqual(self.mesh.from_vertex_handle(he).idx(), 2)
        self.assertEqual(self.mesh.edge_handle(he).idx(), 2)

        eh = self.mesh.edge_handle(he)
        self.assertEqual(self.mesh.calc_dihedral_angle(eh), 0.0)

        # Modify point
        tmp = (openmesh.Vec3d(0.0, 0.0, -1.0) + openmesh.Vec3d(1.0, 1.0, -1.0)) * 0.5
        self.mesh.set_point(self.vhandle[2], tmp)

        difference = fabs(1.36944 - self.mesh.calc_dihedral_angle(eh))

        self.assertTrue(difference < 0.00001)


if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(Others)
    unittest.TextTestRunner(verbosity=2).run(suite)