Last active
February 19, 2024 12:26
-
-
Save RobinCPC/cdbb40001fb5817625cf4e91d87ab4ea to your computer and use it in GitHub Desktop.
Render point cloud in PythonOCC WebGL
This file contains hidden or 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
#! /usr/bin/env python | |
from OCC.Display.WebGl.flask_server import * | |
import random | |
import time | |
import os | |
@app.route("/") | |
def show_pcl(): | |
# remove shapes from previous (avoid duplicate shape after F5 refresh) | |
my_ren._3js_shapes={} | |
my_ren._3js_edges={} | |
my_ren._3js_vertex={} | |
points_3d = [] | |
## Uncomment to load bunny.pcd | |
#pcd_file_name = os.path.join('.', 'bunny.pcd') | |
#pcd_file = open(pcd_file_name, 'r').readlines()[11:] | |
#print("Number of vertices: ", len(pcd_file)) | |
#for line in pcd_file: | |
# x, y, z = map(float, line.split()) | |
# points_3d.append(gp_Pnt(x, y, z)) | |
n_points = 1500 | |
for idx in range(n_points): | |
x = random.uniform(-250, 250) | |
y = random.uniform(-250, 250) | |
z = random.uniform(-250, 250) | |
pnt = gp_Pnt(x,y,z) | |
points_3d.append(pnt) | |
init_time = time.time() | |
# display point cloud for bunny.pcd, use smaller point size, like 0.005. For random point, use 15 | |
my_ren.ConvertShape(points_3d, export_edges=False, color=(0.0, 0.0, 0.0), point_size=15) | |
final_time = time.time() | |
print("\nTotal meshing time : ", final_time - init_time) | |
return render_template('index.html', occ_version=OCC_VERSION, threejs_version=THREEJS_RELEASE, | |
render_cfg=render_cfg, occ_shapes=my_ren._3js_shapes, occ_edges=my_ren._3js_edges, | |
occ_vertex=my_ren._3js_vertex) | |
if __name__ == "__main__": | |
app.run(host='localhost', port=8080, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment