b311480e |
1 | // Created on: 1994-02-23 |
2 | // Created by: Laurent BOURESCHE |
3 | // Copyright (c) 1994-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 | |
42cf5bc1 |
17 | |
7fd59977 |
18 | #include <Geom_BSplineCurve.hxx> |
42cf5bc1 |
19 | #include <Geom_Curve.hxx> |
20 | #include <Geom_TrimmedCurve.hxx> |
21 | #include <GeomAbs_Shape.hxx> |
22 | #include <GeomLProp.hxx> |
7fd59977 |
23 | #include <GeomLProp_CLProps.hxx> |
24 | #include <gp_Dir.hxx> |
25 | #include <gp_Vec.hxx> |
42cf5bc1 |
26 | #include <Precision.hxx> |
7fd59977 |
27 | |
e83d440f |
28 | static Standard_Integer GeomAbsToInteger(const GeomAbs_Shape gcont) |
7fd59977 |
29 | { |
30 | Standard_Integer cont=0 ; |
31 | switch (gcont) { |
32 | case GeomAbs_C0 : |
33 | cont = 0 ; |
34 | break ; |
35 | case GeomAbs_G1 : |
36 | cont = 1 ; |
37 | break ; |
38 | case GeomAbs_C1 : |
39 | cont = 2 ; |
40 | break ; |
41 | case GeomAbs_G2 : |
42 | cont = 3 ; |
43 | break ; |
44 | case GeomAbs_C2 : |
45 | cont = 4 ; |
46 | break ; |
47 | case GeomAbs_C3 : |
48 | cont = 5 ; |
49 | break ; |
50 | case GeomAbs_CN : |
51 | cont = 6 ; |
52 | break ; |
53 | } |
54 | return cont ; |
55 | } |
56 | //======================================================================= |
57 | //function : Continuity |
58 | //purpose : |
59 | //======================================================================= |
60 | |
61 | GeomAbs_Shape GeomLProp::Continuity(const Handle(Geom_Curve)& C1, |
62 | const Handle(Geom_Curve)& C2, |
63 | const Standard_Real u1, |
64 | const Standard_Real u2, |
65 | const Standard_Boolean r1, |
66 | const Standard_Boolean r2, |
67 | const Standard_Real tl, |
68 | const Standard_Real ta) |
69 | { |
70 | GeomAbs_Shape cont = GeomAbs_C0; |
71 | Standard_Integer index1, |
72 | index2 ; |
73 | Standard_Real tolerance ; |
74 | Standard_Boolean fini = Standard_False; |
75 | gp_Vec d1,d2; |
76 | gp_Dir dir1,dir2; |
77 | Standard_Integer cont1, cont2 ; |
78 | GeomAbs_Shape gcont1 = C1->Continuity(), gcont2 = C2->Continuity(); |
79 | cont1 = GeomAbsToInteger(gcont1) ; |
80 | cont2 = GeomAbsToInteger(gcont2) ; |
81 | |
82 | Handle(Geom_Curve) aCurve1 = C1 ; |
83 | Handle(Geom_Curve) aCurve2 = C2 ; |
84 | if (C1->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))){ |
85 | Handle(Geom_TrimmedCurve) aTrimmed = |
86 | Handle(Geom_TrimmedCurve) ::DownCast(aCurve1) ; |
87 | aCurve1 = aTrimmed->BasisCurve() ; |
88 | } |
89 | if (C2->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))){ |
90 | Handle(Geom_TrimmedCurve) aTrimmed = |
91 | Handle(Geom_TrimmedCurve) ::DownCast(aCurve2) ; |
92 | aCurve2 = aTrimmed->BasisCurve() ; |
93 | } |
94 | if (aCurve1->IsKind(STANDARD_TYPE(Geom_BSplineCurve))){ |
95 | Handle(Geom_BSplineCurve) BSplineCurve = |
96 | Handle(Geom_BSplineCurve)::DownCast(aCurve1) ; |
97 | BSplineCurve->Resolution(tl, |
98 | tolerance) ; |
99 | BSplineCurve->LocateU( |
100 | u1, |
101 | tolerance, |
102 | index1, |
103 | index2) ; |
104 | |
105 | if (index1 > 1 && index2 < BSplineCurve->NbKnots() && index1 == index2) { |
106 | cont1 = BSplineCurve->Degree() - BSplineCurve->Multiplicity(index1) ; |
107 | } |
108 | else { |
109 | cont1 = 5 ; |
110 | } |
111 | } |
112 | if (aCurve2->IsKind(STANDARD_TYPE(Geom_BSplineCurve))){ |
113 | Handle(Geom_BSplineCurve) BSplineCurve = |
114 | Handle(Geom_BSplineCurve)::DownCast(aCurve2) ; |
115 | BSplineCurve->Resolution(tl, |
116 | tolerance) ; |
117 | BSplineCurve->LocateU( |
118 | u2, |
119 | tolerance, |
120 | index1, |
121 | index2) ; |
122 | |
123 | if (index1 > 1 && index2 < BSplineCurve->NbKnots() && index1 == index2) { |
124 | cont2 = BSplineCurve->Degree() - BSplineCurve->Multiplicity(index1) ; |
125 | } |
126 | else { |
127 | cont2 = 5 ; |
128 | } |
129 | } |
130 | Standard_Integer n1 = 0, n2 = 0; |
131 | if (cont1 >= 5) n1 = 3; |
132 | else if(cont1 == 4) n1 = 2; |
133 | else if(cont1 == 2) n1 = 1; |
134 | if (cont2 >= 5) n2 = 3; |
135 | else if(cont2 == 4) n2 = 2; |
136 | else if(cont2 == 2) n2 = 1; |
137 | GeomLProp_CLProps clp1(C1,u1,n1,tl); |
138 | GeomLProp_CLProps clp2(C2,u2,n2,tl); |
139 | if(!(clp1.Value().IsEqual(clp2.Value(),tl))) { |
9775fa61 |
140 | throw Standard_Failure("Courbes non jointives"); |
7fd59977 |
141 | } |
142 | Standard_Integer min = Min(n1,n2); |
143 | if ( min >= 1 ) { |
144 | d1 = clp1.D1(); |
145 | d2 = clp2.D1(); |
146 | if(r1) d1.Reverse(); |
147 | if(r2) d2.Reverse(); |
148 | if(d1.IsEqual(d2,tl,ta)) { |
149 | cont = GeomAbs_C1; |
150 | } |
151 | else if(clp1.IsTangentDefined() && clp2.IsTangentDefined()){ |
152 | clp1.Tangent(dir1); |
153 | clp2.Tangent(dir2); |
154 | if(r1) dir1.Reverse(); |
155 | if(r2) dir2.Reverse(); |
156 | if(dir1.IsEqual(dir2,ta)){ |
157 | cont = GeomAbs_G1; |
158 | } |
159 | fini = Standard_True; |
160 | } |
161 | else {fini = Standard_True; } |
162 | } |
163 | if ( min >= 2 && !fini ) { |
164 | d1 = clp1.D2(); |
165 | d2 = clp2.D2(); |
166 | if(d1.IsEqual(d2,tl,ta)){ |
167 | cont = GeomAbs_C2; |
168 | } |
169 | } |
170 | return cont; |
171 | } |
172 | |
173 | |
174 | //======================================================================= |
175 | //function : Continuity |
176 | //purpose : |
177 | //======================================================================= |
178 | |
179 | GeomAbs_Shape GeomLProp::Continuity(const Handle(Geom_Curve)& C1, |
180 | const Handle(Geom_Curve)& C2, |
181 | const Standard_Real u1, |
182 | const Standard_Real u2, |
183 | const Standard_Boolean r1, |
184 | const Standard_Boolean r2) |
185 | { |
186 | return Continuity(C1,C2,u1,u2,r1,r2, |
187 | Precision::Confusion(),Precision::Angular()); |
188 | } |