Ejemplo n.º 1
0
def import_obj(path):
    Blender.Window.WaitCursor(1)
    name = path.split('\\')[-1].split('/')[-1]
    # parse the file

    m = MorphologyLoader.fromSWC(src=open(path), morphname="TestMorphlogy4")

    mf_mesh = MeshBuilderRings.build(morph=m)
    #MeshWriterPLY.write(mesh, '/tmp/testmesh.ply')

    mesh = Blender.NMesh.New(name) # create a new mesh
    for i in range(mf_mesh.nVertices):
      mesh.verts.append(Blender.NMesh.Vert(mf_mesh.vertices[i,0], mf_mesh.vertices[i,1],  mf_mesh.vertices[i,2]))

    for i in range(mf_mesh.nTriangles):
      faceVertList = [
          mesh.verts[mf_mesh.triangles[0]],
          mesh.verts[mf_mesh.triangles[1]],
          mesh.verts[mf_mesh.triangles[2]],
        ]
      newFace = Blender.NMesh.Face(faceVertList)
      mesh.addFace(newFace)


    ob = Blender.Object.New('Mesh', name)  # Mesh must be spelled just this--it is a specific type
    ob.link(mesh)  # tell the object to use the mesh we just made
    scn = Blender.Scene.GetCurrent()
    for o in scn.getChildren():
        o.sel = 0

    scn.link(ob)  # link the object to the current scene
    ob.sel = 1
    ob.Layers = scn.Layers
    Blender.Window.WaitCursor(0)
    Blender.Window.RedrawAll()
Ejemplo n.º 2
0
    def showSimpleCylinders(self):
        """
        Slightly more complex plotting - plot each
        section as a cylinders.
        """

        import sys
        sys.path.append('/usr/share/pyshared/')

        from morphforge.morphology.mesh import MeshBuilderRings
        # MonkeyPatchMayaVi()

        from mayavi import mlab

        assert len(self.morphs) == 1
        mesh = MeshBuilderRings().build(self.morphs[0])

        @mlab.show
        def _showSimpleCylinders():
            mlab.triangular_mesh(mesh.vertices[:, 0],
                                 mesh.vertices[:, 1],
                                 mesh.vertices[:, 2],
                                 mesh.triangles,
                                 colormap=self.colormap)

        _showSimpleCylinders()
Ejemplo n.º 3
0
def swc_to_ply(swc_path, ply_path=None):
    ply_path = ply_path or swc_path.replace('.swc', '.ply')
    #morphologies = MorphologyLoader.fromSWCSet(src=open(swc_path))
    SWCLoader.LoadSet(src=open(swc_path), morphname="UnknownSWC", regionNames=regionNames)

    meshes = [MeshBuilderRings.build(morph) for morph in morphologies]

    # Save the individual meshes:
    for i, mesh in enumerate(meshes):
        MeshWriterPLY.write(mesh, ply_path.replace('.ply', '_%d.ply' % i))

    # Save a set of meshes:
    combined_mesh = TriangleMesh.merge(meshes)
    MeshWriterPLY.write(combined_mesh, ply_path)
Ejemplo n.º 4
0
    def make_video(self):
        """
        Slightly more complex plotting - plot each
        section as a cylinders.
        """

        import sys
        sys.path.append('/usr/share/pyshared/')

        from morphforge.morphology.mesh import MeshBuilderRings
        # MonkeyPatchMayaVi()

        from mayavi import mlab

        assert len(self.morphs) == 1
        mesh = MeshBuilderRings().build(self.morphs[0])

        @mlab.show
        @mlab.animate(delay=100)  #, ui=False) #(delay=500, ui=False)
        def _showSimpleCylinders():

            fig = mlab.figure(bgcolor=None,
                              fgcolor=None,
                              engine=None,
                              size=(1024, 768))
            mlab.triangular_mesh(mesh.vertices[:, 0],
                                 mesh.vertices[:, 1],
                                 mesh.vertices[:, 2],
                                 mesh.triangles,
                                 colormap=self.colormap)

            for i in itertools.count():
                print i
                fig.scene.camera.azimuth(0.1)
                mlab.savefig('/home/michael/Desktop/out/O%04d.png' % i)
                fig.scene.render()
                if i > 3600:
                    break
                yield None

        _showSimpleCylinders()
Ejemplo n.º 5
0
def import_obj(path):
    Blender.Window.WaitCursor(1)
    name = path.split('\\')[-1].split('/')[-1]
    # parse the file

    m = MorphologyLoader.fromSWC(src=open(path), morphname="TestMorphlogy4")

    mf_mesh = MeshBuilderRings.build(morph=m)
    #MeshWriterPLY.write(mesh, '/tmp/testmesh.ply')

    mesh = Blender.NMesh.New(name)  # create a new mesh
    for i in range(mf_mesh.nVertices):
        mesh.verts.append(
            Blender.NMesh.Vert(mf_mesh.vertices[i, 0], mf_mesh.vertices[i, 1],
                               mf_mesh.vertices[i, 2]))

    for i in range(mf_mesh.nTriangles):
        faceVertList = [
            mesh.verts[mf_mesh.triangles[0]],
            mesh.verts[mf_mesh.triangles[1]],
            mesh.verts[mf_mesh.triangles[2]],
        ]
        newFace = Blender.NMesh.Face(faceVertList)
        mesh.addFace(newFace)

    ob = Blender.Object.New(
        'Mesh', name)  # Mesh must be spelled just this--it is a specific type
    ob.link(mesh)  # tell the object to use the mesh we just made
    scn = Blender.Scene.GetCurrent()
    for o in scn.getChildren():
        o.sel = 0

    scn.link(ob)  # link the object to the current scene
    ob.sel = 1
    ob.Layers = scn.Layers
    Blender.Window.WaitCursor(0)
    Blender.Window.RedrawAll()