0023948: Wrong intersection between a surface of revolution and a plane.
[occt.git] / src / BRepExtrema / BRepExtrema_ExtFF.cxx
CommitLineData
b311480e 1// Created on: 1993-12-15
2// Created by: Christophe MARION
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
7fd59977 17// modified by mps (juillet 96 ): on utilise BRepAdaptor a la place de
18// GeomAdaptor dans Initialize et Perform.
92d1589b
A
19
20#include <BRepExtrema_ExtFF.hxx>
21
7fd59977 22#include <BRepExtrema_ExtCF.hxx>
23#include <BRep_Tool.hxx>
24#include <BRepTools.hxx>
7fd59977 25#include <BRepClass_FaceClassifier.hxx>
7fd59977 26#include <gp_Pnt2d.hxx>
27#include <Precision.hxx>
28#include <BRepAdaptor_HSurface.hxx>
29
30//=======================================================================
31//function : BRepExtrema_ExtFF
32//purpose :
33//=======================================================================
34
92d1589b 35BRepExtrema_ExtFF::BRepExtrema_ExtFF(const TopoDS_Face& F1, const TopoDS_Face& F2)
7fd59977 36{
37 Initialize(F2);
38 Perform(F1,F2);
39}
92d1589b 40
7fd59977 41//=======================================================================
42//function : Initialize
43//purpose :
44//=======================================================================
45
46void BRepExtrema_ExtFF::Initialize(const TopoDS_Face& F2)
47{
48 BRepAdaptor_Surface Surf(F2);
49 myHS = new BRepAdaptor_HSurface(Surf);
0e4e1240 50 Standard_Real Tol = Min(BRep_Tool::Tolerance(F2), Precision::Confusion());
51 Tol = Min(Surf.UResolution(Tol), Surf.VResolution(Tol));
52 Tol = Max(Tol, Precision::PConfusion());
7fd59977 53 Standard_Real U1, U2, V1, V2;
54 BRepTools::UVBounds(F2, U1, U2, V1, V2);
92d1589b 55 myExtSS.Initialize(myHS->Surface(), U1, U2, V1, V2, Tol);
7fd59977 56}
57
58//=======================================================================
59//function : Perform
60//purpose :
61//=======================================================================
62
92d1589b 63void BRepExtrema_ExtFF::Perform(const TopoDS_Face& F1, const TopoDS_Face& F2)
7fd59977 64{
7fd59977 65 mySqDist.Clear();
66 myPointsOnS1.Clear();
67 myPointsOnS2.Clear();
92d1589b 68
7fd59977 69 BRepAdaptor_Surface Surf1(F1);
70 Handle(BRepAdaptor_HSurface) HS1 = new BRepAdaptor_HSurface(Surf1);
0e4e1240 71 Standard_Real Tol1 = Min(BRep_Tool::Tolerance(F1), Precision::Confusion());
72 Tol1 = Min(Surf1.UResolution(Tol1), Surf1.VResolution(Tol1));
73 Tol1 = Max(Tol1, Precision::PConfusion());
92d1589b 74 Standard_Real U1, U2, V1, V2;
7fd59977 75 BRepTools::UVBounds(F1, U1, U2, V1, V2);
92d1589b
A
76 myExtSS.Perform(HS1->Surface(), U1, U2, V1, V2, Tol1);
77
78 if (!myExtSS.IsDone())
79 return;
80
81 if (myExtSS.IsParallel())
82 mySqDist.Append(myExtSS.SquareDistance(1));
83 else
84 {
85 // Exploration of points and classification
86 BRepClass_FaceClassifier classifier;
87 const Standard_Real Tol2 = BRep_Tool::Tolerance(F2);
88 Extrema_POnSurf P1, P2;
89
90 Standard_Integer i;
91 for (i = 1; i <= myExtSS.NbExt(); i++)
92 {
93 myExtSS.Points(i, P1, P2);
7fd59977 94 P1.Parameter(U1, U2);
92d1589b
A
95 const gp_Pnt2d Puv1(U1, U2);
96 classifier.Perform(F1, Puv1, Tol1);
97 const TopAbs_State state1 = classifier.State();
98 if (state1 == TopAbs_ON || state1 == TopAbs_IN)
99 {
100 P2.Parameter(U1, U2);
101 const gp_Pnt2d Puv2(U1, U2);
102 classifier.Perform(F2, Puv2, Tol2);
103 const TopAbs_State state2 = classifier.State();
104 if (state2 == TopAbs_ON || state2 == TopAbs_IN)
105 {
106 mySqDist.Append(myExtSS.SquareDistance(i));
107 myPointsOnS1.Append(P1);
108 myPointsOnS2.Append(P2);
109 }
7fd59977 110 }
111 }
112 }
113}