From 9b0f678e27a172b5f0cff96bf3a0efc520ed45b7 Mon Sep 17 00:00:00 2001 From: HiraiKyo Date: Thu, 8 Aug 2024 16:53:10 +0900 Subject: [PATCH] simple test passed --- data/.gitignore | 3 ++- data/samples/stl2ply.py | 36 --------------------------- data/samples/stl2ply.stl | Bin 0 -> 11784 bytes ply_processor_basics/stl/__init__.py | 1 + ply_processor_basics/stl/stl2ply.py | 25 +++++++++++++++++++ tests/stl/test_stl2ply.py | 10 ++++++++ 6 files changed, 38 insertions(+), 37 deletions(-) delete mode 100644 data/samples/stl2ply.py create mode 100644 data/samples/stl2ply.stl create mode 100644 ply_processor_basics/stl/__init__.py create mode 100644 ply_processor_basics/stl/stl2ply.py create mode 100644 tests/stl/test_stl2ply.py diff --git a/data/.gitignore b/data/.gitignore index edfafe1..c3ccab8 100644 --- a/data/.gitignore +++ b/data/.gitignore @@ -1,2 +1,3 @@ !.gitignore -!sample/ \ No newline at end of file +!samples/ +samples/stl2ply.ply \ No newline at end of file diff --git a/data/samples/stl2ply.py b/data/samples/stl2ply.py deleted file mode 100644 index 8db406b..0000000 --- a/data/samples/stl2ply.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env /usr/bin/python3 - -import numpy as np -import open3d as o3d - -names = [ - "outer_mast_AX-VT-Fusion", - "outer_mast_AX-VT_inverse-Fusion", - "middle_mast_outside_AX-VT-Fusion", -] - - -def gen_ply(name: str): - mesh = o3d.io.read_triangle_mesh(name + ".stl") - mesh.compute_vertex_normals() - pcd = mesh.sample_points_uniformly(number_of_points=1000000) - pcdd = pcd.voxel_down_sample(voxel_size=1.0) - o3d.visualization.draw_geometries([pcdd]) - - diameter = np.linalg.norm( - np.asarray(pcdd.get_max_bound()) - np.asarray(pcdd.get_min_bound()) - ) - camera = np.array([-100, -100, 100]) - 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) - o3d.visualization.draw_geometries([pcd]) - - -if __name__ == "__main__": - for name in names: - gen_ply(name) diff --git a/data/samples/stl2ply.stl b/data/samples/stl2ply.stl new file mode 100644 index 0000000000000000000000000000000000000000..9fc8c73880a2a15ef2bced3c8073a40ea70e05f7 GIT binary patch literal 11784 zcmb`NZHyjO6~_l@f(23{G>r|APP=6dNELap@L~7K+yXn5RH?YsV%h>GjVUiKB&?}! z>A*rjVk0Jv(L^i;!77p%0+cA-#~Qx)L9~#lA-D~JCZs?q6dJ;d@%f)K=Q;nm&)n4y zJ|Eh%bIk3?h=CO zG=cm4)z|J2g6TAYd%L)Hn-EN=3EZh4eST61rqcxOyYn~QECkbO0(a5g1)GInI!)l7 zxc|BhLNJ{sFvD%;Go2>9Brllu>zIj{?Z4UaeW{6-=sd>EZ=btQk6#;xj?=ls#9$;X ztvWwh{jIR@@ZAF%gOQBjl?7hE|M(Q4`QB9DHUfJ87+NR<(`n+!FTWjjUba{Wrqjgp zSB6R`a!HLCP)lvrQIgx4x2z@i--7q-t`Yc)J$FK&}*d(XBJ=GD}I zr?uKNxK54Rs0+rTnEc0(SvM-ECa87 zZiAQ{`(7vSt{UyRXI#Q-pW6{pIguCc#Va+4P4C^>*)jeL(QvOa@M`IHL{v`Xg?q6c zh}nlXca{y$iiUfYfuHSegLv}?S9dPheUh9#xWw(e@F#VoQMpE5FyYtJ8XT8x5X%pT z&gJi%CADI8UIE+&@%riKc3!-5L9+YwPYkr(b2YrM7pjnT8-zg{%ls|>u4b{iT*R8HiDd$AsfJum!jbh0xc8tzpF z-rc($5tS2p;a;oDBUS;5OzuRddFWiguKs?a->&yp>wupv%m4Pz_Zl{U7a4*&a zapRNox<5N~jcB-6892A#cACfw_hLN|*#k?uONUF*aIZ3OHp1;Rp}Ek(><5Ua4zBF3 z{`C2x!Lc}h;Wmh=v)6R@oVi#CE^#|AJeQHy(Cq18h9#}RaoGm(%z{nbjhzo=jbe4q zk+_{EdijgioD7JGFWuCAZP_11!@bJDSrxZI?0WD!-6aR^5Q0nG&I`}5q&4z_3D!<& za9p;b@$SKG-KFn*LTbh8oVjs3O*C^o90@xf-;sGNB`kC6*P&4p6)Y}+&4k)is~IEA z3pKF}w9{##3{1EUq8>rf@Dd#l%cT4DG@-M^2#luMAnJJ~8eXC^(cTF7^)yii%nT#k z22tN1+E?U-d&S;t{4Ycqm~a~!^^>8C@$i!7TN1yXCdz^^jjXmAPE5_@mt zcAC&N!w8O)Wq;|dgGUx^5e<%oHPPN1xebkWLf1YcI8tw%d+Yhw4Y!E~$HLlf?~UAs zMmwQvxDgyF%cgt#lDGCui3Z2Q9>v}pxebkWLiZv@aHK5z)7bHQ$7i>T2FJo)%ibHg z4UKj}_f$r3q%3>>SI>@|v;TI{;8@rJ+Iu6nq0vt0-p~k+)Zg!l2FJoq*4{L^4UKvi zE(Djjt$S+Ci-V~5)RBhnicN#HQyLtXZD{Q4oj=Zd|9a8DPT$mVvao!++i61297b@Y zEW4z4j@o~0t!Qv8oRBO-?>02r2|YU*!IAnWNYUU}I1gG*-)(5rr&J-h#BDv-YR(!& zeM*fq^vr1*tew)}xNJkCKGBN?&abA9^SR~1-A)sFqBnvg_45p}MsX~h`z`jC2WxOUSkDzutM+pgpLgQ%V1myz zT*IaYy!88m-ua{dFys_Fhpvv|4>iZu{dzmw3`S`E`0yfzfOt!iV56N=7sxF zzfOq>oB{NU9nN@hW-2CpwJZa-sksC2mQ)=k*sHmorwI0HuC+|y&e5-%I0MOiM%4E=Vf>BVhoYB0fiJQtb-=8t~20(IY0q2>CnFs>C7?1eGcZ)WBqnss-*X07m) z(Ql*pjS0Wmh&Axc&~KyoJh($ literal 0 HcmV?d00001 diff --git a/ply_processor_basics/stl/__init__.py b/ply_processor_basics/stl/__init__.py new file mode 100644 index 0000000..dee59a9 --- /dev/null +++ b/ply_processor_basics/stl/__init__.py @@ -0,0 +1 @@ +from .stl2ply import stl2ply as stl2ply diff --git a/ply_processor_basics/stl/stl2ply.py b/ply_processor_basics/stl/stl2ply.py new file mode 100644 index 0000000..0f9e0cc --- /dev/null +++ b/ply_processor_basics/stl/stl2ply.py @@ -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) diff --git a/tests/stl/test_stl2ply.py b/tests/stl/test_stl2ply.py new file mode 100644 index 0000000..5820c73 --- /dev/null +++ b/tests/stl/test_stl2ply.py @@ -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")