Example #1
0
def loadOFMesh(polyMeshFolder, convertToMeters=1, innerMesh=True):
    """Convert OpenFOAM mesh to a Rhino Mesh."""
    if not polyMeshFolder:
        return

    pff = tuple(f for f in os.listdir(polyMeshFolder) if f.startswith('points'))
    fff = tuple(f for f in os.listdir(polyMeshFolder) if f.startswith('faces'))

    if pff:
        pf = os.path.join(polyMeshFolder, pff[0])
    else:
        raise ValueError('Failed to find points file at {}'.format(polyMeshFolder))
    if fff:
        ff = os.path.join(polyMeshFolder, fff[0])
    else:
        raise ValueError('Failed to find faces file at {}'.format(polyMeshFolder))

    pts = loadOFPointsFile(pf)
    faces = loadOFFacesFile(ff, innerMesh)

    # create the mesh
    dsPts = (DSGeometry.Point.ByCoordinates(*p) for p in pts)
    ind = (i for face in faces for t in _triangulate(face) for i in t)
    mesh = MeshToolkit.Mesh.ByVerticesAndIndices(dsPts, ind)
    # scale mesh to Rhion units if not meters
    if convertToMeters != 1:
        mesh.Scale(1.0 / convertToMeters)

    return mesh
Example #2
0
def loadOFMesh(polyMeshFolder, convertToMeters=1):
    """Convert OpenFOAM mesh to a Rhino Mesh."""
    if not polyMeshFolder:
        return

    pff = tuple(f for f in os.listdir(polyMeshFolder) if f.startswith('points'))
    fff = tuple(f for f in os.listdir(polyMeshFolder) if f.startswith('faces'))

    if pff:
        pf = os.path.join(polyMeshFolder, pff[0])
    else:
        raise ValueError('Failed to find points file at {}'.format(polyMeshFolder))
    if fff:
        ff = os.path.join(polyMeshFolder, fff[0])
    else:
        raise ValueError('Failed to find faces file at {}'.format(polyMeshFolder))

    pts = loadOFPointsFile(pf)
    faces = loadOFFacesFile(ff)

    # create the mesh
    dsPts = (DSGeometry.Point.ByCoordinates(*p) for p in pts)
    ind = (i for face in faces for t in _triangulate(face) for i in t)
    mesh = MeshToolkit.Mesh.ByVerticesAndIndices(dsPts, ind)
    # scale mesh to Rhion units if not meters
    if convertToMeters != 1:
        mesh.Scale(1.0 / convertToMeters)

    return mesh
Example #3
0
def loadOFMesh(polyMeshFolder, convertToMeters=1, innerMesh=True):
    """Convert OpenFOAM mesh to a Rhino Mesh."""
    if not polyMeshFolder:
        return

    pff = tuple(f for f in os.listdir(polyMeshFolder)
                if f.startswith('points'))
    fff = tuple(f for f in os.listdir(polyMeshFolder) if f.startswith('faces'))

    if pff:
        pf = os.path.join(polyMeshFolder, pff[0])
    else:
        raise ValueError(
            'Failed to find points file at {}'.format(polyMeshFolder))
    if fff:
        ff = os.path.join(polyMeshFolder, fff[0])
    else:
        raise ValueError(
            'Failed to find faces file at {}'.format(polyMeshFolder))

    pts = loadOFPointsFile(pf)
    faces = loadOFFacesFile(ff, innerMesh)

    # create the mesh
    mesh = rc.Geometry.Mesh()

    for p in pts:
        mesh.Vertices.Add(rc.Geometry.Point3d(*p))

    for face in faces:
        if len(face) < 5:
            mesh.Faces.AddFace(*face)
        elif len(face) == 5:
            mesh.Faces.AddFace(*face[:3])
            mesh.Faces.AddFace(face[0], face[2], face[3], face[4])
        elif len(face) == 8:
            mesh.Faces.AddFace(*face[:4])
            mesh.Faces.AddFace(face[0], face[3], face[4], face[7])
            mesh.Faces.AddFace(face[7], face[4], face[5], face[6])
        else:
            try:
                mesh.Faces.AddFace(*face[:4])
                mesh.Faces.AddFace(*face[:1] + (face[4:]))
            except:
                msg = "One of the faces has %d vertices." % len(face)
                print msg

    # scale mesh to Rhion units if not meters
    if convertToMeters != 1:
        mesh.Scale(1.0 / convertToMeters)

    return mesh
Example #4
0
def loadOFPoints(polyMeshFolder, convertToMeters=1):
    """Load OpenFOAM points as Rhino points."""
    if not polyMeshFolder:
        return

    pff = tuple(f for f in os.listdir(polyMeshFolder) if f.startswith("points"))

    if pff:
        pf = os.path.join(polyMeshFolder, pff[0])
    else:
        raise ValueError("Failed to find points file at {}".format(polyMeshFolder))

    pts = loadOFPointsFile(pf)
    return tuple(rc.Geometry.Point3d(*p) for p in pts)
