|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# ImmersivePoints - Inline Point Cloud Visualization\n", |
| 8 | + "\n", |
| 9 | + "This notebook demonstrates how to render point clouds directly in Jupyter notebooks using the `immersivePoints` package." |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "code", |
| 14 | + "execution_count": null, |
| 15 | + "metadata": {}, |
| 16 | + "outputs": [], |
| 17 | + "source": [ |
| 18 | + "# Install the package (run once)\n", |
| 19 | + "# !pip install -e .." |
| 20 | + ] |
| 21 | + }, |
| 22 | + { |
| 23 | + "cell_type": "code", |
| 24 | + "execution_count": null, |
| 25 | + "metadata": {}, |
| 26 | + "outputs": [], |
| 27 | + "source": [ |
| 28 | + "import numpy as np\n", |
| 29 | + "import immersivePoints as ip" |
| 30 | + ] |
| 31 | + }, |
| 32 | + { |
| 33 | + "cell_type": "markdown", |
| 34 | + "metadata": {}, |
| 35 | + "source": [ |
| 36 | + "## Example 1: Random Point Cloud with XYZI Format\n", |
| 37 | + "\n", |
| 38 | + "Create a random point cloud with position (X, Y, Z) and intensity/hue (I)." |
| 39 | + ] |
| 40 | + }, |
| 41 | + { |
| 42 | + "cell_type": "code", |
| 43 | + "execution_count": null, |
| 44 | + "metadata": {}, |
| 45 | + "outputs": [], |
| 46 | + "source": [ |
| 47 | + "# Generate random points with XYZI format\n", |
| 48 | + "n_points = 5000\n", |
| 49 | + "points = np.random.randn(n_points, 4).astype(np.float32)\n", |
| 50 | + "points[:, :3] *= 5 # Scale positions\n", |
| 51 | + "points[:, 3] = np.abs(points[:, 3]) % 1.0 # Hue should be 0-1\n", |
| 52 | + "\n", |
| 53 | + "# Render inline\n", |
| 54 | + "ip.renderPoints(points)" |
| 55 | + ] |
| 56 | + }, |
| 57 | + { |
| 58 | + "cell_type": "markdown", |
| 59 | + "metadata": {}, |
| 60 | + "source": [ |
| 61 | + "## Example 2: Point Cloud with RGB Colors\n", |
| 62 | + "\n", |
| 63 | + "Create a point cloud with full RGB color control." |
| 64 | + ] |
| 65 | + }, |
| 66 | + { |
| 67 | + "cell_type": "code", |
| 68 | + "execution_count": null, |
| 69 | + "metadata": {}, |
| 70 | + "outputs": [], |
| 71 | + "source": [ |
| 72 | + "# Create a colorful sphere\n", |
| 73 | + "n_points = 10000\n", |
| 74 | + "\n", |
| 75 | + "# Generate points on a sphere surface\n", |
| 76 | + "theta = np.random.uniform(0, 2 * np.pi, n_points)\n", |
| 77 | + "phi = np.random.uniform(0, np.pi, n_points)\n", |
| 78 | + "r = 5\n", |
| 79 | + "\n", |
| 80 | + "x = r * np.sin(phi) * np.cos(theta)\n", |
| 81 | + "y = r * np.sin(phi) * np.sin(theta)\n", |
| 82 | + "z = r * np.cos(phi)\n", |
| 83 | + "\n", |
| 84 | + "# Color based on position\n", |
| 85 | + "red = (x - x.min()) / (x.max() - x.min())\n", |
| 86 | + "green = (y - y.min()) / (y.max() - y.min())\n", |
| 87 | + "blue = (z - z.min()) / (z.max() - z.min())\n", |
| 88 | + "\n", |
| 89 | + "# Combine into XYZRGB array\n", |
| 90 | + "points_rgb = np.column_stack([x, y, z, red, green, blue]).astype(np.float32)\n", |
| 91 | + "\n", |
| 92 | + "# Render with custom settings\n", |
| 93 | + "ip.renderPoints(points_rgb, point_size=0.1, background_color=0x1a1a2e, height=500)" |
| 94 | + ] |
| 95 | + }, |
| 96 | + { |
| 97 | + "cell_type": "markdown", |
| 98 | + "metadata": {}, |
| 99 | + "source": [ |
| 100 | + "## Example 3: Simple XYZ Points\n", |
| 101 | + "\n", |
| 102 | + "If you only have XYZ coordinates, the package will automatically add a default color." |
| 103 | + ] |
| 104 | + }, |
| 105 | + { |
| 106 | + "cell_type": "code", |
| 107 | + "execution_count": null, |
| 108 | + "metadata": {}, |
| 109 | + "outputs": [], |
| 110 | + "source": [ |
| 111 | + "# Create a spiral\n", |
| 112 | + "t = np.linspace(0, 10 * np.pi, 5000)\n", |
| 113 | + "x = t * np.cos(t) * 0.2\n", |
| 114 | + "y = t * 0.5\n", |
| 115 | + "z = t * np.sin(t) * 0.2\n", |
| 116 | + "\n", |
| 117 | + "# Just XYZ - will get default color\n", |
| 118 | + "points_xyz = np.column_stack([x, y, z]).astype(np.float32)\n", |
| 119 | + "\n", |
| 120 | + "ip.renderPoints(points_xyz, point_size=0.08)" |
| 121 | + ] |
| 122 | + }, |
| 123 | + { |
| 124 | + "cell_type": "markdown", |
| 125 | + "metadata": {}, |
| 126 | + "source": [ |
| 127 | + "## Example 4: Generate VR Link\n", |
| 128 | + "\n", |
| 129 | + "Generate a link to view the point cloud in VR on immersivepoints.com." |
| 130 | + ] |
| 131 | + }, |
| 132 | + { |
| 133 | + "cell_type": "code", |
| 134 | + "execution_count": null, |
| 135 | + "metadata": {}, |
| 136 | + "outputs": [], |
| 137 | + "source": [ |
| 138 | + "# Show a clickable VR link\n", |
| 139 | + "ip.showVR(points_rgb)" |
| 140 | + ] |
| 141 | + }, |
| 142 | + { |
| 143 | + "cell_type": "code", |
| 144 | + "execution_count": null, |
| 145 | + "metadata": {}, |
| 146 | + "outputs": [], |
| 147 | + "source": [ |
| 148 | + "# Or get just the URL string\n", |
| 149 | + "vr_url = ip.renderPointsVR(points_rgb)\n", |
| 150 | + "print(\"VR URL:\", vr_url[:100] + \"...\")" |
| 151 | + ] |
| 152 | + } |
| 153 | + ], |
| 154 | + "metadata": { |
| 155 | + "kernelspec": { |
| 156 | + "display_name": "Python 3", |
| 157 | + "language": "python", |
| 158 | + "name": "python3" |
| 159 | + }, |
| 160 | + "language_info": { |
| 161 | + "name": "python", |
| 162 | + "version": "3.9.0" |
| 163 | + } |
| 164 | + }, |
| 165 | + "nbformat": 4, |
| 166 | + "nbformat_minor": 4 |
| 167 | +} |
0 commit comments