b311480e |
1 | // Created on: 1997-11-06 |
2 | // Created by: Roman BORISOV |
3 | // Copyright (c) 1997-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 | |
42cf5bc1 |
17 | |
18 | #include <Adaptor3d_Curve.hxx> |
19 | #include <Adaptor3d_Surface.hxx> |
20 | #include <gp_Pnt2d.hxx> |
7fd59977 |
21 | #include <math_FunctionSetRoot.hxx> |
22 | #include <math_NewtonFunctionSetRoot.hxx> |
42cf5bc1 |
23 | #include <ProjLib_PrjFunc.hxx> |
24 | #include <ProjLib_PrjResolve.hxx> |
25 | #include <Standard_ConstructionError.hxx> |
26 | #include <Standard_DomainError.hxx> |
27 | #include <StdFail_NotDone.hxx> |
7fd59977 |
28 | |
d533dafb |
29 | ProjLib_PrjResolve::ProjLib_PrjResolve(const Adaptor3d_Curve& C,const Adaptor3d_Surface& S,const Standard_Integer Fix) |
30 | : myDone(Standard_False), |
31 | myFix(Fix) |
7fd59977 |
32 | { |
9775fa61 |
33 | if (myFix > 3 || myFix < 1) throw Standard_ConstructionError(); |
7fd59977 |
34 | mySolution = gp_Pnt2d(0.,0.); |
35 | myCurve = (Adaptor3d_CurvePtr)&C; |
36 | mySurface = (Adaptor3d_SurfacePtr)&S; |
37 | } |
38 | |
39 | // void ProjLib_PrjResolve::Perform(const Standard_Real t, const Standard_Real U, const Standard_Real V, const gp_Pnt2d& Tol2d, const gp_Pnt2d& Inf, const gp_Pnt2d& Sup, const Standard_Real FuncTol, const Standard_Boolean StrictInside) |
40 | void ProjLib_PrjResolve::Perform(const Standard_Real t, const Standard_Real U, const Standard_Real V, const gp_Pnt2d& Tol2d, const gp_Pnt2d& Inf, const gp_Pnt2d& Sup, const Standard_Real FuncTol, const Standard_Boolean ) |
41 | { |
42 | |
43 | myDone = Standard_False; |
44 | Standard_Real FixVal = 0.; |
45 | gp_Pnt2d ExtInf(0.,0.), ExtSup(0.,0.); |
46 | Standard_Real ExtU = 10*Tol2d.X(), ExtV = 10*Tol2d.Y(); |
47 | math_Vector Tol(1, 2), Start(1, 2), BInf(1, 2), BSup(1, 2); |
48 | |
49 | ExtInf.SetCoord(Inf.X() - ExtU, Inf.Y() - ExtV); |
50 | ExtSup.SetCoord(Sup.X() + ExtU, Sup.Y() + ExtV); |
51 | BInf(1) = ExtInf.X(); |
52 | BInf(2) = ExtInf.Y(); |
53 | BSup(1) = ExtSup.X(); |
54 | BSup(2) = ExtSup.Y(); |
55 | Tol(1) = Tol2d.X(); |
56 | Tol(2) = Tol2d.Y(); |
57 | |
58 | switch(myFix) { |
59 | case 1: |
60 | Start(1) = U; |
61 | Start(2) = V; |
62 | FixVal = t; |
63 | break; |
64 | case 2: |
65 | Start(1) = t; |
66 | Start(2) = V; |
67 | FixVal = U; |
68 | break; |
69 | case 3: |
70 | Start(1) = t; |
71 | Start(2) = U; |
72 | FixVal = V; |
73 | } |
74 | |
75 | ProjLib_PrjFunc F(myCurve, FixVal, mySurface, myFix); |
76 | |
77 | |
78 | // Standard_Integer option = 1;//2; |
79 | // if (option == 1) { |
80 | // math_FunctionSetRoot S1 (F, Start,Tol, BInf, BSup); |
81 | // if (!S1.IsDone()) { return; } |
82 | // } |
83 | // else { |
859a47c3 |
84 | math_NewtonFunctionSetRoot SR (F, Tol, 1.e-10); |
85 | SR.Perform(F, Start, BInf, BSup); |
7fd59977 |
86 | // if (!SR.IsDone()) { return; } |
859a47c3 |
87 | if (!SR.IsDone()) |
88 | { |
89 | math_FunctionSetRoot S1 (F, Tol); |
90 | S1.Perform(F, Start, BInf, BSup); |
7fd59977 |
91 | |
859a47c3 |
92 | if (!S1.IsDone()) |
93 | return; |
94 | } |
7fd59977 |
95 | |
96 | mySolution.SetXY(F.Solution().XY()); |
97 | |
98 | // computation of myDone |
99 | myDone = Standard_True; |
100 | |
101 | Standard_Real ExtraU , ExtraV; |
102 | // if(!StrictInside) { |
103 | ExtraU = Tol2d.X(); |
104 | ExtraV = Tol2d.Y(); |
105 | // } |
c84d6e55 |
106 | if (mySolution.X() > Inf.X() - Tol2d.X() && mySolution.X() < Inf.X()) mySolution.SetX(Inf.X()); |
107 | if (mySolution.X() > Sup.X() && mySolution.X() < Sup.X() + Tol2d.X()) mySolution.SetX(Sup.X()); |
108 | if (mySolution.Y() > Inf.Y() - Tol2d.Y() && mySolution.Y() < Inf.Y()) mySolution.SetY(Inf.Y()); |
109 | if (mySolution.Y() > Sup.Y() && mySolution.Y() < Sup.Y() + Tol2d.Y()) mySolution.SetY(Sup.Y()); |
110 | if (mySolution.X() < Inf.X() - ExtraU || |
7fd59977 |
111 | mySolution.X() > Sup.X() + ExtraU || |
c84d6e55 |
112 | mySolution.Y() < Inf.Y() - ExtraV || |
7fd59977 |
113 | mySolution.Y() > Sup.Y() + ExtraV) myDone = Standard_False; |
114 | else if (FuncTol > 0) { |
115 | math_Vector X(1,2,0.), FVal(1,2,0.); |
116 | X(1) = mySolution.X(); |
117 | X(2) = mySolution.Y(); |
118 | |
119 | |
120 | F.Value(X, FVal); |
7fd59977 |
121 | |
122 | if ((FVal(1)*FVal(1) + FVal(2)*FVal(2)) > FuncTol) myDone = Standard_False; |
123 | } |
124 | |
125 | |
126 | } |
127 | |
128 | Standard_Boolean ProjLib_PrjResolve::IsDone() const |
129 | { |
130 | return myDone; |
131 | } |
132 | |
133 | gp_Pnt2d ProjLib_PrjResolve::Solution() const |
134 | { |
9775fa61 |
135 | if (!IsDone()) throw StdFail_NotDone(); |
7fd59977 |
136 | return mySolution; |
137 | } |