test_split_copy.py 2.55 KB
Newer Older
1 2 3
import unittest
import openmesh

4 5
import numpy as np

6 7 8 9 10 11 12
class SplitCopy(unittest.TestCase):

    def test_split_copy_triangle_mesh(self):
        self.mesh = openmesh.TriMesh()
        self.vhandle = []
        
        # Add some vertices
13 14 15 16
        self.vhandle.append(self.mesh.add_vertex(np.array([0, 0, 0])))
        self.vhandle.append(self.mesh.add_vertex(np.array([0, 1, 0])))
        self.vhandle.append(self.mesh.add_vertex(np.array([1, 1, 0])))
        self.vhandle.append(self.mesh.add_vertex(np.array([0.25, 0.25, 0])))
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

        # Add one face
        face_vhandles = []
        
        face_vhandles.append(self.vhandle[2])
        face_vhandles.append(self.vhandle[1])
        face_vhandles.append(self.vhandle[0])
        
        fh = self.mesh.add_face(face_vhandles)

        # Test setup:
        #  1 === 2
        #  |   /
        #  |  /
        #  | /
        #  0
        
        # Set property
Alexander Dielen's avatar
Alexander Dielen committed
35
        self.mesh.set_face_property("fprop_int", fh, 999)
36 37 38 39 40

        # Split face with new vertex
        self.mesh.split_copy(fh, self.vhandle[3])

        # Check setup
Alexander Dielen's avatar
Alexander Dielen committed
41 42
        for fh in self.mesh.faces():
            self.assertEqual(self.mesh.face_property("fprop_int", fh), 999)
43 44 45 46 47 48

    def test_split_copy_polymesh(self):
        self.mesh = openmesh.PolyMesh()
        self.vhandle = []
        
        # Add some vertices
49 50 51 52 53
        self.vhandle.append(self.mesh.add_vertex(np.array([0, 0, 0])))
        self.vhandle.append(self.mesh.add_vertex(np.array([0, 1, 0])))
        self.vhandle.append(self.mesh.add_vertex(np.array([1, 1, 0])))
        self.vhandle.append(self.mesh.add_vertex(np.array([1, 0, 0])))
        self.vhandle.append(self.mesh.add_vertex(np.array([0.5, 0.5, 0])))
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
        
        # Add one face
        face_vhandles = []
        
        face_vhandles.append(self.vhandle[0])
        face_vhandles.append(self.vhandle[1])
        face_vhandles.append(self.vhandle[2])
        face_vhandles.append(self.vhandle[3])
        
        fh = self.mesh.add_face(face_vhandles)
        
        # Test setup:
        #  1 === 2
        #  |     |
        #  |     |
        #  |     |
        #  0 === 3
        
        # Set property
Alexander Dielen's avatar
Alexander Dielen committed
73
        self.mesh.set_face_property("fprop_int", fh, 999)
74 75 76 77 78
        
        # Split face with new vertex
        self.mesh.split_copy(fh, self.vhandle[4])
        
        # Check setup
Alexander Dielen's avatar
Alexander Dielen committed
79 80
        for fh in self.mesh.faces():
            self.assertEqual(self.mesh.face_property("fprop_int", fh), 999)
81 82 83 84 85


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