c444fb06377a54c3e791421b4486b335db126576
[occt.git] / src / Contap / Contap_ArcFunction.gxx
1 // Created on: 1993-06-03
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <gp_Pnt2d.hxx>
18 #include <gp_Vec2d.hxx>
19
20 Contap_ArcFunction::Contap_ArcFunction ():
21        myMean(1.),
22        myType(Contap_ContourStd),
23        myDir(0.,0.,1.)
24 {}
25
26
27 void Contap_ArcFunction::Set(const TheSurface& S)
28 {
29   mySurf = S;
30   Standard_Integer i;
31   Standard_Integer nbs = TheContTool::NbSamplePoints(S);
32   Standard_Real U,V;
33 //  gp_Vec d1u,d1v;
34   gp_Vec norm;
35   if (nbs > 0) {
36     myMean = 0.;
37     for (i = 1; i <= nbs; i++) {
38       TheContTool::SamplePoint(S,i,U,V);
39 //      TheSurfaceTool::D1(S,U,V,solpt,d1u,d1v);
40 //      myMean = myMean + d1u.Crossed(d1v).Magnitude();
41       TheSurfProps::Normale(S,U,V,solpt,norm);
42       myMean = myMean + norm.Magnitude();
43     }
44     myMean = myMean / ((Standard_Real)nbs);
45   }
46 }
47
48
49 Standard_Boolean Contap_ArcFunction::Value (const Standard_Real U,
50                                             Standard_Real& F)
51 {
52   //gp_Vec d1u,d1v;
53   gp_Pnt2d pt2d(TheArcTool::Value(myArc,U));
54 //  TheSurfaceTool::D1(mySurf,pt2d.X(),pt2d.Y(),solpt,d1u,d1v);
55 //  gp_Vec norm(d1u.Crossed(d1v));
56   gp_Vec norm;
57   TheSurfProps::Normale(mySurf,pt2d.X(),pt2d.Y(),solpt,norm);
58
59   switch (myType) {
60   case Contap_ContourStd:
61     {
62       F = (norm.Dot(myDir))/myMean;
63     }
64     break;
65   case Contap_ContourPrs:
66     {
67       F = (norm.Dot(gp_Vec(myEye,solpt)))/myMean;
68     }
69     break;
70   case Contap_DraftStd:
71     {
72       F = (norm.Dot(myDir)-myCosAng*norm.Magnitude())/myMean;
73     }
74     break;
75   case Contap_DraftPrs:
76   default:
77     {
78     }
79   }
80   return Standard_True;
81 }
82
83
84 Standard_Boolean Contap_ArcFunction::Derivative (const Standard_Real U,
85                                                  Standard_Real& D)
86 {
87   gp_Pnt2d pt2d;
88   gp_Vec2d d2d;
89   Standard_Real dfu =0.,dfv =0.;
90 //  gp_Vec d1u,d1v,d2u,d2v,d2uv;
91   TheArcTool::D1(myArc,U,pt2d,d2d);
92 //  TheSurfaceTool::D2(mySurf,pt2d.X(),pt2d.Y(),solpt,d1u,d1v,d2u,d2v,d2uv);
93   gp_Vec norm,dnu,dnv;
94   TheSurfProps::NormAndDn(mySurf,pt2d.X(),pt2d.Y(),solpt,norm,dnu,dnv);
95
96   switch (myType) {
97   case Contap_ContourStd:
98     {
99 //      dfu = ((d2u.Crossed(d1v) + d1u.Crossed(d2uv)).Dot(myDir))/myMean;
100 //      dfv = ((d2uv.Crossed(d1v) + d1u.Crossed(d2v)).Dot(myDir))/myMean;
101       dfu = (dnu.Dot(myDir))/myMean;
102       dfv = (dnv.Dot(myDir))/myMean;
103     }
104     break;
105   case Contap_ContourPrs:
106     {
107       gp_Vec Ep(myEye,solpt);
108 //      dfu = ((d2u.Crossed(d1v) + d1u.Crossed(d2uv)).Dot(Ep))/myMean;
109 //      dfv = ((d2uv.Crossed(d1v) + d1u.Crossed(d2v)).Dot(Ep))/myMean;
110       dfu = (dnu.Dot(Ep))/myMean;
111       dfv = (dnv.Dot(Ep))/myMean;
112     }
113     break;
114   case Contap_DraftStd:
115     {
116 /*
117       gp_Vec norm(d1u.Crossed(d1v).Normalized());
118       gp_Vec dnorm(d2u.Crossed(d1v) + d1u.Crossed(d2uv));
119       dfu = (dnorm.Dot(myDir)-myCosAng*dnorm.Dot(norm))/myMean;
120       dnorm = d2uv.Crossed(d1v) + d1u.Crossed(d2v);
121       dfv = (dnorm.Dot(myDir)-myCosAng*dnorm.Dot(norm))/myMean;
122 */
123       norm.Normalized();
124       dfu = (dnu.Dot(myDir)-myCosAng*dnu.Dot(norm))/myMean;
125       dfv = (dnv.Dot(myDir)-myCosAng*dnv.Dot(norm))/myMean;
126     }
127     break;
128   case Contap_DraftPrs:
129   default:
130     {
131     }
132   }
133   D = d2d.X()*dfu + d2d.Y()*dfv;
134   return Standard_True;
135 }
136
137 Standard_Boolean Contap_ArcFunction::Values (const Standard_Real U,
138                                              Standard_Real& F,
139                                              Standard_Real& D)
140 {
141   gp_Pnt2d pt2d;
142   gp_Vec2d d2d;
143   Standard_Real dfu =0.,dfv =0.;
144 // gp_Vec d1u,d1v,d2u,d2v,d2uv;
145   TheArcTool::D1(myArc,U,pt2d,d2d);
146 //  TheSurfaceTool::D2(mySurf,pt2d.X(),pt2d.Y(),solpt,d1u,d1v,d2u,d2v,d2uv);
147 //  gp_Vec norm(d1u.Crossed(d1v));
148   gp_Vec norm,dnu,dnv;
149   TheSurfProps::NormAndDn(mySurf,pt2d.X(),pt2d.Y(),solpt,norm,dnu,dnv);
150
151   switch (myType) {
152   case Contap_ContourStd:
153     {
154       F   = (norm.Dot(myDir))/myMean;
155 //      dfu = ((d2u.Crossed(d1v) + d1u.Crossed(d2uv)).Dot(myDir))/myMean;
156 //      dfv = ((d2uv.Crossed(d1v) + d1u.Crossed(d2v)).Dot(myDir))/myMean;
157       dfu = (dnu.Dot(myDir))/myMean;
158       dfv = (dnv.Dot(myDir))/myMean;
159     }
160     break;
161   case Contap_ContourPrs:
162     {
163       gp_Vec Ep(myEye,solpt);
164       F   = (norm.Dot(Ep))/myMean;
165 //      dfu = ((d2u.Crossed(d1v) + d1u.Crossed(d2uv)).Dot(Ep))/myMean;
166 //      dfv = ((d2uv.Crossed(d1v) + d1u.Crossed(d2v)).Dot(Ep))/myMean;
167       dfu = (dnu.Dot(Ep))/myMean;
168       dfv = (dnv.Dot(Ep))/myMean;
169     }
170     break;
171   case Contap_DraftStd:
172     {
173       F = (norm.Dot(myDir)-myCosAng*norm.Magnitude())/myMean;
174       norm.Normalize();
175 /*
176       gp_Vec dnorm(d2u.Crossed(d1v) + d1u.Crossed(d2uv));
177       dfu = (dnorm.Dot(myDir)-myCosAng*dnorm.Dot(norm))/myMean;
178       dnorm = d2uv.Crossed(d1v) + d1u.Crossed(d2v);
179       dfv = (dnorm.Dot(myDir)-myCosAng*dnorm.Dot(norm))/myMean;
180 */
181       dfu = (dnu.Dot(myDir)-myCosAng*dnu.Dot(norm))/myMean;
182       dfv = (dnv.Dot(myDir)-myCosAng*dnv.Dot(norm))/myMean;
183     }
184     break;
185   case Contap_DraftPrs:
186   default:
187     {
188     }
189   }
190
191   D = d2d.X()*dfu + d2d.Y()*dfv;
192   return Standard_True;
193 }
194
195 Standard_Integer Contap_ArcFunction::GetStateNumber ()
196 {
197   seqpt.Append(solpt);
198   return seqpt.Length();
199 }
200
201 Standard_Integer Contap_ArcFunction::NbSamples () const
202 {
203   return Max(Max(TheContTool::NbSamplesU(mySurf,0.,0.),
204                  TheContTool::NbSamplesV(mySurf,0.,0.)),
205              TheContTool::NbSamplesOnArc(myArc));
206 }
207
208 //modified by NIZNHY-PKV Thu Mar 29 16:53:07 2001f
209 //=======================================================================
210 //function : Quadric
211 //purpose  : returns empty Quadric
212 //=======================================================================
213   const IntSurf_Quadric& Contap_ArcFunction::Quadric() const 
214
215   return(myQuad);
216 }
217 //modified by NIZNHY-PKV Thu Mar 29 16:53:09 2001t