Wed, 03/30/2005 - 12:42
Dear All,
I have an IGES file(created by someone else) which contains a solid
box.
I tried to find the number of EDGES present in this drawing using the
following code.
/***********************************************************
IGESControl_Reader reader;
IFSelect_ReturnStatus status = reader.ReadFile(filename);
if(status != IFSelect_RetDone)
AfxMessageBox("Failed to load IGES file");
reader.TransferRoots();
TopoDS_Shape aShape = reader.OneShape();
int nCount = 0;
for
(TopExp_Explorer expEdge(aShape, TopAbs_EDGE);
expEdge.More();
expEdge.Next()
)
{
nCount++;
}
CString str;
str.Format("%d", nCount);
AfxMessageBox(str);
/***********************************************************
Although the expected result is 12, I am getting 28.
What will be wrong with me?
TIA,
Regards,
Jahfer
Wed, 03/30/2005 - 16:00
28 does surprise me. I would have expected 24. For starters, remember there are 6 faces in your box. Each face has four edges. Although many of these edges are shared, adjoining faces are connected by separate edges with opposite orientations. I would suggest that your first step is to place the edges in a TopTools_MapOfShape. This uses TopoDS_Shape::IsSame to decide if an item is already in the map and, therefore, removes orientation. So,
change your loop to read:
TopTools_MapOfShape myMap;
for (TopExp_Explorer expEdge(aShape, TopAbs_EDGE); expEdge.More(); expEdge.Next())
{
myMap.Add(expEdge.Current());
}
Then, you can reference myMap.Extent() to get your count.
I would expect this to cut the number of edges in half. That still
leaves 2 unaccounted for edges that I can't explain. You may have to
dump those edges and view their values to better understand what is
happening.