973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | #include <ShapeAnalysis_TransferParametersProj.ixx> |
15 | #include <Geom2dAdaptor_HCurve.hxx> |
16 | #include <Geom2d_Curve.hxx> |
17 | #include <Adaptor3d_CurveOnSurface.hxx> |
18 | #include <Geom_Surface.hxx> |
19 | #include <GeomAdaptor_HSurface.hxx> |
20 | #include <BRep_Tool.hxx> |
21 | #include <TColStd_HArray1OfReal.hxx> |
22 | #include <TopLoc_Location.hxx> |
23 | #include <ShapeAnalysis_Edge.hxx> |
24 | #include <TColgp_SequenceOfPnt.hxx> |
25 | #include <ShapeAnalysis_Curve.hxx> |
26 | #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx> |
27 | #include <BRep_TEdge.hxx> |
28 | #include <BRep_GCurve.hxx> |
29 | #include <BRep_ListOfCurveRepresentation.hxx> |
30 | #include <BRep_ListOfCurveRepresentation.hxx> |
31 | #include <Precision.hxx> |
32 | #include <ShapeBuild_Edge.hxx> |
33 | #include <BRep_Builder.hxx> |
34 | #include <GeomAdaptor_Curve.hxx> |
35 | #include <ShapeAnalysis.hxx> |
36 | #include <Geom2d_TrimmedCurve.hxx> |
37 | #include <Geom2d_OffsetCurve.hxx> |
38 | #include <Geom2d_BSplineCurve.hxx> |
39 | #include <BRep_ListOfPointRepresentation.hxx> |
40 | #include <BRep_TVertex.hxx> |
41 | #include <BRep_ListIteratorOfListOfPointRepresentation.hxx> |
42 | #include <BRep_PointRepresentation.hxx> |
43 | #include <BRep_PointOnSurface.hxx> |
44 | #include <BRep_PointOnCurve.hxx> |
45 | #include <BRep_PointOnCurveOnSurface.hxx> |
46 | #include <TopoDS.hxx> |
47 | #include <ShapeAnalysis_Surface.hxx> |
48 | //======================================================================= |
49 | //function : ShapeAnalysis_TransferParametersProj |
50 | //purpose : |
51 | //======================================================================= |
52 | |
53 | ShapeAnalysis_TransferParametersProj::ShapeAnalysis_TransferParametersProj() |
54 | { |
55 | myMaxTolerance = 1; //Precision::Infinite(); ?? pdn |
56 | myForceProj = Standard_False; |
57 | myInitOK = Standard_False; |
58 | } |
59 | |
60 | |
61 | //======================================================================= |
62 | //function : ShapeAnalysis_TransferParametersProj |
63 | //purpose : |
64 | //======================================================================= |
65 | |
66 | ShapeAnalysis_TransferParametersProj::ShapeAnalysis_TransferParametersProj(const TopoDS_Edge& E, |
67 | const TopoDS_Face& F) |
68 | { |
69 | myMaxTolerance = 1; //Precision::Infinite(); ?? pdn |
70 | myForceProj = Standard_False; |
71 | Init(E,F); |
72 | } |
73 | |
74 | |
75 | //======================================================================= |
76 | //function : Init |
77 | //purpose : |
78 | //======================================================================= |
79 | |
80 | void ShapeAnalysis_TransferParametersProj::Init(const TopoDS_Edge& E, |
81 | const TopoDS_Face& F) |
82 | { |
83 | myInitOK = Standard_False; |
84 | ShapeAnalysis_TransferParameters::Init(E,F); |
85 | myEdge = E; |
86 | myPrecision = BRep_Tool::Tolerance(E); // it is better - skl OCC2851 |
87 | //myPrecision = Precision::Confusion(); |
88 | |
89 | myCurve = BRep_Tool::Curve (E, myFirst, myLast); |
90 | if ( myCurve.IsNull() ) { myFirst = 0.; myLast = 1.; return;} |
91 | |
92 | if ( F.IsNull() ) return; |
93 | |
94 | Standard_Real f2d, l2d; |
95 | ShapeAnalysis_Edge sae; |
96 | if(sae.PCurve (E, F, myCurve2d, f2d, l2d, Standard_False)) { |
97 | |
98 | Handle(Geom2dAdaptor_HCurve) AC2d = new Geom2dAdaptor_HCurve(myCurve2d,f2d,l2d); |
99 | Handle(Geom_Surface) aSurface = BRep_Tool::Surface(F,myLocation); |
100 | Handle(GeomAdaptor_HSurface) AdS = new GeomAdaptor_HSurface(aSurface); |
101 | |
102 | Adaptor3d_CurveOnSurface Ad1(AC2d,AdS); |
103 | myAC3d = Ad1;//new Adaptor3d_CurveOnSurface(AC2d,AdS); |
104 | myInitOK = Standard_True; |
105 | } |
106 | } |
107 | |
108 | |
109 | //======================================================================= |
110 | //function : Perform |
111 | //purpose : |
112 | //======================================================================= |
113 | |
114 | Handle(TColStd_HSequenceOfReal) ShapeAnalysis_TransferParametersProj::Perform |
115 | (const Handle(TColStd_HSequenceOfReal)& Knots, |
116 | const Standard_Boolean To2d) |
117 | { |
118 | //pdn |
119 | if( !myInitOK || |
120 | (! myForceProj && myPrecision < myMaxTolerance && BRep_Tool::SameParameter(myEdge))) |
121 | return ShapeAnalysis_TransferParameters::Perform(Knots,To2d); |
122 | |
123 | Handle(TColStd_HSequenceOfReal) resKnots = new TColStd_HSequenceOfReal; |
124 | |
125 | Standard_Integer len = Knots->Length(); |
126 | Standard_Real preci = 2*Precision::PConfusion(); |
127 | |
128 | Standard_Real first = (To2d ? myAC3d.FirstParameter() : myFirst); |
129 | Standard_Real last = (To2d ? myAC3d.LastParameter() : myLast); |
130 | Standard_Real maxPar = first; |
131 | Standard_Real lastPar = last; |
132 | Standard_Real prevPar = maxPar; |
133 | |
134 | Standard_Integer j; // svv Jan 10 2000 : porting on DEC |
135 | for(j = 1; j <= len; j++) { |
136 | Standard_Real par = PreformSegment(Knots->Value(j),To2d,prevPar,lastPar); |
137 | prevPar = par; |
138 | if(prevPar > lastPar) |
139 | prevPar -= preci; |
140 | resKnots->Append(par); |
141 | if(par > maxPar) |
142 | maxPar = par; |
143 | } |
144 | |
145 | //pdn correcting on periodic |
eafb234b |
146 | if(myCurve->IsClosed()) { |
7fd59977 |
147 | for(j = len; j >=1; j--) |
eafb234b |
148 | if(resKnots->Value(j) < maxPar) |
149 | resKnots->SetValue(j,(To2d ? myAC3d.LastParameter() : myCurve->LastParameter())-(len-j)*preci); |
7fd59977 |
150 | else |
eafb234b |
151 | break; |
152 | } |
7fd59977 |
153 | //pdn correction on range |
154 | for ( j=1; j <= len; j++ ) { |
155 | if ( resKnots->Value (j) < first ) resKnots->SetValue ( j, first ); |
156 | if ( resKnots->Value (j) > last ) resKnots->SetValue ( j, last ); |
157 | } |
158 | |
159 | return resKnots; |
160 | } |
161 | |
162 | |
163 | //======================================================================= |
164 | //function : PreformSegment |
165 | //purpose : |
166 | //======================================================================= |
167 | |
168 | Standard_Real ShapeAnalysis_TransferParametersProj::PreformSegment(const Standard_Real Param, |
169 | const Standard_Boolean To2d, |
170 | const Standard_Real First, |
171 | const Standard_Real Last) |
172 | { |
173 | Standard_Real linPar = ShapeAnalysis_TransferParameters::Perform(Param, To2d); |
174 | if( !myInitOK || |
175 | (! myForceProj && myPrecision < myMaxTolerance && BRep_Tool::SameParameter(myEdge))) |
176 | return linPar; |
177 | |
178 | Standard_Real linDev, projDev; |
179 | |
180 | ShapeAnalysis_Curve sac; |
181 | gp_Pnt pproj; |
182 | Standard_Real ppar; |
183 | if(To2d) { |
184 | gp_Pnt p1 = myCurve->Value(Param).Transformed(myLocation.Inverted()); |
185 | Handle(Adaptor3d_HSurface) AdS = myAC3d.GetSurface(); |
186 | Handle(Geom2dAdaptor_HCurve) AC2d = new Geom2dAdaptor_HCurve(myCurve2d,First,Last); |
187 | Adaptor3d_CurveOnSurface Ad1(AC2d,AdS); |
188 | projDev = sac.Project(Ad1,p1,myPrecision,pproj,ppar);//pdn |
189 | linDev = p1.Distance(Ad1.Value(linPar)); |
190 | } |
191 | else { |
192 | gp_Pnt p1 = myAC3d.Value(Param).Transformed(myLocation); |
193 | projDev = sac.Project(myCurve,p1,myPrecision,pproj,ppar,First,Last,Standard_False); |
194 | linDev = p1.Distance(myCurve->Value(linPar)); |
195 | } |
196 | |
197 | if ( linDev <= projDev || (linDev < myPrecision && linDev <= 2 * projDev ) ) |
198 | ppar = linPar; |
199 | return ppar; |
200 | } |
201 | |
202 | |
203 | //======================================================================= |
204 | //function : Perform |
205 | //purpose : |
206 | //======================================================================= |
207 | |
208 | Standard_Real ShapeAnalysis_TransferParametersProj::Perform(const Standard_Real Knot, |
209 | const Standard_Boolean To2d) |
210 | { |
211 | if( !myInitOK || |
212 | (! myForceProj && myPrecision < myMaxTolerance && BRep_Tool::SameParameter(myEdge))) |
213 | return ShapeAnalysis_TransferParameters::Perform(Knot, To2d); |
214 | |
215 | Standard_Real res; |
216 | if(To2d) |
217 | res = PreformSegment(Knot,To2d,myAC3d.FirstParameter(),myAC3d.LastParameter()); |
218 | else |
219 | res = PreformSegment(Knot,To2d,myFirst,myLast); |
220 | |
221 | //pdn correction on range |
222 | Standard_Real first = (To2d ? myAC3d.FirstParameter() : myFirst); |
223 | Standard_Real last = (To2d ? myAC3d.LastParameter() : myLast); |
224 | if ( res < first ) res = first; |
225 | if ( res > last ) res = last; |
226 | return res; |
227 | } |
228 | |
229 | |
230 | //======================================================================= |
231 | //function : CorrectParameter |
232 | //purpose : auxilary |
233 | //======================================================================= |
234 | static Standard_Real CorrectParameter(const Handle(Geom2d_Curve) crv, |
235 | const Standard_Real param) |
236 | { |
237 | if(crv->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) { |
238 | Handle(Geom2d_TrimmedCurve) tmp = Handle(Geom2d_TrimmedCurve)::DownCast (crv); |
239 | return CorrectParameter(tmp->BasisCurve(),param); |
240 | } |
241 | else if(crv->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve))) { |
242 | Handle(Geom2d_OffsetCurve) tmp = Handle(Geom2d_OffsetCurve)::DownCast (crv); |
243 | return CorrectParameter(tmp->BasisCurve(),param); |
244 | } |
245 | else if(crv->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve))) { |
246 | Handle(Geom2d_BSplineCurve) bspline = Handle(Geom2d_BSplineCurve)::DownCast (crv); |
247 | for(Standard_Integer j = bspline->FirstUKnotIndex(); j <= bspline->LastUKnotIndex(); j++) { |
248 | Standard_Real valknot = bspline->Knot(j); |
249 | if( Abs(valknot-param)<Precision::PConfusion() ) |
250 | return valknot; |
251 | } |
252 | } |
253 | return param; |
254 | } |
255 | |
256 | |
257 | //======================================================================= |
258 | //function : TransferRange |
259 | //purpose : |
260 | //======================================================================= |
261 | |
262 | void ShapeAnalysis_TransferParametersProj::TransferRange(TopoDS_Edge& newEdge, |
263 | const Standard_Real prevPar, |
264 | const Standard_Real currPar, |
265 | const Standard_Boolean Is2d) |
266 | { |
267 | if( !myInitOK || |
268 | (! myForceProj && myPrecision < myMaxTolerance && BRep_Tool::SameParameter(myEdge))) { |
269 | ShapeAnalysis_TransferParameters::TransferRange(newEdge,prevPar,currPar,Is2d); |
270 | return; |
271 | } |
272 | |
273 | BRep_Builder B; |
274 | Standard_Boolean samerange = Standard_True; |
275 | ShapeBuild_Edge sbe; |
276 | sbe.CopyRanges(newEdge,myEdge); |
277 | gp_Pnt p1; |
278 | gp_Pnt p2; |
279 | Standard_Real alpha = 0, beta = 1; |
280 | Standard_Real preci = Precision::PConfusion(); |
281 | Standard_Real firstPar, lastPar; |
282 | if(prevPar < currPar) { |
283 | firstPar = prevPar; |
284 | lastPar = currPar; |
285 | } |
286 | else { |
287 | firstPar = currPar; |
288 | lastPar = prevPar; |
289 | } |
290 | if(Is2d) { |
291 | p1 = myAC3d.Value(firstPar).Transformed(myLocation); |
292 | p2 = myAC3d.Value(lastPar).Transformed(myLocation); |
293 | Standard_Real fact = myAC3d.LastParameter() - myAC3d.FirstParameter(); |
294 | if( fact > Epsilon(myAC3d.LastParameter()) ) { |
295 | alpha = ( firstPar - myAC3d.FirstParameter() ) / fact; |
296 | beta = ( lastPar - myAC3d.FirstParameter() ) / fact; |
297 | } |
298 | } |
299 | else { |
300 | p1 = myCurve->Value(firstPar); |
301 | p2 = myCurve->Value(lastPar); |
302 | Standard_Real fact = myLast - myFirst; |
303 | if( fact > Epsilon(myLast) ) { |
304 | alpha = ( firstPar - myFirst ) / fact; |
305 | beta = ( lastPar - myFirst ) / fact; |
306 | } |
307 | } |
308 | const Standard_Boolean useLinearFirst = (alpha < preci); |
309 | const Standard_Boolean useLinearLast = (1-beta < preci); |
310 | TopLoc_Location EdgeLoc = myEdge.Location(); |
311 | ShapeAnalysis_Curve sac; |
312 | gp_Pnt pproj; |
313 | Standard_Real ppar1,ppar2; |
314 | BRep_ListOfCurveRepresentation& tolist = (*((Handle(BRep_TEdge)*)&newEdge.TShape()))->ChangeCurves(); |
315 | Handle(BRep_GCurve) toGC; |
316 | for (BRep_ListIteratorOfListOfCurveRepresentation toitcr (tolist); toitcr.More(); toitcr.Next()) { |
317 | toGC = Handle(BRep_GCurve)::DownCast(toitcr.Value()); |
318 | if ( toGC.IsNull() ) continue; |
319 | TopLoc_Location loc = ( EdgeLoc * toGC->Location() ).Inverted(); |
320 | if ( toGC->IsCurve3D() ) { |
321 | if (!Is2d) { |
322 | ppar1 = firstPar; |
323 | ppar2 = lastPar; |
324 | } |
325 | else { |
326 | Handle(Geom_Curve) C3d = toGC->Curve3D(); |
327 | if (C3d.IsNull()) continue; |
328 | Standard_Real first = toGC->First(); |
329 | Standard_Real last = toGC->Last(); |
330 | Standard_Real len = last -first; |
331 | gp_Pnt ploc1 = p1.Transformed(loc); |
332 | gp_Pnt ploc2 = p2.Transformed(loc); |
333 | GeomAdaptor_Curve GAC(C3d,first,last); |
334 | // CATIA bplseitli.model FAC1155 - Copy: protection for degenerated edges(3d case for symmetry) |
335 | Standard_Real linFirst = first+alpha*len; |
336 | Standard_Real linLast = first+beta*len; |
337 | Standard_Real dist1 = sac.NextProject(linFirst,GAC,ploc1,myPrecision,pproj,ppar1); |
338 | Standard_Real dist2 = sac.NextProject(linLast,GAC,ploc2,myPrecision,pproj,ppar2); |
339 | Standard_Boolean useLinear = Abs(ppar1-ppar2) < preci; |
340 | |
341 | gp_Pnt pos1 = C3d->Value ( linFirst ); |
342 | gp_Pnt pos2 = C3d->Value ( linLast ); |
343 | Standard_Real d01 = pos1.Distance ( ploc1 ); |
344 | Standard_Real d02 = pos2.Distance ( ploc2 ); |
345 | if ( useLinearFirst || useLinear || d01 <= dist1 || ( d01 < myPrecision && d01 <= 2 * dist1 ) ) |
346 | ppar1 = linFirst; |
347 | if ( useLinearLast || useLinear || d02 <= dist2 || ( d02 < myPrecision && d02 <= 2 * dist2 ) ) |
348 | ppar2 = linLast; |
349 | } |
350 | if(ppar1 > ppar2) { |
351 | Standard_Real tmpP = ppar2; ppar2 = ppar1; ppar1 = tmpP; |
352 | } |
353 | if(ppar2-ppar1 < preci) { |
354 | if(ppar1-toGC->First() < preci) |
355 | ppar2+=2*preci; |
356 | else if(toGC->Last()-ppar2 < preci) |
357 | ppar1-=2*preci; |
358 | else { |
359 | ppar1 -= preci; |
360 | ppar2 += preci; |
361 | } |
362 | } |
363 | toGC->SetRange ( ppar1, ppar2); |
364 | //if(fabs(ppar1- firstPar) > Precision::PConfusion() || |
365 | // fabs(ppar2 - lastPar) >Precision::PConfusion()) // by LSS |
366 | if(ppar1!=firstPar || ppar2!=lastPar) |
367 | samerange = Standard_False; |
368 | |
369 | } |
370 | else if (toGC->IsCurveOnSurface()) { //continue; || |
371 | |
372 | Standard_Boolean localLinearFirst = useLinearFirst; |
373 | Standard_Boolean localLinearLast = useLinearLast; |
374 | Handle(Geom2d_Curve) C2d = toGC->PCurve(); |
375 | Standard_Real first = toGC->First(); |
376 | Standard_Real last = toGC->Last(); |
377 | Standard_Real len = last -first; |
378 | Handle(Geom2dAdaptor_HCurve) AC2d = new Geom2dAdaptor_HCurve(toGC->PCurve(),first,last); |
379 | Handle(GeomAdaptor_HSurface) AdS = new GeomAdaptor_HSurface( toGC->Surface()); |
380 | Adaptor3d_CurveOnSurface Ad1(AC2d,AdS); |
381 | ShapeAnalysis_Curve sac1; |
382 | |
383 | //gp_Pnt p1 = Ad1.Value(prevPar); |
384 | //gp_Pnt p2 = Ad1.Value(currPar); |
385 | gp_Pnt ploc1 = p1.Transformed(loc); |
386 | gp_Pnt ploc2 = p2.Transformed(loc); |
387 | // CATIA bplseitli.model FAC1155 - Copy: protection for degenerated edges |
388 | Standard_Real linFirst = first+alpha*len; |
389 | Standard_Real linLast = first+beta*len; |
390 | Standard_Real dist1 = sac1.NextProject(linFirst, Ad1, ploc1, myPrecision,pproj,ppar1); |
391 | Standard_Real dist2 = sac1.NextProject(linLast, Ad1, ploc2, myPrecision,pproj,ppar2); |
392 | |
393 | Standard_Boolean isFirstOnEnd = (ppar1-first)/len < Precision::PConfusion(); |
394 | Standard_Boolean isLastOnEnd = (last-ppar2)/len < Precision::PConfusion(); |
395 | Standard_Boolean useLinear = Abs(ppar1-ppar2) < Precision::PConfusion(); |
396 | if(isFirstOnEnd && ! localLinearFirst) |
397 | localLinearFirst = Standard_True; |
398 | if(isLastOnEnd && ! localLinearLast) |
399 | localLinearLast = Standard_True; |
400 | |
401 | gp_Pnt pos1 = Ad1.Value ( linFirst ); |
402 | gp_Pnt pos2 = Ad1.Value ( linLast ); |
403 | Standard_Real d01 = pos1.Distance ( ploc1 ); |
404 | Standard_Real d02 = pos2.Distance ( ploc2 ); |
405 | if ( localLinearFirst || useLinear || d01 <= dist1 || ( d01 < myPrecision && d01 <= 2 * dist1 ) ) |
406 | ppar1 = linFirst; |
407 | if ( localLinearLast || useLinear || d02 <= dist2 || ( d02 < myPrecision && d02 <= 2 * dist2 ) ) |
408 | ppar2 = linLast; |
409 | |
410 | if(ppar1 > ppar2) { |
411 | Standard_Real tmpP = ppar2; ppar2 = ppar1; ppar1 = tmpP; |
412 | } |
413 | ppar1 = CorrectParameter(C2d,ppar1); |
414 | ppar2 = CorrectParameter(C2d,ppar2); |
415 | if(ppar2-ppar1 < preci) { |
416 | if(ppar1-toGC->First() < preci) |
417 | ppar2+=2*preci; |
418 | else if(toGC->Last()-ppar2 < preci) |
419 | ppar1-=2*preci; |
420 | else { |
421 | ppar1 -= preci; |
422 | ppar2 += preci; |
423 | } |
424 | } |
425 | toGC->SetRange ( ppar1, ppar2); |
426 | //if(fabs(ppar1 - firstPar) > Precision::PConfusion() || |
427 | // fabs(ppar2 -lastPar) > Precision::PConfusion())// by LSS |
428 | if(ppar1 != firstPar || ppar2 != lastPar) |
429 | samerange = Standard_False; |
430 | } |
431 | } |
432 | B.SameRange(newEdge, samerange); |
433 | } |
434 | |
435 | |
436 | //======================================================================= |
437 | //function : IsSameRange |
438 | //purpose : |
439 | //======================================================================= |
440 | |
441 | Standard_Boolean ShapeAnalysis_TransferParametersProj::IsSameRange() const |
442 | { |
443 | |
444 | if( !myInitOK || |
445 | (! myForceProj && myPrecision < myMaxTolerance && BRep_Tool::SameParameter(myEdge))) |
446 | return ShapeAnalysis_TransferParameters::IsSameRange(); |
447 | else |
448 | return Standard_False; |
449 | } |
450 | |
451 | |
452 | //======================================================================= |
453 | //function : ForceProjection |
454 | //purpose : |
455 | //======================================================================= |
456 | |
457 | Standard_Boolean& ShapeAnalysis_TransferParametersProj::ForceProjection() |
458 | { |
459 | return myForceProj; |
460 | } |
461 | |
462 | //======================================================================= |
463 | //function : CopyNMVertex |
464 | //purpose : |
465 | //======================================================================= |
466 | |
467 | TopoDS_Vertex ShapeAnalysis_TransferParametersProj::CopyNMVertex (const TopoDS_Vertex& theV, |
468 | const TopoDS_Edge& toedge, |
469 | const TopoDS_Edge& fromedge) |
470 | { |
471 | TopoDS_Vertex anewV; |
472 | if(theV.Orientation() != TopAbs_INTERNAL && |
473 | theV.Orientation() != TopAbs_EXTERNAL) |
474 | return anewV; |
475 | |
476 | TopLoc_Location fromLoc; |
477 | Standard_Real f1,l1; |
478 | const Handle(Geom_Curve)& C1 = BRep_Tool::Curve(fromedge,fromLoc,f1,l1); |
479 | fromLoc = fromLoc.Predivided(theV.Location()); |
480 | |
481 | Standard_Real f2,l2; |
482 | Handle(Geom_Curve) C2 = BRep_Tool::Curve(toedge,f2,l2); |
483 | |
484 | anewV = TopoDS::Vertex(theV.EmptyCopied()); |
485 | gp_Pnt apv = BRep_Tool::Pnt(anewV); |
486 | |
487 | BRep_ListOfPointRepresentation& alistrep = |
488 | (*((Handle(BRep_TVertex)*)&anewV.TShape()))->ChangePoints(); |
489 | |
490 | BRep_ListIteratorOfListOfPointRepresentation itpr |
491 | ((*((Handle(BRep_TVertex)*) &theV.TShape()))->Points()); |
492 | |
493 | Standard_Real aOldPar = RealLast(); |
494 | Standard_Boolean hasRepr = Standard_False; |
495 | for ( ;itpr.More(); itpr.Next()) { |
496 | const Handle(BRep_PointRepresentation)& pr = itpr.Value(); |
497 | if(pr.IsNull()) |
498 | continue; |
499 | if(pr->IsPointOnCurve(C1,fromLoc)) { |
500 | aOldPar = pr->Parameter(); |
501 | hasRepr =Standard_True; |
502 | continue; |
503 | } |
504 | else if(pr->IsPointOnSurface()) { |
505 | Handle(BRep_PointOnSurface) aOld = Handle(BRep_PointOnSurface)::DownCast(pr); |
506 | Handle(BRep_PointOnSurface) aPS = new BRep_PointOnSurface(aOld->Parameter(), |
507 | aOld->Parameter2(), |
508 | aOld->Surface(), |
509 | aOld->Location()); |
510 | alistrep.Append(aPS); |
511 | continue; |
512 | } |
513 | else if(pr->IsPointOnCurveOnSurface()) { |
514 | Standard_Boolean found = Standard_False; |
515 | BRep_ListIteratorOfListOfCurveRepresentation fromitcr |
516 | ((*((Handle(BRep_TEdge)*)&fromedge.TShape()))->ChangeCurves()); |
517 | |
518 | for( ;fromitcr.More() && !found; fromitcr.Next()) { |
519 | Handle(BRep_GCurve) fromGC = Handle(BRep_GCurve)::DownCast(fromitcr.Value()); |
520 | if ( fromGC.IsNull() || !fromGC->IsCurveOnSurface()) continue; |
521 | |
522 | TopLoc_Location aL = fromGC->Location(); |
523 | aL.Predivided(theV.Location()); |
524 | Handle(Geom_Surface) surface1 = fromGC->Surface(); |
525 | Handle(Geom2d_Curve) ac2d1 = fromGC->PCurve(); |
526 | if (pr->IsPointOnCurveOnSurface(ac2d1,surface1,aL)) { |
527 | found = Standard_True; |
528 | if(!hasRepr) { |
529 | aOldPar = pr->Parameter(); |
530 | } |
531 | } |
532 | } |
533 | if(found) continue; |
534 | } |
535 | if(pr->IsPointOnCurve()) { |
536 | Handle(BRep_PointOnCurve) aPRep = new BRep_PointOnCurve(pr->Parameter(),pr->Curve(),pr->Location()); |
537 | alistrep.Append(aPRep); |
538 | } |
539 | else if(pr->IsPointOnCurveOnSurface() ) { |
540 | Handle(BRep_PointOnCurveOnSurface) aPonCS = |
541 | new BRep_PointOnCurveOnSurface(pr->Parameter(),pr->PCurve(),pr->Surface(),pr->Location()); |
542 | alistrep.Append(aPonCS); |
543 | } |
544 | } |
545 | Standard_Real apar = aOldPar; |
546 | Standard_Real aTol = BRep_Tool::Tolerance(theV); |
547 | if(!hasRepr || (fabs(f1-f2) > Precision::PConfusion() || fabs(l1-l2)> Precision::PConfusion())) { |
548 | gp_Pnt projP; |
549 | ShapeAnalysis_Curve sae; |
550 | Standard_Real adist = sae.Project(C2,apv,Precision::Confusion(),projP,apar); |
551 | if(aTol < adist) |
552 | aTol = adist; |
553 | } |
554 | BRep_Builder aB; |
555 | aB.UpdateVertex(anewV,apar,toedge,aTol); |
556 | |
557 | //update tolerance |
558 | Standard_Boolean needUpdate = Standard_False; |
559 | gp_Pnt aPV = (*((Handle(BRep_TVertex)*)&anewV.TShape()))->Pnt(); |
560 | TopLoc_Location toLoc = toedge.Location(); |
561 | BRep_ListIteratorOfListOfCurveRepresentation toitcr |
562 | ((*((Handle(BRep_TEdge)*)&toedge.TShape()))->ChangeCurves()); |
563 | |
564 | for( ;toitcr.More() ; toitcr.Next()) { |
565 | Handle(BRep_GCurve) toGC = Handle(BRep_GCurve)::DownCast(toitcr.Value()); |
566 | if ( toGC.IsNull() || !toGC->IsCurveOnSurface()) continue; |
567 | |
568 | TopLoc_Location aL = (toLoc*toGC->Location()).Predivided(theV.Location()); |
569 | //aL.Predivided(theV.Location()); |
570 | Handle(Geom_Surface) surface1 = toGC->Surface(); |
571 | Handle(Geom2d_Curve) ac2d1 = toGC->PCurve(); |
572 | gp_Pnt2d aP2d = ac2d1->Value(apar); |
573 | gp_Pnt aP3d = surface1->Value(aP2d.X(),aP2d.Y()); |
574 | aP3d.Transform(aL.Transformation()); |
575 | Standard_Real adist = aPV.Distance(aP3d); |
576 | if(adist > aTol) { |
577 | aTol = adist; |
578 | needUpdate = Standard_True; |
579 | } |
580 | |
581 | } |
582 | if(needUpdate) |
583 | aB.UpdateVertex(anewV,aTol); |
584 | return anewV; |
585 | } |
586 | |
587 | //======================================================================= |
588 | //function : CopyNMVertex |
589 | //purpose : |
590 | //======================================================================= |
591 | |
592 | TopoDS_Vertex ShapeAnalysis_TransferParametersProj::CopyNMVertex (const TopoDS_Vertex& theV, |
593 | const TopoDS_Face& toFace, |
594 | const TopoDS_Face& fromFace) |
595 | { |
596 | TopoDS_Vertex anewV; |
597 | if(theV.Orientation() != TopAbs_INTERNAL && |
598 | theV.Orientation() != TopAbs_EXTERNAL) |
599 | return anewV; |
600 | |
601 | |
602 | TopLoc_Location fromLoc; |
603 | TopLoc_Location toLoc; |
604 | Handle(Geom_Surface) fromSurf = BRep_Tool::Surface(fromFace,fromLoc); |
605 | Handle(Geom_Surface) toSurf = BRep_Tool::Surface(toFace,toLoc); |
606 | fromLoc = fromLoc.Predivided(theV.Location()); |
607 | |
608 | anewV = TopoDS::Vertex(theV.EmptyCopied()); |
609 | gp_Pnt apv = BRep_Tool::Pnt(anewV); |
610 | |
611 | |
612 | BRep_ListOfPointRepresentation& alistrep = |
613 | (*((Handle(BRep_TVertex)*)&anewV.TShape()))->ChangePoints(); |
614 | |
615 | BRep_ListIteratorOfListOfPointRepresentation itpr |
616 | ((*((Handle(BRep_TVertex)*) &theV.TShape()))->Points()); |
617 | |
618 | Standard_Boolean hasRepr = Standard_False; |
619 | Standard_Real apar1=0., apar2=0.; |
620 | for ( ;itpr.More(); itpr.Next()) { |
621 | const Handle(BRep_PointRepresentation)& pr = itpr.Value(); |
622 | if(pr.IsNull()) |
623 | continue; |
624 | TopLoc_Location aLoc = pr->Location(); |
625 | if( pr->IsPointOnCurveOnSurface()) { |
626 | Handle(BRep_PointOnCurveOnSurface) aPonCS = |
627 | new BRep_PointOnCurveOnSurface(pr->Parameter(),pr->PCurve(),pr->Surface(),aLoc); |
628 | alistrep.Append(aPonCS); |
629 | } |
630 | else if(pr->IsPointOnCurve()) { |
631 | Handle(BRep_PointOnCurve) aPRep = new BRep_PointOnCurve(pr->Parameter(),pr->Curve(),aLoc); |
632 | alistrep.Append(aPRep); |
633 | } |
634 | else if(pr->IsPointOnSurface()) { |
635 | Handle(BRep_PointOnSurface) aOld = Handle(BRep_PointOnSurface)::DownCast(pr); |
636 | |
637 | if(pr->IsPointOnSurface(fromSurf,fromLoc)) { |
638 | apar1= aOld->Parameter(); |
639 | apar2 = aOld->Parameter2(); |
640 | hasRepr = Standard_True; |
641 | } |
642 | else { |
643 | Handle(BRep_PointOnSurface) aPS = new BRep_PointOnSurface(aOld->Parameter(), |
644 | aOld->Parameter2(), |
645 | aOld->Surface(), |
646 | aOld->Location()); |
647 | alistrep.Append(aPS); |
648 | } |
649 | } |
650 | |
651 | } |
652 | Standard_Real aTol = BRep_Tool::Tolerance(anewV); |
653 | if(!hasRepr || (fromSurf != toSurf || fromLoc != toLoc)) { |
654 | Handle(Geom_Surface) aS = BRep_Tool::Surface(toFace); |
655 | Handle(ShapeAnalysis_Surface) aSurfTool = new ShapeAnalysis_Surface(aS); |
656 | gp_Pnt2d aP2d = aSurfTool->ValueOfUV(apv,Precision::Confusion()); |
657 | apar1 = aP2d.X(); |
658 | apar2 = aP2d.Y(); |
659 | |
660 | if(aTol < aSurfTool->Gap()) |
661 | aTol = aSurfTool->Gap() + 0.1*Precision::Confusion(); |
662 | //Handle(BRep_PointOnSurface) aPS = new BRep_PointOnSurface(aP2d.X(),aP2d.Y(),toSurf,toLoc); |
663 | //alistrep.Append(aPS); |
664 | } |
665 | |
666 | BRep_Builder aB; |
667 | aB.UpdateVertex(anewV,apar1,apar2,toFace,aTol); |
668 | return anewV; |
669 | } |
670 | |