Description
Hi there,
first of all, I have to thank you for providing this package, it really provides a very nice interface to occ.
In my project, I have to display point clouds and meshes with about 10M vertices. While the display of these entities works nice, the creation is very slow. I'm using the following approach:
occ_points = Graphic3d_ArrayOfPoints(self.points.shape[0])
for p in self.points:
occ_points.AddVertex(*p)
pc = AIS_PointCloud()
pc.SetPoints(occ_points)
and for the mesh:
n_verts = len(vertices)
c_pts = TColgp_Array1OfPnt(1, n_verts)
for i in range(n_verts):
c_pts.SetValue(i+1, gp_Pnt(*vertices[i,:]))
n_faces = len(faces)
c_faces = Poly_Array1OfTriangle(1, n_faces)
for i in range(n_faces):
c_faces.SetValue(i+1, Poly_Triangle(int(faces[i, 0])+1, int(faces[i, 1])+1, int(faces[i, 2])+1))
occ_tris = Poly_Triangulation(c_pts, c_faces)
While this works, the loops are pretty slow. I imagine, there are better ways to send the arrays through swig. I think numpy provides swig extensions for such cases, but I think it's not used here.
On the other side, since the arrays on C++-side are simply structs, it would also be possible to simply point it to the numpy data in memory. As far as I can see, the NCollection_Array1 provides three options for that:
- Initialize the length and provide a pointer to the first element
- Use the "Move" method of an already initialized object to point it to some memory
- Use the "Assign" method to copy the data from a pointer
I can get a PyCapsule object for the pointer from a numpy-array using the array_struct property, but this is not accepted as a type by the swig interface.
Are there other approaches for reducing data copy and loops like that? Has anybody successfully transferred data using a numpy pointer or other techniques?
Thanks in advance