Back to index

salome-geom  6.5.0
Functions
GEOMAlgo_WireSplitter.cxx File Reference
#include <GEOMAlgo_WireSplitter.hxx>
#include <TColStd_SequenceOfReal.hxx>
#include <Precision.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Vec2d.hxx>
#include <TColgp_SequenceOfPnt2d.hxx>
#include <Geom_Curve.hxx>
#include <Geom2d_Curve.hxx>
#include <GeomAdaptor_Surface.hxx>
#include <TopAbs_Orientation.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Iterator.hxx>
#include <BRep_Tool.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <BRepAdaptor_Curve2d.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_SequenceOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <BOPTColStd_ListOfListOfShape.hxx>
#include <BOPTColStd_ListIteratorOfListOfListOfShape.hxx>
#include <BOPTools_Tools2D.hxx>
#include <BOP_EdgeInfo.hxx>
#include <BOP_ListOfEdgeInfo.hxx>
#include <BOP_ListIteratorOfListOfEdgeInfo.hxx>
#include <BOP_IndexedDataMapOfVertexListEdgeInfo.hxx>

Go to the source code of this file.

Functions

static void Path (const GeomAdaptor_Surface &aGAS, const TopoDS_Face &myFace, const TopoDS_Vertex &aVa, const TopoDS_Edge &aEOuta, BOP_EdgeInfo &anEdgeInfo, TopTools_SequenceOfShape &aLS, TopTools_SequenceOfShape &aVertVa, TColgp_SequenceOfPnt2d &aCoordVa, BOPTColStd_ListOfListOfShape &myShapes, BOP_IndexedDataMapOfVertexListEdgeInfo &mySmartMap)
static Standard_Real Angle (const gp_Dir2d &aDir2D)
static void GetNextVertex (const TopoDS_Vertex &aV, const TopoDS_Edge &aE, TopoDS_Vertex &aV1)
static Standard_Real ClockWiseAngle (const Standard_Real aAngleIn, const Standard_Real aAngleOut)
static Standard_Real AngleIn (const TopoDS_Edge &aEIn, const BOP_ListOfEdgeInfo &aLEInfo)
static Standard_Real Angle2D (const TopoDS_Vertex &aV, const TopoDS_Edge &anEdge, const TopoDS_Face &myFace, const GeomAdaptor_Surface &aGAS, const Standard_Boolean aFlag)
static gp_Pnt2d Coord2d (const TopoDS_Vertex &aV1, const TopoDS_Edge &aE1, const TopoDS_Face &aF)
static gp_Pnt2d Coord2dVf (const TopoDS_Edge &aE, const TopoDS_Face &aF)
static Standard_Real Tolerance2D (const TopoDS_Vertex &aV, const GeomAdaptor_Surface &aGAS)
static Standard_Integer NbWaysOut (const TopoDS_Edge &aEOuta, const BOP_ListOfEdgeInfo &aLEInfo)

Function Documentation

Standard_Real Angle ( const gp_Dir2d &  aDir2D) [static]

Definition at line 839 of file GEOMAlgo_WireSplitter.cxx.

{
  gp_Dir2d      aRefDir(1., 0.);
  Standard_Real anAngle = aRefDir.Angle(aDir2D);

  if (anAngle < 0.)
    anAngle += M_PI + M_PI;

  return anAngle;
}

Here is the caller graph for this function:

Standard_Real Angle2D ( const TopoDS_Vertex &  aV,
const TopoDS_Edge &  anEdge,
const TopoDS_Face &  myFace,
const GeomAdaptor_Surface &  aGAS,
const Standard_Boolean  aFlag 
) [static]

Definition at line 783 of file GEOMAlgo_WireSplitter.cxx.

