7fd59977 |
1 | #include <BndLib_Add3dCurve.ixx> |
2 | #include <GeomAbs_CurveType.hxx> |
3 | #include <BndLib.hxx> |
4 | #include <TColgp_Array1OfPnt.hxx> |
5 | #include <gp_Pnt.hxx> |
6 | #include <Geom_BezierCurve.hxx> |
7 | #include <Geom_BSplineCurve.hxx> |
8 | #include <gp_Lin.hxx> |
9 | #include <gp_Circ.hxx> |
10 | #include <gp_Elips.hxx> |
11 | #include <gp_Parab.hxx> |
12 | #include <gp_Hypr.hxx> |
13 | #include <Precision.hxx> |
14 | #include <TColStd_Array1OfReal.hxx> |
15 | #include <TColStd_Array1OfInteger.hxx> |
16 | |
17 | #include <ElCLib.hxx> |
18 | |
19 | #include <gp_Pnt.hxx> |
20 | #include <GeomAdaptor_Curve.hxx> |
21 | |
22 | //======================================================================= |
23 | //function : Add |
24 | //purpose : |
25 | //======================================================================= |
26 | |
27 | void BndLib_Add3dCurve::Add( const Adaptor3d_Curve& C, |
28 | const Standard_Real Tol, |
29 | Bnd_Box& B ) |
30 | { |
31 | BndLib_Add3dCurve::Add(C, |
32 | C.FirstParameter(), |
33 | C.LastParameter (), |
34 | Tol,B); |
35 | } |
36 | |
37 | //OCC566(apo)-> |
38 | static Standard_Real FillBox(Bnd_Box& B, const Adaptor3d_Curve& C, |
39 | const Standard_Real first, const Standard_Real last, |
40 | const Standard_Integer N) |
41 | { |
42 | gp_Pnt P1, P2, P3; |
43 | C.D0(first,P1); B.Add(P1); |
44 | Standard_Real p = first, dp = last-first, tol= 0.; |
45 | if(Abs(dp) > Precision::PConfusion()){ |
46 | Standard_Integer i; |
47 | dp /= 2*N; |
48 | for(i = 1; i <= N; i++){ |
49 | p += dp; C.D0(p,P2); B.Add(P2); |
50 | p += dp; C.D0(p,P3); B.Add(P3); |
51 | gp_Pnt Pc((P1.XYZ()+P3.XYZ())/2.0); |
52 | tol = Max(tol,Pc.Distance(P2)); |
53 | P1 = P3; |
54 | } |
55 | }else{ |
56 | C.D0(first,P1); B.Add(P1); |
57 | C.D0(last,P3); B.Add(P3); |
58 | tol = 0.; |
59 | } |
60 | return tol; |
61 | } |
62 | //<-OCC566(apo) |
63 | //======================================================================= |
64 | //function : Add |
65 | //purpose : |
66 | //======================================================================= |
67 | |
68 | void BndLib_Add3dCurve::Add( const Adaptor3d_Curve& C, |
69 | const Standard_Real U1, |
70 | const Standard_Real U2, |
71 | const Standard_Real Tol, |
72 | Bnd_Box& B ) |
73 | { |
74 | static Standard_Real weakness = 1.5; //OCC566(apo) |
75 | Standard_Real tol = 0.0; |
76 | switch (C.GetType()) { |
77 | |
78 | case GeomAbs_Line: |
79 | { |
80 | BndLib::Add(C.Line(),U1,U2,Tol,B); |
81 | break; |
82 | } |
83 | case GeomAbs_Circle: |
84 | { |
85 | BndLib::Add(C.Circle(),U1,U2,Tol,B); |
86 | break; |
87 | } |
88 | case GeomAbs_Ellipse: |
89 | { |
90 | BndLib::Add(C.Ellipse(),U1,U2,Tol,B); |
91 | break; |
92 | } |
93 | case GeomAbs_Hyperbola: |
94 | { |
95 | BndLib::Add(C.Hyperbola(),U1,U2,Tol,B); |
96 | break; |
97 | } |
98 | case GeomAbs_Parabola: |
99 | { |
100 | BndLib::Add(C.Parabola(),U1,U2,Tol,B); |
101 | break; |
102 | } |
103 | case GeomAbs_BezierCurve: |
104 | { |
105 | Handle(Geom_BezierCurve) Bz = C.Bezier(); |
106 | //OCC566(apo)-> |
107 | Standard_Integer N = Bz->Degree(); |
108 | GeomAdaptor_Curve GACurve(Bz); |
109 | Bnd_Box B1; |
110 | tol = FillBox(B1,GACurve,U1,U2,N); |
111 | B1.Enlarge(weakness*tol); |
112 | Standard_Real x, y, z, X, Y, Z; |
113 | B1.Get(x, y, z, X, Y, Z); |
114 | B.Update(x, y, z, X, Y, Z); |
115 | B.Enlarge(Tol); |
116 | //<-OCC566(apo) |
117 | break; |
118 | } |
119 | case GeomAbs_BSplineCurve: |
120 | { |
121 | Handle(Geom_BSplineCurve) Bs = C.BSpline(); |
122 | if(Abs(Bs->FirstParameter() - U1) > Precision::Parametric(Tol)|| |
123 | Abs(Bs->LastParameter() - U2) > Precision::Parametric(Tol)) { |
124 | |
125 | Handle(Geom_Geometry) G = Bs->Copy(); |
126 | Handle(Geom_BSplineCurve)& Bsaux = (*((Handle(Geom_BSplineCurve)*)&G)); |
127 | Standard_Real u1 = U1, u2 = U2; |
128 | //// modified by jgv, 24.10.01 for BUC61031 //// |
129 | if (Bsaux->IsPeriodic()) |
130 | ElCLib::AdjustPeriodic( Bsaux->FirstParameter(), Bsaux->LastParameter(), Precision::PConfusion(), u1, u2 ); |
131 | //////////////////////////////////////////////// |
132 | // modified by NIZHNY-EAP Fri Dec 3 14:29:14 1999 ___BEGIN___ |
133 | // To avoid exeption in Segment |
134 | if(Bsaux->FirstParameter() > U1) u1 = Bsaux->FirstParameter(); |
135 | if(Bsaux->LastParameter() < U2 ) u2 = Bsaux->LastParameter(); |
136 | // modified by NIZHNY-EAP Fri Dec 3 14:29:18 1999 ___END___ |
137 | Bsaux->Segment(u1, u2); |
138 | Bs = Bsaux; |
139 | } |
140 | //OCC566(apo)-> |
141 | Bnd_Box B1; |
142 | Standard_Integer k, k1 = Bs->FirstUKnotIndex(), k2 = Bs->LastUKnotIndex(), |
143 | N = Bs->Degree(), NbKnots = Bs->NbKnots(); |
144 | TColStd_Array1OfReal Knots(1,NbKnots); |
145 | Bs->Knots(Knots); |
146 | GeomAdaptor_Curve GACurve(Bs); |
147 | Standard_Real first = Knots(k1), last; |
148 | for(k = k1 + 1; k <= k2; k++){ |
149 | last = Knots(k); |
150 | tol = Max(FillBox(B1,GACurve,first,last,N), tol); |
151 | first = last; |
152 | } |
153 | B1.Enlarge(weakness*tol); |
154 | Standard_Real x, y, z, X, Y, Z; |
155 | B1.Get(x, y, z, X, Y, Z); |
156 | B.Update(x, y, z, X, Y, Z); |
157 | B.Enlarge(Tol); |
158 | //<-OCC566(apo) |
159 | break; |
160 | } |
161 | default: |
162 | { |
163 | Bnd_Box B1; |
164 | static Standard_Integer N = 33; |
165 | tol = FillBox(B1,C,U1,U2,N); |
166 | B1.Enlarge(weakness*tol); |
167 | Standard_Real x, y, z, X, Y, Z; |
168 | B1.Get(x, y, z, X, Y, Z); |
169 | B.Update(x, y, z, X, Y, Z); |
170 | B.Enlarge(Tol); |
171 | } |
172 | } |
173 | } |