def voronoiInner(fn):
    """Determine the inner voronoi diagram corresponding with a triangulated surface.
    
    fn is the file name of a surface, including the extension (.off, .stl, .gts, .neu or .smesh)
    The output are the voronoi nodes and the corresponding radii of the voronoi spheres.
    """
    S = surface.TriSurface.read(fn)
    fn,ftype = os.path.splitext(fn)
    ftype = ftype.strip('.').lower()
    if ftype != 'smesh':
        S.write('%s.smesh' %fn)
    sta,out = runCommand('tetgen -zp %s.smesh' %fn)
    #information tetrahedra
    elems = tetgen.readElems('%s.1.ele' %fn)[0]
    nodes = tetgen.readNodes('%s.1.node' %fn)[0].astype(float64)
    #calculate surface normal for each point
    elemsS = array(S.elems)
    NT = S.areaNormals()[1]
    NP = zeros([nodes.shape[0],3])
    for i in [0,1,2]:
        NP[elemsS[:,i]] = NT
    #calculate centrum circumsphere of each tetrahedron
    centers = circumcenter(nodes,elems)[0]
    #check if circumcenter falls within the geomety described by the surface
    ie = column_stack([((nodes[elems[:,j]] - centers[:])*NP[elems[:,j]]).sum(axis=-1) for j in [0,1,2,3]])
    ie = ie[:,:]>=0
    w = where(ie.all(1))[0]
    elemsInner = elems[w]
    nodesVorInner = centers[w]
    #calculate the radii of the voronoi spheres
    vec = nodesVorInner[:]-nodes[elemsInner[:,0]]
    rad = sqrt((vec*vec).sum(axis=-1))
    return nodesVorInner,rad
Exemple #2
0
def voronoiInner(fn):
    """Determine the inner voronoi diagram corresponding with a triangulated surface.
    
    fn is the file name of a surface, including the extension (.off, .stl, .gts, .neu or .smesh)
    The output are the voronoi nodes and the corresponding radii of the voronoi spheres.
    """
    S = trisurface.TriSurface.read(fn)
    fn,ftype = os.path.splitext(fn)
    ftype = ftype.strip('.').lower()
    if ftype != 'smesh':
        S.write('%s.smesh' %fn)
    sta,out = runCommand('tetgen -zp %s.smesh' %fn)
    #information tetrahedra
    elems = tetgen.readElems('%s.1.ele' %fn)[0]
    nodes = tetgen.readNodes('%s.1.node' %fn)[0].astype(float64)
    #calculate surface normal for each point
    elemsS = array(S.elems)
    NT = S.areaNormals()[1]
    NP = zeros([nodes.shape[0],3])
    for i in [0,1,2]:
        NP[elemsS[:,i]] = NT
    #calculate centrum circumsphere of each tetrahedron
    centers = circumcenter(nodes,elems)[0]
    #check if circumcenter falls within the geomety described by the surface
    ie = column_stack([((nodes[elems[:,j]] - centers[:])*NP[elems[:,j]]).sum(axis=-1) for j in [0,1,2,3]])
    ie = ie[:,:]>=0
    w = where(ie.all(1))[0]
    elemsInner = elems[w]
    nodesVorInner = centers[w]
    #calculate the radii of the voronoi spheres
    vec = nodesVorInner[:]-nodes[elemsInner[:,0]]
    radii = sqrt((vec*vec).sum(axis=-1))
    return nodesVorInner,radii
def read_tetgen(surface=True, volume=True):
    """Read a tetgen model from files  fn.node, fn.ele, fn.smesh."""
    ftype = ''
    if surface:
        ftype += ' *.smesh'
    if volume:
        ftype += ' *.ele'
    fn = askFilename(GD.cfg['workdir'],"Tetgen files (%s)" % ftype,exist=True)
    nodes = elems =surf = None
    if fn:
        chdir(fn)
        project = utils.projectName(fn)
        set_project(project)
        nodes,nodenrs = tetgen.readNodes(project+'.node')
#        print "Read %d nodes" % nodes.shape[0]
        if volume:
            elems,elemnrs,elemattr = tetgen.readElems(project+'.ele')
            print "Read %d tetraeders" % elems.shape[0]
            PF['volume'] = (nodes,elems)
        if surface:
            surf = tetgen.readSurface(project+'.smesh')
            print "Read %d triangles" % surf.shape[0]
            PF['surface'] = (nodes,surf)
    if surface:
        show_surface()
    else:
        show_volume()
Exemple #4
0
def read_tetgen(fn):
    """Read a tetgen model from files  fn.node, fn.ele, fn.smesh."""
    nodes = tetgen.readNodes(fn+'.node')
    print "Read %d nodes" % nodes.shape[0]
    elems = tetgen.readElems(fn+'.ele')
    print "Read %d tetraeders" % elems.shape[0]
    surf = tetgen.readSurface(fn+'.smesh')
    print "Read %d triangles" % elems.shape[0]
    return nodes,elems,surf
def stl_to_abaqus(fn):
    print "Converting %s to Abaqus .INP format" % fn
    stl_tetgen(fn)
    fb = os.path.splitext(fn)[0]
    nodes = tetgen.readNodes(fb+'.1.node')
    elems = tetgen.readElems(fb+'.1.ele')
    faces = tetgen.readSurface(fb+'.1.smesh')
    print "Exporting surface model"
    abq_export(fb+'-surface.inp',nodes,faces,'S3',"Abaqus model generated by tetgen from surface in STL file %s" % fn)
    print "Exporting volume model"
    abq_export(fb+'-volume.inp',nodes,elems,'C3D%d' % elems.shape[1],"Abaqus model generated by tetgen from surface in STL file %s" % fn)
