test_split_copy.py 2.7 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
import unittest
import openmesh

class SplitCopy(unittest.TestCase):

    def test_split_copy_triangle_mesh(self):
        self.mesh = openmesh.TriMesh()
        self.vhandle = []
        
        # 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.25, 0.25, 0)))

        # 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
        fprop_int = openmesh.FPropHandle()
        self.mesh.add_property(fprop_int)
        self.mesh.set_property(fprop_int, fh, 999)

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

        # Check setup
        for f in self.mesh.faces():
            self.assertEqual(self.mesh.property(fprop_int, f), 999)

    def test_split_copy_polymesh(self):
        self.mesh = openmesh.PolyMesh()
        self.vhandle = []
        
        # 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)))
        self.vhandle.append(self.mesh.add_vertex(openmesh.Vec3d(0.5, 0.5, 0)))
        
        # 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
        fprop_int = openmesh.FPropHandle()
        self.mesh.add_property(fprop_int)
        self.mesh.set_property(fprop_int, fh, 999)
        
        # Split face with new vertex
        self.mesh.split_copy(fh, self.vhandle[4])
        
        # Check setup
        for f in self.mesh.faces():
            self.assertEqual(self.mesh.property(fprop_int, f), 999)


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