Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature: generate stil file to ply with camera direction. #3

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion data/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
!.gitignore
!sample/
!samples/
samples/stl2ply.ply
36 changes: 0 additions & 36 deletions data/samples/stl2ply.py

This file was deleted.

Binary file added data/samples/stl2ply.stl
Binary file not shown.
1 change: 1 addition & 0 deletions ply_processor_basics/stl/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .stl2ply import stl2ply as stl2ply
25 changes: 25 additions & 0 deletions ply_processor_basics/stl/stl2ply.py
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)
10 changes: 10 additions & 0 deletions tests/stl/test_stl2ply.py
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")
Loading