跳转至

06 - 交互式可视化

scene.show() 在浏览器中打开一个三维查看器,用来检查场景、运行模拟和查看结果。

打开查看器

import less

scene = less.Scene()
scene.size = 10
scene.terrain = less.Terrain(property=less.Lambertian(reflectance=0.2))
scene.terrain.set_property(less.ThermalProperty(temperature=300))
scene.illumination = less.Illumination(
    source=less.Sun(zenith=30), atmosphere=less.NoAtmosphere())

maize = less.Object("maize", mesh=less.asset_path("maize.obj"))
maize.set_property(less.Prospect(cab=40))
maize.set_property(less.ThermalProperty(temperature=303))
scene.add(maize, positions=[[3, 3, 0], [5, 5, 0], [7, 7, 0]])

scene.show()

查看器在本机启动一个网页服务,并在默认浏览器中打开。物体的位置、旋转和缩放与场景设置一致,可以用来检查摆放是否正确。

鼠标操作:

  • 左键拖动:旋转;
  • 右键拖动或 Shift + 左键:平移;
  • 滚轮:缩放。

在查看器中运行模拟

把传感器和过程传给 show(),就可以在查看器里选择并运行:

sensors = [
    less.OpticalImager(less.Orthographic(image_size=128),
                       bands=[650, 550, 450], quality=32, name="RGB"),
    less.ThermalImager(less.Orthographic(image_size=128),
                       bands=[10600], quality=32, name="Thermal"),
]
processes = [
    less.RadiationFieldProcess(n_samples=32, name="Radiation field"),
]
scene.show(sensors=sensors, processes=processes)

查看器有三个页面:

页面 用途
Visualize 查看物体、地形、组件和实例
Simulate 选择传感器或过程,调整参数后运行
Products 查看、比较和下载结果

逐三角形的结果(例如每个面的吸收)会贴回场景显示。几何改变后请重新模拟,再把新结果贴回场景。

内置示例

python -m less.examples autumn_forest
python -m less.examples maize_field

示例中已经配置好 RGB、多光谱、热红外和激光雷达等传感器,可以在 Simulate 页面逐个运行。

不打开查看器

在服务器上批量计算时,直接循环调用 simulate() 并保存结果即可:

from pathlib import Path

output = Path("output")
output.mkdir(exist_ok=True)
for sensor in sensors:
    scene.simulate(sensor).save(output / f"{sensor.name}.tif")

下一步