DiscussionsIssue archiveOther usage issues

Archived discussion

TopoDS_Shape as a map key?

Other usage issuesMon, 07/25/2011 - 22:374 replies

Browse this forum
QuestionAuthor

I have code that looks like:

std::map shmap;
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

Discussion

4 archived replies

Posts are displayed in their archived order.

01Commenter-1

try TopoDS_Shape::HashCode

02Author

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.

03Commenter-2

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);
}

04Author

Ah, that would have saved me some effort... It's so hard to find stuff in OpenCascade... Thanks...