0031035: Coding - uninitialized class fields reported by Visual Studio Code Analysis
[occt.git] / src / Extrema / Extrema_ExtSS.cxx
CommitLineData
b311480e 1// Created on: 1995-07-19
2// Created by: Modelistation
3// Copyright (c) 1995-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
7fd59977 17
42cf5bc1 18#include <Adaptor3d_Surface.hxx>
19#include <ElCLib.hxx>
20#include <Extrema_ExtSS.hxx>
21#include <Extrema_GenExtSS.hxx>
22#include <Extrema_POnSurf.hxx>
7fd59977 23#include <GeomAbs_SurfaceType.hxx>
7fd59977 24#include <gp_Pln.hxx>
42cf5bc1 25#include <gp_Pnt.hxx>
26#include <Precision.hxx>
42cf5bc1 27#include <Standard_OutOfRange.hxx>
42cf5bc1 28#include <StdFail_NotDone.hxx>
7fd59977 29
d533dafb 30Extrema_ExtSS::Extrema_ExtSS()
31: myS2(NULL),
32 myDone(Standard_False),
33 myIsPar(Standard_False),
34 myuinf1(0.0),
35 myusup1(0.0),
36 myvinf1(0.0),
37 myvsup1(0.0),
38 myuinf2(0.0),
39 myusup2(0.0),
40 myvinf2(0.0),
41 myvsup2(0.0),
42 mytolS1(0.0),
43 mytolS2(0.0),
44 myStype(GeomAbs_OtherSurface)
7fd59977 45{
7fd59977 46}
47
48Extrema_ExtSS::Extrema_ExtSS(const Adaptor3d_Surface& S1,
49 const Adaptor3d_Surface& S2,
50 const Standard_Real TolS1,
51 const Standard_Real TolS2)
52
53{
54 Initialize(S2, S2.FirstUParameter(),
55 S2.LastUParameter(),
56 S2.FirstVParameter(),
57 S2.LastVParameter(), TolS2);
58
59 Perform(S1, S1.FirstUParameter(),
60 S1.LastUParameter(),
61 S1.FirstVParameter(),
62 S1.LastVParameter(), TolS1);
63}
64
65Extrema_ExtSS::Extrema_ExtSS(const Adaptor3d_Surface& S1,
66 const Adaptor3d_Surface& S2,
67 const Standard_Real Uinf1,
68 const Standard_Real Usup1,
69 const Standard_Real Vinf1,
70 const Standard_Real Vsup1,
71 const Standard_Real Uinf2,
72 const Standard_Real Usup2,
73 const Standard_Real Vinf2,
74 const Standard_Real Vsup2,
75 const Standard_Real TolS1,
76 const Standard_Real TolS2)
77
78{
79 Initialize(S2, Uinf2, Usup2, Vinf2, Vsup2, TolS2);
80 Perform(S1, Uinf1, Usup1, Vinf1, Vsup1, TolS1);
81}
82
83
84void Extrema_ExtSS::Initialize(const Adaptor3d_Surface& S2,
85 const Standard_Real Uinf2,
86 const Standard_Real Usup2,
87 const Standard_Real Vinf2,
88 const Standard_Real Vsup2,
89 const Standard_Real TolS2)
90{
91 myS2 = (Adaptor3d_SurfacePtr)&S2;
92 myIsPar = Standard_False;
93 myuinf2 = Uinf2;
94 myusup2 = Usup2;
95 myvinf2 = Vinf2;
96 myvsup2 = Vsup2;
97 mytolS2 = TolS2;
98 myStype = S2.GetType();
99}
100
101
102void Extrema_ExtSS::Perform(const Adaptor3d_Surface& S1,
103 const Standard_Real Uinf1,
104 const Standard_Real Usup1,
105 const Standard_Real Vinf1,
106 const Standard_Real Vsup1,
107 const Standard_Real TolS1)
108{
109 myuinf1 = Uinf1;
110 myusup1 = Usup1;
111 myvinf1 = Vinf1;
112 myvsup1 = Vsup1;
113 mytolS1 = TolS1;
114 myPOnS1.Clear();
115 myPOnS2.Clear();
116 mySqDist.Clear();
117 Standard_Integer i;
118 GeomAbs_SurfaceType myS1type = S1.GetType();
5be09a15 119 const Standard_Integer NbU = 20, NbV = 20;
7fd59977 120
121 switch(myS1type) {
122
123 case GeomAbs_Plane:
124 {
125
126 switch(myStype) {
127 case GeomAbs_Plane:
128 {
129 myExtElSS.Perform(S1.Plane(),myS2->Plane());
130 }
131 break;
132 default:
133 {
134 Extrema_GenExtSS Ext(S1, *myS2, NbU, NbV, mytolS1, mytolS2);
135 myDone = Ext.IsDone();
136 if (myDone) {
137 Standard_Integer NbExt = Ext.NbExt();
138 Standard_Real U1, V1,U2,V2;
139 Extrema_POnSurf PS1;
140 Extrema_POnSurf PS2;
141 for (i = 1; i <= NbExt; i++) {
142 PS1 = Ext.PointOnS1(i);
143 PS2 = Ext.PointOnS2(i);
144 PS1.Parameter(U1, V1);
145 PS2.Parameter(U2, V2);
146 if (S1.IsUPeriodic())
147 U1 = ElCLib::InPeriod(U1, myuinf1, myuinf1+S1.UPeriod());
148 if (S1.IsVPeriodic())
149 V1 = ElCLib::InPeriod(V1, myvinf1, myvinf1+S1.VPeriod());
150 if (myS2->IsUPeriodic())
151 U2 = ElCLib::InPeriod(U2, myuinf2, myuinf2+myS2->UPeriod());
152 if (myS2->IsVPeriodic())
153 V2 = ElCLib::InPeriod(V2, myvinf2, myvinf2+myS2->VPeriod());
154
155 if ((myuinf1-U1) <= mytolS1 && (U1-myusup1) <= mytolS1 &&
156 (myvinf1-V1) <= mytolS1 && (V1-myvsup1) <= mytolS1 &&
157 (myuinf2-U2) <= mytolS2 && (U2-myusup2) <= mytolS2 &&
158 (myvinf2-V2) <= mytolS2 && (V2-myvsup2) <= mytolS2) {
159 mySqDist.Append(Ext.SquareDistance(i));
160 myPOnS1.Append(Extrema_POnSurf(U1, V1, PS1.Value()));
161 myPOnS2.Append(Extrema_POnSurf(U2, V2, PS2.Value()));
162 }
163 }
164 }
165 return;
166
167 }
168 break;
169 }
170 break;
171 }
172 default:
173 {
174 Extrema_GenExtSS Ext(S1, *myS2, NbU, NbV, mytolS1, mytolS2);
175 myDone = Ext.IsDone();
176 if (myDone) {
177 Standard_Integer NbExt = Ext.NbExt();
178 Standard_Real U1, V1,U2,V2;
179 Extrema_POnSurf PS1;
180 Extrema_POnSurf PS2;
181 for (i = 1; i <= NbExt; i++) {
182 PS1 = Ext.PointOnS1(i);
183 PS2 = Ext.PointOnS2(i);
184 PS1.Parameter(U1, V1);
185 PS2.Parameter(U2, V2);
186 if (S1.IsUPeriodic())
187 U1 = ElCLib::InPeriod(U1, myuinf1, myuinf1+S1.UPeriod());
188 if (S1.IsVPeriodic())
189 V1 = ElCLib::InPeriod(V1, myvinf1, myvinf1+S1.VPeriod());
190 if (myS2->IsUPeriodic())
191 U2 = ElCLib::InPeriod(U2, myuinf2, myuinf2+myS2->UPeriod());
192 if (myS2->IsVPeriodic())
193 V2 = ElCLib::InPeriod(V2, myvinf2, myvinf2+myS2->VPeriod());
194
195 if ((myuinf1-U1) <= mytolS1 && (U1-myusup1) <= mytolS1 &&
196 (myvinf1-V1) <= mytolS1 && (V1-myvsup1) <= mytolS1 &&
197 (myuinf2-U2) <= mytolS2 && (U2-myusup2) <= mytolS2 &&
198 (myvinf2-V2) <= mytolS2 && (V2-myvsup2) <= mytolS2) {
199 mySqDist.Append(Ext.SquareDistance(i));
200 myPOnS1.Append(Extrema_POnSurf(U1, V1, PS1.Value()));
201 myPOnS2.Append(Extrema_POnSurf(U2, V2, PS2.Value()));
202 }
203 }
204 }
205 return;
206
207 }
208 break;
209 }
210
211 myDone = myExtElSS.IsDone();
212 if (myDone) {
213 myIsPar = myExtElSS.IsParallel();
214 if (myIsPar) {
215 mySqDist.Append(myExtElSS.SquareDistance(1));
216 }
217 else {
218 Standard_Integer NbExt = myExtElSS.NbExt();
219 Standard_Real U1, V1, U2, V2;
220 Extrema_POnSurf PS1;
221 Extrema_POnSurf PS2;
222 for (i = 1; i <= NbExt; i++) {
223 myExtElSS.Points(i, PS1, PS2);
224 PS1.Parameter(U1, V1);
225 PS2.Parameter(U2, V2);
226 if ((myuinf1-U1) <= mytolS1 && (U1-myusup1) <= mytolS1 &&
227 (myvinf1-V1) <= mytolS1 && (V1-myvsup1) <= mytolS1 &&
228 (myuinf2-U2) <= mytolS2 && (U2-myusup2) <= mytolS2 &&
229 (myvinf2-V2) <= mytolS2 && (V2-myvsup2) <= mytolS2) {
230 mySqDist.Append(myExtElSS.SquareDistance(i));
231 myPOnS1.Append(PS1);
232 myPOnS2.Append(PS2);
233 }
234 }
235 }
236 }
237
238}
239
240
241Standard_Boolean Extrema_ExtSS::IsDone() const
242{
243 return myDone;
244}
245
246Standard_Boolean Extrema_ExtSS::IsParallel() const
247{
638ad7f3 248 if (!IsDone()) throw StdFail_NotDone();
7fd59977 249 return myIsPar;
250}
251
252
253Standard_Real Extrema_ExtSS::SquareDistance(const Standard_Integer N) const
254{
638ad7f3 255 if (N < 1 || N > NbExt())
256 {
257 throw Standard_OutOfRange();
258 }
259
7fd59977 260 return mySqDist.Value(N);
261}
262
263
264Standard_Integer Extrema_ExtSS::NbExt() const
265{
638ad7f3 266 if (!IsDone()) throw StdFail_NotDone();
7fd59977 267 return mySqDist.Length();
268}
269
270
271
272void Extrema_ExtSS::Points(const Standard_Integer N,
273 Extrema_POnSurf& P1,
274 Extrema_POnSurf& P2) const
275{
638ad7f3 276 if (N < 1 || N > NbExt())
277 {
278 throw Standard_OutOfRange();
279 }
280
7fd59977 281 P1 = myPOnS1.Value(N);
282 P2 = myPOnS2.Value(N);
283}