-
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
35ae631
commit b0ca682
Showing
9 changed files
with
369 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# ------------------------------------------------------------------------------- | ||
# Example: Demonstrating vec2, vec3, and vec4 | ||
# ------------------------------------------------------------------------------- | ||
# This script demonstrates how to use the Easy3D vector classes: | ||
# - `vec2`: Represents 2D points | ||
# - `vec3`: Represents 3D points | ||
# - `vec4`: Represents 4D points | ||
# The script shows how to create these objects and convert them to NumPy arrays | ||
# for easy manipulation in Python. | ||
# ------------------------------------------------------------------------------- | ||
|
||
# ------------------------------------------------------------------------------- | ||
# 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-debug/lib/python") | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Importing Necessary Libraries | ||
# ------------------------------------------------------------------------------- | ||
import easy3d # Easy3D library for 3D visualization and processing | ||
import numpy as np # NumPy library (used for handling data) | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Initializing Easy3D | ||
# ------------------------------------------------------------------------------- | ||
# The `easy3d.initialize(True)` function initializes the Easy3D library. | ||
# The `True` parameter enables detailed logging, which is useful for debugging. | ||
easy3d.initialize(True) | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Creating and Converting a vec2 Object | ||
# ------------------------------------------------------------------------------- | ||
# A `vec2` object represents a 2D point. We create a `vec2` object using two values. | ||
# Optionally, the object can also be created using a list: `vec2([x, y])`. | ||
v2 = easy3d.vec2(2.0, 2.0) # or v2 = easy3d.vec2([2.0, 2.0]) | ||
|
||
# The `to_numpy()` method converts the `vec2` object into a NumPy array. | ||
np_v2 = v2.to_numpy() # Convert to NumPy array | ||
|
||
# Output the NumPy array representation of the `vec2` object. | ||
print("vec2 as NumPy array:", np_v2) # Output: [2. 2.] | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Creating and Converting a vec3 Object | ||
# ------------------------------------------------------------------------------- | ||
# A `vec3` object represents a 3D point. We create a `vec3` object using three values. | ||
# Optionally, the object can also be created using a list: `vec3([x, y, z])`. | ||
v3 = easy3d.vec3(3.0, 3.0, 3.0) # or v3 = easy3d.vec3([3.0, 3.0, 3.0]) | ||
|
||
# The `to_numpy()` method converts the `vec3` object into a NumPy array. | ||
np_v3 = v3.to_numpy() # Convert to NumPy array | ||
|
||
# Output the NumPy array representation of the `vec3` object. | ||
print("vec3 as NumPy array:", np_v3) # Output: [3. 3. 3.] | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Creating and Converting a vec4 Object | ||
# ------------------------------------------------------------------------------- | ||
# A `vec4` object represents a 4D point. We create a `vec4` object using four values. | ||
# Optionally, the object can also be created using a list: `vec4([x, y, z, w])`. | ||
v4 = easy3d.vec4(4.0, 4.0, 4.0, 4.0) # or v4 = easy3d.vec4([4.0, 4.0, 4.0, 4.0]) | ||
|
||
# The `to_numpy()` method converts the `vec4` object into a NumPy array. | ||
np_v4 = v4.to_numpy() # Convert to NumPy array | ||
|
||
# Output the NumPy array representation of the `vec4` object. | ||
print("vec4 as NumPy array:", np_v4) # Output: [4. 4. 4. 4.] |
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,81 @@ | ||
# ------------------------------------------------------------------------------- | ||
# Example: Working with the PointCloud class | ||
# ------------------------------------------------------------------------------- | ||
# This script demonstrates how to use the Easy3D `PointCloud` class: | ||
# - Initialize a `PointCloud` object with a NumPy array of points. | ||
# - Add multiple points at once using a NumPy array. | ||
# - Add individual points using various formats (vec3, lists, NumPy arrays). | ||
# - Export the entire point cloud back to a NumPy array. | ||
# ------------------------------------------------------------------------------- | ||
|
||
# ------------------------------------------------------------------------------- | ||
# 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-debug/lib/python") | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Importing Necessary Libraries | ||
# ------------------------------------------------------------------------------- | ||
import easy3d # Easy3D library for 3D visualization and processing | ||
import numpy as np # NumPy library (used for handling data) | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Initializing Easy3D | ||
# ------------------------------------------------------------------------------- | ||
# The `easy3d.initialize(True)` function initializes the Easy3D library. | ||
# The `True` parameter enables detailed logging, which is useful for debugging. | ||
easy3d.initialize(True) | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Creating a PointCloud Object and Initializing with Points | ||
# ------------------------------------------------------------------------------- | ||
# Create a NumPy array of initial points (each point is represented by [x, y, z]). | ||
initial_points = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]) # Initial points | ||
|
||
# Initialize a `PointCloud` object with the array of points. | ||
pc = easy3d.PointCloud(initial_points) | ||
|
||
# Set a name for the point cloud. This helps with identification in complex scenes. | ||
pc.set_name("Small Point Cloud") | ||
|
||
# Output the name of the point cloud. | ||
print(f"Point cloud name: {pc.name()}") # Output: Small Point Cloud | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Adding Multiple Points to the PointCloud | ||
# ------------------------------------------------------------------------------- | ||
# Create a NumPy array of additional points to add to the point cloud. | ||
more_points = np.array([[7.0, 8.0, 9.0], [10.0, 11.0, 12.0]]) # Additional points | ||
|
||
# Add the new points to the point cloud using `add_points`. | ||
pc.add_points(more_points) | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Adding Individual Points Using Various Formats | ||
# ------------------------------------------------------------------------------- | ||
# Add individual points using the `vec3` format. | ||
v3 = easy3d.vec3(3.0, 3.0, 3.0) # Creating a vec3 object | ||
pc.add_point(v3) # Add point using vec3 format | ||
pc.add_point(easy3d.vec3(1, 8, 8)) # Another point using vec3 | ||
|
||
# Add individual points using Python lists. | ||
pc.add_point([20, 20, 20]) # Add point using list format | ||
pc.add_point([5, 5, 5]) # Another point using list format | ||
|
||
# Add individual points using a NumPy array. | ||
point_np = np.array([4.0, 5.0, 6.0], dtype=np.float32) # Point in NumPy array format | ||
pc.add_point(point_np) # Add point using NumPy array format | ||
|
||
# ------------------------------------------------------------------------------- | ||
# Exporting the PointCloud Data to a NumPy Array | ||
# ------------------------------------------------------------------------------- | ||
# Convert the point cloud data back to a NumPy array using the `to_numpy()` method. | ||
points_np = pc.to_numpy() | ||
|
||
# Output the point cloud data in NumPy array format. | ||
print("Point cloud data:\n", points_np) |
Oops, something went wrong.