1 // Created on: 2004-06-10
2 // Created by: Peter KURNEV
3 // Copyright (c) 2004-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <BOPTools_Tools3D.ixx>
25 #include <gp_Cylinder.hxx>
28 #include <gp_Cone.hxx>
30 #include <TopAbs_Orientation.hxx>
31 #include <Geom_Surface.hxx>
32 #include <GeomAbs_SurfaceType.hxx>
33 #include <BRep_Tool.hxx>
34 #include <GeomAdaptor_Surface.hxx>
35 #include <IntTools_Tools.hxx>
36 #include <BOPTools_Tools2D.hxx>
37 #include <Geom_Curve.hxx>
41 Standard_Boolean AnalyticState(const TopoDS_Face& aF1,
42 const TopoDS_Face& aFx,
45 const Standard_Real aTolR,
49 gp_Pnt ProjectedPoint (const gp_Pnt&,
52 //=======================================================================
53 //function : TreatedAsAnalytic
55 //=======================================================================
56 Standard_Boolean BOPTools_Tools3D::TreatedAsAnalytic(const TopoDS_Face& aFx,
57 const TopoDS_Edge& aSpE1,
58 const TopoDS_Face& aF1,
59 const Standard_Real aTolTangent,
60 const Standard_Real aTolR,
62 const Handle(IntTools_Context)& )
64 Standard_Boolean bFlag, bIsAnalytic, bIsDirsCoinside;
65 Standard_Real aT1, aTb, aTe;
71 bIsAnalytic=BOPTools_Tools3D::HasAnalyticSurfaceType(aFx);
75 bIsAnalytic=BOPTools_Tools3D::HasAnalyticSurfaceType(aF1);
80 Handle(Geom_Curve)aC3D =BRep_Tool::Curve(aSpE1, aTb, aTe);
81 aT1=BOPTools_Tools2D::IntermediatePoint (aTb, aTe);
84 BOPTools_Tools3D::GetNormalToFaceOnEdge(aSpE1, aF1, aT1, aDNS1);
85 BOPTools_Tools3D::GetNormalToFaceOnEdge(aSpE1, aFx, aT1, aDNSx);
87 bIsDirsCoinside=IntTools_Tools::IsDirsCoinside(aDNSx, aDNS1, aTolTangent);
88 if (!bIsDirsCoinside) {
92 bFlag=AnalyticState(aF1, aFx, aP1, aDNSx, aTolR, aSt);
97 //=======================================================================
98 //function : TreatedAsAnalytic
100 //=======================================================================
101 Standard_Boolean BOPTools_Tools3D::TreatedAsAnalytic(const Standard_Real aTx,
103 const TopoDS_Edge& anEx,
104 const TopoDS_Face& aFx,
105 const TopoDS_Edge& anE1,
106 const TopoDS_Face& aF1,
107 const Standard_Real aTolTangent,
108 const Standard_Real aTolR,
110 const Handle(IntTools_Context)& aContext)
112 Standard_Boolean bFlag, bIsAnalytic, bIsDirsCoinside;
116 bFlag=Standard_False;
118 bIsAnalytic=BOPTools_Tools3D::HasAnalyticSurfaceType(aFx);
122 bIsAnalytic=BOPTools_Tools3D::HasAnalyticSurfaceType(aF1);
127 BOPTools_Tools3D::GetNormalToFaceOnEdge(anEx, aFx, aTx, aDNSx);
128 aContext->ProjectPointOnEdge(aPx, anE1, aT1);
129 BOPTools_Tools3D::GetNormalToFaceOnEdge(anE1, aF1, aT1, aDNS1);
131 bIsDirsCoinside=IntTools_Tools::IsDirsCoinside(aDNSx, aDNS1, aTolTangent);
132 if (!bIsDirsCoinside) {
136 bFlag=AnalyticState(aF1, aFx, aPx, aDNSx, aTolR, aSt);
141 //=======================================================================
142 //function : AnalyticState
144 //=======================================================================
145 Standard_Boolean AnalyticState(const TopoDS_Face& aF1,
146 const TopoDS_Face& aFx,
149 const Standard_Real aTolR,
152 Standard_Boolean bFlag;
154 Handle(Geom_Surface) aSF1, aSFx;
155 GeomAbs_SurfaceType aTypeF1, aTypeFx;
156 TopAbs_Orientation anOrFx;
160 bFlag=Standard_False;
163 aSF1=BRep_Tool::Surface(aF1);
164 GeomAdaptor_Surface aGASF1(aSF1);
165 aTypeF1=aGASF1.GetType();
167 aSFx=BRep_Tool::Surface(aFx);
168 GeomAdaptor_Surface aGASFx(aSFx);
169 aTypeFx=aGASFx.GetType();
172 anOrFx=aFx.Orientation();
173 if (anOrFx==TopAbs_REVERSED){
178 if (aTypeF1==GeomAbs_Plane && aTypeFx==GeomAbs_Cylinder) {
181 aCYx=aGASFx.Cylinder();
182 aPOnAxis=ProjectedPoint(aP, aCYx.Axis());
183 gp_Vec aVTC(aP, aPOnAxis);
195 else if (aTypeF1==GeomAbs_Cylinder && aTypeFx==GeomAbs_Plane) {
198 aCY1=aGASF1.Cylinder();
199 aPOnAxis=ProjectedPoint(aP, aCY1.Axis());
200 gp_Vec aVTC(aP, aPOnAxis);
211 else if ( aTypeF1==GeomAbs_Plane && aTypeFx==GeomAbs_Cone) {
215 aPOnAxis=ProjectedPoint(aP, aCNx.Axis());
216 gp_Vec aVTC(aP, aPOnAxis);
226 else if (aTypeF1==GeomAbs_Cone && aTypeFx==GeomAbs_Plane) {
230 aPOnAxis=ProjectedPoint(aP, aCN1.Axis());
231 gp_Vec aVTC(aP, aPOnAxis);
241 // Cylinder(Cone)/Cylinder(Cone)
242 else if ((aTypeF1==GeomAbs_Cylinder || aTypeF1==GeomAbs_Cone) &&
243 (aTypeFx==GeomAbs_Cylinder || aTypeFx==GeomAbs_Cone)) {
245 Standard_Real aPr, aR1, aRx, aSemiAngle, aDist;
246 gp_Pnt aPOnAxis1, aPOnAxisx;
247 gp_Cylinder aCY1, aCYx;
252 if (aTypeF1==GeomAbs_Cylinder) {
253 aCY1=aGASF1.Cylinder();
256 aPOnAxis1=ProjectedPoint(aP, anAx1);
261 aSemiAngle=aCN1.SemiAngle();
263 aDist=aLin.Distance(aP);
264 aR1=aDist/cos(aSemiAngle);
265 aPOnAxis1=ProjectedPoint(aP, anAx1);
268 if (aTypeFx==GeomAbs_Cylinder) {
269 aCYx=aGASFx.Cylinder();
272 aPOnAxisx=ProjectedPoint(aP, anAxx);
277 aSemiAngle=aCNx.SemiAngle();
279 aDist=aLin.Distance(aP);
280 aRx=aDist/cos(aSemiAngle);
281 aPOnAxisx=ProjectedPoint(aP, anAxx);
284 if (fabs(aRx-aR1) < aTolR) {
288 gp_Vec aVTC1(aP, aPOnAxis1);
289 gp_Vec aVTCx(aP, aPOnAxisx);
323 //=======================================================================
324 //function : HasAnalyticSurfaceType
326 //=======================================================================
327 Standard_Boolean BOPTools_Tools3D::HasAnalyticSurfaceType(const TopoDS_Face& aF)
329 Standard_Boolean bFlag=Standard_False;
330 GeomAbs_SurfaceType aType;
332 Handle(Geom_Surface) aS;
334 aS=BRep_Tool::Surface(aF);
335 GeomAdaptor_Surface aGAS(aS);
336 aType=aGAS.GetType();
339 bFlag= (aType==GeomAbs_Plane ||
340 aType==GeomAbs_Cylinder ||
341 aType==GeomAbs_Cone ||
342 aType==GeomAbs_Sphere);
347 //=======================================================================
348 //function :ProjectedPoint
350 //=======================================================================
351 gp_Pnt ProjectedPoint (const gp_Pnt& aP,
356 gp_Vec aVDirection(anAx1.Direction());
357 gp_Pnt anOrigin=anAx1.Location();
358 gp_Vec aV(anOrigin, aP);
359 aDist = aVDirection.Dot(aV);
361 gp_Pnt aPx= anOrigin.Translated(aDist*aVDirection);