def clip(self, mesh, grid):
    assert isinstance(mesh, IndexedPolygons)
    assert isinstance(grid, Grid3D)
    origin = grid.getOriginReal()
    stepSize = grid.getStepSizeReal()
    (dx, dy, dz) = grid.dimensions
    vertices = mesh.vertexSet.vertices.array
    triangles = mesh.faceSet.faces.array
    vertInd = ((vertices - origin) / stepSize).astype('i')
    selVert = []
    vertEquiv = {}
    numVertSel = 0
    nvert = 0
    data = grid.data
    for (i, j, k) in vertInd:
        if ((i >= 0) and (i < dx)):
            if ((j >= 0) and (j < dy)):
                if ((k >= 0) and (k < dz)):
                    if data[(i, j, k)]:
                        selVert.append(vertices[nvert])
                        vertEquiv[nvert] = numVertSel
                        numVertSel += 1
        nvert += 1
    selFaces = []
    for (i, j, k) in triangles:
        nbvs = 0
        v1 = vertEquiv.get(i, None)
        if v1:
            nbvs += 1
        v2 = vertEquiv.get(j, None)
        if v2:
            nbvs += 1
        v3 = vertEquiv.get(k, None)
        if v3:
            nbvs += 1
        if (nbvs == 3):
            selFaces.append((v1, v2, v3))
    clippedGeom = IndexedPolygons((mesh.name + '_clipped'), vertices=selVert, faces=selFaces)
    return clippedGeom
def clip(self, mesh, grid):
    assert isinstance(mesh, IndexedPolygons)
    assert isinstance(grid, Grid3D)
    origin = grid.getOriginReal()
    stepSize = grid.getStepSizeReal()
    (dx, dy, dz) = grid.dimensions
    vertices = mesh.vertexSet.vertices.array
    triangles = mesh.faceSet.faces.array
    vertInd = ((vertices - origin) / stepSize).astype('i')
    selVert = []
    vertEquiv = {}
    numVertSel = 0
    nvert = 0
    data = grid.data
    for (i, j, k) in vertInd:
        if ((i >= 0) and (i < dx)):
            if ((j >= 0) and (j < dy)):
                if ((k >= 0) and (k < dz)):
                    if data[(i, j, k)]:
                        selVert.append(vertices[nvert])
                        vertEquiv[nvert] = numVertSel
                        numVertSel += 1
        nvert += 1
    selFaces = []
    for (i, j, k) in triangles:
        nbvs = 0
        v1 = vertEquiv.get(i, None)
        if v1:
            nbvs += 1
        v2 = vertEquiv.get(j, None)
        if v2:
            nbvs += 1
        v3 = vertEquiv.get(k, None)
        if v3:
            nbvs += 1
        if (nbvs == 3):
            selFaces.append((v1, v2, v3))
    clippedGeom = IndexedPolygons((mesh.name + '_clipped'), vertices=selVert, faces=selFaces)
    return clippedGeom