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