X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMAlgo%2FGEOMAlgo_SurfaceTools.cxx;h=213975d92d21d7afff62564257cc13272ed40bd7;hb=8422ddce7f07cce7117b80c6c8e26fb0bd8cbe78;hp=fd2171e632ea8a40a81dceb84c02a0a4bf985d01;hpb=9499b99fe2dcb53e1ea364f97986f8f432b04600;p=modules%2Fgeom.git diff --git a/src/GEOMAlgo/GEOMAlgo_SurfaceTools.cxx b/src/GEOMAlgo/GEOMAlgo_SurfaceTools.cxx index fd2171e63..213975d92 100644 --- a/src/GEOMAlgo/GEOMAlgo_SurfaceTools.cxx +++ b/src/GEOMAlgo/GEOMAlgo_SurfaceTools.cxx @@ -1,29 +1,31 @@ -// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// File: GEOMAlgo_SurfaceTools.cxx -// Created: Thu Jan 27 11:05:16 2005 -// Author: Peter KURNEV -// - -#include +// File: GEOMAlgo_SurfaceTools.cxx +// Created: Thu Jan 27 11:05:16 2005 +// Author: Peter KURNEV +// +// +#include #include @@ -39,59 +41,52 @@ #include #include +#include //======================================================================= //function : GetState -//purpose : +//purpose : //======================================================================= - Standard_Integer GEOMAlgo_SurfaceTools::GetState(const gp_Pnt& aP, - const GeomAdaptor_Surface& aGAS, - const Standard_Real aTol, - TopAbs_State& aState) + Standard_Integer GEOMAlgo_SurfaceTools::GetState + (const gp_Pnt& aP, + const GeomAdaptor_Surface& aGAS, + const Standard_Real aTol, + TopAbs_State& aState) { - Standard_Integer iErr; - Standard_Real aDp, aR; - GeomAbs_SurfaceType aType; - gp_Sphere aSph; - gp_Cylinder aCyl; - gp_Pln aPln; + Standard_Integer iErr = 0; + GeomAbs_SurfaceType aType = aGAS.GetType(); + IntSurf_Quadric aQuad; // - iErr=0; - aState=TopAbs_UNKNOWN; + aState = TopAbs_UNKNOWN; // - aType=aGAS.GetType(); switch (aType) { case GeomAbs_Plane: - aPln=aGAS.Plane(); - aR=0.; - aDp=GEOMAlgo_SurfaceTools::Distance(aP, aPln); + aQuad.SetValue(aGAS.Plane()); + break; + + case GeomAbs_Cylinder: + aQuad.SetValue(aGAS.Cylinder()); break; - - case GeomAbs_Cylinder: - aCyl=aGAS.Cylinder(); - aR=aCyl.Radius(); - aDp=GEOMAlgo_SurfaceTools::Distance(aP, aCyl); - break; - case GeomAbs_Sphere: - aSph=aGAS.Sphere(); - aR=aSph.Radius(); - aDp=GEOMAlgo_SurfaceTools::Distance(aP, aSph); + case GeomAbs_Sphere: + aQuad.SetValue(aGAS.Sphere()); break; - + default: iErr=1; // unprocessed surface type break; } // if (!iErr) { - aState=TopAbs_ON; - if (aDp>aR+aTol) { - aState=TopAbs_OUT; - } - else if (aDp aTol) { + aState = TopAbs_OUT; + } else if (aDp < -aTol) { + aState = TopAbs_IN; } } // @@ -99,12 +94,13 @@ } //======================================================================= //function : GetState -//purpose : +//purpose : //======================================================================= - Standard_Integer GEOMAlgo_SurfaceTools::GetState(const gp_Pnt& aP, - const Handle(Geom_Surface)& aSurf, - const Standard_Real aTol, - TopAbs_State& aState) + Standard_Integer GEOMAlgo_SurfaceTools::GetState + (const gp_Pnt& aP, + const Handle(Geom_Surface)& aSurf, + const Standard_Real aTol, + TopAbs_State& aState) { Standard_Integer iErr; GeomAdaptor_Surface aGAS; @@ -118,9 +114,10 @@ } //======================================================================= //function : ReverseState -//purpose : +//purpose : //======================================================================= - TopAbs_State GEOMAlgo_SurfaceTools::ReverseState(const TopAbs_State aState) + TopAbs_State GEOMAlgo_SurfaceTools::ReverseState + (const TopAbs_State aState) { TopAbs_State aRSt=aState; // @@ -138,82 +135,50 @@ return aRSt; } //======================================================================= -//function : Distance -//purpose : -//======================================================================= -Standard_Real GEOMAlgo_SurfaceTools::Distance(const gp_Pnt& aP, - const gp_Sphere& aSph) -{ - Standard_Real aD; - // - const gp_Pnt& aLoc=aSph.Location(); - aD=aLoc.Distance(aP); - // - return aD; -} -//======================================================================= -//function : Distance -//purpose : -//======================================================================= -Standard_Real GEOMAlgo_SurfaceTools::Distance(const gp_Pnt& aP, - const gp_Cylinder& aCyl) -{ - Standard_Real aD; - // - const gp_Ax1& aAxis=aCyl.Axis(); - gp_Lin aLin(aAxis); - aD=aLin.Distance(aP); - // - return aD; -} -//======================================================================= -//function : Distance -//purpose : -//======================================================================= -Standard_Real GEOMAlgo_SurfaceTools::Distance(const gp_Pnt& aP, - const gp_Pln& aPL) -{ - Standard_Real aD; - // - const gp_Ax3& aPos=aPL.Position(); - const gp_Pnt& aLoc=aPos.Location (); - const gp_Dir& aDir=aPos.Direction(); - // - aD= (aDir.X() * (aP.X() - aLoc.X()) + - aDir.Y() * (aP.Y() - aLoc.Y()) + - aDir.Z() * (aP.Z() - aLoc.Z())); - return aD; -} -//======================================================================= //function : IsCoaxial -//purpose : +//purpose : //======================================================================= -Standard_Boolean GEOMAlgo_SurfaceTools::IsCoaxial(const gp_Pnt& aP1, - const gp_Pnt& aP2, - const gp_Cylinder& aCyl, - const Standard_Real aTol) +Standard_Boolean GEOMAlgo_SurfaceTools::IsCoaxial + (const gp_Pnt& aP1, + const gp_Pnt& aP2, + const gp_Cylinder& aCyl, + const Standard_Real aTol) { - Standard_Boolean bRet=Standard_False; - Standard_Real aSM; - // - gp_Vec aV12(aP1, aP2); - gp_Dir aD12(aV12); - // - const gp_Ax1& aAxis=aCyl.Axis(); - const gp_Dir& aDAxis=aAxis.Direction(); - // - aSM=fabs(aD12*aDAxis); - if (fabs(1.-aSM) > aTol) { - return bRet; + const gp_XYZ &aLoc = aCyl.Location().XYZ(); + const gp_Ax1 &aAxis = aCyl.Axis(); + const gp_XYZ &aDAxis = aAxis.Direction().XYZ(); + gp_XYZ aDP1 = aP1.XYZ().Subtracted(aLoc); + gp_XYZ aDP2 = aP2.XYZ().Subtracted(aLoc); + Standard_Real aDot1 = aDP1.Dot(aDAxis); + Standard_Real aDot2 = aDP1.Dot(aDAxis); + //Standard_Real aTol2 = aTol*aTol; + + // Project P1 and P2 onto a plane with location aLoc and Norm aDAxis. + aDP1.Subtract(aDAxis.Multiplied(aDot1)); + aDP2.Subtract(aDAxis.Multiplied(aDot2)); + + Standard_Real aRadius1 = aDP1.Modulus(); + Standard_Real aRadius2 = aDP2.Modulus(); + Standard_Boolean isOn = Standard_False; + + if (fabs(aRadius1 - aRadius2) <= aTol) { + // Check the deflection of the middle point. + //gp_XYZ aMidP = 0.5*(aDP1 + aDP2); + //Standard_Real aMidRadius1 = aMidP.Modulus(); + + if (fabs(aRadius1 - aRadius2) <= aTol) { + isOn = Standard_True; + } } - // - return !bRet; + + return isOn; } //======================================================================= //function : IsAnalytic -//purpose : +//purpose : //======================================================================= -Standard_Boolean GEOMAlgo_SurfaceTools::IsAnalytic(const Handle(Geom_Surface)& aSurf) +Standard_Boolean GEOMAlgo_SurfaceTools::IsAnalytic + (const Handle(Geom_Surface)& aSurf) { Standard_Boolean bRet; GeomAbs_SurfaceType aType; @@ -221,44 +186,45 @@ Standard_Boolean GEOMAlgo_SurfaceTools::IsAnalytic(const Handle(Geom_Surface)& a // aGAS.Load(aSurf); aType=aGAS.GetType(); - bRet=(aType==GeomAbs_Plane || - aType==GeomAbs_Cylinder || - aType==GeomAbs_Sphere); + bRet=(aType==GeomAbs_Plane || + aType==GeomAbs_Cylinder || + aType==GeomAbs_Sphere); return bRet; } //======================================================================= //function : IsConformState -//purpose : +//purpose : //======================================================================= -Standard_Boolean GEOMAlgo_SurfaceTools::IsConformState(const TopAbs_State aST1, - const GEOMAlgo_State aST2) +Standard_Boolean GEOMAlgo_SurfaceTools::IsConformState + (const TopAbs_State aST1, + const GEOMAlgo_State aST2) { Standard_Boolean bRet=Standard_False; // switch (aST2) { case GEOMAlgo_ST_IN: if (aST1==TopAbs_IN) { - bRet=!bRet; + bRet=!bRet; } break; case GEOMAlgo_ST_OUT: if (aST1==TopAbs_OUT) { - bRet=!bRet; + bRet=!bRet; } break; case GEOMAlgo_ST_ON: if (aST1==TopAbs_ON) { - bRet=!bRet; + bRet=!bRet; } break; case GEOMAlgo_ST_ONIN: if (aST1==TopAbs_ON || aST1==TopAbs_IN) { - bRet=!bRet; + bRet=!bRet; } break; case GEOMAlgo_ST_ONOUT: if (aST1==TopAbs_ON || aST1==TopAbs_OUT) { - bRet=!bRet; + bRet=!bRet; } break; default: