1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: GEOMAlgo_SurfaceTools.cxx
24 // Created: Thu Jan 27 11:05:16 2005
25 // Author: Peter KURNEV
28 #include <GEOMAlgo_SurfaceTools.hxx>
33 #include <gp_Cylinder.hxx>
34 #include <gp_Sphere.hxx>
42 #include <GeomAbs_SurfaceType.hxx>
43 #include <GeomAdaptor_Surface.hxx>
44 #include <IntSurf_Quadric.hxx>
47 //=======================================================================
50 //=======================================================================
51 Standard_Integer GEOMAlgo_SurfaceTools::GetState(const gp_Pnt& aP,
52 const GeomAdaptor_Surface& aGAS,
53 const Standard_Real aTol,
56 Standard_Integer iErr = 0;
57 GeomAbs_SurfaceType aType = aGAS.GetType();
58 IntSurf_Quadric aQuad;
60 aState = TopAbs_UNKNOWN;
64 aQuad.SetValue(aGAS.Plane());
67 case GeomAbs_Cylinder:
68 aQuad.SetValue(aGAS.Cylinder());
72 aQuad.SetValue(aGAS.Sphere());
76 iErr=1; // unprocessed surface type
81 const Standard_Real aDp = aQuad.Distance(aP);
87 } else if (aDp < -aTol) {
94 //=======================================================================
97 //=======================================================================
98 Standard_Integer GEOMAlgo_SurfaceTools::GetState(const gp_Pnt& aP,
99 const Handle(Geom_Surface)& aSurf,
100 const Standard_Real aTol,
101 TopAbs_State& aState)
103 Standard_Integer iErr;
104 GeomAdaptor_Surface aGAS;
106 aState=TopAbs_UNKNOWN;
109 iErr=GEOMAlgo_SurfaceTools::GetState(aP, aGAS, aTol, aState);
113 //=======================================================================
114 //function : ReverseState
116 //=======================================================================
117 TopAbs_State GEOMAlgo_SurfaceTools::ReverseState(const TopAbs_State aState)
119 TopAbs_State aRSt=aState;
134 //=======================================================================
135 //function : IsCoaxial
137 //=======================================================================
138 Standard_Boolean GEOMAlgo_SurfaceTools::IsCoaxial(const gp_Pnt& aP1,
140 const gp_Cylinder& aCyl,
141 const Standard_Real aTol)
143 const gp_XYZ &aLoc = aCyl.Location().XYZ();
144 const gp_Ax1 &aAxis = aCyl.Axis();
145 const gp_XYZ &aDAxis = aAxis.Direction().XYZ();
146 gp_XYZ aDP1 = aP1.XYZ().Subtracted(aLoc);
147 gp_XYZ aDP2 = aP2.XYZ().Subtracted(aLoc);
148 Standard_Real aDot1 = aDP1.Dot(aDAxis);
149 Standard_Real aDot2 = aDP1.Dot(aDAxis);
150 Standard_Real aTol2 = aTol*aTol;
152 // Project P1 and P2 onto a plane with location aLoc and Norm aDAxis.
153 aDP1.Subtract(aDAxis.Multiplied(aDot1));
154 aDP2.Subtract(aDAxis.Multiplied(aDot2));
156 Standard_Real aRadius1 = aDP1.Modulus();
157 Standard_Real aRadius2 = aDP2.Modulus();
158 Standard_Boolean isOn = Standard_False;
160 if (fabs(aRadius1 - aRadius2) <= aTol) {
161 // Check the deflection of the middle point.
162 gp_XYZ aMidP = 0.5*(aDP1 + aDP2);
163 Standard_Real aMidRadius1 = aMidP.Modulus();
165 if (fabs(aRadius1 - aRadius2) <= aTol) {
166 isOn = Standard_True;
172 //=======================================================================
173 //function : IsAnalytic
175 //=======================================================================
176 Standard_Boolean GEOMAlgo_SurfaceTools::IsAnalytic(const Handle(Geom_Surface)& aSurf)
178 Standard_Boolean bRet;
179 GeomAbs_SurfaceType aType;
180 GeomAdaptor_Surface aGAS;
183 aType=aGAS.GetType();
184 bRet=(aType==GeomAbs_Plane ||
185 aType==GeomAbs_Cylinder ||
186 aType==GeomAbs_Sphere);
189 //=======================================================================
190 //function : IsConformState
192 //=======================================================================
193 Standard_Boolean GEOMAlgo_SurfaceTools::IsConformState(const TopAbs_State aST1,
194 const GEOMAlgo_State aST2)
196 Standard_Boolean bRet=Standard_False;
200 if (aST1==TopAbs_IN) {
204 case GEOMAlgo_ST_OUT:
205 if (aST1==TopAbs_OUT) {
210 if (aST1==TopAbs_ON) {
214 case GEOMAlgo_ST_ONIN:
215 if (aST1==TopAbs_ON || aST1==TopAbs_IN) {
219 case GEOMAlgo_ST_ONOUT:
220 if (aST1==TopAbs_ON || aST1==TopAbs_OUT) {