Hi Jelle
My particular need was to hash TopoDS_Shape objects properly. I'm not
sure if this is a good permanent solution, but this works for me, for
shapes at least:
def shape_hash(self):
return self.HashCode(sys.maxint)
TopoDS.TopoDS_Shape.__hash__ = shape_hash
Now I can use shapes in a Python set and as keys in a Python dict -
which also means that your Topology.Topo class works properly now (if
topo_item in topo_set)!
I can't help thinking there must be a more general way to incorporate
this into the SWIG wrapper for *all* OCC classes, but I don't know
enough about swig yet to know for sure.
Cheers,
Frank
jelle feringa wrote:
In order to use pythonocc objects in sets and as dict keys, they
must hash to the underlying OCC object. In fact, your Topo class
uses a set internally that does not work because of this very
fact, because set checks for set membership via hash, and thus,
two of the same objects that get explored will hash to different
values and thus be passed back twice.
Hi Frank,
This is really interesting, thanks so much for explaining.
Actually, now I recall what I messed up. I looped through a list of
some topology, lets say vertices and checked for their id -> id(vertex).
That did work, however as you point out hash != id.
I think overloading the hash with comparing id()'s could work.
Hope this makes sense.
A lot, thanks for your advice here.
I suppose I could overwrite __hash__ the same way you guys
initially got past the == issue.
What do you think of overloading hash with id?
I'll check tomorrow morning, would be great if this is a stable fix,
it sure could be useful.
Thanks,
-jelle
_______________________________________________
Pythonocc-users mailing list
Pythonocc-users@gna.org
https://mail.gna.org/listinfo/pythonocc-users