def actions(): SOURCE_NAME = "Source" RESULT_NAME = "Result (Poisson reconstruction)" TRUTH_NAME = "Ground truth" bunny = o3dex.get_bunny_mesh() bunny.paint_uniform_color((1, 0.75, 0)) bunny.compute_vertex_normals() cloud = o3d.geometry.PointCloud() cloud.points = bunny.vertices cloud.normals = bunny.vertex_normals def make_mesh(o3dvis): # TODO: call o3dvis.get_geometry instead of using bunny mesh, _ = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson( cloud) mesh.paint_uniform_color((1, 1, 1)) mesh.compute_vertex_normals() o3dvis.add_geometry({"name": RESULT_NAME, "geometry": mesh}) o3dvis.show_geometry(SOURCE_NAME, False) def toggle_result(o3dvis): truth_vis = o3dvis.get_geometry(TRUTH_NAME).is_visible o3dvis.show_geometry(TRUTH_NAME, not truth_vis) o3dvis.show_geometry(RESULT_NAME, truth_vis) vis.draw([{ "name": SOURCE_NAME, "geometry": cloud }, { "name": TRUTH_NAME, "geometry": bunny, "is_visible": False }], actions=[("Create Mesh", make_mesh), ("Toggle truth/result", toggle_result)])
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. # ---------------------------------------------------------------------------- import open3d as o3d import numpy as np import sys import os pyexample_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(pyexample_path) import open3d_example as o3dex if __name__ == "__main__": gt_mesh = o3dex.get_bunny_mesh() pcd = gt_mesh.sample_points_poisson_disk(5000) # Invalidate existing normals. pcd.normals = o3d.utility.Vector3dVector(np.zeros((1, 3))) print("Displaying input pointcloud ...") o3d.visualization.draw_geometries([pcd], point_show_normal=True) pcd.estimate_normals() print("Displaying pointcloud with normals ...") o3d.visualization.draw_geometries([pcd], point_show_normal=True) print("Printing the normal vectors ...") print(np.asarray(pcd.normals))
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. # ---------------------------------------------------------------------------- import open3d as o3d import numpy as np import copy import os import sys dir_path = os.path.dirname(os.path.abspath(__file__)) sys.path.append(dir_path + "/..") import open3d_example as o3dex if __name__ == "__main__": mesh = o3dex.get_bunny_mesh().subdivide_midpoint(number_of_iterations=2) vert = np.asarray(mesh.vertices) min_vert, max_vert = vert.min(axis=0), vert.max(axis=0) for _ in range(30): cube = o3d.geometry.TriangleMesh.create_box() cube.scale(0.005, center=cube.get_center()) cube.translate( ( np.random.uniform(min_vert[0], max_vert[0]), np.random.uniform(min_vert[1], max_vert[1]), np.random.uniform(min_vert[2], max_vert[2]), ), relative=False, ) mesh += cube mesh.compute_vertex_normals()
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. # ---------------------------------------------------------------------------- import open3d as o3d import numpy as np import os import sys pyexample_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(pyexample_path) import open3d_example as o3dex if __name__ == "__main__": mesh_in = o3dex.get_bunny_mesh() print("Before Simplification: ", mesh_in) o3d.visualization.draw_geometries([mesh_in]) voxel_size = max(mesh_in.get_max_bound() - mesh_in.get_min_bound()) / 32 mesh_smp = mesh_in.simplify_vertex_clustering( voxel_size=voxel_size, contraction=o3d.geometry.SimplificationContraction.Average) print("After Simplification with voxel size =", voxel_size, ":\n", mesh_smp) o3d.visualization.draw_geometries([mesh_smp]) voxel_size = max(mesh_in.get_max_bound() - mesh_in.get_min_bound()) / 16 mesh_smp = mesh_in.simplify_vertex_clustering( voxel_size=voxel_size, contraction=o3d.geometry.SimplificationContraction.Average) print("After Simplification with voxel size =", voxel_size, ":\n", mesh_smp)
# The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. # ---------------------------------------------------------------------------- import open3d as o3d import numpy as np import sys import os dir_path = os.path.dirname(os.path.abspath(__file__)) sys.path.append(dir_path + "/..") import open3d_example as o3dex if __name__ == "__main__": print("Displaying pointcloud with convex hull ...") pcl = o3dex.get_bunny_mesh().sample_points_poisson_disk( number_of_points=10000) hull, _ = pcl.compute_convex_hull() hull_ls = o3d.geometry.LineSet.create_from_triangle_mesh(hull) hull_ls.paint_uniform_color((1, 0, 0)) o3d.visualization.draw([pcl, hull_ls])