Loading files
b8f597c67This file is pinned to the selected release. Download the original to open it in your design tool.
// Created on: 1994-10-07
// Created by: Jean Yves LEBEY
// Copyright (c) 1994-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <BRep_Tool.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pnt2d.hxx>
#include <Standard_Failure.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopOpeBRep_EdgesIntersector.hxx>
#include <TopOpeBRep_Point2d.hxx>
#include <TopOpeBRepDS_Transition.hxx>
#include <TopOpeBRepTool_ShapeTool.hxx>
//=================================================================================================
const IntRes2d_IntersectionSegment& TopOpeBRep_EdgesIntersector::Segment1() const
{
if (!IsPointOfSegment1())
{
throw Standard_Failure("TopOpeBRep_EdgesIntersector : Not a segment point");
}
int iseg = 1 + (myPointIndex - myNbPoints - 1) / 2;
return mylseg.Value(iseg);
}
//=================================================================================================
bool TopOpeBRep_EdgesIntersector::IsOpposite1() const
{
bool b = Segment1().IsOpposite();
return b;
}
//=================================================================================================
void TopOpeBRep_EdgesIntersector::InitPoint1()
{
myPointIndex = 1;
myIsVertexPointIndex = 0;
myIsVertexIndex = 0;
myIsVertexValue = false;
}
//=================================================================================================
bool TopOpeBRep_EdgesIntersector::MorePoint1() const
{
return myPointIndex <= myTrueNbPoints;
}
//=================================================================================================
void TopOpeBRep_EdgesIntersector::NextPoint1()
{
myPointIndex++;
}
//=================================================================================================
const IntRes2d_IntersectionPoint& TopOpeBRep_EdgesIntersector::Point1() const
{
if (!IsPointOfSegment1())
{ // point is an intersection point
return mylpnt.Value(myPointIndex);
}
else
{ // point is a point of segment
int i = myPointIndex - myNbPoints - 1;
if (i % 2 == 0)
{
return Segment1().FirstPoint();
}
else
{
return Segment1().LastPoint();
}
}
}
//=================================================================================================
TopOpeBRep_P2Dstatus TopOpeBRep_EdgesIntersector::Status1() const
{
if (!IsPointOfSegment1())
{ // point is an intersection point
return TopOpeBRep_P2DINT;
}
else
{ // point is a point of segment
int i = myPointIndex - myNbPoints - 1;
if (i % 2 == 0)
{
return TopOpeBRep_P2DSGF;
}
else
{
return TopOpeBRep_P2DSGL;
}
}
}
//=================================================================================================
bool TopOpeBRep_EdgesIntersector::IsPointOfSegment1() const
{
bool b = (myPointIndex > myNbPoints);
return b;
}
//=================================================================================================
int TopOpeBRep_EdgesIntersector::Index1() const
{
return myPointIndex;
}
//=================================================================================================
TopOpeBRepDS_Config TopOpeBRep_EdgesIntersector::EdgesConfig1() const
{
TopOpeBRepDS_Config c = TopOpeBRepDS_UNSHGEOMETRY;
bool ps = IsPointOfSegment1();
if (ps)
{
bool so;
so = TopOpeBRepTool_ShapeTool::EdgesSameOriented(myEdge2, myEdge1);
c = (so) ? TopOpeBRepDS_SAMEORIENTED : TopOpeBRepDS_DIFFORIENTED;
}
return c;
}
//=================================================================================================
TopOpeBRepDS_Transition TopOpeBRep_EdgesIntersector::Transition1(
const int Index,
const TopAbs_Orientation EdgeOrientation) const
{
bool pointofsegment = IsPointOfSegment1();
bool pur1d = (pointofsegment && mySameDomain);
TopAbs_State staB = TopAbs_UNKNOWN, staA = TopAbs_UNKNOWN;
TopAbs_ShapeEnum shaB = TopAbs_COMPOUND, shaA = TopAbs_COMPOUND;
bool pextremity;
TopAbs_State staINON = TopAbs_IN;
int dim = myDimension;
if (dim == 1)
{
shaA = shaB = TopAbs_EDGE;
}
else if (dim == 2 && pur1d)
{
shaA = shaB = TopAbs_EDGE;
}
else if (dim == 2 && !pur1d)
{
shaA = shaB = TopAbs_FACE;
}
if ((EdgeOrientation == TopAbs_INTERNAL) || (EdgeOrientation == TopAbs_EXTERNAL))
{
TopOpeBRepDS_Transition TR(staINON, staINON, shaB, shaA);
TR.Set(EdgeOrientation);
return TR;
}
pextremity = false; // JYL290998 corr regr cto100K1 fex6 fex4 : 5eme inters E/E
const IntRes2d_IntersectionPoint& IP = Point1();
const IntRes2d_Transition& T = (Index == 1) ? IP.TransitionOfFirst() : IP.TransitionOfSecond();
switch (T.TransitionType())
{
case IntRes2d_In:
staB = TopAbs_OUT;
staA = staINON;
break;
case IntRes2d_Out:
staB = staINON;
staA = TopAbs_OUT;
break;
case IntRes2d_Touch:
switch (T.Situation())
{
case IntRes2d_Inside:
staB = staINON;
staA = staINON;
break;
case IntRes2d_Outside:
staB = TopAbs_OUT;
staA = TopAbs_OUT;
break;
case IntRes2d_Unknown: {
// get posindex = position on of point on edge <Index>
IntRes2d_Position posindex = (Index == 1) ? IP.TransitionOfFirst().PositionOnCurve()
: IP.TransitionOfSecond().PositionOnCurve();
if (pointofsegment)
{
// get posother = position of point on the other edge
IntRes2d_Position posother = (Index == 1) ? IP.TransitionOfSecond().PositionOnCurve()
: IP.TransitionOfFirst().PositionOnCurve();
if (posother == IntRes2d_Middle)
{
if (posindex != IntRes2d_Middle)
{
staB = staINON;
staA = staINON;
}
else
{ // Middle/Middle is impossible
throw Standard_Failure("TopOpeBRep_EdgesIntersector : Situation Unknown MM");
}
}
else
{ // posother = Head or End
bool opposite = IsOpposite1();
if (opposite)
{
if (posother == IntRes2d_Head)
{
staB = staINON;
staA = TopAbs_OUT;
}
else if (posother == IntRes2d_End)
{
staB = TopAbs_OUT;
staA = staINON;
}
}
else
{
if (posother == IntRes2d_Head)
{
staB = TopAbs_OUT;
staA = staINON;
}
else if (posother == IntRes2d_End)
{
staB = staINON;
staA = TopAbs_OUT;
}
}
}
} // point is a segment point
else
{ // point is not a segment point
// two edges intersect on a vertex
// the vertex is shared by the two edges
// the edges are tangent on vertex.
pextremity = true;
shaA = shaB = TopAbs_EDGE;
if (posindex == IntRes2d_Head)
{
staB = staINON;
staA = TopAbs_OUT;
}
else if (posindex == IntRes2d_End)
{
staB = TopAbs_OUT;
staA = staINON;
}
else
{ // Middle is impossible
throw Standard_Failure("TopOpeBRep_EdgesIntersector : Situation Unknown M");
}
} // point is not a segment point
} // T.Situation == IntRes2d_Unknown
break;
} // switch T.Situation()
break;
case IntRes2d_Undecided:
throw Standard_Failure("TopOpeBRep_EdgesIntersector : TransitionType Undecided");
break;
} // switch TransitionType()
TopOpeBRepDS_Transition TR;
if (pur1d || pextremity)
{
TR.Set(staB, staA, shaB, shaA);
}
else
{ // +ooOO
bool composori = false;
composori = composori || ((Index == 1) && (!myf2surf1F_sameoriented));
composori = composori || ((Index == 2) && (!myf1surf1F_sameoriented));
// Index = 1 <==> on demande la transition sur
// une arete de la 1ere face par rapport a une arete orientee de
// la 2eme face.
// EdgeOrientation est l'orientation d'une arete de la 2eme face
// de l'appel SetFaces(), i.e ume arete de la face dont la surface
// n'est PAS la surface de reference de l'intersecteur 2d.
// Cette orientation d'arete dans la face doit etre composee avec
// l'orientation relative de la topologie de la 2eme face par rapport
// a la topologie de la 1ere face orientee FORWARD (car la
// geometrie naturelle de la 1ere face est la reference).
TopAbs_Orientation eori = EdgeOrientation;
if (composori)
{
eori = TopAbs::Reverse(eori);
}
// retournement des etats en fonction de l'orientation de l'arete
// croisee dans l'espace geometrique de reference.
TR.Set(staB, staA, shaB, shaA);
if (eori == TopAbs_REVERSED)
{
TR = TR.Complement();
}
}
return TR;
}
//=================================================================================================
double TopOpeBRep_EdgesIntersector::Parameter1(const int Index) const
{
if (Index == 1)
{
return Point1().ParamOnFirst();
}
else
{
return Point1().ParamOnSecond();
}
}
//=================================================================================================
bool TopOpeBRep_EdgesIntersector::IsVertex1(const int Index)
{
// check if last IsVertex1() call has been performed
// on current point and with same <Index>.
if (myIsVertexPointIndex == myPointIndex && myIsVertexIndex == Index)
{
return myIsVertexValue;
}
// search if current point is a vertex of edge <Index>
myIsVertexValue = false;
IntRes2d_Position pos;
if (Index == 1)
{
pos = Point1().TransitionOfFirst().PositionOnCurve();
}
else
{
pos = Point1().TransitionOfSecond().PositionOnCurve();
}
if (pos == IntRes2d_Middle)
{
// search for an INTERNAL vertex on edge <Index> with
// a 2d parameter <parV> equal to current point parameter <par>
double par = Parameter1(Index);
const TopoDS_Edge* pE = nullptr;
pE = (Index == 1) ? &myEdge1 : &myEdge2;
const TopoDS_Edge& E = *pE;
TopExp_Explorer ex;
for (ex.Init(E, TopAbs_VERTEX); ex.More(); ex.Next())
{
// for (TopExp_Explorer ex(E,TopAbs_VERTEX); ex.More(); ex.Next()) {
const TopoDS_Vertex& V = TopoDS::Vertex(ex.Current());
if (V.Orientation() == TopAbs_INTERNAL)
{
double parV = BRep_Tool::Parameter(V, E, myFace1);
if (std::abs(par - parV) <= Precision::PConfusion())
{
myIsVertexValue = true;
myIsVertexVertex = V;
break;
}
}
}
}
else
{ // pos = head or end
TopoDS_Vertex V1, V2;
if (Index == 1)
{
TopExp::Vertices(myEdge1, V1, V2);
}
else
{
TopExp::Vertices(myEdge2, V1, V2);
}
if (pos == IntRes2d_Head && !V1.IsNull())
{
myIsVertexValue = true;
myIsVertexVertex = V1;
}
else if (pos == IntRes2d_End && !V2.IsNull())
{
myIsVertexValue = true;
myIsVertexVertex = V2;
}
// ... else myIsVertexValue has been set to False
}
// memorize that IsVertex1() has been called :
// - on point myPointIndex
// - on edge <Index>
myIsVertexPointIndex = myPointIndex;
myIsVertexIndex = Index;
return myIsVertexValue;
}
//=================================================================================================
const TopoDS_Shape& TopOpeBRep_EdgesIntersector::Vertex1(const int Index)
{
if (!IsVertex1(Index))
{
throw Standard_Failure("TopOpeBRep_EdgesIntersector : Vertex1");
}
return myIsVertexVertex;
}
//=================================================================================================
gp_Pnt TopOpeBRep_EdgesIntersector::Value1() const
{
gp_Pnt2d p2 = Point1().Value();
if (Precision::IsInfinite(p2.X()) || Precision::IsInfinite(p2.Y()))
{
return gp_Pnt(Precision::Infinite(), Precision::Infinite(), Precision::Infinite());
}
else
{
return mySurface1->EvalD0(p2.X(), p2.Y());
}
}