-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0ca682
commit 92ca840
Showing
8 changed files
with
186 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# ------------------------------------------------------------------------------- | ||
# Example: Offscreen Rendering | ||
# ------------------------------------------------------------------------------- | ||
# This script demonstrates how to render 3D models into images without using a viewer. | ||
# The model is rendered offscreen and saved as PNG images. | ||
# The script includes steps for changing the camera position to get different views. | ||
# ------------------------------------------------------------------------------- | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Adding Easy3D Python Bindings to the System Path | ||
# ------------------------------------------------------------------------------- | ||
# This is required if the bindings are not installed via `pip` but are located in | ||
# a local build directory. To install the bindings, use the following command: | ||
# "pip install YOUR_BUILD_DIRECTORY/lib/python/setup.py" | ||
# ------------------------------------------------------------------------------- | ||
import sys | ||
sys.path.append("../../cmake-build-release/lib/python") | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Importing Necessary Libraries | ||
# ------------------------------------------------------------------------------- | ||
import easy3d # Easy3D library for 3D visualization and processing | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Initializing Easy3D | ||
# ------------------------------------------------------------------------------- | ||
# The `easy3d.initialize(False)` function initializes the Easy3D library. | ||
# Use `True` to enable detailed logging, which is useful for debugging. | ||
easy3d.initialize(False) | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Setting Up the Model and Renderer | ||
# ------------------------------------------------------------------------------- | ||
# Define the input model file. In this case, a 3D model of a bunny in .ply format. | ||
file_name = easy3d.directory() + "/data/bunny.ply" | ||
print(f"Input file name: {file_name}") | ||
|
||
# Create an offscreen renderer instance. This allows rendering without a viewer. | ||
renderer = easy3d.OffScreen() | ||
|
||
# Add the model to the renderer. | ||
model = renderer.add_model(file_name) | ||
|
||
# Render the model to a PNG file. | ||
renderer.render(file_name + ".png") | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Modifying Camera Position | ||
# ------------------------------------------------------------------------------- | ||
# Get the current camera of the renderer. | ||
camera = renderer.camera() | ||
|
||
# Move the camera position slightly by adding a small offset. | ||
# This gives a different view of the model. | ||
pos = camera.position() + easy3d.vec3(0.2, 0.2, 0.2) | ||
|
||
# Set the new camera position. | ||
camera.setPosition(pos) | ||
|
||
# Render the model again with the new camera position. | ||
renderer.render(file_name + "2.png") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# ------------------------------------------------------------------------------- | ||
# Example: Estimate Point Cloud Normals | ||
# ------------------------------------------------------------------------------- | ||
# This script demonstrates how to estimate normals for a point cloud using Easy3D. | ||
# The script loads a point cloud from a file, estimates its normals, reorients | ||
# them, saves the resulting point cloud, and visualizes it in a viewer. | ||
# ------------------------------------------------------------------------------- | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Adding Easy3D Python Bindings to the System Path | ||
# ------------------------------------------------------------------------------- | ||
# This step is necessary if the Easy3D bindings are not installed via `pip` | ||
# but are located in a local build directory. To install the bindings, | ||
# use the following command: | ||
# "pip install YOUR_BUILD_DIRECTORY/lib/python/setup.py" | ||
# ------------------------------------------------------------------------------- | ||
import sys | ||
sys.path.append("../../cmake-build-release/lib/python") | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Importing Necessary Libraries | ||
# ------------------------------------------------------------------------------- | ||
import easy3d # Easy3D library for 3D visualization and processing | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Initializing Easy3D | ||
# ------------------------------------------------------------------------------- | ||
# Initialize the Easy3D library. The `True` parameter enables detailed logging, | ||
# which is helpful for debugging. | ||
easy3d.initialize(True) | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Loading the Point Cloud | ||
# ------------------------------------------------------------------------------- | ||
# Define the input point cloud file. In this case, a point cloud in .bin format. | ||
file_name = easy3d.directory() + "/data/bunny.bin" | ||
print(f"Input file name: {file_name}") | ||
|
||
# Load the point cloud from the specified file. | ||
pc = easy3d.PointCloudIO.load(file_name) | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Estimating Point Cloud Normals | ||
# ------------------------------------------------------------------------------- | ||
# Estimate normals for the point cloud. The `16` parameter specifies the | ||
# number of neighbors to use for normal estimation. | ||
easy3d.PointCloudNormals.estimate(pc, 16) | ||
|
||
# Reorient the normals to ensure consistency. | ||
easy3d.PointCloudNormals.reorient(pc, 16) | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Saving the Processed Point Cloud | ||
# ------------------------------------------------------------------------------- | ||
# Save the point cloud with estimated normals to a new file in .ply format. | ||
output_file = file_name + "-result.ply" | ||
easy3d.PointCloudIO.save(output_file, pc) | ||
print(f"Processed point cloud saved to: {output_file}") | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Visualizing the Point Cloud | ||
# ------------------------------------------------------------------------------- | ||
# Create a viewer instance to visualize the point cloud. | ||
viewer = easy3d.Viewer("Easy3D Viewer") | ||
|
||
# Set to an empty to get rid of the lengthy usage instructions | ||
viewer.set_usage("") | ||
|
||
# Add the point cloud model to the viewer and run the viewer to interact with the model. | ||
viewer.add_model(pc) | ||
viewer.run() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,71 @@ | ||
# ------------------------------------------------------------------------------- | ||
# Example: The basic Easy3D viewer | ||
# Example: Estimate Point Cloud Normals | ||
# ------------------------------------------------------------------------------- | ||
# This script demonstrates how to estimate normals for a point cloud using Easy3D. | ||
# The script loads a point cloud from a file, estimates its normals, reorients | ||
# them, saves the resulting point cloud, and visualizes it in a viewer. | ||
# ------------------------------------------------------------------------------- | ||
# This script demonstrates how to use the Easy3D `Viewer` class to: | ||
# 1. Create a 3D viewer with a custom title. | ||
# 2. Load and visualize a 3D mesh model (`SurfaceMesh`) from a file. | ||
# 3. Load and visualize a 3D point cloud model (`PointCloud`) from a file. | ||
# 4. Run the viewer to interact with the models (e.g., rotate, zoom, pan). | ||
|
||
|
||
# ------------------------------------------------------------------------------- | ||
# Adding Easy3D Python Bindings to the System Path | ||
# ------------------------------------------------------------------------------- | ||
# This is required if the bindings are not installed via `pip` but are located in | ||
# a local build directory. To install the bindings, use the following command: | ||
# This step is necessary if the Easy3D bindings are not installed via `pip` | ||
# but are located in a local build directory. To install the bindings, | ||
# use the following command: | ||
# "pip install YOUR_BUILD_DIRECTORY/lib/python/setup.py" | ||
# ------------------------------------------------------------------------------- | ||
import sys | ||
sys.path.append("../../cmake-build-debug/lib/python") | ||
sys.path.append("../../cmake-build-release/lib/python") | ||
|
||
# Importing necessary libraries | ||
import easy3d # Easy3D library for 3D visualization and processing | ||
import numpy as np # NumPy library (used for handling data if needed) | ||
# ------------------------------------------------------------------------------- | ||
# Importing Necessary Libraries | ||
# ------------------------------------------------------------------------------- | ||
import easy3d # Easy3D library for 3D visualization and processing | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Initializing Easy3D | ||
# ------------------------------------------------------------------------------- | ||
# The `easy3d.initialize(True)` function initializes the Easy3D library. | ||
# The `True` parameter enables detailed logging, which is useful for debugging. | ||
# Initialize the Easy3D library. The `True` parameter enables detailed logging, | ||
# which is helpful for debugging. | ||
easy3d.initialize(True) | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Creating a Viewer | ||
# Loading the Point Cloud | ||
# ------------------------------------------------------------------------------- | ||
# The `Viewer` class provides a GUI window for visualizing 3D models. | ||
# Here, we create a viewer instance with a custom title, "Easy3D Viewer". | ||
viewer = easy3d.Viewer("Easy3D Viewer") | ||
# Define the input point cloud file. In this case, a point cloud in .bin format. | ||
file_name = easy3d.directory() + "/data/bunny.bin" | ||
print(f"Input file name: {file_name}") | ||
|
||
# Load the point cloud from the specified file. | ||
pc = easy3d.PointCloudIO.load(file_name) | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Loading and Adding a 3D Mesh Model | ||
# Estimating Point Cloud Normals | ||
# ------------------------------------------------------------------------------- | ||
# Load a 3D mesh file (e.g., Stanford Bunny in .ply format). | ||
# The `easy3d.directory()` function retrieves the root directory of Easy3D's | ||
# resources. The model is located in the `data` subdirectory. | ||
mesh_file = easy3d.directory() + "/data/bunny.ply" | ||
|
||
# Add the mesh model to the viewer. | ||
# This can be done directly using the file path, as shown below: | ||
viewer.add_model(mesh_file) | ||
# Estimate normals for the point cloud. The `16` parameter specifies the | ||
# number of neighbors to use for normal estimation. | ||
easy3d.PointCloudNormals.estimate(pc, 16) | ||
|
||
# Alternatively, you can load the model as a `SurfaceMesh` object and add it: | ||
# model = easy3d.SurfaceMeshIO.load(mesh_file) | ||
# viewer.add_model(model) | ||
# Reorient the normals to ensure consistency. | ||
easy3d.PointCloudNormals.reorient(pc, 16) | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Loading and Adding a 3D Point Cloud Model | ||
# Saving the Processed Point Cloud | ||
# ------------------------------------------------------------------------------- | ||
# Load a 3D point cloud file (e.g., a polyhedron in .bin format). | ||
pointcloud_file = easy3d.directory() + "/data/polyhedron.bin" | ||
|
||
# The `PointCloudIO.load()` function reads the point cloud data from the file. | ||
pointcloud = easy3d.PointCloudIO.load(pointcloud_file) | ||
|
||
# Add the point cloud model to the viewer. | ||
# You can add the point cloud object directly as shown below: | ||
viewer.add_model(pointcloud) | ||
|
||
# Alternatively, the point cloud file path can also be added directly: | ||
# viewer.add_model(pointcloud_file) | ||
# Save the point cloud with estimated normals to a new file in .ply format. | ||
output_file = file_name + "-result.ply" | ||
easy3d.PointCloudIO.save(output_file, pc) | ||
print(f"Processed point cloud saved to: {output_file}") | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Running the Viewer | ||
# Visualizing the Point Cloud | ||
# ------------------------------------------------------------------------------- | ||
# The `viewer.run()` function launches the viewer window, where users can: | ||
# - Interact with the 3D models (e.g., rotate, zoom, pan). | ||
# - Explore the structure and details of the loaded models. | ||
# Create a viewer instance to visualize the point cloud. | ||
viewer = easy3d.Viewer("Easy3D Viewer") | ||
|
||
# Set to an empty to get rid of the lengthy usage instructions | ||
viewer.set_usage("") | ||
|
||
# Add the point cloud model to the viewer and run the viewer to interact with the model. | ||
viewer.add_model(pc) | ||
viewer.run() |