marian42 / mesh_to_sdf

Calculate signed distance fields for arbitrary meshes
https://pypi.org/project/mesh-to-sdf/
MIT License
1.02k stars 108 forks source link

sample_sdf_near_surface getting slower and slower in loops #11

Closed YuDeng closed 4 years ago

YuDeng commented 4 years ago

Hi, I have used sample_sdf_near_surface function to transfer mesh to sdf for multiple objects. However, I find this function runs slower and slower. It takes around a minute to handle a single object but spends about 5 hours for 60 objects. I simply wrote a for loop to generate sdf for each object as follows: image

Do you know how I can fix this problem?

marian42 commented 4 years ago

Your code looks good. I'm not sure why it gets slower. Can you confirm that it really gets slower each iteration? Maybe some models with more triangles just take longer? Does the computation time depend on which model you're processing or does it depend on how many you processed before?

To save time, you can also run multiple threads. Since my code runs mostly single threaded, parallelizing on a 16 thread PC should speed it up almost 16 times. (The kd-tree query however is already parallel, so this part won't get faster in parallel.). You can look at my code for an example on how to use multiprocessing to process the Shapenet dataset in multiple threads.

YuDeng commented 4 years ago

Thanks for your reply. I record the time for processing each object and it grows from 60s to around 1000s after handling 50 objects. If I terminate the program and resume it from the breakpoint, the process time reduce to 60s for the same object which needs 1000s in the last run. So it seems that the processing time depend on the number of object it has processed. I guess it may be caused by some mechanism in OpenGL? For example the scenes /invisible windows created for previous objects do not disappear and become more and more with the growing iteration. I'm not so familiar with OpenGL and this is only a guess.

YuDeng commented 4 years ago

I solved the problem by using subprocess to deal with each object.

jiennyteng commented 1 year ago

I solved the problem by using subprocess to deal with each object.

can you describe more detailed about the solution, i met similar problem with you .