def read_tetgen(filename):
    """Read a tetgen tetraeder model.

    filename is the base of the path of the input files.
    For a filename 'proj', nodes are expected in 'proj.1.node'  and
    elems are in file 'proj.1.ele'.
    """
    nodes = tetgen.readNodes(filename+'.1.node')
    print("Read %d nodes" % nodes.shape[0])
    elems = tetgen.readElems(filename+'.1.ele')
    print("Read %d tetraeders" % elems.shape[0])
    return nodes,elems
Exemple #7
0
def read_tetgen(filename):
    """Read a tetgen tetraeder model.

    filename is the base of the path of the input files.
    For a filename 'proj', nodes are expected in 'proj.1.node'  and
    elems are in file 'proj.1.ele'.
    """
    nodes = tetgen.readNodes(filename + '.1.node')
    print("Read %d nodes" % nodes.shape[0])
    elems = tetgen.readElems(filename + '.1.ele')
    print("Read %d tetraeders" % elems.shape[0])
    return nodes, elems
def stl_to_abaqus(fn):
    print("Converting %s to Abaqus .INP format" % fn)
    tetgen.runTetgen(fn)
    fb = os.path.splitext(fn)[0]
    nodes = tetgen.readNodes(fb+'.1.node')
    elems = tetgen.readElems(fb+'.1.ele')
    faces = tetgen.readSurface(fb+'.1.smesh')
    print("Exporting surface model")
    smesh = Mesh(nodes,faces,eltype='S3')
    fe_abq.exportMesh(fb+'-surface.inp',smesh,"Abaqus model generated by tetgen from surface in STL file %s" % fn)
    print("Exporting volume model")
    vmesh = Mesh(nodes,elems,eltype='C3D%d' % elems.shape[1])
    abq_export(fb+'-volume.inp',vmesh,"Abaqus model generated by tetgen from surface in STL file %s" % fn)
Exemple #9
0
def stl_to_abaqus(fn):
    print("Converting %s to Abaqus .INP format" % fn)
    tetgen.runTetgen(fn)
    fb = os.path.splitext(fn)[0]
    nodes = tetgen.readNodes(fb + '.1.node')
    elems = tetgen.readElems(fb + '.1.ele')
    faces = tetgen.readSurface(fb + '.1.smesh')
    print("Exporting surface model")
    smesh = Mesh(nodes, faces, eltype='S3')
    fe_abq.exportMesh(
        fb + '-surface.inp', smesh,
        "Abaqus model generated by tetgen from surface in STL file %s" % fn)
    print("Exporting volume model")
    vmesh = Mesh(nodes, elems, eltype='C3D%d' % elems.shape[1])
    abq_export(
        fb + '-volume.inp', vmesh,
        "Abaqus model generated by tetgen from surface in STL file %s" % fn)
def read_tetgen(surface=True, volume=True):
    """Read a tetgen model from files  fn.node, fn.ele, fn.smesh."""
    global nodes,elems,surf
    fn = askFilename(GD.cfg['workdir'],"Tetgen files (*.node)")
    nodes = elems =surf = None
    if fn:
        os.chdir(os.path.dirname(fn))
        message("Your current workdir is %s" % os.getcwd())
        project = os.path.splitext(fn)[0]
        nodes = tetgen.readNodes(project+'.node')
        print "Read %d nodes" % nodes.shape[0]
        if volume:
            elems = tetgen.readElems(project+'.ele')
            print "Read %d tetraeders" % elems.shape[0]
        if surface:
            surf = tetgen.readSurface(project+'.smesh')
            print "Read %d triangles" % surf.shape[0]
    show_tetgen_surface()
def voronoi(fn):
    """Determine the voronoi diagram corresponding with a triangulated surface.
    
    fn is the file name of a surface, including the extension (.off, .stl, .gts, .neu or .smesh)
    The voronoi diagram is determined by Tetgen.
    The output are the voronoi nodes and the corresponding radii of the voronoi spheres.
    """
    S = surface.TriSurface.read(fn)
    fn,ftype = os.path.splitext(fn)
    ftype = ftype.strip('.').lower()
    if ftype != 'smesh':
        S.write('%s.smesh' %fn)
    sta,out = runCommand('tetgen -zpv %s.smesh' %fn)
    #information tetrahedra
    elems = tetgen.readElems('%s.1.ele' %fn)[0]
    nodes = tetgen.readNodes('%s.1.node' %fn)[0]
    #voronoi information
    nodesVor = tetgen.readNodes('%s.1.v.node' %fn)[0]
    #calculate the radii of the voronoi spheres
    vec = nodesVor[:]-nodes[elems[:,0]]
    rad = sqrt((vec*vec).sum(axis=-1))
    return nodesVor,rad
Exemple #12
0
def voronoi(fn):
    """Determine the voronoi diagram corresponding with a triangulated surface.
    
    fn is the file name of a surface, including the extension (.off, .stl, .gts, .neu or .smesh)
    The voronoi diagram is determined by Tetgen.
    The output are the voronoi nodes and the corresponding radii of the voronoi spheres.
    """
    S = trisurface.TriSurface.read(fn)
    fn,ftype = os.path.splitext(fn)
    ftype = ftype.strip('.').lower()
    if ftype != 'smesh':
        S.write('%s.smesh' %fn)
    sta,out = runCommand('tetgen -zpv %s.smesh' %fn)
    #information tetrahedra
    elems = tetgen.readElems('%s.1.ele' %fn)[0]
    nodes = tetgen.readNodes('%s.1.node' %fn)[0]
    #voronoi information
    nodesVor = tetgen.readNodes('%s.1.v.node' %fn)[0]
    #calculate the radii of the voronoi spheres
    vec = nodesVor[:]-nodes[elems[:,0]]
    radii = sqrt((vec*vec).sum(axis=-1))
    return nodesVor,radii