Forum archiveIssue archiveModeling Data and Algorithms

Archived discussion

BRepAlgoAPI_Section and HasAncestorFaceOn1

Modeling Data and AlgorithmsWed, 07/14/2021 - 12:397 replies

Browse this forum
QuestionAuthor

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, Author.

Discussion

7 archived replies

Posts are displayed in their archived order.

01Commenter-1

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

02Author

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

03Commenter-1

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.

04Author

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

05Author

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?

06Commenter-1

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.

07Author

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, Author.