Notifications
Clear all

[Closed] Speeding up importing XYZ points

Hi guys,

I’ve got a set of data in a text file which I can easily import into MAX. When I say a set, I mean around 700’000 points (so that’s 700’000 x 3 separate numbers).

Ultimately, I’d like to convert this into a mesh (the data is from a 3D laser scanner), so any help with that is appreciated, but what I need first is to speed up the importing of points.

At the moment, it takes about 10 to 15 minutes to import the points and put them in an array. Any tips on making it go faster?

Currently I’ve disabled the print parts of the script as I noticed this was slowing it down considerably. However, this does mean that Max hangs and I have no idea where in the loop MAX is or how long it’s likely to take – any suggestions on this also?

My data is formatted exactly thus:

X1, Y1, Z1
X2, Y2, Z2
X3, Y3, Z3
X4, Y4, Z4

and so on for another 699’996 or so lines.

The main parsing section of the code is thus:


i = 1
while not eof in_file do
(
s = readLine in_file
arr = filterString s ", "
for j = 1 to 3 do
(
	 i += 1
	 vert_array[i] = arr[j]
)
 
--str = "i Number: " + i as string + " at position:" + pos as string
--Print str
 
)

Also, for what it’s worth my computer hasn’t got the greatest spec: 3GHz with 2GB RAM

7 Replies

I would suggest avoiding the loading of all vertices into memory before creating the mesh.
Of course, this might require the knowledge of the total number of vertices to be read, but it looks like you know it already.

In short, do this:

*Create a mesh with numverts and numfaces set before the actual vertices have been read, and faces set to 0. This will give you a mesh with 700,000 vertices, all set to [0,0,0] by default.
*Loop to read the data as you do now, and for each vertex, instead of appending to an array, just set the corresponding vertex of the existing mesh to the Point3 value.
*Once done, call Update() on the mesh to refresh its internal caches, just in case.

I switched to this mode when writing BFF because loading 1+ million faces/vertices into memory wasn’t possible in those days – my machine had around 512MB back in 2001, and the CPU wasn’t even 1GHz…

Since this avoids any memory allocations beyond the creation of the mesh itself, it can work with any number of vertices. If the slow part is memory management, then it might also run faster than your current code.

fn saveMesh theObj =
(
	st = timestamp()
	theMesh = snapshotasmesh theObj
	theCount = theMesh.numverts
	theFile = createFile ("C:\	emp\\MeshOutputTest.txt")
	format "%
" theCount to:theFile
	for v = 1 to theCount do
	(
		theVert = getVert theMesh v
		format "%, %, %
" theVert.x theVert.y theVert.z to:theFile
	)
	close theFile
	delete theMesh
	timestamp()-st
)--2719ms with 131330 verts.

fn readMesh =
(
	st = timestamp()
	theFile = openFile ("C:\	emp\\MeshOutputTest.txt")
	theCount = readValue theFile
	theMesh = mesh numverts:theCount numfaces:0
	for v = 1 to theCount do
		setVert theMesh v (Point3 (readValue theFile) (readValue theFile) (readValue theFile))
	close theFile
	timestamp()-st
)--6781ms with 131330 verts.

This is a quick test. I saved a 64 segs teapot (131,330 vertices) in the same format as you used, with the difference that the first entry in the file was the vertex count.

The saving took 2.7 seconds, the loading 6.8 seconds.

1 Reply
(@bobo)
Joined: 1 year ago

Posts: 0

Just tested with a plane with 1000×1000 segments which has 1M vertices.
Saving: 21.922 sec.
Loading:45.063 sec.

Well, this numfaces bit might be a problem: I don’t have information on faces at all since the 3D laser scanner only generates a point cloud – will that hamper anything?

1 Reply
(@bobo)
Joined: 1 year ago

Posts: 0

Nope, set it to 0 as I did. It creates a mesh with only vertices and no faces at all.

Is there something you don’t know the answer to? Lol!!

Thanks a lot, I’ll give it a try!!

OK, so that’s done and it all works fine – thanks very much!!

Now, is there a way to populate the mesh with faces to get some sort of 3D shape? It’s a long shot I know, but just wondering if it can be done. At the moment, unless I select the vertices, I can’t see anything…

Also, when I import the points and I select Editable Mesh –> Vertex it doesn’t show all the points (Max 2008). However, when I apply a Mesh Smooth modifier and select the vertices in that, all the vertices show?!!