Potree Point Cloud Viewer Example¶
This notebook demonstrates the capabilities of the anymap PotreeMap widget for creating interactive point cloud visualizations.
What is Potree?¶
Potree is a free open-source WebGL based point cloud renderer for large point clouds. It's particularly useful for:
- LiDAR data visualization
- 3D scanning results
- Large-scale point cloud datasets
- Archaeological documentation
- Building and infrastructure modeling
Setup¶
First, import the PotreeMap widget from anymap:
import os
from anymap import PotreeMap
print("Potree backend loaded successfully!")
Potree backend loaded successfully!
Basic Point Cloud Viewer¶
Create a basic Potree viewer. Note that you'll need a converted Potree point cloud dataset (with metadata.json) to load actual data:
# Create a basic Potree viewer
viewer = PotreeMap(
width="100%",
height="600px",
background_color="#1a1a1a", # Dark background
point_size=1.5,
point_size_type="adaptive", # Adaptive point sizing
point_shape="square",
camera_position=[0, 0, 50],
camera_target=[0, 0, 0],
fov=60,
edl_enabled=True, # Eye Dome Lighting for better depth perception
show_grid=True,
grid_size=10,
grid_color="#444444",
)
viewer
Loading Point Cloud Data¶
To load actual point cloud data, you need a Potree-converted dataset. You can convert LAS/LAZ files using PotreeConverter:
# Example conversion command (not run in this notebook)
PotreeConverter input.las -o output_directory --output-format LAZ
For demonstration purposes, here's how you would load a point cloud:
# Example of loading a point cloud (requires actual converted data)
# Replace with the URL to your Potree-converted point cloud metadata.json
# viewer.load_point_cloud(
# "https://example.com/pointclouds/your_pointcloud/metadata.json",
# "My Point Cloud"
# )
print("To load actual point cloud data, you need a Potree-converted dataset.")
print("Point the load_point_cloud method to your metadata.json file.")
To load actual point cloud data, you need a Potree-converted dataset. Point the load_point_cloud method to your metadata.json file.
Point Rendering Settings¶
Customize how points are rendered in the viewer:
# Adjust point size
viewer.set_point_size(2.0)
print("Point size set to 2.0")
# Change point size type
viewer.set_point_size_type("fixed") # Options: "fixed", "adaptive", "attenuation"
print("Point size type set to fixed")
# Change point shape
viewer.set_point_shape("circle") # Options: "square", "circle"
print("Point shape set to circle")
Point size set to 2.0 Point size type set to fixed Point shape set to circle
Camera Controls¶
Control the camera position and viewing angle:
# Set camera position and target
viewer.set_camera_position(position=[20, 20, 30], target=[0, 0, 0])
print("Camera position updated")
# Adjust field of view
viewer.set_fov(75)
print("Field of view set to 75 degrees")
# Set clipping distances
viewer.set_clip_distances(near=0.1, far=1000)
print("Clipping distances updated")
Camera position updated Field of view set to 75 degrees Clipping distances updated
Visual Enhancements¶
Configure visual effects and enhancements:
# Configure Eye Dome Lighting (EDL) for better depth perception
viewer.enable_edl(True)
viewer.set_edl_settings(radius=1.5, strength=1.2)
print("Eye Dome Lighting configured")
# Show coordinate grid
viewer.show_coordinate_grid(show=True, size=20, color="#666666")
print("Coordinate grid enabled")
# Change background color
viewer.set_background_color("#2a2a2a")
print("Background color changed")
Eye Dome Lighting configured Coordinate grid enabled Background color changed
Quality Settings¶
Adjust rendering quality for performance optimization:
# Set rendering quality
viewer.set_quality("high") # Options: "low", "medium", "high"
print("Rendering quality set to high")
# For large datasets, you might want to use "medium" or "low" for better performance
Rendering quality set to high
Multiple Point Clouds¶
Load and manage multiple point cloud datasets:
# Example of loading multiple point clouds
point_clouds = [
{
"url": "https://example.com/pointclouds/scan1/metadata.json",
"name": "Building Scan",
},
{
"url": "https://example.com/pointclouds/scan2/metadata.json",
"name": "Terrain Scan",
},
]
# viewer.load_multiple_point_clouds(point_clouds)
print("Multiple point clouds can be loaded simultaneously")
Multiple point clouds can be loaded simultaneously
Point Cloud Filtering¶
Filter points based on various criteria:
# Filter points by elevation
viewer.filter_by_elevation(min_elevation=0, max_elevation=50)
print("Elevation filter applied (0-50 units)")
# Filter by classification (LAS classification codes)
# Common classifications: 1=Unclassified, 2=Ground, 3=Low Vegetation, 4=Medium Vegetation, 5=High Vegetation, 6=Building
classifications = {
1: True, # Show unclassified
2: True, # Show ground
3: False, # Hide low vegetation
4: False, # Hide medium vegetation
5: False, # Hide high vegetation
6: True, # Show buildings
}
viewer.set_classification_visibility(classifications)
print("Classification filter applied")
# Clear all filters
# viewer.clear_filters()
# print("All filters cleared")
Elevation filter applied (0-50 units) Classification filter applied
Measurement Tools¶
Add measurement capabilities to the viewer:
# Add distance measurement tool
viewer.add_measurement("distance")
print("Distance measurement tool added")
# Add area measurement tool
viewer.add_measurement("area")
print("Area measurement tool added")
# Add volume measurement tool
viewer.add_measurement("volume")
print("Volume measurement tool added")
# Clear all measurements
# viewer.clear_measurements()
# print("All measurements cleared")
Distance measurement tool added Area measurement tool added Volume measurement tool added
Utility Functions¶
Demonstrate various utility functions:
# Fit point clouds to screen
viewer.fit_to_screen()
print("View fitted to point cloud bounds")
# Take a screenshot
viewer.take_screenshot()
print("Screenshot captured")
# Get current camera position
camera_pos = viewer.get_camera_position()
camera_target = viewer.get_camera_target()
print(f"Camera position: {camera_pos}")
print(f"Camera target: {camera_target}")
View fitted to point cloud bounds Screenshot captured Camera position: [20, 20, 30] Camera target: [0, 0, 0]
Multi-cell Rendering Test¶
Test that the viewer works correctly when displayed in multiple cells:
# Display the same viewer instance again
# This should maintain all the settings and state from above
viewer
# Change settings while displayed in multiple cells
viewer.set_background_color("#0a0a0a")
viewer.set_point_size(3.0)
viewer.set_point_shape("square")
print("Settings changed! Updates should appear on all viewer instances above.")
Settings changed! Updates should appear on all viewer instances above.
Creating a Second Viewer Instance¶
Create a separate viewer to verify independence:
# Create a second, independent viewer with different settings
viewer2 = PotreeMap(
width="100%",
height="500px",
background_color="#003366", # Blue background
point_size=1.0,
point_size_type="attenuation",
point_shape="circle",
camera_position=[10, 10, 20],
edl_enabled=False,
show_grid=False,
)
# Load different point cloud data (if available)
# viewer2.load_point_cloud(
# "https://example.com/pointclouds/another_scan/metadata.json",
# "Another Point Cloud"
# )
viewer2
Cleanup¶
Clear point clouds and reset viewers:
# Clear all point clouds from the first viewer
viewer.clear_point_clouds()
print("Point clouds cleared from first viewer")
# Clear measurements
viewer.clear_measurements()
print("Measurements cleared")
# Clear filters
viewer.clear_filters()
print("Filters cleared")
Point clouds cleared from first viewer Measurements cleared Filters cleared
Working with Real Data¶
To work with real point cloud data in Potree:
1. Convert your data¶
Use PotreeConverter to convert LAS/LAZ files:
PotreeConverter input.las -o output_directory --output-format LAZ
2. Host the data¶
Upload the converted point cloud directory to a web server that supports CORS.
3. Load in the viewer¶
viewer.load_point_cloud(
"https://your-server.com/pointclouds/your_data/metadata.json",
"Your Point Cloud Name"
)
Sample Data Sources¶
You can find sample Potree-compatible datasets at:
Summary¶
This notebook demonstrated the key features of the anymap PotreeMap widget:
- Point Cloud Visualization: Interactive rendering of large point cloud datasets
- Rendering Controls: Point size, shape, and quality settings
- Camera Controls: Position, target, field of view, and clipping
- Visual Effects: Eye Dome Lighting, coordinate grid, background
- Data Management: Loading single and multiple point clouds
- Filtering: Elevation and classification-based filtering
- Measurements: Distance, area, and volume measurement tools
- Multi-cell Rendering: Persistent state across notebook cells
- Multiple Instances: Independent viewer widgets
The PotreeMap widget provides a powerful platform for interactive point cloud visualization with the full capabilities of Potree.js in a Jupyter environment.