Skip to content

algorithm

Native Layer v2 几何算法模块

对外返回 numpy 数组与 NativeTin,内部完成 C++ 类型转换。

calculate_min_rectangle_2d(points, bounds)

计算二维点集最小外接矩形。

Parameters:

Name Type Description Default
points 'np.ndarray'

形状 (N, 3) 或 (N, 2)

required
bounds Sequence[float]

边界约束 [min_x, min_y, max_x, max_y]

required

Returns:

Type Description
'np.ndarray'

矩形角点 (4, 3)

Source code in dimine_python_sdk\lib\native\algorithm.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def calculate_min_rectangle_2d(points: "np.ndarray", bounds: Sequence[float]) -> "np.ndarray":
    """
    计算二维点集最小外接矩形。

    Args:
        points: 形状 (N, 3) 或 (N, 2)
        bounds: 边界约束 [min_x, min_y, max_x, max_y]

    Returns:
        矩形角点 (4, 3)
    """
    arr = ensure_points(points)
    cpp_points = _geom.points_to_native(arr)
    cpp_result = Dm.thModelFunc.CalcultateMinRectangle2D(cpp_points, list(bounds))
    return _geom.points_from_native(cpp_result)

cut_model_data(input_tin, origin, normal, num=1, dist=0)

裁剪模型数据。

Parameters:

Name Type Description Default
input_tin NativeTin

输入三角网

required
origin 'np.ndarray'

裁剪原点

required
normal 'np.ndarray'

裁剪法线

required
num int

裁剪次数

1
dist float

裁剪距离

0

Returns:

Type Description
NativeTin

裁剪后的三角网

Source code in dimine_python_sdk\lib\native\algorithm.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def cut_model_data(
    input_tin: NativeTin,
    origin: "np.ndarray",
    normal: "np.ndarray",
    num: int = 1,
    dist: float = 0,
) -> NativeTin:
    """
    裁剪模型数据。

    Args:
        input_tin: 输入三角网
        origin: 裁剪原点
        normal: 裁剪法线
        num: 裁剪次数
        dist: 裁剪距离

    Returns:
        裁剪后的三角网
    """
    import numpy as np

    input_poly = _geom.tin_to_polydata(input_tin)
    output_poly = Dm.dmPolyData()
    o = _geom.point_to_native(ensure_array_3d(origin))
    n = _geom.point_to_native(ensure_array_3d(normal))

    ret = Dm.thModelFunc.CutModelData(input_poly, o, n, output_poly, num, dist)
    if ret != 1:
        raise NativeAlgorithmError(f"模型切割失败,底层返回结果码: {ret}")

    return _geom.tin_from_polydata(output_poly)

line_x_polyline(start, end, point_set, tolerance)

计算线段与多段线的交点。

Parameters:

Name Type Description Default
start 'np.ndarray'

线段起点

required
end 'np.ndarray'

线段终点

required
point_set 'np.ndarray'

多段线顶点 (N, 3)

required
tolerance float

容差

required

Returns:

Type Description
'np.ndarray'

交点数组 (M, 3)

Source code in dimine_python_sdk\lib\native\algorithm.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def line_x_polyline(
    start: "np.ndarray",
    end: "np.ndarray",
    point_set: "np.ndarray",
    tolerance: float,
) -> "np.ndarray":
    """
    计算线段与多段线的交点。

    Args:
        start: 线段起点
        end: 线段终点
        point_set: 多段线顶点 (N, 3)
        tolerance: 容差

    Returns:
        交点数组 (M, 3)
    """
    s = _geom.point_to_native(ensure_array_3d(start))
    e = _geom.point_to_native(ensure_array_3d(end))
    pts = _geom.points_to_native(ensure_points(point_set))
    cpp_result = Dm.thModelFunc.LineXPolyline(s, e, pts, float(tolerance))
    if not cpp_result:
        import numpy as np

        return np.zeros((0, 3), dtype=float)
    return _geom.points_from_native(cpp_result)