
Mon, 07/25/2011 - 22:37
Forums:
I have code that looks like:
std::map
shmap[myshape] = "have a nice day";
but I get a compilation error:
/usr/include/c++/4.5/bits/stl_function.h:230:22: error: no match for 'operator
Is there a way to use a TopoDS_Shape as a stl::map key? Alternately, is there a way I can get a unique id (string, int, whatever) from a shape that I can use in this way?
Thanks,
Wayne
Tue, 07/26/2011 - 05:25
try TopoDS_Shape::HashCode
Tue, 07/26/2011 - 17:57
The problem with HashCode is that a hash is not one-to-one - multiple shapes could have the same hash code.
I ended up solving this by creating my own shape -> unique id map using TopTools_IndexedMapOfShape and then using this as a key to the map.
I think a few additions to the shape class would make it possible to use it as a key in maps. The > operation could be based on the address of the underlying TShape (which is invariant, correct?) and the address and orientation fields.
Tue, 07/26/2011 - 18:13
Why you do not use NCollection_DataMap template class?
NCollection_DataMap shmap;
shmap.Bind(myshape, "have a nice day");
For that, define the following global methods:
inline Standard_Boolean IsEqual(const TopoDS_Shape& s1, const TopoDS_Shape& s2)
{
s1 == s2;
}
inline int HashCode(const TopoDS_Shape& s, int u)
{
return s.HashCode(u);
}
Tue, 07/26/2011 - 18:36
Ah, that would have saved me some effort... It's so hard to find stuff in OpenCascade... Thanks...