BRepAlgoAPI_Section and HasAncestorFaceOn1

Hello Guys,
I am confused by some simple issue.
I need to get connecting faces for all edges after BRepAlgoAPI_Section operation.

HasAncestorFaceOn1 returns false for every edge.
And I see it is Obsolete.

What is the way nowadays to get correspond faces?
I use OCCT 7.5.

Thanks in advance.
With respects, Eugene.

Mikhail Sazonov's picture

Use the history of modifications (BRepTools_History), see API of BRepAlgoAPI_BuilderAlgo.hxx. The section edge must hit into 'generated' set of corresponding faces.

Eugene Zaliznyak's picture

Hello Mikhail,
My code returns r1 as empty and r2 the edge itself. There is no any face objects.

Handle(BRepTools_History) hHistory = op.History();
TopTools_ListOfEdge listEdges;
CollectEdges(resShape, listEdges);
for (TopTools_ListIteratorOfListOfEdge iter = listEdges; iter.More(); iter.Next())
{
const auto& r1 = hHistory->Generated(iter.Value());
const auto& r2 = hHistory->Modified(iter.Value());
}

Mikhail Sazonov's picture

You incorrectly understood what to do. You should iterate on all faces of all input shapes and for each face ask history for generated shapes. And here you can build a mapping of edges to faces.

Eugene Zaliznyak's picture

This code also provides empty result

TopTools_ListOfFace listFaces2;
CollectFaces(s2, listFaces2);
Handle(BRepTools_History) hHistory = op.History();
for (TopTools_ListIteratorOfListOfFace iter = listFaces2; iter.More(); iter.Next())
{
const auto& listGenerated = hHistory->Generated(iter.Value());
const auto& listModified = hHistory->Modified(iter.Value());
if (listGenerated.IsEmpty() && listModified.IsEmpty())
{
// always here
continue;
}
}

Eugene Zaliznyak's picture

As I see I have non-empty listModified in case check history for edges of original shells.
Could it be so? For example, in case all section edges were constructed by only edges of source shells?

Mikhail Sazonov's picture

The following code works:

#pragma comment(lib,"TKernel")
#pragma comment(lib,"TKBO")
#pragma comment(lib,"TKBRep")
#pragma comment(lib,"TKBRep")
#pragma comment(lib,"TKTopAlgo")
#pragma comment(lib,"TKPrim")

#include <iostream>
#include <OSD_Timer.hxx>
#include <Precision.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepAlgoAPI_Section.hxx>
#include <TopExp_Explorer.hxx>

inline bool IsInfinite(double a)
{
  return Precision::IsInfinite(a);
  //return Precision::IsPositiveInfinite(a) || Precision::IsNegativeInfinite(a);
}

int main(int narg, char** argv)
{
  TopoDS_Shape aBox1 = BRepPrimAPI_MakeBox (gp_Pnt (0,0,0), 10, 10, 10);
  TopoDS_Shape aBox2 = BRepPrimAPI_MakeBox (gp_Pnt (2,2,2), 10, 10, 10);
  BRepAlgoAPI_Section aSec (aBox1, aBox2);
  Handle(BRepTools_History) hHistory = aSec.History();
  int i = 1;
  for (TopExp_Explorer ex (aBox1, TopAbs_FACE); ex.More(); ex.Next(), i++)
  {
    const auto& lst = hHistory->Generated(ex.Value());
    if (!lst.IsEmpty())
    {
      std::cout << "face " << i << " from box1 generated " << lst.Extent() << " shapes" << std::endl;
    }
  }
  i = 1;
  for (TopExp_Explorer ex (aBox2, TopAbs_FACE); ex.More(); ex.Next(), i++)
  {
    const auto& lst = hHistory->Generated(ex.Value());
    if (!lst.IsEmpty())
    {
      std::cout << "face " << i << " from box2 generated " << lst.Extent() << " shapes" << std::endl;
    }
  }
  return 0;
}

Its output:

face 2 from box1 generated 3 shapes
face 4 from box1 generated 3 shapes
face 6 from box1 generated 3 shapes
face 1 from box2 generated 3 shapes
face 3 from box2 generated 3 shapes
face 5 from box2 generated 3 shapes

If a section edge was produced as a part of model edge then you should evaluate the history of that edge.

Eugene Zaliznyak's picture

Yes, this example works.
But in case touching boxes:
TopoDS_Shape aBox1 = BRepPrimAPI_MakeBox(gp_Pnt(0, 0, 0), 10, 10, 10);
TopoDS_Shape aBox2 = BRepPrimAPI_MakeBox(gp_Pnt(2, 2, 10), 5, 5, 5);

There is no any faces which helped to generate any edge.
There is only edges in set of Modified().

I expected some faces also in case of touching boxes.

Thank you, Mikhail for your time! It was really useful for me.

With respects, Eugene.