generated from HiraiKyo/pyproject-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from HiraiKyo/feature/stl2ply
Add feature: generate stil file to ply with camera direction.
- Loading branch information
Showing
6 changed files
with
38 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
!.gitignore | ||
!sample/ | ||
!samples/ | ||
samples/stl2ply.ply |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
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 @@ | ||
from .stl2ply import stl2ply as stl2ply |
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,25 @@ | ||
#!/usr/bin/env /usr/bin/python3 | ||
|
||
from typing import List | ||
|
||
import numpy as np | ||
import open3d as o3d | ||
|
||
|
||
def stl2ply( | ||
name: str, cam_dir: List[float] = [-100.0, -100, 100], sample_points: int = 1000000, voxel_size: float = 1.0 | ||
): | ||
mesh = o3d.io.read_triangle_mesh(name + ".stl") | ||
mesh.compute_vertex_normals() | ||
pcd = mesh.sample_points_uniformly(number_of_points=sample_points) | ||
pcdd = pcd.voxel_down_sample(voxel_size=voxel_size) | ||
|
||
diameter = np.linalg.norm(np.asarray(pcdd.get_max_bound()) - np.asarray(pcdd.get_min_bound())) | ||
camera = np.array(cam_dir) | ||
radius = diameter * 100 | ||
|
||
_, pt_map = pcdd.hidden_point_removal(camera, radius) | ||
|
||
pcd = pcdd.select_by_index(pt_map) | ||
|
||
o3d.io.write_point_cloud(name + ".ply", pcd) |
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,10 @@ | ||
import os | ||
|
||
from ply_processor_basics.stl import stl2ply | ||
|
||
|
||
def test_stl2ply_simple(): | ||
filename = "data/samples/stl2ply" | ||
stl2ply(filename) | ||
# ファイルがdata/test.plyに生成されている事を確認 | ||
assert os.path.exists(f"{filename}.ply") |