{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 点云数据" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of points: (678418, 3)\n", "Elevation range: [1753.949951171875, 1786.7099609375]\n" ] }, { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import dash\n", "import dash_vtk\n", "from dash import html, dcc\n", "from dash.dependencies import Input, Output, State\n", "\n", "import numpy as np\n", "from pyvista import examples\n", "\n", "np.random.seed(42)\n", "\n", "# Get point cloud data from PyVista\n", "dataset = examples.download_lidar()\n", "subset = 0.2\n", "selection = np.random.randint(\n", " low=0, high=dataset.n_points - 1, size=int(dataset.n_points * subset)\n", ")\n", "points = dataset.points[selection]\n", "xyz = points.ravel()\n", "elevation = points[:, -1].ravel()\n", "min_elevation = np.amin(elevation)\n", "max_elevation = np.amax(elevation)\n", "print(f\"Number of points: {points.shape}\")\n", "print(f\"Elevation range: [{min_elevation}, {max_elevation}]\")\n", "\n", "# Setup VTK rendering of PointCloud\n", "app = dash.Dash(__name__)\n", "server = app.server\n", "\n", "vtk_view = dash_vtk.View(\n", " [\n", " dash_vtk.PointCloudRepresentation(\n", " xyz=xyz,\n", " scalars=elevation,\n", " colorDataRange=[min_elevation, max_elevation],\n", " property={\"pointSize\": 2},\n", " )\n", " ]\n", ")\n", "\n", "app.layout = html.Div(\n", " style={\"height\": \"calc(100vh - 16px)\"},\n", " children=[html.Div(vtk_view, style={\"height\": \"100%\", \"width\": \"100%\"})],\n", ")\n", "\n", "if __name__ == \"__main__\":\n", " app.run_server(debug=True, port=8891)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "也可以直接使用 `open3d` 加载 `.ply` 文件:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of points: (8192, 3)\n", "Elevation range: [-0.340668, 0.300229]\n" ] } ], "source": [ "import numpy as np\n", "import open3d\n", "\n", "pcd = open3d.io.read_point_cloud(\"test.ply\")\n", "points = np.asarray(pcd.points)\n", "xyz = points.ravel()\n", "elevation = points[:, -1].ravel()\n", "min_elevation = np.amin(elevation)\n", "max_elevation = np.amax(elevation)\n", "print(f\"Number of points: {points.shape}\")\n", "print(f\"Elevation range: [{min_elevation}, {max_elevation}]\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "py311", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.7" } }, "nbformat": 4, "nbformat_minor": 2 }