1 // Copyright (C) 2007-2013 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
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 Standard_Boolean bRet=Standard_False;
146 gp_Vec aV12(aP1, aP2);
149 const gp_Ax1& aAxis=aCyl.Axis();
150 const gp_Dir& aDAxis=aAxis.Direction();
152 aSM=fabs(aD12*aDAxis);
153 if (fabs(1.-aSM) > aTol) {
159 //=======================================================================
160 //function : IsAnalytic
162 //=======================================================================
163 Standard_Boolean GEOMAlgo_SurfaceTools::IsAnalytic(const Handle(Geom_Surface)& aSurf)
165 Standard_Boolean bRet;
166 GeomAbs_SurfaceType aType;
167 GeomAdaptor_Surface aGAS;
170 aType=aGAS.GetType();
171 bRet=(aType==GeomAbs_Plane ||
172 aType==GeomAbs_Cylinder ||
173 aType==GeomAbs_Sphere);
176 //=======================================================================
177 //function : IsConformState
179 //=======================================================================
180 Standard_Boolean GEOMAlgo_SurfaceTools::IsConformState(const TopAbs_State aST1,
181 const GEOMAlgo_State aST2)
183 Standard_Boolean bRet=Standard_False;
187 if (aST1==TopAbs_IN) {
191 case GEOMAlgo_ST_OUT:
192 if (aST1==TopAbs_OUT) {
197 if (aST1==TopAbs_ON) {
201 case GEOMAlgo_ST_ONIN:
202 if (aST1==TopAbs_ON || aST1==TopAbs_IN) {
206 case GEOMAlgo_ST_ONOUT:
207 if (aST1==TopAbs_ON || aST1==TopAbs_OUT) {