示例#1
0
 def setUp(self):
     verts = list(
         map(lambda x: Vertex(x), [(0.0, 0.0, 0.0), (0.0, 0.0, 0.0),
                                   (0.0, 0.5, 0.0), (1.0, 1.0, 1.0)]))
     edges = list(
         map(lambda x: Curve(x), [(0, 0, 1), (0, 0, 2), (0, 0, 3),
                                  (1, 1, 2), (1, 1, 3), (2, 2, 3)]))
     faces = list(
         map(lambda x: Face(x), [(0, 1, 2), (1, 2, 3), (2, 3, 4),
                                 (3, 4, 5)]))
     self.mesh = Mesh(verts, edges, faces)
示例#2
0
    def load_mesh(self, filename):
        """ Load mesh from surface mesh file

        Parameters
        ----------
        filename: str
            Pathstr to a CIFTI file

        Returns
        -------
        Self: an Surface object
        """
        if filename.endswith(('.inflated', '.white', '.pial', '.orig')):
            vertices, faces = freesurfer.read_geometry(filename)

        elif filename.endswith('.surf.gii'):
            geo_img = nib.load(filename)
            vertices = geo_img.darray[0].data
            faces = geo_img.darray[1].data

        else:
            suffix = os.path.split(filename)[1].split('.')[-1]
            raise ImageFileError('The format-{} is not supported at present.'.format(suffix))

        self.mesh = Mesh(vertices, faces)
示例#3
0
class GeometryOperations(unittest.TestCase):
    def setUp(self):
        verts = list(
            map(lambda x: Vertex(x), [(0.0, 0.0, 0.0), (0.0, 0.0, 0.0),
                                      (0.0, 0.5, 0.0), (1.0, 1.0, 1.0)]))
        edges = list(
            map(lambda x: Curve(x), [(0, 0, 1), (0, 0, 2), (0, 0, 3),
                                     (1, 1, 2), (1, 1, 3), (2, 2, 3)]))
        faces = list(
            map(lambda x: Face(x), [(0, 1, 2), (1, 2, 3), (2, 3, 4),
                                    (3, 4, 5)]))
        self.mesh = Mesh(verts, edges, faces)

    def test_vertex_operations(self):
        self.assertEqual(Vertex((1, 1, 1)), -Vertex((-1, -1, -1)))
        self.assertEqual(
            Vertex((1, 1, 1)) + Vertex((1, 2, 3)), Vertex((2, 3, 4)))
        self.assertEqual(
            Vertex((1, 1, 1)) - Vertex((1, 2, 3)), Vertex((0, -1, -2)))
        self.assertEqual(Vertex((1, 1, 1)) * 2, Vertex((2, 2, 2)))
        self.assertEqual(2 * Vertex((1, 1, 1)), Vertex((2, 2, 2)))
        self.assertEqual(Vertex((1, 1, 1)) + 1, Vertex((2, 2, 2)))
        self.assertEqual(1 + Vertex((1, 1, 1)), Vertex((2, 2, 2)))
        self.assertEqual(round(Vertex([1.11, 1.11, 1.11])), Vertex([1, 1, 1]))
        self.assertEqual(round(Vertex([1.11, 1.11, 1.11]), 1),
                         Vertex([1.1, 1.1, 1.1]))
        self.assertNotEqual(
            Vertex((0.05555557459592819, -0.05555557459592819, 0.0)),
            Vertex((0.05555557459592819, -0.5, 0.0)))

    def test_adj_funcs(self):
        self.assertEqual(set(get_adj_vertex(self.mesh, 0)), set([1, 2, 3]))
        self.assertEqual(set(get_adj_edges(self.mesh, 1)), set([0, 3, 4]))

    def test_remove(self):
        remove_face(self.mesh, 1)
        self.assertEqual(self.mesh.faces,
                         [[0, 1, 2], None, [2, 3, 4], [3, 4, 5]])
        self.mesh.update_indexes()
        self.assertEqual(self.mesh.faces, [[0, 1, 2], [2, 3, 4], [3, 4, 5]])

    def runTest(self):
        self.test_vertex_operations()
        self.test_adj_funcs()
        self.test_remove()
