Skip to content

Commit

Permalink
Merge pull request #3 from HiraiKyo/feature/stl2ply
Browse files Browse the repository at this point in the history
Add feature: generate stil file to ply with camera direction.
  • Loading branch information
HiraiKyo authored Aug 8, 2024
2 parents 76b9863 + 9b0f678 commit 35015ff
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 37 deletions.
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")

0 comments on commit 35015ff

Please sign in to comment.