Exemple #1
0
def _BresTriBase(p0,p1,p2,dss_rerun=False, iscan_iline=None):
    '''Do grunt work common to both Bresenham Triangle functions'''
    borderPts = GetTriangleBorderPoints(p0,p1,p2)
    
    if iscan_iline is not None:
        iscan, iline = iscan_iline
        return iscan, iline, borderPts
    
    # Get the steepest dimension relative to every other dimension:
    dSS = GetDirectionsOfSteepestSlope(p0,p1,p2)
    
    dSS_notNone = [i for i in dSS if i!=None]
    if len(dSS_notNone) == 0:
        # Degenerate slope matrix (all 0's); points are collinear
        return borderPts
    iscan = getMostCommonVal(dSS_notNone)
    if dss_rerun:
        all_but = [i for i in range(len(p0)) if i != iscan]
        p0a,p1a,p2a = fL([p0,p1,p2])[:, all_but]
        dSS2 = GetDirectionsOfSteepestSlope(p0a,p1a,p2a)
        dSS2_notNone = [i for i in dSS2 if i!=None]
        iline = getMostCommonVal(dSS2_notNone)
        if iline >= iscan:
            iline += 1
    else:
        iline = dSS[iscan]
    assert iline!=None, "iline is <flat>, that can't be right!"
    
    return iscan, iline, borderPts
Exemple #2
0
def GetDirectionsOfSteepestSlope_BorderCheckingVersion(borderPts):
    '''Taking each dimension as the potential scanning dimension,
       find the other dimension that has the largest slope.
       Needs the list of points of the triangle's boundary.
       Returns a list of integers (one for each dimension).
       '''
    ndim = len(borderPts[0])
    def minMaxDiff(l):
        return max(l)-min(l)
    
    maxSlopeDim = []
    for i in range(ndim): # loop over all dimensions as the assumed scan dimension (i)
        # Bin the points into hyper-planes with the same value on the i-axis
        binnedPts = {}
        for p in borderPts:
            binnedPts.setdefault(p[i],[]).append(p)
        
        # Traversing along the i-axis, find the other dimension(s) with the greatest slope
        # Collect the results in dimsOfGreatestExtent, a flat list of integers
        dimsOfGreatestExtent = []
        for pts in binnedPts.values(): # loop through the points in each bin (hyperplane)
            deltas = [ minMaxDiff([ p[j] for p in pts ]) # get the maximum delta in each dimension
                      for j in range(ndim) ]
            maxExtent = max(deltas)
            dimsOfGreatestExtent += [ j for j in range(ndim) if deltas[j]==maxExtent ]
        
        # Get the dimension that most often has the steepest slope
        maxSlopeDim.append(getMostCommonVal(dimsOfGreatestExtent))
    return maxSlopeDim