Problem with vector of TopTools_IndexedMapOfShape

Hello,

I try to memorize the vertices of each face in a shape. And I create a TopTools_IndexedMapOfShape for each face. Now I try to add a TopTools_IndexedMapOfShape to a vector. When I compile my program I get the following error "error C2248: "TopTools_IndexedMapOfShape::TopTools_IndexedMapOfShape": No access to private member, which declaration takes place in the TopTools_IndexedMapOfShape class."

Herre is the code:

TopExp_Explorer explorer;
vector verticesMaps;

for (explorer.Init(shape, TopAbs_FACE); explorer.More(); explorer.Next())
{
TopTools_IndexedMapOfShape verticesMap;
processFace(explorer.Current(), verticesMap); // Fill the verticesMap.
verticesMaps.push_back(verticesMap); // Results in error.
}

Has anybody an idea how to solve this or an alternative approach? Thanks.

Greets
Patrick

P Dolbey's picture

I had a similarish problem where I thought it might be a neat idea to be able to pass Handle() wrapper classes between 2 OpenCascade aware DLLs by a top-level app that wasn't linked to the OCC libs. These would Qt4 QObject derived OCC proxies capable of slots and signal and....

OK I digress. Anyway what I think is happening is that you're calling the copy constructor which is protected to avoid shallow copies of objects. I'm not an STL expert, but what might work is to use pointers instead. I managed to get this working with Handle() - I'll worry about the reference counting another day.

Have you tried something like
TopExp_Explorer explorer;
vector verticesMaps;

for (explorer.Init(shape, TopAbs_FACE); explorer.More(); explorer.Next())
{
TopTools_IndexedMapOfShape verticesMap;
processFace(explorer.Current(), verticesMap); //
verticesMaps.push_back(&verticesMap); // Use "address of" operator.
}

Then dereference the verticesMap whenever you need to get to the data.

Just a thought - and untried.

Pete

P Dolbey's picture

Thinking again, it might need to be

TopExp_Explorer explorer;
vector verticesMaps;

for (explorer.Init(shape, TopAbs_FACE); explorer.More(); explorer.Next())
{
TopTools_IndexedMapOfShape* pVerticesMap = new TopTools_IndexedMapOfShape();
processFace(explorer.Current(), *pVerticesMap); //
verticesMaps.push_back(pVerticesMap);
}

and remember to "free" the instances of pVerticesMap when you're done with the verticesMaps vector. I hope you get the idea.

Pete

P Dolbey's picture

For "free" read "delete". I can't remember me "malloc" from me "new".

Pete

pkoeppe's picture

Thanks Pete this works fine.

Patrick