wolph / numpy-stl

Simple library to make working with STL files (and 3D objects in general) fast and easy.
http://numpy-stl.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
605 stars 103 forks source link

Compare two stl files #149

Closed Kartheek410 closed 3 years ago

Kartheek410 commented 3 years ago

Hello, this library has given us so much information. I have seen the code for combining two stl files, I wanted to compare two stl files for the similarities or differences. Would that be possible with numpy-stl? I thought to convert stl files to image, so we could compare two images but it's not working out.

Is there a way or code by which we could compare two different stl files?

wolph commented 3 years ago

It's quite complicated to compare meshes and there's no one solution that will be useful in all cases. While you can easily use numpy-stl to read the stl files, there are no built-in algorithms for comparing similarities or differences currently.

One thing you could do fairly easily is compute the volume and compare that. But making a smart comparison between two meshes is not trivial to do

Kartheek410 commented 3 years ago

@WoLpH haha, trivial = meaningless (synonym) or insignificant?

Yes, I did the volume comparison for both files. The volume comparison is actually a good one. But for 3D printing that doesn't even give 1% insight, as it supposed to check inside layers of an STL file. I have been trying to compare the STL files for a month now in various possible ways.

So, if you have to make a friendly suggestion to me at the end, on this comparison project?

Thank you for your time mate.

idh-incom commented 3 years ago

You can try comparing convex hull polygon surfaces as a slightly more elaborate try. Trying to compare oriented area filtered on positive inproduct with a plane is another thought. Basically, only count positive contributions in x,y,z direction. And see if they match up to similar total oriented areas.

Combining: If the convex hull has the same key elements, volume matches and the oriented area matches; you'll have to find very specific maybe even handcrafted examples to not have the same object on your hand..

wolph commented 3 years ago

I meant insignificant :) What I mean is that it can vary from a difficult to a nearly impossible problem to solve.

It depends on what you want to do of course. But if you're interested in the complexity of an object than I would recommend cheating and looking at the (amount of) gcode produced by the slicer. Objects that have similar features will have similar gcode so that could be a nice shortcut to the problem :P

Kartheek410 commented 3 years ago

@idh-incom : Thank you for your suggestion. Not that simple for me as I'm a junior developer but I read about the idea what you have said. Hopefully, I could try making it. @WoLpH : Oh, thank you. Could be easier to make this as an alternative. I would look into it as of now.