Skip to content

tin_renderer

TIN 三角网 PyVista 渲染引擎

纯 Python 实现,不依赖 DmPyBindInterface.pyd。 PyVista 为可选依赖,通过懒加载方式导入。

render_tin(geometries, config, output_path=None, output_prefix='tin_render', image_format='png')

渲染 TIN 三角网模型

Parameters

geometries : TINGeometry 或 List[TINGeometry] 待渲染的三角网几何体 config : TinRenderConfig 渲染配置(角度、模式、样式等) output_path : str, optional 输出路径: - separate 模式:指定目录,每个角度保存为独立文件 - combined 模式:指定文件路径,保存为单张组合图 - None:返回 Plotter 对象用于交互式显示 output_prefix : str 输出文件前缀(separate 模式有效),默认 "tin_render" image_format : str 图像格式(png/jpg/svg 等),默认 "png"

Returns

dict { "mode": "separate" | "combined", "angles": [...], "output_files": [...] | None, "plotters": [...] | None, "config": TinRenderConfig, }

Raises

MissingPyVistaError: PyVista 未安装 InvalidTINDataError: 输入数据无效 TINRenderError: 渲染过程中发生错误 LayoutError: 子图布局配置错误

Source code in dimine_python_sdk\lib\visualization\tin_renderer.py
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
def render_tin(
    geometries: Union[TINGeometry, List[TINGeometry]],
    config: TinRenderConfig,
    output_path: Optional[str] = None,
    output_prefix: str = "tin_render",
    image_format: str = "png",
) -> Dict[str, Any]:
    """渲染 TIN 三角网模型

    Parameters
    ----------
    geometries : TINGeometry 或 List[TINGeometry]
        待渲染的三角网几何体
    config : TinRenderConfig
        渲染配置(角度、模式、样式等)
    output_path : str, optional
        输出路径:
        - separate 模式:指定目录,每个角度保存为独立文件
        - combined 模式:指定文件路径,保存为单张组合图
        - None:返回 Plotter 对象用于交互式显示
    output_prefix : str
        输出文件前缀(separate 模式有效),默认 "tin_render"
    image_format : str
        图像格式(png/jpg/svg 等),默认 "png"

    Returns
    -------
    dict
        {
            "mode": "separate" | "combined",
            "angles": [...],
            "output_files": [...] | None,
            "plotters": [...] | None,
            "config": TinRenderConfig,
        }

    Raises
    ------
    MissingPyVistaError: PyVista 未安装
    InvalidTINDataError: 输入数据无效
    TINRenderError: 渲染过程中发生错误
    LayoutError: 子图布局配置错误
    """
    if isinstance(geometries, TINGeometry):
        geometries = [geometries]

    # 1. 校验数据
    for i, geo in enumerate(geometries):
        _validate_tin_geometry(geo, i)

    num_angles = len(config.angles)

    # 2. 转换数据
    polydata_list = [_tin_to_polydata(geo) for geo in geometries]

    # 3. 计算包围盒和相机参数
    bounds = _compute_bounds(geometries)
    centroid = _compute_centroid(bounds)
    diagonal = _compute_diagonal(bounds)
    if diagonal == 0:
        diagonal = 1.0

    # 4. 确定输出模式
    off_screen = output_path is not None

    try:
        if config.mode == "separate":
            return _render_separate(
                polydata_list, config, bounds, centroid, diagonal,
                output_path, output_prefix, image_format, off_screen,
            )
        else:
            return _render_combined(
                polydata_list, config, bounds, centroid, diagonal,
                output_path, image_format, off_screen,
            )
    except (InvalidTINDataError, MissingPyVistaError, LayoutError):
        raise
    except Exception as e:
        raise TINRenderError(f"渲染失败: {e}") from e