1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: GEOMAlgo_SurfaceTools.cxx
21 // Created: Thu Jan 27 11:05:16 2005
22 // Author: Peter KURNEV
26 #include <GEOMAlgo_SurfaceTools.ixx>
31 #include <gp_Cylinder.hxx>
32 #include <gp_Sphere.hxx>
40 #include <GeomAbs_SurfaceType.hxx>
41 #include <GeomAdaptor_Surface.hxx>
44 //=======================================================================
47 //=======================================================================
48 Standard_Integer GEOMAlgo_SurfaceTools::GetState(const gp_Pnt& aP,
49 const GeomAdaptor_Surface& aGAS,
50 const Standard_Real aTol,
53 Standard_Integer iErr;
54 Standard_Real aDp, aR;
55 GeomAbs_SurfaceType aType;
61 aState=TopAbs_UNKNOWN;
68 aDp=GEOMAlgo_SurfaceTools::Distance(aP, aPln);
71 case GeomAbs_Cylinder:
74 aDp=GEOMAlgo_SurfaceTools::Distance(aP, aCyl);
80 aDp=GEOMAlgo_SurfaceTools::Distance(aP, aSph);
84 iErr=1; // unprocessed surface type
93 else if (aDp<aR-aTol) {
100 //=======================================================================
101 //function : GetState
103 //=======================================================================
104 Standard_Integer GEOMAlgo_SurfaceTools::GetState(const gp_Pnt& aP,
105 const Handle(Geom_Surface)& aSurf,
106 const Standard_Real aTol,
107 TopAbs_State& aState)
109 Standard_Integer iErr;
110 GeomAdaptor_Surface aGAS;
112 aState=TopAbs_UNKNOWN;
115 iErr=GEOMAlgo_SurfaceTools::GetState(aP, aGAS, aTol, aState);
119 //=======================================================================
120 //function : ReverseState
122 //=======================================================================
123 TopAbs_State GEOMAlgo_SurfaceTools::ReverseState(const TopAbs_State aState)
125 TopAbs_State aRSt=aState;
140 //=======================================================================
141 //function : Distance
143 //=======================================================================
144 Standard_Real GEOMAlgo_SurfaceTools::Distance(const gp_Pnt& aP,
145 const gp_Sphere& aSph)
149 const gp_Pnt& aLoc=aSph.Location();
150 aD=aLoc.Distance(aP);
154 //=======================================================================
155 //function : Distance
157 //=======================================================================
158 Standard_Real GEOMAlgo_SurfaceTools::Distance(const gp_Pnt& aP,
159 const gp_Cylinder& aCyl)
163 const gp_Ax1& aAxis=aCyl.Axis();
165 aD=aLin.Distance(aP);
169 //=======================================================================
170 //function : Distance
172 //=======================================================================
173 Standard_Real GEOMAlgo_SurfaceTools::Distance(const gp_Pnt& aP,
178 const gp_Ax3& aPos=aPL.Position();
179 const gp_Pnt& aLoc=aPos.Location ();
180 const gp_Dir& aDir=aPos.Direction();
182 aD= (aDir.X() * (aP.X() - aLoc.X()) +
183 aDir.Y() * (aP.Y() - aLoc.Y()) +
184 aDir.Z() * (aP.Z() - aLoc.Z()));
187 //=======================================================================
188 //function : IsCoaxial
190 //=======================================================================
191 Standard_Boolean GEOMAlgo_SurfaceTools::IsCoaxial(const gp_Pnt& aP1,
193 const gp_Cylinder& aCyl,
194 const Standard_Real aTol)
196 Standard_Boolean bRet=Standard_False;
199 gp_Vec aV12(aP1, aP2);
202 const gp_Ax1& aAxis=aCyl.Axis();
203 const gp_Dir& aDAxis=aAxis.Direction();
205 aSM=fabs(aD12*aDAxis);
206 if (fabs(1.-aSM) > aTol) {
212 //=======================================================================
213 //function : IsAnalytic
215 //=======================================================================
216 Standard_Boolean GEOMAlgo_SurfaceTools::IsAnalytic(const Handle(Geom_Surface)& aSurf)
218 Standard_Boolean bRet;
219 GeomAbs_SurfaceType aType;
220 GeomAdaptor_Surface aGAS;
223 aType=aGAS.GetType();
224 bRet=(aType==GeomAbs_Plane ||
225 aType==GeomAbs_Cylinder ||
226 aType==GeomAbs_Sphere);
229 //=======================================================================
230 //function : IsConformState
232 //=======================================================================
233 Standard_Boolean GEOMAlgo_SurfaceTools::IsConformState(const TopAbs_State aST1,
234 const GEOMAlgo_State aST2)
236 Standard_Boolean bRet=Standard_False;
240 if (aST1==TopAbs_IN) {
244 case GEOMAlgo_ST_OUT:
245 if (aST1==TopAbs_OUT) {
250 if (aST1==TopAbs_ON) {
254 case GEOMAlgo_ST_ONIN:
255 if (aST1==TopAbs_ON || aST1==TopAbs_IN) {
259 case GEOMAlgo_ST_ONOUT:
260 if (aST1==TopAbs_ON || aST1==TopAbs_OUT) {