Example #5
0
def loadOFPoints(polyMeshFolder, convertToMeters=1):
    """Load OpenFOAM points as Rhino points."""
    if not polyMeshFolder:
        return

    pff = tuple(f for f in os.listdir(polyMeshFolder) if f.startswith('points'))

    if pff:
        pf = os.path.join(polyMeshFolder, pff[0])
    else:
        raise ValueError('Failed to find points file at {}'.format(polyMeshFolder))

    pts = loadOFPointsFile(pf)
    return tuple(DSGeometry.Point.ByCoordinates(*p) for p in pts)
Example #6
0
def loadOFMesh(polyMeshFolder, convertToMeters=1):
    """Convert OpenFOAM mesh to a Rhino Mesh."""
    if not polyMeshFolder:
        return

    pff = tuple(f for f in os.listdir(polyMeshFolder) if f.startswith("points"))
    fff = tuple(f for f in os.listdir(polyMeshFolder) if f.startswith("faces"))

    if pff:
        pf = os.path.join(polyMeshFolder, pff[0])
    else:
        raise ValueError("Failed to find points file at {}".format(polyMeshFolder))
    if fff:
        ff = os.path.join(polyMeshFolder, fff[0])
    else:
        raise ValueError("Failed to find faces file at {}".format(polyMeshFolder))

    pts = loadOFPointsFile(pf)
    faces = loadOFFacesFile(ff)

    # create the mesh
    mesh = rc.Geometry.Mesh()

    for p in pts:
        mesh.Vertices.Add(rc.Geometry.Point3d(*p))

    for face in faces:
        if len(face) < 5:
            mesh.Faces.AddFace(*face)
        elif len(face) == 5:
            mesh.Faces.AddFace(*face[:3])
            mesh.Faces.AddFace(*face[:1] + (face[3:]))
        elif len(face) == 8:
            mesh.Faces.AddFace(*face[:4])
            mesh.Faces.AddFace(*(face[0], face[3], face[4], face[7]))
            mesh.Faces.AddFace(*(face[7], face[4], face[5], face[6]))
        else:
            try:
                mesh.Faces.AddFace(*face[:4])
                mesh.Faces.AddFace(*face[:1] + (face[4:]))
            except:
                msg = "One of the faces has %d vertices." % len(face)
                print msg

    # scale mesh to Rhion units if not meters
    if convertToMeters != 1:
        mesh.Scale(1.0 / convertToMeters)

    return mesh
Example #7
0
def loadOFMesh(polyMeshFolder, convertToMeters=1, innerMesh=True):
    """Convert OpenFOAM mesh to a Rhino Mesh."""
    if not polyMeshFolder:
        return

    pff = tuple(f for f in os.listdir(polyMeshFolder)
                if f.startswith('points'))
    fff = tuple(f for f in os.listdir(polyMeshFolder) if f.startswith('faces'))

    if pff:
        pf = os.path.join(polyMeshFolder, pff[0])
    else:
        raise ValueError(
            'Failed to find points file at {}'.format(polyMeshFolder))
    if fff:
        ff = os.path.join(polyMeshFolder, fff[0])
    else:
        raise ValueError(
            'Failed to find faces file at {}'.format(polyMeshFolder))

    pts = loadOFPointsFile(pf)
    faces = loadOFFacesFile(ff, innerMesh)

    # create the mesh
    pts = tuple(DSGeometry.Point.ByCoordinates(*p) for p in pts)
    mesh = tuple(
        DSGeometry.PolyCurve.ByPoints((pts[i] for i in f), True)
        for f in faces)

    # scale mesh to Dynamo units if not meters
    if convertToMeters != 1:
        mesh = tuple(m.Scale(1.0 / convertToMeters) for m in mesh)

    # dispose points
    for pt in pts:
        pt.Dispose()
    return mesh
def loadOFMesh(polyMeshFolder, convertToMeters=1, innerMesh=True):
    """Convert OpenFOAM mesh to a Rhino Mesh."""
    if not polyMeshFolder:
        return

    pff = tuple(f for f in os.listdir(polyMeshFolder)
                if f.startswith('points'))
    fff = tuple(f for f in os.listdir(polyMeshFolder) if f.startswith('faces'))

    if pff:
        pf = os.path.join(polyMeshFolder, pff[0])
    else:
        raise ValueError(
            'Failed to find points file at {}'.format(polyMeshFolder))
    if fff:
        ff = os.path.join(polyMeshFolder, fff[0])
    else:
        raise ValueError(
            'Failed to find faces file at {}'.format(polyMeshFolder))

    pts = loadOFPointsFile(pf)
    faces = loadOFFacesFile(ff, innerMesh)

    # create mesh edges
    pts = tuple(rc.Geometry.Point3d(*p) for p in pts)
    # create a closed polyline for each edge
    mesh = tuple(
        rc.Geometry.Polyline([pts[i] for i in f] + [pts[f[0]]]).ToNurbsCurve()
        for f in faces)

    # scale mesh to Rhion units if not meters
    if convertToMeters != 1:
        for m in mesh:
            m.Scale(1.0 / convertToMeters)

    return mesh