95 lines
3.2 KiB
C#
95 lines
3.2 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.Api;
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace VisionCommon {
|
|
[Serializable]
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct PointData {
|
|
public double X;
|
|
public double Y;
|
|
}
|
|
|
|
public static class NativePattern {
|
|
private const string FILE_NAME_VISION_DLL = "VisionCore.dll";
|
|
private static Logger _Logger = new Logger("NativePattern");
|
|
|
|
[DllImport(FILE_NAME_VISION_DLL)]
|
|
extern private static PointData IntersectionPoint(
|
|
double line1A, double line1B, double line1C,
|
|
double line2A, double line2B, double line2C);
|
|
|
|
[DllImport(FILE_NAME_VISION_DLL)]
|
|
extern private static PointData VerticalIntersectionPoint(
|
|
PointData line1Point,
|
|
double line1A, double line1B, double line1C,
|
|
double line2A, double line2B, double line2C);
|
|
|
|
[DllImport(FILE_NAME_VISION_DLL)]
|
|
extern private static double DistancePointToLine(
|
|
PointData point,
|
|
double lineA, double lineB, double lineC);
|
|
|
|
/// <summary>
|
|
/// 라인1,2 간에 교점 계산
|
|
/// </summary>
|
|
/// <param name="le1">라인1</param>
|
|
/// <param name="le2">라인2</param>
|
|
/// <returns>라인1,2 간에 교점</returns>
|
|
public static T GetIntersectionPoint<T>(LineEquation le1, LineEquation le2) where T : DoublePoint {
|
|
|
|
PointData pointData = IntersectionPoint(
|
|
le1.A, le1.B, le1.C,
|
|
le2.A, le2.B, le2.C);
|
|
|
|
return (T)Activator.CreateInstance(typeof(T), pointData.X, pointData.Y);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 라인1을 지나는 점에서 수직인 라인과 라인2 간에 교점 계산
|
|
/// </summary>
|
|
/// <param name="le1Point">라인1을 지나는 점</param>
|
|
/// <param name="le1">라인1</param>
|
|
/// <param name="le2">라인2</param>
|
|
/// <returns>라인1을 지나는 점에서 수직인 라인과 라인2 간에 교점</returns>
|
|
public static ImagePoint GetVerticalIntersectionPoint(ImagePoint le1Point, LineEquation le1, LineEquation le2) {
|
|
|
|
PointData le1PointData = new PointData() {
|
|
X = le1Point.X,
|
|
Y = le1Point.Y
|
|
};
|
|
|
|
PointData pointData = VerticalIntersectionPoint(
|
|
le1PointData,
|
|
le1.A, le1.B, le1.C,
|
|
le2.A, le2.B, le2.C);
|
|
|
|
return new ImagePoint(pointData.X, pointData.Y);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 점과 라인 간에 거리 계산
|
|
/// </summary>
|
|
/// <param name="point">점</param>
|
|
/// <param name="le">라인</param>
|
|
/// <returns>점과 라인 간에 거리</returns>
|
|
public static double GetDistancePointToLine(ImagePoint point, LineEquation le) {
|
|
|
|
PointData le1PointData = new PointData() {
|
|
X = point.X,
|
|
Y = point.Y
|
|
};
|
|
|
|
double distance = DistancePointToLine(
|
|
le1PointData,
|
|
le.A, le.B, le.C);
|
|
|
|
return distance;
|
|
}
|
|
}
|
|
}
|