Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1992-03-13 |
2 | // Created by: Christophe MARION | |
3 | // Copyright (c) 1992-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 | |
18 | #include <BRepAdaptor_Curve.hxx> | |
19 | #include <Geom_BezierCurve.hxx> | |
20 | #include <Geom_BSplineCurve.hxx> | |
7fd59977 | 21 | #include <gp.hxx> |
22 | #include <gp_Ax3.hxx> | |
42cf5bc1 | 23 | #include <gp_Circ2d.hxx> |
24 | #include <gp_Dir2d.hxx> | |
25 | #include <gp_Elips2d.hxx> | |
26 | #include <gp_Hypr2d.hxx> | |
27 | #include <gp_Lin2d.hxx> | |
28 | #include <gp_Parab2d.hxx> | |
7fd59977 | 29 | #include <gp_Pln.hxx> |
42cf5bc1 | 30 | #include <gp_Pnt.hxx> |
31 | #include <gp_Pnt2d.hxx> | |
32 | #include <gp_Vec.hxx> | |
33 | #include <gp_Vec2d.hxx> | |
7fd59977 | 34 | #include <HLRAlgo.hxx> |
35 | #include <HLRAlgo_Projector.hxx> | |
36 | #include <HLRBRep_CLProps.hxx> | |
42cf5bc1 | 37 | #include <HLRBRep_Curve.hxx> |
38 | #include <Precision.hxx> | |
39 | #include <ProjLib.hxx> | |
40 | #include <Standard_DomainError.hxx> | |
41 | #include <Standard_NoSuchObject.hxx> | |
42 | #include <Standard_OutOfRange.hxx> | |
43 | #include <StdFail_UndefinedDerivative.hxx> | |
44 | #include <TColgp_Array1OfPnt.hxx> | |
45 | #include <TopoDS_Edge.hxx> | |
7fd59977 | 46 | |
733a0e55 | 47 | //OCC155 // jfa 05.03.2002 // bad vectors projection |
7fd59977 | 48 | //======================================================================= |
49 | //function : HLRBRep_Curve | |
50 | //purpose : | |
51 | //======================================================================= | |
7fd59977 | 52 | HLRBRep_Curve::HLRBRep_Curve () |
53 | {} | |
54 | ||
55 | //======================================================================= | |
56 | //function : Curve | |
57 | //purpose : | |
58 | //======================================================================= | |
59 | ||
60 | void HLRBRep_Curve::Curve (const TopoDS_Edge& E) | |
61 | { myCurve.Initialize(E); } | |
62 | ||
63 | //======================================================================= | |
64 | //function : Parameter2d | |
65 | //purpose : | |
66 | //======================================================================= | |
67 | ||
68 | Standard_Real | |
69 | HLRBRep_Curve::Parameter2d (const Standard_Real P3d) const | |
70 | { | |
7fd59977 | 71 | // Mathematical formula for lines |
72 | ||
73 | // myOF P3d (myOF myVX - myOZ myVX + myOX myVZ) | |
733a0e55 | 74 | // Res -> -------------------------------------------- |
7fd59977 | 75 | // (-myOF + myOZ) (-myOF + myOZ + P3d myVZ) |
76 | ||
5c953701 | 77 | switch (myType) |
78 | { | |
79 | case GeomAbs_Line: | |
80 | if (((HLRAlgo_Projector*) myProj)->Perspective()) { | |
81 | const Standard_Real FmOZ = myOF - myOZ; | |
82 | return myOF * P3d * (myVX * FmOZ + myOX * myVZ) / (FmOZ * (FmOZ - P3d * myVZ)); | |
83 | } | |
84 | return P3d * myVX; | |
85 | ||
86 | case GeomAbs_Ellipse: | |
87 | return P3d + myOX; | |
1aec3320 | 88 | |
89 | default: // implemented to avoid gcc compiler warnings | |
90 | break; | |
7fd59977 | 91 | } |
733a0e55 | 92 | return P3d; |
7fd59977 | 93 | } |
94 | ||
95 | //======================================================================= | |
96 | //function : Parameter3d | |
97 | //purpose : | |
98 | //======================================================================= | |
99 | ||
100 | Standard_Real | |
101 | HLRBRep_Curve::Parameter3d (const Standard_Real P2d) const | |
102 | { | |
7fd59977 | 103 | // Mathematical formula for lines |
104 | ||
105 | // 2 | |
106 | // (-myOF + myOZ) P2d | |
107 | // P3d -> ----------------------------------------------------- | |
108 | // (myOF - myOZ) (myOF myVX + P2d myVZ) + myOF myOX myVZ | |
109 | ||
7fd59977 | 110 | if (myType == GeomAbs_Line) { |
111 | if (((HLRAlgo_Projector*) myProj)->Perspective()) { | |
733a0e55 S |
112 | const Standard_Real FmOZ = myOF - myOZ; |
113 | return P2d * FmOZ * FmOZ / (FmOZ * (myOF * myVX + P2d * myVZ) + myOF * myOX * myVZ); | |
7fd59977 | 114 | } |
5ec5d80d | 115 | return ((myVX <= gp::Resolution())? P2d : (P2d / myVX)); |
7fd59977 | 116 | } |
117 | ||
118 | else if (myType == GeomAbs_Ellipse) { | |
733a0e55 | 119 | return P2d - myOX; |
7fd59977 | 120 | } |
121 | ||
733a0e55 | 122 | return P2d; |
7fd59977 | 123 | } |
124 | ||
125 | //======================================================================= | |
126 | //function : Update | |
127 | //purpose : | |
128 | //======================================================================= | |
129 | ||
681f3919 | 130 | Standard_Real HLRBRep_Curve::Update( |
131 | Standard_Real TotMin[16], Standard_Real TotMax[16]) | |
7fd59977 | 132 | { |
133 | GeomAbs_CurveType typ = HLRBRep_BCurveTool::GetType(myCurve); | |
134 | myType = GeomAbs_OtherCurve; | |
135 | ||
136 | switch (typ) { | |
137 | ||
138 | case GeomAbs_Line: | |
139 | myType = typ; | |
140 | break; | |
141 | ||
142 | case GeomAbs_Circle: | |
143 | if (!((HLRAlgo_Projector*) myProj)->Perspective()) { | |
144 | gp_Dir D1 = HLRBRep_BCurveTool::Circle(myCurve).Axis().Direction(); | |
145 | D1.Transform(((HLRAlgo_Projector*) myProj)->Transformation()); | |
146 | if (D1.IsParallel(gp::DZ(),Precision::Angular())) | |
733a0e55 | 147 | myType = GeomAbs_Circle; |
7fd59977 | 148 | else if (Abs(D1.Dot(gp::DZ())) < Precision::Angular()*10) //*10: The minor radius of ellipse should not be too small. |
733a0e55 | 149 | myType = GeomAbs_OtherCurve; |
7fd59977 | 150 | else { |
733a0e55 S |
151 | myType = GeomAbs_Ellipse; |
152 | // compute the angle offset | |
153 | gp_Dir D3 = D1.Crossed(gp::DZ()); | |
154 | gp_Dir D2 = HLRBRep_BCurveTool::Circle(myCurve).XAxis().Direction(); | |
155 | D2.Transform(((HLRAlgo_Projector*) myProj)->Transformation()); | |
156 | myOX = D3.AngleWithRef(D2,D1); | |
7fd59977 | 157 | } |
158 | } | |
159 | break; | |
160 | ||
161 | case GeomAbs_Ellipse: | |
162 | if (!((HLRAlgo_Projector*) myProj)->Perspective()) { | |
163 | gp_Dir D1 = HLRBRep_BCurveTool::Ellipse(myCurve).Axis().Direction(); | |
164 | D1.Transform(((HLRAlgo_Projector*) myProj)->Transformation()); | |
165 | if (D1.IsParallel(gp::DZ(),Precision::Angular())) { | |
733a0e55 S |
166 | myOX = 0.; // no offset on the angle |
167 | myType = GeomAbs_Ellipse; | |
7fd59977 | 168 | } |
169 | } | |
170 | break; | |
171 | ||
172 | case GeomAbs_BezierCurve: | |
173 | if (HLRBRep_BCurveTool::Degree(myCurve) == 1) | |
174 | myType = GeomAbs_Line; | |
175 | else if (!((HLRAlgo_Projector*) myProj)->Perspective()) | |
176 | myType = typ; | |
177 | break; | |
178 | ||
179 | case GeomAbs_BSplineCurve: | |
180 | if (!((HLRAlgo_Projector*) myProj)->Perspective()) | |
181 | myType = typ; | |
182 | break; | |
183 | ||
184 | default: | |
185 | break; | |
186 | } | |
187 | ||
188 | if (myType == GeomAbs_Line) { | |
189 | // compute the values for a line | |
190 | gp_Lin L; | |
191 | Standard_Real l3d = 1.; // length of the 3d bezier curve | |
192 | if (HLRBRep_BCurveTool::GetType(myCurve) == GeomAbs_Line) { | |
193 | L = HLRBRep_BCurveTool::Line(myCurve); | |
194 | } | |
195 | else { // bezier degree 1 | |
196 | gp_Pnt PL; | |
197 | gp_Vec VL; | |
198 | HLRBRep_BCurveTool::D1(myCurve,0,PL,VL); | |
199 | L = gp_Lin(PL,VL); | |
200 | l3d = PL.Distance(HLRBRep_BCurveTool::Value(myCurve,1.)); | |
201 | } | |
202 | gp_Pnt P = L.Location(); | |
203 | gp_Vec V = L.Direction(); | |
204 | P.Transform(((HLRAlgo_Projector*) myProj)->Transformation()); | |
205 | V.Transform(((HLRAlgo_Projector*) myProj)->Transformation()); | |
206 | if (((HLRAlgo_Projector*) myProj)->Perspective()) { | |
207 | gp_Pnt2d F; | |
208 | gp_Vec2d VFX; | |
209 | D1(0.,F,VFX); | |
210 | VFX.Normalize(); | |
211 | myVX = (VFX.X()*V.X()+VFX.Y()*V.Y()) * l3d; | |
212 | Standard_Real l = - (VFX.X()*F.X() + VFX.Y()*F.Y()); | |
213 | F.SetCoord(F.X()+VFX.X()*l,F.Y()+VFX.Y()*l); | |
214 | myOX = VFX.X()*(P.X()-F.X()) + VFX.Y()*(P.Y()-F.Y()); | |
215 | gp_Vec VFZ(-F.X(),-F.Y(),((HLRAlgo_Projector*) myProj)->Focus()); | |
216 | myOF = VFZ.Magnitude(); | |
217 | VFZ /= myOF; | |
218 | myVZ = VFZ * V; | |
219 | myVZ *= l3d; | |
220 | myOZ = VFZ * gp_Vec(P.X()-F.X(),P.Y()-F.Y(),P.Z()); | |
221 | } | |
222 | else myVX = Sqrt(V.X() * V.X() + V.Y() * V.Y()) * l3d; | |
223 | } | |
224 | return(UpdateMinMax(TotMin,TotMax)); | |
225 | } | |
226 | ||
227 | //======================================================================= | |
228 | //function : UpdateMinMax | |
229 | //purpose : | |
230 | //======================================================================= | |
231 | ||
681f3919 | 232 | Standard_Real HLRBRep_Curve::UpdateMinMax( |
233 | Standard_Real TotMin[16], Standard_Real TotMax[16]) | |
7fd59977 | 234 | { |
235 | Standard_Real a = HLRBRep_BCurveTool::FirstParameter(myCurve); | |
236 | Standard_Real b = HLRBRep_BCurveTool::LastParameter(myCurve); | |
237 | Standard_Real x,y,z,tolMinMax = 0; | |
238 | ((HLRAlgo_Projector*) myProj)->Project(Value3D(a),x,y,z); | |
239 | HLRAlgo::UpdateMinMax(x,y,z,TotMin,TotMax); | |
240 | ||
241 | if (myType != GeomAbs_Line) { | |
242 | Standard_Integer nbPnt = 30; | |
243 | Standard_Integer i; | |
244 | Standard_Real step = (b-a)/(nbPnt+1); | |
7fd59977 | 245 | Standard_Real xa,ya,za,xb =0.,yb =0.,zb =0.; |
7fd59977 | 246 | Standard_Real dx1,dy1,dz1,dd1; |
247 | Standard_Real dx2,dy2,dz2,dd2; | |
248 | ||
249 | for (i = 1; i <= nbPnt; i++) { | |
250 | a += step; | |
251 | xa = xb; ya = yb; za = zb; | |
252 | xb = x ; yb = y ; zb = z ; | |
253 | ((HLRAlgo_Projector*) myProj)->Project(Value3D(a),x,y,z); | |
254 | HLRAlgo::UpdateMinMax(x,y,z,TotMin,TotMax); | |
733a0e55 S |
255 | if (i >= 2) { |
256 | dx1 = x - xa; dy1 = y - ya; dz1 = z - za; | |
257 | dd1 = sqrt (dx1 * dx1 + dy1 * dy1 + dz1 * dz1); | |
258 | if (dd1 > 0) { | |
259 | dx2 = xb - xa; dy2 = yb - ya; dz2 = zb - za; | |
260 | dd2 = sqrt (dx2 * dx2 + dy2 * dy2 + dz2 * dz2); | |
261 | if (dd2 > 0) { | |
262 | Standard_Real p = (dx1 * dx2 + dy1 * dy2 + dz1 * dz2) / (dd1 * dd2); | |
263 | dx1 = xa + p * dx1 - xb; | |
264 | dy1 = ya + p * dy1 - yb; | |
265 | dz1 = za + p * dz1 - zb; | |
266 | dd1 = sqrt (dx1 * dx1 + dy1 * dy1 + dz1 * dz1); | |
267 | if (dd1 > tolMinMax) tolMinMax = dd1; | |
268 | } | |
269 | } | |
7fd59977 | 270 | } |
271 | } | |
272 | } | |
273 | ((HLRAlgo_Projector*) myProj)->Project(Value3D(b),x,y,z); | |
274 | HLRAlgo::UpdateMinMax(x,y,z,TotMin,TotMax); | |
275 | return tolMinMax; | |
276 | } | |
277 | ||
278 | //======================================================================= | |
279 | //function : Z | |
280 | //purpose : | |
281 | //======================================================================= | |
282 | ||
283 | Standard_Real HLRBRep_Curve::Z (const Standard_Real U) const | |
284 | { | |
285 | gp_Pnt P3d; | |
286 | HLRBRep_BCurveTool::D0(myCurve,U,P3d); | |
287 | P3d.Transform(((HLRAlgo_Projector*) myProj)->Transformation()); | |
288 | return P3d.Z(); | |
289 | } | |
290 | ||
291 | //======================================================================= | |
292 | //function : Tangent | |
293 | //purpose : | |
294 | //======================================================================= | |
295 | ||
296 | void HLRBRep_Curve::Tangent (const Standard_Boolean AtStart, | |
733a0e55 | 297 | gp_Pnt2d& P, gp_Dir2d& D) const |
7fd59977 | 298 | { |
733a0e55 S |
299 | Standard_Real U = AtStart? HLRBRep_BCurveTool::FirstParameter(myCurve) : |
300 | HLRBRep_BCurveTool::LastParameter (myCurve); | |
7fd59977 | 301 | |
302 | D0(U,P); | |
303 | HLRBRep_CLProps CLP(2,Epsilon(1.)); | |
681f3919 | 304 | const HLRBRep_Curve* aCurve = this; |
305 | CLP.SetCurve(aCurve); | |
7fd59977 | 306 | CLP.SetParameter(U); |
307 | StdFail_UndefinedDerivative_Raise_if | |
308 | (!CLP.IsTangentDefined(), "HLRBRep_Curve::Tangent"); | |
309 | CLP.Tangent(D); | |
310 | } | |
311 | ||
312 | //======================================================================= | |
313 | //function : D0 | |
314 | //purpose : | |
315 | //======================================================================= | |
316 | ||
317 | void HLRBRep_Curve::D0 (const Standard_Real U, gp_Pnt2d& P) const | |
318 | { | |
733a0e55 | 319 | /* gp_Pnt P3d; |
7fd59977 | 320 | HLRBRep_BCurveTool::D0(myCurve,U,P3d); |
321 | P3d.Transform(((HLRAlgo_Projector*) myProj)->Transformation()); | |
322 | if (((HLRAlgo_Projector*) myProj)->Perspective()) { | |
323 | Standard_Real R = 1.-P3d.Z()/((HLRAlgo_Projector*) myProj)->Focus(); | |
324 | P.SetCoord(P3d.X()/R,P3d.Y()/R); | |
325 | } | |
733a0e55 | 326 | else P.SetCoord(P3d.X(),P3d.Y()); */ |
7fd59977 | 327 | gp_Pnt P3d; |
328 | HLRBRep_BCurveTool::D0(myCurve,U,P3d); | |
329 | ((HLRAlgo_Projector*) myProj)->Project(P3d,P); | |
7fd59977 | 330 | } |
331 | ||
332 | //======================================================================= | |
333 | //function : D1 | |
334 | //purpose : | |
335 | //======================================================================= | |
336 | ||
337 | void HLRBRep_Curve::D1 (const Standard_Real U, | |
733a0e55 | 338 | gp_Pnt2d& P, gp_Vec2d& V) const |
7fd59977 | 339 | { |
7fd59977 | 340 | // Mathematical formula for lines |
341 | ||
342 | // X'[t] X[t] Z'[t] | |
343 | // D1 = -------- + ------------- | |
344 | // Z[t] Z[t] 2 | |
345 | // 1 - ---- f (1 - ----) | |
346 | // f f | |
347 | ||
733a0e55 | 348 | /* gp_Pnt P3D; |
7fd59977 | 349 | gp_Vec V13D; |
350 | HLRBRep_BCurveTool::D1(myCurve,U,P3D,V13D); | |
351 | P3D .Transform(((HLRAlgo_Projector*) myProj)->Transformation()); | |
352 | V13D.Transform(((HLRAlgo_Projector*) myProj)->Transformation()); | |
353 | if (((HLRAlgo_Projector*) myProj)->Perspective()) { | |
354 | Standard_Real f = ((HLRAlgo_Projector*) myProj)->Focus(); | |
355 | Standard_Real R = 1. - P3D.Z()/f; | |
356 | Standard_Real e = V13D.Z()/(f*R*R); | |
357 | P.SetCoord(P3D .X()/R , P3D .Y()/R ); | |
358 | V.SetCoord(V13D.X()/R + P3D.X()*e, V13D.Y()/R + P3D.Y()*e); | |
359 | } | |
360 | else { | |
361 | P.SetCoord(P3D .X(),P3D .Y()); | |
362 | V.SetCoord(V13D.X(),V13D.Y()); | |
733a0e55 | 363 | } */ |
7fd59977 | 364 | gp_Pnt P3D; |
365 | gp_Vec V13D; | |
366 | HLRBRep_BCurveTool::D1(myCurve,U,P3D,V13D); | |
367 | if (((HLRAlgo_Projector*) myProj)->Perspective()) { | |
368 | Standard_Real f = ((HLRAlgo_Projector*) myProj)->Focus(); | |
369 | Standard_Real R = 1. - P3D.Z()/f; | |
370 | Standard_Real e = V13D.Z()/(f*R*R); | |
371 | P.SetCoord(P3D .X()/R , P3D .Y()/R ); | |
372 | V.SetCoord(V13D.X()/R + P3D.X()*e, V13D.Y()/R + P3D.Y()*e); | |
373 | } | |
374 | else { | |
733a0e55 | 375 | //OCC155 |
7fd59977 | 376 | ((HLRAlgo_Projector*) myProj)->Project(P3D,V13D,P,V); |
733a0e55 | 377 | /* ((HLRAlgo_Projector*) myProj)->Project(P3D,P); |
7fd59977 | 378 | gp_Pnt2d opop; |
379 | gp_Pnt uiui(V13D.X(),V13D.Y(),V13D.Z()); | |
380 | ((HLRAlgo_Projector*) myProj)->Project(uiui,opop); | |
733a0e55 | 381 | V.SetCoord(opop.X(),opop.Y()); */ |
7fd59977 | 382 | } |
7fd59977 | 383 | } |
384 | ||
385 | //======================================================================= | |
386 | //function : D2 | |
387 | //purpose : | |
388 | //======================================================================= | |
389 | ||
390 | void HLRBRep_Curve::D2 (const Standard_Real U, | |
733a0e55 | 391 | gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2) const |
7fd59977 | 392 | { |
7fd59977 | 393 | // Mathematical formula for lines |
394 | ||
395 | // 2 | |
396 | // 2 X'[t] Z'[t] 2 X[t] Z'[t] X''[t] X[t] Z''[t] | |
397 | // D2 = ------------- + -------------- + -------- + ------------- | |
398 | // Z[t] 2 2 Z[t] 3 Z[t] Z[t] 2 | |
399 | // f (1 - ----) f (1 - ----) 1 - ---- f (1 - ----) | |
400 | // f f f f | |
401 | ||
402 | gp_Pnt P3D; | |
403 | gp_Vec V13D,V23D; | |
404 | HLRBRep_BCurveTool::D2(myCurve,U,P3D,V13D,V23D); | |
405 | P3D .Transform(((HLRAlgo_Projector*) myProj)->Transformation()); | |
406 | V13D.Transform(((HLRAlgo_Projector*) myProj)->Transformation()); | |
407 | V23D.Transform(((HLRAlgo_Projector*) myProj)->Transformation()); | |
408 | if (((HLRAlgo_Projector*) myProj)->Perspective()) { | |
409 | Standard_Real f = ((HLRAlgo_Projector*) myProj)->Focus(); | |
410 | Standard_Real R = 1. - P3D.Z() / f; | |
411 | Standard_Real q = f*R*R; | |
412 | Standard_Real e = V13D.Z()/q; | |
413 | Standard_Real c = e*V13D.Z()/(f*R); | |
414 | P .SetCoord(P3D .X()/R , P3D .Y()/R ); | |
415 | V1.SetCoord(V13D.X()/R + P3D.X()*e, V13D.Y()/R + P3D.Y()*e); | |
416 | V2.SetCoord(V23D.X()/R + 2*V13D.X()*e + P3D.X()*V23D.Z()/q + 2*P3D.X()*c, | |
417 | V23D.Y()/R + 2*V13D.Y()*e + P3D.Y()*V23D.Z()/q + 2*P3D.Y()*c); | |
418 | } | |
419 | else { | |
420 | P .SetCoord(P3D .X(),P3D .Y()); | |
421 | V1.SetCoord(V13D.X(),V13D.Y()); | |
422 | V2.SetCoord(V23D.X(),V23D.Y()); | |
423 | } | |
424 | } | |
425 | ||
426 | //======================================================================= | |
427 | //function : D3 | |
428 | //purpose : | |
429 | //======================================================================= | |
430 | ||
431 | void HLRBRep_Curve::D3 (const Standard_Real, | |
733a0e55 | 432 | gp_Pnt2d&, gp_Vec2d&, gp_Vec2d&, gp_Vec2d&) const |
7fd59977 | 433 | { |
434 | } | |
435 | ||
436 | //======================================================================= | |
437 | //function : DN | |
438 | //purpose : | |
439 | //======================================================================= | |
440 | ||
733a0e55 | 441 | gp_Vec2d HLRBRep_Curve::DN (const Standard_Real, const Standard_Integer) const |
7fd59977 | 442 | { return gp_Vec2d(); } |
443 | ||
444 | //======================================================================= | |
445 | //function : Line | |
446 | //purpose : | |
447 | //======================================================================= | |
448 | ||
449 | gp_Lin2d HLRBRep_Curve::Line () const | |
450 | { | |
451 | gp_Pnt2d P; | |
452 | gp_Vec2d V; | |
453 | D1(0.,P,V); | |
454 | return gp_Lin2d(P,V); | |
455 | } | |
456 | ||
457 | //======================================================================= | |
458 | //function : Circle | |
459 | //purpose : | |
460 | //======================================================================= | |
461 | ||
462 | gp_Circ2d HLRBRep_Curve::Circle () const | |
463 | { | |
464 | gp_Circ C = HLRBRep_BCurveTool::Circle(myCurve); | |
681f3919 | 465 | C.Transform(myProj->Transformation()); |
7fd59977 | 466 | return ProjLib::Project(gp_Pln(gp::XOY()),C); |
467 | } | |
468 | ||
469 | //======================================================================= | |
470 | //function : Ellipse | |
471 | //purpose : | |
472 | //======================================================================= | |
473 | ||
474 | gp_Elips2d HLRBRep_Curve::Ellipse () const | |
475 | { | |
733a0e55 | 476 | if (HLRBRep_BCurveTool::GetType(myCurve) == GeomAbs_Ellipse) { |
7fd59977 | 477 | gp_Elips E = HLRBRep_BCurveTool::Ellipse(myCurve); |
681f3919 | 478 | E.Transform(myProj->Transformation()); |
7fd59977 | 479 | return ProjLib::Project(gp_Pln(gp::XOY()),E); |
480 | } | |
733a0e55 S |
481 | // this is a circle |
482 | gp_Circ C = HLRBRep_BCurveTool::Circle(myCurve); | |
681f3919 | 483 | C.Transform(myProj->Transformation()); |
733a0e55 S |
484 | const gp_Dir& D1 = C.Axis().Direction(); |
485 | const gp_Dir& D3 = D1.Crossed(gp::DZ()); | |
486 | const gp_Dir& D2 = D1.Crossed(D3); | |
487 | Standard_Real rap = sqrt( D2.X()*D2.X() + D2.Y()*D2.Y() ); | |
488 | gp_Dir2d d(D1.Y(),-D1.X()); | |
489 | gp_Pnt2d p(C.Location().X(),C.Location().Y()); | |
490 | gp_Elips2d El(gp_Ax2d(p,d),C.Radius(),C.Radius()*rap); | |
491 | if ( D1.Z() < 0 ) El.Reverse(); | |
492 | return El; | |
7fd59977 | 493 | } |
494 | ||
495 | //======================================================================= | |
496 | //function : Hyperbola | |
497 | //purpose : | |
498 | //======================================================================= | |
499 | ||
500 | gp_Hypr2d HLRBRep_Curve::Hyperbola () const | |
501 | { return gp_Hypr2d(); } | |
502 | ||
503 | //======================================================================= | |
504 | //function : Parabola | |
505 | //purpose : | |
506 | //======================================================================= | |
507 | gp_Parab2d HLRBRep_Curve::Parabola () const | |
508 | { return gp_Parab2d(); } | |
509 | ||
510 | //======================================================================= | |
511 | //function : Poles | |
512 | //purpose : | |
513 | //======================================================================= | |
514 | ||
515 | void HLRBRep_Curve::Poles (TColgp_Array1OfPnt2d& TP) const | |
516 | { | |
517 | Standard_Integer i1 = TP.Lower(); | |
518 | Standard_Integer i2 = TP.Upper(); | |
519 | TColgp_Array1OfPnt TP3(i1,i2); | |
520 | //-- HLRBRep_BCurveTool::Poles(myCurve,TP3); | |
521 | if(HLRBRep_BCurveTool::GetType(myCurve) == GeomAbs_BSplineCurve) { | |
522 | (HLRBRep_BCurveTool::BSpline(myCurve))->Poles(TP3); | |
523 | } | |
524 | else { | |
525 | (HLRBRep_BCurveTool::Bezier(myCurve))->Poles(TP3); | |
526 | } | |
527 | for (Standard_Integer i = i1; i <= i2; i++) { | |
681f3919 | 528 | myProj->Transform(TP3(i)); |
7fd59977 | 529 | TP(i).SetCoord(TP3(i).X(),TP3(i).Y()); |
530 | } | |
531 | } | |
532 | ||
0a768f56 | 533 | //======================================================================= |
534 | //function : Poles | |
535 | //purpose : | |
536 | //======================================================================= | |
537 | ||
538 | void HLRBRep_Curve::Poles (const Handle(Geom_BSplineCurve)& aCurve, | |
539 | TColgp_Array1OfPnt2d& TP) const | |
540 | { | |
541 | Standard_Integer i1 = TP.Lower(); | |
542 | Standard_Integer i2 = TP.Upper(); | |
543 | TColgp_Array1OfPnt TP3(i1,i2); | |
544 | //-- HLRBRep_BCurveTool::Poles(myCurve,TP3); | |
545 | aCurve->Poles(TP3); | |
546 | ||
547 | for (Standard_Integer i = i1; i <= i2; i++) { | |
548 | ((HLRAlgo_Projector*) myProj)->Transform(TP3(i)); | |
549 | TP(i).SetCoord(TP3(i).X(),TP3(i).Y()); | |
550 | } | |
551 | } | |
552 | ||
7fd59977 | 553 | //======================================================================= |
554 | //function : PolesAndWeights | |
555 | //purpose : | |
556 | //======================================================================= | |
557 | ||
558 | void HLRBRep_Curve::PolesAndWeights (TColgp_Array1OfPnt2d& TP, | |
559 | TColStd_Array1OfReal& TW) const | |
560 | { | |
561 | Standard_Integer i1 = TP.Lower(); | |
562 | Standard_Integer i2 = TP.Upper(); | |
563 | TColgp_Array1OfPnt TP3(i1,i2); | |
564 | //-- HLRBRep_BCurveTool::PolesAndWeights(myCurve,TP3,TW); | |
565 | ||
566 | if(HLRBRep_BCurveTool::GetType(myCurve) == GeomAbs_BSplineCurve) { | |
567 | Handle(Geom_BSplineCurve) HB = (HLRBRep_BCurveTool::BSpline(myCurve)); | |
568 | HB->Poles(TP3); | |
569 | HB->Weights(TW); | |
570 | //-- (HLRBRep_BCurveTool::BSpline(myCurve))->PolesAndWeights(TP3,TW); | |
571 | } | |
572 | else { | |
573 | Handle(Geom_BezierCurve) HB = (HLRBRep_BCurveTool::Bezier(myCurve)); | |
574 | HB->Poles(TP3); | |
575 | HB->Weights(TW); | |
576 | //-- (HLRBRep_BCurveTool::Bezier(myCurve))->PolesAndWeights(TP3,TW); | |
577 | } | |
578 | for (Standard_Integer i = i1; i <= i2; i++) { | |
579 | ((HLRAlgo_Projector*) myProj)->Transform(TP3(i)); | |
580 | TP(i).SetCoord(TP3(i).X(),TP3(i).Y()); | |
581 | } | |
582 | } | |
583 | ||
0a768f56 | 584 | //======================================================================= |
585 | //function : PolesAndWeights | |
586 | //purpose : | |
587 | //======================================================================= | |
588 | ||
589 | void HLRBRep_Curve::PolesAndWeights (const Handle(Geom_BSplineCurve)& aCurve, | |
590 | TColgp_Array1OfPnt2d& TP, | |
591 | TColStd_Array1OfReal& TW) const | |
592 | { | |
593 | Standard_Integer i1 = TP.Lower(); | |
594 | Standard_Integer i2 = TP.Upper(); | |
595 | TColgp_Array1OfPnt TP3(i1,i2); | |
596 | //-- HLRBRep_BCurveTool::PolesAndWeights(myCurve,TP3,TW); | |
597 | ||
598 | aCurve->Poles(TP3); | |
599 | aCurve->Weights(TW); | |
600 | //-- (HLRBRep_BCurveTool::BSpline(myCurve))->PolesAndWeights(TP3,TW); | |
601 | ||
602 | for (Standard_Integer i = i1; i <= i2; i++) { | |
603 | ((HLRAlgo_Projector*) myProj)->Transform(TP3(i)); | |
604 | TP(i).SetCoord(TP3(i).X(),TP3(i).Y()); | |
605 | } | |
606 | } | |
607 | ||
7fd59977 | 608 | //======================================================================= |
609 | //function : Knots | |
610 | //purpose : | |
611 | //======================================================================= | |
612 | ||
613 | void HLRBRep_Curve::Knots (TColStd_Array1OfReal& kn) const | |
614 | { | |
615 | if(HLRBRep_BCurveTool::GetType(myCurve) == GeomAbs_BSplineCurve) { | |
616 | Handle(Geom_BSplineCurve) HB = (HLRBRep_BCurveTool::BSpline(myCurve)); | |
617 | HB->Knots(kn); | |
618 | } | |
619 | } | |
620 | ||
7fd59977 | 621 | //======================================================================= |
622 | //function : Multiplicities | |
623 | //purpose : | |
624 | //======================================================================= | |
625 | ||
626 | void HLRBRep_Curve::Multiplicities (TColStd_Array1OfInteger& mu) const | |
627 | { | |
628 | if(HLRBRep_BCurveTool::GetType(myCurve) == GeomAbs_BSplineCurve) { | |
629 | Handle(Geom_BSplineCurve) HB = (HLRBRep_BCurveTool::BSpline(myCurve)); | |
630 | HB->Multiplicities(mu); | |
631 | } | |
632 | } |