1 // Created on: 2014-10-14
2 // Created by: Anton POLETAEV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <StdPrs_Isolines.hxx>
18 #include <Adaptor3d_IsoCurve.hxx>
19 #include <BRepTools.hxx>
20 #include <BRep_Tool.hxx>
21 #include <GCPnts_AbscissaPoint.hxx>
22 #include <GCPnts_QuasiUniformDeflection.hxx>
23 #include <Geom_BezierSurface.hxx>
24 #include <Geom_BSplineSurface.hxx>
25 #include <Geom_Plane.hxx>
26 #include <Geom_Line.hxx>
27 #include <Geom2d_Line.hxx>
28 #include <Geom2dAdaptor_Curve.hxx>
29 #include <GeomAdaptor_Curve.hxx>
30 #include <GeomLib_Tool.hxx>
31 #include <gp_Lin2d.hxx>
32 #include <Hatch_Hatcher.hxx>
33 #include <NCollection_Shared.hxx>
35 #include <Prs3d_IsoAspect.hxx>
36 #include <Poly_Array1OfTriangle.hxx>
37 #include <Poly_Triangulation.hxx>
38 #include <StdPrs_DeflectionCurve.hxx>
39 #include <StdPrs_ToolRFace.hxx>
40 #include <TColgp_SequenceOfPnt2d.hxx>
41 #include <Standard_ErrorHandler.hxx>
42 #include <Geom_Surface.hxx>
43 #include <Geom_OffsetSurface.hxx>
44 #include <Geom_RectangularTrimmedSurface.hxx>
49 const gp_Lin2d isoU (const Standard_Real theU) { return gp_Lin2d (gp_Pnt2d (theU, 0.0), gp::DY2d()); }
50 const gp_Lin2d isoV (const Standard_Real theV) { return gp_Lin2d (gp_Pnt2d (0.0, theV), gp::DX2d()); }
52 typedef NCollection_Shared< NCollection_Vector<StdPrs_Isolines::SegOnIso> > VecOfSegments;
53 typedef NCollection_Sequence<Handle(VecOfSegments)> SeqOfVecOfSegments;
55 //! Pack isoline segments into polylines.
56 static void sortSegments (const SeqOfVecOfSegments& theSegments,
57 Prs3d_NListOfSequenceOfPnt& thePolylines)
59 for (SeqOfVecOfSegments::Iterator aLineIter (theSegments); aLineIter.More(); aLineIter.Next())
61 Handle(VecOfSegments)& anIsoSegs = aLineIter.ChangeValue();
62 std::stable_sort (anIsoSegs->begin(), anIsoSegs->end());
64 Handle(TColgp_HSequenceOfPnt) aPolyline = new TColgp_HSequenceOfPnt();
65 thePolylines.Append (aPolyline);
66 Standard_Real aLast = 0.0;
67 for (VecOfSegments::Iterator aSegIter (*anIsoSegs); aSegIter.More(); aSegIter.Next())
69 if (!aPolyline->IsEmpty()
70 && Abs (aSegIter.Value()[0].Param - aLast) > Precision::PConfusion())
72 aPolyline = new TColgp_HSequenceOfPnt();
73 thePolylines.Append (aPolyline);
76 aPolyline->Append (aSegIter.Value()[0].Pnt);
77 aPolyline->Append (aSegIter.Value()[1].Pnt);
78 aLast = aSegIter.Value()[1].Param;
83 //! Reoder and adjust to the limit a curve's parameter values.
84 //! @param theCurve [in] the curve.
85 //! @param theLimit [in] the parameter limit value.
86 //! @param theFirst [in/out] the first parameter value.
87 //! @param theLast [in/out] the last parameter value.
88 static void findLimits (const Adaptor3d_Curve& theCurve,
89 const Standard_Real theLimit,
90 Standard_Real& theFirst,
91 Standard_Real& theLast)
93 theFirst = Max (theCurve.FirstParameter(), theFirst);
94 theLast = Min (theCurve.LastParameter(), theLast);
96 Standard_Boolean isFirstInf = Precision::IsNegativeInfinite (theFirst);
97 Standard_Boolean isLastInf = Precision::IsPositiveInfinite (theLast);
99 if (!isFirstInf && !isLastInf)
105 Standard_Real aDelta = 1.0;
106 if (isFirstInf && isLastInf)
113 theCurve.D0 (theFirst, aP1);
114 theCurve.D0 (theLast, aP2);
116 while (aP1.Distance (aP2) < theLimit);
120 theCurve.D0 (theLast, aP2);
124 theFirst = theLast - aDelta;
125 theCurve.D0 (theFirst, aP1);
127 while (aP1.Distance (aP2) < theLimit);
131 theCurve.D0 (theFirst, aP1);
135 theLast = theFirst + aDelta;
136 theCurve.D0 (theLast, aP2);
138 while (aP1.Distance (aP2) < theLimit);
144 //==================================================================
145 // function : AddOnTriangulation
147 //==================================================================
148 void StdPrs_Isolines::AddOnTriangulation (const Handle(Prs3d_Presentation)& thePresentation,
149 const TopoDS_Face& theFace,
150 const Handle(Prs3d_Drawer)& theDrawer)
152 Prs3d_NListOfSequenceOfPnt aUPolylines, aVPolylines;
153 AddOnTriangulation (theFace, theDrawer, aUPolylines, aVPolylines);
154 Prs3d::AddPrimitivesGroup (thePresentation, theDrawer->UIsoAspect(), aUPolylines);
155 Prs3d::AddPrimitivesGroup (thePresentation, theDrawer->VIsoAspect(), aVPolylines);
158 //==================================================================
159 // function : AddOnTriangulation
161 //==================================================================
162 void StdPrs_Isolines::AddOnTriangulation (const TopoDS_Face& theFace,
163 const Handle(Prs3d_Drawer)& theDrawer,
164 Prs3d_NListOfSequenceOfPnt& theUPolylines,
165 Prs3d_NListOfSequenceOfPnt& theVPolylines)
167 const Standard_Integer aNbIsoU = theDrawer->UIsoAspect()->Number();
168 const Standard_Integer aNbIsoV = theDrawer->VIsoAspect()->Number();
169 if (aNbIsoU < 1 && aNbIsoV < 1)
174 // Evaluate parameters for uv isolines.
175 TColStd_SequenceOfReal aUIsoParams;
176 TColStd_SequenceOfReal aVIsoParams;
177 Standard_Real aUmin = 0., aUmax = 0., aVmin = 0., aVmax = 0.;
178 UVIsoParameters (theFace, aNbIsoU, aNbIsoV, theDrawer->MaximalParameterValue(), aUIsoParams, aVIsoParams,
179 aUmin, aUmax, aVmin, aVmax);
181 // Access surface definition.
182 TopLoc_Location aLocSurface;
183 Handle(Geom_Surface) aSurface = BRep_Tool::Surface (theFace, aLocSurface);
184 if (aSurface.IsNull())
189 // Access triangulation.
190 TopLoc_Location aLocTriangulation;
191 const Handle(Poly_Triangulation)& aTriangulation = BRep_Tool::Triangulation (theFace, aLocTriangulation);
192 if (aTriangulation.IsNull())
197 // Setup equal location for surface and triangulation.
198 if (!aLocTriangulation.IsEqual (aLocSurface))
200 aSurface = Handle (Geom_Surface)::DownCast (
201 aSurface->Transformed ((aLocSurface / aLocTriangulation).Transformation()));
204 const Handle(Standard_Type)& TheType = aSurface->DynamicType();
205 if (TheType == STANDARD_TYPE(Geom_OffsetSurface))
207 Standard_Real u1, u2, v1, v2;
208 aSurface->Bounds(u1, u2, v1, v2);
209 //Isolines of Offset surfaces are calculated by approximation and
210 //cannot be calculated for infinite limits.
211 if (Precision::IsInfinite(u1) || Precision::IsInfinite(u2) ||
212 Precision::IsInfinite(v1) || Precision::IsInfinite(v2))
218 aSurface = new Geom_RectangularTrimmedSurface(aSurface, u1, u2, v1, v2);
222 addOnTriangulation (aTriangulation, aSurface, aLocTriangulation, aUIsoParams, aVIsoParams, theUPolylines, theVPolylines);
225 //==================================================================
226 // function : AddOnTriangulation
228 //==================================================================
229 void StdPrs_Isolines::AddOnTriangulation (const Handle(Prs3d_Presentation)& thePresentation,
230 const Handle(Poly_Triangulation)& theTriangulation,
231 const Handle(Geom_Surface)& theSurface,
232 const TopLoc_Location& theLocation,
233 const Handle(Prs3d_Drawer)& theDrawer,
234 const TColStd_SequenceOfReal& theUIsoParams,
235 const TColStd_SequenceOfReal& theVIsoParams)
237 Prs3d_NListOfSequenceOfPnt aUPolylines, aVPolylines;
238 addOnTriangulation (theTriangulation, theSurface, theLocation, theUIsoParams, theVIsoParams, aUPolylines, aVPolylines);
239 Prs3d::AddPrimitivesGroup (thePresentation, theDrawer->UIsoAspect(), aUPolylines);
240 Prs3d::AddPrimitivesGroup (thePresentation, theDrawer->VIsoAspect(), aVPolylines);
243 //==================================================================
244 // function : addOnTriangulation
246 //==================================================================
247 void StdPrs_Isolines::addOnTriangulation (const Handle(Poly_Triangulation)& theTriangulation,
248 const Handle(Geom_Surface)& theSurface,
249 const TopLoc_Location& theLocation,
250 const TColStd_SequenceOfReal& theUIsoParams,
251 const TColStd_SequenceOfReal& theVIsoParams,
252 Prs3d_NListOfSequenceOfPnt& theUPolylines,
253 Prs3d_NListOfSequenceOfPnt& theVPolylines)
255 const Poly_Array1OfTriangle& aTriangles = theTriangulation->Triangles();
256 const TColgp_Array1OfPnt& aNodes = theTriangulation->Nodes();
257 const TColgp_Array1OfPnt2d& aUVNodes = theTriangulation->UVNodes();
258 for (Standard_Integer anUVIter = 0; anUVIter < 2; ++anUVIter)
260 const Standard_Boolean isUIso = anUVIter == 0;
261 const TColStd_SequenceOfReal& anIsoParams = isUIso ? theUIsoParams : theVIsoParams;
262 const Standard_Integer aNbIsolines = anIsoParams.Length();
263 if (aNbIsolines == 0)
268 SeqOfVecOfSegments aPolylines;
269 TColStd_Array1OfInteger anIsoIndexes (1, aNbIsolines);
270 anIsoIndexes.Init (-1);
271 for (Standard_Integer anIsoIdx = 1; anIsoIdx <= aNbIsolines; ++anIsoIdx)
273 const gp_Lin2d anIsolineUV = isUIso ? isoU (anIsoParams.Value (anIsoIdx)) : isoV (anIsoParams.Value (anIsoIdx));
274 Handle(VecOfSegments) anIsoPnts;
275 if (anIsoIndexes.Value (anIsoIdx) != -1)
277 anIsoPnts = aPolylines.ChangeValue (anIsoIndexes.Value (anIsoIdx));
280 for (Standard_Integer aTriIter = aTriangles.Lower(); aTriIter <= aTriangles.Upper(); ++aTriIter)
282 Standard_Integer aNodeIdxs[3];
283 aTriangles.Value (aTriIter).Get (aNodeIdxs[0], aNodeIdxs[1],aNodeIdxs[2]);
284 const gp_Pnt aNodesXYZ[3] = { aNodes.Value (aNodeIdxs[0]),
285 aNodes.Value (aNodeIdxs[1]),
286 aNodes.Value (aNodeIdxs[2]) };
287 const gp_Pnt2d aNodesUV[3] = { aUVNodes.Value (aNodeIdxs[0]),
288 aUVNodes.Value (aNodeIdxs[1]),
289 aUVNodes.Value (aNodeIdxs[2]) };
291 // Find intersections with triangle in uv space and its projection on triangulation.
293 if (!findSegmentOnTriangulation (theSurface, isUIso, anIsolineUV, aNodesXYZ, aNodesUV, aSegment))
298 if (anIsoPnts.IsNull())
300 aPolylines.Append (new VecOfSegments());
301 anIsoIndexes.SetValue (anIsoIdx, aPolylines.Size());
302 anIsoPnts = aPolylines.ChangeValue (anIsoIndexes.Value (anIsoIdx));
305 if (!theLocation.IsIdentity())
307 aSegment[0].Pnt.Transform (theLocation);
308 aSegment[1].Pnt.Transform (theLocation);
310 anIsoPnts->Append (aSegment);
314 sortSegments (aPolylines, isUIso ? theUPolylines : theVPolylines);
318 //==================================================================
319 // function : AddOnSurface
321 //==================================================================
322 void StdPrs_Isolines::AddOnSurface (const Handle(Prs3d_Presentation)& thePresentation,
323 const TopoDS_Face& theFace,
324 const Handle(Prs3d_Drawer)& theDrawer,
325 const Standard_Real theDeflection)
327 Prs3d_NListOfSequenceOfPnt aUPolylines, aVPolylines;
328 AddOnSurface (theFace, theDrawer, theDeflection, aUPolylines, aVPolylines);
329 Prs3d::AddPrimitivesGroup (thePresentation, theDrawer->UIsoAspect(), aUPolylines);
330 Prs3d::AddPrimitivesGroup (thePresentation, theDrawer->VIsoAspect(), aVPolylines);
333 //==================================================================
334 // function : AddOnSurface
336 //==================================================================
337 void StdPrs_Isolines::AddOnSurface (const TopoDS_Face& theFace,
338 const Handle(Prs3d_Drawer)& theDrawer,
339 const Standard_Real theDeflection,
340 Prs3d_NListOfSequenceOfPnt& theUPolylines,
341 Prs3d_NListOfSequenceOfPnt& theVPolylines)
343 const Standard_Integer aNbIsoU = theDrawer->UIsoAspect()->Number();
344 const Standard_Integer aNbIsoV = theDrawer->VIsoAspect()->Number();
345 if (aNbIsoU < 1 && aNbIsoV < 1)
350 // Evaluate parameters for uv isolines.
351 TColStd_SequenceOfReal aUIsoParams, aVIsoParams;
352 Standard_Real aUmin = 0., aUmax = 0., aVmin = 0., aVmax = 0.;
353 UVIsoParameters (theFace, aNbIsoU, aNbIsoV, theDrawer->MaximalParameterValue(), aUIsoParams, aVIsoParams,
354 aUmin, aUmax, aVmin, aVmax);
356 BRepAdaptor_Surface aSurface (theFace);
357 addOnSurface (new BRepAdaptor_HSurface (aSurface),
366 //==================================================================
367 // function : AddOnSurface
369 //==================================================================
370 void StdPrs_Isolines::AddOnSurface (const Handle(Prs3d_Presentation)& thePresentation,
371 const Handle(BRepAdaptor_HSurface)& theSurface,
372 const Handle(Prs3d_Drawer)& theDrawer,
373 const Standard_Real theDeflection,
374 const TColStd_SequenceOfReal& theUIsoParams,
375 const TColStd_SequenceOfReal& theVIsoParams)
377 Prs3d_NListOfSequenceOfPnt aUPolylines, aVPolylines;
378 addOnSurface (theSurface, theDrawer, theDeflection, theUIsoParams, theVIsoParams, aUPolylines, aVPolylines);
379 Prs3d::AddPrimitivesGroup (thePresentation, theDrawer->UIsoAspect(), aUPolylines);
380 Prs3d::AddPrimitivesGroup (thePresentation, theDrawer->VIsoAspect(), aVPolylines);
383 //==================================================================
384 // function : addOnSurface
386 //==================================================================
387 void StdPrs_Isolines::addOnSurface (const Handle(BRepAdaptor_HSurface)& theSurface,
388 const Handle(Prs3d_Drawer)& theDrawer,
389 const Standard_Real theDeflection,
390 const TColStd_SequenceOfReal& theUIsoParams,
391 const TColStd_SequenceOfReal& theVIsoParams,
392 Prs3d_NListOfSequenceOfPnt& theUPolylines,
393 Prs3d_NListOfSequenceOfPnt& theVPolylines)
395 // Choose a deflection for sampling edge uv curves.
396 Standard_Real aUVLimit = theDrawer->MaximalParameterValue();
397 Standard_Real aUmin = Max (theSurface->FirstUParameter(), -aUVLimit);
398 Standard_Real aUmax = Min (theSurface->LastUParameter(), aUVLimit);
399 Standard_Real aVmin = Max (theSurface->FirstVParameter(), -aUVLimit);
400 Standard_Real aVmax = Min (theSurface->LastVParameter(), aUVLimit);
401 Standard_Real aSamplerDeflection = Max (aUmax - aUmin, aVmax - aVmin) * theDrawer->DeviationCoefficient();
402 Standard_Real aHatchingTolerance = RealLast();
407 // Determine edge points for trimming uv hatch region.
408 TColgp_SequenceOfPnt2d aTrimPoints;
409 StdPrs_ToolRFace anEdgeTool (theSurface);
410 for (anEdgeTool.Init(); anEdgeTool.More(); anEdgeTool.Next())
412 TopAbs_Orientation anOrientation = anEdgeTool.Orientation();
413 const Adaptor2d_Curve2d* anEdgeCurve = &anEdgeTool.Value();
414 if (anEdgeCurve->GetType() != GeomAbs_Line)
416 GCPnts_QuasiUniformDeflection aSampler (*anEdgeCurve, aSamplerDeflection);
417 if (!aSampler.IsDone())
420 std::cout << "Cannot evaluate curve on surface" << std::endl;
425 Standard_Integer aNumberOfPoints = aSampler.NbPoints();
426 if (aNumberOfPoints < 2)
431 for (Standard_Integer anI = 1; anI < aNumberOfPoints; ++anI)
433 gp_Pnt2d aP1 (aSampler.Value (anI ).X(), aSampler.Value (anI ).Y());
434 gp_Pnt2d aP2 (aSampler.Value (anI + 1).X(), aSampler.Value (anI + 1).Y());
436 aHatchingTolerance = Min (aP1.SquareDistance (aP2), aHatchingTolerance);
438 aTrimPoints.Append (anOrientation == TopAbs_FORWARD ? aP1 : aP2);
439 aTrimPoints.Append (anOrientation == TopAbs_FORWARD ? aP2 : aP1);
444 Standard_Real aU1 = anEdgeCurve->FirstParameter();
445 Standard_Real aU2 = anEdgeCurve->LastParameter();
447 // MSV 17.08.06 OCC13144: U2 occured less than U1, to overcome it
448 // ensure that distance U2-U1 is not greater than aLimit*2,
449 // if greater then choose an origin and use aLimit to define
451 Standard_Real anOrigin = 0.0;
453 if (!Precision::IsNegativeInfinite (aU1) || !Precision::IsPositiveInfinite(aU2))
455 if (Precision::IsNegativeInfinite (aU1))
457 anOrigin = aU2 - aUVLimit;
459 else if (Precision::IsPositiveInfinite (aU2))
461 anOrigin = aU1 + aUVLimit;
465 anOrigin = (aU1 + aU2) * 0.5;
469 aU1 = Max (anOrigin - aUVLimit, aU1);
470 aU2 = Min (anOrigin + aUVLimit, aU2);
472 gp_Pnt2d aP1 = anEdgeCurve->Value (aU1);
473 gp_Pnt2d aP2 = anEdgeCurve->Value (aU2);
475 aHatchingTolerance = Min (aP1.SquareDistance(aP2), aHatchingTolerance);
477 aTrimPoints.Append (anOrientation == TopAbs_FORWARD ? aP1 : aP2);
478 aTrimPoints.Append (anOrientation == TopAbs_FORWARD ? aP2 : aP1);
482 // Compute a hatching tolerance.
483 aHatchingTolerance *= 0.1;
484 aHatchingTolerance = Max (Precision::Confusion(), aHatchingTolerance);
485 aHatchingTolerance = Min (1.0E-5, aHatchingTolerance);
487 // Load isolines into hatcher.
488 Hatch_Hatcher aHatcher (aHatchingTolerance, anEdgeTool.IsOriented());
490 for (Standard_Integer anIso = 1; anIso <= theUIsoParams.Length(); ++anIso)
492 aHatcher.AddXLine (theUIsoParams.Value (anIso));
494 for (Standard_Integer anIso = 1; anIso <= theVIsoParams.Length(); ++anIso)
496 aHatcher.AddYLine (theVIsoParams.Value (anIso));
499 // Trim hatching region.
500 for (Standard_Integer anI = 1; anI <= aTrimPoints.Length(); anI += 2)
502 aHatcher.Trim (aTrimPoints (anI), aTrimPoints (anI + 1));
505 // Use surface definition for evaluation of Bezier, B-spline surface.
506 // Use isoline adapter for other types of surfaces.
507 GeomAbs_SurfaceType aSurfType = theSurface->GetType();
508 Handle(Geom_Surface) aBSurface;
509 GeomAdaptor_Curve aBSurfaceCurve;
510 Adaptor3d_IsoCurve aCanonicalCurve;
511 if (aSurfType == GeomAbs_BezierSurface)
513 aBSurface = theSurface->Bezier();
515 else if (aSurfType == GeomAbs_BSplineSurface)
517 aBSurface = theSurface->BSpline();
521 aCanonicalCurve.Load (theSurface);
524 // For each isoline: compute its segments.
525 for (Standard_Integer anI = 1; anI <= aHatcher.NbLines(); anI++)
527 Standard_Real anIsoParam = aHatcher.Coordinate (anI);
528 Standard_Boolean isIsoU = aHatcher.IsXLine (anI);
530 // For each isoline's segment: evaluate its points.
531 for (Standard_Integer aJ = 1; aJ <= aHatcher.NbIntervals (anI); aJ++)
533 Standard_Real aSegmentP1 = aHatcher.Start (anI, aJ);
534 Standard_Real aSegmentP2 = aHatcher.End (anI, aJ);
536 if (!aBSurface.IsNull())
538 aBSurfaceCurve.Load (isIsoU ? aBSurface->UIso (anIsoParam) : aBSurface->VIso (anIsoParam));
540 findLimits (aBSurfaceCurve, aUVLimit, aSegmentP1, aSegmentP2);
542 if (aSegmentP2 - aSegmentP1 <= Precision::Confusion())
549 aCanonicalCurve.Load (isIsoU ? GeomAbs_IsoU : GeomAbs_IsoV, anIsoParam, aSegmentP1, aSegmentP2);
551 findLimits (aCanonicalCurve, aUVLimit, aSegmentP1, aSegmentP2);
553 if (aSegmentP2 - aSegmentP1 <= Precision::Confusion())
558 Adaptor3d_Curve* aCurve = aBSurface.IsNull() ? (Adaptor3d_Curve*) &aCanonicalCurve
559 : (Adaptor3d_Curve*) &aBSurfaceCurve;
561 Handle(TColgp_HSequenceOfPnt) aPoints = new TColgp_HSequenceOfPnt();
562 StdPrs_DeflectionCurve::Add (Handle(Prs3d_Presentation)(),
567 aPoints->ChangeSequence(),
568 theDrawer->DeviationAngle(),
570 if (aPoints->IsEmpty())
577 theUPolylines.Append (aPoints);
581 theVPolylines.Append (aPoints);
586 catch (Standard_Failure const&)
592 //==================================================================
593 // function : UVIsoParameters
595 //==================================================================
596 void StdPrs_Isolines::UVIsoParameters (const TopoDS_Face& theFace,
597 const Standard_Integer theNbIsoU,
598 const Standard_Integer theNbIsoV,
599 const Standard_Real theUVLimit,
600 TColStd_SequenceOfReal& theUIsoParams,
601 TColStd_SequenceOfReal& theVIsoParams,
602 Standard_Real& theUmin,
603 Standard_Real& theUmax,
604 Standard_Real& theVmin,
605 Standard_Real& theVmax)
608 TopLoc_Location aLocation;
609 const Handle(Geom_Surface)& aSurface = BRep_Tool::Surface(theFace, aLocation);
610 if (aSurface.IsNull())
615 BRepTools::UVBounds (theFace, theUmin, theUmax, theVmin, theVmax);
617 Standard_Real aUmin = theUmin;
618 Standard_Real aUmax = theUmax;
619 Standard_Real aVmin = theVmin;
620 Standard_Real aVmax = theVmax;
622 if (Precision::IsInfinite (aUmin))
624 if (Precision::IsInfinite (aUmax))
626 if (Precision::IsInfinite (aVmin))
628 if (Precision::IsInfinite (aVmax))
632 const Standard_Boolean isUClosed = aSurface->IsUClosed();
633 const Standard_Boolean isVClosed = aSurface->IsVClosed();
637 aUmin = aUmin + (aUmax - aUmin) / 1000.0;
638 aUmax = aUmax - (aUmax - aUmin) / 1000.0;
643 aVmin = aVmin + (aVmax - aVmin) / 1000.0;
644 aVmax = aVmax - (aVmax - aVmin) / 1000.0;
647 Standard_Real aUstep = (aUmax - aUmin) / (1 + theNbIsoU);
648 Standard_Real aVstep = (aVmax - aVmin) / (1 + theNbIsoV);
650 for (Standard_Integer anIso = 1; anIso <= theNbIsoU; ++anIso)
652 theUIsoParams.Append (aUmin + aUstep * anIso);
655 for (Standard_Integer anIso = 1; anIso <= theNbIsoV; ++anIso)
657 theVIsoParams.Append (aVmin + aVstep * anIso);
661 //==================================================================
662 // function : FindSegmentOnTriangulation
664 //==================================================================
665 Standard_Boolean StdPrs_Isolines::findSegmentOnTriangulation (const Handle(Geom_Surface)& theSurface,
667 const gp_Lin2d& theIsoline,
668 const gp_Pnt* theNodesXYZ,
669 const gp_Pnt2d* theNodesUV,
670 SegOnIso& theSegment)
672 Standard_Integer aNPoints = 0;
674 for (Standard_Integer aLinkIter = 0; aLinkIter < 3 && aNPoints < 2; ++aLinkIter)
677 // Check that uv isoline crosses the triangulation link in parametric space
680 const gp_Pnt2d& aNodeUV1 = theNodesUV[aLinkIter];
681 const gp_Pnt2d& aNodeUV2 = theNodesUV[(aLinkIter + 1) % 3];
682 const gp_Pnt& aNode1 = theNodesXYZ[aLinkIter];
683 const gp_Pnt& aNode2 = theNodesXYZ[(aLinkIter + 1) % 3];
685 // Compute distance of uv points to isoline taking into consideration their relative
686 // location against the isoline (left or right). Null value for a node means that the
687 // isoline crosses the node. Both positive or negative means that the isoline does not
688 // cross the segment.
689 Standard_Boolean isLeftUV1 = (theIsoline.Direction().XY() ^ gp_Vec2d (theIsoline.Location(), aNodeUV1).XY()) > 0.0;
690 Standard_Boolean isLeftUV2 = (theIsoline.Direction().XY() ^ gp_Vec2d (theIsoline.Location(), aNodeUV2).XY()) > 0.0;
691 Standard_Real aDistanceUV1 = isLeftUV1 ? theIsoline.Distance (aNodeUV1) : -theIsoline.Distance (aNodeUV1);
692 Standard_Real aDistanceUV2 = isLeftUV2 ? theIsoline.Distance (aNodeUV2) : -theIsoline.Distance (aNodeUV2);
694 // Isoline crosses first point of an edge.
695 if (Abs (aDistanceUV1) < Precision::PConfusion())
697 theSegment[aNPoints].Param = theIsU ? aNodeUV1.Y() : aNodeUV1.X();
698 theSegment[aNPoints].Pnt = aNode1;
703 // Isoline crosses second point of an edge.
704 if (Abs (aDistanceUV2) < Precision::PConfusion())
706 theSegment[aNPoints].Param = theIsU ? aNodeUV2.Y() : aNodeUV2.X();
707 theSegment[aNPoints].Pnt = aNode2;
714 // Isoline does not cross the triangle link.
715 if (aDistanceUV1 * aDistanceUV2 > 0.0)
720 // Isoline crosses degenerated link.
721 if (aNode1.SquareDistance (aNode2) < Precision::PConfusion())
723 theSegment[aNPoints].Param = theIsU ? aNodeUV1.Y() : aNodeUV1.X();
724 theSegment[aNPoints].Pnt = aNode1;
730 // Derive cross-point from parametric coordinates
733 Standard_Real anAlpha = Abs (aDistanceUV1) / (Abs (aDistanceUV1) + Abs (aDistanceUV2));
735 gp_Pnt aCross (0.0, 0.0, 0.0);
736 Standard_Real aCrossU = aNodeUV1.X() + anAlpha * (aNodeUV2.X() - aNodeUV1.X());
737 Standard_Real aCrossV = aNodeUV1.Y() + anAlpha * (aNodeUV2.Y() - aNodeUV1.Y());
738 Standard_Real aCrossParam = theIsU ? aCrossV : aCrossU;
739 if (theSurface.IsNull())
741 // Do linear interpolation of point coordinates using triangulation nodes.
742 aCross.SetX (aNode1.X() + anAlpha * (aNode2.X() - aNode1.X()));
743 aCross.SetY (aNode1.Y() + anAlpha * (aNode2.Y() - aNode1.Y()));
744 aCross.SetZ (aNode1.Z() + anAlpha * (aNode2.Z() - aNode1.Z()));
748 // Do linear interpolation of point coordinates by triangulation nodes.
749 // Get 3d point on surface.
750 Handle(Geom_Curve) anIso1, anIso2;
751 Standard_Real aPntOnNode1Iso = 0.0;
752 Standard_Real aPntOnNode2Iso = 0.0;
753 Standard_Real aPntOnNode3Iso = 0.0;
755 if (theIsoline.Direction().X() == 0.0)
757 aPntOnNode1Iso = aNodeUV1.X();
758 aPntOnNode2Iso = aNodeUV2.X();
759 aPntOnNode3Iso = aCrossU;
760 anIso1 = theSurface->VIso (aNodeUV1.Y());
761 anIso2 = theSurface->VIso (aNodeUV2.Y());
763 else if (theIsoline.Direction().Y() == 0.0)
765 aPntOnNode1Iso = aNodeUV1.Y();
766 aPntOnNode2Iso = aNodeUV2.Y();
767 aPntOnNode3Iso = aCrossV;
768 anIso1 = theSurface->UIso (aNodeUV1.X());
769 anIso2 = theSurface->UIso (aNodeUV2.X());
772 GeomAdaptor_Curve aCurveAdaptor1 (anIso1);
773 GeomAdaptor_Curve aCurveAdaptor2 (anIso2);
774 Standard_Real aLength1 = GCPnts_AbscissaPoint::Length (aCurveAdaptor1, aPntOnNode1Iso, aPntOnNode3Iso, 1e-2);
775 Standard_Real aLength2 = GCPnts_AbscissaPoint::Length (aCurveAdaptor2, aPntOnNode2Iso, aPntOnNode3Iso, 1e-2);
776 if (Abs (aLength1) < Precision::Confusion() || Abs (aLength2) < Precision::Confusion())
778 theSegment[aNPoints].Param = aCrossParam;
779 theSegment[aNPoints].Pnt = (aNode2.XYZ() - aNode1.XYZ()) * anAlpha + aNode1.XYZ();
784 aCross = (aNode2.XYZ() - aNode1.XYZ()) * (aLength1 / (aLength1 + aLength2)) + aNode1.XYZ();
787 theSegment[aNPoints].Param = aCrossParam;
788 theSegment[aNPoints].Pnt = aCross;
793 || Abs (theSegment[1].Param - theSegment[0].Param) <= Precision::PConfusion())
798 if (theSegment[1].Param < theSegment[0].Param)
800 std::swap (theSegment[0], theSegment[1]);