Exemple #1
0
    def __init__(self):
        # v1.60final looked at giving hint with plant part name again; still has problem
        # that what you record is only points, and what you need to record is rects
        # it can be done, but the plant parts have to change to record rects, and they
        # have to deal with all their different ways of drawing. not worth doing at this time.

        self.matrixStack = []
        self.currentMatrix = u3dsupport.KfMatrix()
        self.currentMatrix.initializeAsUnitMatrix()
        self.matrixStack.append(self.currentMatrix)
        self.numMatrixesUsed = 1
        # start with a bunch of matrixes
        for i in range(0, kInitialTurtleMatrixStackDepth):
            self.matrixStack.append(u3dsupport.KfMatrix())

        self.drawingSurface = udrawingsurface.KfDrawingSurface()

        self.scale_pixelsPerMm = 1.0

        self.recordedPoints = []

        self.tempPosition = u3dsupport.KfPoint3D()
        self.realBoundsRect = u3dsupport.TRealRect()
        self.drawOptions = PlantDrawOptionsStructure()
        self.writingTo = 0
    def plantPartIDForPoint(self, point):
        points = []
        for i in range(2):
            points.append(u3dsupport.KfPoint3D())

        x = point.x
        y = point.y
        result = -1
        closestDistanceSoFar = 0
        closestPartID = -1
        for triangle in self.triangles:
            if triangle.isLine:
                centerX = (triangle.points[0].x + triangle.points[1].x) / 2.0
                centerY = (triangle.points[0].y + triangle.points[1].y) / 2.0
                thisDistance = (centerX - x) * (centerX - x) + (centerY - y) * (centerY - y)
                if (closestPartID == -1) or (thisDistance < closestDistanceSoFar):
                    closestDistanceSoFar = thisDistance
                    closestPartID = triangle.plantPartID
            else:
                points[0].X = intround(triangle.points[0].x)
                points[0].Y = intround(triangle.points[0].y)
                points[1].X = intround(triangle.points[1].x)
                points[1].Y = intround(triangle.points[1].y)
                points[2].X = intround(triangle.points[2].x)
                points[2].Y = intround(triangle.points[2].y)
                if u3dsupport.pointInTriangle(point, points):
                    result = triangle.plantPartID
                    return result
        result = closestPartID
        return result
Exemple #3
0
 def addPointString(self, stream):
     aPoint3D = u3dsupport.KfPoint3D()
     x = stream.nextInteger()
     y = stream.nextInteger()
     z = stream.nextInteger()
     u3dsupport.KfPoint3D_setXYZ(aPoint3D, x, y, z)
     self.addPoint(aPoint3D)