#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
-#include <TopOpeBRepTool_BoxSort.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_MapIteratorOfMapOfShape.hxx>
#include <TopTools_MapOfShape.hxx>
//
+#include <BRepBndLib.hxx>
+#include <BOPCol_BoxBndTree.hxx>
+#include <NCollection_UBTreeFiller.hxx>
+//
#include <BOPTools_AlgoTools.hxx>
//=======================================================================
// Calculate the intersections of offset faces
// Distinction of intersection between faces // tangents.
//---------------------------------------------------------------
- TopoDS_Face F2;
- TopTools_ListIteratorOfListOfShape it;
- //---------------------------------------------------------------
- // Construction of bounding boxes
- //---------------------------------------------------------------
- TopOpeBRepTool_BoxSort BOS;
- BRep_Builder B;
- TopoDS_Compound CompOS;
- B.MakeCompound(CompOS);
-
- for (it.Initialize(SetOfFaces); it.More(); it.Next()) {
- const TopoDS_Shape& OS = it.Value();
- B.Add(CompOS,OS);
+ // Prepare tools for sorting the bounding boxes
+ BOPCol_BoxBndTree aBBTree;
+ NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
+ //
+ NCollection_IndexedDataMap<TopoDS_Shape, Bnd_Box, TopTools_ShapeMapHasher> aMFaces;
+ // Construct bounding boxes for faces and add them to the tree
+ TopTools_ListIteratorOfListOfShape aItL(SetOfFaces);
+ for (; aItL.More(); aItL.Next()) {
+ const TopoDS_Face& aF = TopoDS::Face(aItL.Value());
+ //
+ // compute bounding box
+ Bnd_Box aBoxF;
+ BRepBndLib::Add(aF, aBoxF);
+ //
+ Standard_Integer i = aMFaces.Add(aF, aBoxF);
+ //
+ aTreeFiller.Add(i, aBoxF);
}
- BOS.AddBoxesMakeCOB(CompOS,TopAbs_FACE);
-
- //---------------------------
- // Intersection of faces //
- //---------------------------
- for (it.Initialize(SetOfFaces); it.More(); it.Next()) {
- const TopoDS_Face& F1 = TopoDS::Face(it.Value());
- TColStd_ListIteratorOfListOfInteger itLI = BOS.Compare(F1);
- for (; itLI.More(); itLI.Next()) {
- F2 = TopoDS::Face(BOS.TouchedShape(itLI));
- FaceInter(F1,F2,InitOffsetFace);
+ //
+ // shake tree filler
+ aTreeFiller.Fill();
+ //
+ // get faces with interfering bounding boxes
+ aItL.Initialize(SetOfFaces);
+ for (; aItL.More(); aItL.Next()) {
+ const TopoDS_Face& aF1 = TopoDS::Face(aItL.Value());
+ const Bnd_Box& aBoxF1 = aMFaces.FindFromKey(aF1);
+ //
+ BOPCol_BoxBndTreeSelector aSelector;
+ aSelector.SetBox(aBoxF1);
+ aBBTree.Select(aSelector);
+ //
+ const BOPCol_ListOfInteger& aLI = aSelector.Indices();
+ BOPCol_ListIteratorOfListOfInteger aItLI(aLI);
+ for (; aItLI.More(); aItLI.Next()) {
+ Standard_Integer i = aItLI.Value();
+ const TopoDS_Face& aF2 = TopoDS::Face(aMFaces.FindKey(i));
+ //
+ // intersect faces
+ FaceInter(aF1, aF2, InitOffsetFace);
}
}
}
//=======================================================================
-//function : CompletInt
-//purpose :
+//function : FaceInter
+//purpose : Performs intersection of the given faces
//=======================================================================
void BRepOffset_Inter3d::FaceInter(const TopoDS_Face& F1,
#include <TopoDS_Iterator.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Wire.hxx>
-#include <TopOpeBRep_EdgesIntersector.hxx>
-#include <TopOpeBRep_Point2d.hxx>
#include <TopTools_DataMapOfShapeSequenceOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_SequenceOfShape.hxx>
+#include <Geom2dInt_GInter.hxx>
+#include <IntRes2d_IntersectionPoint.hxx>
+
//=======================================================================
//function : BRepOffsetAPI_DraftAngle
//purpose :
CurEdge = Eseq(i);
CurWire = Wseq(i);
CurFace = Fseq(i);
+ //
+ const TopoDS_Face& aFace = TopoDS::Face(CurFace);
+ //
+ // Prepare 2D adaptors for intersection.
+ // The seam edge has two 2D curve, thus we have to create 2 adaptors
+ BRepAdaptor_Curve2d aBAC2D1(TopoDS::Edge(CurEdge), aFace);
+ BRepAdaptor_Curve2d aBAC2D1R(TopoDS::Edge(CurEdge.Reversed()), aFace);
+ // Get surface of the face to get 3D intersection point
+ TopLoc_Location aLoc;
+ const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface(aFace, aLoc);
+ // Get the tolerance of the current edge to compare intersection points
+ Standard_Real aTolCurE = BRep_Tool::Tolerance(TopoDS::Edge(CurEdge));
+ //
wit.Initialize( CurFace );
for (; wit.More(); wit.Next())
{
if (! aWire.IsSame( CurWire ))
{
TColgp_SequenceOfPnt pts;
- TopTools_SequenceOfShape edges;
- TColStd_SequenceOfReal pars;
Standard_Boolean Wadd = Standard_False;
eit.Initialize( aWire );
for (; eit.More(); eit.Next())
{
- TopoDS_Shape anEdge = eit.Value();
- TopOpeBRep_EdgesIntersector EInter;
- EInter.SetFaces( CurFace, CurFace );
- EInter.ForceTolerances( TolInter, TolInter );
- EInter.Perform( CurEdge, anEdge );
- if (EInter.IsEmpty())
- {
- EInter.Perform( CurEdge.Reversed(), anEdge );
- if (EInter.IsEmpty())
+ const TopoDS_Edge& anEdge = TopoDS::Edge(eit.Value());
+ //
+ // Prepare 2D adaptor for intersection
+ BRepAdaptor_Curve2d aBAC2D2(anEdge, aFace);
+ // Perform intersection
+ Geom2dInt_GInter aGInter;
+ aGInter.Perform(aBAC2D1, aBAC2D2, TolInter, TolInter);
+ if (!aGInter.IsDone() || aGInter.IsEmpty()) {
+ // If first intersection is empty try intersection with reversed edge
+ aGInter.Perform(aBAC2D1R, aBAC2D2, TolInter, TolInter);
+ if (!aGInter.IsDone() || aGInter.IsEmpty()) {
continue;
+ }
}
+ //
Wadd = Standard_True;
if (! WFmap.IsBound( aWire ))
WFmap.Bind( aWire, CurFace );
Standard_Integer ind = 0;
- for (j = 1; j <= NonSeam.Length(); j++)
- if (anEdge.IsSame( NonSeam(j) ))
+ for (j = 1; j <= NonSeam.Length(); j++) {
+ if (anEdge.IsSame(NonSeam(j)))
{
ind = j;
break;
}
- if (ind == 0)
- {
- NonSeam.Append( anEdge );
- NonSeamWires.Append( aWire );
- ind = NonSeam.Length();
- TColStd_SequenceOfReal emptyseq1, emptyseq2;
- TopTools_SequenceOfShape emptyedgeseq;
- ParsNonSeam.Append( emptyseq1 );
- Seam.Append( emptyedgeseq );
- ParsSeam.Append( emptyseq2 );
+ }
+ if (ind == 0)
+ {
+ NonSeam.Append(anEdge);
+ NonSeamWires.Append(aWire);
+ ind = NonSeam.Length();
+ TColStd_SequenceOfReal emptyseq1, emptyseq2;
+ TopTools_SequenceOfShape emptyedgeseq;
+ ParsNonSeam.Append(emptyseq1);
+ Seam.Append(emptyedgeseq);
+ ParsSeam.Append(emptyseq2);
+ }
+ if (!Emap.IsBound(CurEdge))
+ {
+ TColStd_SequenceOfReal emptyseq;
+ Emap.Bind(CurEdge, emptyseq);
+ }
+ //
+ // Get the tolerance of edge to compare intersection points
+ Standard_Real aTolE = BRep_Tool::Tolerance(anEdge);
+ // Tolerance to compare the intersection points is the maximal
+ // tolerance of intersecting edges
+ Standard_Real aTolCmp = Max(aTolCurE, aTolE);
+ //
+ Standard_Integer k, aNbIntPnt = aGInter.NbPoints();
+ for (k = 1; k <= aNbIntPnt; ++k) {
+ const IntRes2d_IntersectionPoint& aP2DInt = aGInter.Point(k);
+ const gp_Pnt2d& aP2D = aP2DInt.Value();
+ gp_Pnt aP3D = aSurf->Value(aP2D.X(), aP2D.Y());
+ //
+ // Check if the intersection point is new
+ Standard_Integer ied = 0;
+ for (j = 1; j <= pts.Length(); j++) {
+ if (aP3D.IsEqual(pts(j), aTolCmp))
+ {
+ ied = j;
+ break;
+ }
}
- if (! Emap.IsBound( CurEdge ))
+ if (ied == 0)
{
- TColStd_SequenceOfReal emptyseq;
- Emap.Bind( CurEdge, emptyseq );
+ pts.Append(aP3D);
+ Emap(CurEdge).Append(aP2DInt.ParamOnFirst());
+ ParsNonSeam(ind).Append(aP2DInt.ParamOnSecond());
+ Seam(ind).Append(CurEdge);
+ ParsSeam(ind).Append(aP2DInt.ParamOnFirst());
}
- EInter.InitPoint();
- for (; EInter.MorePoint(); EInter.NextPoint())
- {
- const TopOpeBRep_Point2d& bp = EInter.Point();
- if (bp.IsVertex(2))
- {
- gp_Pnt Pnt = bp.Value();
- Standard_Integer ied = 0;
- for (j = 1; j <= pts.Length(); j++)
- if (Pnt.IsEqual( pts(j), Precision::Confusion() ))
- {
- ied = j;
- break;
- }
- if (ied == 0)
- {
- pts.Append( Pnt );
- edges.Append( anEdge );
- pars.Append( bp.Parameter(2) );
- Emap(CurEdge).Append( bp.Parameter(1) );
- ParsNonSeam(ind).Append( bp.Parameter(2) );
- Seam(ind).Append( CurEdge );
- ParsSeam(ind).Append( bp.Parameter(1) );
- }
- /*
- else
- {
- Standard_Real ParOnSeam = bp.Parameter(1);
- Standard_Real Par1 = pars(ied);
- Standard_Real Par2 = bp.Parameter(2);
- BRepAdaptor_Curve2d SeamCurve( CurEdge, CurFace );
- BRepAdaptor_Curve2d Curve1( edges(ied), CurFace );
- BRepAdaptor_Curve2d Curve2( anEdge. CurFace );
- gp_Pnt2d P2d;
- gp_Vec2d SeamDer, Der1, Der2;
- //SeamCurve->D1( ParOnSeam, P2d, SeamDer );
- //Curve1->D1( Par1, P2d, Der1 );
- //Curve2->D1( Par2, P2d, Der2 );
- Standard_Real Crossed1 = SeamDer ^ Der1;
- Standard_Real Crossed2 = SeamDer ^ Der2;
- //if (Crossed1 > 0
- }
- */
- }
- else // ! bp.IsVertex(2)
- {
- //Temporary the case of tangency is not implemented
- Emap(CurEdge).Append( bp.Parameter(1) );
- ParsNonSeam(ind).Append( bp.Parameter(2) );
- Seam(ind).Append( CurEdge );
- ParsSeam(ind).Append( bp.Parameter(1) );
- }
- } //for (; EInter.MorePoint(); EInter.NextPoint())
+ }
} //for (; eit.More(); eit.Next())
if (Wadd)
{