{
  Standard_Real aFirst, aLast, aToler, dt, aTV, aTV1, anAngle, aTX;
  gp_Pnt2d aPV, aPV1;
  gp_Vec2d aV2D;
  Handle(Geom2d_Curve) aC2D;
  //
  aTV=BRep_Tool::Parameter (aV, anEdge, myFace);
  if (Precision::IsInfinite(aTV)) {
    return 0.;
  }
  //
  BOPTools_Tools2D::CurveOnSurface (anEdge, myFace, aC2D,
                                    aFirst, aLast, aToler, Standard_True);
  //dt=1.e-7;
  dt=2.*Tolerance2D(aV, aGAS);
  //
  aTX=0.25*(aLast - aFirst);
  if(dt > aTX) {
    // to save direction of the curve as much as it possible
    // in the case of big tolerances
    dt = aTX;
  }
  //
  if (fabs (aTV-aFirst) < fabs(aTV - aLast)) {
    aTV1=aTV + dt;
  }
  else {
    aTV1=aTV - dt;
  }
  //
  aC2D->D0 (aTV, aPV);
  aC2D->D0 (aTV1, aPV1);
  //
  if (aFlag) {//IN
    gp_Vec2d aV2DIn(aPV1, aPV);
    aV2D=aV2DIn;
  }
  else {
    gp_Vec2d aV2DOut(aPV, aPV1);
    aV2D=aV2DOut;
  }
  //
  gp_Dir2d aDir2D(aV2D);
  anAngle=Angle(aDir2D);
  //
  return anAngle;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Standard_Real AngleIn ( const TopoDS_Edge &  aEIn,
const BOP_ListOfEdgeInfo &  aLEInfo 
) [static]

Definition at line 697 of file GEOMAlgo_WireSplitter.cxx.

{
  Standard_Real anAngleIn;
  Standard_Boolean anIsIn;
  BOP_ListIteratorOfListOfEdgeInfo anIt;

  anIt.Initialize(aLEInfo);
  for (; anIt.More(); anIt.Next()) {
    BOP_EdgeInfo& anEdgeInfo=anIt.Value();
    const TopoDS_Edge& aE=anEdgeInfo.Edge();
    anIsIn=anEdgeInfo.IsIn();
    //
    if (anIsIn && aE==aEIn) {
      anAngleIn=anEdgeInfo.Angle();
      return anAngleIn;
    }
  }
  anAngleIn=0.;
  return anAngleIn;
}

Here is the caller graph for this function:

Standard_Real ClockWiseAngle ( const Standard_Real  aAngleIn,
const Standard_Real  aAngleOut 
) [static]

Definition at line 722 of file GEOMAlgo_WireSplitter.cxx.

{
  Standard_Real aTwoPi = M_PI+M_PI;
  Standard_Real dA, A1, A2, AIn, AOut ;

  AIn=aAngleIn;
  AOut=aAngleOut;
  if (AIn >= aTwoPi) {
    AIn=AIn-aTwoPi;
  }

  if (AOut >= aTwoPi) {
    AOut=AOut-aTwoPi;
  }

  A1 = AIn + M_PI;

  if (A1 >= aTwoPi) {
    A1=A1-aTwoPi;
  }

  A2=AOut;

  dA=A1-A2;
  if (dA <= 0.) {
    dA=aTwoPi+dA;
    if (dA <= 1.e-14) {
      dA=aTwoPi;
    }
  }
  //xx
  else if (dA <= 1.e-14) {
    dA=aTwoPi;
  }
  return dA;
}

Here is the caller graph for this function:

gp_Pnt2d Coord2d ( const TopoDS_Vertex &  aV1,
const TopoDS_Edge &  aE1,
const TopoDS_Face &  aF 
) [static]

Definition at line 679 of file GEOMAlgo_WireSplitter.cxx.

{
  Standard_Real aT, aFirst, aLast;
  Handle(Geom2d_Curve) aC2D;
  gp_Pnt2d aP2D1;
  //
  aT=BRep_Tool::Parameter (aV1, aE1, aF);
  aC2D=BRep_Tool::CurveOnSurface(aE1, aF, aFirst, aLast);
  aC2D->D0 (aT, aP2D1);
  //
  return aP2D1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

gp_Pnt2d Coord2dVf ( const TopoDS_Edge &  aE,
const TopoDS_Face &  aF 
) [static]

Definition at line 626 of file GEOMAlgo_WireSplitter.cxx.

{
  Standard_Real aCoord=99.;
  gp_Pnt2d aP2D1(aCoord, aCoord);
  TopoDS_Iterator aIt;
  //
  aIt.Initialize(aE);
  for (; aIt.More(); aIt.Next()) {
    const TopoDS_Shape& aVx=aIt.Value();
    if (aVx.Orientation()==TopAbs_FORWARD) {
      const TopoDS_Vertex& aVxx=TopoDS::Vertex(aVx);
      aP2D1=Coord2d(aVxx, aE, aF);
      return aP2D1;
    }
  }
  return aP2D1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void GetNextVertex ( const TopoDS_Vertex &  aV,
const TopoDS_Edge &  aE,
TopoDS_Vertex &  aV1 
) [static]

Definition at line 763 of file GEOMAlgo_WireSplitter.cxx.

{
  TopoDS_Iterator aIt;
  //
  aIt.Initialize(aE);
  for (; aIt.More(); aIt.Next()) {
    const TopoDS_Shape& aVx=aIt.Value();
    if (!aVx.IsEqual(aV)) {
      aV1=TopoDS::Vertex(aVx);
      return ;
    }
  }
  aV1=aV;
}

Here is the caller graph for this function:

Standard_Integer NbWaysOut ( const TopoDS_Edge &  aEOuta,
const BOP_ListOfEdgeInfo &  aLEInfo 
) [static]

Definition at line 854 of file GEOMAlgo_WireSplitter.cxx.

{
  Standard_Boolean bIsOut, bIsNotPassed;
  Standard_Integer iCnt=0;
  BOP_ListIteratorOfListOfEdgeInfo anIt;
  //
  anIt.Initialize(aLEInfo);
  for (; anIt.More(); anIt.Next()) {
    BOP_EdgeInfo& aEI=anIt.Value();
    const TopoDS_Edge& aE=aEI.Edge();
    bIsOut=!aEI.IsIn();
    bIsNotPassed=!aEI.Passed();
    if (bIsOut && bIsNotPassed) {
      if (!aE.IsSame(aEOuta)) {
       iCnt++;
      }
    }
  }
  return iCnt;
}

Here is the caller graph for this function:

void Path ( const GeomAdaptor_Surface &  aGAS,
const TopoDS_Face &  myFace,
const TopoDS_Vertex &  aVa,
const TopoDS_Edge &  aEOuta,
BOP_EdgeInfo &  anEdgeInfo,
TopTools_SequenceOfShape &  aLS,
TopTools_SequenceOfShape &  aVertVa,
TColgp_SequenceOfPnt2d &  aCoordVa,
BOPTColStd_ListOfListOfShape &  myShapes,
BOP_IndexedDataMapOfVertexListEdgeInfo &  mySmartMap 
) [static]

Definition at line 441 of file GEOMAlgo_WireSplitter.cxx.

{
  Standard_Integer i,j, aNb, aNbj, iCnt;
  Standard_Real aTol, anAngleIn, anAngleOut, anAngle, aMinAngle;
  Standard_Real aTol2D, aTol2D2;
  Standard_Real aTol2, aD2;
  Standard_Boolean anIsSameV2d, anIsSameV, anIsFound, anIsOut, anIsNotPassed;
  BOP_ListIteratorOfListOfEdgeInfo anIt;
  TopoDS_Vertex aVb;
  TopoDS_Edge aEOutb;
  //
  aTol=1.e-7;
  //
  // append block
  //
  // Do not escape through edge from which you enter
  aNb=aLS.Length();
  if (aNb==1) {
    const TopoDS_Shape& anEPrev=aLS(aNb);
    if (anEPrev.IsSame(aEOuta)) {
      return;
    }
  }
  //
  //
  anEdgeInfo.SetPassed(Standard_True);
  aLS.Append(aEOuta);
  aVertVa.Append(aVa);

  TopoDS_Vertex pVa=aVa;
  pVa.Orientation(TopAbs_FORWARD);
  gp_Pnt2d aPa=Coord2d(pVa, aEOuta, myFace);
  aCoordVa.Append(aPa);

  GetNextVertex (pVa, aEOuta, aVb);

  gp_Pnt2d aPb=Coord2d(aVb, aEOuta, myFace);
  //
  aTol=2.*Tolerance2D(aVb, aGAS);
  aTol2=10.*aTol*aTol;
  //
  aNb=aLS.Length();
  if (aNb>0) {
    //
    TopTools_ListOfShape aBuf;
    //
    for (i=aNb; i>0; i--) {
      const TopoDS_Shape& aVPrev=aVertVa(i);
      const gp_Pnt2d& aPaPrev=aCoordVa(i);
      const TopoDS_Shape& aEPrev=aLS(i);

      aBuf.Append(aEPrev);

      anIsSameV=aVPrev.IsSame(aVb);
      anIsSameV2d=Standard_False;

      if (anIsSameV) {
        anIsSameV2d = Standard_True;
        //
        aD2=aPaPrev.SquareDistance(aPb);
        anIsSameV2d =aD2<aTol2;
      }//if (anIsSameV) {
      //
      if (anIsSameV && anIsSameV2d) {
        myShapes.Append(aBuf);
        //
        TopTools_SequenceOfShape aLSt, aVertVat;
        TColgp_SequenceOfPnt2d aCoordVat;
        //
        aNbj=i-1;
        if (aNbj<1) {
          //
          aLS.Clear();
          aVertVa.Clear();
          aCoordVa.Clear();
          //
          return;
        }

        aVb=TopoDS::Vertex(aVertVa(i));

        for (j=1; j<=aNbj; j++) {
          aLSt.Append(aLS(j));
          aVertVat.Append(aVertVa(j));
          aCoordVat.Append(aCoordVa(j));
        }
        //
        aLS.Clear();
        aVertVa.Clear();
        aCoordVa.Clear();

        aLS=aLSt;
        aVertVa=aVertVat;
        aCoordVa=aCoordVat;
        //
        break;
      }
    }
  }
  //
  aTol2D=2.*Tolerance2D(aVb, aGAS);
  aTol2D2=100.*aTol2D*aTol2D;
  //
  // anAngleIn in Vb from edge aEOuta
  const BOP_ListOfEdgeInfo& aLEInfo=mySmartMap.FindFromKey(aVb);
  //
  anAngleIn=AngleIn(aEOuta, aLEInfo);
  //
  // aEOutb
  BOP_EdgeInfo *pEdgeInfo=NULL;

  aMinAngle=100.;
  anIsFound=Standard_False;
  //
  //modified by NIZNHY-PKV Thu Apr 19 09:05:09 2012f
  iCnt=NbWaysOut (aEOuta, aLEInfo); 
  //iCnt=NbWaysOut (aLEInfo); 
  //modified by NIZNHY-PKV Thu Apr 19 09:05:12 2012t
  if (!iCnt) { // no way to go . (Error)
    return ;
  }
  //
  anIt.Initialize(aLEInfo);
  for (; anIt.More(); anIt.Next()) {
    BOP_EdgeInfo& anEI=anIt.Value();
    const TopoDS_Edge& aE=anEI.Edge();
    anIsOut=!anEI.IsIn();
    anIsNotPassed=!anEI.Passed();
    //
    if (anIsOut && anIsNotPassed) {
      if (aE.IsSame(aEOuta)) {
       continue;
      }
      //
      if (iCnt==1) {
        // the one and only way to go out .
        pEdgeInfo=&anEI;
        anIsFound=Standard_True;
        break;
      }
      //
      // Look for minimal angle and make the choice.
      gp_Pnt2d aP2Dx;
      //
      aP2Dx=Coord2dVf(aE, myFace);
      //
      aD2=aP2Dx.SquareDistance(aPb);
      if (aD2 > aTol2D2){
        continue;
      }
      //
      anAngleOut=anEI.Angle();
      //
      anAngle=ClockWiseAngle(anAngleIn, anAngleOut);
      if (anAngle < aMinAngle) {
        aMinAngle=anAngle;
        pEdgeInfo=&anEI;
        anIsFound=Standard_True;
      }
    }
  } // for (; anIt.More(); anIt.Next())
  //
  if (!anIsFound) {
    // no way to go . (Error)
    return;
  }
  //
  aEOutb=pEdgeInfo->Edge();
  //
  Path (aGAS, myFace, aVb, aEOutb, *pEdgeInfo, aLS,
        aVertVa, aCoordVa, myShapes, mySmartMap);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Standard_Real Tolerance2D ( const TopoDS_Vertex &  aV,
const GeomAdaptor_Surface &  aGAS 
) [static]

Definition at line 648 of file GEOMAlgo_WireSplitter.cxx.

{
  Standard_Real aTol2D, anUr, aVr, aTolV3D;
  GeomAbs_SurfaceType aType;
  //
  aType=aGAS.GetType();
  aTolV3D=BRep_Tool::Tolerance(aV);

  anUr=aGAS.UResolution(aTolV3D);
  aVr =aGAS.VResolution(aTolV3D);
  aTol2D=(aVr>anUr) ? aVr : anUr;
  //
  if (aType==GeomAbs_BSplineSurface||
      aType==GeomAbs_Sphere||
      GeomAbs_SurfaceOfRevolution) {
    if (aTol2D < aTolV3D) {
      aTol2D=aTolV3D;
    }
  }
  if (aType==GeomAbs_BSplineSurface) {
    aTol2D=1.1*aTol2D;
  }
  //
  return aTol2D;
}

Here is the caller graph for this function: