Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

was HashCode removed from TopAbs_Face? #1345

Open
philosophical1337 opened this issue Jun 27, 2024 · 4 comments
Open

was HashCode removed from TopAbs_Face? #1345

philosophical1337 opened this issue Jun 27, 2024 · 4 comments

Comments

@philosophical1337
Copy link

I am working with step files and when imported using read_step_file_with_names_colors you can always tell they contain many duplicate faces (obvious z-fighting).

I'm not sure if its just not noticeable when importing without colors due to the surfaces all being grey but anyway, I was using the following function to compare all the faces and discard duplicates which was working wonderfully until I updated to 7.8.1.

now I get the error message that HashCode attribute doesn't exist.

identifier = face.HashCode(-1)
                   ^^^^^^^^^^^^^
AttributeError: 'TopoDS_Face' object has no attribute 'HashCode'

here is my function:

    def removeDuplicateFaces(self, shape):
        # Create a compound to hold the result
        compound = TopoDS_Compound()
        builder = BRep_Builder()
        builder.MakeCompound(compound)

        uniqueFaces = {}

        explorer = TopExp_Explorer(shape, TopAbs_FACE)
        while explorer.More():
            face = explorer.Current()

            identifier = face.HashCode(-1)

            if identifier not in uniqueFaces:
                # Add the face to the result compound
                builder.Add(compound, face)
                # Store the identifier
                uniqueFaces[identifier] = face

            explorer.Next()

        return compound
@tpaviot
Copy link
Owner

tpaviot commented Jun 28, 2024

The HashCode method was actually removed from OpenCascade itself. You can use the builtin hash function:
identifier=hash(face)

@tpaviot
Copy link
Owner

tpaviot commented Jun 28, 2024

I should have generated a deprecation warning when using the HashCode method

@philosophical1337
Copy link
Author

this is just a guess but although the faces are geometrically identical, i think the actual face objects have small differences, so just hashing the object with the built in hash doesn't work at all.

I think the HashCode method was hashing only the geometric properties of the face and thus worked to find the identical faces, ignoring the differences in the object

@philosophical1337
Copy link
Author

okay, i didn't realize that my code was effectively always returning only the first face and then discarding the rest, the HashCode(-1) just resulted in a hash of 1 every time.

i just ended up discarding everything but the first face and it works out the same, oops!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants