Author Topic: Advice on speeding up union of thousands of solids  (Read 1749 times)

0 Members and 1 Guest are viewing this topic.

jh_dempsey

  • Mosquito
  • Posts: 11
Advice on speeding up union of thousands of solids
« on: July 21, 2020, 07:25:37 AM »
Hi All

I have already written some code which replicates the "Extract Solids From Surface" tool in Civil 3D
It takes a surface, extracts its triangles, extrudes those triangles down to form a 3D solid, then runs a union command on the 3D solids to create a single solid.

All of the above works, but the union command takes a long time to run.
I'm finding my script takes up to 600 seconds to run when trying to union the solids on a large surface.

When I switched to inserting each individual triangle solid into a block, the run time came down to 30-40 seconds, so its clear the union command has a huge time overhead, particularly when a surface can have tens of thousands of triangles.

I still want to use the union option if i can, mainly because AutoCAD seems to struggle when I go into 3D view to view the output. I have read somewhere that AutoCADs performance will be much improved if it's trying to display a single large solid, rather than 20,000 small individual solids. At the moment, trying to view that block which contains 20,000+ individual solids grounds my Civil 3D to a halt, and I've got a pretty decent CAD spec machine.

Does anyone know of any way in which I can speed up the union command? Could the BREP tools help out?
Is it possible to create an AutoCAD surface or some kind of mesh from the surface traingles so when i do the extrude command, I'm doing it for the whole surface in one go (rather than on individual triangles)?

Any ideas welcome!

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Advice on speeding up union of thousands of solids
« Reply #1 on: July 21, 2020, 06:11:02 PM »
Brep could be a solution, maybe you can save the mesh as faces to form part of a shell, you would need to create the other faces of the shell yourself and make sure that the faces meet correctly before forming the final Brep.
Example, say you want to give the mesh depth down to a fixed level (to look like a 3d terrain graph say), you would need to project each vertex of the extreme outside of your mesh to the level to create an edge then create faces for each 'panel' formed by these new edges, the edge of the mesh the edges projected from and the edge create from the end vertices at the level (hope that makes sense).

Had a quick search and found one of Kean's posts that may give some direction -> https://www.keanw.com/2011/03/generating-a-mesh-for-a-3d-solid-using-autocads-brep-api-from-net.html
I didn't have time to read it though but it sounds like something that might be useful nonetheless.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Advice on speeding up union of thousands of solids
« Reply #2 on: July 22, 2020, 11:13:09 PM »

When I switched to inserting each individual triangle solid into a block, the run time came down to 30-40 seconds, so its clear the union command has a huge time overhead, particularly when a surface can have tens of thousands of triangles.


I've had some time to think on this.

Do you mean "When I switched to inserting each individual triangle solid into the result solid block," ?

I was thinking that the Union method may not be very optimized for more than a few solids at a time, that is, maybe it's iterating over the same original list of solids each union iteration or something non-performant like that.

I'd try creating the initial solid from say the first triangle in the triangle collection, store that as the 'result' solid then loop through the rest of the collection adding (union-ing) each new triangle solid to the 'result'.

I'd try this using both a single transaction to do all the work and also a main transaction that 'uses'/creates a nested transaction for creating each new solid before doing the union. I've found on occasion that single transactions for a lot of work are not always faster....that was a while ago and I can't remember why just now though :P

hth
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien