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> |
7fd59977 |
20 | #include <gp_Pnt.hxx> |
42cf5bc1 |
21 | #include <gp_Pnt2d.hxx> |
7fd59977 |
22 | #include <gp_Vec.hxx> |
42cf5bc1 |
23 | #include <math_Matrix.hxx> |
24 | #include <ProjLib_PrjFunc.hxx> |
25 | #include <Standard_ConstructionError.hxx> |
7fd59977 |
26 | |
27 | ProjLib_PrjFunc::ProjLib_PrjFunc(const Adaptor3d_CurvePtr & C,const Standard_Real FixVal,const Adaptor3d_SurfacePtr & S, const Standard_Integer Fix) : myCurve(C), mySurface(S), myt(0), myU(0), myV(0), myFix(Fix) |
28 | { |
29 | myNorm=Min(1.,Min(mySurface->UResolution(1.),mySurface->VResolution(1.))); |
30 | // myNorm=1.; |
31 | switch(myFix) { |
32 | case 1: myt = FixVal; break; |
33 | case 2: myU = FixVal; break; |
34 | case 3: myV = FixVal; break; |
9775fa61 |
35 | default: throw Standard_ConstructionError(); |
7fd59977 |
36 | } |
37 | } |
38 | |
39 | Standard_Integer ProjLib_PrjFunc::NbVariables() const |
40 | { |
41 | return 2; |
42 | } |
43 | |
44 | Standard_Integer ProjLib_PrjFunc::NbEquations() const |
45 | { |
46 | return 2; |
47 | } |
48 | |
49 | Standard_Boolean ProjLib_PrjFunc::Value(const math_Vector& X,math_Vector& F) |
50 | { |
51 | math_Matrix D (1,2,1,2); |
52 | return Values(X,F,D); |
53 | } |
54 | |
55 | Standard_Boolean ProjLib_PrjFunc::Derivatives(const math_Vector& X,math_Matrix& D) |
56 | { |
57 | math_Vector F(1,2); |
58 | return Values(X,F,D); |
59 | } |
60 | |
61 | Standard_Boolean ProjLib_PrjFunc::Values(const math_Vector& X,math_Vector& F,math_Matrix& D) |
62 | { |
63 | Standard_Real u = 0., v = 0., t = 0.; |
64 | switch(myFix) { |
65 | case 1: |
66 | t = myt; |
67 | u = X(1); |
68 | v = X(2); |
69 | break; |
70 | case 2: |
71 | t = X(1); |
72 | u = myU; |
73 | v = X(2); |
74 | break; |
75 | case 3: |
76 | t = X(1); |
77 | u = X(2); |
78 | v = myV; |
79 | } |
80 | |
81 | /* if(X(1) > mySup.X() || X(1) < myInf.X()) return Standard_False; |
82 | if(X(2) > mySup.Y() || X(2) < myInf.Y()) return Standard_False; |
83 | */ |
84 | gp_Pnt S, C; |
85 | gp_Vec DS1_u, DS1_v, DS2_u, DS2_uv, DS2_v, DC1_t; |
86 | myCurve->D1(t, C, DC1_t); |
87 | mySurface->D2(u, v, S, DS1_u, DS1_v, DS2_u, DS2_v, DS2_uv); |
88 | |
89 | gp_Vec V(C, S); |
90 | |
91 | F(1) = V*DS1_u*myNorm; |
92 | F(2) = V*DS1_v*myNorm; |
93 | |
94 | switch(myFix) { |
95 | case 1: |
96 | D(1, 1) = (DS1_u.SquareMagnitude() + V*DS2_u)*myNorm; // dE1/du |
97 | D(1, 2) = (DS1_v*DS1_u + V*DS2_uv)*myNorm; // dE1/dv |
98 | D(2, 1) = D(1, 2); // dE2/du |
99 | D(2, 2) = (DS1_v.SquareMagnitude() + V*DS2_v)*myNorm; // dE2/dv |
100 | break; |
101 | case 2: |
102 | D(1, 1) = (-DC1_t*DS1_u)*myNorm; // dE1/dt |
103 | D(1, 2) = (DS1_v*DS1_u + V*DS2_uv)*myNorm; // dE1/dv |
104 | D(2, 1) = (-DC1_t*DS1_v)*myNorm; // dE2/dt |
105 | D(2, 2) = (DS1_v.SquareMagnitude() + V*DS2_v)*myNorm; // dE2/dv |
106 | break; |
107 | case 3: |
108 | D(1, 1) = -DC1_t*DS1_u*myNorm; // dE1/dt |
109 | D(1, 2) = (DS1_u.SquareMagnitude() + V*DS2_u)*myNorm; // dE1/du |
110 | D(2, 1) = -DC1_t*DS1_v*myNorm; // dE2/dt |
111 | D(2, 2) = (DS1_v*DS1_u + V*DS2_uv)*myNorm;// dE2/du |
112 | } |
113 | |
04232180 |
114 | /* std::cout<<"F = ("<<F(1)<<", "<<F(2)<<")"<<std::endl; |
115 | std::cout<<"dE1/dt = "<<D(1,1)<<std::endl; |
116 | std::cout<<"dE1/dv = "<<D(1,2)<<std::endl; |
117 | std::cout<<"dE2/dt = "<<D(2,1)<<std::endl; |
118 | std::cout<<"dE2/dv = "<<D(2,2)<<std::endl; |
7fd59977 |
119 | */ |
120 | |
121 | |
122 | myU = u; |
123 | myV = v; |
124 | myt = t; |
125 | |
126 | return Standard_True; |
127 | } |
128 | |
129 | gp_Pnt2d ProjLib_PrjFunc::Solution() const |
130 | { |
131 | switch(myFix) { |
132 | case 1: return gp_Pnt2d(myU, myV); |
133 | case 2: return gp_Pnt2d(myt, myV); |
134 | case 3: return gp_Pnt2d(myt, myU); |
135 | } |
136 | // pout NT, meme si on n'y passe pas. |
137 | return gp_Pnt2d(0.,0.); |
138 | } |
139 | |
140 | |