Commit | Line | Data |
---|---|---|
b311480e | 1 | // Copyright (c) 1996-1999 Matra Datavision |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS | |
3 | // | |
4 | // The content of this file is subject to the Open CASCADE Technology Public | |
5 | // License Version 6.5 (the "License"). You may not use the content of this file | |
6 | // except in compliance with the License. Please obtain a copy of the License | |
7 | // at http://www.opencascade.org and read it completely before using this file. | |
8 | // | |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
11 | // | |
12 | // The Original Code and all software distributed under the License is | |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
14 | // Initial Developer hereby disclaims all such warranties, including without | |
15 | // limitation, any warranties of merchantability, fitness for a particular | |
16 | // purpose or non-infringement. Please see the License for the specific terms | |
17 | // and conditions governing the rights and limitations under the License. | |
18 | ||
7fd59977 | 19 | #include <BndLib_Add3dCurve.ixx> |
20 | #include <GeomAbs_CurveType.hxx> | |
21 | #include <BndLib.hxx> | |
22 | #include <TColgp_Array1OfPnt.hxx> | |
23 | #include <gp_Pnt.hxx> | |
24 | #include <Geom_BezierCurve.hxx> | |
25 | #include <Geom_BSplineCurve.hxx> | |
26 | #include <gp_Lin.hxx> | |
27 | #include <gp_Circ.hxx> | |
28 | #include <gp_Elips.hxx> | |
29 | #include <gp_Parab.hxx> | |
30 | #include <gp_Hypr.hxx> | |
31 | #include <Precision.hxx> | |
32 | #include <TColStd_Array1OfReal.hxx> | |
33 | #include <TColStd_Array1OfInteger.hxx> | |
34 | ||
35 | #include <ElCLib.hxx> | |
36 | ||
37 | #include <gp_Pnt.hxx> | |
38 | #include <GeomAdaptor_Curve.hxx> | |
39 | ||
40 | //======================================================================= | |
41 | //function : Add | |
42 | //purpose : | |
43 | //======================================================================= | |
44 | ||
45 | void BndLib_Add3dCurve::Add( const Adaptor3d_Curve& C, | |
46 | const Standard_Real Tol, | |
47 | Bnd_Box& B ) | |
48 | { | |
49 | BndLib_Add3dCurve::Add(C, | |
50 | C.FirstParameter(), | |
51 | C.LastParameter (), | |
52 | Tol,B); | |
53 | } | |
54 | ||
55 | //OCC566(apo)-> | |
56 | static Standard_Real FillBox(Bnd_Box& B, const Adaptor3d_Curve& C, | |
57 | const Standard_Real first, const Standard_Real last, | |
58 | const Standard_Integer N) | |
59 | { | |
60 | gp_Pnt P1, P2, P3; | |
61 | C.D0(first,P1); B.Add(P1); | |
62 | Standard_Real p = first, dp = last-first, tol= 0.; | |
63 | if(Abs(dp) > Precision::PConfusion()){ | |
64 | Standard_Integer i; | |
65 | dp /= 2*N; | |
66 | for(i = 1; i <= N; i++){ | |
67 | p += dp; C.D0(p,P2); B.Add(P2); | |
68 | p += dp; C.D0(p,P3); B.Add(P3); | |
69 | gp_Pnt Pc((P1.XYZ()+P3.XYZ())/2.0); | |
70 | tol = Max(tol,Pc.Distance(P2)); | |
71 | P1 = P3; | |
72 | } | |
73 | }else{ | |
74 | C.D0(first,P1); B.Add(P1); | |
75 | C.D0(last,P3); B.Add(P3); | |
76 | tol = 0.; | |
77 | } | |
78 | return tol; | |
79 | } | |
80 | //<-OCC566(apo) | |
81 | //======================================================================= | |
82 | //function : Add | |
83 | //purpose : | |
84 | //======================================================================= | |
85 | ||
86 | void BndLib_Add3dCurve::Add( const Adaptor3d_Curve& C, | |
87 | const Standard_Real U1, | |
88 | const Standard_Real U2, | |
89 | const Standard_Real Tol, | |
90 | Bnd_Box& B ) | |
91 | { | |
92 | static Standard_Real weakness = 1.5; //OCC566(apo) | |
93 | Standard_Real tol = 0.0; | |
94 | switch (C.GetType()) { | |
95 | ||
96 | case GeomAbs_Line: | |
97 | { | |
98 | BndLib::Add(C.Line(),U1,U2,Tol,B); | |
99 | break; | |
100 | } | |
101 | case GeomAbs_Circle: | |
102 | { | |
103 | BndLib::Add(C.Circle(),U1,U2,Tol,B); | |
104 | break; | |
105 | } | |
106 | case GeomAbs_Ellipse: | |
107 | { | |
108 | BndLib::Add(C.Ellipse(),U1,U2,Tol,B); | |
109 | break; | |
110 | } | |
111 | case GeomAbs_Hyperbola: | |
112 | { | |
113 | BndLib::Add(C.Hyperbola(),U1,U2,Tol,B); | |
114 | break; | |
115 | } | |
116 | case GeomAbs_Parabola: | |
117 | { | |
118 | BndLib::Add(C.Parabola(),U1,U2,Tol,B); | |
119 | break; | |
120 | } | |
121 | case GeomAbs_BezierCurve: | |
122 | { | |
123 | Handle(Geom_BezierCurve) Bz = C.Bezier(); | |
124 | //OCC566(apo)-> | |
125 | Standard_Integer N = Bz->Degree(); | |
126 | GeomAdaptor_Curve GACurve(Bz); | |
127 | Bnd_Box B1; | |
128 | tol = FillBox(B1,GACurve,U1,U2,N); | |
129 | B1.Enlarge(weakness*tol); | |
130 | Standard_Real x, y, z, X, Y, Z; | |
131 | B1.Get(x, y, z, X, Y, Z); | |
132 | B.Update(x, y, z, X, Y, Z); | |
133 | B.Enlarge(Tol); | |
134 | //<-OCC566(apo) | |
135 | break; | |
136 | } | |
137 | case GeomAbs_BSplineCurve: | |
138 | { | |
139 | Handle(Geom_BSplineCurve) Bs = C.BSpline(); | |
140 | if(Abs(Bs->FirstParameter() - U1) > Precision::Parametric(Tol)|| | |
141 | Abs(Bs->LastParameter() - U2) > Precision::Parametric(Tol)) { | |
142 | ||
143 | Handle(Geom_Geometry) G = Bs->Copy(); | |
144 | Handle(Geom_BSplineCurve)& Bsaux = (*((Handle(Geom_BSplineCurve)*)&G)); | |
145 | Standard_Real u1 = U1, u2 = U2; | |
146 | //// modified by jgv, 24.10.01 for BUC61031 //// | |
147 | if (Bsaux->IsPeriodic()) | |
148 | ElCLib::AdjustPeriodic( Bsaux->FirstParameter(), Bsaux->LastParameter(), Precision::PConfusion(), u1, u2 ); | |
1bd657ae | 149 | else { |
253881cf | 150 | //////////////////////////////////////////////// |
151 | // modified by NIZHNY-EAP Fri Dec 3 14:29:14 1999 ___BEGIN___ | |
152 | // To avoid exeption in Segment | |
153 | if(Bsaux->FirstParameter() > U1) u1 = Bsaux->FirstParameter(); | |
154 | if(Bsaux->LastParameter() < U2 ) u2 = Bsaux->LastParameter(); | |
155 | // modified by NIZHNY-EAP Fri Dec 3 14:29:18 1999 ___END___ | |
1bd657ae | 156 | } |
7fd59977 | 157 | Bsaux->Segment(u1, u2); |
158 | Bs = Bsaux; | |
159 | } | |
160 | //OCC566(apo)-> | |
161 | Bnd_Box B1; | |
162 | Standard_Integer k, k1 = Bs->FirstUKnotIndex(), k2 = Bs->LastUKnotIndex(), | |
163 | N = Bs->Degree(), NbKnots = Bs->NbKnots(); | |
164 | TColStd_Array1OfReal Knots(1,NbKnots); | |
165 | Bs->Knots(Knots); | |
166 | GeomAdaptor_Curve GACurve(Bs); | |
167 | Standard_Real first = Knots(k1), last; | |
168 | for(k = k1 + 1; k <= k2; k++){ | |
169 | last = Knots(k); | |
170 | tol = Max(FillBox(B1,GACurve,first,last,N), tol); | |
171 | first = last; | |
172 | } | |
44fb70f2 M |
173 | if (!B1.IsVoid()) |
174 | { | |
175 | B1.Enlarge(weakness*tol); | |
176 | Standard_Real x, y, z, X, Y, Z; | |
177 | B1.Get(x, y, z, X, Y, Z); | |
178 | B.Update(x, y, z, X, Y, Z); | |
179 | B.Enlarge(Tol); | |
180 | } | |
7fd59977 | 181 | //<-OCC566(apo) |
182 | break; | |
183 | } | |
184 | default: | |
185 | { | |
186 | Bnd_Box B1; | |
187 | static Standard_Integer N = 33; | |
188 | tol = FillBox(B1,C,U1,U2,N); | |
189 | B1.Enlarge(weakness*tol); | |
190 | Standard_Real x, y, z, X, Y, Z; | |
191 | B1.Get(x, y, z, X, Y, Z); | |
192 | B.Update(x, y, z, X, Y, Z); | |
193 | B.Enlarge(Tol); | |
194 | } | |
195 | } | |
196 | } |