0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[occt.git] / src / LocalAnalysis / LocalAnalysis_CurveContinuity.cxx
CommitLineData
b311480e 1// Copyright (c) 1996-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
42cf5bc1 15
16#include <Geom_Curve.hxx>
7fd59977 17#include <GeomLProp_CLProps.hxx>
18#include <gp.hxx>
42cf5bc1 19#include <gp_Dir.hxx>
7fd59977 20#include <gp_Pnt.hxx>
21#include <gp_Vec.hxx>
42cf5bc1 22#include <LocalAnalysis_CurveContinuity.hxx>
23#include <LocalAnalysis_StatusErrorType.hxx>
7fd59977 24#include <StdFail_NotDone.hxx>
25
7fd59977 26/***********************************************************************/
27void LocalAnalysis_CurveContinuity::CurvC0( GeomLProp_CLProps& Curv1,
28 GeomLProp_CLProps& Curv2)
29{ myContC0= (Curv1.Value()).Distance(Curv2.Value());
30}
31
32/****************************************************************************/
33void LocalAnalysis_CurveContinuity::CurvC1( GeomLProp_CLProps& Curv1,
34 GeomLProp_CLProps& Curv2)
35{ gp_Vec V1, V2;
36 Standard_Real ang;
37 V1 = Curv1.D1();
38 V2 = Curv2.D1();
39 Standard_Real norm1,norm2;
40 norm1 = V1.Magnitude();
41 norm2 = V2.Magnitude();
42
43 if ((norm1>myepsnul)&&(norm2>myepsnul))
44 { if ( norm1 >= norm2 )
45 { myLambda1 = norm2 / norm1;}
46 else { myLambda1 = norm1 / norm2;}
47 ang= V1.Angle(V2);
c6541a0c 48 if (ang>M_PI/2) myContC1=M_PI-ang;
7fd59977 49 else myContC1=ang;
50 }
51 else {myIsDone= Standard_False;
52 myErrorStatus=LocalAnalysis_NullFirstDerivative;}
53}
54
55/*********************************************************************************/
56
57void LocalAnalysis_CurveContinuity::CurvC2(GeomLProp_CLProps& Curv1,
58 GeomLProp_CLProps& Curv2)
59{ gp_Vec V1, V2, V12, V22;
60// gp_Dir D1, D2;
61 Standard_Real norm1, norm2, norm12, norm22,ang;
62 V1 = Curv1.D1();
63 V2 = Curv2.D1();
64 V12 = Curv1.D2();
65 V22 = Curv2.D2();
66 norm1 = V1.Magnitude();
67 norm2 = V2.Magnitude();
68 norm12 = V12.Magnitude();
69 norm22 = V22.Magnitude();
70
71 if ((norm1>myepsnul)&&(norm2>myepsnul))
72 {if((norm12>myepsnul)&&(norm22>myepsnul))
73 {if (norm1 >= norm2 )
74 { myLambda1 = norm2 / norm1;
75 myLambda2 = norm22 / norm12;}
76
77 else {myLambda1 = norm1 / norm2;
78 myLambda2 = norm12 / norm22;}
79 ang=V12.Angle(V22);
c6541a0c 80 if (ang>M_PI/2) myContC2=M_PI-ang;
7fd59977 81 else myContC2=ang; }
82
83 else{myIsDone= Standard_False ;
84 myErrorStatus=LocalAnalysis_NullSecondDerivative;} }
85
86 else {myIsDone= Standard_False ;
87 myErrorStatus=LocalAnalysis_NullFirstDerivative;}
88}
89
90/*********************************************************************************/
91
92void LocalAnalysis_CurveContinuity::CurvG1 ( GeomLProp_CLProps& Curv1,
93 GeomLProp_CLProps & Curv2)
94{ gp_Dir Tang1,Tang2;
95 Standard_Real ang;
96 if (Curv1.IsTangentDefined() && Curv2.IsTangentDefined ())
97 { Curv1.Tangent(Tang1);
98 Curv2.Tangent(Tang2);
99 ang=Tang1.Angle(Tang2);
c6541a0c 100 if (ang>M_PI/2) myContG1=M_PI-ang;
7fd59977 101 else myContG1=ang;
102 }
103 else {myIsDone= Standard_False ;
104 myErrorStatus=LocalAnalysis_TangentNotDefined;}
105}
106
107/*********************************************************************************/
108
109void LocalAnalysis_CurveContinuity::CurvG2( GeomLProp_CLProps& Curv1,
110 GeomLProp_CLProps & Curv2 )
111{ gp_Vec V1, V2;
112 gp_Dir D1, D2;
113 Standard_Real ang;
114 Standard_Real epscrb= 8*myepsC0/(myMaxLon*myMaxLon);
115
116 if (Curv1.IsTangentDefined() && Curv2.IsTangentDefined())
117 { myCourbC1= Curv1.Curvature();
118 myCourbC2 = Curv2.Curvature();
119 if( (Abs(myCourbC1)>epscrb)&& (Abs(myCourbC2)>epscrb))
120 { V1 = Curv1.D1();
121 V2 = Curv2.D1();
122 Curv1.Normal(D1);
123 Curv2.Normal(D2);
124 ang =D1.Angle(D2);
c6541a0c 125 if (ang>M_PI/2) myContG2=M_PI-ang;
7fd59977 126 else myContG2=ang;
127 myCourbC1= Curv1.Curvature();
128 myCourbC2 = Curv2.Curvature();
129 myG2Variation= Abs(myCourbC1-myCourbC2) / sqrt (myCourbC1* myCourbC2);}
130 else {myIsDone = Standard_False ;
131 myErrorStatus=LocalAnalysis_NormalNotDefined; }
132 }
133 else { myIsDone = Standard_False ;
134 myErrorStatus=LocalAnalysis_TangentNotDefined;}
135}
136
137/*********************************************************************************/
138
139LocalAnalysis_CurveContinuity::LocalAnalysis_CurveContinuity(const Handle(Geom_Curve)& Curv1,
140 const Standard_Real u1, const Handle(Geom_Curve)& Curv2, const Standard_Real u2,
141 const GeomAbs_Shape Order,
142 const Standard_Real Epsnul,
143 const Standard_Real EpsC0,
144 const Standard_Real EpsC1,
145 const Standard_Real EpsC2,
146 const Standard_Real EpsG1,
147 const Standard_Real EpsG2,
148 const Standard_Real Percent,
149 const Standard_Real Maxlen )
150{ myTypeCont = Order;
151 myepsnul= Epsnul;
152 myMaxLon=Maxlen;
153 myepsC0= EpsC0;
154 myepsC1= EpsC1;
155 myepsC2= EpsC2;
156 myepsG1= EpsG1;
157 myepsG2= EpsG2;
158 myperce=Percent;
159
160 myIsDone = Standard_True;
161
162 switch ( Order)
163 { case GeomAbs_C0 : { //TypeCont=GeomAbs_C0;
164 GeomLProp_CLProps Curve1 ( Curv1, u1, 0, myepsnul);
165 GeomLProp_CLProps Curve2 ( Curv2, u2, 0, myepsnul);
166 CurvC0(Curve1, Curve2);}
167 break;
168 case GeomAbs_C1 : { //TypeCont=GeomAbs_C1;
169
170 GeomLProp_CLProps Curve1 ( Curv1, u1, 1, myepsnul);
171 GeomLProp_CLProps Curve2 ( Curv2, u2, 1, myepsnul );
172 CurvC0(Curve1, Curve2);
173 CurvC1(Curve1, Curve2);}
174 break;
175 case GeomAbs_C2 : { //TypeCont=GeomAbs_C2;
176
177 GeomLProp_CLProps Curve1 ( Curv1, u1, 2, myepsnul);
178 GeomLProp_CLProps Curve2 ( Curv2, u2, 2, myepsnul);
179 CurvC0(Curve1, Curve2);
180 CurvC1(Curve1, Curve2);
181 CurvC2(Curve1, Curve2);}
182 break;
183 case GeomAbs_G1 : { //TypeCont=GeomAbs_G1;
184 GeomLProp_CLProps Curve1 ( Curv1, u1, 1, myepsnul);
185 GeomLProp_CLProps Curve2 ( Curv2, u2, 1, myepsnul);
186 CurvC0(Curve1, Curve2);
187 CurvG1(Curve1, Curve2);}
188 break;
189 case GeomAbs_G2 : { //TypeCont=GeomAbs_G2;
190 GeomLProp_CLProps Curve1 ( Curv1, u1, 2, myepsnul);
191 GeomLProp_CLProps Curve2 ( Curv2, u2, 2, myepsnul);
192 CurvC0(Curve1, Curve2);
193 CurvG1(Curve1, Curve2);
194 CurvG2(Curve1, Curve2);}
195 break;
196 default : {}
197 }
198}
199
200/*********************************************************************************/
201
202Standard_Boolean LocalAnalysis_CurveContinuity::IsC0() const
203{
9775fa61 204 if (!myIsDone) { throw StdFail_NotDone();}
7fd59977 205 if (myContC0 <= myepsC0 )
206 return Standard_True;
207 else return Standard_False;
208}
209
210/*********************************************************************************/
211
212Standard_Boolean LocalAnalysis_CurveContinuity::IsC1() const
213{
9775fa61 214 if (!myIsDone) { throw StdFail_NotDone();}
c6541a0c 215 if ( IsC0() && ( (myContC1 <= myepsC1)||(Abs(myContC1-M_PI)<=myepsC1)))
7fd59977 216 return Standard_True;
217 else return Standard_False;
218}
219
220/*********************************************************************************/
221
222Standard_Boolean LocalAnalysis_CurveContinuity::IsC2() const
223{ Standard_Real epsil1, epsil2;
224
9775fa61 225 if (!myIsDone) { throw StdFail_NotDone();}
7fd59977 226 if ( IsC1())
c6541a0c 227 { if ((myContC2 <= myepsC2)||(Abs(myContC2-M_PI)<=myepsC2))
7fd59977 228 { epsil1 = 0.5*myepsC1*myepsC1*myLambda1;
229 epsil2 = 0.5*myepsC2*myepsC2*myLambda2;
230 if ( (Abs(myLambda1*myLambda1-myLambda2)) <= (epsil1*epsil1+epsil2))
231 return Standard_True;}
232 else return Standard_False;
233 }
234 return Standard_False;
235
236}
237
238
239/*********************************************************************************/
240
241Standard_Boolean LocalAnalysis_CurveContinuity::IsG1() const
242{
9775fa61 243 if (!myIsDone) { throw StdFail_NotDone();}
c6541a0c 244 if ( IsC0() && (( myContG1 <= myepsG1||(Abs(myContG1-M_PI)<=myepsG1))))
7fd59977 245 return Standard_True;
246 else return Standard_False;
247}
248
249/*********************************************************************************/
250
251Standard_Boolean LocalAnalysis_CurveContinuity::IsG2()const
252{ Standard_Real CRBINF, CRBNUL;
253 Standard_Integer IETA1, IETA2;
254 // etat des coubures IETA. -> 0 Crbure nulle
255 // -> 1 Crbure finie
256 // -> 2 Crbure infinie
257
9775fa61 258 if (!myIsDone) { throw StdFail_NotDone();}
7fd59977 259 if ( IsG1 ())
260 { CRBINF = 1/myepsC0;
261 CRBNUL = 8*myepsC0/(myMaxLon*myMaxLon);
262
263 if (myCourbC1 > CRBINF) IETA1=2;
264 else if (myCourbC1 < CRBNUL) IETA1=0;
265 else IETA1=1;
266 if (myCourbC2 > CRBINF) IETA2=2;
267 else if (myCourbC2 < CRBNUL) IETA2=0;
268 else IETA2=1;
269 if (IETA1 == IETA2)
270 { if (IETA1 == 1)
c6541a0c 271 { Standard_Real eps= RealPart( (myContG2+myepsG2)/M_PI) * M_PI;
7fd59977 272 if (Abs( eps - myepsG2) < myepsG2)
273 {if (myG2Variation < myperce )
274 return Standard_True;
275 else return Standard_False;}
276 else return Standard_False;
277 }
278 else return Standard_True;
279 }
280 else return Standard_False;
281 }
282 else return Standard_False;
283}
284
285/*********************************************************************************/
286
287Standard_Real LocalAnalysis_CurveContinuity::C0Value() const
288{
9775fa61 289 if (!myIsDone) {throw StdFail_NotDone();}
7fd59977 290 return ( myContC0 );
291}
292
293/*********************************************************************************/
294
295Standard_Real LocalAnalysis_CurveContinuity::C1Angle() const
296{
9775fa61 297 if (!myIsDone) { throw StdFail_NotDone();}
7fd59977 298 return ( myContC1 );
299}
300
301/*********************************************************************************/
302
303Standard_Real LocalAnalysis_CurveContinuity::C2Angle() const
304{
9775fa61 305 if (!myIsDone) { throw StdFail_NotDone();}
7fd59977 306 return ( myContC2 );
307}
308
309/*********************************************************************************/
310
311Standard_Real LocalAnalysis_CurveContinuity::G1Angle() const
312{
9775fa61 313 if (!myIsDone) { throw StdFail_NotDone();}
7fd59977 314 return ( myContG1 );
315}
316/*********************************************************************************/
317
318Standard_Real LocalAnalysis_CurveContinuity::G2Angle() const
319{
9775fa61 320 if (!myIsDone) { throw StdFail_NotDone();}
7fd59977 321 return ( myContG2 );
322}
323
324
325
326/*********************************************************************************/
327
328Standard_Real LocalAnalysis_CurveContinuity::C1Ratio() const
329{
9775fa61 330 if (!myIsDone) {throw StdFail_NotDone();}
7fd59977 331 return ( myLambda1 );
332}
333
334/*********************************************************************************/
335
336Standard_Real LocalAnalysis_CurveContinuity::C2Ratio() const
337{
9775fa61 338 if (!myIsDone) {throw StdFail_NotDone();}
7fd59977 339 return ( myLambda2 );
340}
341
342/********************************************************************************/
343Standard_Real LocalAnalysis_CurveContinuity::G2CurvatureVariation() const
344{
9775fa61 345 if (!myIsDone) {throw StdFail_NotDone();}
7fd59977 346 return ( myG2Variation);
347}
348
349
350/********************************************************************************/
351
352Standard_Boolean LocalAnalysis_CurveContinuity::IsDone() const
353{ return ( myIsDone );
354}
355
356/*********************************************************************************/
357
358LocalAnalysis_StatusErrorType LocalAnalysis_CurveContinuity::StatusError() const
359{
360return myErrorStatus;
361}
362/*************************************************************************/
363GeomAbs_Shape LocalAnalysis_CurveContinuity::ContinuityStatus() const
364{
9775fa61 365 if (!myIsDone) { throw StdFail_NotDone();}
7fd59977 366 return (myTypeCont);
367}
368/*********************************************************************************/
369
370
371
372
373
374
375
376
377
378