1 // Copyright (C) 2007-2016 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
53 const GeomAdaptor_Surface& aGAS,
54 const Standard_Real aTol,
57 Standard_Integer iErr = 0;
58 GeomAbs_SurfaceType aType = aGAS.GetType();
59 IntSurf_Quadric aQuad;
61 aState = TopAbs_UNKNOWN;
65 aQuad.SetValue(aGAS.Plane());
68 case GeomAbs_Cylinder:
69 aQuad.SetValue(aGAS.Cylinder());
73 aQuad.SetValue(aGAS.Sphere());
77 iErr=1; // unprocessed surface type
82 const Standard_Real aDp = aQuad.Distance(aP);
88 } else if (aDp < -aTol) {
95 //=======================================================================
98 //=======================================================================
99 Standard_Integer GEOMAlgo_SurfaceTools::GetState
101 const Handle(Geom_Surface)& aSurf,
102 const Standard_Real aTol,
103 TopAbs_State& aState)
105 Standard_Integer iErr;
106 GeomAdaptor_Surface aGAS;
108 aState=TopAbs_UNKNOWN;
111 iErr=GEOMAlgo_SurfaceTools::GetState(aP, aGAS, aTol, aState);
115 //=======================================================================
116 //function : ReverseState
118 //=======================================================================
119 TopAbs_State GEOMAlgo_SurfaceTools::ReverseState
120 (const TopAbs_State aState)
122 TopAbs_State aRSt=aState;
137 //=======================================================================
138 //function : IsCoaxial
140 //=======================================================================
141 Standard_Boolean GEOMAlgo_SurfaceTools::IsCoaxial
144 const gp_Cylinder& aCyl,
145 const Standard_Real aTol)
147 const gp_XYZ &aLoc = aCyl.Location().XYZ();
148 const gp_Ax1 &aAxis = aCyl.Axis();
149 const gp_XYZ &aDAxis = aAxis.Direction().XYZ();
150 gp_XYZ aDP1 = aP1.XYZ().Subtracted(aLoc);
151 gp_XYZ aDP2 = aP2.XYZ().Subtracted(aLoc);
152 Standard_Real aDot1 = aDP1.Dot(aDAxis);
153 Standard_Real aDot2 = aDP1.Dot(aDAxis);
154 //Standard_Real aTol2 = aTol*aTol;
156 // Project P1 and P2 onto a plane with location aLoc and Norm aDAxis.
157 aDP1.Subtract(aDAxis.Multiplied(aDot1));
158 aDP2.Subtract(aDAxis.Multiplied(aDot2));
160 Standard_Real aRadius1 = aDP1.Modulus();
161 Standard_Real aRadius2 = aDP2.Modulus();
162 Standard_Boolean isOn = Standard_False;
164 if (fabs(aRadius1 - aRadius2) <= aTol) {
165 // Check the deflection of the middle point.
166 gp_XYZ aMidP = 0.5*(aDP1 + aDP2);
167 //Standard_Real aMidRadius1 = aMidP.Modulus();
169 if (fabs(aRadius1 - aRadius2) <= aTol) {
170 isOn = Standard_True;
176 //=======================================================================
177 //function : IsAnalytic
179 //=======================================================================
180 Standard_Boolean GEOMAlgo_SurfaceTools::IsAnalytic
181 (const Handle(Geom_Surface)& aSurf)
183 Standard_Boolean bRet;
184 GeomAbs_SurfaceType aType;
185 GeomAdaptor_Surface aGAS;
188 aType=aGAS.GetType();
189 bRet=(aType==GeomAbs_Plane ||
190 aType==GeomAbs_Cylinder ||
191 aType==GeomAbs_Sphere);
194 //=======================================================================
195 //function : IsConformState
197 //=======================================================================
198 Standard_Boolean GEOMAlgo_SurfaceTools::IsConformState
199 (const TopAbs_State aST1,
200 const GEOMAlgo_State aST2)
202 Standard_Boolean bRet=Standard_False;
206 if (aST1==TopAbs_IN) {
210 case GEOMAlgo_ST_OUT:
211 if (aST1==TopAbs_OUT) {
216 if (aST1==TopAbs_ON) {
220 case GEOMAlgo_ST_ONIN:
221 if (aST1==TopAbs_ON || aST1==TopAbs_IN) {
225 case GEOMAlgo_ST_ONOUT:
226 if (aST1==TopAbs_ON || aST1==TopAbs_OUT) {