1 // Copyright (C) 2007-2008 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.
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
22 // File: GEOMAlgo_SurfaceTools.cxx
23 // Created: Thu Jan 27 11:05:16 2005
24 // Author: Peter KURNEV
27 #include <GEOMAlgo_SurfaceTools.ixx>
32 #include <gp_Cylinder.hxx>
33 #include <gp_Sphere.hxx>
41 #include <GeomAbs_SurfaceType.hxx>
42 #include <GeomAdaptor_Surface.hxx>
45 //=======================================================================
48 //=======================================================================
49 Standard_Integer GEOMAlgo_SurfaceTools::GetState(const gp_Pnt& aP,
50 const GeomAdaptor_Surface& aGAS,
51 const Standard_Real aTol,
54 Standard_Integer iErr;
55 Standard_Real aDp, aR;
56 GeomAbs_SurfaceType aType;
62 aState=TopAbs_UNKNOWN;
69 aDp=GEOMAlgo_SurfaceTools::Distance(aP, aPln);
72 case GeomAbs_Cylinder:
75 aDp=GEOMAlgo_SurfaceTools::Distance(aP, aCyl);
81 aDp=GEOMAlgo_SurfaceTools::Distance(aP, aSph);
85 iErr=1; // unprocessed surface type
94 else if (aDp<aR-aTol) {
101 //=======================================================================
102 //function : GetState
104 //=======================================================================
105 Standard_Integer GEOMAlgo_SurfaceTools::GetState(const gp_Pnt& aP,
106 const Handle(Geom_Surface)& aSurf,
107 const Standard_Real aTol,
108 TopAbs_State& aState)
110 Standard_Integer iErr;
111 GeomAdaptor_Surface aGAS;
113 aState=TopAbs_UNKNOWN;
116 iErr=GEOMAlgo_SurfaceTools::GetState(aP, aGAS, aTol, aState);
120 //=======================================================================
121 //function : ReverseState
123 //=======================================================================
124 TopAbs_State GEOMAlgo_SurfaceTools::ReverseState(const TopAbs_State aState)
126 TopAbs_State aRSt=aState;
141 //=======================================================================
142 //function : Distance
144 //=======================================================================
145 Standard_Real GEOMAlgo_SurfaceTools::Distance(const gp_Pnt& aP,
146 const gp_Sphere& aSph)
150 const gp_Pnt& aLoc=aSph.Location();
151 aD=aLoc.Distance(aP);
155 //=======================================================================
156 //function : Distance
158 //=======================================================================
159 Standard_Real GEOMAlgo_SurfaceTools::Distance(const gp_Pnt& aP,
160 const gp_Cylinder& aCyl)
164 const gp_Ax1& aAxis=aCyl.Axis();
166 aD=aLin.Distance(aP);
170 //=======================================================================
171 //function : Distance
173 //=======================================================================
174 Standard_Real GEOMAlgo_SurfaceTools::Distance(const gp_Pnt& aP,
179 const gp_Ax3& aPos=aPL.Position();
180 const gp_Pnt& aLoc=aPos.Location ();
181 const gp_Dir& aDir=aPos.Direction();
183 aD= (aDir.X() * (aP.X() - aLoc.X()) +
184 aDir.Y() * (aP.Y() - aLoc.Y()) +
185 aDir.Z() * (aP.Z() - aLoc.Z()));
188 //=======================================================================
189 //function : IsCoaxial
191 //=======================================================================
192 Standard_Boolean GEOMAlgo_SurfaceTools::IsCoaxial(const gp_Pnt& aP1,
194 const gp_Cylinder& aCyl,
195 const Standard_Real aTol)
197 Standard_Boolean bRet=Standard_False;
200 gp_Vec aV12(aP1, aP2);
203 const gp_Ax1& aAxis=aCyl.Axis();
204 const gp_Dir& aDAxis=aAxis.Direction();
206 aSM=fabs(aD12*aDAxis);
207 if (fabs(1.-aSM) > aTol) {
213 //=======================================================================
214 //function : IsAnalytic
216 //=======================================================================
217 Standard_Boolean GEOMAlgo_SurfaceTools::IsAnalytic(const Handle(Geom_Surface)& aSurf)
219 Standard_Boolean bRet;
220 GeomAbs_SurfaceType aType;
221 GeomAdaptor_Surface aGAS;
224 aType=aGAS.GetType();
225 bRet=(aType==GeomAbs_Plane ||
226 aType==GeomAbs_Cylinder ||
227 aType==GeomAbs_Sphere);
230 //=======================================================================
231 //function : IsConformState
233 //=======================================================================
234 Standard_Boolean GEOMAlgo_SurfaceTools::IsConformState(const TopAbs_State aST1,
235 const GEOMAlgo_State aST2)
237 Standard_Boolean bRet=Standard_False;
241 if (aST1==TopAbs_IN) {
245 case GEOMAlgo_ST_OUT:
246 if (aST1==TopAbs_OUT) {
251 if (aST1==TopAbs_ON) {
255 case GEOMAlgo_ST_ONIN:
256 if (aST1==TopAbs_ON || aST1==TopAbs_IN) {
260 case GEOMAlgo_ST_ONOUT:
261 if (aST1==TopAbs_ON || aST1==TopAbs_OUT) {