def tstEdgeCurvature(trianglePoint, pointXyz, pointTriangle, pointNeighbor):
  '''for each edge, calculate the angle between the triangles around it.
  calculate point curvature based on average of these for each point'''
  triXyz = {}
  for triPtList in trianglePoint:
    tri = triPtList[0]
    xyz = []
    for pt in triPtList[1:]:
      xyz.append(pointXyz[pt-1][1:])
    triXyz[tri] = xyz
  edgeAngle = {}  # store edge angles as they are found so don't duplicate work
  pointMeanAngle = []  # once all edges found, find mean, store in tst format
  pointWeightedMeanAngle = []  # weight by edge length
  for pointNeighborList in pointNeighbor:
    mainPt = pointNeighborList[0]
    angles = []
    weightedAngles = []
    for otherPt in pointNeighborList[2:]:  # pN[1] is count
      ptList = [mainPt, otherPt]
      ptList.sort()
      ptTuple = tuple(ptList)  # canonicalized format
      edgeLength = geometry.distL2(
          pointXyz[mainPt-1][1:], pointXyz[otherPt-1][1:])
      if ptTuple in edgeAngle:  # already done
        angles.append(edgeAngle[ptTuple])
        weightedAngles.append(edgeAngle[ptTuple] * edgeLength)
      else:  # have to compute it
        mainTris = set(pointTriangle[mainPt-1][2:])
        otherTris = set(pointTriangle[otherPt-1][2:])
        tris = list(mainTris.intersection(otherTris))
        #will almost always be 2
        #for now assume only 2
        normalA = geometry.getTriNormalList(triXyz[tris[0]])
        normalB = geometry.getTriNormalList(triXyz[tris[1]])
        unsignedAngle = geometry.getAngle(normalA, normalB)  # unsigned
        centerTriA = geometry.getAverage(triXyz[tris[0]])
        planeA = geometry.calculatePlaneD(normalA, centerTriA)
        ptsB = set(trianglePoint[tris[1]-1][1:])
        edgePts = set(ptList)
        otherB = pointXyz[list(ptsB.difference(edgePts))[0]-1][1:]
        side = geometry.checkPlaneSide(normalA+[planeA], otherB)
        if side:
          angle = - unsignedAngle * 180 / math.pi   # concave negative
        else:
          angle = unsignedAngle * 180 / math.pi  # convex positive
        edgeAngle[ptTuple] = angle
        angles.append(angle)
        weightedAngles.append(angle*edgeLength)
    pointMeanAngle.append([mainPt, statistics.computeMean(angles)])
    pointWeightedMeanAngle.append(
        [mainPt, statistics.computeMean(weightedAngles)])
  return edgeAngle, pointMeanAngle, pointWeightedMeanAngle
示例#2
0
def averageTheta(path):
  '''calculates the mean theta of ab to bc for each triple of points'''
  if len(path) <= 2:
    return [], 0  # no reason to count, not enough nodes
  thetas = []
  firstPt = path[0][1:4]  # first node
  secondPt = path[1][1:4]  # second node
  for node in path[2:]:
    firstVec = geometry.getVector(secondPt, firstPt)
    secondVec = geometry.getVector(node[1:4], secondPt)
    theta = geometry.getAngle(firstVec, secondVec)
    thetas.append(theta)
    firstPt = secondPt
    secondPt = node[1:4]
  averageTheta = statistics.computeMean(thetas)
  return thetas, averageTheta