frompathlibimportPathfromcompas.colorsimportColorfromcompas.geometryimportLinefromcompas.geometryimportPointfromcompas.geometryimportPointcloudfromcompas.geometryimportPolygonfromcompas_cgal.polygonal_surface_reconstructionimportpolygonal_surface_reconstruction_ransacfromcompas_cgal.reconstructionimportpointset_normal_estimationfromcompas_viewerimportViewer# Define the file path for the point cloud dataFILE=Path(__file__).parent.parent.parent/"data"/"two_intersecting_boxes.ply"# Load the point cloud data from the PLY filecloud=Pointcloud.from_ply(FILE)# Estimate normals for the point cloudpoints,vectors=pointset_normal_estimation(cloud,4,True)vertices,faces=polygonal_surface_reconstruction_ransac(points,vectors)# Create polygons from vertices and facespolygons=[]forfaceinfaces:polygon=[]foriinface:polygon.append(Point(*vertices[i]))polygons.append(Polygon(polygon))# Create lines and properties for visualizing normalslines=[]line_properties=[]line_scale=25# Iterate over points and vectors to create lines and color propertiesforp,vinzip(points,vectors):# Create lineslines.append(Line(Point(p[0],p[1],p[2]),Point(p[0]+v[0]*line_scale,p[1]+v[1]*line_scale,p[2]+v[2]*line_scale,),))# Normalize vector components to be in the range [0, 1] for color representationr=(v[0]+1)*0.5g=(v[1]+1)*0.5b=(v[2]+1)*0.5# Store line color propertiesline_properties.append({"linecolor":Color(r,g,b)})# =============================================================================# Viz# =============================================================================viewer=Viewer()# viewer.renderer.camera.position = [5, -4, 2]# viewer.renderer.camera.target = [0, 1, 0])# viewer.scene.add(Pointcloud(points))# line_collection = Collection(lines, line_properties)# viewer.scene.add(line_collection)forpolygoninpolygons:viewer.scene.add(polygon,linewidth=2)viewer.show()