예제 #1
0
파일: past.py 프로젝트: stefie10/slu_hri
    def doCompute(self, drawer, landmark, figure, **args):
        fPoints = list(
            math2d.stepAlongLine(figure,
                                 math2d.length(figure) / 100.0))
        gPoints = [math2d.closestPointOnPolygon(landmark, p) for p in fPoints]
        distances = math2d.squareDistances(fPoints, gPoints)
        #[math2d.squaredist(f1, g1) for f1, g1 in zip(fPoints, gPoints)]

        i, dist = math2d.argMin(distances)

        fPoint = fPoints[i]
        gPoint = math2d.closestPointOnPolygon(landmark, fPoint)

        axes = [fPoint, gPoint]

        m = {}

        drawer.drawSegment("angleFigureToPastAxes", fPoint, gPoint)
        bborigin, (width, height) = math2d.boundingBox(figure)
        scale = pow(pow(width, 2) + pow(height, 2), 0.5)
        if scale == 0:
            bborigin, (width, height) = math2d.boundingBox(landmark)
            scale = pow(pow(width, 2) + pow(height, 2), 0.5)
        if math2d.isDegenerate(axes):
            m['angleFigureToPastAxes'] = 0
        else:
            m['angleFigureToPastAxes'] = math2d.angleBetweenLines(
                axes, [figure[0], figure[-1]])
        drawer.distanceFeature(m, "pastAxesLength", "Axes Start", "Axes End",
                               axes[0], axes[1], scale)

        return m
예제 #2
0
    def nearestNeighbor(self, x_rand, tree):
        nodes = [n for n in tree.nodes()]

        x1, x2 = x_rand

        distances = [
            math2d.dist(p1, x1) + math2d.dist(p2, x2) for p1, p2 in nodes
        ]

        minI, min = math2d.argMin(distances)
        return nodes[minI]
예제 #3
0
파일: to.py 프로젝트: stefie10/slu_hri
    def doCompute(self, drawer, landmark, figure, **args):
        figureSteps = list(
            math2d.stepAlongLine(figure,
                                 math2d.length(figure) / 100.0))
        points = [
            math2d.closestPointOnPolygon(landmark, p) for p in figureSteps
        ]
        interiorPoints = math2d.interiorPoints(landmark, figureSteps)
        landmarkCentroid = math2d.centroid(landmark)
        distances = [math2d.squaredist(p, (0, 0)) for p in points]
        bborigin, (width,
                   height) = math2d.boundingBox(na.append(landmark, figure, 0))
        scale = pow(pow(width, 2) + pow(height, 2), 0.5)
        out = {}
        i, dist = math2d.argMin(distances)
        drawer.distanceFeature(out, "minimumDistanceToLandmark",
                               "Closest point on landmark", "Figure End",
                               figureSteps[i], points[i], scale)

        for p in interiorPoints:
            drawer.drawPoint("numInteriorPoints", p)
        if len(interiorPoints) == 0:
            drawer.drawText("numInteriorPoints", landmarkCentroid,
                            "No interior points.")
            #if out["numInteriorPoints"] > 0:
            #out["numInteriorPoints"] = 1

        out["numInteriorPoints"] = len(interiorPoints)
        if math2d.isInteriorPoint(landmark, figureSteps[i]):
            out["minimumDistanceToLandmark"] = 0
        if math2d.isInteriorPoint(landmark, figure[-1]):
            out["distFigureEndToLandmark"] = 0

        differences = [d1 - d2 for d1, d2 in zip(distances, distances[1:])]
        differences = [d / d if d != 0 else 0 for d in differences]
        if len(differences) == 0:
            out["averageDistanceDifference"] = 0
        else:
            out["averageDistanceDifference"] = math2d.mean(differences)
        for p1, p2 in zip(points, points[1:]):
            drawer.drawLine("averageDistanceDifference", [p1, p2])

        return out
예제 #4
0
    def doCompute(self, drawer, ground, figure, **args):
        steps = 100
        fPoints = list(
            math2d.stepAlongLine(figure,
                                 math2d.length(figure) / 100))

        gPoints = [math2d.closestPointOnPolygon(ground, p) for p in fPoints]
        distances = [
            math2d.squaredist(f1, g1) for f1, g1 in zip(fPoints, gPoints)
        ]

        i, minDist = math2d.argMin(distances)
        bborigin, (width, height) = math2d.boundingBox(ground + figure)
        scale = pow(pow(width, 2) + pow(height, 2), 0.5)
        featureMap = {}
        drawer.distanceFeature(self, featureMap, "minimumDistanceToGround",
                               "Figure", "Ground", fPoints[i], gPoints[i],
                               scale)

        for f1, g1 in zip(fPoints, gPoints):
            self.drawSegment("averageDistanceToGround", f1, g1)
        featureMap["averageDistanceToGround"] = math2d.mean(distances) / scale

        return featureMap
예제 #5
0
    def nearestNeighbor(self, x_rand, tree):
        nodes = [n for n in tree.nodes()]
        distances = [math2d.dist(n, x_rand) for n in nodes]

        minI, min = math2d.argMin(distances)
        return nodes[minI]