b311480e |
1 | // Created on: 1993-12-06 |
2 | // Created by: Jacques GOUSSARD |
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. |
7fd59977 |
16 | |
c22b52d6 |
17 | #include <BRepBlend_BlendTool.hxx> |
7fd59977 |
18 | |
c22b52d6 |
19 | #include <Adaptor2d_Curve2d.hxx> |
20 | #include <Adaptor3d_Surface.hxx> |
42cf5bc1 |
21 | #include <BRep_Tool.hxx> |
42cf5bc1 |
22 | #include <BRepBlend_HCurve2dTool.hxx> |
7fd59977 |
23 | #include <Extrema_EPCOfExtPC2d.hxx> |
24 | #include <Extrema_POnCurv2d.hxx> |
7fd59977 |
25 | #include <Geom2d_Line.hxx> |
26 | #include <Geom2dAdaptor_Curve.hxx> |
42cf5bc1 |
27 | #include <Geom2dInt_GInter.hxx> |
7fd59977 |
28 | #include <gp_Dir2d.hxx> |
42cf5bc1 |
29 | #include <gp_Pnt2d.hxx> |
7fd59977 |
30 | #include <gp_Vec2d.hxx> |
7fd59977 |
31 | #include <IntRes2d_IntersectionPoint.hxx> |
7fd59977 |
32 | |
33 | //======================================================================= |
34 | //function : Project |
35 | //purpose : Projection orthogonal d'un point sur une courbe |
36 | // pmn 8/10/98 : On retourne toujours une distance. (BUC60360) |
37 | //======================================================================= |
38 | Standard_Boolean BRepBlend_BlendTool::Project(const gp_Pnt2d& P, |
c22b52d6 |
39 | const Handle(Adaptor3d_Surface)&, |
40 | const Handle(Adaptor2d_Curve2d)& C, |
7fd59977 |
41 | Standard_Real& Paramproj, |
42 | Standard_Real& Dist) |
43 | { |
44 | Paramproj = BRepBlend_HCurve2dTool::FirstParameter(C); |
45 | gp_Pnt2d P2d; |
46 | BRepBlend_HCurve2dTool::D0(C, Paramproj, P2d); |
47 | Dist = P2d.Distance(P); |
48 | |
49 | const Standard_Real t = BRepBlend_HCurve2dTool::LastParameter(C); |
50 | BRepBlend_HCurve2dTool::D0(C, t, P2d); |
51 | if (P2d.Distance(P) < Dist) { |
52 | Paramproj = t; |
53 | Dist = P2d.Distance(P); |
54 | } |
55 | |
56 | const Standard_Real epsX = 1.e-8; |
57 | const Standard_Integer Nbu = 20; |
58 | const Standard_Real Tol = 1.e-5; |
c22b52d6 |
59 | Extrema_EPCOfExtPC2d extrema(P, *C, Nbu, epsX, Tol); |
7fd59977 |
60 | if (!extrema.IsDone()) |
61 | return Standard_True; |
62 | |
63 | const Standard_Integer Nbext = extrema.NbExt(); |
64 | Standard_Real aDist2 = Dist * Dist; |
65 | for (Standard_Integer i=1; i<=Nbext; i++) { |
66 | if (extrema.SquareDistance(i) < aDist2) { |
67 | aDist2 = extrema.SquareDistance(i); |
68 | Paramproj = extrema.Point(i).Parameter(); |
69 | } |
70 | } |
71 | Dist = sqrt (aDist2); |
72 | |
73 | return Standard_True; |
74 | } |
75 | |
76 | //======================================================================= |
77 | //function : Inters |
78 | //purpose : Intersection d'un segment avec une courbe |
79 | //======================================================================= |
80 | Standard_Boolean BRepBlend_BlendTool::Inters(const gp_Pnt2d& P1, |
81 | const gp_Pnt2d& P2, |
c22b52d6 |
82 | const Handle(Adaptor3d_Surface)&, |
83 | const Handle(Adaptor2d_Curve2d)& C, |
7fd59977 |
84 | Standard_Real& Param, |
85 | Standard_Real& Dist) |
86 | { |
87 | const Standard_Real Tol = 1.e-8; |
88 | const gp_Vec2d v(P1,P2); |
89 | const Standard_Real mag = v.Magnitude(); |
90 | if(mag < Tol) return Standard_False; |
91 | |
92 | gp_Dir2d d(v); |
93 | Handle(Geom2d_Line) bid = new Geom2d_Line(P1,d); |
94 | Geom2dAdaptor_Curve seg(bid,-0.01*mag,1.01*mag); |
95 | |
c22b52d6 |
96 | Geom2dInt_GInter inter (seg, *C, Tol, Tol); |
7fd59977 |
97 | if (!inter.IsDone()) |
98 | return Standard_False; |
99 | |
100 | const Standard_Integer Nbint = inter.NbPoints(); |
101 | if (Nbint == 0) |
102 | return Standard_False; |
103 | |
104 | IntRes2d_IntersectionPoint ip = inter.Point(1); |
105 | Param = ip.ParamOnSecond(); |
106 | Dist = P1.Distance(ip.Value()); |
107 | return Standard_True; |
108 | } |
109 | |
110 | Standard_Integer BRepBlend_BlendTool::NbSamplesV |
c22b52d6 |
111 | (const Handle(Adaptor3d_Surface)&, |
35e08fe8 |
112 | const Standard_Real, |
113 | const Standard_Real) |
7fd59977 |
114 | { |
115 | return 10; |
116 | } |
117 | |
118 | Standard_Integer BRepBlend_BlendTool::NbSamplesU |
c22b52d6 |
119 | (const Handle(Adaptor3d_Surface)&, |
35e08fe8 |
120 | const Standard_Real, |
121 | const Standard_Real) |
7fd59977 |
122 | { |
123 | return 10; |
124 | } |
125 | |
c22b52d6 |
126 | void BRepBlend_BlendTool::Bounds(const Handle(Adaptor2d_Curve2d)& A, |
7fd59977 |
127 | Standard_Real& Ufirst, |
128 | Standard_Real& Ulast) |
129 | { |
130 | Ufirst = BRepBlend_HCurve2dTool::FirstParameter(A); |
131 | Ulast = BRepBlend_HCurve2dTool::LastParameter(A); |
132 | } |