private static Vector2D GetVectorOfDirection(WalkerField.Direction direction) { CoordinateSystem2D coordSys = Game.GetLocalCoordsystemOfPlayer(); Vector2D vector = new Vector2D(0, 0); switch (direction) { case WalkerField.Direction.FORWARD: vector = new Vector2D(1, 0); break; case WalkerField.Direction.BACKWARD: vector = new Vector2D(-1, 0); break; case WalkerField.Direction.RIGHT: vector = new Vector2D(0, -1); break; case WalkerField.Direction.LEFT: vector = new Vector2D(0, 1); break; case WalkerField.Direction.FORWARDLEFT: vector = new Vector2D(1, 1); break; case WalkerField.Direction.FORWARDRIGHT: vector = new Vector2D(1, -1); break; case WalkerField.Direction.BACKWARDLEFT: vector = new Vector2D(-1, -1); break; case WalkerField.Direction.BACKWARDRIGHT: vector = new Vector2D(-1, 1); break; } return(coordSys.LocalToGlobal(vector.UnitVector)); }
/// <summary> /// Detects circles on gasket image /// </summary> private static void DetectCircles(Image gasketImage, out Circle2D[] detectedCircles, out Segment2D[] conntectingSegments, CoordinateSystem2D localSystem) { using (CircleFittingMap circleMap1 = new CircleFittingMap(), circleMap2 = new CircleFittingMap()) { AVL.CreateCircleFittingMap(new ImageFormat(gasketImage), new CircleFittingField(largeExpectedCircle, 35.0f), localSystem, 16, 5, InterpolationMethod.Bilinear, circleMap1); AVL.CreateCircleFittingMap(new ImageFormat(gasketImage), new CircleFittingField(smallExpectedCircle, 35.0f), localSystem, 16, 5, InterpolationMethod.Bilinear, circleMap2); Circle2D?largeCircle, smallCircle; AVL.FitCircleToEdges(gasketImage, circleMap1, scanParams, Selection.Best, 0.1f, CircleFittingMethod.GeometricLandau, out largeCircle); AVL.FitCircleToEdges(gasketImage, circleMap2, scanParams, Selection.Best, 0.1f, CircleFittingMethod.GeometricLandau, out smallCircle); conntectingSegments = new Segment2D[2]; if (largeCircle.HasValue && smallCircle.HasValue) { detectedCircles = new[] { largeCircle.Value, smallCircle.Value }; conntectingSegments[0] = new Segment2D(detectedCircles[0].Center, detectedCircles[1].Center); } else { detectedCircles = new Circle2D[0]; } } }
public RectangleCollider(CoordinateSystem2D coordinateSystem, float width, float height) { CoordinateSystem = coordinateSystem; Width = width; Heigth = height; }
/// <summary> /// Detects arcs on gasket image /// </summary> private static void DetectArcs(Image gasketImage, out Arc2D[] detectedArcs, Segment2D[] conntectingSegments, CoordinateSystem2D localSystem) { using (ArcFittingMap arcMap1 = new ArcFittingMap(), arcMap2 = new ArcFittingMap()) { //public static void CreateArcFittingMap //( // AvlNet.ImageFormat inImageFormat, // AvlNet.ArcFittingField inFittingField, // AvlNet.CoordinateSystem2D? inFittingFieldAlignment, // int inScanCount, // int inScanWidth, // AvlNet.InterpolationMethod inImageInterpolation, // AvlNet.ArcFittingMap outFittingMap, // IList<AvlNet.Segment2D> diagScanSegments, // IList<AvlNet.Rectangle2D> diagSamplingAreas //) AVL.CreateArcFittingMap(new ImageFormat(gasketImage), new ArcFittingField(upperExpectedArc, 20.0f), localSystem, 10, 5, InterpolationMethod.Bilinear, arcMap1); AVL.CreateArcFittingMap(new ImageFormat(gasketImage), new ArcFittingField(lowerExpectedArc, 20.0f), localSystem, 10, 5, InterpolationMethod.Bilinear, arcMap2); Arc2D?upperArc, lowerArc; //public static void FitArcToEdges //( // AvlNet.Image inImage, // AvlNet.ArcFittingMap inFittingMap, // AvlNet.EdgeScanParams inEdgeScanParams, // AvlNet.Selection inEdgeSelection, // AvlNet.LocalBlindness? inLocalBlindness, // float inMaxIncompleteness, // AvlNet.CircleFittingMethod inFittingMethod, // AvlNet.MEstimator? inOutlierSuppression, // out AvlNet.Arc2D? outArc, // IList<AvlNet.Edge1D?> outEdges, // INullable<AvlNet.Profile> outDeviationProfile, // IList<AvlNet.Point2D> outInliers, // IList<AvlNet.Profile> diagBrightnessProfiles, // IList<AvlNet.Profile> diagResponseProfiles //) AVL.FitArcToEdges(gasketImage, arcMap1, scanParams, Selection.Best, 0.1f, CircleFittingMethod.GeometricLandau, out upperArc); AVL.FitArcToEdges(gasketImage, arcMap2, scanParams, Selection.Best, 0.1f, CircleFittingMethod.GeometricLandau, out lowerArc); if (upperArc.HasValue && lowerArc.HasValue) { //mr:: 这里使用了 Value 属性来取值. detectedArcs = new[] { upperArc.Value, lowerArc.Value }; conntectingSegments[1] = new Segment2D(detectedArcs[0].Center, detectedArcs[1].Center); } else { detectedArcs = new Arc2D[0]; } } }