test_trimesh_circulator_face_vertex.py 1.68 KB
Newer Older
1 2 3
import unittest
import openmesh

4 5
import numpy as np

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

    def setUp(self):
        self.mesh = openmesh.TriMesh()

        # Add some vertices
        self.vhandle = []

14 15 16 17 18
        self.vhandle.append(self.mesh.add_vertex(np.array([0, 1, 0])))
        self.vhandle.append(self.mesh.add_vertex(np.array([1, 0, 0])))
        self.vhandle.append(self.mesh.add_vertex(np.array([2, 1, 0])))
        self.vhandle.append(self.mesh.add_vertex(np.array([0,-1, 0])))
        self.vhandle.append(self.mesh.add_vertex(np.array([2,-1, 0])))
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
        
        # Add four faces
        self.fh0 = self.mesh.add_face(self.vhandle[0], self.vhandle[1], self.vhandle[2])
        self.mesh.add_face(self.vhandle[1], self.vhandle[3], self.vhandle[4])
        self.mesh.add_face(self.vhandle[0], self.vhandle[3], self.vhandle[1])
        self.mesh.add_face(self.vhandle[2], self.vhandle[1], self.vhandle[4])

        '''
        Test setup:
            0 ==== 2
            |\  0 /|
            | \  / |
            |2  1 3|
            | /  \ |
            |/  1 \|
            3 ==== 4
        '''

    def test_face_vertex_iter_without_increment(self):
        self.assertEqual(self.fh0.idx(), 0)
    
        # Iterate around face 0 at the top
        fv_it = openmesh.FaceVertexIter(self.mesh, self.fh0)
42 43 44 45 46
        self.assertEqual(next(fv_it).idx(), 0)
        self.assertEqual(next(fv_it).idx(), 1)
        self.assertEqual(next(fv_it).idx(), 2)
        with self.assertRaises(StopIteration):
            next(fv_it)
47 48 49 50 51
        

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