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