pyvista可视化加强版

增加了一个随机按钮,可以即时切换case可视化
按钮

import os
import glob
import random

import pyvista as pv


def display_multi_meshes(meshes: list, titles=None, point_size=3, opacity=0.9):
    num = len(meshes)
    for i in range(num):
        pl.subplot(0, i)
        if i == 2:
            pl.add_checkbox_button_widget(toggle_vis, position=(250.0, 20.0), value=True)

        if titles is not None:
            pl.add_title(titles[i], font_size=20, font='times')
        pl.show_axes()
        pl.add_mesh(meshes[i], point_size=point_size, opacity=opacity, show_scalar_bar=False)
    pl.show()


def toggle_vis(flag=0):
    pl.clear()
    case_id = random.randint(0, len(result_paths) // 3)

    gts = [p for p in result_paths if 'gt' in p]

    gt_path = os.path.join(gts[case_id])
    print('Test case:', gt_path)

    pred_path = gt_path.replace('gt', 'pred')
    diff_path = gt_path.replace('gt', 'diff')
    meshes = []

    titles = ["Gt", "Pred", "Diff"]
    paths = [gt_path, pred_path, diff_path]

    for path in paths:
        meshes.append(pv.read(path))
    display_multi_meshes(meshes, titles)


if __name__ == '__main__':
    result_paths = glob.glob(r'./examples/shapenet/results/predict_err_ply/*/*')
    print(len(result_paths))

    pl = pv.Plotter(shape=(1, 3))
    pl.set_background([0.9, 0.9, 0.9])
    toggle_vis(0)
    pl.show()

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2024-03-21 22:32:02       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-21 22:32:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-21 22:32:02       20 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-21 22:32:02       20 阅读

热门阅读

  1. 二、Spring源码学习之prepareRefresh方法

    2024-03-21 22:32:02       23 阅读
  2. 【LeetCode-46.全排列】

    2024-03-21 22:32:02       21 阅读
  3. RecyclerView万能适配器之BaseQuickAdapter方法详解

    2024-03-21 22:32:02       23 阅读
  4. Python PEP 8 代码风格指南

    2024-03-21 22:32:02       20 阅读
  5. Python电子邮件自动化实战案例

    2024-03-21 22:32:02       19 阅读
  6. 每日一题 第二十期 洛谷 烤鸡

    2024-03-21 22:32:02       23 阅读