示例#4
0
class GeometryOperations(unittest.TestCase):

    def setUp(self):
        verts = list(map(lambda x: Vertex(x), [(0.0, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.5, 0.0), (1.0, 1.0, 1.0)]))
        edges = list(map(lambda x: Curve(x), [(0, 0, 1), (0, 0, 2), (0, 0, 3), (1, 1, 2), (1, 1, 3), (2, 2, 3)]))
        faces = list(map(lambda x: Face(x), [(0, 1, 2), (1, 2, 3), (2, 3, 4), (3, 4, 5)]))
        self.mesh = Mesh(verts, edges, faces)

    def test_vertex_operations(self):
        self.assertEqual(Vertex((1,1,1)), -Vertex((-1,-1,-1)))
        self.assertEqual(Vertex((1,1,1)) + Vertex((1,2,3)), Vertex((2,3,4)))
        self.assertEqual(Vertex((1,1,1)) - Vertex((1,2,3)), Vertex((0,-1,-2)))
        self.assertEqual(Vertex((1,1,1)) * 2, Vertex((2,2,2)))
        self.assertEqual(2 * Vertex((1,1,1)), Vertex((2,2,2)))
        self.assertEqual(Vertex((1,1,1)) + 1, Vertex((2,2,2)))
        self.assertEqual(1 + Vertex((1,1,1)), Vertex((2,2,2)))
        self.assertEqual(round(Vertex([1.11, 1.11, 1.11])), Vertex([1,1,1]))
        self.assertEqual(round(Vertex([1.11, 1.11, 1.11]), 1), Vertex([1.1,1.1,1.1]))
        self.assertNotEqual(Vertex((0.05555557459592819,-0.05555557459592819,0.0)), 
                            Vertex((0.05555557459592819,-0.5,0.0)))


    def test_adj_funcs(self):
        self.assertEqual(set(get_adj_vertex(self.mesh, 0)), set([1,2,3]))
        self.assertEqual(set(get_adj_edges(self.mesh, 1)), set([0,3,4]))

    def test_remove(self):
        remove_face(self.mesh, 1)
        self.assertEqual(self.mesh.faces, [[0, 1, 2], None, [2, 3, 4], [3, 4, 5]])
        self.mesh.update_indexes()
        self.assertEqual(self.mesh.faces, [[0, 1, 2], [2, 3, 4], [3, 4, 5]])

    def runTest(self):
        self.test_vertex_operations()
        self.test_adj_funcs()
        self.test_remove()
示例#5
0
 def setUp(self):
     verts = list(map(lambda x: Vertex(x), [(0.0, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.5, 0.0), (1.0, 1.0, 1.0)]))
     edges = list(map(lambda x: Curve(x), [(0, 0, 1), (0, 0, 2), (0, 0, 3), (1, 1, 2), (1, 1, 3), (2, 2, 3)]))
     faces = list(map(lambda x: Face(x), [(0, 1, 2), (1, 2, 3), (2, 3, 4), (3, 4, 5)]))
     self.mesh = Mesh(verts, edges, faces)
示例#6
0
 def setUp(self):
     verts_args = [(0.0, 0.0, 0.0), (0.5, 1.0, 0.0), (1.0, 0.0, 0.0),
                   (1.5, 0.5, 0.0), (2.0, 0.0, 0.0)]
     verts = [Vertex(args) for args in verts_args]
     self.mesh = Mesh(verts, None, None)
示例#7
0
 def setup(self):
     self.mesh = Mesh(shapes.cube(1), (1, 2, 3), color=(0.1, 1, 0))
示例#8
0
 def add_cube(x, y, z):
     self.meshes.add(Mesh(shapes.cube(1), (x, y, z)))
示例#9
0
 def add_circle(rad, sides, z, func=shapes.circle):
     self.meshes.add(
         Mesh(func(rad, sides), (0, 0, z), color=RGBA.random(0.5)))
示例#10
0
 def load_meshes_3(self):
     sides = next_randint(3, 12)
     self.meshes.add(Mesh(shapes.polygon(sides, 0.2), (0, 0, 3)))