Example #1
0
def decideInsidePhi(
    phiData, triTuples, allPoints, pointTriList, pointList, triList,
    valueToSet=1, valueToUnset=0, maxIntersect=False):
  '''helper function that puts values into a phimap instead of a grid.
  cubic so doesn't matter which axis, just use x.
  ToSet is inside surface, ToUnset is outside the surface.
  the values in PhiData are destroyed and replaced with values.'''
  longEdge = 1.0000001 * geometry.getLongestEdge(triList, pointList, 0)
  #build orthogonal range search tree structure now, save in orst
  orst = buildOrst(
      triTuples, 1, 2, allPoints, pointTriList, pointList)
  if False != orst:
    for short1 in xrange(0, phiData.gridDimension):
      #print " "
      for short2 in xrange(0, phiData.gridDimension):
        startPt, endPt = [], []  # set these up next
        x, y, z = 0, short1, short2
        yCoord = phiData.getXYZ(x, y, z)[1]
        zCoord = phiData.getXYZ(x, y, z)[2]
        xCoordStart = phiData.getXYZ(x, y, z)[0]
        xCoordEnd = phiData.getXYZ(phiData.gridDimension - 1, y, z)[0]
        startPt = [xCoordStart, yCoord, zCoord]
        endPt = [xCoordEnd, yCoord, zCoord]
        intersectingPts, maxIt, usedStart, usedEnd = False, 5000, startPt, endPt
        while False == intersectingPts:
          intersectingPts = getIntersectingPts(
              usedStart, usedEnd, longEdge, 1, 2, orst, maxIntersect)
          usedStart, usedEnd = geometry.perturbLine(
              0, 1, 2, usedStart, usedEnd, maxIt)
          maxIt -= 1
          if maxIt < 0:
            print "had to perturb line 5000 times..."
            print usedStart, usedEnd
            sys.exit(1)
        if len(intersectingPts) > 0:
          #need to sort based on ascending long-axis int pt
          #longInts mean long dimension intercepts
          longInts = [xb[0] for xb in intersectingPts]  # make quick array
          longInts.sort()
          #then decide inside/outside ms points, put -2 in grid if inside
          lPlace, lInside = 0, False  # records which intercepts
                       # have been seen, and whether currently outside or inside
                       #outside is False!
          for longCount in xrange(0, phiData.gridDimension):
            x, y, z = longCount, short1, short2
            gridPiece = phiData.getXYZ(x, y, z)
            while lPlace < len(longInts) and \
                gridPiece[0] > longInts[lPlace]:  # switch
              lPlace += 1
              lInside = not lInside
            if lInside:  # replace the encoding int
              phiData.setValue(x, y, z, valueToSet)
            else:
              phiData.setValue(x, y, z, valueToUnset)
        else:  # no intersecting points
          for longCount in xrange(0, phiData.gridDimension):
            x, y, z = longCount, short1, short2
            phiData.setValue(x, y, z, valueToUnset)
Example #2
0
def decideInsideLong(
    emptyGrid, triTuples, longAxis, allPoints, pointTriList, pointList,
    triList, valueToSet, valueFromSet=False, maxIntersect=False):
  '''helper function that does proper stuff depending on longAxis value'''
  #don't bother figuring out what's inside the ms if already bad grid
  lenX = len(emptyGrid)
  lenY = len(emptyGrid[0])
  lenZ = len(emptyGrid[0][0])
  lens = (lenX, lenY, lenZ)
  shortAxis1, shortAxis2 = 0, 0
  if longAxis == 0:
    shortAxis1, shortAxis2 = 1, 2
  elif longAxis == 1:
    shortAxis1, shortAxis2 = 0, 2
  elif longAxis == 2:
    shortAxis1, shortAxis2 = 0, 1
  longEdge = 1.0000001 * geometry.getLongestEdge(triList, pointList, longAxis)
  #build orthogonal range search tree structure now, save in orst
  orst = buildOrst(
      triTuples, shortAxis1, shortAxis2, allPoints, pointTriList, pointList)
  if False != orst:
    for short1 in range(0, lens[shortAxis1]):
      #print " "
      for short2 in range(0, lens[shortAxis2]):
        startPt, endPt = [], []  # set these up in next switch
        if longAxis == 0:
          x, y, z = 0, short1, short2
          yCoord = emptyGrid[x][y][z][2]
          zCoord = emptyGrid[x][y][z][3]
          xCoordStart = emptyGrid[0][y][z][1]
          xCoordEnd = emptyGrid[lenX - 1][y][z][1]
          startPt = [xCoordStart, yCoord, zCoord]
          endPt = [xCoordEnd, yCoord, zCoord]
        elif longAxis == 1:
          x, y, z = short1, 0, short2
          xCoord = emptyGrid[x][y][z][1]
          zCoord = emptyGrid[x][y][z][3]
          yCoordStart = emptyGrid[x][0][z][2]
          yCoordEnd = emptyGrid[x][lenY - 1][z][2]
          startPt = [xCoord, yCoordStart, zCoord]
          endPt = [xCoord, yCoordEnd, zCoord]
        elif longAxis == 2:
          x, y, z = short1, short2, 0
          xCoord = emptyGrid[x][y][z][1]
          yCoord = emptyGrid[x][y][z][2]
          zCoordStart = emptyGrid[x][y][0][3]
          zCoordEnd = emptyGrid[x][y][lenZ - 1][3]
          startPt = [xCoord, yCoord, zCoordStart]
          endPt = [xCoord, yCoord, zCoordEnd]
        intersectingPts, maxIt, usedStart, usedEnd = False, 5000, startPt, endPt
        while False == intersectingPts:
          intersectingPts = getIntersectingPts(
              usedStart, usedEnd, longEdge, shortAxis1, shortAxis2, orst,
              maxIntersect)
          usedStart, usedEnd = geometry.perturbLine(
              longAxis, shortAxis1, shortAxis2, usedStart, usedEnd, maxIt)
          maxIt -= 1
          if maxIt < 0:
            print "had to perturb line 5000 times..."
            print usedStart, usedEnd
            sys.exit(1)
        if len(intersectingPts) > 0:
          #print len(intersectingPts),
          #check even-ness... perhaps perturb if odd
          if len(intersectingPts) % 2 == 1:
            pass
            #print "odd number of intersecting points!!"
            #perturb starting line, try again
          #need to sort based on ascending long-axis int pt
          #longInts mean long dimension intercepts
          longInts = [xb[longAxis] for xb in intersectingPts]  # make quick list
          longInts.sort()
          #then decide inside/outside ms points, put -2 in grid if inside
          lPlace, lInside = 0, False  # records which intercepts
                       # have been seen, and whether currently outside or inside
          for longCount in range(0, lens[longAxis]):
            x, y, z = -1, -1, -1
            if longAxis == 0:
              x, y, z = longCount, short1, short2
            elif longAxis == 1:
              x, y, z = short1, longCount, short2
            elif longAxis == 2:
              x, y, z = short1, short2, longCount
            gridPiece = emptyGrid[x][y][z]
            while lPlace < len(longInts) and \
                gridPiece[longAxis+1] > longInts[lPlace]:  # switch
              lPlace += 1
              lInside = not lInside
            if lInside:  # replace the encoding int
              if False == valueFromSet or valueFromSet == gridPiece[0]:
                newGridPiece = valueToSet, gridPiece[1], gridPiece[2], \
                    gridPiece[3]
                emptyGrid[x][y][z] = newGridPiece