#include <ElCLib.hxx>
#include <GeomLib.hxx>
#include <Extrema_ExtPC.hxx>
+#include <NCollection_DataMap.hxx>
//=======================================================================
//function : IsoIsDeg
}
myTolerance = Comp.Tolerance();
}
- else if (myResult.IsDone())
+
+ Standard_Boolean isPeriodic[] = {mySurface->IsUPeriodic(),
+ mySurface->IsVPeriodic()};
+ if (myResult.IsDone() &&
+ (isPeriodic[0] || isPeriodic[1]))
{
- // On remet arbitrairement la tol atteinte a une valeur
- // petite en attendant mieux. dub lbo 11/03/97
- myTolerance = Min(myTolerance,Precision::Confusion());
-
- // Translate the projected curve to keep the first point
- // In the canonical boundaries of periodic surfaces.
- if (mySurface->IsUPeriodic())
+ // Check result curve to be in params space.
+
+ // U and V parameters space correspondingly.
+ const Standard_Real aSurfFirstPar[2] = {mySurface->FirstUParameter(),
+ mySurface->FirstVParameter()};
+ Standard_Real aSurfPeriod[2] = {0.0, 0.0};
+ if (isPeriodic[0])
+ aSurfPeriod[0] = mySurface->UPeriod();
+ if (isPeriodic[1])
+ aSurfPeriod[1] = mySurface->VPeriod();
+
+ for(Standard_Integer anIdx = 1; anIdx <= 2; anIdx++)
{
- // xf
- Standard_Real aT1, aT2, aU1, aU2, aUPeriod, aUr, aUm, aUmid, dUm, dUr;
- GeomAbs_CurveType aTypeR;
- ProjLib_Projector aResult;
- //
- aT1 = myCurve->FirstParameter();
- aT2 = myCurve->LastParameter();
- aU1 = mySurface->FirstUParameter();
- aU2 = mySurface->LastUParameter();
- aUPeriod = mySurface->UPeriod();
- //
- aTypeR = myResult.GetType();
- if ((aU2 - aU1) < (aUPeriod - myTolerance) && aTypeR == GeomAbs_Line)
- {
- aResult = myResult;
- aResult.UFrame(aT1, aT2, aU1, aUPeriod);
- //
- gp_Lin2d &aLr = (gp_Lin2d &) aResult.Line();
- aUr=aLr.Location().X();
- gp_Lin2d &aLm = (gp_Lin2d &) myResult.Line();
- aUm=aLm.Location().X();
- //
- aUmid = 0.5 * (aU2 + aU1);
- dUm = fabs(aUm - aUmid);
- dUr = fabs(aUr - aUmid);
- if (dUr < dUm)
- {
- myResult = aResult;
- }
- }
- else
- {
- myResult.UFrame(aT1, aT2, aU1, aUPeriod);
- }
- //
- /*
- myResult.UFrame(myCurve->FirstParameter(),
- myCurve->LastParameter(),
- mySurface->FirstUParameter(),
- mySurface->UPeriod());
- */
- //xt
- // Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 Begin
- // Correct the U isoline in periodical surface
- // to be inside restriction boundaries.
- if (myResult.GetType() == GeomAbs_Line)
- {
- gp_Lin2d &aLine = (gp_Lin2d &) myResult.Line();
+ if (!isPeriodic[anIdx - 1])
+ continue;
- Standard_Real aPeriod = mySurface->UPeriod();
- Standard_Real aFUPar = mySurface->FirstUParameter();
- Standard_Real aLUPar = mySurface->LastUParameter();
+ if (myResult.GetType() == GeomAbs_BSplineCurve)
+ {
+ NCollection_DataMap<Standard_Integer, Standard_Integer> aMap;
+ Handle(Geom2d_BSplineCurve) aRes = myResult.BSpline();
+ const Standard_Integer aDeg = aRes->Degree();
- // Check if the parametric range is lower then the period.
- if (aLUPar - aFUPar < aPeriod - myTolerance)
+ for(Standard_Integer aKnotIdx = aRes->FirstUKnotIndex();
+ aKnotIdx < aRes->LastUKnotIndex();
+ aKnotIdx++)
{
- Standard_Real aU = aLine.Location().X();
+ const Standard_Real aFirstParam = aRes->Knot(aKnotIdx);
+ const Standard_Real aLastParam = aRes->Knot(aKnotIdx + 1);
- if (Abs(aU + aPeriod - aFUPar) < myTolerance ||
- Abs(aU - aPeriod - aFUPar) < myTolerance)
+ for(Standard_Integer anIntIdx = 0; anIntIdx <= aDeg; anIntIdx++)
{
- gp_Pnt2d aNewLoc(aFUPar, aLine.Location().Y());
+ const Standard_Real aCurrParam = aFirstParam + (aLastParam - aFirstParam) * anIntIdx / (aDeg + 1.0);
+ gp_Pnt2d aPnt2d;
+ aRes->D0(aCurrParam, aPnt2d);
+
+ Standard_Integer aMapKey = Standard_Integer ((aPnt2d.Coord(anIdx) - aSurfFirstPar[anIdx - 1]) / aSurfPeriod[anIdx - 1]);
- aLine.SetLocation(aNewLoc);
+ if (aPnt2d.Coord(anIdx) - aSurfFirstPar[anIdx - 1] < 0.0)
+ aMapKey--;
+
+ if (aMap.IsBound(aMapKey))
+ aMap.ChangeFind(aMapKey)++;
+ else
+ aMap.Bind(aMapKey, 1);
}
- else if (Abs(aU + aPeriod - aLUPar) < myTolerance ||
- Abs(aU - aPeriod - aLUPar) < myTolerance)
+ }
+
+ Standard_Integer aMaxPoints = 0, aMaxIdx = 0;
+ NCollection_DataMap<Standard_Integer, Standard_Integer>::Iterator aMapIter(aMap);
+ for( ; aMapIter.More(); aMapIter.Next())
+ {
+ if (aMapIter.Value() > aMaxPoints)
{
- gp_Pnt2d aNewLoc(aLUPar, aLine.Location().Y());
- aLine.SetLocation(aNewLoc);
+ aMaxPoints = aMapIter.Value();
+ aMaxIdx = aMapIter.Key();
}
}
+ if (aMaxIdx != 0)
+ {
+ gp_Pnt2d aFirstPnt = aRes->Value(aRes->FirstParameter());
+ gp_Pnt2d aSecondPnt = aFirstPnt;
+ aSecondPnt.SetCoord(anIdx, aFirstPnt.Coord(anIdx) - aSurfPeriod[anIdx - 1] * aMaxIdx);
+ aRes->Translate(gp_Vec2d(aFirstPnt, aSecondPnt));
+ }
}
- }
- // Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 End
- if (mySurface->IsVPeriodic())
- {
- myResult.VFrame(myCurve->FirstParameter(), myCurve->LastParameter(),
- mySurface->FirstVParameter(), mySurface->VPeriod());
- // Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 Begin
- // Correct the V isoline in a periodical surface
- // to be inside restriction boundaries.
if (myResult.GetType() == GeomAbs_Line)
{
- gp_Lin2d &aLine = (gp_Lin2d &) myResult.Line();
+ Standard_Real aT1 = myCurve->FirstParameter();
+ Standard_Real aT2 = myCurve->LastParameter();
- Standard_Real aPeriod = mySurface->VPeriod();
- Standard_Real aFVPar = mySurface->FirstVParameter();
- Standard_Real aLVPar = mySurface->LastVParameter();
-
- // Check if the parametric range is lower then the period.
- if (aLVPar - aFVPar < aPeriod - myTolerance)
+ if (anIdx == 1)
{
- Standard_Real aV = aLine.Location().Y();
-
- if (Abs(aV + aPeriod - aFVPar) < myTolerance ||
- Abs(aV - aPeriod - aFVPar) < myTolerance)
- {
- gp_Pnt2d aNewLoc(aLine.Location().X(), aFVPar);
- aLine.SetLocation(aNewLoc);
- }
- else if (Abs(aV + aPeriod - aLVPar) < myTolerance ||
- Abs(aV - aPeriod - aLVPar) < myTolerance)
- {
- gp_Pnt2d aNewLoc(aLine.Location().X(), aLVPar);
- aLine.SetLocation(aNewLoc);
- }
+ // U param space.
+ myResult.UFrame(aT1, aT2, aSurfFirstPar[anIdx - 1], aSurfPeriod[anIdx - 1]);
+ }
+ else
+ {
+ // V param space.
+ myResult.VFrame(aT1, aT2, aSurfFirstPar[anIdx - 1], aSurfPeriod[anIdx - 1]);
}
}
}
- // Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 End
- }
+ }
}