I have the following function to save points cloud in PLOT3D format:
def write(filename, mesh):
"""
Write the mesh to filename in PLOT3D format.
filename: is the name of the output file.
mesh: is a numpy array of size (N,2) or (N, 3) where N is the number of points. mesh[i] is a numpy array coordinates of the i'th point.
"""
points = mesh.points
imax = np.unique(points[:, 0]).size
jmax = np.unique(points[:, 1]).size
_2d = False
if points.shape[1] == 2:
_2d = True
elif np.unique(points[:, 2]).size == 1:
_2d = True
with open(filename, "w") as p3dfile:
if not _2d:
kmax = np.unique(points[:, 2]).size
print(imax, jmax, kmax, file=p3dfile)
for value in points.flatten(order="F"):
print(value, file=p3dfile)
else:
print(imax, jmax, file=p3dfile)
for value in points[:, 0:2].flatten(order="F"):
print(value, file=p3dfile)
For large number of points this function is very slow.
I appreciate any suggestion to improve the code above.