コード例 #1
0
ファイル: core.py プロジェクト: NeuroArchive/morphforge
    def finalise(self, plyfilename):

        m = TriangleMesh.merge(meshes=self.meshes)
        ply = MeshWriterPLY.build_string(m)

        with self.global_scope.getFileObjWrite(plyfilename) as f:
            f.write(ply)
コード例 #2
0
ファイル: core.py プロジェクト: bmerrison/morphforge
    def finalise(self, plyfilename):

        m = TriangleMesh.merge(meshes=self.meshes)
        ply = MeshWriterPLY.build_string(m)

        with self.global_scope.getFileObjWrite(plyfilename) as f:
            f.write(ply)
コード例 #3
0
    def build(cls, m, plot=True, region_color_map=None):
        import gts
        surface_sections = cls.buildsurface_sectiondict(m.to_tree())

        meshes = []
        for (sect, sect_surface) in surface_sections.iteritems():
            print sect
            assert sect.region is not None

            # Look up the region color:
            if not sect.region.name in region_color_map:
                for (rgn, color) in region_color_map.iteritems():
                    print rgn.name, rgn, color
                print 'Looking for:', sect.region.name, sect.region
                assert False, "Can't find region in color map!"
            sect_color = region_color_map[sect.region.name]
            print sect_color

            vertex_objs = sect_surface.vertices()
            N = len(vertex_objs)
            dShape = (N, 3)
            v = np.array([(v.x, v.y, v.z)
                          for v in vertex_objs]).reshape(dShape)

            color = np.array((sect_color.r, sect_color.g, sect_color.b))
            colors = np.repeat(color, len(vertex_objs)).reshape(dShape,
                                                                order='F')

            triangles = sect_surface.face_indices(vertex_objs)

            tm = TriangleMesh(vertices=v,
                              triangles=triangles,
                              vertex_colors=colors)
            meshes.append(tm)
        m = TriangleMesh.merge(meshes=meshes)

        if plot:
            from mayavi import mlab
            mlab.figure(size=(1024, 768))
            for surface in surface_sections:
                (x, y, z, t) = gts.get_coords_and_face_indices(surface, True)
                mlab.triangular_mesh(x, y, z, t, color=(0.9, 0.9, 0.9))
            mlab.show()

        return m
コード例 #4
0
    def build(cls, m, plot=True, region_color_map=None):
        import gts
        surface_sections = cls.buildsurface_sectiondict(m.to_tree())

        meshes = []
        for (sect, sect_surface) in surface_sections.iteritems():
            print sect
            assert sect.region is not None

            # Look up the region color:
            if not sect.region.name in region_color_map:
                for (rgn, color) in region_color_map.iteritems():
                    print rgn.name, rgn, color
                print 'Looking for:', sect.region.name, sect.region
                assert False, "Can't find region in color map!"
            sect_color = region_color_map[sect.region.name]
            print sect_color

            vertex_objs = sect_surface.vertices()
            N = len(vertex_objs)
            dShape = (N, 3)
            v = np.array([(v.x, v.y, v.z) for v in vertex_objs]).reshape(dShape)

            color = np.array((sect_color.r, sect_color.g, sect_color.b))
            colors = np.repeat(color, len(vertex_objs)).reshape(dShape, order='F')

            triangles = sect_surface.face_indices(vertex_objs)

            tm = TriangleMesh(vertices=v, triangles=triangles,
                              vertex_colors=colors)
            meshes.append(tm)
        m = TriangleMesh.merge(meshes=meshes)

        if plot:
            from mayavi import mlab
            mlab.figure(size=(1024, 768))
            for surface in surface_sections:
                (x, y, z, t) = gts.get_coords_and_face_indices(surface,
                        True)
                mlab.triangular_mesh(x, y, z, t, color=(0.9, 0.9, 0.9))
            mlab.show()

        return m