Example #1
0
def delaunayMap(points, imageSize = (0, 0)):
    """Return a GeoMap containing a Delaunay Triangulation of the given
    points."""

    if len(points) < 3:
        raise ValueError, \
              "cannot compute Delaunay Triangulation of less than three points"

    if triangle:
        nodePositions, edges = triangle.delaunay(points)
        sigma = None
    else:
        nodePositions, edges, sigma = geomap.delaunay(points)
    return _delaunayMapFromData(nodePositions, edges, imageSize,
                                sigma)
Example #2
0
def delaunayMap(points, imageSize = (0, 0)):
    """Return a GeoMap containing a Delaunay Triangulation of the given
    points."""

    if len(points) < 3:
        raise ValueError, \
              "cannot compute Delaunay Triangulation of less than three points"
    
    if triangle:
        nodePositions, edges = triangle.delaunay(points)
        sigma = None
    else:
        nodePositions, edges, sigma = geomap.delaunay(points)
    return _delaunayMapFromData(nodePositions, edges, imageSize,
                                sigma)
Example #3
0
def fakedConstrainedDelaunayMap(polygons, imageSize, extraPoints = [],
                                onlyInner = True):

    """See constrainedDelaunayMap, this calculates a DT and throws
    away outer edges retroactively.  This may fail when the DT does
    not contain all constrained segments, which is checked in this
    function and leads to an AssertionError."""

    points = []
    jumpPoints = [0]
    for polygon in polygons:
        points.extend(list(polygon))
        del points[-1]
        jumpPoints.append(len(points))

    print "- performing Delaunay Triangulation (%d points)..." % len(points)
    nodePositions, edges, sigma = geomap.delaunay(points)

    print "- storing result in a GeoMap..."
    result = _delaunayMapFromData(nodePositions, edges, imageSize, sigma)

    print "- ex-post marking of contour edges for faked CDT..."
    print "  (keep your fingers crossed that no segment is missing!)"

    edgeSourceDarts = [None] * result.maxEdgeLabel()

    i = 0
    while i < len(jumpPoints) - 1:
        contourStartLabel = jumpPoints[i] + 1 # +1 for conversion of
        contourEndLabel = jumpPoints[i+1] + 1 #    point indices -> node labels
        dart = result.node(contourStartLabel).anchor()
        for nodeLabel in range(contourStartLabel+1, contourEndLabel):
            j = dart.startNode().degree() + 2
            while dart.endNodeLabel() != nodeLabel and j > 0:
                dart.nextSigma()
                j -= 1
            assert j > 0, """Original contour fragment missing in Delauny map!
            (This is a problem of the fakedConstrainedDelaunayMap, try compiling
            the triangle module and using the real constrainedDelaunayMap instead.)"""
            dart.edge().setFlag(CONTOUR_SEGMENT)
            edgeSourceDarts[dart.edgeLabel()] = dart.label()
            dart.nextAlpha()
        j = dart.startNode().degree() + 1
        while dart.endNodeLabel() != contourStartLabel and j > 0:
            dart.nextSigma()
            j -= 1
        assert j > 0, "Original contour fragment missing in Delauny map!"
        dart.edge().setFlag(CONTOUR_SEGMENT)
        edgeSourceDarts[dart.edgeLabel()] = dart.label()
        i += 1

    if onlyInner:
        sys.stdout.write("- reducing delaunay triangulation to inner part...")
        outerFace = [False] * result.maxFaceLabel()
        for edge in result.edgeIter():
            if edge.flag(CONTOUR_SEGMENT):
                dart = result.dart(edgeSourceDarts[edge.label()])
                assert dart.edgeLabel() == edge.label(), str(edge)
                while True:
                    mergeDart = dart.clone().prevSigma()
                    if mergeDart.edge().flag(CONTOUR_SEGMENT):
                        break
                    outerFace[result.mergeFaces(mergeDart).label()] = True
                    #sys.stdout.write(".")
                    #sys.stdout.flush()
        sys.stdout.write("\n")

    return result
Example #4
0
def fakedConstrainedDelaunayMap(polygons, imageSize, extraPoints = [],
                                onlyInner = True):

    """See constrainedDelaunayMap, this calculates a DT and throws
    away outer edges retroactively.  This may fail when the DT does
    not contain all constrained segments, which is checked in this
    function and leads to an AssertionError."""

    points = []
    jumpPoints = [0]
    for polygon in polygons:
        points.extend(list(polygon))
        del points[-1]
        jumpPoints.append(len(points))
    
    print "- performing Delaunay Triangulation (%d points)..." % len(points)
    nodePositions, edges, sigma = geomap.delaunay(points)
    
    print "- storing result in a GeoMap..."
    result = _delaunayMapFromData(nodePositions, edges, imageSize, sigma)

    print "- ex-post marking of contour edges for faked CDT..."
    print "  (keep your fingers crossed that no segment is missing!)"

    edgeSourceDarts = [None] * result.maxEdgeLabel()

    i = 0
    while i < len(jumpPoints) - 1:
        contourStartLabel = jumpPoints[i] + 1 # +1 for conversion of
        contourEndLabel = jumpPoints[i+1] + 1 #    point indices -> node labels
        dart = result.node(contourStartLabel).anchor()
        for nodeLabel in range(contourStartLabel+1, contourEndLabel):
            j = dart.startNode().degree() + 2
            while dart.endNodeLabel() != nodeLabel and j > 0:
                dart.nextSigma()
                j -= 1
            assert j > 0, """Original contour fragment missing in Delauny map!
            (This is a problem of the fakedConstrainedDelaunayMap, try compiling
            the triangle module and using the real constrainedDelaunayMap instead.)"""
            dart.edge().setFlag(CONTOUR_SEGMENT)
            edgeSourceDarts[dart.edgeLabel()] = dart.label()
            dart.nextAlpha()
        j = dart.startNode().degree() + 1
        while dart.endNodeLabel() != contourStartLabel and j > 0:
            dart.nextSigma()
            j -= 1
        assert j > 0, "Original contour fragment missing in Delauny map!"
        dart.edge().setFlag(CONTOUR_SEGMENT)
        edgeSourceDarts[dart.edgeLabel()] = dart.label()
        i += 1

    if onlyInner:
        sys.stdout.write("- reducing delaunay triangulation to inner part...")
        outerFace = [False] * result.maxFaceLabel()
        for edge in result.edgeIter():
            if edge.flag(CONTOUR_SEGMENT):
                dart = result.dart(edgeSourceDarts[edge.label()])
                assert dart.edgeLabel() == edge.label(), str(edge)
                while True:
                    mergeDart = dart.clone().prevSigma()
                    if mergeDart.edge().flag(CONTOUR_SEGMENT):
                        break
                    outerFace[result.mergeFaces(mergeDart).label()] = True
                    #sys.stdout.write(".")
                    #sys.stdout.flush()
        sys.stdout.write("\n")
    
    return result