diff --git a/src/ApplicationFramework/TKLCAF/TDataStd/TDataStd_DeltaOnModificationOfIntPackedMap.cxx b/src/ApplicationFramework/TKLCAF/TDataStd/TDataStd_DeltaOnModificationOfIntPackedMap.cxx index 971cb0800e..39d26e4b63 100644 --- a/src/ApplicationFramework/TKLCAF/TDataStd/TDataStd_DeltaOnModificationOfIntPackedMap.cxx +++ b/src/ApplicationFramework/TKLCAF/TDataStd/TDataStd_DeltaOnModificationOfIntPackedMap.cxx @@ -51,22 +51,22 @@ TDataStd_DeltaOnModificationOfIntPackedMap::TDataStd_DeltaOnModificationOfIntPac { const TColStd_PackedMapOfInteger& map1 = aMap1->Map(); const TColStd_PackedMapOfInteger& map2 = aMap2->Map(); - if (map1.IsSubset(map2)) + if (NCollection_PackedMapAlgo::IsSubset(map1, map2)) { myDeletion = new TColStd_HPackedMapOfInteger(); - myDeletion->ChangeMap().Subtraction(map2, map1); + NCollection_PackedMapAlgo::Subtraction(myDeletion->ChangeMap(), map2, map1); } - else if (map2.IsSubset(map1)) + else if (NCollection_PackedMapAlgo::IsSubset(map2, map1)) { myAddition = new TColStd_HPackedMapOfInteger(); - myAddition->ChangeMap().Subtraction(map1, map2); + NCollection_PackedMapAlgo::Subtraction(myAddition->ChangeMap(), map1, map2); } - else if (map1.HasIntersection(map2)) + else if (NCollection_PackedMapAlgo::HasIntersection(map1, map2)) { myAddition = new TColStd_HPackedMapOfInteger(); - myAddition->ChangeMap().Subtraction(map1, map2); + NCollection_PackedMapAlgo::Subtraction(myAddition->ChangeMap(), map1, map2); myDeletion = new TColStd_HPackedMapOfInteger(); - myDeletion->ChangeMap().Subtraction(map2, map1); + NCollection_PackedMapAlgo::Subtraction(myDeletion->ChangeMap(), map2, map1); } else { @@ -120,12 +120,12 @@ void TDataStd_DeltaOnModificationOfIntPackedMap::Apply() if (!myDeletion.IsNull()) { if (myDeletion->Map().Extent()) - IntMap->ChangeMap().Subtract(myDeletion->Map()); + NCollection_PackedMapAlgo::Subtract(IntMap->ChangeMap(), myDeletion->Map()); } if (!myAddition.IsNull()) { if (myAddition->Map().Extent()) - IntMap->ChangeMap().Unite(myAddition->Map()); + NCollection_PackedMapAlgo::Unite(IntMap->ChangeMap(), myAddition->Map()); } #ifdef OCCT_DEBUG_disable diff --git a/src/ApplicationFramework/TKLCAF/TDataStd/TDataStd_IntPackedMap.cxx b/src/ApplicationFramework/TKLCAF/TDataStd/TDataStd_IntPackedMap.cxx index 94428e590c..27371ecaf3 100644 --- a/src/ApplicationFramework/TKLCAF/TDataStd/TDataStd_IntPackedMap.cxx +++ b/src/ApplicationFramework/TKLCAF/TDataStd/TDataStd_IntPackedMap.cxx @@ -69,7 +69,7 @@ bool TDataStd_IntPackedMap::ChangeMap(const occ::handleMap().IsEqual(theMap->Map())) + if (!NCollection_PackedMapAlgo::IsEqual(myMap->Map(), theMap->Map())) { Backup(); myMap->ChangeMap().Assign(theMap->Map()); @@ -83,7 +83,7 @@ bool TDataStd_IntPackedMap::ChangeMap(const occ::handleMap().IsEqual(theMap)) + if (!NCollection_PackedMapAlgo::IsEqual(myMap->Map(), theMap)) { Backup(); myMap->ChangeMap().Assign(theMap); diff --git a/src/ApplicationFramework/TKStd/ShapePersistent/ShapePersistent_Geom2d_Curve.cxx b/src/ApplicationFramework/TKStd/ShapePersistent/ShapePersistent_Geom2d_Curve.cxx index 8d79c7b35f..7e8f02ca3a 100644 --- a/src/ApplicationFramework/TKStd/ShapePersistent/ShapePersistent_Geom2d_Curve.cxx +++ b/src/ApplicationFramework/TKStd/ShapePersistent/ShapePersistent_Geom2d_Curve.cxx @@ -298,7 +298,7 @@ Handle(ShapePersistent_Geom2d::Curve) ShapePersistent_Geom2d_Curve::Translate( if (theCurve->IsRational()) { aPpBC->myWeights = - StdLPersistent_HArray1::Translate>(*theCurve->Weights()); + StdLPersistent_HArray1::Translate>(theCurve->WeightsArray()); } aPBC->myPersistent = aPpBC; aPC = aPBC; @@ -332,7 +332,7 @@ Handle(ShapePersistent_Geom2d::Curve) ShapePersistent_Geom2d_Curve::Translate( if (theCurve->IsRational()) { aPpBSC->myWeights = - StdLPersistent_HArray1::Translate>(*theCurve->Weights()); + StdLPersistent_HArray1::Translate>(theCurve->WeightsArray()); } aPpBSC->myKnots = StdLPersistent_HArray1::Translate>(theCurve->Knots()); diff --git a/src/ApplicationFramework/TKStd/ShapePersistent/ShapePersistent_Geom_Curve.cxx b/src/ApplicationFramework/TKStd/ShapePersistent/ShapePersistent_Geom_Curve.cxx index f89a529fc6..65db81482a 100644 --- a/src/ApplicationFramework/TKStd/ShapePersistent/ShapePersistent_Geom_Curve.cxx +++ b/src/ApplicationFramework/TKStd/ShapePersistent/ShapePersistent_Geom_Curve.cxx @@ -294,7 +294,7 @@ Handle(ShapePersistent_Geom::Curve) ShapePersistent_Geom_Curve::Translate( if (theCurve->IsRational()) { aPpBC->myWeights = - StdLPersistent_HArray1::Translate>(*theCurve->Weights()); + StdLPersistent_HArray1::Translate>(theCurve->WeightsArray()); } aPBC->myPersistent = aPpBC; aPC = aPBC; @@ -328,7 +328,7 @@ Handle(ShapePersistent_Geom::Curve) ShapePersistent_Geom_Curve::Translate( if (theCurve->IsRational()) { aPpBSC->myWeights = - StdLPersistent_HArray1::Translate>(*theCurve->Weights()); + StdLPersistent_HArray1::Translate>(theCurve->WeightsArray()); } aPpBSC->myKnots = StdLPersistent_HArray1::Translate>(theCurve->Knots()); diff --git a/src/ApplicationFramework/TKStd/ShapePersistent/ShapePersistent_Geom_Surface.cxx b/src/ApplicationFramework/TKStd/ShapePersistent/ShapePersistent_Geom_Surface.cxx index 8acb0b4d3b..4a26be93f2 100644 --- a/src/ApplicationFramework/TKStd/ShapePersistent/ShapePersistent_Geom_Surface.cxx +++ b/src/ApplicationFramework/TKStd/ShapePersistent/ShapePersistent_Geom_Surface.cxx @@ -399,7 +399,7 @@ Handle(ShapePersistent_Geom::Surface) ShapePersistent_Geom_Surface::Translate( if (theSurf->IsURational() || theSurf->IsVRational()) { aPpB->myWeights = - StdLPersistent_HArray2::Translate>(*theSurf->Weights()); + StdLPersistent_HArray2::Translate>(theSurf->WeightsArray()); } aPB->myPersistent = aPpB; aPS = aPB; @@ -436,7 +436,7 @@ Handle(ShapePersistent_Geom::Surface) ShapePersistent_Geom_Surface::Translate( if (theSurf->IsURational() || theSurf->IsVRational()) { aPpBS->myWeights = - StdLPersistent_HArray2::Translate>(*theSurf->Weights()); + StdLPersistent_HArray2::Translate>(theSurf->WeightsArray()); } aPpBS->myUKnots = StdLPersistent_HArray1::Translate>(theSurf->UKnots()); diff --git a/src/DataExchange/TKDEIGES/GeomToIGES/GeomToIGES_GeomCurve.cxx b/src/DataExchange/TKDEIGES/GeomToIGES/GeomToIGES_GeomCurve.cxx index 55627e1b5b..f19cb300cb 100644 --- a/src/DataExchange/TKDEIGES/GeomToIGES/GeomToIGES_GeomCurve.cxx +++ b/src/DataExchange/TKDEIGES/GeomToIGES/GeomToIGES_GeomCurve.cxx @@ -249,16 +249,12 @@ static bool IsPlanar(const occ::handle& curve, gp_XYZ& Normal) if (curve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) { DeclareAndCast(Geom_BSplineCurve, BSpline, curve); - NCollection_Array1 Poles(1, BSpline->NbPoles()); - BSpline->Poles(Poles); - return ArePolesPlanar(Poles, Normal); + return ArePolesPlanar(BSpline->Poles(), Normal); } if (curve->IsKind(STANDARD_TYPE(Geom_BezierCurve))) { DeclareAndCast(Geom_BezierCurve, Bezier, curve); - NCollection_Array1 Poles(1, Bezier->NbPoles()); - Bezier->Poles(Poles); - return ArePolesPlanar(Poles, Normal); + return ArePolesPlanar(Bezier->Poles(), Normal); } return false; } @@ -348,10 +344,9 @@ occ::handle GeomToIGES_GeomCurve::TransferCurve( // Sequence des Knots de [-Deg, Index+1] dans IGESGeom. // and from [1, Nbpoles+Deg+1] in Geom - int Knotindex; - double rtampon; - NCollection_Array1 K(1, Nbpoles + Deg + 1); - mycurve->KnotSequence(K); + int Knotindex; + double rtampon; + const NCollection_Array1& K = mycurve->KnotSequence(); int itampon = -Deg; occ::handle> Knots = new NCollection_HArray1(-Deg, Index + 1); for (Knotindex = K.Lower(); Knotindex <= K.Upper(); Knotindex++) @@ -362,8 +357,7 @@ occ::handle GeomToIGES_GeomCurve::TransferCurve( } // Tableau Weights de [0,Index] - NCollection_Array1 W(1, Nbpoles); - mycurve->Weights(W); + const NCollection_Array1& W = mycurve->WeightsArray(); itampon = 0; occ::handle> Weights = new NCollection_HArray1(0, Index); for (Knotindex = W.Lower(); Knotindex <= W.Upper(); Knotindex++) @@ -374,9 +368,8 @@ occ::handle GeomToIGES_GeomCurve::TransferCurve( } // Tableau Poles de [0,Index] - NCollection_Array1 P(1, Nbpoles); - mycurve->Poles(P); - int Poleindex; + const NCollection_Array1& P = mycurve->Poles(); + int Poleindex; itampon = 0; double Xpt, Ypt, Zpt; occ::handle> Poles = new NCollection_HArray1(0, Index); @@ -610,9 +603,8 @@ occ::handle GeomToIGES_GeomCurve::TransferCurve( if (approx.HasResult()) Bspline = approx.Curve(); if (Bspline.IsNull()) - GeomConvert::CurveToBSplineCurve(copystart, Convert_QuasiAngular); - NCollection_Array1 Knots(1, Bspline->NbKnots()); - Bspline->Knots(Knots); + Bspline = GeomConvert::CurveToBSplineCurve(copystart, Convert_QuasiAngular); + NCollection_Array1 Knots(Bspline->Knots()); BSplCLib::Reparametrize(Udeb, Udeb + 2 * M_PI, Knots); Bspline->SetKnots(Knots); return TransferCurve(Bspline, Udeb, Ufin); diff --git a/src/DataExchange/TKDEIGES/GeomToIGES/GeomToIGES_GeomSurface.cxx b/src/DataExchange/TKDEIGES/GeomToIGES/GeomToIGES_GeomSurface.cxx index 9968c1016f..7a9329f03a 100644 --- a/src/DataExchange/TKDEIGES/GeomToIGES/GeomToIGES_GeomSurface.cxx +++ b/src/DataExchange/TKDEIGES/GeomToIGES/GeomToIGES_GeomSurface.cxx @@ -336,12 +336,11 @@ occ::handle GeomToIGES_GeomSurface::TransferSurface( // filling knots array for U : // Knots sequence from [-DegU, IndexU+1] in IGESGeom. - int Knotindex; - double rtampon; - int itampon; - NCollection_Array1 KU(1, NbUPoles + DegU + 1); - mysurface->UKnotSequence(KU); - itampon = -DegU; + int Knotindex; + double rtampon; + int itampon; + const NCollection_Array1& KU = mysurface->UKnotSequence(); + itampon = -DegU; occ::handle> KnotsU = new NCollection_HArray1(-DegU, IndexU + 1); for (Knotindex = KU.Lower(); Knotindex <= KU.Upper(); Knotindex++) @@ -353,9 +352,8 @@ occ::handle GeomToIGES_GeomSurface::TransferSurface( // filling knots array for V : // Knots sequence from [-DegV, IndexV+1] in IGESGeom. - NCollection_Array1 KV(1, NbVPoles + DegV + 1); - mysurface->VKnotSequence(KV); - itampon = -DegV; + const NCollection_Array1& KV = mysurface->VKnotSequence(); + itampon = -DegV; occ::handle> KnotsV = new NCollection_HArray1(-DegV, IndexV + 1); for (Knotindex = KV.Lower(); Knotindex <= KV.Upper(); Knotindex++) diff --git a/src/DataExchange/TKDEIGES/IGESToBRep/IGESToBRep_BasicCurve.cxx b/src/DataExchange/TKDEIGES/IGESToBRep/IGESToBRep_BasicCurve.cxx index 8c2719354e..6e05bd6848 100644 --- a/src/DataExchange/TKDEIGES/IGESToBRep/IGESToBRep_BasicCurve.cxx +++ b/src/DataExchange/TKDEIGES/IGESToBRep/IGESToBRep_BasicCurve.cxx @@ -897,14 +897,10 @@ occ::handle IGESToBRep_BasicCurve::Transfer2dSplineCurve( // 2d // == int nbPoles = res3d->NbPoles(); - int nbKnots = res3d->NbKnots(); - NCollection_Array1 bspoles2d(1, nbPoles); - NCollection_Array1 knots(1, nbKnots); - NCollection_Array1 multi(1, nbKnots); - - res3d->Knots(knots); - res3d->Multiplicities(multi); + NCollection_Array1 bspoles2d(1, nbPoles); + const NCollection_Array1& knots = res3d->Knots(); + const NCollection_Array1& multi = res3d->Multiplicities(); for (int i = bspoles2d.Lower(); i <= bspoles2d.Upper(); i++) bspoles2d.SetValue(i, gp_Pnt2d(res3d->Pole(i).X(), res3d->Pole(i).Y())); @@ -1261,21 +1257,14 @@ occ::handle IGESToBRep_BasicCurve::Transfer2dBSplineCurve( // Knots and multiplicities are the same : // ======================================= - int NbKnots = Bspline->NbKnots(); - - NCollection_Array1 Knot(1, NbKnots); - Bspline->Knots(Knot); - - NCollection_Array1 Mult(1, NbKnots); - Bspline->Multiplicities(Mult); + const NCollection_Array1& Knot = Bspline->Knots(); + const NCollection_Array1& Mult = Bspline->Multiplicities(); int Degree = Bspline->Degree(); if (Bspline->IsRational()) { - NCollection_Array1 Weight(1, NbPoles); - Bspline->Weights(Weight); - BSplineC = new Geom2d_BSplineCurve(Pole, Weight, Knot, Mult, Degree); + BSplineC = new Geom2d_BSplineCurve(Pole, Bspline->WeightsArray(), Knot, Mult, Degree); } else BSplineC = new Geom2d_BSplineCurve(Pole, Knot, Mult, Degree); diff --git a/src/DataExchange/TKDEIGES/IGESToBRep/IGESToBRep_TopoSurface.cxx b/src/DataExchange/TKDEIGES/IGESToBRep/IGESToBRep_TopoSurface.cxx index a0d1cbca20..acb2808a27 100644 --- a/src/DataExchange/TKDEIGES/IGESToBRep/IGESToBRep_TopoSurface.cxx +++ b/src/DataExchange/TKDEIGES/IGESToBRep/IGESToBRep_TopoSurface.cxx @@ -344,8 +344,7 @@ static void reparamBSpline(occ::handle& curve, const double First, c if (bscurve.IsNull()) return; - NCollection_Array1 Knots(1, bscurve->NbKnots()); - bscurve->Knots(Knots); + NCollection_Array1 Knots(bscurve->Knots()); BSplCLib::Reparametrize(0., 1., Knots); bscurve->SetKnots(Knots); curve = bscurve; @@ -620,8 +619,7 @@ TopoDS_Shape IGESToBRep_TopoSurface::TransferRuledSurface( bscurve = occ::down_cast(curve); bscurve->Segment(First, Last); } - NCollection_Array1 Knots(1, bscurve->NbKnots()); - bscurve->Knots(Knots); + NCollection_Array1 Knots(bscurve->Knots()); BSplCLib::Reparametrize(0., 1., Knots); bscurve->SetKnots(Knots); diff --git a/src/DataExchange/TKDESTEP/GeomToStep/GeomToStep_MakeBSplineCurveWithKnotsAndRationalBSplineCurve_gen.pxx b/src/DataExchange/TKDESTEP/GeomToStep/GeomToStep_MakeBSplineCurveWithKnotsAndRationalBSplineCurve_gen.pxx index edc3882d78..93cd5daf94 100644 --- a/src/DataExchange/TKDESTEP/GeomToStep/GeomToStep_MakeBSplineCurveWithKnotsAndRationalBSplineCurve_gen.pxx +++ b/src/DataExchange/TKDESTEP/GeomToStep/GeomToStep_MakeBSplineCurveWithKnotsAndRationalBSplineCurve_gen.pxx @@ -28,10 +28,9 @@ StepGeom_KnotType KnotSpec; Deg = BS->Degree(); -N = BS->NbPoles(); -Array1OfPnt_gen P(1, N); -BS->Poles(P); -Listpoints = new NCollection_HArray1>(1, N); +N = BS->NbPoles(); +const Array1OfPnt_gen& P = BS->Poles(); +Listpoints = new NCollection_HArray1>(1, N); for (i = P.Lower(); i <= P.Upper(); i++) { GeomToStep_MakeCartesianPoint MkPoint(P.Value(i), theLocalFactors.LengthFactor()); @@ -48,19 +47,17 @@ else Selfinter = StepData_LFalse; -Nknots = BS->NbKnots(); -NCollection_Array1 M(1, Nknots); -BS->Multiplicities(M); -Mult = new NCollection_HArray1(1, Nknots); +Nknots = BS->NbKnots(); +const NCollection_Array1& M = BS->Multiplicities(); +Mult = new NCollection_HArray1(1, Nknots); for (i = M.Lower(); i <= M.Upper(); i++) { itampon = M.Value(i); Mult->SetValue(i, itampon); } -NCollection_Array1 K(1, Nknots); -BS->Knots(K); -ListKnots = new NCollection_HArray1(1, Nknots); +const NCollection_Array1& K = BS->Knots(); +ListKnots = new NCollection_HArray1(1, Nknots); for (i = K.Lower(); i <= K.Upper(); i++) { rtampon = K.Value(i); @@ -77,13 +74,11 @@ else if (Distribution == GeomAbs_QuasiUniform) else KnotSpec = StepGeom_ktPiecewiseBezierKnots; -NCollection_Array1 W(1, N); -BS->Weights(W); -ListWeights = new NCollection_HArray1(1, N); +const NCollection_Array1& W = BS->WeightsArray(); +ListWeights = new NCollection_HArray1(1, N); for (i = W.Lower(); i <= W.Upper(); i++) { - rtampon = W.Value(i); - ListWeights->SetValue(i, rtampon); + ListWeights->SetValue(i, W.Value(i)); } BSWK = new StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve; diff --git a/src/DataExchange/TKDESTEP/GeomToStep/GeomToStep_MakeBSplineCurveWithKnots_gen.pxx b/src/DataExchange/TKDESTEP/GeomToStep/GeomToStep_MakeBSplineCurveWithKnots_gen.pxx index 05dbd44635..90e505b68b 100644 --- a/src/DataExchange/TKDESTEP/GeomToStep/GeomToStep_MakeBSplineCurveWithKnots_gen.pxx +++ b/src/DataExchange/TKDESTEP/GeomToStep/GeomToStep_MakeBSplineCurveWithKnots_gen.pxx @@ -28,10 +28,9 @@ StepGeom_KnotType KnotSpec; Deg = BS->Degree(); -N = BS->NbPoles(); -Array1OfPnt_gen P(1, N); -BS->Poles(P); -Listpoints = new NCollection_HArray1>(1, N); +N = BS->NbPoles(); +const Array1OfPnt_gen& P = BS->Poles(); +Listpoints = new NCollection_HArray1>(1, N); for (i = P.Lower(); i <= P.Upper(); i++) { GeomToStep_MakeCartesianPoint MkPoint(P.Value(i), theLocalFactors.LengthFactor()); @@ -48,19 +47,17 @@ else Selfinter = StepData_LFalse; -Nknots = BS->NbKnots(); -NCollection_Array1 M(1, Nknots); -BS->Multiplicities(M); -Mult = new NCollection_HArray1(1, Nknots); +Nknots = BS->NbKnots(); +const NCollection_Array1& M = BS->Multiplicities(); +Mult = new NCollection_HArray1(1, Nknots); for (i = M.Lower(); i <= M.Upper(); i++) { itampon = M.Value(i); Mult->SetValue(i, itampon); } -NCollection_Array1 K(1, Nknots); -BS->Knots(K); -ListKnots = new NCollection_HArray1(1, Nknots); +const NCollection_Array1& K = BS->Knots(); +ListKnots = new NCollection_HArray1(1, Nknots); for (i = K.Lower(); i <= K.Upper(); i++) { rtampon = K.Value(i); diff --git a/src/DataExchange/TKDESTEP/GeomToStep/GeomToStep_MakeBSplineSurfaceWithKnots.cxx b/src/DataExchange/TKDESTEP/GeomToStep/GeomToStep_MakeBSplineSurfaceWithKnots.cxx index 7d82a02f9e..9d840870b7 100644 --- a/src/DataExchange/TKDESTEP/GeomToStep/GeomToStep_MakeBSplineSurfaceWithKnots.cxx +++ b/src/DataExchange/TKDESTEP/GeomToStep/GeomToStep_MakeBSplineSurfaceWithKnots.cxx @@ -55,10 +55,9 @@ GeomToStep_MakeBSplineSurfaceWithKnots::GeomToStep_MakeBSplineSurfaceWithKnots( aUDegree = BS->UDegree(); aVDegree = BS->VDegree(); - NU = BS->NbUPoles(); - NV = BS->NbVPoles(); - NCollection_Array2 P(1, NU, 1, NV); - BS->Poles(P); + NU = BS->NbUPoles(); + NV = BS->NbVPoles(); + const NCollection_Array2& P = BS->Poles(); aControlPointsList = new NCollection_HArray2>(1, NU, 1, NV); for (i = P.LowerRow(); i <= P.UpperRow(); i++) { @@ -84,31 +83,27 @@ GeomToStep_MakeBSplineSurfaceWithKnots::GeomToStep_MakeBSplineSurfaceWithKnots( aSelfIntersect = StepData_LFalse; - NUknots = BS->NbUKnots(); - NVknots = BS->NbVKnots(); - NCollection_Array1 MU(1, NUknots); - BS->UMultiplicities(MU); - aUMultiplicities = new NCollection_HArray1(1, NUknots); + NUknots = BS->NbUKnots(); + NVknots = BS->NbVKnots(); + const NCollection_Array1& MU = BS->UMultiplicities(); + aUMultiplicities = new NCollection_HArray1(1, NUknots); for (i = MU.Lower(); i <= MU.Upper(); i++) { itampon = MU.Value(i); aUMultiplicities->SetValue(i, itampon); } - NCollection_Array1 MV(1, NVknots); - BS->VMultiplicities(MV); - aVMultiplicities = new NCollection_HArray1(1, NVknots); + const NCollection_Array1& MV = BS->VMultiplicities(); + aVMultiplicities = new NCollection_HArray1(1, NVknots); for (i = MV.Lower(); i <= MV.Upper(); i++) { itampon = MV.Value(i); aVMultiplicities->SetValue(i, itampon); } - NCollection_Array1 KU(1, NUknots); - NCollection_Array1 KV(1, NVknots); - BS->UKnots(KU); - BS->VKnots(KV); - aUKnots = new NCollection_HArray1(1, NUknots); - aVKnots = new NCollection_HArray1(1, NVknots); + const NCollection_Array1& KU = BS->UKnots(); + const NCollection_Array1& KV = BS->VKnots(); + aUKnots = new NCollection_HArray1(1, NUknots); + aVKnots = new NCollection_HArray1(1, NVknots); for (i = KU.Lower(); i <= KU.Upper(); i++) { rtampon = KU.Value(i); diff --git a/src/DataExchange/TKDESTEP/GeomToStep/GeomToStep_MakeBSplineSurfaceWithKnotsAndRationalBSplineSurface.cxx b/src/DataExchange/TKDESTEP/GeomToStep/GeomToStep_MakeBSplineSurfaceWithKnotsAndRationalBSplineSurface.cxx index 2d7c3a5d9b..048ab76c2b 100644 --- a/src/DataExchange/TKDESTEP/GeomToStep/GeomToStep_MakeBSplineSurfaceWithKnotsAndRationalBSplineSurface.cxx +++ b/src/DataExchange/TKDESTEP/GeomToStep/GeomToStep_MakeBSplineSurfaceWithKnotsAndRationalBSplineSurface.cxx @@ -58,10 +58,9 @@ GeomToStep_MakeBSplineSurfaceWithKnotsAndRationalBSplineSurface:: aUDegree = BS->UDegree(); aVDegree = BS->VDegree(); - NU = BS->NbUPoles(); - NV = BS->NbVPoles(); - NCollection_Array2 P(1, NU, 1, NV); - BS->Poles(P); + NU = BS->NbUPoles(); + NV = BS->NbVPoles(); + const NCollection_Array2& P = BS->Poles(); aControlPointsList = new NCollection_HArray2>(1, NU, 1, NV); for (i = P.LowerRow(); i <= P.UpperRow(); i++) { @@ -87,31 +86,27 @@ GeomToStep_MakeBSplineSurfaceWithKnotsAndRationalBSplineSurface:: aSelfIntersect = StepData_LFalse; - NUknots = BS->NbUKnots(); - NVknots = BS->NbVKnots(); - NCollection_Array1 MU(1, NUknots); - BS->UMultiplicities(MU); - aUMultiplicities = new NCollection_HArray1(1, NUknots); + NUknots = BS->NbUKnots(); + NVknots = BS->NbVKnots(); + const NCollection_Array1& MU = BS->UMultiplicities(); + aUMultiplicities = new NCollection_HArray1(1, NUknots); for (i = MU.Lower(); i <= MU.Upper(); i++) { itampon = MU.Value(i); aUMultiplicities->SetValue(i, itampon); } - NCollection_Array1 MV(1, NVknots); - BS->VMultiplicities(MV); - aVMultiplicities = new NCollection_HArray1(1, NVknots); + const NCollection_Array1& MV = BS->VMultiplicities(); + aVMultiplicities = new NCollection_HArray1(1, NVknots); for (i = MV.Lower(); i <= MV.Upper(); i++) { itampon = MV.Value(i); aVMultiplicities->SetValue(i, itampon); } - NCollection_Array1 KU(1, NUknots); - NCollection_Array1 KV(1, NVknots); - BS->UKnots(KU); - BS->VKnots(KV); - aUKnots = new NCollection_HArray1(1, NUknots); - aVKnots = new NCollection_HArray1(1, NVknots); + const NCollection_Array1& KU = BS->UKnots(); + const NCollection_Array1& KV = BS->VKnots(); + aUKnots = new NCollection_HArray1(1, NUknots); + aVKnots = new NCollection_HArray1(1, NVknots); for (i = KU.Lower(); i <= KU.Upper(); i++) { rtampon = KU.Value(i); @@ -136,15 +131,13 @@ GeomToStep_MakeBSplineSurfaceWithKnotsAndRationalBSplineSurface:: else KnotSpec = StepGeom_ktUnspecified; - NCollection_Array2 W(1, NU, 1, NV); - BS->Weights(W); - aWeightsData = new NCollection_HArray2(1, NU, 1, NV); + const NCollection_Array2& W = BS->WeightsArray(); + aWeightsData = new NCollection_HArray2(1, NU, 1, NV); for (i = W.LowerRow(); i <= W.UpperRow(); i++) { for (j = W.LowerCol(); j <= W.UpperCol(); j++) { - rtampon = W.Value(i, j); - aWeightsData->SetValue(i, j, rtampon); + aWeightsData->SetValue(i, j, W.Value(i, j)); } } diff --git a/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BSplineCurve.cxx b/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BSplineCurve.cxx index 1a420c37aa..68faf7a3e1 100644 --- a/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BSplineCurve.cxx +++ b/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BSplineCurve.cxx @@ -65,10 +65,9 @@ void DrawTrSurf_BSplineCurve::DrawOn(Draw_Display& dis) const occ::handle C = occ::down_cast(curv); if (drawPoles) { - int NbPoles = C->NbPoles(); dis.SetColor(polesLook); - NCollection_Array1 CPoles(1, NbPoles); - C->Poles(CPoles); + const NCollection_Array1& CPoles = C->Poles(); + int NbPoles = CPoles.Length(); dis.MoveTo(CPoles(1)); for (int i = 2; i <= NbPoles; i++) { @@ -83,9 +82,7 @@ void DrawTrSurf_BSplineCurve::DrawOn(Draw_Display& dis) const DrawTrSurf_Curve::DrawOn(dis); if (drawKnots) { - int NbKnots = C->NbKnots(); - NCollection_Array1 CKnots(1, NbKnots); - C->Knots(CKnots); + const NCollection_Array1& CKnots = C->Knots(); dis.SetColor(knotsLook); int first = C->FirstUKnotIndex(); int last = C->LastUKnotIndex(); @@ -103,10 +100,9 @@ void DrawTrSurf_BSplineCurve::DrawOn(Draw_Display& dis, occ::handle C = occ::down_cast(curv); if (drawPoles && ShowPoles) { - int NbPoles = C->NbPoles(); dis.SetColor(polesLook); - NCollection_Array1 CPoles(1, NbPoles); - C->Poles(CPoles); + const NCollection_Array1& CPoles = C->Poles(); + int NbPoles = CPoles.Length(); dis.MoveTo(CPoles(1)); for (int i = 2; i <= NbPoles; i++) { @@ -118,11 +114,9 @@ void DrawTrSurf_BSplineCurve::DrawOn(Draw_Display& dis, if (drawKnots && ShowKnots) { - int NbKnots = C->NbKnots(); - NCollection_Array1 CKnots(1, NbKnots); - C->Knots(CKnots); + const NCollection_Array1& CKnots = C->Knots(); dis.SetColor(knotsLook); - for (int i = 1; i <= NbKnots; i++) + for (int i = CKnots.Lower(); i <= CKnots.Upper(); i++) { dis.DrawMarker(C->Value(CKnots(i)), knotsForm, knotsDim); } @@ -147,10 +141,9 @@ void DrawTrSurf_BSplineCurve::DrawOn(Draw_Display& dis, if (drawPoles && ShowPoles) { - int NbPoles = C->NbPoles(); dis.SetColor(polesLook); - NCollection_Array1 CPoles(1, NbPoles); - C->Poles(CPoles); + const NCollection_Array1& CPoles = C->Poles(); + int NbPoles = CPoles.Length(); if (Pindex == 0) { dis.MoveTo(CPoles(1)); @@ -267,9 +260,7 @@ void DrawTrSurf_BSplineCurve::DrawOn(Draw_Display& dis, if (drawKnots && ShowKnots) { - int NbKnots = C->NbKnots(); - NCollection_Array1 CKnots(1, NbKnots); - C->Knots(CKnots); + const NCollection_Array1& CKnots = C->Knots(); dis.SetColor(knotsLook); for (int i = J1; i <= I2; i++) { diff --git a/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BSplineCurve2d.cxx b/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BSplineCurve2d.cxx index dc80a89124..016e536d7c 100644 --- a/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BSplineCurve2d.cxx +++ b/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BSplineCurve2d.cxx @@ -63,12 +63,10 @@ void DrawTrSurf_BSplineCurve2d::DrawOn(Draw_Display& dis) const if (drawPoles) { - int NbPoles = C->NbPoles(); dis.SetColor(polesLook); - NCollection_Array1 CPoles(1, NbPoles); - C->Poles(CPoles); + const NCollection_Array1& CPoles = C->Poles(); dis.MoveTo(CPoles(1)); - for (int i = 2; i <= NbPoles; i++) + for (int i = 2; i <= CPoles.Length(); i++) { dis.DrawTo(CPoles(i)); } @@ -80,11 +78,9 @@ void DrawTrSurf_BSplineCurve2d::DrawOn(Draw_Display& dis) const if (drawKnots) { - int NbKnots = C->NbKnots(); - NCollection_Array1 CKnots(1, NbKnots); - C->Knots(CKnots); + const NCollection_Array1& CKnots = C->Knots(); dis.SetColor(knotsLook); - for (int i = 1; i <= NbKnots; i++) + for (int i = CKnots.Lower(); i <= CKnots.Upper(); i++) { gp_Pnt2d P = C->Value(CKnots(i)); dis.DrawMarker(P, knotsForm, knotsDim); diff --git a/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BSplineSurface.cxx b/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BSplineSurface.cxx index dcefb1d659..ab7430fea2 100644 --- a/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BSplineSurface.cxx +++ b/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BSplineSurface.cxx @@ -122,11 +122,10 @@ void DrawTrSurf_BSplineSurface::DrawOn(Draw_Display& dis) const if (drawPoles) { - int NbUPoles = S->NbUPoles(); - int NbVPoles = S->NbVPoles(); dis.SetColor(polesLook); - NCollection_Array2 SPoles(1, NbUPoles, 1, NbVPoles); - S->Poles(SPoles); + const NCollection_Array2& SPoles = S->Poles(); + int NbUPoles = SPoles.NbRows(); + int NbVPoles = SPoles.NbColumns(); for (j = 1; j <= NbVPoles; j++) { dis.MoveTo(SPoles(1, j)); @@ -180,10 +179,8 @@ void DrawTrSurf_BSplineSurface::DrawOn(Draw_Display& dis) const if (drawKnots) { - int first, last; - int NbUKnots = S->NbUKnots(); - NCollection_Array1 SUKnots(1, NbUKnots); - S->UKnots(SUKnots); + int first, last; + const NCollection_Array1& SUKnots = S->UKnots(); dis.SetColor(knotsLook); first = S->FirstUKnotIndex(); last = S->LastUKnotIndex(); @@ -191,9 +188,7 @@ void DrawTrSurf_BSplineSurface::DrawOn(Draw_Display& dis) const { dis.DrawMarker(S->Value(SUKnots(i), Va), knotsForm, knotsDim); } - int NbVKnots = S->NbVKnots(); - NCollection_Array1 SVKnots(1, NbVKnots); - S->VKnots(SVKnots); + const NCollection_Array1& SVKnots = S->VKnots(); dis.SetColor(knotsLook); first = S->FirstVKnotIndex(); last = S->LastVKnotIndex(); diff --git a/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BezierCurve.cxx b/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BezierCurve.cxx index 8566f01404..2cc284a247 100644 --- a/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BezierCurve.cxx +++ b/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BezierCurve.cxx @@ -51,10 +51,9 @@ void DrawTrSurf_BezierCurve::DrawOn(Draw_Display& dis) const occ::handle C = occ::down_cast(curv); if (drawPoles) { - int NbPoles = C->NbPoles(); dis.SetColor(polesLook); - NCollection_Array1 CPoles(1, NbPoles); - C->Poles(CPoles); + const NCollection_Array1& CPoles = C->Poles(); + int NbPoles = CPoles.Length(); dis.MoveTo(CPoles(1)); for (int i = 2; i <= NbPoles; i++) { diff --git a/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BezierCurve2d.cxx b/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BezierCurve2d.cxx index 2e8ee6d052..2091e132dd 100644 --- a/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BezierCurve2d.cxx +++ b/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BezierCurve2d.cxx @@ -50,8 +50,7 @@ void DrawTrSurf_BezierCurve2d::DrawOn(Draw_Display& dis) const if (drawPoles) { dis.SetColor(polesLook); - NCollection_Array1 CPoles(1, C->NbPoles()); - C->Poles(CPoles); + const NCollection_Array1& CPoles = C->Poles(); dis.MoveTo(CPoles(1)); for (int i = 2; i <= C->NbPoles(); i++) { diff --git a/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BezierSurface.cxx b/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BezierSurface.cxx index a37c9c7ac2..c362f67e04 100644 --- a/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BezierSurface.cxx +++ b/src/Draw/TKDraw/DrawTrSurf/DrawTrSurf_BezierSurface.cxx @@ -57,11 +57,10 @@ void DrawTrSurf_BezierSurface::DrawOn(Draw_Display& dis) const occ::handle S = occ::down_cast(surf); if (drawPoles) { - int NbUPoles = S->NbUPoles(); - int NbVPoles = S->NbVPoles(); dis.SetColor(polesLook); - NCollection_Array2 SPoles(1, NbUPoles, 1, NbVPoles); - S->Poles(SPoles); + const NCollection_Array2& SPoles = S->Poles(); + int NbUPoles = SPoles.NbRows(); + int NbVPoles = SPoles.NbColumns(); for (j = 1; j <= NbVPoles; j++) { dis.MoveTo(SPoles(1, j)); diff --git a/src/Draw/TKQADraw/QABugs/QABugs_11.cxx b/src/Draw/TKQADraw/QABugs/QABugs_11.cxx index e75cfd3831..eb94f4098c 100644 --- a/src/Draw/TKQADraw/QABugs/QABugs_11.cxx +++ b/src/Draw/TKQADraw/QABugs/QABugs_11.cxx @@ -4558,11 +4558,11 @@ int OCC22301(Draw_Interpretor& di, int argc, const char** argv) bool isAffected; - isAffected = aFullMask.Intersect(aPartMask); // true; extent == 2 (OK) + isAffected = NCollection_PackedMapAlgo::Intersect(aFullMask, aPartMask); // true; extent == 2 (OK) di << "First time: aFullMask.Intersect(aPartMask), isAffected = " << (int)isAffected << "\n"; - isAffected = aFullMask.Intersect(aPartMask); // true; extent == 0 (?) + isAffected = NCollection_PackedMapAlgo::Intersect(aFullMask, aPartMask); // true; extent == 0 (?) di << "Second time: aFullMask.Intersect(aPartMask), isAffected = " << (int)isAffected << "\n"; - isAffected = aFullMask.Subtract(aPartMask); // false (?) + isAffected = NCollection_PackedMapAlgo::Subtract(aFullMask, aPartMask); // false (?) di << "After two intersections: aFullMask.Subtract(aPartMask), isAffected = " << (int)isAffected << "\n"; diff --git a/src/Draw/TKTopTest/GeometryTest/GeometryTest_CurveCommands.cxx b/src/Draw/TKTopTest/GeometryTest/GeometryTest_CurveCommands.cxx index 227e22639f..13ba21204c 100644 --- a/src/Draw/TKTopTest/GeometryTest/GeometryTest_CurveCommands.cxx +++ b/src/Draw/TKTopTest/GeometryTest/GeometryTest_CurveCommands.cxx @@ -787,14 +787,10 @@ static int movelaw(Draw_Interpretor& di, int n, const char** a) condition = std::max(Draw::Atoi(a[5]), -1); condition = std::min(condition, G2->Degree() - 1); } - NCollection_Array1 curve_poles(1, G2->NbPoles()); - NCollection_Array1 law_poles(1, G2->NbPoles()); - NCollection_Array1 law_knots(1, G2->NbKnots()); - NCollection_Array1 law_mults(1, G2->NbKnots()); - - G2->Knots(law_knots); - G2->Multiplicities(law_mults); - G2->Poles(curve_poles); + NCollection_Array1 curve_poles(G2->Poles()); + NCollection_Array1 law_poles(1, G2->NbPoles()); + const NCollection_Array1& law_knots = G2->Knots(); + const NCollection_Array1& law_mults = G2->Multiplicities(); for (ii = 1; ii <= G2->NbPoles(); ii++) { law_poles(ii) = curve_poles(ii).Coord(2); @@ -843,9 +839,8 @@ static void ComputeDeviation(const Adaptor3d_Curve& theCurve, theImax = 0; // take knots - int nbp = thePnts->NbKnots(); - NCollection_Array1 aKnots(1, nbp); - thePnts->Knots(aKnots); + const NCollection_Array1& aKnots = thePnts->Knots(); + int nbp = aKnots.Length(); int i; for (i = 1; i < nbp; ++i) diff --git a/src/Draw/TKTopTest/GeomliteTest/GeomliteTest_SurfaceCommands.cxx b/src/Draw/TKTopTest/GeomliteTest/GeomliteTest_SurfaceCommands.cxx index bfd47c6a45..7db10c9920 100644 --- a/src/Draw/TKTopTest/GeomliteTest/GeomliteTest_SurfaceCommands.cxx +++ b/src/Draw/TKTopTest/GeomliteTest/GeomliteTest_SurfaceCommands.cxx @@ -851,8 +851,7 @@ static int convbz(Draw_Interpretor& di, int n, const char** a) di << "the curve " << kk << "is not a BezierCurve\n"; return 1; } - NCollection_Array1 Poles(1, BZ->NbPoles()); - BZ->Poles(Poles); + NCollection_Array1 Poles(BZ->Poles()); Conv.AddCurve(Poles); } diff --git a/src/Draw/TKTopTest/SWDRAW/SWDRAW_ShapeCustom.cxx b/src/Draw/TKTopTest/SWDRAW/SWDRAW_ShapeCustom.cxx index 620376e0a0..e20332544d 100644 --- a/src/Draw/TKTopTest/SWDRAW/SWDRAW_ShapeCustom.cxx +++ b/src/Draw/TKTopTest/SWDRAW/SWDRAW_ShapeCustom.cxx @@ -171,9 +171,8 @@ static void expcurv2d(const occ::handle& aCurve, Nb.ChangeValue(1, 3)++; if (aCont < theCont && Bs->NbKnots() > 2) { - NCollection_Array1 aKnots(1, Bs->NbKnots()); - Bs->Knots(aKnots); - int nbInt = ckeckKnots(aKnots, theFirst, theLast); + const NCollection_Array1& aKnots = Bs->Knots(); + int nbInt = ckeckKnots(aKnots, theFirst, theLast); if (nbInt > 1) Nb.ChangeValue(1, 4)++; } @@ -235,9 +234,8 @@ static void expcurv(const occ::handle& aCurve, Nb.ChangeValue(1, 3)++; if (aCont < theCont && Bs->NbKnots() > 2) { - NCollection_Array1 aKnots(1, Bs->NbKnots()); - Bs->Knots(aKnots); - int nbInt = ckeckKnots(aKnots, theFirst, theLast); + const NCollection_Array1& aKnots = Bs->Knots(); + int nbInt = ckeckKnots(aKnots, theFirst, theLast); if (nbInt > 1) Nb.ChangeValue(1, 4)++; } diff --git a/src/FoundationClasses/TKMath/BSplCLib/BSplCLib.cxx b/src/FoundationClasses/TKMath/BSplCLib/BSplCLib.cxx index 26c3a63c42..b3de14e41a 100644 --- a/src/FoundationClasses/TKMath/BSplCLib/BSplCLib.cxx +++ b/src/FoundationClasses/TKMath/BSplCLib/BSplCLib.cxx @@ -4630,3 +4630,42 @@ const double& BSplCLib::FlatBezierKnots(const int Degree) return knots[25 - Degree]; } + +//================================================================================================== + +namespace +{ +struct UnitWeightsArray +{ + double Data[2049]; + + constexpr UnitWeightsArray() + : Data{} + { + for (int i = 0; i < 2049; ++i) + Data[i] = 1.0; + } +}; + +static constexpr UnitWeightsArray THE_UNIT_WEIGHTS{}; +} // namespace + +NCollection_Array1 BSplCLib::UnitWeights(const int theNbElems) +{ + if (theNbElems <= MaxUnitWeightsSize()) + { + // Non-owning view over global static array (zero allocation). + return NCollection_Array1(THE_UNIT_WEIGHTS.Data[0], 1, theNbElems); + } + // Rare: allocate fresh array. + NCollection_Array1 aResult(1, theNbElems); + aResult.Init(1.0); + return aResult; +} + +//================================================================================================== + +const double* BSplCLib::UnitWeightsData() +{ + return THE_UNIT_WEIGHTS.Data; +} diff --git a/src/FoundationClasses/TKMath/BSplCLib/BSplCLib.hxx b/src/FoundationClasses/TKMath/BSplCLib/BSplCLib.hxx index bd8f644822..a022cf56ab 100644 --- a/src/FoundationClasses/TKMath/BSplCLib/BSplCLib.hxx +++ b/src/FoundationClasses/TKMath/BSplCLib/BSplCLib.hxx @@ -458,6 +458,25 @@ public: //! Used as argument for a flatknots evaluation. static NCollection_Array1* NoMults(); + //! Returns the maximum number of elements supported by the pre-allocated + //! unit weights array (2049). For sizes larger than this, UnitWeights() + //! will allocate a new array. + static constexpr int MaxUnitWeightsSize() { return 2049; } + + //! Returns an NCollection_Array1 filled with 1.0 values. + //! If theNbElems <= MaxUnitWeightsSize(), references a pre-allocated global array + //! (zero allocation). Otherwise, allocates a new array and fills with 1.0. + //! @warning The returned array may reference global static memory -- do NOT modify elements. + //! @param[in] theNbElems the number of elements in the returned array + //! @return array of unit weights with bounds [1, theNbElems] + Standard_EXPORT static NCollection_Array1 UnitWeights(const int theNbElems); + + //! Returns a pointer to the pre-allocated unit weights static array. + //! The array contains MaxUnitWeightsSize() elements, all equal to 1.0. + //! @warning Do NOT modify elements through this pointer. + //! @return pointer to the first element of the static unit weights array + Standard_EXPORT static const double* UnitWeightsData(); + //! Stores in LK the useful knots for the BoorSchem //! on the span Knots(Index) - Knots(Index+1) Standard_EXPORT static void BuildKnots(const int Degree, diff --git a/src/FoundationClasses/TKMath/BSplSLib/BSplSLib.cxx b/src/FoundationClasses/TKMath/BSplSLib/BSplSLib.cxx index 0fc176dca5..3641933e63 100644 --- a/src/FoundationClasses/TKMath/BSplSLib/BSplSLib.cxx +++ b/src/FoundationClasses/TKMath/BSplSLib/BSplSLib.cxx @@ -3844,3 +3844,23 @@ void BSplSLib::FunctionMultiply(const BSplSLib_EvaluatorFunction& Function, throw Standard_ConstructionError(); } } + +//================================================================================================== + +NCollection_Array2 BSplSLib::UnitWeights(const int theNbUPoles, const int theNbVPoles) +{ + const int aTotal = theNbUPoles * theNbVPoles; + if (aTotal <= BSplCLib::MaxUnitWeightsSize()) + { + // Non-owning view over global static array (zero allocation). + return NCollection_Array2(BSplCLib::UnitWeightsData()[0], + 1, + theNbUPoles, + 1, + theNbVPoles); + } + // Rare: allocate fresh array. + NCollection_Array2 aResult(1, theNbUPoles, 1, theNbVPoles); + aResult.Init(1.0); + return aResult; +} diff --git a/src/FoundationClasses/TKMath/BSplSLib/BSplSLib.hxx b/src/FoundationClasses/TKMath/BSplSLib/BSplSLib.hxx index 6c1c9e8f43..f15069245c 100644 --- a/src/FoundationClasses/TKMath/BSplSLib/BSplSLib.hxx +++ b/src/FoundationClasses/TKMath/BSplSLib/BSplSLib.hxx @@ -769,6 +769,17 @@ public: NCollection_Array2& NewNumerator, NCollection_Array2& NewDenominator, int& theStatus); + + //! Returns an NCollection_Array2 filled with 1.0 values. + //! If theNbUPoles * theNbVPoles <= BSplCLib::MaxUnitWeightsSize(), + //! references a pre-allocated global array (zero allocation). + //! Otherwise, allocates a new array and fills with 1.0. + //! @warning The returned array may reference global static memory -- do NOT modify elements. + //! @param[in] theNbUPoles number of poles in U direction + //! @param[in] theNbVPoles number of poles in V direction + //! @return array of unit weights with bounds [1, theNbUPoles] x [1, theNbVPoles] + Standard_EXPORT static NCollection_Array2 UnitWeights(const int theNbUPoles, + const int theNbVPoles); }; #include diff --git a/src/FoundationClasses/TKMath/GTests/BSplCLib_Test.cxx b/src/FoundationClasses/TKMath/GTests/BSplCLib_Test.cxx new file mode 100644 index 0000000000..4d50824c62 --- /dev/null +++ b/src/FoundationClasses/TKMath/GTests/BSplCLib_Test.cxx @@ -0,0 +1,76 @@ +// Copyright (c) 2025 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include + +TEST(BSplCLibTest, UnitWeights_SmallSize_ReturnsNonOwning) +{ + const int aNbElems = 10; + const NCollection_Array1 aWeights = BSplCLib::UnitWeights(aNbElems); + + EXPECT_EQ(aWeights.Lower(), 1); + EXPECT_EQ(aWeights.Upper(), aNbElems); + EXPECT_EQ(aWeights.Length(), aNbElems); + EXPECT_FALSE(aWeights.IsDeletable()); + + for (int i = 1; i <= aNbElems; ++i) + { + EXPECT_DOUBLE_EQ(aWeights(i), 1.0); + } +} + +TEST(BSplCLibTest, UnitWeights_MaxSize_ReturnsNonOwning) +{ + const int aNbElems = BSplCLib::MaxUnitWeightsSize(); + const NCollection_Array1 aWeights = BSplCLib::UnitWeights(aNbElems); + + EXPECT_EQ(aWeights.Length(), aNbElems); + EXPECT_FALSE(aWeights.IsDeletable()); + + EXPECT_DOUBLE_EQ(aWeights(1), 1.0); + EXPECT_DOUBLE_EQ(aWeights(aNbElems), 1.0); +} + +TEST(BSplCLibTest, UnitWeights_OverMaxSize_ReturnsOwning) +{ + const int aNbElems = BSplCLib::MaxUnitWeightsSize() + 1; + const NCollection_Array1 aWeights = BSplCLib::UnitWeights(aNbElems); + + EXPECT_EQ(aWeights.Lower(), 1); + EXPECT_EQ(aWeights.Upper(), aNbElems); + EXPECT_EQ(aWeights.Length(), aNbElems); + EXPECT_TRUE(aWeights.IsDeletable()); + + for (int i = 1; i <= aNbElems; ++i) + { + EXPECT_DOUBLE_EQ(aWeights(i), 1.0); + } +} + +TEST(BSplCLibTest, UnitWeights_SingleElement) +{ + const NCollection_Array1 aWeights = BSplCLib::UnitWeights(1); + + EXPECT_EQ(aWeights.Length(), 1); + EXPECT_FALSE(aWeights.IsDeletable()); + EXPECT_DOUBLE_EQ(aWeights(1), 1.0); +} + +TEST(BSplCLibTest, MaxUnitWeightsSize_IsPositive) +{ + EXPECT_GT(BSplCLib::MaxUnitWeightsSize(), 0); + EXPECT_EQ(BSplCLib::MaxUnitWeightsSize(), 2049); +} diff --git a/src/FoundationClasses/TKMath/GTests/BSplSLib_Test.cxx b/src/FoundationClasses/TKMath/GTests/BSplSLib_Test.cxx new file mode 100644 index 0000000000..33fba55534 --- /dev/null +++ b/src/FoundationClasses/TKMath/GTests/BSplSLib_Test.cxx @@ -0,0 +1,93 @@ +// Copyright (c) 2025 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include +#include + +TEST(BSplSLibTest, UnitWeights_SmallSurface_ReturnsNonOwning) +{ + const int aNbU = 4; + const int aNbV = 5; + const NCollection_Array2 aWeights = BSplSLib::UnitWeights(aNbU, aNbV); + + EXPECT_EQ(aWeights.ColLength(), aNbU); + EXPECT_EQ(aWeights.RowLength(), aNbV); + EXPECT_EQ(aWeights.Size(), aNbU * aNbV); + EXPECT_FALSE(aWeights.IsDeletable()); + + for (int i = 1; i <= aNbU; ++i) + { + for (int j = 1; j <= aNbV; ++j) + { + EXPECT_DOUBLE_EQ(aWeights(i, j), 1.0); + } + } +} + +TEST(BSplSLibTest, UnitWeights_MaxBezierSize_ReturnsNonOwning) +{ + // Max Bezier: 26x26 = 676 poles, well within limit + const int aNbU = 26; + const int aNbV = 26; + const NCollection_Array2 aWeights = BSplSLib::UnitWeights(aNbU, aNbV); + + EXPECT_EQ(aWeights.Size(), aNbU * aNbV); + EXPECT_FALSE(aWeights.IsDeletable()); + EXPECT_DOUBLE_EQ(aWeights(1, 1), 1.0); + EXPECT_DOUBLE_EQ(aWeights(aNbU, aNbV), 1.0); +} + +TEST(BSplSLibTest, UnitWeights_AtMaxLimit_ReturnsNonOwning) +{ + // Exactly at the limit: 2049 total poles + const int aNbU = 3; + const int aNbV = 683; + const NCollection_Array2 aWeights = BSplSLib::UnitWeights(aNbU, aNbV); + + EXPECT_EQ(aWeights.Size(), aNbU * aNbV); + EXPECT_FALSE(aWeights.IsDeletable()); + EXPECT_DOUBLE_EQ(aWeights(1, 1), 1.0); + EXPECT_DOUBLE_EQ(aWeights(aNbU, aNbV), 1.0); +} + +TEST(BSplSLibTest, UnitWeights_OverMaxLimit_ReturnsOwning) +{ + // Over the limit: needs allocation + const int aNbU = 50; + const int aNbV = 50; + const NCollection_Array2 aWeights = BSplSLib::UnitWeights(aNbU, aNbV); + + EXPECT_EQ(aWeights.ColLength(), aNbU); + EXPECT_EQ(aWeights.RowLength(), aNbV); + EXPECT_EQ(aWeights.Size(), aNbU * aNbV); + EXPECT_TRUE(aWeights.IsDeletable()); + + for (int i = 1; i <= aNbU; ++i) + { + for (int j = 1; j <= aNbV; ++j) + { + EXPECT_DOUBLE_EQ(aWeights(i, j), 1.0); + } + } +} + +TEST(BSplSLibTest, UnitWeights_SingleElement) +{ + const NCollection_Array2 aWeights = BSplSLib::UnitWeights(1, 1); + + EXPECT_EQ(aWeights.Size(), 1); + EXPECT_FALSE(aWeights.IsDeletable()); + EXPECT_DOUBLE_EQ(aWeights(1, 1), 1.0); +} diff --git a/src/FoundationClasses/TKMath/GTests/FILES.cmake b/src/FoundationClasses/TKMath/GTests/FILES.cmake index 2d8ec9607d..b513fafa0a 100644 --- a/src/FoundationClasses/TKMath/GTests/FILES.cmake +++ b/src/FoundationClasses/TKMath/GTests/FILES.cmake @@ -8,7 +8,9 @@ set(OCCT_TKMath_GTests_FILES Bnd_Box_Test.cxx Bnd_OBB_Test.cxx BSplCLib_Cache_Test.cxx + BSplCLib_Test.cxx BSplSLib_Cache_Test.cxx + BSplSLib_Test.cxx BVH_BinnedBuilder_Test.cxx BVH_Box_Test.cxx BVH_BuildQueue_Test.cxx diff --git a/src/ModelingAlgorithms/TKBO/IntTools/IntTools_BeanFaceIntersector.cxx b/src/ModelingAlgorithms/TKBO/IntTools/IntTools_BeanFaceIntersector.cxx index 6104b19be5..6dbe3775f8 100644 --- a/src/ModelingAlgorithms/TKBO/IntTools/IntTools_BeanFaceIntersector.cxx +++ b/src/ModelingAlgorithms/TKBO/IntTools/IntTools_BeanFaceIntersector.cxx @@ -2152,16 +2152,13 @@ void ComputeGridPoints(const BRepAdaptor_Surface& theSurf, const double theTolerance, IntTools_SurfaceRangeLocalizeData& theSurfaceData) { - int i; - int j; - int k; - int aNbSamples[2] = {theSurf.UDegree(), theSurf.VDegree()}; - int aNbKnots[2] = {theSurf.NbUKnots(), theSurf.NbVKnots()}; - NCollection_Array1 aKnotsU(1, aNbKnots[0]); - NCollection_Array1 aKnotsV(1, aNbKnots[1]); - - theBsplSurf->UKnots(aKnotsU); - theBsplSurf->VKnots(aKnotsV); + int i; + int j; + int k; + int aNbSamples[2] = {theSurf.UDegree(), theSurf.VDegree()}; + int aNbKnots[2] = {theSurf.NbUKnots(), theSurf.NbVKnots()}; + const NCollection_Array1& aKnotsU = theBsplSurf->UKnots(); + const NCollection_Array1& aKnotsV = theBsplSurf->VKnots(); int iLmI; int iMin[2] = {-1, -1}; diff --git a/src/ModelingAlgorithms/TKBO/IntTools/IntTools_TopolTool.cxx b/src/ModelingAlgorithms/TKBO/IntTools/IntTools_TopolTool.cxx index 7d2a2eb119..1a553b053f 100644 --- a/src/ModelingAlgorithms/TKBO/IntTools/IntTools_TopolTool.cxx +++ b/src/ModelingAlgorithms/TKBO/IntTools/IntTools_TopolTool.cxx @@ -275,8 +275,7 @@ void IntTools_TopolTool::ComputeSamplePoints() if (nbsu > 10 || nbsv > 10) { - NCollection_Array2 array2(1, myS->NbUPoles(), 1, myS->NbVPoles()); - myS->Bezier()->Poles(array2); + const NCollection_Array2& array2 = myS->Bezier()->Poles(); Analyse(array2, nbsu, nbsv); } @@ -298,8 +297,7 @@ void IntTools_TopolTool::ComputeSamplePoints() if (nbsu > 10 || nbsv > 10) { - NCollection_Array2 array2(1, myS->NbUPoles(), 1, myS->NbVPoles()); - myS->BSpline()->Poles(array2); + const NCollection_Array2& array2 = myS->BSpline()->Poles(); Analyse(array2, nbsu, nbsv); } if (nbsu < 10) diff --git a/src/ModelingAlgorithms/TKBool/BRepFill/BRepFill_NSections.cxx b/src/ModelingAlgorithms/TKBool/BRepFill/BRepFill_NSections.cxx index 64ef35c2d0..be15049d46 100644 --- a/src/ModelingAlgorithms/TKBool/BRepFill/BRepFill_NSections.cxx +++ b/src/ModelingAlgorithms/TKBool/BRepFill/BRepFill_NSections.cxx @@ -109,8 +109,7 @@ static occ::handle EdgeToBSpline(const TopoDS_Edge& theEdge) aBSCurve->Transform(aLoc.Transformation()); // reparameterize to [0,1] - NCollection_Array1 aKnots(1, aBSCurve->NbKnots()); - aBSCurve->Knots(aKnots); + NCollection_Array1 aKnots(aBSCurve->Knots()); BSplCLib::Reparametrize(0., 1., aKnots); aBSCurve->SetKnots(aKnots); } diff --git a/src/ModelingAlgorithms/TKBool/TopOpeBRepBuild/TopOpeBRepBuild_FuseFace.cxx b/src/ModelingAlgorithms/TKBool/TopOpeBRepBuild/TopOpeBRepBuild_FuseFace.cxx index 7588beee8b..be38017b88 100644 --- a/src/ModelingAlgorithms/TKBool/TopOpeBRepBuild/TopOpeBRepBuild_FuseFace.cxx +++ b/src/ModelingAlgorithms/TKBool/TopOpeBRepBuild/TopOpeBRepBuild_FuseFace.cxx @@ -1285,9 +1285,8 @@ bool SameSupport(const TopoDS_Edge& E1, const TopoDS_Edge& E2) return false; } - NCollection_Array1 P1(1, nbpoles), P2(1, nbpoles); - B1->Poles(P1); - B2->Poles(P2); + const NCollection_Array1& P1 = B1->Poles(); + const NCollection_Array1& P2 = B2->Poles(); double tol3d = BRep_Tool::Tolerance(E1); for (int p = 1; p <= nbpoles; p++) @@ -1298,13 +1297,11 @@ bool SameSupport(const TopoDS_Edge& E1, const TopoDS_Edge& E2) } } - NCollection_Array1 K1(1, nbknots), K2(1, nbknots); - B1->Knots(K1); - B2->Knots(K2); + const NCollection_Array1& K1 = B1->Knots(); + const NCollection_Array1& K2 = B2->Knots(); - NCollection_Array1 M1(1, nbknots), M2(1, nbknots); - B1->Multiplicities(M1); - B2->Multiplicities(M2); + const NCollection_Array1& M1 = B1->Multiplicities(); + const NCollection_Array1& M2 = B2->Multiplicities(); for (int k = 1; k <= nbknots; k++) { @@ -1335,9 +1332,8 @@ bool SameSupport(const TopoDS_Edge& E1, const TopoDS_Edge& E2) if (B1->IsRational()) { - NCollection_Array1 W1(1, nbpoles), W2(1, nbpoles); - B1->Weights(W1); - B2->Weights(W2); + const NCollection_Array1& W1 = B1->WeightsArray(); + const NCollection_Array1& W2 = B2->WeightsArray(); for (int w = 1; w <= nbpoles; w++) { @@ -1360,9 +1356,8 @@ bool SameSupport(const TopoDS_Edge& E1, const TopoDS_Edge& E2) return false; } - NCollection_Array1 P1(1, nbpoles), P2(1, nbpoles); - B1->Poles(P1); - B2->Poles(P2); + const NCollection_Array1& P1 = B1->Poles(); + const NCollection_Array1& P2 = B2->Poles(); for (int p = 1; p <= nbpoles; p++) { @@ -1389,9 +1384,8 @@ bool SameSupport(const TopoDS_Edge& E1, const TopoDS_Edge& E2) if (B1->IsRational()) { - NCollection_Array1 W1(1, nbpoles), W2(1, nbpoles); - B1->Weights(W1); - B2->Weights(W2); + const NCollection_Array1& W1 = B1->WeightsArray(); + const NCollection_Array1& W2 = B2->WeightsArray(); for (int w = 1; w <= nbpoles; w++) { diff --git a/src/ModelingAlgorithms/TKBool/TopOpeBRepTool/TopOpeBRepTool_CurveTool.cxx b/src/ModelingAlgorithms/TKBool/TopOpeBRepTool/TopOpeBRepTool_CurveTool.cxx index 17d3559188..acad1a7c25 100644 --- a/src/ModelingAlgorithms/TKBool/TopOpeBRepTool/TopOpeBRepTool_CurveTool.cxx +++ b/src/ModelingAlgorithms/TKBool/TopOpeBRepTool/TopOpeBRepTool_CurveTool.cxx @@ -344,20 +344,16 @@ bool TopOpeBRepTool_CurveTool::MakeCurves(const double parmi // std::cout <<"nbpol = " << nbpol << std::endl; if (nbpol > 100) { - NCollection_Array1 PolC3D(1, nbpol); - NCollection_Array1 PolPC1(1, nbpol); - NCollection_Array1 PolPC2(1, nbpol); - NCollection_Array1 IsValid(1, nbpol); + const NCollection_Array1& PolC3D = HC3D->Poles(); + NCollection_Array1 aDummyPnt2d; + const NCollection_Array1& PolPC1 = CompPC1 ? HPC1->Poles() : aDummyPnt2d; + const NCollection_Array1& PolPC2 = CompPC2 ? HPC2->Poles() : aDummyPnt2d; + NCollection_Array1 IsValid(1, nbpol); IsValid.Init(true); double tol = std::max(1.e-10, 100. * tol3d * tol3d); // tol *= tol; - square distance double tl2d = tol * (tol2d * tol2d) / (tol3d * tol3d); double def = tol; double def2d = tol2d; - HC3D->Poles(PolC3D); - if (CompPC1) - HPC1->Poles(PolPC1); - if (CompPC2) - HPC2->Poles(PolPC2); int ip = 1, NbPol = 1; double d, d1, d2; @@ -529,11 +525,10 @@ bool TopOpeBRepTool_CurveTool::MakeCurves(const double parmi int degmax = 8; Approx_ParametrizationType parametrization = Approx_ChordLength; - int npol = HC3D->NbPoles(); - NCollection_Array1 Polc3d(1, npol); - NCollection_Array1 par(1, npol); - HC3D->Poles(Polc3d); - gp_Pnt P = Polc3d(1); + int npol = HC3D->NbPoles(); + const NCollection_Array1& Polc3d = HC3D->Poles(); + NCollection_Array1 par(1, npol); + gp_Pnt P = Polc3d(1); bool IsBad = false; int ip; diff --git a/src/ModelingAlgorithms/TKBool/TopOpeBRepTool/TopOpeBRepTool_FuseEdges.cxx b/src/ModelingAlgorithms/TKBool/TopOpeBRepTool/TopOpeBRepTool_FuseEdges.cxx index 2acae62355..a41ec5c138 100644 --- a/src/ModelingAlgorithms/TKBool/TopOpeBRepTool/TopOpeBRepTool_FuseEdges.cxx +++ b/src/ModelingAlgorithms/TKBool/TopOpeBRepTool/TopOpeBRepTool_FuseEdges.cxx @@ -745,9 +745,8 @@ bool TopOpeBRepTool_FuseEdges::SameSupport(const TopoDS_Edge& E1, const TopoDS_E return false; } - NCollection_Array1 P1(1, nbpoles), P2(1, nbpoles); - B1->Poles(P1); - B2->Poles(P2); + const NCollection_Array1& P1 = B1->Poles(); + const NCollection_Array1& P2 = B2->Poles(); double tol3d = BRep_Tool::Tolerance(E1); for (int p = 1; p <= nbpoles; p++) @@ -758,13 +757,11 @@ bool TopOpeBRepTool_FuseEdges::SameSupport(const TopoDS_Edge& E1, const TopoDS_E } } - NCollection_Array1 K1(1, nbknots), K2(1, nbknots); - B1->Knots(K1); - B2->Knots(K2); + const NCollection_Array1& K1 = B1->Knots(); + const NCollection_Array1& K2 = B2->Knots(); - NCollection_Array1 M1(1, nbknots), M2(1, nbknots); - B1->Multiplicities(M1); - B2->Multiplicities(M2); + const NCollection_Array1& M1 = B1->Multiplicities(); + const NCollection_Array1& M2 = B2->Multiplicities(); for (int k = 1; k <= nbknots; k++) { @@ -795,9 +792,8 @@ bool TopOpeBRepTool_FuseEdges::SameSupport(const TopoDS_Edge& E1, const TopoDS_E if (B1->IsRational()) { - NCollection_Array1 W1(1, nbpoles), W2(1, nbpoles); - B1->Weights(W1); - B2->Weights(W2); + const NCollection_Array1& W1 = B1->WeightsArray(); + const NCollection_Array1& W2 = B2->WeightsArray(); for (int w = 1; w <= nbpoles; w++) { @@ -828,9 +824,8 @@ bool TopOpeBRepTool_FuseEdges::SameSupport(const TopoDS_Edge& E1, const TopoDS_E return false; } - NCollection_Array1 P1(1, nbpoles), P2(1, nbpoles); - B1->Poles(P1); - B2->Poles(P2); + const NCollection_Array1& P1 = B1->Poles(); + const NCollection_Array1& P2 = B2->Poles(); for (int p = 1; p <= nbpoles; p++) { @@ -857,9 +852,8 @@ bool TopOpeBRepTool_FuseEdges::SameSupport(const TopoDS_Edge& E1, const TopoDS_E if (B1->IsRational()) { - NCollection_Array1 W1(1, nbpoles), W2(1, nbpoles); - B1->Weights(W1); - B2->Weights(W2); + const NCollection_Array1& W1 = B1->WeightsArray(); + const NCollection_Array1& W2 = B2->WeightsArray(); for (int w = 1; w <= nbpoles; w++) { @@ -980,8 +974,7 @@ bool TopOpeBRepTool_FuseEdges::UpdatePCurve(const TopoDS_Edge& || std::abs(last - el) > Precision::PConfusion()) { occ::handle bc = occ::down_cast(Curv2d); - NCollection_Array1 Knots(1, bc->NbKnots()); - bc->Knots(Knots); + NCollection_Array1 Knots(bc->Knots()); BSplCLib::Reparametrize(ef, el, Knots); bc->SetKnots(Knots); } diff --git a/src/ModelingAlgorithms/TKFeat/LocOpe/LocOpe_FindEdges.cxx b/src/ModelingAlgorithms/TKFeat/LocOpe/LocOpe_FindEdges.cxx index 037903bf49..fe54ca8686 100644 --- a/src/ModelingAlgorithms/TKFeat/LocOpe/LocOpe_FindEdges.cxx +++ b/src/ModelingAlgorithms/TKFeat/LocOpe/LocOpe_FindEdges.cxx @@ -253,9 +253,8 @@ void LocOpe_FindEdges::Set(const TopoDS_Shape& FFrom, const TopoDS_Shape& FTo) if (IsSame) { - NCollection_Array1 Pf(1, nbpoles), Pt(1, nbpoles); - Bf->Poles(Pf); - Bt->Poles(Pt); + const NCollection_Array1& Pf = Bf->Poles(); + const NCollection_Array1& Pt = Bt->Poles(); double tol3d = BRep_Tool::Tolerance(edgt); for (int p = 1; p <= nbpoles; p++) @@ -269,13 +268,11 @@ void LocOpe_FindEdges::Set(const TopoDS_Shape& FFrom, const TopoDS_Shape& FTo) if (IsSame) { - NCollection_Array1 Kf(1, nbknots), Kt(1, nbknots); - Bf->Knots(Kf); - Bt->Knots(Kt); + const NCollection_Array1& Kf = Bf->Knots(); + const NCollection_Array1& Kt = Bt->Knots(); - NCollection_Array1 Mf(1, nbknots), Mt(1, nbknots); - Bf->Multiplicities(Mf); - Bt->Multiplicities(Mt); + const NCollection_Array1& Mf = Bf->Multiplicities(); + const NCollection_Array1& Mt = Bt->Multiplicities(); for (int k = 1; k <= nbknots; k++) { @@ -308,9 +305,8 @@ void LocOpe_FindEdges::Set(const TopoDS_Shape& FFrom, const TopoDS_Shape& FTo) if (IsSame && Bf->IsRational()) { - NCollection_Array1 Wf(1, nbpoles), Wt(1, nbpoles); - Bf->Weights(Wf); - Bt->Weights(Wt); + const NCollection_Array1& Wf = Bf->WeightsArray(); + const NCollection_Array1& Wt = Bt->WeightsArray(); for (int w = 1; w <= nbpoles; w++) { @@ -350,9 +346,8 @@ void LocOpe_FindEdges::Set(const TopoDS_Shape& FFrom, const TopoDS_Shape& FTo) if (IsSame) { - NCollection_Array1 Pf(1, nbpoles), Pt(1, nbpoles); - Bf->Poles(Pf); - Bt->Poles(Pt); + const NCollection_Array1& Pf = Bf->Poles(); + const NCollection_Array1& Pt = Bt->Poles(); for (int p = 1; p <= nbpoles; p++) { @@ -382,9 +377,8 @@ void LocOpe_FindEdges::Set(const TopoDS_Shape& FFrom, const TopoDS_Shape& FTo) if (IsSame && Bf->IsRational()) { - NCollection_Array1 Wf(1, nbpoles), Wt(1, nbpoles); - Bf->Weights(Wf); - Bt->Weights(Wt); + const NCollection_Array1& Wf = Bf->WeightsArray(); + const NCollection_Array1& Wt = Bt->WeightsArray(); for (int w = 1; w <= nbpoles; w++) { diff --git a/src/ModelingAlgorithms/TKFeat/LocOpe/LocOpe_Pipe.cxx b/src/ModelingAlgorithms/TKFeat/LocOpe/LocOpe_Pipe.cxx index 52be3d89b2..307bcc5b80 100644 --- a/src/ModelingAlgorithms/TKFeat/LocOpe/LocOpe_Pipe.cxx +++ b/src/ModelingAlgorithms/TKFeat/LocOpe/LocOpe_Pipe.cxx @@ -358,9 +358,7 @@ const NCollection_Sequence>& LocOpe_Pipe::Curves( { C->Segment(p1, p2); } - int Nbkn = C->NbKnots(); - NCollection_Array1 Tkn(1, Nbkn); - C->Knots(Tkn); + NCollection_Array1 Tkn(C->Knots()); BSplCLib::Reparametrize(seq.Length(), seq.Length() + 1, Tkn); C->SetKnots(Tkn); seq.Append(C); @@ -487,9 +485,7 @@ occ::handle LocOpe_Pipe::BarycCurve() { C->Segment(p1, p2); } - int Nbkn = C->NbKnots(); - NCollection_Array1 Tkn(1, Nbkn); - C->Knots(Tkn); + NCollection_Array1 Tkn(C->Knots()); BSplCLib::Reparametrize(seq.Length(), seq.Length() + 1, Tkn); C->SetKnots(Tkn); seq.Append(C); diff --git a/src/ModelingAlgorithms/TKFillet/BlendFunc/BlendFunc.cxx b/src/ModelingAlgorithms/TKFillet/BlendFunc/BlendFunc.cxx index 57a91713db..6fc49a83c4 100644 --- a/src/ModelingAlgorithms/TKFillet/BlendFunc/BlendFunc.cxx +++ b/src/ModelingAlgorithms/TKFillet/BlendFunc/BlendFunc.cxx @@ -113,15 +113,13 @@ void BlendFunc::GetMinimalWeights(const BlendFunc_SectionShape SShape, gp_Circ C(popAx2, 1); occ::handle Sect1 = new Geom_TrimmedCurve(new Geom_Circle(C), 0., MaxAng); occ::handle CtoBspl = GeomConvert::CurveToBSplineCurve(Sect1, TConv); - CtoBspl->Weights(Weights); - - NCollection_Array1 poids(Weights.Lower(), Weights.Upper()); - double angle_min = std::max(Precision::PConfusion(), MinAng); + Weights.Assign(CtoBspl->WeightsArray()); + double angle_min = std::max(Precision::PConfusion(), MinAng); occ::handle Sect2 = new Geom_TrimmedCurve(new Geom_Circle(C), 0., angle_min); - CtoBspl = GeomConvert::CurveToBSplineCurve(Sect2, TConv); - CtoBspl->Weights(poids); + CtoBspl = GeomConvert::CurveToBSplineCurve(Sect2, TConv); + const NCollection_Array1& poids = CtoBspl->WeightsArray(); for (int ii = Weights.Lower(); ii <= Weights.Upper(); ii++) { diff --git a/src/ModelingAlgorithms/TKFillet/ChFi3d/ChFi3d_Builder_0.cxx b/src/ModelingAlgorithms/TKFillet/ChFi3d/ChFi3d_Builder_0.cxx index 179a5585af..5a945f323f 100644 --- a/src/ModelingAlgorithms/TKFillet/ChFi3d/ChFi3d_Builder_0.cxx +++ b/src/ModelingAlgorithms/TKFillet/ChFi3d/ChFi3d_Builder_0.cxx @@ -1325,13 +1325,10 @@ void ChFi3d_ReparamPcurv(const double Uf, const double Ul, occ::handleFirstParameter()) > Precision::PConfusion() || std::abs(Ul - pc->LastParameter()) > Precision::PConfusion()) { - NCollection_Array1 pol(1, pc->NbPoles()); - pc->Poles(pol); - NCollection_Array1 kn(1, pc->NbKnots()); - pc->Knots(kn); - NCollection_Array1 mu(1, pc->NbKnots()); - pc->Multiplicities(mu); - int deg = pc->Degree(); + const NCollection_Array1& pol = pc->Poles(); + NCollection_Array1 kn(pc->Knots()); + const NCollection_Array1& mu = pc->Multiplicities(); + int deg = pc->Degree(); BSplCLib::Reparametrize(Uf, Ul, kn); pc = new Geom2d_BSplineCurve(pol, kn, mu, deg); } @@ -4736,8 +4733,7 @@ Standard_EXPORT void ChFi3d_PerformElSpine(occ::handle& HES, // valide des aretes du chemin. BSpline = Concat.BSplineCurve(); // There is a reparametrisation to maximally connect the abscissas of edges. - NCollection_Array1 BSNoeuds(1, BSpline->NbKnots()); - BSpline->Knots(BSNoeuds); + NCollection_Array1 BSNoeuds(BSpline->Knots()); BSplCLib::Reparametrize(Wrefdeb, Wreffin, BSNoeuds); BSpline->SetKnots(BSNoeuds); // diff --git a/src/ModelingAlgorithms/TKFillet/ChFi3d/ChFi3d_Builder_1.cxx b/src/ModelingAlgorithms/TKFillet/ChFi3d/ChFi3d_Builder_1.cxx index 2357ae3916..eac12f82d4 100644 --- a/src/ModelingAlgorithms/TKFillet/ChFi3d/ChFi3d_Builder_1.cxx +++ b/src/ModelingAlgorithms/TKFillet/ChFi3d/ChFi3d_Builder_1.cxx @@ -286,8 +286,7 @@ static TopoDS_Edge MakeOffsetEdge(const TopoDS_Edge& theEdge, std::abs(LastDiff) > ParTol) { occ::handle BsplCurve = occ::down_cast(IntCurve); - NCollection_Array1 aKnots(1, BsplCurve->NbKnots()); - BsplCurve->Knots(aKnots); + NCollection_Array1 aKnots(BsplCurve->Knots()); BSplCLib::Reparametrize(aBAcurve.FirstParameter(), aBAcurve.LastParameter(), aKnots); BsplCurve->SetKnots(aKnots); if (aBAcurve.IsPeriodic() && !BsplCurve->IsPeriodic()) diff --git a/src/ModelingAlgorithms/TKFillet/ChFi3d/ChFi3d_FilBuilder_C2.cxx b/src/ModelingAlgorithms/TKFillet/ChFi3d/ChFi3d_FilBuilder_C2.cxx index 83a3874425..3599d63d26 100644 --- a/src/ModelingAlgorithms/TKFillet/ChFi3d/ChFi3d_FilBuilder_C2.cxx +++ b/src/ModelingAlgorithms/TKFillet/ChFi3d/ChFi3d_FilBuilder_C2.cxx @@ -616,8 +616,7 @@ void ChFi3d_FilBuilder::PerformTwoCorner(const int Index) std::max(parCP1, parCP2), tol2d); } - NCollection_Array1 kk(1, PCurveOnPiv->NbKnots()); - PCurveOnPiv->Knots(kk); + NCollection_Array1 kk(PCurveOnPiv->Knots()); BSplCLib::Reparametrize(0., 1., kk); PCurveOnPiv->SetKnots(kk); if (pcfalenvers) diff --git a/src/ModelingAlgorithms/TKFillet/ChFiKPart/ChFiKPart_ComputeData_Fcts.cxx b/src/ModelingAlgorithms/TKFillet/ChFiKPart/ChFiKPart_ComputeData_Fcts.cxx index 7bf8718e61..d5ab8c5143 100644 --- a/src/ModelingAlgorithms/TKFillet/ChFiKPart/ChFiKPart_ComputeData_Fcts.cxx +++ b/src/ModelingAlgorithms/TKFillet/ChFiKPart/ChFiKPart_ComputeData_Fcts.cxx @@ -90,40 +90,30 @@ void ChFiKPart_ProjPC(const GeomAdaptor_Curve& Cg, } break; case GeomAbs_BezierCurve: { - occ::handle BezProjc = Projc.Bezier(); - NCollection_Array1 TP(1, BezProjc->NbPoles()); + occ::handle BezProjc = Projc.Bezier(); + const NCollection_Array1& TP = BezProjc->Poles(); if (BezProjc->IsRational()) { - NCollection_Array1 TW(1, BezProjc->NbPoles()); - BezProjc->Poles(TP); - BezProjc->Weights(TW); - Pcurv = new Geom2d_BezierCurve(TP, TW); + Pcurv = new Geom2d_BezierCurve(TP, BezProjc->WeightsArray()); } else { - BezProjc->Poles(TP); Pcurv = new Geom2d_BezierCurve(TP); } } break; case GeomAbs_BSplineCurve: { - occ::handle BspProjc = Projc.BSpline(); - NCollection_Array1 TP(1, BspProjc->NbPoles()); - NCollection_Array1 TK(1, BspProjc->NbKnots()); - NCollection_Array1 TM(1, BspProjc->NbKnots()); + occ::handle BspProjc = Projc.BSpline(); + const NCollection_Array1& TP = BspProjc->Poles(); + const NCollection_Array1& TK = BspProjc->Knots(); + const NCollection_Array1& TM = BspProjc->Multiplicities(); - BspProjc->Knots(TK); - BspProjc->Multiplicities(TM); if (BspProjc->IsRational()) { - NCollection_Array1 TW(1, BspProjc->NbPoles()); - BspProjc->Poles(TP); - BspProjc->Weights(TW); - Pcurv = new Geom2d_BSplineCurve(TP, TW, TK, TM, BspProjc->Degree()); + Pcurv = new Geom2d_BSplineCurve(TP, BspProjc->WeightsArray(), TK, TM, BspProjc->Degree()); } else { - BspProjc->Poles(TP); Pcurv = new Geom2d_BSplineCurve(TP, TK, TM, BspProjc->Degree()); } } diff --git a/src/ModelingAlgorithms/TKGeomAlgo/FairCurve/FairCurve_Batten.cxx b/src/ModelingAlgorithms/TKGeomAlgo/FairCurve/FairCurve_Batten.cxx index 67439b4753..6831686ab5 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/FairCurve/FairCurve_Batten.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/FairCurve/FairCurve_Batten.cxx @@ -301,7 +301,7 @@ bool FairCurve_Batten::Compute(const gp_Vec2d& DeltaP1, } // Summing - DeltaCurve->Poles(NPoles->ChangeArray1()); + NPoles->ChangeArray1() = DeltaCurve->Poles(); for (kk = NPoles->Lower(); kk <= NPoles->Upper(); kk++) { NPoles->ChangeValue(kk).ChangeCoord() += Poles->Value(kk).Coord(); @@ -468,13 +468,11 @@ bool FairCurve_Batten::Compute(const gp_Vec2d& DeltaP1, NewBS->InsertKnots(NKnots->Array1(), NMults->Array1(), 1.e-10); occ::handle> NewNPoles = - new NCollection_HArray1(1, NewBS->NbPoles()); - NewBS->Poles(NewNPoles->ChangeArray1()); - NewBS->Multiplicities(NMults->ChangeArray1()); - NewBS->Knots(NKnots->ChangeArray1()); + new NCollection_HArray1(NewBS->Poles()); + NMults = new NCollection_HArray1(NewBS->Multiplicities()); + NKnots = new NCollection_HArray1(NewBS->Knots()); occ::handle> FKnots = - new NCollection_HArray1(1, NewBS->NbPoles() + Degree + 1); - NewBS->KnotSequence(FKnots->ChangeArray1()); + new NCollection_HArray1(NewBS->KnotSequence()); Poles = NewNPoles; Mults = NMults; diff --git a/src/ModelingAlgorithms/TKGeomAlgo/FairCurve/FairCurve_MinimalVariation.cxx b/src/ModelingAlgorithms/TKGeomAlgo/FairCurve/FairCurve_MinimalVariation.cxx index c6ff5a211f..6c59fcdf30 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/FairCurve/FairCurve_MinimalVariation.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/FairCurve/FairCurve_MinimalVariation.cxx @@ -268,7 +268,7 @@ bool FairCurve_MinimalVariation::Compute(const gp_Vec2d& DeltaP1, } // Summing - DeltaCurve->Poles(NPoles->ChangeArray1()); + NPoles->ChangeArray1() = DeltaCurve->Poles(); for (kk = NPoles->Lower(); kk <= NPoles->Upper(); kk++) { NPoles->ChangeValue(kk).ChangeCoord() += Poles->Value(kk).Coord(); @@ -466,13 +466,11 @@ bool FairCurve_MinimalVariation::Compute(const gp_Vec2d& DeltaP1, NewBS->InsertKnots(NKnots->Array1(), NMults->Array1(), 1.e-10); occ::handle> NewNPoles = - new NCollection_HArray1(1, NewBS->NbPoles()); - NewBS->Poles(NewNPoles->ChangeArray1()); - NewBS->Multiplicities(NMults->ChangeArray1()); - NewBS->Knots(NKnots->ChangeArray1()); + new NCollection_HArray1(NewBS->Poles()); + NMults = new NCollection_HArray1(NewBS->Multiplicities()); + NKnots = new NCollection_HArray1(NewBS->Knots()); occ::handle> FKnots = - new NCollection_HArray1(1, NewBS->NbPoles() + Degree + 1); - NewBS->KnotSequence(FKnots->ChangeArray1()); + new NCollection_HArray1(NewBS->KnotSequence()); Poles = NewNPoles; Mults = NMults; diff --git a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill.cxx b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill.cxx index 66386928da..4436dcb21b 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill.cxx @@ -244,14 +244,12 @@ void GeomFill::GetMinimalWeights(const Convert_ParameterisationType TConv, gp_Circ C(popAx2, 1); occ::handle Sect1 = new Geom_TrimmedCurve(new Geom_Circle(C), 0., MaxAng); occ::handle CtoBspl = GeomConvert::CurveToBSplineCurve(Sect1, TConv); - CtoBspl->Weights(Weights); - - NCollection_Array1 poids(Weights.Lower(), Weights.Upper()); - double angle_min = std::max(Precision::PConfusion(), MinAng); + Weights.Assign(CtoBspl->WeightsArray()); + double angle_min = std::max(Precision::PConfusion(), MinAng); occ::handle Sect2 = new Geom_TrimmedCurve(new Geom_Circle(C), 0., angle_min); CtoBspl = GeomConvert::CurveToBSplineCurve(Sect2, TConv); - CtoBspl->Weights(poids); + const NCollection_Array1& poids = CtoBspl->WeightsArray(); for (int ii = Weights.Lower(); ii <= Weights.Upper(); ii++) { diff --git a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_BSplineCurves.cxx b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_BSplineCurves.cxx index 63db9a754a..dfc461ae38 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_BSplineCurves.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_BSplineCurves.cxx @@ -133,38 +133,20 @@ static bool Arrange(const occ::handle& C1, static int SetSameDistribution(occ::handle& C1, occ::handle& C2) { - int nbp1 = C1->NbPoles(); - int nbk1 = C1->NbKnots(); - NCollection_Array1 P1(1, nbp1); - NCollection_Array1 W1(1, nbp1); - W1.Init(1.); - NCollection_Array1 K1(1, nbk1); - NCollection_Array1 M1(1, nbk1); + NCollection_Array1 P1(C1->Poles()); + const NCollection_Array1& W1 = C1->WeightsArray(); + NCollection_Array1 K1(C1->Knots()); + NCollection_Array1 M1(C1->Multiplicities()); - C1->Poles(P1); - if (C1->IsRational()) - C1->Weights(W1); - C1->Knots(K1); - C1->Multiplicities(M1); - - int nbp2 = C2->NbPoles(); - int nbk2 = C2->NbKnots(); - NCollection_Array1 P2(1, nbp2); - NCollection_Array1 W2(1, nbp2); - W2.Init(1.); - NCollection_Array1 K2(1, nbk2); - NCollection_Array1 M2(1, nbk2); - - C2->Poles(P2); - if (C2->IsRational()) - C2->Weights(W2); - C2->Knots(K2); - C2->Multiplicities(M2); + NCollection_Array1 P2(C2->Poles()); + const NCollection_Array1& W2 = C2->WeightsArray(); + NCollection_Array1 K2(C2->Knots()); + NCollection_Array1 M2(C2->Multiplicities()); double K11 = K1(1); - double K12 = K1(nbk1); + double K12 = K1(K1.Upper()); double K21 = K2(1); - double K22 = K2(nbk2); + double K22 = K2(K2.Upper()); if ((K12 - K11) > (K22 - K21)) { @@ -330,45 +312,18 @@ void GeomFill_BSplineCurves::Init(const occ::handle& C1, throw Standard_ConstructionError("GeomFill_BSplineCurves: invalid filling style"); } - NCollection_Array1 P1(1, NbUPoles); - NCollection_Array1 P2(1, NbVPoles); - NCollection_Array1 P3(1, NbUPoles); - NCollection_Array1 P4(1, NbVPoles); - CC1->Poles(P1); - CC2->Poles(P2); - CC3->Poles(P3); - CC4->Poles(P4); + const NCollection_Array1& P1 = CC1->Poles(); + const NCollection_Array1& P2 = CC2->Poles(); + const NCollection_Array1& P3 = CC3->Poles(); + const NCollection_Array1& P4 = CC4->Poles(); // Traitement des courbes rationelles bool isRat = (CC1->IsRational() || CC2->IsRational() || CC3->IsRational() || CC4->IsRational()); - NCollection_Array1 W1(1, NbUPoles); - NCollection_Array1 W3(1, NbUPoles); - NCollection_Array1 W2(1, NbVPoles); - NCollection_Array1 W4(1, NbVPoles); - W1.Init(1.); - W2.Init(1.); - W3.Init(1.); - W4.Init(1.); - if (isRat) - { - if (CC1->IsRational()) - { - CC1->Weights(W1); - } - if (CC2->IsRational()) - { - CC2->Weights(W2); - } - if (CC3->IsRational()) - { - CC3->Weights(W3); - } - if (CC4->IsRational()) - { - CC4->Weights(W4); - } - } + const NCollection_Array1& W1 = CC1->WeightsArray(); + const NCollection_Array1& W2 = CC2->WeightsArray(); + const NCollection_Array1& W3 = CC3->WeightsArray(); + const NCollection_Array1& W4 = CC4->WeightsArray(); GeomFill_Filling Caro; if (isRat) @@ -407,17 +362,11 @@ void GeomFill_BSplineCurves::Init(const occ::handle& C1, NCollection_Array2 Poles(1, NbUPoles, 1, NbVPoles); // Creation de la surface - int NbUKnot = CC1->NbKnots(); - NCollection_Array1 UKnots(1, NbUKnot); - NCollection_Array1 UMults(1, NbUKnot); - CC1->Knots(UKnots); - CC1->Multiplicities(UMults); + const NCollection_Array1& UKnots = CC1->Knots(); + const NCollection_Array1& UMults = CC1->Multiplicities(); - int NbVKnot = CC2->NbKnots(); - NCollection_Array1 VKnots(1, NbVKnot); - NCollection_Array1 VMults(1, NbVKnot); - CC2->Knots(VKnots); - CC2->Multiplicities(VMults); + const NCollection_Array1& VKnots = CC2->Knots(); + const NCollection_Array1& VMults = CC2->Multiplicities(); Caro.Poles(Poles); @@ -497,23 +446,18 @@ void GeomFill_BSplineCurves::Init(const occ::handle& C1, CC2->IncreaseDegree(DegU); // Mise en conformite des distributions de noeuds - int NbPoles = SetSameDistribution(CC1, CC2); - NCollection_Array2 Poles(1, NbPoles, 1, 2); - NCollection_Array1 P1(1, NbPoles); - NCollection_Array1 P2(1, NbPoles); - CC1->Poles(P1); - CC2->Poles(P2); - int i; + int NbPoles = SetSameDistribution(CC1, CC2); + NCollection_Array2 Poles(1, NbPoles, 1, 2); + const NCollection_Array1& P1 = CC1->Poles(); + const NCollection_Array1& P2 = CC2->Poles(); + int i; for (i = 1; i <= NbPoles; i++) { Poles(i, 1) = P1(i); Poles(i, 2) = P2(i); } - int NbUKnots = CC1->NbKnots(); - NCollection_Array1 UKnots(1, NbUKnots); - NCollection_Array1 UMults(1, NbUKnots); - CC1->Knots(UKnots); - CC1->Multiplicities(UMults); + const NCollection_Array1& UKnots = CC1->Knots(); + const NCollection_Array1& UMults = CC1->Multiplicities(); // int NbVKnots = 2; NCollection_Array1 VKnots(1, 2); NCollection_Array1 VMults(1, 2); @@ -525,27 +469,13 @@ void GeomFill_BSplineCurves::Init(const occ::handle& C1, // Traitement des courbes rationelles if (isRat) { - NCollection_Array2 Weights(1, NbPoles, 1, 2); - NCollection_Array1 W1(1, NbPoles); - NCollection_Array1 W2(1, NbPoles); - W1.Init(1.); - W2.Init(1.); - - if (isRat) + NCollection_Array2 Weights(1, NbPoles, 1, 2); + const NCollection_Array1& W1 = CC1->WeightsArray(); + const NCollection_Array1& W2 = CC2->WeightsArray(); + for (i = 1; i <= NbPoles; i++) { - if (CC1->IsRational()) - { - CC1->Weights(W1); - } - if (CC2->IsRational()) - { - CC2->Weights(W2); - } - for (i = 1; i <= NbPoles; i++) - { - Weights(i, 1) = W1(i); - Weights(i, 2) = W2(i); - } + Weights(i, 1) = W1(i); + Weights(i, 2) = W2(i); } mySurface = new Geom_BSplineSurface(Poles, Weights, @@ -591,41 +521,22 @@ void GeomFill_BSplineCurves::Init(const occ::handle& C1, if (!IsOK) throw Standard_OutOfRange("GeomFill_BSplineCurves: Courbes non jointives"); - int NbUPoles = CC1->NbPoles(); - int NbVPoles = CC2->NbPoles(); - NCollection_Array1 P1(1, NbUPoles); - NCollection_Array1 P2(1, NbVPoles); - CC1->Poles(P1); - CC2->Poles(P2); + int NbUPoles = CC1->NbPoles(); + int NbVPoles = CC2->NbPoles(); + const NCollection_Array1& P1 = CC1->Poles(); + const NCollection_Array1& P2 = CC2->Poles(); - int NbUKnots = CC1->NbKnots(); - int NbVKnots = CC2->NbKnots(); - NCollection_Array1 UKnots(1, NbUKnots); - NCollection_Array1 VKnots(1, NbVKnots); - NCollection_Array1 UMults(1, NbUKnots); - NCollection_Array1 VMults(1, NbVKnots); - CC1->Knots(UKnots); - CC1->Multiplicities(UMults); - CC2->Knots(VKnots); - CC2->Multiplicities(VMults); - - NCollection_Array1 W1(1, NbUPoles); - NCollection_Array1 W2(1, NbVPoles); - W1.Init(1.); - W2.Init(1.); + const NCollection_Array1& UKnots = CC1->Knots(); + const NCollection_Array1& UMults = CC1->Multiplicities(); + const NCollection_Array1& VKnots = CC2->Knots(); + const NCollection_Array1& VMults = CC2->Multiplicities(); GeomFill_Filling Caro; if (isRat) { - if (CC1->IsRational()) - { - CC1->Weights(W1); - } - if (CC2->IsRational()) - { - CC2->Weights(W2); - } - Caro = GeomFill_Curved(P1, P2, W1, W2); + const NCollection_Array1& W1 = CC1->WeightsArray(); + const NCollection_Array1& W2 = CC2->WeightsArray(); + Caro = GeomFill_Curved(P1, P2, W1, W2); } else { diff --git a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_BezierCurves.cxx b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_BezierCurves.cxx index a884065611..6cabf850c0 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_BezierCurves.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_BezierCurves.cxx @@ -225,50 +225,21 @@ void GeomFill_BezierCurves::Init(const occ::handle& C1, if (CC4->Degree() < DegV) CC4->Increase(DegV); - NCollection_Array1 P1(1, DegU + 1); - NCollection_Array1 P3(1, DegU + 1); - NCollection_Array1 P2(1, DegV + 1); - NCollection_Array1 P4(1, DegV + 1); - CC1->Poles(P1); - CC2->Poles(P2); - CC3->Poles(P3); - CC4->Poles(P4); + const NCollection_Array1& P1 = CC1->Poles(); + const NCollection_Array1& P2 = CC2->Poles(); + const NCollection_Array1& P3 = CC3->Poles(); + const NCollection_Array1& P4 = CC4->Poles(); // Traitement des courbes rationelles bool isRat = (CC1->IsRational() || CC2->IsRational() || CC3->IsRational() || CC4->IsRational()); - NCollection_Array1 W1(1, DegU + 1); - NCollection_Array1 W3(1, DegU + 1); - NCollection_Array1 W2(1, DegV + 1); - NCollection_Array1 W4(1, DegV + 1); - W1.Init(1.); - W2.Init(1.); - W3.Init(1.); - W4.Init(1.); - - if (isRat) - { - if (CC1->IsRational()) - { - CC1->Weights(W1); - } - if (CC2->IsRational()) - { - CC2->Weights(W2); - } - if (CC3->IsRational()) - { - CC3->Weights(W3); - } - if (CC4->IsRational()) - { - CC4->Weights(W4); - } - } - GeomFill_Filling Caro; if (isRat) { + NCollection_Array1 W1(CC1->WeightsArray()); + NCollection_Array1 W2(CC2->WeightsArray()); + NCollection_Array1 W3(CC3->WeightsArray()); + NCollection_Array1 W4(CC4->WeightsArray()); // Mise en conformite des poids aux coins. SetSameWeights(W1, W2, W3, W4); switch (Type) @@ -369,11 +340,9 @@ void GeomFill_BezierCurves::Init(const occ::handle& C1, if (CC2->Degree() < DegU) CC2->Increase(DegU); - NCollection_Array2 Poles(1, DegU + 1, 1, 2); - NCollection_Array1 P1(1, DegU + 1); - NCollection_Array1 P2(1, DegU + 1); - CC1->Poles(P1); - CC2->Poles(P2); + NCollection_Array2 Poles(1, DegU + 1, 1, 2); + const NCollection_Array1& P1 = CC1->Poles(); + const NCollection_Array1& P2 = CC2->Poles(); int i; for (i = 1; i <= DegU + 1; i++) @@ -383,20 +352,9 @@ void GeomFill_BezierCurves::Init(const occ::handle& C1, } if (isRat) { - NCollection_Array1 W1(1, DegU + 1); - NCollection_Array1 W2(1, DegU + 1); - W1.Init(1.); - W2.Init(1.); - - if (CC1->IsRational()) - { - CC1->Weights(W1); - } - if (CC2->IsRational()) - { - CC2->Weights(W2); - } - NCollection_Array2 Weights(1, DegU + 1, 1, 2); + const NCollection_Array1& W1 = CC1->WeightsArray(); + const NCollection_Array1& W2 = CC2->WeightsArray(); + NCollection_Array2 Weights(1, DegU + 1, 1, 2); for (i = 1; i <= DegU + 1; i++) { Weights(i, 1) = W1(i); @@ -411,9 +369,6 @@ void GeomFill_BezierCurves::Init(const occ::handle& C1, } else { - NCollection_Array1 P1(1, Deg1 + 1); - NCollection_Array1 P2(1, Deg2 + 1); - constexpr double Eps = Precision::Confusion(); bool IsOK = false; if (CC1->StartPoint().IsEqual(CC2->StartPoint(), Eps)) @@ -440,26 +395,15 @@ void GeomFill_BezierCurves::Init(const occ::handle& C1, if (!IsOK) throw Standard_OutOfRange("GeomFill_BezierCurves: Courbes non jointives"); - CC1->Poles(P1); - CC2->Poles(P2); - - NCollection_Array1 W1(1, Deg1 + 1); - NCollection_Array1 W2(1, Deg2 + 1); - W1.Init(1.); - W2.Init(1.); + const NCollection_Array1& P1 = CC1->Poles(); + const NCollection_Array1& P2 = CC2->Poles(); GeomFill_Filling Caro; if (isRat) { - if (CC1->IsRational()) - { - CC1->Weights(W1); - } - if (CC2->IsRational()) - { - CC2->Weights(W2); - } - Caro = GeomFill_Curved(P1, P2, W1, W2); + const NCollection_Array1& W1 = CC1->WeightsArray(); + const NCollection_Array1& W2 = CC2->WeightsArray(); + Caro = GeomFill_Curved(P1, P2, W1, W2); } else { diff --git a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_CorrectedFrenet.cxx b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_CorrectedFrenet.cxx index cc3240002e..a37b6ead89 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_CorrectedFrenet.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_CorrectedFrenet.cxx @@ -208,8 +208,7 @@ static bool FindPlane(const occ::handle& theC, occ::handle)(1, nbp); - GC->Poles(TabP->ChangeArray1()); + TabP = new NCollection_HArray1(GC->Poles()); } } break; @@ -225,8 +224,7 @@ static bool FindPlane(const occ::handle& theC, occ::handle)(1, nbp); - GC->Poles(TabP->ChangeArray1()); + TabP = new NCollection_HArray1(GC->Poles()); } } break; diff --git a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_EvolvedSection.cxx b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_EvolvedSection.cxx index a4907bc2bb..d449c199ad 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_EvolvedSection.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_EvolvedSection.cxx @@ -59,13 +59,13 @@ bool GeomFill_EvolvedSection::D0(const double U, { double val; int ii, L = Poles.Length(); - val = TLaw->Value(U); - myCurve->Poles(Poles); + val = TLaw->Value(U); + Poles = myCurve->Poles(); for (ii = 1; ii <= L; ii++) { Poles(ii).ChangeCoord() *= val; } - myCurve->Weights(Weights); + Weights = myCurve->WeightsArray(); return true; } @@ -83,8 +83,8 @@ bool GeomFill_EvolvedSection::D1(const double U, int ii, L = Poles.Length(); TLaw->D1(U, val, dval); - myCurve->Poles(Poles); - myCurve->Weights(Weights); + Poles = myCurve->Poles(); + Weights = myCurve->WeightsArray(); for (ii = 1; ii <= L; ii++) { DPoles(ii).SetXYZ(Poles(ii).XYZ()); @@ -110,8 +110,8 @@ bool GeomFill_EvolvedSection::D2(const double U, double val, dval, d2val; int ii, L = Poles.Length(); TLaw->D2(U, val, dval, d2val); - myCurve->Poles(Poles); - myCurve->Weights(Weights); + Poles = myCurve->Poles(); + Weights = myCurve->WeightsArray(); for (ii = 1; ii <= L; ii++) { @@ -172,7 +172,7 @@ void GeomFill_EvolvedSection::SectionShape(int& NbPoles, int& NbKnots, int& Degr void GeomFill_EvolvedSection::Knots(NCollection_Array1& TKnots) const { - myCurve->Knots(TKnots); + TKnots = myCurve->Knots(); } //======================================================= @@ -180,7 +180,7 @@ void GeomFill_EvolvedSection::Knots(NCollection_Array1& TKnots) const //======================================================= void GeomFill_EvolvedSection::Mults(NCollection_Array1& TMults) const { - myCurve->Multiplicities(TMults); + TMults = myCurve->Multiplicities(); } //======================================================= @@ -311,14 +311,7 @@ double GeomFill_EvolvedSection::MaximalSection() const void GeomFill_EvolvedSection::GetMinimalWeight(NCollection_Array1& Weights) const { - if (myCurve->IsRational()) - { - myCurve->Weights(Weights); - } - else - { - Weights.Init(1); - } + Weights = myCurve->WeightsArray(); } bool GeomFill_EvolvedSection::IsConstant(double& Error) const diff --git a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_Generator.cxx b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_Generator.cxx index b1b89014b9..e6e27874bc 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_Generator.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_Generator.cxx @@ -56,18 +56,16 @@ void GeomFill_Generator::Perform(const double PTol) KnotsAndMults(UKnots, UMults); - NCollection_Array1 Pole(1, NbUPoles); - NCollection_Array1 Weight(1, NbUPoles); for (j = 1; j <= NbVPoles; j++) { - occ::handle Cj = occ::down_cast(mySequence(j)); - Cj->Poles(Pole); - Cj->Weights(Weight); - VKnots(j) = (double)(j - 1); + occ::handle Cj = occ::down_cast(mySequence(j)); + const NCollection_Array1& aPoles = Cj->Poles(); + const NCollection_Array1& aWeights = Cj->WeightsArray(); + VKnots(j) = (double)(j - 1); for (i = 1; i <= NbUPoles; i++) { - Poles(i, j) = Pole(i); - Weights(i, j) = Weight(i); + Poles(i, j) = aPoles(i); + Weights(i, j) = aWeights(i); } } diff --git a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_NSections.cxx b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_NSections.cxx index 43fa4f8b78..88d6c4aa82 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_NSections.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_NSections.cxx @@ -157,9 +157,7 @@ static void ResultEval(const occ::handle& surf, int Cdeg = surf->VDegree(), Cdim = surf->NbUPoles() * gap, NbP = surf->NbVPoles(); // les noeuds plats - int Ksize = NbP + Cdeg + 1; - NCollection_Array1 FKnots(1, Ksize); - surf->VKnotSequence(FKnots); + const NCollection_Array1& FKnots = surf->VKnotSequence(); // les poles int Psize = Cdim * NbP; @@ -298,11 +296,9 @@ bool GeomFill_NSections::D0(const double V, { occ::handle Curve = occ::down_cast(mySurface->VIso(V, false)); - NCollection_Array1 poles(1, mySurface->NbUPoles()); - NCollection_Array1 weights(1, mySurface->NbUPoles()); - Curve->Poles(poles); - Curve->Weights(weights); - int ii, L = Poles.Length(); + const NCollection_Array1& poles = Curve->Poles(); + const NCollection_Array1& weights = Curve->WeightsArray(); + int ii, L = Poles.Length(); for (ii = 1; ii <= L; ii++) { Poles(ii).SetXYZ(poles(ii).XYZ()); @@ -514,8 +510,7 @@ void GeomFill_NSections::ComputeSurface() curvBS = GeomConvert::CurveToBSplineCurve(curv, Convert_QuasiAngular); } - NCollection_Array1 BSK(1, curvBS->NbKnots()); - curvBS->Knots(BSK); + NCollection_Array1 BSK(curvBS->Knots()); BSplCLib::Reparametrize(UFirst, ULast, BSK); curvBS->SetKnots(BSK); @@ -630,7 +625,7 @@ void GeomFill_NSections::SectionShape(int& NbPoles, int& NbKnots, int& Degree) c void GeomFill_NSections::Knots(NCollection_Array1& TKnots) const { if (!mySurface.IsNull()) - mySurface->UKnots(TKnots); + TKnots = mySurface->UKnots(); } //======================================================= @@ -639,7 +634,7 @@ void GeomFill_NSections::Knots(NCollection_Array1& TKnots) const void GeomFill_NSections::Mults(NCollection_Array1& TMults) const { if (!mySurface.IsNull()) - mySurface->UMultiplicities(TMults); + TMults = mySurface->UMultiplicities(); } //======================================================= @@ -802,10 +797,15 @@ void GeomFill_NSections::GetMinimalWeight(NCollection_Array1& Weights) c if (mySurface->IsURational()) { - int NbU = mySurface->NbUPoles(), NbV = mySurface->NbVPoles(); - NCollection_Array2 WSurf(1, NbU, 1, NbV); - mySurface->Weights(WSurf); - int i, j; + int NbU = mySurface->NbUPoles(), NbV = mySurface->NbVPoles(); + const NCollection_Array2* aWSurfPtr = mySurface->Weights(); + if (aWSurfPtr == nullptr) + { + Weights.Init(1); + return; + } + const NCollection_Array2& WSurf = *aWSurfPtr; + int i, j; for (i = 1; i <= NbU; i++) { double min = WSurf(i, 1); diff --git a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_Profiler.cxx b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_Profiler.cxx index 94e23bf905..11ff9561e6 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_Profiler.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_Profiler.cxx @@ -35,19 +35,15 @@ static void UnifyByInsertingAllKnots(NCollection_Sequence Ci = occ::down_cast(theCurves(i)); - NCollection_Array1 Ki(1, Ci->NbKnots()); - Ci->Knots(Ki); - NCollection_Array1 Mi(1, Ci->NbKnots()); - Ci->Multiplicities(Mi); + occ::handle Ci = occ::down_cast(theCurves(i)); + const NCollection_Array1& Ki = Ci->Knots(); + const NCollection_Array1& Mi = Ci->Multiplicities(); C->InsertKnots(Ki, Mi, PTol, false); } - NCollection_Array1 NewKnots(1, C->NbKnots()); - C->Knots(NewKnots); - NCollection_Array1 NewMults(1, C->NbKnots()); - C->Multiplicities(NewMults); + const NCollection_Array1& NewKnots = C->Knots(); + const NCollection_Array1& NewMults = C->Multiplicities(); for (i = 2; i <= theCurves.Length(); i++) { occ::handle Ci = occ::down_cast(theCurves(i)); @@ -205,8 +201,7 @@ void GeomFill_Profiler::Perform(const double PTol) C->IncreaseDegree(myDegree); - NCollection_Array1 Knots(1, C->NbKnots()); - C->Knots(Knots); + NCollection_Array1 Knots(C->Knots()); BSplCLib::Reparametrize(UFirst, ULast, Knots); C->SetKnots(Knots); } @@ -269,7 +264,7 @@ void GeomFill_Profiler::Poles(const int Index, NCollection_Array1& Poles occ::handle C = occ::down_cast(mySequence(Index)); - C->Poles(Poles); + Poles = C->Poles(); } //================================================================================================= @@ -285,7 +280,7 @@ void GeomFill_Profiler::Weights(const int Index, NCollection_Array1& Wei occ::handle C = occ::down_cast(mySequence(Index)); - C->Weights(Weights); + Weights = C->WeightsArray(); } //================================================================================================= @@ -316,6 +311,6 @@ void GeomFill_Profiler::KnotsAndMults(NCollection_Array1& Knots, occ::handle C = occ::down_cast(mySequence(1)); - C->Knots(Knots); - C->Multiplicities(Mults); + Knots = C->Knots(); + Mults = C->Multiplicities(); } diff --git a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_SectionGenerator.cxx b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_SectionGenerator.cxx index 7996eb1182..d821484feb 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_SectionGenerator.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_SectionGenerator.cxx @@ -63,14 +63,14 @@ void GeomFill_SectionGenerator::GetShape(int& NbPoles, void GeomFill_SectionGenerator::Knots(NCollection_Array1& TKnots) const { - (occ::down_cast(mySequence(1)))->Knots(TKnots); + TKnots = (occ::down_cast(mySequence(1)))->Knots(); } //================================================================================================= void GeomFill_SectionGenerator::Mults(NCollection_Array1& TMults) const { - (occ::down_cast(mySequence(1)))->Multiplicities(TMults); + TMults = (occ::down_cast(mySequence(1)))->Multiplicities(); } //================================================================================================= @@ -97,8 +97,8 @@ void GeomFill_SectionGenerator::Section(const int P, { occ::handle C = occ::down_cast(mySequence(P)); - C->Poles(Poles); - C->Weights(Weigths); + Poles = C->Poles(); + Weigths = C->WeightsArray(); } //================================================================================================= diff --git a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_SweepSectionGenerator.cxx b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_SweepSectionGenerator.cxx index ed66bae5f1..bfad8d3ef5 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_SweepSectionGenerator.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_SweepSectionGenerator.cxx @@ -399,7 +399,7 @@ void GeomFill_SweepSectionGenerator::Knots(NCollection_Array1& TKnots) c */ if (myType != 0) { - myFirstSect->Knots(TKnots); + TKnots = myFirstSect->Knots(); } else { @@ -422,7 +422,7 @@ void GeomFill_SweepSectionGenerator::Mults(NCollection_Array1& TMults) cons */ if (myType != 0) { - myFirstSect->Multiplicities(TMults); + TMults = myFirstSect->Multiplicities(); } else { @@ -524,8 +524,8 @@ void GeomFill_SweepSectionGenerator::Section(const int P, { if (myType != 0) { - myFirstSect->Poles(Poles); - myFirstSect->Weights(Weigths); + Poles = myFirstSect->Poles(); + Weigths = myFirstSect->WeightsArray(); gp_Trsf cumulTR; if (P > 1) { @@ -630,8 +630,8 @@ void GeomFill_SweepSectionGenerator::Section(const int P, else BS = GeomConvert::CurveToBSplineCurve(CT, Convert_QuasiAngular); - BS->Poles(Poles); - BS->Weights(Weigths); + Poles = BS->Poles(); + Weigths = BS->WeightsArray(); } } } diff --git a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_UniformSection.cxx b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_UniformSection.cxx index 4433c75ddf..e48899561f 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_UniformSection.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/GeomFill/GeomFill_UniformSection.cxx @@ -58,8 +58,8 @@ bool GeomFill_UniformSection::D0(const double, NCollection_Array1& Poles, NCollection_Array1& Weights) { - myCurve->Poles(Poles); - myCurve->Weights(Weights); + Poles = myCurve->Poles(); + Weights = myCurve->WeightsArray(); return true; } @@ -73,8 +73,8 @@ bool GeomFill_UniformSection::D1(const double, NCollection_Array1& Weights, NCollection_Array1& DWeights) { - myCurve->Poles(Poles); - myCurve->Weights(Weights); + Poles = myCurve->Poles(); + Weights = myCurve->WeightsArray(); gp_Vec V0(0, 0, 0); DPoles.Init(V0); DWeights.Init(0); @@ -93,8 +93,8 @@ bool GeomFill_UniformSection::D2(const double, NCollection_Array1& DWeights, NCollection_Array1& D2Weights) { - myCurve->Poles(Poles); - myCurve->Weights(Weights); + Poles = myCurve->Poles(); + Weights = myCurve->WeightsArray(); gp_Vec V0(0, 0, 0); DPoles.Init(V0); DWeights.Init(0); @@ -109,21 +109,23 @@ bool GeomFill_UniformSection::D2(const double, //======================================================= occ::handle GeomFill_UniformSection::BSplineSurface() const { - int ii, NbPoles = myCurve->NbPoles(); - NCollection_Array2 Poles(1, NbPoles, 1, 2); - NCollection_Array1 UKnots(1, myCurve->NbKnots()), VKnots(1, 2); - NCollection_Array1 UMults(1, myCurve->NbKnots()), VMults(1, 2); + int ii, NbPoles = myCurve->NbPoles(); + NCollection_Array2 Poles(1, NbPoles, 1, 2); + const NCollection_Array1& CurKnots = myCurve->Knots(); + NCollection_Array1 UKnots(CurKnots); + NCollection_Array1 VKnots(1, 2); + const NCollection_Array1& CurMults = myCurve->Multiplicities(); + NCollection_Array1 UMults(CurMults); + NCollection_Array1 VMults(1, 2); for (ii = 1; ii <= NbPoles; ii++) { Poles(ii, 1) = Poles(ii, 2) = myCurve->Pole(ii); } - myCurve->Knots(UKnots); VKnots(1) = First; VKnots(2) = Last; - myCurve->Multiplicities(UMults); VMults.Init(2); occ::handle BS = new (Geom_BSplineSurface)(Poles, @@ -150,7 +152,7 @@ void GeomFill_UniformSection::SectionShape(int& NbPoles, int& NbKnots, int& Degr void GeomFill_UniformSection::Knots(NCollection_Array1& TKnots) const { - myCurve->Knots(TKnots); + TKnots = myCurve->Knots(); } //======================================================= @@ -158,7 +160,7 @@ void GeomFill_UniformSection::Knots(NCollection_Array1& TKnots) const //======================================================= void GeomFill_UniformSection::Mults(NCollection_Array1& TMults) const { - myCurve->Multiplicities(TMults); + TMults = myCurve->Multiplicities(); } //======================================================= @@ -276,14 +278,7 @@ double GeomFill_UniformSection::MaximalSection() const void GeomFill_UniformSection::GetMinimalWeight(NCollection_Array1& Weights) const { - if (myCurve->IsRational()) - { - myCurve->Weights(Weights); - } - else - { - Weights.Init(1); - } + Weights = myCurve->WeightsArray(); } bool GeomFill_UniformSection::IsConstant(double& Error) const diff --git a/src/ModelingAlgorithms/TKGeomAlgo/GeomInt/GeomInt_IntSS_1.cxx b/src/ModelingAlgorithms/TKGeomAlgo/GeomInt/GeomInt_IntSS_1.cxx index ee53bfcb7f..2f8ca72dd9 100644 --- a/src/ModelingAlgorithms/TKGeomAlgo/GeomInt/GeomInt_IntSS_1.cxx +++ b/src/ModelingAlgorithms/TKGeomAlgo/GeomInt/GeomInt_IntSS_1.cxx @@ -1182,8 +1182,7 @@ void GeomInt_IntSS::BuildPCurves(const double theFirst, || (theLast - theCurve2d->LastParameter() > Precision::PConfusion())) { occ::handle aBspl = occ::down_cast(theCurve2d); - NCollection_Array1 aKnots(1, aBspl->NbKnots()); - aBspl->Knots(aKnots); + NCollection_Array1 aKnots(aBspl->Knots()); BSplCLib::Reparametrize(theFirst, theLast, aKnots); aBspl->SetKnots(aKnots); } diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep.cxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep.cxx index 9c1cc34ccb..3760331c32 100644 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep.cxx +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep.cxx @@ -97,11 +97,8 @@ TopoDS_Edge HLRBRep::MakeEdge(const HLRBRep_Curve& ec, const double U1, const do { theCurve->Segment(sta, end); NCollection_Array1 Poles(1, theCurve->NbPoles()); - NCollection_Array1 knots(1, theCurve->NbKnots()); - NCollection_Array1 mults(1, theCurve->NbKnots()); - //-- ec.KnotsAndMultiplicities(knots,mults); - theCurve->Knots(knots); - theCurve->Multiplicities(mults); + NCollection_Array1 knots(theCurve->Knots()); + NCollection_Array1 mults(theCurve->Multiplicities()); if (theCurve->IsRational()) { NCollection_Array1 Weights(1, theCurve->NbPoles()); diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_BCurveTool.cxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_BCurveTool.cxx index 8a03ba6a18..60ec718f44 100644 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_BCurveTool.cxx +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_BCurveTool.cxx @@ -51,9 +51,19 @@ int HLRBRep_BCurveTool::NbSamples(const BRepAdaptor_Curve& C, const double U0, c void HLRBRep_BCurveTool::Poles(const BRepAdaptor_Curve& C, NCollection_Array1& T) { if (C.GetType() == GeomAbs_BezierCurve) - C.Bezier()->Poles(T); + { + occ::handle aBez = C.Bezier(); + const NCollection_Array1& aSrcPoles = aBez->Poles(); + for (int i = T.Lower(); i <= T.Upper(); i++) + T(i) = aSrcPoles(i); + } else if (C.GetType() == GeomAbs_BSplineCurve) - C.BSpline()->Poles(T); + { + occ::handle aBSpl = C.BSpline(); + const NCollection_Array1& aSrcPoles = aBSpl->Poles(); + for (int i = T.Lower(); i <= T.Upper(); i++) + T(i) = aSrcPoles(i); + } } //================================================================================================= @@ -64,15 +74,23 @@ void HLRBRep_BCurveTool::PolesAndWeights(const BRepAdaptor_Curve& C, { if (C.GetType() == GeomAbs_BezierCurve) { - const occ::handle HB = C.Bezier(); - HB->Poles(T); - HB->Weights(W); + const occ::handle HB = C.Bezier(); + const NCollection_Array1& aSrcPoles = HB->Poles(); + const NCollection_Array1& aSrcWeights = HB->WeightsArray(); + for (int i = T.Lower(); i <= T.Upper(); i++) + T(i) = aSrcPoles(i); + for (int i = W.Lower(); i <= W.Upper(); i++) + W(i) = aSrcWeights(i); } else if (C.GetType() == GeomAbs_BSplineCurve) { - const occ::handle HB = C.BSpline(); - HB->Poles(T); - HB->Weights(W); + const occ::handle HB = C.BSpline(); + const NCollection_Array1& aSrcPoles = HB->Poles(); + const NCollection_Array1& aSrcWeights = HB->WeightsArray(); + for (int i = T.Lower(); i <= T.Upper(); i++) + T(i) = aSrcPoles(i); + for (int i = W.Lower(); i <= W.Upper(); i++) + W(i) = aSrcWeights(i); } } diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_Curve.cxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_Curve.cxx index e214da4621..f1aba2006e 100644 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_Curve.cxx +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_Curve.cxx @@ -468,11 +468,17 @@ void HLRBRep_Curve::Poles(NCollection_Array1& TP) const //-- HLRBRep_BCurveTool::Poles(myCurve,TP3); if (HLRBRep_BCurveTool::GetType(myCurve) == GeomAbs_BSplineCurve) { - (HLRBRep_BCurveTool::BSpline(myCurve))->Poles(TP3); + occ::handle aBSpl = HLRBRep_BCurveTool::BSpline(myCurve); + const NCollection_Array1& aSrcPoles = aBSpl->Poles(); + for (int i = i1; i <= i2; i++) + TP3(i) = aSrcPoles(i); } else { - (HLRBRep_BCurveTool::Bezier(myCurve))->Poles(TP3); + occ::handle aBez = HLRBRep_BCurveTool::Bezier(myCurve); + const NCollection_Array1& aSrcPoles = aBez->Poles(); + for (int i = i1; i <= i2; i++) + TP3(i) = aSrcPoles(i); } for (int i = i1; i <= i2; i++) { @@ -490,7 +496,9 @@ void HLRBRep_Curve::Poles(const occ::handle& aCurve, int i2 = TP.Upper(); NCollection_Array1 TP3(i1, i2); //-- HLRBRep_BCurveTool::Poles(myCurve,TP3); - aCurve->Poles(TP3); + const NCollection_Array1& aSrcPoles = aCurve->Poles(); + for (int i = i1; i <= i2; i++) + TP3(i) = aSrcPoles(i); for (int i = i1; i <= i2; i++) { @@ -511,17 +519,23 @@ void HLRBRep_Curve::PolesAndWeights(NCollection_Array1& TP, if (HLRBRep_BCurveTool::GetType(myCurve) == GeomAbs_BSplineCurve) { - occ::handle HB = (HLRBRep_BCurveTool::BSpline(myCurve)); - HB->Poles(TP3); - HB->Weights(TW); - //-- (HLRBRep_BCurveTool::BSpline(myCurve))->PolesAndWeights(TP3,TW); + occ::handle HB = (HLRBRep_BCurveTool::BSpline(myCurve)); + const NCollection_Array1& aSrcPoles = HB->Poles(); + const NCollection_Array1& aSrcWeights = HB->WeightsArray(); + for (int i = i1; i <= i2; i++) + TP3(i) = aSrcPoles(i); + for (int i = i1; i <= i2; i++) + TW(i) = aSrcWeights(i); } else { - occ::handle HB = (HLRBRep_BCurveTool::Bezier(myCurve)); - HB->Poles(TP3); - HB->Weights(TW); - //-- (HLRBRep_BCurveTool::Bezier(myCurve))->PolesAndWeights(TP3,TW); + occ::handle HB = (HLRBRep_BCurveTool::Bezier(myCurve)); + const NCollection_Array1& aSrcPoles = HB->Poles(); + const NCollection_Array1& aSrcWeights = HB->WeightsArray(); + for (int i = i1; i <= i2; i++) + TP3(i) = aSrcPoles(i); + for (int i = i1; i <= i2; i++) + TW(i) = aSrcWeights(i); } for (int i = i1; i <= i2; i++) { @@ -541,9 +555,12 @@ void HLRBRep_Curve::PolesAndWeights(const occ::handle& aCurve NCollection_Array1 TP3(i1, i2); //-- HLRBRep_BCurveTool::PolesAndWeights(myCurve,TP3,TW); - aCurve->Poles(TP3); - aCurve->Weights(TW); - //-- (HLRBRep_BCurveTool::BSpline(myCurve))->PolesAndWeights(TP3,TW); + const NCollection_Array1& aSrcPoles = aCurve->Poles(); + const NCollection_Array1& aSrcWeights = aCurve->WeightsArray(); + for (int i = i1; i <= i2; i++) + TP3(i) = aSrcPoles(i); + for (int i = i1; i <= i2; i++) + TW(i) = aSrcWeights(i); for (int i = i1; i <= i2; i++) { @@ -558,8 +575,10 @@ void HLRBRep_Curve::Knots(NCollection_Array1& kn) const { if (HLRBRep_BCurveTool::GetType(myCurve) == GeomAbs_BSplineCurve) { - occ::handle HB = (HLRBRep_BCurveTool::BSpline(myCurve)); - HB->Knots(kn); + occ::handle aBSpl = HLRBRep_BCurveTool::BSpline(myCurve); + const NCollection_Array1& aSrcKnots = aBSpl->Knots(); + for (int i = kn.Lower(); i <= kn.Upper(); i++) + kn(i) = aSrcKnots(i); } } @@ -569,7 +588,9 @@ void HLRBRep_Curve::Multiplicities(NCollection_Array1& mu) const { if (HLRBRep_BCurveTool::GetType(myCurve) == GeomAbs_BSplineCurve) { - occ::handle HB = (HLRBRep_BCurveTool::BSpline(myCurve)); - HB->Multiplicities(mu); + occ::handle aBSpl = HLRBRep_BCurveTool::BSpline(myCurve); + const NCollection_Array1& aSrcMults = aBSpl->Multiplicities(); + for (int i = mu.Lower(); i <= mu.Upper(); i++) + mu(i) = aSrcMults(i); } } diff --git a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_Surface.cxx b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_Surface.cxx index 3c2c0c07b9..03dfd1f88d 100644 --- a/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_Surface.cxx +++ b/src/ModelingAlgorithms/TKHLR/HLRBRep/HLRBRep_Surface.cxx @@ -183,22 +183,26 @@ bool HLRBRep_Surface::IsSide(const double tolF, const double toler) const { if (myProj->Perspective()) return false; - int nu = HLRBRep_BSurfaceTool::NbUPoles(mySurf); - int nv = HLRBRep_BSurfaceTool::NbVPoles(mySurf); - NCollection_Array2 Pnt(1, nu, 1, nv); - HLRBRep_BSurfaceTool::Bezier(mySurf)->Poles(Pnt); + int nu = HLRBRep_BSurfaceTool::NbUPoles(mySurf); + int nv = HLRBRep_BSurfaceTool::NbVPoles(mySurf); + NCollection_Array2 Pnt(1, nu, 1, nv); + const NCollection_Array2& aSrcPoles = HLRBRep_BSurfaceTool::Bezier(mySurf)->Poles(); + for (int iu = 1; iu <= nu; iu++) + for (int iv = 1; iv <= nv; iv++) + Pnt(iu, iv) = aSrcPoles(iu, iv); return SideRowsOfPoles(tolF, nu, nv, Pnt); } else if (myType == GeomAbs_BSplineSurface) { if (myProj->Perspective()) return false; - int nu = HLRBRep_BSurfaceTool::NbUPoles(mySurf); - int nv = HLRBRep_BSurfaceTool::NbVPoles(mySurf); - NCollection_Array2 Pnt(1, nu, 1, nv); - NCollection_Array2 W(1, nu, 1, nv); - HLRBRep_BSurfaceTool::BSpline(mySurf)->Poles(Pnt); - HLRBRep_BSurfaceTool::BSpline(mySurf)->Weights(W); + int nu = HLRBRep_BSurfaceTool::NbUPoles(mySurf); + int nv = HLRBRep_BSurfaceTool::NbVPoles(mySurf); + NCollection_Array2 Pnt(1, nu, 1, nv); + const NCollection_Array2& aSrcPoles = HLRBRep_BSurfaceTool::BSpline(mySurf)->Poles(); + for (int iu = 1; iu <= nu; iu++) + for (int iv = 1; iv <= nv; iv++) + Pnt(iu, iv) = aSrcPoles(iu, iv); return SideRowsOfPoles(tolF, nu, nv, Pnt); } else diff --git a/src/ModelingAlgorithms/TKOffset/BRepOffset/BRepOffset_Inter2d.cxx b/src/ModelingAlgorithms/TKOffset/BRepOffset/BRepOffset_Inter2d.cxx index ba9952dc68..0e45c7f490 100644 --- a/src/ModelingAlgorithms/TKOffset/BRepOffset/BRepOffset_Inter2d.cxx +++ b/src/ModelingAlgorithms/TKOffset/BRepOffset/BRepOffset_Inter2d.cxx @@ -1043,9 +1043,8 @@ static bool ExtendPCurve(const occ::handle& aPCurve, occ::handle aBezier = occ::down_cast(NewPCurve); if (aBezier->NbPoles() == 2) { - NCollection_Array1 thePoles(1, 2); - aBezier->Poles(thePoles); - gp_Vec2d aVec(thePoles(1), thePoles(2)); + const NCollection_Array1& thePoles = aBezier->Poles(); + gp_Vec2d aVec(thePoles(1), thePoles(2)); NewPCurve = new Geom2d_Line(thePoles(1), aVec); return true; } @@ -1055,9 +1054,8 @@ static bool ExtendPCurve(const occ::handle& aPCurve, occ::handle aBSpline = occ::down_cast(NewPCurve); if (aBSpline->NbKnots() == 2 && aBSpline->NbPoles() == 2) { - NCollection_Array1 thePoles(1, 2); - aBSpline->Poles(thePoles); - gp_Vec2d aVec(thePoles(1), thePoles(2)); + const NCollection_Array1& thePoles = aBSpline->Poles(); + gp_Vec2d aVec(thePoles(1), thePoles(2)); NewPCurve = new Geom2d_Line(thePoles(1), aVec); return true; } diff --git a/src/ModelingAlgorithms/TKOffset/BRepOffsetAPI/BRepOffsetAPI_ThruSections.cxx b/src/ModelingAlgorithms/TKOffset/BRepOffsetAPI/BRepOffsetAPI_ThruSections.cxx index b16f26528a..eab7048e71 100644 --- a/src/ModelingAlgorithms/TKOffset/BRepOffsetAPI/BRepOffsetAPI_ThruSections.cxx +++ b/src/ModelingAlgorithms/TKOffset/BRepOffsetAPI/BRepOffsetAPI_ThruSections.cxx @@ -1124,8 +1124,7 @@ static occ::handle EdgeToBSpline(const TopoDS_Edge& theEdge) aBSCurve->Transform(aLoc.Transformation()); // reparameterize to [0,1] - NCollection_Array1 aKnots(1, aBSCurve->NbKnots()); - aBSCurve->Knots(aKnots); + NCollection_Array1 aKnots(aBSCurve->Knots()); BSplCLib::Reparametrize(0., 1., aKnots); aBSCurve->SetKnots(aKnots); } diff --git a/src/ModelingAlgorithms/TKShHealing/ShapeAlgo/ShapeAlgo_AlgoContainer.cxx b/src/ModelingAlgorithms/TKShHealing/ShapeAlgo/ShapeAlgo_AlgoContainer.cxx index 945bd6d427..34645dc775 100644 --- a/src/ModelingAlgorithms/TKShHealing/ShapeAlgo/ShapeAlgo_AlgoContainer.cxx +++ b/src/ModelingAlgorithms/TKShHealing/ShapeAlgo/ShapeAlgo_AlgoContainer.cxx @@ -132,20 +132,12 @@ void ShapeAlgo_AlgoContainer::ApproxBSplineCurve( // on detecte d`eventuelles cassures par la multiplicite des poles. // Puis on approxime chaque "partie" de BSpline - int NbKnots = bspline->NbKnots(); - int NbPoles = bspline->NbPoles(); - NCollection_Array1 Poles(1, NbPoles); - NCollection_Array1 Weigs(1, NbPoles); - Weigs.Init(1.); - NCollection_Array1 Knots(1, NbKnots); - NCollection_Array1 Mults(1, NbKnots); - - bspline->Poles(Poles); - if (bspline->IsRational()) - bspline->Weights(Weigs); - bspline->Knots(Knots); - bspline->Multiplicities(Mults); - int deg = bspline->Degree(); + int NbPoles = bspline->NbPoles(); + const NCollection_Array1& Poles = bspline->Poles(); + const NCollection_Array1& Weigs = bspline->WeightsArray(); + const NCollection_Array1& Knots = bspline->Knots(); + const NCollection_Array1& Mults = bspline->Multiplicities(); + int deg = bspline->Degree(); int jpole = 1; int j, PoleIndex, I1; @@ -163,7 +155,7 @@ void ShapeAlgo_AlgoContainer::ApproxBSplineCurve( { NCollection_Array1 newPoles(1, jpole); NCollection_Array1 newWeigs(1, jpole); - Weigs.Init(1.); + newWeigs.Init(1.); int NbNew = jpole - deg + 1; NCollection_Array1 newKnots(1, NbNew); NCollection_Array1 newMults(1, NbNew); @@ -206,10 +198,9 @@ void ShapeAlgo_AlgoContainer::ApproxBSplineCurve( jpole = mycurve->NbPoles(); if (jpole > 2) { - NCollection_Array1 newP(1, jpole); - mycurve->Poles(newP); - occ::handle R = new IntSurf_LineOn2S(); - double u1, v1, u2, v2; + const NCollection_Array1& newP = mycurve->Poles(); + occ::handle R = new IntSurf_LineOn2S(); + double u1, v1, u2, v2; u1 = v1 = 0.; u2 = v2 = 1.; for (j = 1; j <= jpole; j++) @@ -277,20 +268,12 @@ void ShapeAlgo_AlgoContainer::ApproxBSplineCurve( // Puis on approxime chaque "partie" de BSpline et on reconstruit // une BSpline = somme des BSplines traitees - int NbKnots = bspline->NbKnots(); - int NbPoles = bspline->NbPoles(); - NCollection_Array1 Poles(1, NbPoles); - NCollection_Array1 Weigs(1, NbPoles); - Weigs.Init(1.); - NCollection_Array1 Knots(1, NbKnots); - NCollection_Array1 Mults(1, NbKnots); - - bspline->Poles(Poles); - if (bspline->IsRational()) - bspline->Weights(Weigs); - bspline->Knots(Knots); - bspline->Multiplicities(Mults); - int deg = bspline->Degree(); + int NbPoles = bspline->NbPoles(); + const NCollection_Array1& Poles = bspline->Poles(); + const NCollection_Array1& Weigs = bspline->WeightsArray(); + const NCollection_Array1& Knots = bspline->Knots(); + const NCollection_Array1& Mults = bspline->Multiplicities(); + int deg = bspline->Degree(); int jpole = 1; int j, PoleIndex, I1; @@ -308,7 +291,7 @@ void ShapeAlgo_AlgoContainer::ApproxBSplineCurve( { NCollection_Array1 newPoles(1, jpole); NCollection_Array1 newWeigs(1, jpole); - Weigs.Init(1.); + newWeigs.Init(1.); int NbNew = jpole - deg + 1; NCollection_Array1 newKnots(1, NbNew); NCollection_Array1 newMults(1, NbNew); @@ -351,11 +334,10 @@ void ShapeAlgo_AlgoContainer::ApproxBSplineCurve( jpole = mycurve->NbPoles(); if (jpole > 10) { - NCollection_Array1 P(1, jpole); - NCollection_Array1 newP(1, jpole); - mycurve->Poles(newP); - occ::handle R = new IntSurf_LineOn2S(); - double u2, v2; + NCollection_Array1 P(1, jpole); + const NCollection_Array1& newP = mycurve->Poles(); + occ::handle R = new IntSurf_LineOn2S(); + double u2, v2; u2 = v2 = 1.; for (j = 1; j <= jpole; j++) { diff --git a/src/ModelingAlgorithms/TKShHealing/ShapeAnalysis/ShapeAnalysis_CheckSmallFace.cxx b/src/ModelingAlgorithms/TKShHealing/ShapeAnalysis/ShapeAnalysis_CheckSmallFace.cxx index d2e7283ad7..be94e8f6de 100644 --- a/src/ModelingAlgorithms/TKShHealing/ShapeAnalysis/ShapeAnalysis_CheckSmallFace.cxx +++ b/src/ModelingAlgorithms/TKShHealing/ShapeAnalysis/ShapeAnalysis_CheckSmallFace.cxx @@ -750,11 +750,12 @@ bool ShapeAnalysis_CheckSmallFace::CheckPin(const TopoDS_Face& F, int& whatrow, if (nbu == 0 || nbv == 0) return false; - NCollection_Array2 allpoles(1, nbu, 1, nbv); + const NCollection_Array2* allpolesPtr = nullptr; if (!bs.IsNull()) - bs->Poles(allpoles); + allpolesPtr = &bs->Poles(); if (!bz.IsNull()) - bz->Poles(allpoles); + allpolesPtr = &bz->Poles(); + const NCollection_Array2& allpoles = *allpolesPtr; // Check each natural bound if it is a singularity (i.e. a pin) diff --git a/src/ModelingAlgorithms/TKShHealing/ShapeAnalysis/ShapeAnalysis_Curve.cxx b/src/ModelingAlgorithms/TKShHealing/ShapeAnalysis/ShapeAnalysis_Curve.cxx index 8ef43cbe09..49eded2724 100644 --- a/src/ModelingAlgorithms/TKShHealing/ShapeAnalysis/ShapeAnalysis_Curve.cxx +++ b/src/ModelingAlgorithms/TKShHealing/ShapeAnalysis/ShapeAnalysis_Curve.cxx @@ -1007,21 +1007,16 @@ static void AppendControlPoles(NCollection_Sequence& seq, } else if (curve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) { - // DeclareAndCast(Geom_BSplineCurve, BSpline, curve); - occ::handle BSpline = occ::down_cast(curve); - NCollection_Array1 Poles(1, BSpline->NbPoles()); - BSpline->Poles(Poles); - for (int i = 1; i <= BSpline->NbPoles(); i++) + occ::handle BSpline = occ::down_cast(curve); + const NCollection_Array1& Poles = BSpline->Poles(); + for (int i = 1; i <= Poles.Length(); i++) seq.Append(Poles(i)); } else if (curve->IsKind(STANDARD_TYPE(Geom_BezierCurve))) { - // DeclareAndCast(Geom_BezierCurve, Bezier, curve); - // occ::handle Bezier = occ::down_cast(curve); - occ::handle Bezier = occ::down_cast(curve); - NCollection_Array1 Poles(1, Bezier->NbPoles()); - Bezier->Poles(Poles); - for (int i = 1; i <= Bezier->NbPoles(); i++) + occ::handle Bezier = occ::down_cast(curve); + const NCollection_Array1& Poles = Bezier->Poles(); + for (int i = 1; i <= Poles.Length(); i++) seq.Append(Poles(i)); } } @@ -1151,20 +1146,14 @@ bool ShapeAnalysis_Curve::IsPlanar(const occ::handle& curve, if (curve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) { - // DeclareAndCast(Geom_BSplineCurve, BSpline, curve); occ::handle BSpline = occ::down_cast(curve); - NCollection_Array1 Poles(1, BSpline->NbPoles()); - BSpline->Poles(Poles); - return IsPlanar(Poles, Normal, precision); + return IsPlanar(BSpline->Poles(), Normal, precision); } if (curve->IsKind(STANDARD_TYPE(Geom_BezierCurve))) { - // DeclareAndCast(Geom_BezierCurve, Bezier, curve); occ::handle Bezier = occ::down_cast(curve); - NCollection_Array1 Poles(1, Bezier->NbPoles()); - Bezier->Poles(Poles); - return IsPlanar(Poles, Normal, precision); + return IsPlanar(Bezier->Poles(), Normal, precision); } if (curve->IsKind(STANDARD_TYPE(ShapeExtend_ComplexCurve))) diff --git a/src/ModelingAlgorithms/TKShHealing/ShapeConstruct/ShapeConstruct.cxx b/src/ModelingAlgorithms/TKShHealing/ShapeConstruct/ShapeConstruct.cxx index 2ca61e8cbd..3eb9a546e6 100644 --- a/src/ModelingAlgorithms/TKShHealing/ShapeConstruct/ShapeConstruct.cxx +++ b/src/ModelingAlgorithms/TKShHealing/ShapeConstruct/ShapeConstruct.cxx @@ -186,17 +186,11 @@ occ::handle ShapeConstruct::ConvertSurfaceToBSpline( shiftF.SetTranslation(extr->Value(UF, 0), extr->Value(UF, VF)); shiftL.SetTranslation(extr->Value(UF, 0), extr->Value(UF, VL)); - int nbPoles = bspl->NbPoles(); - NCollection_Array1 poles(1, nbPoles); - NCollection_Array1 weights(1, nbPoles); - int nbKnots = bspl->NbKnots(); - NCollection_Array1 knots(1, nbKnots); - NCollection_Array1 mults(1, nbKnots); - - bspl->Poles(poles); - bspl->Knots(knots); - bspl->Multiplicities(mults); - bspl->Weights(weights); + int nbPoles = bspl->NbPoles(); + const NCollection_Array1& poles = bspl->Poles(); + const NCollection_Array1& weights = bspl->WeightsArray(); + const NCollection_Array1& knots = bspl->Knots(); + const NCollection_Array1& mults = bspl->Multiplicities(); NCollection_Array2 resPoles(1, nbPoles, 1, 2); NCollection_Array2 resWeigth(1, nbPoles, 1, 2); diff --git a/src/ModelingAlgorithms/TKShHealing/ShapeConstruct/ShapeConstruct_ProjectCurveOnSurface.cxx b/src/ModelingAlgorithms/TKShHealing/ShapeConstruct/ShapeConstruct_ProjectCurveOnSurface.cxx index 9493a9ae42..d127d4e415 100644 --- a/src/ModelingAlgorithms/TKShHealing/ShapeConstruct/ShapeConstruct_ProjectCurveOnSurface.cxx +++ b/src/ModelingAlgorithms/TKShHealing/ShapeConstruct/ShapeConstruct_ProjectCurveOnSurface.cxx @@ -2082,22 +2082,18 @@ occ::handle ShapeConstruct_ProjectCurveOnSurface::approximatePCurv GeomAPI_PointsToBSpline appr(points3d, params, 1, 10, GeomAbs_C1, theTolerance2d); const occ::handle& crv3d = appr.Curve(); - const int NbPoles = crv3d->NbPoles(); - NCollection_Array1 poles3d(1, NbPoles); - NCollection_Array1 poles2d(1, NbPoles); - crv3d->Poles(poles3d); + const int NbPoles = crv3d->NbPoles(); + const NCollection_Array1& poles3d = crv3d->Poles(); + NCollection_Array1 poles2d(1, NbPoles); for (int i = 1; i <= NbPoles; i++) { poles2d(i).SetCoord(poles3d(i).X(), poles3d(i).Y()); } - NCollection_Array1 weights(1, NbPoles); - NCollection_Array1 multiplicities(1, crv3d->NbKnots()); - NCollection_Array1 knots(1, crv3d->NbKnots()); - crv3d->Knots(knots); - crv3d->Weights(weights); - crv3d->Multiplicities(multiplicities); + const NCollection_Array1& weights = crv3d->WeightsArray(); + const NCollection_Array1& knots = crv3d->Knots(); + const NCollection_Array1& multiplicities = crv3d->Multiplicities(); aC2D = new Geom2d_BSplineCurve(poles2d, weights, diff --git a/src/ModelingAlgorithms/TKShHealing/ShapeCustom/ShapeCustom_BSplineRestriction.cxx b/src/ModelingAlgorithms/TKShHealing/ShapeCustom/ShapeCustom_BSplineRestriction.cxx index 70457f4ad3..591260abe7 100644 --- a/src/ModelingAlgorithms/TKShHealing/ShapeCustom/ShapeCustom_BSplineRestriction.cxx +++ b/src/ModelingAlgorithms/TKShHealing/ShapeCustom/ShapeCustom_BSplineRestriction.cxx @@ -436,18 +436,12 @@ static void ConvertExtrusion(const occ::handle& C, /*const gp_Dir& d const double VL, occ::handle& bspline) { - occ::handle bspl = occ::down_cast(C); - int nbPoles = bspl->NbPoles(); - NCollection_Array1 poles(1, nbPoles); - NCollection_Array1 weights(1, nbPoles); - int nbKnots = bspl->NbKnots(); - NCollection_Array1 knots(1, nbKnots); - NCollection_Array1 mults(1, nbKnots); - - bspl->Poles(poles); - bspl->Knots(knots); - bspl->Multiplicities(mults); - bspl->Weights(weights); + occ::handle bspl = occ::down_cast(C); + int nbPoles = bspl->NbPoles(); + const NCollection_Array1& poles = bspl->Poles(); + const NCollection_Array1& weights = bspl->WeightsArray(); + const NCollection_Array1& knots = bspl->Knots(); + const NCollection_Array1& mults = bspl->Multiplicities(); NCollection_Array2 resPoles(1, nbPoles, 1, 2); NCollection_Array2 resWeigth(1, nbPoles, 1, 2); @@ -639,16 +633,12 @@ bool ShapeCustom_BSplineRestriction::ConvertSurface(const occ::handleIsKind(STANDARD_TYPE(Geom_BezierSurface)) && myParameters->ConvertBezierSurf()) { - occ::handle bezier = occ::down_cast(aSurf); - int nbUPoles = bezier->NbUPoles(); - int nbVPoles = bezier->NbVPoles(); - int uDegree = bezier->UDegree(); - int vDegree = bezier->VDegree(); - NCollection_Array2 aPoles(1, nbUPoles, 1, nbVPoles); - NCollection_Array2 aWeights(1, nbUPoles, 1, nbVPoles); - bezier->Poles(aPoles); - bezier->Weights(aWeights); - NCollection_Array1 uKnots(1, 2), vKnots(1, 2); + occ::handle bezier = occ::down_cast(aSurf); + int uDegree = bezier->UDegree(); + int vDegree = bezier->VDegree(); + const NCollection_Array2& aPoles = bezier->Poles(); + const NCollection_Array2& aWeights = bezier->WeightsArray(); + NCollection_Array1 uKnots(1, 2), vKnots(1, 2); uKnots(1) = 0; uKnots(2) = 1; vKnots(1) = 0; @@ -805,19 +795,15 @@ bool ShapeCustom_BSplineRestriction::ConvertSurface(const occ::handle Precision::PConfusion()) { - int nb = Bsc->NbUKnots(); - NCollection_Array1 uknots(1, nb); - Bsc->UKnots(uknots); - for (int j = 1; j <= nb; j++) + NCollection_Array1 uknots(Bsc->UKnots()); + for (int j = 1; j <= uknots.Length(); j++) uknots(j) += ShiftU; Bsc->SetUKnots(uknots); } if (std::abs(ShiftV) > Precision::PConfusion()) { - int nb = Bsc->NbVKnots(); - NCollection_Array1 vknots(1, nb); - Bsc->VKnots(vknots); - for (int j = 1; j <= nb; j++) + NCollection_Array1 vknots(Bsc->VKnots()); + for (int j = 1; j <= vknots.Length(); j++) vknots(j) += ShiftV; Bsc->SetVKnots(vknots); } @@ -1043,10 +1029,8 @@ bool ShapeCustom_BSplineRestriction::ConvertCurve(const occ::handle& double Shift = First - aBSpline->FirstParameter(); if (std::abs(Shift) > Precision::PConfusion()) { - int nbKnots = aBSpline->NbKnots(); - NCollection_Array1 newKnots(1, nbKnots); - aBSpline->Knots(newKnots); - for (int i = 1; i <= nbKnots; i++) + NCollection_Array1 newKnots(aBSpline->Knots()); + for (int i = 1; i <= newKnots.Length(); i++) newKnots(i) += Shift; aBSpline->SetKnots(newKnots); } @@ -1417,10 +1401,8 @@ bool ShapeCustom_BSplineRestriction::ConvertCurve2d(const occ::handleFirstParameter(); if (std::abs(Shift) > Precision::PConfusion()) { - int nbKnots = aBSpline2d->NbKnots(); - NCollection_Array1 newKnots(1, nbKnots); - aBSpline2d->Knots(newKnots); - for (int i = 1; i <= nbKnots; i++) + NCollection_Array1 newKnots(aBSpline2d->Knots()); + for (int i = 1; i <= newKnots.Length(); i++) newKnots(i) += Shift; aBSpline2d->SetKnots(newKnots); } diff --git a/src/ModelingAlgorithms/TKShHealing/ShapeCustom/ShapeCustom_Curve.cxx b/src/ModelingAlgorithms/TKShHealing/ShapeCustom/ShapeCustom_Curve.cxx index 3cb435ccb8..8003b968ee 100644 --- a/src/ModelingAlgorithms/TKShHealing/ShapeCustom/ShapeCustom_Curve.cxx +++ b/src/ModelingAlgorithms/TKShHealing/ShapeCustom/ShapeCustom_Curve.cxx @@ -60,17 +60,11 @@ occ::handle ShapeCustom_Curve::ConvertToPeriodic(const bool substi if (BSpl->Multiplicity(1) == BSpl->Degree() + 1 && BSpl->Multiplicity(BSpl->NbKnots()) == BSpl->Degree() + 1) { - int nbPoles = BSpl->NbPoles(); - NCollection_Array1 oldPoles(1, nbPoles); - NCollection_Array1 oldWeights(1, nbPoles); - int nbKnots = BSpl->NbKnots(); - NCollection_Array1 oldKnots(1, nbKnots); - NCollection_Array1 oldMults(1, nbKnots); - - BSpl->Poles(oldPoles); - BSpl->Weights(oldWeights); - BSpl->Knots(oldKnots); - BSpl->Multiplicities(oldMults); + const NCollection_Array1& oldPoles = BSpl->Poles(); + const NCollection_Array1& oldWeights = BSpl->WeightsArray(); + int nbKnots = BSpl->NbKnots(); + const NCollection_Array1& oldKnots = BSpl->Knots(); + const NCollection_Array1& oldMults = BSpl->Multiplicities(); NCollection_Array1 newKnots(1, nbKnots + 2); NCollection_Array1 newMults(1, nbKnots + 2); diff --git a/src/ModelingAlgorithms/TKShHealing/ShapeCustom/ShapeCustom_Curve2d.cxx b/src/ModelingAlgorithms/TKShHealing/ShapeCustom/ShapeCustom_Curve2d.cxx index 50cdfd304a..eda8168a48 100644 --- a/src/ModelingAlgorithms/TKShHealing/ShapeCustom/ShapeCustom_Curve2d.cxx +++ b/src/ModelingAlgorithms/TKShHealing/ShapeCustom/ShapeCustom_Curve2d.cxx @@ -115,10 +115,7 @@ occ::handle ShapeCustom_Curve2d::ConvertToLine2d( occ::handle bsc = occ::down_cast(theCurve); if (!bsc.IsNull()) { - int nbPoles = bsc->NbPoles(); - NCollection_Array1 Poles(1, nbPoles); - bsc->Poles(Poles); - if (!ShapeCustom_Curve2d::IsLinear(Poles, theTolerance, theDeviation)) + if (!ShapeCustom_Curve2d::IsLinear(bsc->Poles(), theTolerance, theDeviation)) return aLine2d; // non gp_Lin2d alin = GetLine(P1, P2, c1, cf, cl); aLine2d = new Geom2d_Line(alin); @@ -128,10 +125,7 @@ occ::handle ShapeCustom_Curve2d::ConvertToLine2d( occ::handle bzc = occ::down_cast(theCurve); if (!bzc.IsNull()) { - int nbPoles = bzc->NbPoles(); - NCollection_Array1 Poles(1, nbPoles); - bzc->Poles(Poles); - if (!ShapeCustom_Curve2d::IsLinear(Poles, theTolerance, theDeviation)) + if (!ShapeCustom_Curve2d::IsLinear(bzc->Poles(), theTolerance, theDeviation)) return aLine2d; // non gp_Lin2d alin = GetLine(P1, P2, c1, cf, cl); aLine2d = new Geom2d_Line(alin); diff --git a/src/ModelingAlgorithms/TKShHealing/ShapeCustom/ShapeCustom_Surface.cxx b/src/ModelingAlgorithms/TKShHealing/ShapeCustom/ShapeCustom_Surface.cxx index b3a0415f26..c84bfcebf5 100644 --- a/src/ModelingAlgorithms/TKShHealing/ShapeCustom/ShapeCustom_Surface.cxx +++ b/src/ModelingAlgorithms/TKShHealing/ShapeCustom/ShapeCustom_Surface.cxx @@ -454,23 +454,13 @@ occ::handle ShapeCustom_Surface::ConvertToPeriodic(const bool su if (BSpl->UMultiplicity(1) == BSpl->UDegree() + 1 && BSpl->UMultiplicity(BSpl->NbUKnots()) == BSpl->UDegree() + 1) { - int nbUPoles = BSpl->NbUPoles(); - int nbVPoles = BSpl->NbVPoles(); - NCollection_Array2 oldPoles(1, nbUPoles, 1, nbVPoles); - NCollection_Array2 oldWeights(1, nbUPoles, 1, nbVPoles); - int nbUKnots = BSpl->NbUKnots(); - int nbVKnots = BSpl->NbVKnots(); - NCollection_Array1 oldUKnots(1, nbUKnots); - NCollection_Array1 oldVKnots(1, nbVKnots); - NCollection_Array1 oldUMults(1, nbUKnots); - NCollection_Array1 oldVMults(1, nbVKnots); - - BSpl->Poles(oldPoles); - BSpl->Weights(oldWeights); - BSpl->UKnots(oldUKnots); - BSpl->VKnots(oldVKnots); - BSpl->UMultiplicities(oldUMults); - BSpl->VMultiplicities(oldVMults); + const NCollection_Array2& oldPoles = BSpl->Poles(); + const NCollection_Array2& oldWeights = BSpl->WeightsArray(); + int nbUKnots = BSpl->NbUKnots(); + const NCollection_Array1& oldUKnots = BSpl->UKnots(); + const NCollection_Array1& oldVKnots = BSpl->VKnots(); + const NCollection_Array1& oldUMults = BSpl->UMultiplicities(); + const NCollection_Array1& oldVMults = BSpl->VMultiplicities(); NCollection_Array1 newUKnots(1, nbUKnots + 2); NCollection_Array1 newUMults(1, nbUKnots + 2); @@ -515,23 +505,13 @@ occ::handle ShapeCustom_Surface::ConvertToPeriodic(const bool su if (BSpl->VMultiplicity(1) == BSpl->VDegree() + 1 && BSpl->VMultiplicity(BSpl->NbVKnots()) == BSpl->VDegree() + 1) { - int nbUPoles = BSpl->NbUPoles(); - int nbVPoles = BSpl->NbVPoles(); - NCollection_Array2 oldPoles(1, nbUPoles, 1, nbVPoles); - NCollection_Array2 oldWeights(1, nbUPoles, 1, nbVPoles); - int nbUKnots = BSpl->NbUKnots(); - int nbVKnots = BSpl->NbVKnots(); - NCollection_Array1 oldUKnots(1, nbUKnots); - NCollection_Array1 oldVKnots(1, nbVKnots); - NCollection_Array1 oldUMults(1, nbUKnots); - NCollection_Array1 oldVMults(1, nbVKnots); - - BSpl->Poles(oldPoles); - BSpl->Weights(oldWeights); - BSpl->UKnots(oldUKnots); - BSpl->VKnots(oldVKnots); - BSpl->UMultiplicities(oldUMults); - BSpl->VMultiplicities(oldVMults); + const NCollection_Array2& oldPoles = BSpl->Poles(); + const NCollection_Array2& oldWeights = BSpl->WeightsArray(); + int nbVKnots = BSpl->NbVKnots(); + const NCollection_Array1& oldUKnots = BSpl->UKnots(); + const NCollection_Array1& oldVKnots = BSpl->VKnots(); + const NCollection_Array1& oldUMults = BSpl->UMultiplicities(); + const NCollection_Array1& oldVMults = BSpl->VMultiplicities(); NCollection_Array1 newVKnots(1, nbVKnots + 2); NCollection_Array1 newVMults(1, nbVKnots + 2); diff --git a/src/ModelingAlgorithms/TKShHealing/ShapeFix/ShapeFix_EdgeProjAux.cxx b/src/ModelingAlgorithms/TKShHealing/ShapeFix/ShapeFix_EdgeProjAux.cxx index 5394cf53be..b514484d00 100644 --- a/src/ModelingAlgorithms/TKShHealing/ShapeFix/ShapeFix_EdgeProjAux.cxx +++ b/src/ModelingAlgorithms/TKShHealing/ShapeFix/ShapeFix_EdgeProjAux.cxx @@ -386,8 +386,7 @@ void ShapeFix_EdgeProjAux::Init2d(const double preci) // Try to reparametrize (CASE dxf read bug25899) occ::handle aBspl = occ::down_cast(theCurve2d->Copy()); - NCollection_Array1 aNewKnots(1, aBspl->NbKnots()); - aBspl->Knots(aNewKnots); + NCollection_Array1 aNewKnots(aBspl->Knots()); BSplCLib::Reparametrize(cf, cl, aNewKnots); aBspl->SetKnots(aNewKnots); theCurve2d = aBspl; diff --git a/src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade.cxx b/src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade.cxx index fbaa7da1f9..de71cebecb 100644 --- a/src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade.cxx +++ b/src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade.cxx @@ -47,23 +47,12 @@ bool ShapeUpgrade::C0BSplineToSequenceOfC1BSplineCurve( seqBS = new NCollection_HSequence>; BS->SetNotPeriodic(); // to have equation NbPoles = NbKnots with Multiplicities - degree - 1 - int deg = BS->Degree(); - int NbKnots = BS->NbKnots(); - int NbPoles = BS->NbPoles(); - NCollection_Array1 Poles(1, NbPoles); - NCollection_Array1 Weights(1, NbPoles); - NCollection_Array1 Knots(1, NbKnots); - NCollection_Array1 Mults(1, NbKnots); - NCollection_Array1 KnotSequence(1, NbPoles + deg + 1); - - BS->Poles(Poles); - if (BS->IsRational()) - BS->Weights(Weights); - else - Weights.Init(1.); - BS->Knots(Knots); - BS->Multiplicities(Mults); - BS->KnotSequence(KnotSequence); + int deg = BS->Degree(); + const NCollection_Array1& Poles = BS->Poles(); + const NCollection_Array1& Weights = BS->WeightsArray(); + const NCollection_Array1& Knots = BS->Knots(); + const NCollection_Array1& Mults = BS->Multiplicities(); + const NCollection_Array1& KnotSequence = BS->KnotSequence(); int StartKnotIndex, EndKnotIndex, j; @@ -78,8 +67,8 @@ bool ShapeUpgrade::C0BSplineToSequenceOfC1BSplineCurve( int EndFlatIndex = BSplCLib::FlatIndex(deg, EndKnotIndex, Mults, false); EndFlatIndex -= Mults(EndKnotIndex) - 1; - NCollection_Array1 TempKnots(1, NbKnots); - NCollection_Array1 TempMults(1, NbKnots); + NCollection_Array1 TempKnots(1, Knots.Length()); + NCollection_Array1 TempMults(1, Knots.Length()); TempMults.Init(1); int TempKnotIndex = 1; TempKnots(TempKnotIndex) = KnotSequence(StartFlatIndex - deg); @@ -130,21 +119,12 @@ bool ShapeUpgrade::C0BSplineToSequenceOfC1BSplineCurve( static occ::handle BSplineCurve2dTo3d(const occ::handle& BS) { - int deg = BS->Degree(); - int NbKnots = BS->NbKnots(); - int NbPoles = BS->NbPoles(); - NCollection_Array1 Poles2d(1, NbPoles); - NCollection_Array1 Weights(1, NbPoles); - NCollection_Array1 Knots(1, NbKnots); - NCollection_Array1 Mults(1, NbKnots); - - BS->Poles(Poles2d); - if (BS->IsRational()) - BS->Weights(Weights); - else - Weights.Init(1); - BS->Knots(Knots); - BS->Multiplicities(Mults); + int deg = BS->Degree(); + int NbPoles = BS->NbPoles(); + const NCollection_Array1& Poles2d = BS->Poles(); + const NCollection_Array1& Weights = BS->WeightsArray(); + const NCollection_Array1& Knots = BS->Knots(); + const NCollection_Array1& Mults = BS->Multiplicities(); NCollection_Array1 Poles3d(1, NbPoles); for (int i = 1; i <= NbPoles; i++) @@ -157,21 +137,12 @@ static occ::handle BSplineCurve2dTo3d(const occ::handle BSplineCurve3dTo2d(const occ::handle& BS) { - int deg = BS->Degree(); - int NbKnots = BS->NbKnots(); - int NbPoles = BS->NbPoles(); - NCollection_Array1 Poles3d(1, NbPoles); - NCollection_Array1 Weights(1, NbPoles); - NCollection_Array1 Knots(1, NbKnots); - NCollection_Array1 Mults(1, NbKnots); - - BS->Poles(Poles3d); - if (BS->IsRational()) - BS->Weights(Weights); - else - Weights.Init(1); - BS->Knots(Knots); - BS->Multiplicities(Mults); + int deg = BS->Degree(); + int NbPoles = BS->NbPoles(); + const NCollection_Array1& Poles3d = BS->Poles(); + const NCollection_Array1& Weights = BS->WeightsArray(); + const NCollection_Array1& Knots = BS->Knots(); + const NCollection_Array1& Mults = BS->Multiplicities(); NCollection_Array1 Poles2d(1, NbPoles); for (int i = 1; i <= NbPoles; i++) diff --git a/src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade_ConvertSurfaceToBezierBasis.cxx b/src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade_ConvertSurfaceToBezierBasis.cxx index c90005fba2..132e727749 100644 --- a/src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade_ConvertSurfaceToBezierBasis.cxx +++ b/src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade_ConvertSurfaceToBezierBasis.cxx @@ -409,11 +409,10 @@ void ShapeUpgrade_ConvertSurfaceToBezierBasis::Compute(const bool Segment) int i; // svv #1 for (i = 1; i <= nbCurves; i++) { - occ::handle bez = occ::down_cast(curves->Value(i)); - int nbPoles = bez->NbPoles(); - NCollection_Array1 poles(1, nbPoles); - bez->Poles(poles); - NCollection_Array2 resPoles(1, nbPoles, 1, 2); + occ::handle bez = occ::down_cast(curves->Value(i)); + int nbPoles = bez->NbPoles(); + const NCollection_Array1& poles = bez->Poles(); + NCollection_Array2 resPoles(1, nbPoles, 1, 2); for (int j = 1; j <= nbPoles; j++) { resPoles(j, 1) = poles(j).Transformed(shiftF); diff --git a/src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade_UnifySameDomain.cxx b/src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade_UnifySameDomain.cxx index d4290a7923..d32a2b18af 100644 --- a/src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade_UnifySameDomain.cxx +++ b/src/ModelingAlgorithms/TKShHealing/ShapeUpgrade/ShapeUpgrade_UnifySameDomain.cxx @@ -1956,8 +1956,7 @@ void ShapeUpgrade_UnifySameDomain::UnionPCurves(const NCollection_Sequence aBSplinePCurve = Geom2dConvert::CurveToBSplineCurve(aTrPCurve); - NCollection_Array1 aKnots(1, aBSplinePCurve->NbKnots()); - aBSplinePCurve->Knots(aKnots); + NCollection_Array1 aKnots(aBSplinePCurve->Knots()); BSplCLib::Reparametrize(aFirst3d, aLast3d, aKnots); aBSplinePCurve->SetKnots(aKnots); ResPCurves(ii) = aBSplinePCurve; @@ -2005,8 +2004,7 @@ void ShapeUpgrade_UnifySameDomain::UnionPCurves(const NCollection_Sequence aBSplinePCurve = Geom2dConvert::CurveToBSplineCurve(aTrPCurve); - NCollection_Array1 aKnots(1, aBSplinePCurve->NbKnots()); - aBSplinePCurve->Knots(aKnots); + NCollection_Array1 aKnots(aBSplinePCurve->Knots()); BSplCLib::Reparametrize(aFirst3d, aLast3d, aKnots); aBSplinePCurve->SetKnots(aKnots); ResPCurves(ii) = aBSplinePCurve; diff --git a/src/ModelingAlgorithms/TKTopAlgo/BRepGProp/BRepGProp_Face.cxx b/src/ModelingAlgorithms/TKTopAlgo/BRepGProp/BRepGProp_Face.cxx index c6c6006566..b47ead18fd 100644 --- a/src/ModelingAlgorithms/TKTopAlgo/BRepGProp/BRepGProp_Face.cxx +++ b/src/ModelingAlgorithms/TKTopAlgo/BRepGProp/BRepGProp_Face.cxx @@ -345,9 +345,13 @@ void BRepGProp_Face::UKnots(NCollection_Array1& Knots) const Knots(3) = M_PI * 4.0 / 3.0; Knots(4) = M_PI * 6.0 / 3.0; break; - case GeomAbs_BSplineSurface: - (*((occ::handle*)&((mySurface.Surface()).Surface())))->UKnots(Knots); - break; + case GeomAbs_BSplineSurface: { + const NCollection_Array1& aSrcKnots = + (*((occ::handle*)&((mySurface.Surface()).Surface())))->UKnots(); + for (int i = Knots.Lower(); i <= Knots.Upper(); i++) + Knots(i) = aSrcKnots(i); + } + break; default: Knots(1) = mySurface.FirstUParameter(); Knots(2) = mySurface.LastUParameter(); @@ -378,9 +382,13 @@ void BRepGProp_Face::VKnots(NCollection_Array1& Knots) const Knots(3) = M_PI * 4.0 / 3.0; Knots(4) = M_PI * 6.0 / 3.0; break; - case GeomAbs_BSplineSurface: - (*((occ::handle*)&((mySurface.Surface()).Surface())))->VKnots(Knots); - break; + case GeomAbs_BSplineSurface: { + const NCollection_Array1& aSrcKnots = + (*((occ::handle*)&((mySurface.Surface()).Surface())))->VKnots(); + for (int i = Knots.Lower(); i <= Knots.Upper(); i++) + Knots(i) = aSrcKnots(i); + } + break; default: Knots(1) = mySurface.FirstUParameter(); Knots(2) = mySurface.LastUParameter(); @@ -493,9 +501,13 @@ void BRepGProp_Face::LKnots(NCollection_Array1& Knots) const Knots(1) = myCurve.FirstParameter(); Knots(2) = myCurve.LastParameter(); break; - case GeomAbs_BSplineCurve: - (*((occ::handle*)&(myCurve.Curve())))->Knots(Knots); - break; + case GeomAbs_BSplineCurve: { + const NCollection_Array1& aSrcKnots = + (*((occ::handle*)&(myCurve.Curve())))->Knots(); + for (int i = Knots.Lower(); i <= Knots.Upper(); i++) + Knots(i) = aSrcKnots(i); + } + break; default: Knots(1) = myCurve.FirstParameter(); Knots(2) = myCurve.LastParameter(); @@ -606,13 +618,10 @@ static void GetCurveKnots(const double theMin, if (isSBSpline) { occ::handle aCrv; - int aNbKnots; occ::handle> aCrvKnots; aCrv = occ::down_cast(theCurve.Curve()); - aNbKnots = aCrv->NbKnots(); - aCrvKnots = new NCollection_HArray1(1, aNbKnots); - aCrv->Knots(aCrvKnots->ChangeArray1()); + aCrvKnots = new NCollection_HArray1(aCrv->Knots()); GetRealKnots(theMin, theMax, aCrvKnots, theKnots); } else @@ -649,7 +658,6 @@ void BRepGProp_Face::GetUKnots(const double theUMin { // Using span decomposition for BSpline. occ::handle> aKnots; - int aNbKnots; if (isSBSpline) { @@ -658,9 +666,7 @@ void BRepGProp_Face::GetUKnots(const double theUMin occ::handle aBSplSurf; aBSplSurf = occ::down_cast(aSurf); - aNbKnots = aBSplSurf->NbUKnots(); - aKnots = new NCollection_HArray1(1, aNbKnots); - aBSplSurf->UKnots(aKnots->ChangeArray1()); + aKnots = new NCollection_HArray1(aBSplSurf->UKnots()); } else { @@ -672,9 +678,7 @@ void BRepGProp_Face::GetUKnots(const double theUMin aCurve.Load(occ::down_cast(aSurf)->BasisCurve()); aBSplCurve = aCurve.BSpline(); - aNbKnots = aBSplCurve->NbKnots(); - aKnots = new NCollection_HArray1(1, aNbKnots); - aBSplCurve->Knots(aKnots->ChangeArray1()); + aKnots = new NCollection_HArray1(aBSplCurve->Knots()); } // Compute number of knots inside theUMin and theUMax. @@ -701,16 +705,13 @@ void BRepGProp_Face::GetTKnots(const double theTMin { // Using span decomposition for BSpline. occ::handle> aSurfKnots; - int aNbKnots; // Get V knots of BSpline surface. occ::handle aSurf = mySurface.Surface().Surface(); occ::handle aBSplSurf; aBSplSurf = occ::down_cast(aSurf); - aNbKnots = aBSplSurf->NbVKnots(); - aSurfKnots = new NCollection_HArray1(1, aNbKnots); - aBSplSurf->VKnots(aSurfKnots->ChangeArray1()); + aSurfKnots = new NCollection_HArray1(aBSplSurf->VKnots()); // occ::handle> aCurveKnots; diff --git a/src/ModelingAlgorithms/TKTopAlgo/BRepLib/BRepLib.cxx b/src/ModelingAlgorithms/TKTopAlgo/BRepLib/BRepLib.cxx index fd970bb737..48ecb974a3 100644 --- a/src/ModelingAlgorithms/TKTopAlgo/BRepLib/BRepLib.cxx +++ b/src/ModelingAlgorithms/TKTopAlgo/BRepLib/BRepLib.cxx @@ -1348,8 +1348,7 @@ TopoDS_Edge BRepLib::SameParameter(const TopoDS_Edge& theEdge, || std::abs(OriginPoint.Y() - NewOriginPoint.Y()) > Precision::PConfusion()) { - NCollection_Array1 Knotbs2d(1, bs2d->NbKnots()); - bs2d->Knots(Knotbs2d); + NCollection_Array1 Knotbs2d(bs2d->Knots()); for (int Index = 1; Index <= bs2d->NbKnots(); Index++) { @@ -1375,11 +1374,10 @@ TopoDS_Edge BRepLib::SameParameter(const TopoDS_Edge& theEdge, double Tol2dbail = std::min(UResbail, VResbail); bs2d->D0(bs2d->FirstParameter(), OriginPoint); - int nbp = bs2d->NbPoles(); - NCollection_Array1 poles(1, nbp); - bs2d->Poles(poles); - gp_Pnt2d p = poles(1), p1; - double d = Precision::Infinite(); + int nbp = bs2d->NbPoles(); + const NCollection_Array1& poles = bs2d->Poles(); + gp_Pnt2d p = poles(1), p1; + double d = Precision::Infinite(); for (int ip = 2; ip <= nbp; ip++) { p1 = poles(ip); @@ -1400,8 +1398,7 @@ TopoDS_Edge BRepLib::SameParameter(const TopoDS_Edge& theEdge, || std::abs(OriginPoint.Y() - NewOriginPoint.Y()) > Precision::PConfusion()) { - NCollection_Array1 Knotbs2d(1, bs2d->NbKnots()); - bs2d->Knots(Knotbs2d); + const NCollection_Array1& Knotbs2d = bs2d->Knots(); for (int Index = 1; Index <= bs2d->NbKnots(); Index++) { @@ -1431,9 +1428,7 @@ TopoDS_Edge BRepLib::SameParameter(const TopoDS_Edge& theEdge, { if (repar) { - int NbKnots = bs2d->NbKnots(); - NCollection_Array1 Knots(1, NbKnots); - bs2d->Knots(Knots); + NCollection_Array1 Knots(bs2d->Knots()); // BSplCLib::Reparametrize(f3d,l3d,Knots); BSplCLib::Reparametrize(fC0, lC0, Knots); bs2d->SetKnots(Knots); @@ -1463,13 +1458,12 @@ TopoDS_Edge BRepLib::SameParameter(const TopoDS_Edge& theEdge, if (cont > GeomAbs_C0 && error > std::max(1.e-3, theTolerance)) { - int NbKnots = bs2d->NbKnots(); - NCollection_Array1 Knots(1, NbKnots); - bs2d->Knots(Knots); - double critratio = 10.; - double dtprev = Knots(2) - Knots(1), dtratio = 1.; - double dtmin = dtprev; - double dtcur; + int NbKnots = bs2d->NbKnots(); + const NCollection_Array1& Knots = bs2d->Knots(); + double critratio = 10.; + double dtprev = Knots(2) - Knots(1), dtratio = 1.; + double dtmin = dtprev; + double dtcur; for (int j = 2; j < NbKnots; j++) { dtcur = Knots(j + 1) - Knots(j); @@ -1522,9 +1516,7 @@ TopoDS_Edge BRepLib::SameParameter(const TopoDS_Edge& theEdge, if (std::abs(bs2d->FirstParameter() - fC0) > TolSameRange || std::abs(bs2d->LastParameter() - lC0) > TolSameRange) { - int NbKnots = bs2d->NbKnots(); - NCollection_Array1 Knots(1, NbKnots); - bs2d->Knots(Knots); + NCollection_Array1 Knots(bs2d->Knots()); // BSplCLib::Reparametrize(f3d,l3d,Knots); BSplCLib::Reparametrize(fC0, lC0, Knots); bs2d->SetKnots(Knots); diff --git a/src/ModelingAlgorithms/TKTopAlgo/BRepLib/BRepLib_FuseEdges.cxx b/src/ModelingAlgorithms/TKTopAlgo/BRepLib/BRepLib_FuseEdges.cxx index 826f9cca7d..1c19f55a67 100644 --- a/src/ModelingAlgorithms/TKTopAlgo/BRepLib/BRepLib_FuseEdges.cxx +++ b/src/ModelingAlgorithms/TKTopAlgo/BRepLib/BRepLib_FuseEdges.cxx @@ -76,12 +76,9 @@ static void BCSmoothing(occ::handle& theC, { int aNbKnots = theC->NbKnots(); - NCollection_Array1 aMults(1, aNbKnots); - NCollection_Array1 aKnots(1, aNbKnots); - - theC->Multiplicities(aMults); - theC->Knots(aKnots); - int i, m = theC->Degree(); + NCollection_Array1 aMults(theC->Multiplicities()); + NCollection_Array1 aKnots(theC->Knots()); + int i, m = theC->Degree(); m = m - theCont; if (m < 1) @@ -912,9 +909,8 @@ bool BRepLib_FuseEdges::SameSupport(const TopoDS_Edge& E1, const TopoDS_Edge& E2 return false; } - NCollection_Array1 P1(1, nbpoles), P2(1, nbpoles); - B1->Poles(P1); - B2->Poles(P2); + const NCollection_Array1& P1 = B1->Poles(); + const NCollection_Array1& P2 = B2->Poles(); double tol3d = BRep_Tool::Tolerance(E1); for (int p = 1; p <= nbpoles; p++) @@ -925,13 +921,11 @@ bool BRepLib_FuseEdges::SameSupport(const TopoDS_Edge& E1, const TopoDS_Edge& E2 } } - NCollection_Array1 K1(1, nbknots), K2(1, nbknots); - B1->Knots(K1); - B2->Knots(K2); + const NCollection_Array1& K1 = B1->Knots(); + const NCollection_Array1& K2 = B2->Knots(); - NCollection_Array1 M1(1, nbknots), M2(1, nbknots); - B1->Multiplicities(M1); - B2->Multiplicities(M2); + const NCollection_Array1& M1 = B1->Multiplicities(); + const NCollection_Array1& M2 = B2->Multiplicities(); for (int k = 1; k <= nbknots; k++) { @@ -962,9 +956,8 @@ bool BRepLib_FuseEdges::SameSupport(const TopoDS_Edge& E1, const TopoDS_Edge& E2 if (B1->IsRational()) { - NCollection_Array1 W1(1, nbpoles), W2(1, nbpoles); - B1->Weights(W1); - B2->Weights(W2); + const NCollection_Array1& W1 = B1->WeightsArray(); + const NCollection_Array1& W2 = B2->WeightsArray(); for (int w = 1; w <= nbpoles; w++) { @@ -995,9 +988,8 @@ bool BRepLib_FuseEdges::SameSupport(const TopoDS_Edge& E1, const TopoDS_Edge& E2 return false; } - NCollection_Array1 P1(1, nbpoles), P2(1, nbpoles); - B1->Poles(P1); - B2->Poles(P2); + const NCollection_Array1& P1 = B1->Poles(); + const NCollection_Array1& P2 = B2->Poles(); for (int p = 1; p <= nbpoles; p++) { @@ -1024,9 +1016,8 @@ bool BRepLib_FuseEdges::SameSupport(const TopoDS_Edge& E1, const TopoDS_Edge& E2 if (B1->IsRational()) { - NCollection_Array1 W1(1, nbpoles), W2(1, nbpoles); - B1->Weights(W1); - B2->Weights(W2); + const NCollection_Array1& W1 = B1->WeightsArray(); + const NCollection_Array1& W2 = B2->WeightsArray(); for (int w = 1; w <= nbpoles; w++) { @@ -1147,8 +1138,7 @@ bool BRepLib_FuseEdges::UpdatePCurve(const TopoDS_Edge& theOl || std::abs(last - el) > Precision::PConfusion()) { occ::handle bc = occ::down_cast(Curv2d); - NCollection_Array1 Knots(1, bc->NbKnots()); - bc->Knots(Knots); + NCollection_Array1 Knots(bc->Knots()); BSplCLib::Reparametrize(ef, el, Knots); bc->SetKnots(Knots); } diff --git a/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_TopolTool.cxx b/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_TopolTool.cxx index 61db5a0960..a09f923642 100644 --- a/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_TopolTool.cxx +++ b/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_TopolTool.cxx @@ -465,11 +465,10 @@ void BRepTopAdaptor_TopolTool::ComputeSamplePoints() { if (typS == GeomAbs_BSplineSurface) { - const occ::handle& Bspl = myS->BSpline(); - int nbup = Bspl->NbUPoles(); - int nbvp = Bspl->NbVPoles(); - NCollection_Array2 array2(1, nbup, 1, nbvp); - Bspl->Poles(array2); + const occ::handle& Bspl = myS->BSpline(); + int nbup = Bspl->NbUPoles(); + int nbvp = Bspl->NbVPoles(); + const NCollection_Array2& array2 = Bspl->Poles(); Analyse(array2, nbup, nbvp, myNbSamplesU, myNbSamplesV); nbsu = myNbSamplesU; nbsv = myNbSamplesV; @@ -477,11 +476,10 @@ void BRepTopAdaptor_TopolTool::ComputeSamplePoints() } else if (typS == GeomAbs_BezierSurface) { - const occ::handle& Bez = myS->Bezier(); - int nbup = Bez->NbUPoles(); - int nbvp = Bez->NbVPoles(); - NCollection_Array2 array2(1, nbup, 1, nbvp); - Bez->Poles(array2); + const occ::handle& Bez = myS->Bezier(); + int nbup = Bez->NbUPoles(); + int nbvp = Bez->NbVPoles(); + const NCollection_Array2& array2 = Bez->Poles(); Analyse(array2, nbup, nbvp, myNbSamplesU, myNbSamplesV); nbsu = myNbSamplesU; nbsv = myNbSamplesV; diff --git a/src/ModelingData/TKBRep/BRepTools/BRepTools_NurbsConvertModification.cxx b/src/ModelingData/TKBRep/BRepTools/BRepTools_NurbsConvertModification.cxx index 6b45cbc384..e3a1f2793a 100644 --- a/src/ModelingData/TKBRep/BRepTools/BRepTools_NurbsConvertModification.cxx +++ b/src/ModelingData/TKBRep/BRepTools/BRepTools_NurbsConvertModification.cxx @@ -61,8 +61,7 @@ static void GeomLib_ChangeUBounds(occ::handle& aSurface, const double newU1, const double newU2) { - NCollection_Array1 knots(1, aSurface->NbUKnots()); - aSurface->UKnots(knots); + NCollection_Array1 knots(aSurface->UKnots()); BSplCLib::Reparametrize(newU1, newU2, knots); aSurface->SetUKnots(knots); } @@ -71,8 +70,7 @@ static void GeomLib_ChangeVBounds(occ::handle& aSurface, const double newV1, const double newV2) { - NCollection_Array1 knots(1, aSurface->NbVKnots()); - aSurface->VKnots(knots); + NCollection_Array1 knots(aSurface->VKnots()); BSplCLib::Reparametrize(newV1, newV2, knots); aSurface->SetVKnots(knots); } @@ -449,8 +447,7 @@ bool BRepTools_NurbsConvertModification::NewCurve(const TopoDS_Edge& E, BC->Resolution(Tol, UTol); if (std::abs(f - fnew) > UTol || std::abs(l - lnew) > UTol) { - NCollection_Array1 knots(1, BC->NbKnots()); - BC->Knots(knots); + NCollection_Array1 knots(BC->Knots()); BSplCLib::Reparametrize(f, l, knots); BC->SetKnots(knots); } diff --git a/src/ModelingData/TKG2d/GTests/Geom2d_BSplineCurve_Test.cxx b/src/ModelingData/TKG2d/GTests/Geom2d_BSplineCurve_Test.cxx index c224c5cdf7..89e10eff2c 100644 --- a/src/ModelingData/TKG2d/GTests/Geom2d_BSplineCurve_Test.cxx +++ b/src/ModelingData/TKG2d/GTests/Geom2d_BSplineCurve_Test.cxx @@ -447,4 +447,57 @@ TEST_F(Geom2d_BSplineCurve_Test, InsertKnots_Multiple) EXPECT_EQ(myOriginalCurve->NbKnots(), 4); gp_Pnt2d aValAfter = myOriginalCurve->Value(0.5); EXPECT_TRUE(aValBefore.IsEqual(aValAfter, 1e-10)); -} \ No newline at end of file +} + +TEST_F(Geom2d_BSplineCurve_Test, WeightsArray_NonRational_ReturnsUnitWeights) +{ + ASSERT_FALSE(myOriginalCurve->IsRational()); + + const NCollection_Array1& aWeights = myOriginalCurve->WeightsArray(); + EXPECT_EQ(aWeights.Length(), myOriginalCurve->NbPoles()); + EXPECT_FALSE(aWeights.IsDeletable()); + for (int i = 1; i <= aWeights.Length(); ++i) + { + EXPECT_DOUBLE_EQ(aWeights(i), 1.0); + } + // Verify that the reference is stable + EXPECT_EQ(&aWeights, &myOriginalCurve->WeightsArray()); +} + +TEST_F(Geom2d_BSplineCurve_Test, WeightsArray_Rational_ReturnsOwning) +{ + // Create a rational BSpline + NCollection_Array1 aPoles(1, 4); + aPoles(1) = gp_Pnt2d(0, 0); + aPoles(2) = gp_Pnt2d(1, 1); + aPoles(3) = gp_Pnt2d(2, 1); + aPoles(4) = gp_Pnt2d(3, 0); + + NCollection_Array1 aWeightsIn(1, 4); + aWeightsIn(1) = 1.0; + aWeightsIn(2) = 2.0; + aWeightsIn(3) = 3.0; + aWeightsIn(4) = 1.0; + + NCollection_Array1 aKnots(1, 2); + aKnots(1) = 0.0; + aKnots(2) = 1.0; + + NCollection_Array1 aMults(1, 2); + aMults(1) = 4; + aMults(2) = 4; + + occ::handle aRational = + new Geom2d_BSplineCurve(aPoles, aWeightsIn, aKnots, aMults, 3); + ASSERT_TRUE(aRational->IsRational()); + + const NCollection_Array1& aWeights = aRational->WeightsArray(); + EXPECT_EQ(aWeights.Length(), 4); + EXPECT_TRUE(aWeights.IsDeletable()); + EXPECT_DOUBLE_EQ(aWeights(1), 1.0); + EXPECT_DOUBLE_EQ(aWeights(2), 2.0); + EXPECT_DOUBLE_EQ(aWeights(3), 3.0); + EXPECT_DOUBLE_EQ(aWeights(4), 1.0); + // Verify that the reference is stable + EXPECT_EQ(&aWeights, &aRational->WeightsArray()); +} diff --git a/src/ModelingData/TKG2d/GTests/Geom2d_BezierCurve_Test.cxx b/src/ModelingData/TKG2d/GTests/Geom2d_BezierCurve_Test.cxx index 961999959d..f3203fd7c0 100644 --- a/src/ModelingData/TKG2d/GTests/Geom2d_BezierCurve_Test.cxx +++ b/src/ModelingData/TKG2d/GTests/Geom2d_BezierCurve_Test.cxx @@ -454,4 +454,42 @@ TEST_F(Geom2d_BezierCurve_Test, RationalIncrease) EXPECT_TRUE(aCurve->IsRational()); gp_Pnt2d aValAfter = aCurve->Value(0.5); EXPECT_TRUE(aValBefore.IsEqual(aValAfter, 1e-10)); -} \ No newline at end of file +} + +TEST_F(Geom2d_BezierCurve_Test, WeightsArray_NonRational_ReturnsUnitWeights) +{ + ASSERT_FALSE(myOriginalCurve->IsRational()); + + const NCollection_Array1& aWeights = myOriginalCurve->WeightsArray(); + EXPECT_EQ(aWeights.Length(), myOriginalCurve->NbPoles()); + EXPECT_FALSE(aWeights.IsDeletable()); + for (int i = 1; i <= aWeights.Length(); ++i) + { + EXPECT_DOUBLE_EQ(aWeights(i), 1.0); + } + EXPECT_EQ(&aWeights, &myOriginalCurve->WeightsArray()); +} + +TEST_F(Geom2d_BezierCurve_Test, WeightsArray_Rational_ReturnsOwning) +{ + NCollection_Array1 aPoles(1, 3); + aPoles(1) = gp_Pnt2d(0, 0); + aPoles(2) = gp_Pnt2d(1, 1); + aPoles(3) = gp_Pnt2d(2, 0); + + NCollection_Array1 aWeightsIn(1, 3); + aWeightsIn(1) = 1.0; + aWeightsIn(2) = 2.0; + aWeightsIn(3) = 1.0; + + occ::handle aRational = new Geom2d_BezierCurve(aPoles, aWeightsIn); + ASSERT_TRUE(aRational->IsRational()); + + const NCollection_Array1& aWeights = aRational->WeightsArray(); + EXPECT_EQ(aWeights.Length(), 3); + EXPECT_TRUE(aWeights.IsDeletable()); + EXPECT_DOUBLE_EQ(aWeights(1), 1.0); + EXPECT_DOUBLE_EQ(aWeights(2), 2.0); + EXPECT_DOUBLE_EQ(aWeights(3), 1.0); + EXPECT_EQ(&aWeights, &aRational->WeightsArray()); +} diff --git a/src/ModelingData/TKG2d/Geom2d/Geom2d_BSplineCurve.cxx b/src/ModelingData/TKG2d/Geom2d/Geom2d_BSplineCurve.cxx index 9c636d9b70..d1019c50fe 100644 --- a/src/ModelingData/TKG2d/Geom2d/Geom2d_BSplineCurve.cxx +++ b/src/ModelingData/TKG2d/Geom2d/Geom2d_BSplineCurve.cxx @@ -97,7 +97,8 @@ occ::handle Geom2d_BSplineCurve::Copy() const Geom2d_BSplineCurve::Geom2d_BSplineCurve(const Geom2d_BSplineCurve& theOther) : myPoles(theOther.myPoles), - myWeights(theOther.myWeights), + myWeights(theOther.myRational ? NCollection_Array1(theOther.myWeights) + : BSplCLib::UnitWeights(theOther.myPoles.Length())), myKnots(theOther.myKnots), myFlatKnots(theOther.myFlatKnots), myMults(theOther.myMults), @@ -134,6 +135,8 @@ Geom2d_BSplineCurve::Geom2d_BSplineCurve(const NCollection_Array1& Pol myPoles.Resize(1, Poles.Length(), false); myPoles.Assign(Poles); + myWeights = BSplCLib::UnitWeights(Poles.Length()); + myKnots.Resize(1, Knots.Length(), false); myKnots.Assign(Knots); @@ -186,6 +189,10 @@ Geom2d_BSplineCurve::Geom2d_BSplineCurve(const NCollection_Array1& Pol myWeights.Resize(1, Weights.Length(), false); myWeights.Assign(Weights); } + else + { + myWeights = BSplCLib::UnitWeights(Poles.Length()); + } myKnots.Resize(1, Knots.Length(), false); myKnots.Assign(Knots); @@ -247,11 +254,14 @@ void Geom2d_BSplineCurve::IncreaseDegree(const int Degree) nknots, nmults); - myDeg = Degree; - myPoles = std::move(npoles); - myWeights = std::move(nweights); - myKnots = std::move(nknots); - myMults = std::move(nmults); + myDeg = Degree; + myPoles = std::move(npoles); + if (IsRational()) + myWeights = std::move(nweights); + else + myWeights = BSplCLib::UnitWeights(myPoles.Length()); + myKnots = std::move(nknots); + myMults = std::move(nmults); updateKnots(); } @@ -348,10 +358,13 @@ void Geom2d_BSplineCurve::InsertKnots(const NCollection_Array1& Knots, nmults, Epsilon, Add); - myWeights = std::move(nweights); - myPoles = std::move(npoles); - myKnots = std::move(nknots); - myMults = std::move(nmults); + if (myRational) + myWeights = std::move(nweights); + else + myWeights = BSplCLib::UnitWeights(npoles.Length()); + myPoles = std::move(npoles); + myKnots = std::move(nknots); + myMults = std::move(nmults); updateKnots(); } @@ -404,10 +417,13 @@ bool Geom2d_BSplineCurve::RemoveKnot(const int Index, const int M, const double return false; } - myWeights = std::move(nweights); - myPoles = std::move(npoles); - myKnots = std::move(nknots); - myMults = std::move(nmults); + if (IsRational()) + myWeights = std::move(nweights); + else + myWeights = BSplCLib::UnitWeights(npoles.Length()); + myPoles = std::move(npoles); + myKnots = std::move(nknots); + myMults = std::move(nmults); updateKnots(); myMaxDerivInvOk = false; @@ -489,8 +505,12 @@ void Geom2d_BSplineCurve::InsertPoleAfter(const int Index, const gp_Pnt2d& P, co nweights(i + 1) = 1.; } - myPoles = std::move(npoles); - myWeights = std::move(nweights); + myPoles = std::move(npoles); + if (rat) + myWeights = std::move(nweights); + else + myWeights = BSplCLib::UnitWeights(myPoles.Length()); + myRational = rat; myKnots = std::move(nknots); myMults = std::move(nmults); myMaxDerivInvOk = false; @@ -548,10 +568,20 @@ void Geom2d_BSplineCurve::RemovePole(const int Index) nweights(i) = myWeights.Value(i + 1); } - myPoles = std::move(npoles); - myWeights = std::move(nweights); - myKnots = std::move(nknots); - myMults = std::move(nmults); + myPoles = std::move(npoles); + if (IsRational()) + { + myWeights = std::move(nweights); + myRational = Rational(myWeights); + if (!myRational) + myWeights = BSplCLib::UnitWeights(myPoles.Length()); + } + else + { + myWeights = BSplCLib::UnitWeights(myPoles.Length()); + } + myKnots = std::move(nknots); + myMults = std::move(nmults); updateKnots(); } @@ -747,9 +777,9 @@ void Geom2d_BSplineCurve::Segment(const double aU1, const double aU2, const doub myMults = std::move(nmults); myPoles = std::move(npoles); if (myRational) - { myWeights = std::move(nweights); - } + else + myWeights = BSplCLib::UnitWeights(myPoles.Length()); myMaxDerivInvOk = false; updateKnots(); } @@ -830,6 +860,8 @@ void Geom2d_BSplineCurve::SetPeriodic() myPoles.Resize(1, nbp, true); if (myRational) myWeights.Resize(1, nbp, true); + else + myWeights = BSplCLib::UnitWeights(nbp); myPeriodic = true; @@ -919,6 +951,8 @@ void Geom2d_BSplineCurve::SetOrigin(const int Index) myMults = std::move(nmults); if (myRational) myWeights = std::move(nweights); + else + myWeights = BSplCLib::UnitWeights(nbpoles); myMaxDerivInvOk = false; updateKnots(); } @@ -953,8 +987,11 @@ void Geom2d_BSplineCurve::SetNotPeriodic() nknots, npoles, myRational ? &nweights : BSplCLib::NoWeights()); - myPoles = std::move(npoles); - myWeights = std::move(nweights); + myPoles = std::move(npoles); + if (IsRational()) + myWeights = std::move(nweights); + else + myWeights = BSplCLib::UnitWeights(myPoles.Length()); myMults = std::move(nmults); myKnots = std::move(nknots); myPeriodic = false; @@ -995,10 +1032,10 @@ void Geom2d_BSplineCurve::SetWeight(const int Index, const double W) if (rat) { + // Becoming rational from non-rational: copy non-owning view to owned array. if (!IsRational()) { - myWeights.Resize(1, myPoles.Length(), false); - myWeights.Init(1.); + myWeights = NCollection_Array1(myWeights); } myWeights.SetValue(Index, W); @@ -1007,10 +1044,10 @@ void Geom2d_BSplineCurve::SetWeight(const int Index, const double W) { rat = Rational(myWeights); if (!rat) - myWeights = NCollection_Array1(); + myWeights = BSplCLib::UnitWeights(myPoles.Length()); } - myRational = myWeights.Size() > 0; + myRational = rat; } myMaxDerivInvOk = false; @@ -1105,7 +1142,6 @@ void Geom2d_BSplineCurve::MovePointAndTangent(const double U, void Geom2d_BSplineCurve::updateKnots() { - myRational = myWeights.Size() > 0; myMaxDerivInvOk = false; int MaxKnotMult = 0; diff --git a/src/ModelingData/TKG2d/Geom2d/Geom2d_BSplineCurve.hxx b/src/ModelingData/TKG2d/Geom2d/Geom2d_BSplineCurve.hxx index 74e938e109..996754fb63 100644 --- a/src/ModelingData/TKG2d/Geom2d/Geom2d_BSplineCurve.hxx +++ b/src/ModelingData/TKG2d/Geom2d/Geom2d_BSplineCurve.hxx @@ -818,6 +818,13 @@ public: //! Returns the weights of the B-spline curve; Standard_EXPORT const NCollection_Array1* Weights() const; + //! Returns a const reference to the weights array. + //! For rational curves: the internal owning weights array. + //! For non-rational curves: a non-owning view of unit weights from BSplCLib. + //! The array is always sized to match NbPoles(). + //! @warning Do NOT modify elements through the returned reference. + const NCollection_Array1& WeightsArray() const { return myWeights; } + //! Applies the transformation T to this BSpline curve. Standard_EXPORT void Transform(const gp_Trsf2d& T) override; diff --git a/src/ModelingData/TKG2d/Geom2d/Geom2d_BezierCurve.cxx b/src/ModelingData/TKG2d/Geom2d/Geom2d_BezierCurve.cxx index 89071c3e73..dc7c165652 100644 --- a/src/ModelingData/TKG2d/Geom2d/Geom2d_BezierCurve.cxx +++ b/src/ModelingData/TKG2d/Geom2d/Geom2d_BezierCurve.cxx @@ -103,7 +103,8 @@ Geom2d_BezierCurve::Geom2d_BezierCurve(const NCollection_Array1& Poles Geom2d_BezierCurve::Geom2d_BezierCurve(const Geom2d_BezierCurve& theOther) : myPoles(theOther.myPoles), - myWeights(theOther.myWeights), + myWeights(theOther.myRational ? NCollection_Array1(theOther.myWeights) + : BSplCLib::UnitWeights(theOther.myPoles.Length())), myRational(theOther.myRational), myClosed(theOther.myClosed), myMaxDerivInvOk(false) @@ -382,9 +383,8 @@ void Geom2d_BezierCurve::SetWeight(const int Index, const double Weight) if (std::abs(Weight - 1.) <= gp::Resolution()) return; - // set weights of 1. - myWeights.Resize(1, nbpoles, false); - myWeights.Init(1.); + // Becoming rational: copy non-owning view to owned array. + myWeights = NCollection_Array1(myWeights); } myWeights(Index) = Weight; @@ -393,7 +393,7 @@ void Geom2d_BezierCurve::SetWeight(const int Index, const double Weight) if (wasrat && !Rational(myWeights)) { myRational = false; - myWeights = NCollection_Array1(); + myWeights = BSplCLib::UnitWeights(nbpoles); } else myRational = true; @@ -619,13 +619,13 @@ void Geom2d_BezierCurve::init(const NCollection_Array1& thePoles, myRational = Rational(myWeights); if (!myRational) { - myWeights = NCollection_Array1(); + myWeights = BSplCLib::UnitWeights(nbpoles); } } else { myRational = false; - myWeights = NCollection_Array1(); + myWeights = BSplCLib::UnitWeights(nbpoles); } myMaxDerivInv = 0.0; diff --git a/src/ModelingData/TKG2d/Geom2d/Geom2d_BezierCurve.hxx b/src/ModelingData/TKG2d/Geom2d/Geom2d_BezierCurve.hxx index a38b148d65..523b13c82b 100644 --- a/src/ModelingData/TKG2d/Geom2d/Geom2d_BezierCurve.hxx +++ b/src/ModelingData/TKG2d/Geom2d/Geom2d_BezierCurve.hxx @@ -280,6 +280,13 @@ public: return myRational ? &myWeights : BSplCLib::NoWeights(); } + //! Returns a const reference to the weights array. + //! For rational curves: the internal owning weights array. + //! For non-rational curves: a non-owning view of unit weights from BSplCLib. + //! The array is always sized to match NbPoles(). + //! @warning Do NOT modify elements through the returned reference. + const NCollection_Array1& WeightsArray() const { return myWeights; } + //! Applies the transformation T to this Bezier curve. Standard_EXPORT void Transform(const gp_Trsf2d& T) override; diff --git a/src/ModelingData/TKG2d/Geom2dAdaptor/Geom2dAdaptor_Curve.cxx b/src/ModelingData/TKG2d/Geom2dAdaptor/Geom2dAdaptor_Curve.cxx index ab67286ae2..247c214785 100644 --- a/src/ModelingData/TKG2d/Geom2dAdaptor/Geom2dAdaptor_Curve.cxx +++ b/src/ModelingData/TKG2d/Geom2dAdaptor/Geom2dAdaptor_Curve.cxx @@ -109,15 +109,13 @@ occ::handle Geom2dAdaptor_Curve::ShallowCopy() const GeomAbs_Shape Geom2dAdaptor_Curve::LocalContinuity(const double U1, const double U2) const { Standard_NoSuchObject_Raise_if(myTypeCurve != GeomAbs_BSplineCurve, " "); - const auto& aBSpline = std::get(myCurveData).Curve; - int Nb = aBSpline->NbKnots(); - int Index1 = 0; - int Index2 = 0; - double newFirst, newLast; - NCollection_Array1 TK(1, Nb); - NCollection_Array1 TM(1, Nb); - aBSpline->Knots(TK); - aBSpline->Multiplicities(TM); + const auto& aBSpline = std::get(myCurveData).Curve; + int Nb = aBSpline->NbKnots(); + int Index1 = 0; + int Index2 = 0; + double newFirst, newLast; + const NCollection_Array1& TK = aBSpline->Knots(); + const NCollection_Array1& TM = aBSpline->Multiplicities(); BSplCLib::LocateParameter(aBSpline->Degree(), TK, TM, diff --git a/src/ModelingData/TKG3d/Adaptor3d/Adaptor3d_CurveOnSurface.cxx b/src/ModelingData/TKG3d/Adaptor3d/Adaptor3d_CurveOnSurface.cxx index f9905c921d..e34624521e 100644 --- a/src/ModelingData/TKG3d/Adaptor3d/Adaptor3d_CurveOnSurface.cxx +++ b/src/ModelingData/TKG3d/Adaptor3d/Adaptor3d_CurveOnSurface.cxx @@ -275,12 +275,11 @@ static void Locate1Coord(const int Index, gp_Pnt2d& LeftBot, gp_Pnt2d& RightTop) { - double Comp1 = 0, DComp1 = 0, cur, f = 0.0, l = 0.0; - constexpr double Tol = Precision::PConfusion() / 10; - int i = 1, Bnd1, Bnd2; - bool DIsNull = false; - NCollection_Array1 Arr(1, BSplC->NbKnots()); - BSplC->Knots(Arr); + double Comp1 = 0, DComp1 = 0, cur, f = 0.0, l = 0.0; + constexpr double Tol = Precision::PConfusion() / 10; + int i = 1, Bnd1, Bnd2; + bool DIsNull = false; + const NCollection_Array1& Arr = BSplC->Knots(); if (Index == 1) { @@ -495,14 +494,12 @@ static void Locate1Coord(const int Index, int Bnd1 = Down, Bnd2 = Up; if (Index == 1) { - NCollection_Array1 Arr1(1, BSplS->NbUKnots()); - BSplS->UKnots(Arr1); // Up1=Arr1.Upper(); Down1=Arr1.Lower(); + const NCollection_Array1& Arr1 = BSplS->UKnots(); FindBounds(Arr1, cur, DUV.X(), Bnd1, Bnd2, DIsNull); } else if (Index == 2) { - NCollection_Array1 Arr2(1, BSplS->NbVKnots()); - BSplS->VKnots(Arr2); // Up2=Arr2.Upper(); Down2=Arr2.Lower(); + const NCollection_Array1& Arr2 = BSplS->VKnots(); FindBounds(Arr2, cur, DUV.Y(), Bnd1, Bnd2, DIsNull); } @@ -1456,9 +1453,8 @@ occ::handle Adaptor3d_CurveOnSurface::Bezier() const if (Bez2d->IsRational()) { - NCollection_Array1 Weights(1, NbPoles); - Bez2d->Weights(Weights); - Bez = new Geom_BezierCurve(Poles, Weights); + const NCollection_Array1& Weights = Bez2d->WeightsArray(); + Bez = new Geom_BezierCurve(Poles, Weights); } else { @@ -1485,17 +1481,14 @@ occ::handle Adaptor3d_CurveOnSurface::BSpline() const Poles(i) = to3d(Plane, Bsp2d->Pole(i)); } - NCollection_Array1 Knots(1, Bsp2d->NbKnots()); - NCollection_Array1 Mults(1, Bsp2d->NbKnots()); - Bsp2d->Knots(Knots); - Bsp2d->Multiplicities(Mults); + const NCollection_Array1& Knots = Bsp2d->Knots(); + const NCollection_Array1& Mults = Bsp2d->Multiplicities(); occ::handle Bsp; if (Bsp2d->IsRational()) { - NCollection_Array1 Weights(1, NbPoles); - Bsp2d->Weights(Weights); + const NCollection_Array1& Weights = Bsp2d->WeightsArray(); Bsp = new Geom_BSplineCurve(Poles, Weights, Knots, Mults, Bsp2d->Degree(), Bsp2d->IsPeriodic()); } else @@ -1889,14 +1882,12 @@ void Adaptor3d_CurveOnSurface::LocatePart(const gp_Pnt2d& if ((DUIsNull) && (!DVIsNull)) { - NCollection_Array1 ArrU(1, BSplS->NbUKnots()); - BSplS->UKnots(ArrU); + const NCollection_Array1& ArrU = BSplS->UKnots(); Locate2Coord(1, UV, DUV, BSplS, ArrU, LeftBot, RightTop); } else if ((DVIsNull) && (!DUIsNull)) { - NCollection_Array1 ArrV(1, BSplS->NbVKnots()); - BSplS->VKnots(ArrV); + const NCollection_Array1& ArrV = BSplS->VKnots(); Locate2Coord(2, UV, DUV, BSplS, ArrV, LeftBot, RightTop); } } diff --git a/src/ModelingData/TKG3d/Adaptor3d/Adaptor3d_TopolTool.cxx b/src/ModelingData/TKG3d/Adaptor3d/Adaptor3d_TopolTool.cxx index 5e135275dc..4bd49fcd13 100644 --- a/src/ModelingData/TKG3d/Adaptor3d/Adaptor3d_TopolTool.cxx +++ b/src/ModelingData/TKG3d/Adaptor3d/Adaptor3d_TopolTool.cxx @@ -849,11 +849,10 @@ void Adaptor3d_TopolTool::ComputeSamplePoints() { if (nbsu > 8 || nbsv > 8) { - const occ::handle& Bspl = myS->BSpline(); - int nbup = Bspl->NbUPoles(); - int nbvp = Bspl->NbVPoles(); - NCollection_Array2 array2(1, nbup, 1, nbvp); - Bspl->Poles(array2); + const occ::handle& Bspl = myS->BSpline(); + const NCollection_Array2& array2 = Bspl->Poles(); + int nbup = array2.NbRows(); + int nbvp = array2.NbColumns(); Analyse(array2, nbup, nbvp, nbsu, nbsv); } // Check anisotropy @@ -875,11 +874,10 @@ void Adaptor3d_TopolTool::ComputeSamplePoints() { if (nbsu > 8 || nbsv > 8) { - const occ::handle& Bez = myS->Bezier(); - int nbup = Bez->NbUPoles(); - int nbvp = Bez->NbVPoles(); - NCollection_Array2 array2(1, nbup, 1, nbvp); - Bez->Poles(array2); + const occ::handle& Bez = myS->Bezier(); + const NCollection_Array2& array2 = Bez->Poles(); + int nbup = array2.NbRows(); + int nbvp = array2.NbColumns(); Analyse(array2, nbup, nbvp, nbsu, nbsv); } } diff --git a/src/ModelingData/TKG3d/GTests/Geom_BSplineCurve_Test.cxx b/src/ModelingData/TKG3d/GTests/Geom_BSplineCurve_Test.cxx index 5c283601fd..d66ecaa077 100644 --- a/src/ModelingData/TKG3d/GTests/Geom_BSplineCurve_Test.cxx +++ b/src/ModelingData/TKG3d/GTests/Geom_BSplineCurve_Test.cxx @@ -676,4 +676,57 @@ TEST_F(Geom_BSplineCurve_Test, LocalD1) EXPECT_TRUE(aPnt.IsEqual(aPntL, 1e-10)); EXPECT_NEAR(aV1.X(), aV1L.X(), 1e-10); EXPECT_NEAR(aV1.Y(), aV1L.Y(), 1e-10); -} \ No newline at end of file +} + +TEST_F(Geom_BSplineCurve_Test, WeightsArray_NonRational_ReturnsUnitWeights) +{ + ASSERT_FALSE(myOriginalCurve->IsRational()); + + const NCollection_Array1& aWeights = myOriginalCurve->WeightsArray(); + EXPECT_EQ(aWeights.Length(), myOriginalCurve->NbPoles()); + EXPECT_FALSE(aWeights.IsDeletable()); + for (int i = 1; i <= aWeights.Length(); ++i) + { + EXPECT_DOUBLE_EQ(aWeights(i), 1.0); + } + // Verify that the reference is stable + EXPECT_EQ(&aWeights, &myOriginalCurve->WeightsArray()); +} + +TEST_F(Geom_BSplineCurve_Test, WeightsArray_Rational_ReturnsOwning) +{ + // Create a rational BSpline + NCollection_Array1 aPoles(1, 4); + aPoles(1) = gp_Pnt(0, 0, 0); + aPoles(2) = gp_Pnt(1, 1, 0); + aPoles(3) = gp_Pnt(2, 1, 0); + aPoles(4) = gp_Pnt(3, 0, 0); + + NCollection_Array1 aWeightsIn(1, 4); + aWeightsIn(1) = 1.0; + aWeightsIn(2) = 2.0; + aWeightsIn(3) = 3.0; + aWeightsIn(4) = 1.0; + + NCollection_Array1 aKnots(1, 2); + aKnots(1) = 0.0; + aKnots(2) = 1.0; + + NCollection_Array1 aMults(1, 2); + aMults(1) = 4; + aMults(2) = 4; + + occ::handle aRational = + new Geom_BSplineCurve(aPoles, aWeightsIn, aKnots, aMults, 3); + ASSERT_TRUE(aRational->IsRational()); + + const NCollection_Array1& aWeights = aRational->WeightsArray(); + EXPECT_EQ(aWeights.Length(), 4); + EXPECT_TRUE(aWeights.IsDeletable()); + EXPECT_DOUBLE_EQ(aWeights(1), 1.0); + EXPECT_DOUBLE_EQ(aWeights(2), 2.0); + EXPECT_DOUBLE_EQ(aWeights(3), 3.0); + EXPECT_DOUBLE_EQ(aWeights(4), 1.0); + // Verify that the reference is stable + EXPECT_EQ(&aWeights, &aRational->WeightsArray()); +} diff --git a/src/ModelingData/TKG3d/GTests/Geom_BSplineSurface_Test.cxx b/src/ModelingData/TKG3d/GTests/Geom_BSplineSurface_Test.cxx index fa093669a6..9d96a2d445 100644 --- a/src/ModelingData/TKG3d/GTests/Geom_BSplineSurface_Test.cxx +++ b/src/ModelingData/TKG3d/GTests/Geom_BSplineSurface_Test.cxx @@ -875,4 +875,60 @@ TEST_F(Geom_BSplineSurface_Test, CopyIndependence_Knots) // Original now has 3 U-knots, copy should still have 2 EXPECT_EQ(aCopy->NbUKnots(), 2); EXPECT_EQ(myOriginalSurface->NbUKnots(), 3); -} \ No newline at end of file +} + +TEST_F(Geom_BSplineSurface_Test, WeightsArray_NonRational_ReturnsUnitWeights) +{ + ASSERT_FALSE(myOriginalSurface->IsURational()); + ASSERT_FALSE(myOriginalSurface->IsVRational()); + + const NCollection_Array2& aWeights = myOriginalSurface->WeightsArray(); + EXPECT_EQ(aWeights.ColLength(), myOriginalSurface->NbUPoles()); + EXPECT_EQ(aWeights.RowLength(), myOriginalSurface->NbVPoles()); + EXPECT_FALSE(aWeights.IsDeletable()); + for (int i = aWeights.LowerRow(); i <= aWeights.UpperRow(); ++i) + { + for (int j = aWeights.LowerCol(); j <= aWeights.UpperCol(); ++j) + { + EXPECT_DOUBLE_EQ(aWeights(i, j), 1.0); + } + } + EXPECT_EQ(&aWeights, &myOriginalSurface->WeightsArray()); +} + +TEST_F(Geom_BSplineSurface_Test, WeightsArray_Rational_ReturnsOwning) +{ + NCollection_Array2 aPoles(1, 3, 1, 3); + NCollection_Array2 aWeightsIn(1, 3, 1, 3); + for (int i = 1; i <= 3; ++i) + { + for (int j = 1; j <= 3; ++j) + { + aPoles(i, j) = gp_Pnt(i, j, 0); + aWeightsIn(i, j) = (i == 2 && j == 2) ? 2.0 : 1.0; + } + } + + NCollection_Array1 aKnotsU(1, 2), aKnotsV(1, 2); + aKnotsU(1) = 0.0; + aKnotsU(2) = 1.0; + aKnotsV(1) = 0.0; + aKnotsV(2) = 1.0; + + NCollection_Array1 aMultsU(1, 2), aMultsV(1, 2); + aMultsU(1) = 3; + aMultsU(2) = 3; + aMultsV(1) = 3; + aMultsV(2) = 3; + + occ::handle aRational = + new Geom_BSplineSurface(aPoles, aWeightsIn, aKnotsU, aKnotsV, aMultsU, aMultsV, 2, 2); + + const NCollection_Array2& aWeights = aRational->WeightsArray(); + EXPECT_EQ(aWeights.ColLength(), 3); + EXPECT_EQ(aWeights.RowLength(), 3); + EXPECT_TRUE(aWeights.IsDeletable()); + EXPECT_DOUBLE_EQ(aWeights(2, 2), 2.0); + EXPECT_DOUBLE_EQ(aWeights(1, 1), 1.0); + EXPECT_EQ(&aWeights, &aRational->WeightsArray()); +} diff --git a/src/ModelingData/TKG3d/GTests/Geom_BezierCurve_Test.cxx b/src/ModelingData/TKG3d/GTests/Geom_BezierCurve_Test.cxx index 743a1d147d..2498577a63 100644 --- a/src/ModelingData/TKG3d/GTests/Geom_BezierCurve_Test.cxx +++ b/src/ModelingData/TKG3d/GTests/Geom_BezierCurve_Test.cxx @@ -485,4 +485,42 @@ TEST_F(Geom_BezierCurve_Test, LinearCurve) gp_Vec aV1, aV2; aCurve->D2(0.5, aPnt, aV1, aV2); EXPECT_NEAR(aV2.Magnitude(), 0.0, 1e-10); -} \ No newline at end of file +} + +TEST_F(Geom_BezierCurve_Test, WeightsArray_NonRational_ReturnsUnitWeights) +{ + ASSERT_FALSE(myOriginalCurve->IsRational()); + + const NCollection_Array1& aWeights = myOriginalCurve->WeightsArray(); + EXPECT_EQ(aWeights.Length(), myOriginalCurve->NbPoles()); + EXPECT_FALSE(aWeights.IsDeletable()); + for (int i = 1; i <= aWeights.Length(); ++i) + { + EXPECT_DOUBLE_EQ(aWeights(i), 1.0); + } + EXPECT_EQ(&aWeights, &myOriginalCurve->WeightsArray()); +} + +TEST_F(Geom_BezierCurve_Test, WeightsArray_Rational_ReturnsOwning) +{ + NCollection_Array1 aPoles(1, 3); + aPoles(1) = gp_Pnt(0, 0, 0); + aPoles(2) = gp_Pnt(1, 1, 0); + aPoles(3) = gp_Pnt(2, 0, 0); + + NCollection_Array1 aWeightsIn(1, 3); + aWeightsIn(1) = 1.0; + aWeightsIn(2) = 2.0; + aWeightsIn(3) = 1.0; + + occ::handle aRational = new Geom_BezierCurve(aPoles, aWeightsIn); + ASSERT_TRUE(aRational->IsRational()); + + const NCollection_Array1& aWeights = aRational->WeightsArray(); + EXPECT_EQ(aWeights.Length(), 3); + EXPECT_TRUE(aWeights.IsDeletable()); + EXPECT_DOUBLE_EQ(aWeights(1), 1.0); + EXPECT_DOUBLE_EQ(aWeights(2), 2.0); + EXPECT_DOUBLE_EQ(aWeights(3), 1.0); + EXPECT_EQ(&aWeights, &aRational->WeightsArray()); +} diff --git a/src/ModelingData/TKG3d/GTests/Geom_BezierSurface_Test.cxx b/src/ModelingData/TKG3d/GTests/Geom_BezierSurface_Test.cxx index 6e0a095809..cc86e20a87 100644 --- a/src/ModelingData/TKG3d/GTests/Geom_BezierSurface_Test.cxx +++ b/src/ModelingData/TKG3d/GTests/Geom_BezierSurface_Test.cxx @@ -682,4 +682,46 @@ TEST_F(Geom_BezierSurface_Test, SetPoleColWithWeights) EXPECT_TRUE(aSurf->Pole(1, 2).IsEqual(gp_Pnt(5, 0, 0), 1e-10)); EXPECT_DOUBLE_EQ(aSurf->Weight(1, 2), 3.0); EXPECT_DOUBLE_EQ(aSurf->Weight(2, 2), 4.0); -} \ No newline at end of file +} + +TEST_F(Geom_BezierSurface_Test, WeightsArray_NonRational_ReturnsUnitWeights) +{ + ASSERT_FALSE(myOriginalSurface->IsURational()); + ASSERT_FALSE(myOriginalSurface->IsVRational()); + + const NCollection_Array2& aWeights = myOriginalSurface->WeightsArray(); + EXPECT_EQ(aWeights.ColLength(), myOriginalSurface->NbUPoles()); + EXPECT_EQ(aWeights.RowLength(), myOriginalSurface->NbVPoles()); + EXPECT_FALSE(aWeights.IsDeletable()); + for (int i = aWeights.LowerRow(); i <= aWeights.UpperRow(); ++i) + { + for (int j = aWeights.LowerCol(); j <= aWeights.UpperCol(); ++j) + { + EXPECT_DOUBLE_EQ(aWeights(i, j), 1.0); + } + } + EXPECT_EQ(&aWeights, &myOriginalSurface->WeightsArray()); +} + +TEST_F(Geom_BezierSurface_Test, WeightsArray_Rational_ReturnsOwning) +{ + NCollection_Array2 aPoles(1, 2, 1, 2); + NCollection_Array2 aWeightsIn(1, 2, 1, 2); + aPoles(1, 1) = gp_Pnt(0, 0, 0); + aPoles(1, 2) = gp_Pnt(1, 0, 0); + aPoles(2, 1) = gp_Pnt(0, 1, 0); + aPoles(2, 2) = gp_Pnt(1, 1, 0); + aWeightsIn(1, 1) = 1.0; + aWeightsIn(1, 2) = 2.0; + aWeightsIn(2, 1) = 1.0; + aWeightsIn(2, 2) = 1.0; + + occ::handle aRational = new Geom_BezierSurface(aPoles, aWeightsIn); + + const NCollection_Array2& aWeights = aRational->WeightsArray(); + EXPECT_EQ(aWeights.Size(), 4); + EXPECT_TRUE(aWeights.IsDeletable()); + EXPECT_DOUBLE_EQ(aWeights(1, 2), 2.0); + EXPECT_DOUBLE_EQ(aWeights(1, 1), 1.0); + EXPECT_EQ(&aWeights, &aRational->WeightsArray()); +} diff --git a/src/ModelingData/TKG3d/Geom/Geom_BSplineCurve.cxx b/src/ModelingData/TKG3d/Geom/Geom_BSplineCurve.cxx index 72f2cd435e..025adb10ee 100644 --- a/src/ModelingData/TKG3d/Geom/Geom_BSplineCurve.cxx +++ b/src/ModelingData/TKG3d/Geom/Geom_BSplineCurve.cxx @@ -100,7 +100,8 @@ occ::handle Geom_BSplineCurve::Copy() const Geom_BSplineCurve::Geom_BSplineCurve(const Geom_BSplineCurve& theOther) : myPoles(theOther.myPoles), - myWeights(theOther.myWeights), + myWeights(theOther.myRational ? NCollection_Array1(theOther.myWeights) + : BSplCLib::UnitWeights(theOther.myPoles.Length())), myKnots(theOther.myKnots), myFlatKnots(theOther.myFlatKnots), myMults(theOther.myMults), @@ -137,6 +138,8 @@ Geom_BSplineCurve::Geom_BSplineCurve(const NCollection_Array1& Poles, myPoles.Resize(1, Poles.Length(), false); myPoles.Assign(Poles); + myWeights = BSplCLib::UnitWeights(Poles.Length()); + myKnots.Resize(1, Knots.Length(), false); myKnots.Assign(Knots); @@ -189,6 +192,10 @@ Geom_BSplineCurve::Geom_BSplineCurve(const NCollection_Array1& Poles, myWeights.Resize(1, Weights.Length(), false); myWeights.Assign(Weights); } + else + { + myWeights = BSplCLib::UnitWeights(Poles.Length()); + } myKnots.Resize(1, Knots.Length(), false); myKnots.Assign(Knots); @@ -246,11 +253,14 @@ void Geom_BSplineCurve::IncreaseDegree(const int Degree) myRational ? &nweights : BSplCLib::NoWeights(), nknots, nmults); - myDeg = Degree; - myPoles = std::move(npoles); - myWeights = std::move(nweights); - myKnots = std::move(nknots); - myMults = std::move(nmults); + myDeg = Degree; + myPoles = std::move(npoles); + if (IsRational()) + myWeights = std::move(nweights); + else + myWeights = BSplCLib::UnitWeights(myPoles.Length()); + myKnots = std::move(nknots); + myMults = std::move(nmults); updateKnots(); } @@ -350,10 +360,13 @@ void Geom_BSplineCurve::InsertKnots(const NCollection_Array1& Knots, nmults, Epsilon, Add); - myWeights = std::move(nweights); - myPoles = std::move(npoles); - myKnots = std::move(nknots); - myMults = std::move(nmults); + if (myRational) + myWeights = std::move(nweights); + else + myWeights = BSplCLib::UnitWeights(npoles.Length()); + myPoles = std::move(npoles); + myKnots = std::move(nknots); + myMults = std::move(nmults); updateKnots(); } @@ -410,10 +423,13 @@ bool Geom_BSplineCurve::RemoveKnot(const int Index, const int M, const double To return false; } - myWeights = std::move(nweights); - myPoles = std::move(npoles); - myKnots = std::move(nknots); - myMults = std::move(nmults); + if (IsRational()) + myWeights = std::move(nweights); + else + myWeights = BSplCLib::UnitWeights(npoles.Length()); + myPoles = std::move(npoles); + myKnots = std::move(nknots); + myMults = std::move(nmults); updateKnots(); myMaxDerivInvOk = false; @@ -608,9 +624,9 @@ void Geom_BSplineCurve::Segment(const double U1, const double U2, const double t myMults = std::move(nmults); myPoles = std::move(npoles); if (myRational) - { myWeights = std::move(nweights); - } + else + myWeights = BSplCLib::UnitWeights(myPoles.Length()); myMaxDerivInvOk = false; updateKnots(); @@ -692,6 +708,8 @@ void Geom_BSplineCurve::SetPeriodic() myPoles.Resize(1, nbp, true); if (myRational) myWeights.Resize(1, nbp, true); + else + myWeights = BSplCLib::UnitWeights(nbp); myPeriodic = true; @@ -775,6 +793,7 @@ void Geom_BSplineCurve::SetOrigin(const int Index) newpoles(k) = myPoles.Value(i); k++; } + myWeights = BSplCLib::UnitWeights(nbpoles); } myPoles = std::move(newpoles); @@ -864,8 +883,11 @@ void Geom_BSplineCurve::SetNotPeriodic() nknots, npoles, myRational ? &nweights : BSplCLib::NoWeights()); - myPoles = std::move(npoles); - myWeights = std::move(nweights); + myPoles = std::move(npoles); + if (IsRational()) + myWeights = std::move(nweights); + else + myWeights = BSplCLib::UnitWeights(myPoles.Length()); myMults = std::move(nmults); myKnots = std::move(nknots); myPeriodic = false; @@ -907,10 +929,10 @@ void Geom_BSplineCurve::SetWeight(const int Index, const double W) if (rat) { + // Becoming rational from non-rational: copy non-owning view to owned array. if (!IsRational()) { - myWeights.Resize(1, myPoles.Length(), false); - myWeights.Init(1.); + myWeights = NCollection_Array1(myWeights); } myWeights.SetValue(Index, W); @@ -919,10 +941,10 @@ void Geom_BSplineCurve::SetWeight(const int Index, const double W) { rat = Rational(myWeights); if (!rat) - myWeights = NCollection_Array1(); + myWeights = BSplCLib::UnitWeights(myPoles.Length()); } - myRational = myWeights.Size() > 0; + myRational = rat; } myMaxDerivInvOk = false; } @@ -1014,7 +1036,6 @@ void Geom_BSplineCurve::MovePointAndTangent(const double U, void Geom_BSplineCurve::updateKnots() { - myRational = myWeights.Size() > 0; myMaxDerivInvOk = false; int MaxKnotMult = 0; @@ -1093,7 +1114,7 @@ void Geom_BSplineCurve::DumpJson(Standard_OStream& theOStream, int theDepth) con if (myPoles.Size() > 0) OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myPoles.Size()) - if (myWeights.Size() > 0) + if (myRational) OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myWeights.Size()) if (myFlatKnots.Size() > 0) OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myFlatKnots.Size()) diff --git a/src/ModelingData/TKG3d/Geom/Geom_BSplineCurve.hxx b/src/ModelingData/TKG3d/Geom/Geom_BSplineCurve.hxx index 3d629545cc..2501f398eb 100644 --- a/src/ModelingData/TKG3d/Geom/Geom_BSplineCurve.hxx +++ b/src/ModelingData/TKG3d/Geom/Geom_BSplineCurve.hxx @@ -784,6 +784,13 @@ public: //! Returns the weights of the B-spline curve; Standard_EXPORT const NCollection_Array1* Weights() const; + //! Returns a const reference to the weights array. + //! For rational curves: the internal owning weights array. + //! For non-rational curves: a non-owning view of unit weights from BSplCLib. + //! The array is always sized to match NbPoles(). + //! @warning Do NOT modify elements through the returned reference. + const NCollection_Array1& WeightsArray() const { return myWeights; } + //! Applies the transformation T to this BSpline curve. Standard_EXPORT void Transform(const gp_Trsf& T) override; diff --git a/src/ModelingData/TKG3d/Geom/Geom_BSplineSurface.cxx b/src/ModelingData/TKG3d/Geom/Geom_BSplineSurface.cxx index e4101e85c4..f206c25a14 100644 --- a/src/ModelingData/TKG3d/Geom/Geom_BSplineSurface.cxx +++ b/src/ModelingData/TKG3d/Geom/Geom_BSplineSurface.cxx @@ -132,7 +132,10 @@ occ::handle Geom_BSplineSurface::Copy() const Geom_BSplineSurface::Geom_BSplineSurface(const Geom_BSplineSurface& theOther) : myPoles(theOther.myPoles), - myWeights(theOther.myWeights), + myWeights( + (theOther.myURational || theOther.myVRational) + ? NCollection_Array2(theOther.myWeights) + : BSplSLib::UnitWeights(theOther.myPoles.ColLength(), theOther.myPoles.RowLength())), myUKnots(theOther.myUKnots), myVKnots(theOther.myVKnots), myUFlatKnots(theOther.myUFlatKnots), @@ -187,6 +190,8 @@ Geom_BSplineSurface::Geom_BSplineSurface(const NCollection_Array2& Poles myPoles.Resize(1, Poles.ColLength(), 1, Poles.RowLength(), false); myPoles.Assign(Poles); + myWeights = BSplSLib::UnitWeights(Poles.ColLength(), Poles.RowLength()); + myUKnots.Resize(1, UKnots.Length(), false); myUKnots.Assign(UKnots); @@ -263,6 +268,10 @@ Geom_BSplineSurface::Geom_BSplineSurface(const NCollection_Array2& Poles myWeights.Resize(1, Poles.ColLength(), 1, Poles.RowLength(), false); myWeights.Assign(Weights); } + else + { + myWeights = BSplSLib::UnitWeights(Poles.ColLength(), Poles.RowLength()); + } myUKnots.Resize(1, UKnots.Length(), false); myUKnots.Assign(UKnots); @@ -312,6 +321,10 @@ void Geom_BSplineSurface::ExchangeUV() { myWeights = std::move(nweights); } + else + { + myWeights = BSplSLib::UnitWeights(myPoles.ColLength(), myPoles.RowLength()); + } std::swap(myURational, myVRational); std::swap(myUPeriodic, myVPeriodic); @@ -379,6 +392,7 @@ void Geom_BSplineSurface::IncreaseDegree(const int UDegree, const int VDegree) BSplSLib::NoWeights(), nknots, nmults); + myWeights = BSplSLib::UnitWeights(npoles.ColLength(), npoles.RowLength()); } myUDeg = UDegree; myPoles = std::move(npoles); @@ -439,6 +453,7 @@ void Geom_BSplineSurface::IncreaseDegree(const int UDegree, const int VDegree) BSplSLib::NoWeights(), nknots, nmults); + myWeights = BSplSLib::UnitWeights(npoles.ColLength(), npoles.RowLength()); } myVDeg = VDegree; myPoles = std::move(npoles); @@ -766,6 +781,7 @@ void Geom_BSplineSurface::segment(const double U1, } k++; } + myWeights = BSplSLib::UnitWeights(nbupoles, nbvpoles); } myUKnots = std::move(nuknots); @@ -1210,19 +1226,15 @@ void Geom_BSplineSurface::SetWeight(const int UIndex, const int VIndex, const do { throw Standard_OutOfRange("Geom_BSplineSurface::SetWeight: Index and #pole mismatch"); } - if (myWeights.Size() == 0) + if (!myURational && !myVRational) { - myWeights.Resize(myPoles.LowerRow(), - myPoles.UpperRow(), - myPoles.LowerCol(), - myPoles.UpperCol(), - false); - myWeights.Init(1.0); + // Make an owned copy of the unit weights view before modifying. + myWeights = NCollection_Array2(myWeights); } myWeights(UIndex + myWeights.LowerRow() - 1, VIndex + myWeights.LowerCol() - 1) = Weight; Rational(myWeights, myURational, myVRational); if (!myURational && !myVRational) - myWeights = NCollection_Array2(); + myWeights = BSplSLib::UnitWeights(myPoles.ColLength(), myPoles.RowLength()); myMaxDerivInvOk = false; } @@ -1240,14 +1252,10 @@ void Geom_BSplineSurface::SetWeightCol(const int VIndex, { throw Standard_ConstructionError("Geom_BSplineSurface::SetWeightCol: invalid array dimension"); } - if (myWeights.Size() == 0) + if (!myURational && !myVRational) { - myWeights.Resize(myPoles.LowerRow(), - myPoles.UpperRow(), - myPoles.LowerCol(), - myPoles.UpperCol(), - false); - myWeights.Init(1.0); + // Make an owned copy of the unit weights view before modifying. + myWeights = NCollection_Array2(myWeights); } int I = CPoleWeights.Lower(); while (I <= CPoleWeights.Upper()) @@ -1262,7 +1270,7 @@ void Geom_BSplineSurface::SetWeightCol(const int VIndex, // Verifie si c'est rationnel Rational(myWeights, myURational, myVRational); if (!myURational && !myVRational) - myWeights = NCollection_Array2(); + myWeights = BSplSLib::UnitWeights(myPoles.ColLength(), myPoles.RowLength()); myMaxDerivInvOk = false; } @@ -1281,14 +1289,10 @@ void Geom_BSplineSurface::SetWeightRow(const int UIndex, throw Standard_ConstructionError("Geom_BSplineSurface::SetWeightRow: invalid array dimension"); } - if (myWeights.Size() == 0) + if (!myURational && !myVRational) { - myWeights.Resize(myPoles.LowerRow(), - myPoles.UpperRow(), - myPoles.LowerCol(), - myPoles.UpperCol(), - false); - myWeights.Init(1.0); + // Make an owned copy of the unit weights view before modifying. + myWeights = NCollection_Array2(myWeights); } int I = CPoleWeights.Lower(); @@ -1304,7 +1308,7 @@ void Geom_BSplineSurface::SetWeightRow(const int UIndex, // Verifie si c'est rationnel Rational(myWeights, myURational, myVRational); if (!myURational && !myVRational) - myWeights = NCollection_Array2(); + myWeights = BSplSLib::UnitWeights(myPoles.ColLength(), myPoles.RowLength()); myMaxDerivInvOk = false; } diff --git a/src/ModelingData/TKG3d/Geom/Geom_BSplineSurface.hxx b/src/ModelingData/TKG3d/Geom/Geom_BSplineSurface.hxx index 508cbdfb96..9bf80e4f4a 100644 --- a/src/ModelingData/TKG3d/Geom/Geom_BSplineSurface.hxx +++ b/src/ModelingData/TKG3d/Geom/Geom_BSplineSurface.hxx @@ -1072,6 +1072,13 @@ public: Standard_DEPRECATED("use Weights() returning const pointer instead") Standard_EXPORT void Weights(NCollection_Array2& W) const; + //! Returns a const reference to the weights array. + //! For rational surfaces: the internal owning weights array. + //! For non-rational surfaces: a non-owning view of unit weights from BSplSLib. + //! The array is always sized to match NbUPoles() x NbVPoles(). + //! @warning Do NOT modify elements through the returned reference. + const NCollection_Array2& WeightsArray() const { return myWeights; } + //! Returns the weights of the B-spline surface. //! value and derivatives computation Standard_EXPORT const NCollection_Array2* Weights() const; diff --git a/src/ModelingData/TKG3d/Geom/Geom_BSplineSurface_1.cxx b/src/ModelingData/TKG3d/Geom/Geom_BSplineSurface_1.cxx index 36ce348da1..d7a045b20f 100644 --- a/src/ModelingData/TKG3d/Geom/Geom_BSplineSurface_1.cxx +++ b/src/ModelingData/TKG3d/Geom/Geom_BSplineSurface_1.cxx @@ -934,6 +934,10 @@ void Geom_BSplineSurface::SetUPeriodic() { myWeights.ResizeWithTrim(1, nbp, myWeights.LowerCol(), myWeights.UpperCol(), true); } + else + { + myWeights = BSplSLib::UnitWeights(nbp, myPoles.RowLength()); + } myUPeriodic = true; @@ -968,6 +972,10 @@ void Geom_BSplineSurface::SetVPeriodic() { myWeights.ResizeWithTrim(myWeights.LowerRow(), myWeights.UpperRow(), 1, nbp, true); } + else + { + myWeights = BSplSLib::UnitWeights(myPoles.ColLength(), nbp); + } myVPeriodic = true; @@ -1064,6 +1072,7 @@ void Geom_BSplineSurface::SetUOrigin(const int Index) } k++; } + myWeights = BSplSLib::UnitWeights(nbpoles, nbvp); } myPoles = std::move(newpoles); @@ -1161,6 +1170,7 @@ void Geom_BSplineSurface::SetVOrigin(const int Index) } k++; } + myWeights = BSplSLib::UnitWeights(nbup, nbpoles); } myPoles = std::move(newpoles); @@ -1212,6 +1222,7 @@ void Geom_BSplineSurface::SetUNotPeriodic() nknots, npoles, BSplSLib::NoWeights()); + myWeights = BSplSLib::UnitWeights(npoles.ColLength(), npoles.RowLength()); } myPoles = std::move(npoles); myUMults = std::move(nmults); @@ -1266,6 +1277,7 @@ void Geom_BSplineSurface::SetVNotPeriodic() nknots, npoles, BSplSLib::NoWeights()); + myWeights = BSplSLib::UnitWeights(npoles.ColLength(), npoles.RowLength()); } myPoles = std::move(npoles); myVMults = std::move(nmults); @@ -1816,6 +1828,7 @@ void Geom_BSplineSurface::InsertUKnots(const NCollection_Array1& Knots, nmults, ParametricTolerance, Add); + myWeights = BSplSLib::UnitWeights(npoles.ColLength(), npoles.RowLength()); } myPoles = std::move(npoles); @@ -1890,6 +1903,7 @@ void Geom_BSplineSurface::InsertVKnots(const NCollection_Array1& Knots, nmults, ParametricTolerance, Add); + myWeights = BSplSLib::UnitWeights(npoles.ColLength(), npoles.RowLength()); } myPoles = std::move(npoles); @@ -1962,6 +1976,7 @@ bool Geom_BSplineSurface::RemoveUKnot(const int Index, const int M, const double nmults, Tolerance)) return false; + myWeights = BSplSLib::UnitWeights(npoles.ColLength(), npoles.RowLength()); } myPoles = std::move(npoles); @@ -2037,6 +2052,7 @@ bool Geom_BSplineSurface::RemoveVKnot(const int Index, const int M, const double nmults, Tolerance)) return false; + myWeights = BSplSLib::UnitWeights(npoles.ColLength(), npoles.RowLength()); } myPoles = std::move(npoles); diff --git a/src/ModelingData/TKG3d/Geom/Geom_BezierCurve.cxx b/src/ModelingData/TKG3d/Geom/Geom_BezierCurve.cxx index 55e024da01..04b3976352 100644 --- a/src/ModelingData/TKG3d/Geom/Geom_BezierCurve.cxx +++ b/src/ModelingData/TKG3d/Geom/Geom_BezierCurve.cxx @@ -63,7 +63,8 @@ static bool Rational(const NCollection_Array1& W) Geom_BezierCurve::Geom_BezierCurve(const Geom_BezierCurve& theOther) : myPoles(theOther.myPoles), - myWeights(theOther.myWeights), + myWeights(theOther.myRational ? NCollection_Array1(theOther.myWeights) + : BSplCLib::UnitWeights(theOther.myPoles.Length())), myRational(theOther.myRational), myClosed(theOther.myClosed), myMaxDerivInvOk(false) @@ -410,9 +411,8 @@ void Geom_BezierCurve::SetWeight(const int Index, const double Weight) if (std::abs(Weight - 1.) <= gp::Resolution()) return; - // set weights of 1. - myWeights.Resize(1, nbpoles, false); - myWeights.Init(1.); + // Becoming rational: copy non-owning view to owned array. + myWeights = NCollection_Array1(myWeights); } myWeights(Index) = Weight; @@ -421,7 +421,7 @@ void Geom_BezierCurve::SetWeight(const int Index, const double Weight) if (wasrat && !Rational(myWeights)) { myRational = false; - myWeights = NCollection_Array1(); + myWeights = BSplCLib::UnitWeights(nbpoles); } else myRational = true; @@ -659,13 +659,13 @@ void Geom_BezierCurve::init(const NCollection_Array1& thePoles, myRational = Rational(myWeights); if (!myRational) { - myWeights = NCollection_Array1(); + myWeights = BSplCLib::UnitWeights(nbpoles); } } else { myRational = false; - myWeights = NCollection_Array1(); + myWeights = BSplCLib::UnitWeights(nbpoles); } myMaxDerivInv = 0.0; diff --git a/src/ModelingData/TKG3d/Geom/Geom_BezierCurve.hxx b/src/ModelingData/TKG3d/Geom/Geom_BezierCurve.hxx index e10485656f..ae14ead29e 100644 --- a/src/ModelingData/TKG3d/Geom/Geom_BezierCurve.hxx +++ b/src/ModelingData/TKG3d/Geom/Geom_BezierCurve.hxx @@ -299,6 +299,13 @@ public: return myRational ? &myWeights : BSplCLib::NoWeights(); } + //! Returns a const reference to the weights array. + //! For rational curves: the internal owning weights array. + //! For non-rational curves: a non-owning view of unit weights from BSplCLib. + //! The array is always sized to match NbPoles(). + //! @warning Do NOT modify elements through the returned reference. + const NCollection_Array1& WeightsArray() const { return myWeights; } + //! Applies the transformation T to this Bezier curve. Standard_EXPORT void Transform(const gp_Trsf& T) override; diff --git a/src/ModelingData/TKG3d/Geom/Geom_BezierSurface.cxx b/src/ModelingData/TKG3d/Geom/Geom_BezierSurface.cxx index a94674e50a..8d19e093af 100644 --- a/src/ModelingData/TKG3d/Geom/Geom_BezierSurface.cxx +++ b/src/ModelingData/TKG3d/Geom/Geom_BezierSurface.cxx @@ -359,7 +359,10 @@ static void DeleteRatPoleRow(const NCollection_Array2& Poles, Geom_BezierSurface::Geom_BezierSurface(const Geom_BezierSurface& theOther) : myPoles(theOther.myPoles), - myWeights(theOther.myWeights), + myWeights( + (theOther.myURational || theOther.myVRational) + ? NCollection_Array2(theOther.myWeights) + : BSplSLib::UnitWeights(theOther.myPoles.ColLength(), theOther.myPoles.RowLength())), myURational(theOther.myURational), myVRational(theOther.myVRational), myUMaxDerivInv(theOther.myUMaxDerivInv), @@ -494,6 +497,10 @@ void Geom_BezierSurface::ExchangeUV() { myWeights = std::move(nweights); } + else + { + myWeights = BSplSLib::UnitWeights(UC - LC + 1, UR - LR + 1); + } std::swap(myURational, myVRational); myMaxDerivInvOk = false; @@ -607,9 +614,13 @@ void Geom_BezierSurface::Increase(const int UDeg, const int VDeg) Rational(myWeights, myURational, myVRational); if (!(myURational || myVRational)) { - myWeights = NCollection_Array2(); + myWeights = BSplSLib::UnitWeights(myPoles.ColLength(), myPoles.RowLength()); } } + else + { + myWeights = BSplSLib::UnitWeights(myPoles.ColLength(), myPoles.RowLength()); + } myMaxDerivInvOk = false; } @@ -642,6 +653,7 @@ void Geom_BezierSurface::InsertPoleColAfter(const int VI else { AddPoleCol(myPoles, CPoles, VIndex, npoles); + myWeights = BSplSLib::UnitWeights(NbUPoles, NbVPoles + 1); } myPoles = std::move(npoles); myMaxDerivInvOk = false; @@ -672,11 +684,10 @@ void Geom_BezierSurface::InsertPoleColAfter(const int VI int NbUPoles = myPoles.ColLength(); int NbVPoles = myPoles.RowLength(); - // Ensure weights exist for rational insertion + // Ensure weights are an owned copy for rational insertion if (!(myURational || myVRational)) { - myWeights.Resize(1, NbUPoles, 1, NbVPoles, false); - myWeights.Init(1.0); + myWeights = NCollection_Array2(myWeights); } NCollection_Array2 npoles(1, NbUPoles, 1, NbVPoles + 1); @@ -688,6 +699,10 @@ void Geom_BezierSurface::InsertPoleColAfter(const int VI myWeights = std::move(nweights); Rational(myWeights, myURational, myVRational); + if (!(myURational || myVRational)) + { + myWeights = BSplSLib::UnitWeights(myPoles.ColLength(), myPoles.RowLength()); + } myMaxDerivInvOk = false; } @@ -737,6 +752,7 @@ void Geom_BezierSurface::InsertPoleRowAfter(const int UI else { AddPoleRow(myPoles, CPoles, UIndex, npoles); + myWeights = BSplSLib::UnitWeights(NbUPoles + 1, NbVPoles); } myPoles = std::move(npoles); myMaxDerivInvOk = false; @@ -767,11 +783,10 @@ void Geom_BezierSurface::InsertPoleRowAfter(const int UI int NbUPoles = myPoles.ColLength(); int NbVPoles = myPoles.RowLength(); - // Ensure weights exist for rational insertion + // Ensure weights are an owned copy for rational insertion if (!(myURational || myVRational)) { - myWeights.Resize(1, NbUPoles, 1, NbVPoles, false); - myWeights.Init(1.0); + myWeights = NCollection_Array2(myWeights); } NCollection_Array2 npoles(1, NbUPoles + 1, 1, NbVPoles); @@ -783,6 +798,10 @@ void Geom_BezierSurface::InsertPoleRowAfter(const int UI myWeights = std::move(nweights); Rational(myWeights, myURational, myVRational); + if (!(myURational || myVRational)) + { + myWeights = BSplSLib::UnitWeights(myPoles.ColLength(), myPoles.RowLength()); + } myMaxDerivInvOk = false; } @@ -825,11 +844,12 @@ void Geom_BezierSurface::RemovePoleCol(const int VIndex) if (myURational || myVRational) myWeights = std::move(nweights); else - myWeights = NCollection_Array2(); + myWeights = BSplSLib::UnitWeights(NbUPoles, NbVPoles - 1); } else { DeletePoleCol(myPoles, VIndex, npoles); + myWeights = BSplSLib::UnitWeights(NbUPoles, NbVPoles - 1); } myPoles = std::move(npoles); myMaxDerivInvOk = false; @@ -858,11 +878,12 @@ void Geom_BezierSurface::RemovePoleRow(const int UIndex) if (myURational || myVRational) myWeights = std::move(nweights); else - myWeights = NCollection_Array2(); + myWeights = BSplSLib::UnitWeights(NbUPoles - 1, NbVPoles); } else { DeletePoleRow(myPoles, UIndex, npoles); + myWeights = BSplSLib::UnitWeights(NbUPoles - 1, NbVPoles); } myPoles = std::move(npoles); myMaxDerivInvOk = false; @@ -1098,9 +1119,8 @@ void Geom_BezierSurface::SetWeight(const int UIndex, const int VIndex, const dou if (std::abs(Weight - 1.) <= gp::Resolution()) return; - // set weights of 1. - myWeights.Resize(1, myPoles.ColLength(), 1, myPoles.RowLength(), false); - myWeights.Init(1.); + // owned copy from non-owning view + myWeights = NCollection_Array2(myWeights); } if (std::abs(Weight - myWeights(UIndex, VIndex)) > gp::Resolution()) @@ -1109,7 +1129,7 @@ void Geom_BezierSurface::SetWeight(const int UIndex, const int VIndex, const dou Rational(myWeights, myURational, myVRational); if (!(myURational || myVRational)) { - myWeights = NCollection_Array2(); + myWeights = BSplSLib::UnitWeights(myPoles.ColLength(), myPoles.RowLength()); } } myMaxDerivInvOk = false; @@ -1133,9 +1153,8 @@ void Geom_BezierSurface::SetWeightCol(const int VIndex, bool wasrat = (myURational || myVRational); if (!wasrat) { - // set weights of 1. - myWeights.Resize(1, myPoles.ColLength(), 1, myPoles.RowLength(), false); - myWeights.Init(1.); + // owned copy from non-owning view + myWeights = NCollection_Array2(myWeights); } I = CPoleWeights.Lower(); @@ -1152,7 +1171,7 @@ void Geom_BezierSurface::SetWeightCol(const int VIndex, Rational(myWeights, myURational, myVRational); if (!(myURational || myVRational)) { - myWeights = NCollection_Array2(); + myWeights = BSplSLib::UnitWeights(myPoles.ColLength(), myPoles.RowLength()); } myMaxDerivInvOk = false; } @@ -1175,9 +1194,8 @@ void Geom_BezierSurface::SetWeightRow(const int UIndex, bool wasrat = (myURational || myVRational); if (!wasrat) { - // set weights of 1. - myWeights.Resize(1, myPoles.ColLength(), 1, myPoles.RowLength(), false); - myWeights.Init(1.); + // owned copy from non-owning view + myWeights = NCollection_Array2(myWeights); } I = CPoleWeights.Lower(); @@ -1194,7 +1212,7 @@ void Geom_BezierSurface::SetWeightRow(const int UIndex, Rational(myWeights, myURational, myVRational); if (!(myURational || myVRational)) { - myWeights = NCollection_Array2(); + myWeights = BSplSLib::UnitWeights(myPoles.ColLength(), myPoles.RowLength()); } myMaxDerivInvOk = false; } @@ -1922,14 +1940,14 @@ void Geom_BezierSurface::init(const NCollection_Array2& thePoles, Rational(myWeights, myURational, myVRational); if (!(myURational || myVRational)) { - myWeights = NCollection_Array2(); + myWeights = BSplSLib::UnitWeights(NbUPoles, NbVPoles); } } else { myURational = false; myVRational = false; - myWeights = NCollection_Array2(); + myWeights = BSplSLib::UnitWeights(NbUPoles, NbVPoles); } myMaxDerivInvOk = false; diff --git a/src/ModelingData/TKG3d/Geom/Geom_BezierSurface.hxx b/src/ModelingData/TKG3d/Geom/Geom_BezierSurface.hxx index 6e0d6b5caa..9cbacf7e3f 100644 --- a/src/ModelingData/TKG3d/Geom/Geom_BezierSurface.hxx +++ b/src/ModelingData/TKG3d/Geom/Geom_BezierSurface.hxx @@ -535,6 +535,13 @@ public: return (myURational || myVRational) ? &myWeights : BSplSLib::NoWeights(); } + //! Returns a const reference to the weights array. + //! For rational surfaces: the internal owning weights array. + //! For non-rational surfaces: a non-owning view of unit weights from BSplSLib. + //! The array is always sized to match NbUPoles() x NbVPoles(). + //! @warning Do NOT modify elements through the returned reference. + const NCollection_Array2& WeightsArray() const { return myWeights; } + //! Returns True if the first control points row and the //! last control points row are identical. The tolerance //! criterion is Resolution from package gp. diff --git a/src/ModelingData/TKG3d/GeomAdaptor/GeomAdaptor_Surface.cxx b/src/ModelingData/TKG3d/GeomAdaptor/GeomAdaptor_Surface.cxx index b2211c8adf..c3a193d167 100644 --- a/src/ModelingData/TKG3d/GeomAdaptor/GeomAdaptor_Surface.cxx +++ b/src/ModelingData/TKG3d/GeomAdaptor/GeomAdaptor_Surface.cxx @@ -463,11 +463,8 @@ GeomAbs_Shape GeomAdaptor_Surface::UContinuity() const { case GeomAbs_BSplineSurface: { const auto& aBSpl = std::get(mySurfaceData).Surface; - const int N = aBSpl->NbUKnots(); - NCollection_Array1 TK(1, N); - NCollection_Array1 TM(1, N); - aBSpl->UKnots(TK); - aBSpl->UMultiplicities(TM); + NCollection_Array1 TK(aBSpl->UKnots()); + NCollection_Array1 TM(aBSpl->UMultiplicities()); return LocalContinuity(aBSpl->UDegree(), aBSpl->NbUKnots(), TK, @@ -521,11 +518,8 @@ GeomAbs_Shape GeomAdaptor_Surface::VContinuity() const { case GeomAbs_BSplineSurface: { const auto& aBSpl = std::get(mySurfaceData).Surface; - const int N = aBSpl->NbVKnots(); - NCollection_Array1 TK(1, N); - NCollection_Array1 TM(1, N); - aBSpl->VKnots(TK); - aBSpl->VMultiplicities(TM); + NCollection_Array1 TK(aBSpl->VKnots()); + NCollection_Array1 TM(aBSpl->VMultiplicities()); return LocalContinuity(aBSpl->VDegree(), aBSpl->NbVKnots(), TK, diff --git a/src/ModelingData/TKGeomBase/BndLib/BndLib_Add3dCurve.cxx b/src/ModelingData/TKGeomBase/BndLib/BndLib_Add3dCurve.cxx index 247f673d43..618b7a8dce 100644 --- a/src/ModelingData/TKGeomBase/BndLib/BndLib_Add3dCurve.cxx +++ b/src/ModelingData/TKGeomBase/BndLib/BndLib_Add3dCurve.cxx @@ -238,12 +238,10 @@ void BndLib_Add3dCurve::Add(const Adaptor3d_Curve& C, } // OCC566(apo)-> Bnd_Box B1; - int k, k1 = Bs->FirstUKnotIndex(), k2 = Bs->LastUKnotIndex(), N = Bs->Degree(), - NbKnots = Bs->NbKnots(); - NCollection_Array1 Knots(1, NbKnots); - Bs->Knots(Knots); - GeomAdaptor_Curve GACurve(Bs); - double first = Knots(k1), last; + int k, k1 = Bs->FirstUKnotIndex(), k2 = Bs->LastUKnotIndex(), N = Bs->Degree(); + const NCollection_Array1& Knots = Bs->Knots(); + GeomAdaptor_Curve GACurve(Bs); + double first = Knots(k1), last; for (k = k1 + 1; k <= k2; k++) { last = Knots(k); diff --git a/src/ModelingData/TKGeomBase/BndLib/BndLib_AddSurface.cxx b/src/ModelingData/TKGeomBase/BndLib/BndLib_AddSurface.cxx index b482fc119b..c3c08b7971 100644 --- a/src/ModelingData/TKGeomBase/BndLib/BndLib_AddSurface.cxx +++ b/src/ModelingData/TKGeomBase/BndLib/BndLib_AddSurface.cxx @@ -361,7 +361,7 @@ void BndLib_AddSurface::Add(const Adaptor3d_Surface& S, bool isUPeriodic = S.IsUPeriodic(), isVPeriodic = S.IsVPeriodic(); if (Type == GeomAbs_BezierSurface) { - S.Bezier()->Poles(Tp); + Tp = S.Bezier()->Poles(); UMinIdx = 1; UMaxIdx = aNbUPoles; VMinIdx = 1; @@ -369,7 +369,7 @@ void BndLib_AddSurface::Add(const Adaptor3d_Surface& S, } else { - aBS->Poles(Tp); + Tp = aBS->Poles(); UMinIdx = 1; UMaxIdx = aNbUPoles; @@ -378,10 +378,8 @@ void BndLib_AddSurface::Add(const Adaptor3d_Surface& S, if (UMin > anUMinParam || UMax < anUMaxParam) { - NCollection_Array1 aMults(1, aBS->NbUKnots()); - NCollection_Array1 aKnots(1, aBS->NbUKnots()); - aBS->UKnots(aKnots); - aBS->UMultiplicities(aMults); + const NCollection_Array1& aMults = aBS->UMultiplicities(); + const NCollection_Array1& aKnots = aBS->UKnots(); ComputePolesIndexes(aKnots, aMults, @@ -396,10 +394,8 @@ void BndLib_AddSurface::Add(const Adaptor3d_Surface& S, if (VMin > aVMinParam || VMax < aVMaxParam) { - NCollection_Array1 aMults(1, aBS->NbVKnots()); - NCollection_Array1 aKnots(1, aBS->NbVKnots()); - aBS->VKnots(aKnots); - aBS->VMultiplicities(aMults); + const NCollection_Array1& aMults = aBS->VMultiplicities(); + const NCollection_Array1& aKnots = aBS->VKnots(); ComputePolesIndexes(aKnots, aMults, diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_GGExtPC.hxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_GGExtPC.hxx index 81ceb71930..28f14826ee 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_GGExtPC.hxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_GGExtPC.hxx @@ -188,10 +188,10 @@ public: return; } case GeomAbs_BSplineCurve: { - const int aFirstIdx = TheCurveTool::BSpline(aCurve)->FirstUKnotIndex(), - aLastIdx = TheCurveTool::BSpline(aCurve)->LastUKnotIndex(); - NCollection_Array1 aKnots(aFirstIdx, aLastIdx); - TheCurveTool::BSpline(aCurve)->Knots(aKnots); + auto aBSpline = TheCurveTool::BSpline(aCurve); + const int aFirstIdx = aBSpline->FirstUKnotIndex(); + const int aLastIdx = aBSpline->LastUKnotIndex(); + const NCollection_Array1& aKnots = aBSpline->Knots(); double aPeriodJump = 0.0; const double aTolCoeff = (myusup - myuinf) * Precision::PConfusion(); @@ -228,7 +228,7 @@ public: aLastUsedKnot = aFirstIdx + 1; } - mysample = (TheCurveTool::BSpline(aCurve))->Degree() + 1; + mysample = aBSpline->Degree() + 1; if (mysample == 2) { diff --git a/src/ModelingData/TKGeomBase/Extrema/Extrema_GenExtPS.cxx b/src/ModelingData/TKGeomBase/Extrema/Extrema_GenExtPS.cxx index e29a1548c8..ce743abb00 100644 --- a/src/ModelingData/TKGeomBase/Extrema/Extrema_GenExtPS.cxx +++ b/src/ModelingData/TKGeomBase/Extrema/Extrema_GenExtPS.cxx @@ -370,10 +370,8 @@ void Extrema_GenExtPS::GetGridPoints(const Adaptor3d_Surface& theSurf) occ::handle aBspl = theSurf.BSpline(); if (!aBspl.IsNull()) { - NCollection_Array1 aUKnots(1, aBspl->NbUKnots()); - aBspl->UKnots(aUKnots); - NCollection_Array1 aVKnots(1, aBspl->NbVKnots()); - aBspl->VKnots(aVKnots); + const NCollection_Array1& aUKnots = aBspl->UKnots(); + const NCollection_Array1& aVKnots = aBspl->VKnots(); fillParams(aUKnots, aBspl->UDegree(), myumin, myusup, myUParams, myusample); fillParams(aVKnots, aBspl->VDegree(), myvmin, myvsup, myVParams, myvsample); } @@ -402,9 +400,8 @@ void Extrema_GenExtPS::GetGridPoints(const Adaptor3d_Surface& theSurf) occ::handle aBspl = theSurf.BasisCurve()->BSpline(); if (!aBspl.IsNull()) { - anArrKnots = new NCollection_HArray1(1, aBspl->NbKnots()); - aBspl->Knots(anArrKnots->ChangeArray1()); - aDegree = aBspl->Degree(); + anArrKnots = new NCollection_HArray1(aBspl->Knots()); + aDegree = aBspl->Degree(); } } if (theSurf.BasisCurve()->GetType() == GeomAbs_BezierCurve) diff --git a/src/ModelingData/TKGeomBase/GTests/FILES.cmake b/src/ModelingData/TKGeomBase/GTests/FILES.cmake index c091f03ef0..d7f8d2ea5b 100644 --- a/src/ModelingData/TKGeomBase/GTests/FILES.cmake +++ b/src/ModelingData/TKGeomBase/GTests/FILES.cmake @@ -5,5 +5,6 @@ set(OCCT_TKGeomBase_GTests_FILES BndLib_Test.cxx Extrema_ExtPC_Test.cxx GeomConvert_CompCurveToBSplineCurve_Test.cxx + Hermit_Test.cxx IntAna_IntQuadQuad_Test.cxx ) diff --git a/src/ModelingData/TKGeomBase/GTests/Hermit_Test.cxx b/src/ModelingData/TKGeomBase/GTests/Hermit_Test.cxx new file mode 100644 index 0000000000..37f3d046e6 --- /dev/null +++ b/src/ModelingData/TKGeomBase/GTests/Hermit_Test.cxx @@ -0,0 +1,252 @@ +// Copyright (c) 2025 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +#include + +#include +#include +#include +#include +#include +#include + +// Helper to create a simple rational BSpline curve (degree 2, 3 poles) +// with weights that produce distinct endpoint weight values. +static Handle(Geom_BSplineCurve) MakeRationalBSpline3D(const double theW1, + const double theW2, + const double theW3) +{ + NCollection_Array1 aPoles(1, 3); + aPoles(1) = gp_Pnt(0.0, 0.0, 0.0); + aPoles(2) = gp_Pnt(1.0, 1.0, 0.0); + aPoles(3) = gp_Pnt(2.0, 0.0, 0.0); + + NCollection_Array1 aWeights(1, 3); + aWeights(1) = theW1; + aWeights(2) = theW2; + aWeights(3) = theW3; + + NCollection_Array1 aKnots(1, 2); + aKnots(1) = 0.0; + aKnots(2) = 1.0; + + NCollection_Array1 aMults(1, 2); + aMults(1) = 3; + aMults(2) = 3; + + return new Geom_BSplineCurve(aPoles, aWeights, aKnots, aMults, 2); +} + +// Helper to create a simple rational BSpline 2D curve (degree 2, 3 poles). +static Handle(Geom2d_BSplineCurve) MakeRationalBSpline2D(const double theW1, + const double theW2, + const double theW3) +{ + NCollection_Array1 aPoles(1, 3); + aPoles(1) = gp_Pnt2d(0.0, 0.0); + aPoles(2) = gp_Pnt2d(1.0, 1.0); + aPoles(3) = gp_Pnt2d(2.0, 0.0); + + NCollection_Array1 aWeights(1, 3); + aWeights(1) = theW1; + aWeights(2) = theW2; + aWeights(3) = theW3; + + NCollection_Array1 aKnots(1, 2); + aKnots(1) = 0.0; + aKnots(2) = 1.0; + + NCollection_Array1 aMults(1, 2); + aMults(1) = 3; + aMults(2) = 3; + + return new Geom2d_BSplineCurve(aPoles, aWeights, aKnots, aMults, 2); +} + +TEST(HermitTest, Solution3D_UniformWeights_ReturnsValidCurve) +{ + // Uniform weights => weight function is constant 1.0 everywhere + Handle(Geom_BSplineCurve) aBS = MakeRationalBSpline3D(1.0, 1.0, 1.0); + + Handle(Geom2d_BSplineCurve) aResult = Hermit::Solution(aBS); + + ASSERT_FALSE(aResult.IsNull()); + EXPECT_GE(aResult->NbPoles(), 4); + + // The result a(u) * D(u) should have value 1 at endpoints + // For uniform weights D(u)=1 everywhere, so a(0)=1, a(1)=1 + const gp_Pnt2d aP0 = aResult->Value(aResult->FirstParameter()); + const gp_Pnt2d aP1 = aResult->Value(aResult->LastParameter()); + + EXPECT_NEAR(aP0.Y(), 1.0, 1.0e-6); + EXPECT_NEAR(aP1.Y(), 1.0, 1.0e-6); +} + +TEST(HermitTest, Solution3D_DistinctWeights_ReturnsValidCurve) +{ + // Different weights at endpoints: w(0)=2, w(1)=3 + Handle(Geom_BSplineCurve) aBS = MakeRationalBSpline3D(2.0, 1.5, 3.0); + + Handle(Geom2d_BSplineCurve) aResult = Hermit::Solution(aBS); + + ASSERT_FALSE(aResult.IsNull()); + + // a(0) should be 1/w(0) = 0.5, a(1) should be 1/w(1) = 1/3 + const gp_Pnt2d aP0 = aResult->Value(aResult->FirstParameter()); + const gp_Pnt2d aP1 = aResult->Value(aResult->LastParameter()); + + EXPECT_NEAR(aP0.Y(), 0.5, 1.0e-4); + EXPECT_NEAR(aP1.Y(), 1.0 / 3.0, 1.0e-4); +} + +TEST(HermitTest, Solution3D_HighWeightRatio_Endpoint) +{ + // Large weight ratio: w(0) small, w(1) large - tests the Pole0 < Pole3 branch + Handle(Geom_BSplineCurve) aBS = MakeRationalBSpline3D(0.5, 1.0, 5.0); + + Handle(Geom2d_BSplineCurve) aResult = Hermit::Solution(aBS); + + ASSERT_FALSE(aResult.IsNull()); + + const gp_Pnt2d aP0 = aResult->Value(aResult->FirstParameter()); + const gp_Pnt2d aP1 = aResult->Value(aResult->LastParameter()); + + // a(u)*D(u) = 1 at endpoints => a(0) = 1/w(0) = 2, a(1) = 1/w(1) = 0.2 + EXPECT_NEAR(aP0.Y(), 1.0 / 0.5, 1.0e-4); + EXPECT_NEAR(aP1.Y(), 1.0 / 5.0, 1.0e-4); +} + +TEST(HermitTest, Solution3D_ReversedWeightRatio_Endpoint) +{ + // Reversed ratio: w(0) large, w(1) small - tests the Pole0 > Pole3 branch + Handle(Geom_BSplineCurve) aBS = MakeRationalBSpline3D(5.0, 1.0, 0.5); + + Handle(Geom2d_BSplineCurve) aResult = Hermit::Solution(aBS); + + ASSERT_FALSE(aResult.IsNull()); + + const gp_Pnt2d aP0 = aResult->Value(aResult->FirstParameter()); + const gp_Pnt2d aP1 = aResult->Value(aResult->LastParameter()); + + EXPECT_NEAR(aP0.Y(), 1.0 / 5.0, 1.0e-4); + EXPECT_NEAR(aP1.Y(), 1.0 / 0.5, 1.0e-4); +} + +TEST(HermitTest, Solution3D_PositivePoles) +{ + // The result curve should have all positive Y coordinates (positive denominator) + Handle(Geom_BSplineCurve) aBS = MakeRationalBSpline3D(2.0, 3.0, 1.5); + + Handle(Geom2d_BSplineCurve) aResult = Hermit::Solution(aBS); + + ASSERT_FALSE(aResult.IsNull()); + for (int i = 1; i <= aResult->NbPoles(); ++i) + { + EXPECT_GT(aResult->Pole(i).Y(), 0.0) << "Pole " << i << " Y should be positive"; + } +} + +TEST(HermitTest, Solution2D_UniformWeights_ReturnsValidCurve) +{ + Handle(Geom2d_BSplineCurve) aBS = MakeRationalBSpline2D(1.0, 1.0, 1.0); + + Handle(Geom2d_BSplineCurve) aResult = Hermit::Solution(aBS); + + ASSERT_FALSE(aResult.IsNull()); + + const gp_Pnt2d aP0 = aResult->Value(aResult->FirstParameter()); + const gp_Pnt2d aP1 = aResult->Value(aResult->LastParameter()); + + EXPECT_NEAR(aP0.Y(), 1.0, 1.0e-6); + EXPECT_NEAR(aP1.Y(), 1.0, 1.0e-6); +} + +TEST(HermitTest, Solution2D_DistinctWeights_ReturnsValidCurve) +{ + Handle(Geom2d_BSplineCurve) aBS = MakeRationalBSpline2D(2.0, 1.5, 3.0); + + Handle(Geom2d_BSplineCurve) aResult = Hermit::Solution(aBS); + + ASSERT_FALSE(aResult.IsNull()); + + const gp_Pnt2d aP0 = aResult->Value(aResult->FirstParameter()); + const gp_Pnt2d aP1 = aResult->Value(aResult->LastParameter()); + + EXPECT_NEAR(aP0.Y(), 0.5, 1.0e-4); + EXPECT_NEAR(aP1.Y(), 1.0 / 3.0, 1.0e-4); +} + +TEST(HermitTest, Solution2D_HighWeightRatio_Endpoint) +{ + // Large ratio tests the Pole0 < Pole3 branch in 2D PolyTest + Handle(Geom2d_BSplineCurve) aBS = MakeRationalBSpline2D(0.5, 1.0, 5.0); + + Handle(Geom2d_BSplineCurve) aResult = Hermit::Solution(aBS); + + ASSERT_FALSE(aResult.IsNull()); + + const gp_Pnt2d aP0 = aResult->Value(aResult->FirstParameter()); + const gp_Pnt2d aP1 = aResult->Value(aResult->LastParameter()); + + EXPECT_NEAR(aP0.Y(), 1.0 / 0.5, 1.0e-4); + EXPECT_NEAR(aP1.Y(), 1.0 / 5.0, 1.0e-4); +} + +TEST(HermitTest, Solutionbis_UniformWeights_KnotsUnchanged) +{ + Handle(Geom_BSplineCurve) aBS = MakeRationalBSpline3D(1.0, 1.0, 1.0); + + double aKnotmin = 0.0; + double aKnotmax = 1.0; + + Hermit::Solutionbis(aBS, aKnotmin, aKnotmax); + + // For uniform weights, the Hermite coefficients are trivial (1,0,0,1) + // and no tolerance knots are needed, so the output knots should be + // the second and second-to-last of the resulting BS2 + EXPECT_GE(aKnotmin, 0.0); + EXPECT_LE(aKnotmax, 1.0); +} + +TEST(HermitTest, Solutionbis_DistinctWeights_ReturnsValidKnots) +{ + Handle(Geom_BSplineCurve) aBS = MakeRationalBSpline3D(2.0, 1.5, 3.0); + + double aKnotmin = 0.0; + double aKnotmax = 1.0; + + Hermit::Solutionbis(aBS, aKnotmin, aKnotmax); + + EXPECT_GE(aKnotmin, 0.0); + EXPECT_LE(aKnotmax, 1.0); + EXPECT_LE(aKnotmin, aKnotmax); +} + +TEST(HermitTest, Solution3D_Symmetric_WeightsProduceSymmetricResult) +{ + // Symmetric weights: w(0) == w(1), so a(0) == a(1) + Handle(Geom_BSplineCurve) aBS = MakeRationalBSpline3D(2.0, 1.0, 2.0); + + Handle(Geom2d_BSplineCurve) aResult = Hermit::Solution(aBS); + + ASSERT_FALSE(aResult.IsNull()); + + const gp_Pnt2d aP0 = aResult->Value(aResult->FirstParameter()); + const gp_Pnt2d aP1 = aResult->Value(aResult->LastParameter()); + + // Both endpoints should yield the same value: 1/w = 0.5 + EXPECT_NEAR(aP0.Y(), 0.5, 1.0e-4); + EXPECT_NEAR(aP1.Y(), 0.5, 1.0e-4); +} diff --git a/src/ModelingData/TKGeomBase/Geom2dConvert/Geom2dConvert.cxx b/src/ModelingData/TKGeomBase/Geom2dConvert/Geom2dConvert.cxx index 61e52f1751..127fbfd326 100644 --- a/src/ModelingData/TKGeomBase/Geom2dConvert/Geom2dConvert.cxx +++ b/src/ModelingData/TKGeomBase/Geom2dConvert/Geom2dConvert.cxx @@ -310,21 +310,17 @@ occ::handle Geom2dConvert::CurveToBSplineCurve( occ::handle CBez = occ::down_cast(Curv->Copy()); CBez->Segment(U1, U2); - int NbPoles = CBez->NbPoles(); - int Degree = CBez->Degree(); - Array1OfPnt2d Poles(1, NbPoles); + int Degree = CBez->Degree(); Array1OfReal Knots(1, 2); Array1OfInteger Mults(1, 2); - Knots(1) = 0.0; - Knots(2) = 1.0; - Mults(1) = Degree + 1; - Mults(2) = Degree + 1; - CBez->Poles(Poles); + Knots(1) = 0.0; + Knots(2) = 1.0; + Mults(1) = Degree + 1; + Mults(2) = Degree + 1; + const Array1OfPnt2d& Poles = CBez->Poles(); if (CBez->IsRational()) { - Array1OfReal Weights(1, NbPoles); - CBez->Weights(Weights); - TheCurve = new BSplineCurve(Poles, Weights, Knots, Mults, Degree); + TheCurve = new BSplineCurve(Poles, CBez->WeightsArray(), Knots, Mults, Degree); } else { @@ -384,21 +380,17 @@ occ::handle Geom2dConvert::CurveToBSplineCurve( { occ::handle CBez = occ::down_cast(C); - int NbPoles = CBez->NbPoles(); - int Degree = CBez->Degree(); - Array1OfPnt2d Poles(1, NbPoles); + int Degree = CBez->Degree(); Array1OfReal Knots(1, 2); Array1OfInteger Mults(1, 2); - Knots(1) = 0.0; - Knots(2) = 1.0; - Mults(1) = Degree + 1; - Mults(2) = Degree + 1; - CBez->Poles(Poles); + Knots(1) = 0.0; + Knots(2) = 1.0; + Mults(1) = Degree + 1; + Mults(2) = Degree + 1; + const Array1OfPnt2d& Poles = CBez->Poles(); if (CBez->IsRational()) { - Array1OfReal Weights(1, NbPoles); - CBez->Weights(Weights); - TheCurve = new BSplineCurve(Poles, Weights, Knots, Mults, Degree); + TheCurve = new BSplineCurve(Poles, CBez->WeightsArray(), Knots, Mults, Degree); } else { @@ -474,32 +466,24 @@ static occ::handle MultNumandDenom(const occ::handle& BS) { - NCollection_Array1 aKnots(1, a->NbKnots()); - NCollection_Array1 BSKnots(1, BS->NbKnots()); - NCollection_Array1 BSFlatKnots(1, BS->NbPoles() + BS->Degree() + 1); - NCollection_Array1 BSWeights(1, BS->NbPoles()); - NCollection_Array1 aMults(1, a->NbKnots()); - NCollection_Array1 BSMults(1, BS->NbKnots()); - NCollection_Array1 aPoles(1, a->NbPoles()); - NCollection_Array1 BSPoles(1, BS->NbPoles()); occ::handle res; occ::handle> resKnots; occ::handle> resMults; double start_value, end_value; int resNbPoles, degree, ii, jj, aStatus; - BS->Knots(BSKnots); - BS->Multiplicities(BSMults); - BS->Poles(BSPoles); - BS->Weights(BSWeights); - BS->KnotSequence(BSFlatKnots); - start_value = BSKnots(1); - end_value = BSKnots(BS->NbKnots()); - double tolerance = 10. * Epsilon(std::abs(end_value)); + const NCollection_Array1& BSKnots = BS->Knots(); + const NCollection_Array1& BSMults = BS->Multiplicities(); + NCollection_Array1 BSPoles(BS->Poles()); + const NCollection_Array1& BSWeights = BS->WeightsArray(); + const NCollection_Array1& BSFlatKnots = BS->KnotSequence(); + start_value = BSKnots(1); + end_value = BSKnots(BS->NbKnots()); + double tolerance = 10. * Epsilon(std::abs(end_value)); - a->Knots(aKnots); - a->Poles(aPoles); - a->Multiplicities(aMults); + NCollection_Array1 aKnots(a->Knots()); + const NCollection_Array1& aPoles = a->Poles(); + const NCollection_Array1& aMults = a->Multiplicities(); BSplCLib::Reparametrize(BS->FirstParameter(), BS->LastParameter(), aKnots); occ::handle anAncore = new Geom2d_BSplineCurve(aPoles, aKnots, aMults, a->Degree()); @@ -586,10 +570,9 @@ static void Pretreatment(NCollection_Array1>& t static bool NeedToBeTreated(const occ::handle& BS) { - NCollection_Array1 tabWeights(1, BS->NbPoles()); if (BS->IsRational()) { - BS->Weights(tabWeights); + const NCollection_Array1& tabWeights = BS->WeightsArray(); return (BSplCLib::IsRational(tabWeights, 1, BS->NbPoles())) && ((BS->Weight(1) < (1 - Precision::Confusion())) || (BS->Weight(1) > (1 + Precision::Confusion())) @@ -976,8 +959,7 @@ void Geom2dConvert::ConcatG1( Curve2->D1(Curve2->LastParameter(), Pint, Vec1); Curve1->D1(Curve1->FirstParameter(), Pint, Vec2); lambda = Vec2.Magnitude() / Vec1.Magnitude(); - NCollection_Array1 KnotC1(1, Curve1->NbKnots()); - Curve1->Knots(KnotC1); + NCollection_Array1 KnotC1(Curve1->Knots()); Curve1->D1(Curve1->LastParameter(), Pint, Vec2); ArrayOfCurves(0)->D1(ArrayOfCurves(0)->FirstParameter(), Pint, Vec1); double lambda2 = Vec1.Magnitude() / Vec2.Magnitude(); @@ -990,8 +972,7 @@ void Geom2dConvert::ConcatG1( c = umin; aPolynomialCoefficient[0] = c; NCollection_Array1 Curve1FlatKnots(1, Curve1->NbPoles() + Curve1->Degree() + 1); - NCollection_Array1 KnotC1Mults(1, Curve1->NbKnots()); - Curve1->Multiplicities(KnotC1Mults); + NCollection_Array1 KnotC1Mults(Curve1->Multiplicities()); BSplCLib::KnotSequence(KnotC1, KnotC1Mults, Curve1FlatKnots); KnotC1(1) = 0.0; for (ii = 2; ii <= KnotC1.Length(); ii++) @@ -999,8 +980,7 @@ void Geom2dConvert::ConcatG1( KnotC1(ii) = (-b + std::sqrt(b * b - 4 * a * (c - KnotC1(ii)))) / (2 * a); // ifv 17.05.00 buc60667 } - NCollection_Array1 Curve1Poles(1, Curve1->NbPoles()); - Curve1->Poles(Curve1Poles); + NCollection_Array1 Curve1Poles(Curve1->Poles()); for (ii = 1; ii <= Curve1->NbKnots(); ii++) KnotC1Mults(ii) = (Curve1->Degree() + KnotC1Mults(ii)); @@ -1012,8 +992,7 @@ void Geom2dConvert::ConcatG1( BSplCLib::KnotSequence(KnotC1, KnotC1Mults, FlatKnots); NCollection_Array1 NewPoles(1, FlatKnots.Length() - (2 * Curve1->Degree() + 1)); int aStatus; - NCollection_Array1 Curve1Weights(1, Curve1->NbPoles()); - Curve1->Weights(Curve1Weights); + const NCollection_Array1& Curve1Weights = Curve1->WeightsArray(); for (ii = 1; ii <= Curve1->NbPoles(); ii++) for (jj = 1; jj <= 2; jj++) Curve1Poles(ii).SetCoord(jj, Curve1Poles(ii).Coord(jj) * Curve1Weights(ii)); @@ -1243,8 +1222,7 @@ void Geom2dConvert::ConcatC1( Curve2->D1(Curve2->LastParameter(), Pint, Vec1); Curve1->D1(Curve1->FirstParameter(), Pint, Vec2); lambda = Vec2.Magnitude() / Vec1.Magnitude(); - NCollection_Array1 KnotC1(1, Curve1->NbKnots()); - Curve1->Knots(KnotC1); + NCollection_Array1 KnotC1(Curve1->Knots()); Curve1->D1(Curve1->LastParameter(), Pint, Vec2); ArrayOfCurves(0)->D1(ArrayOfCurves(0)->FirstParameter(), Pint, Vec1); double lambda2 = Vec1.Magnitude() / Vec2.Magnitude(); @@ -1257,8 +1235,7 @@ void Geom2dConvert::ConcatC1( c = umin; aPolynomialCoefficient[0] = c; NCollection_Array1 Curve1FlatKnots(1, Curve1->NbPoles() + Curve1->Degree() + 1); - NCollection_Array1 KnotC1Mults(1, Curve1->NbKnots()); - Curve1->Multiplicities(KnotC1Mults); + NCollection_Array1 KnotC1Mults(Curve1->Multiplicities()); BSplCLib::KnotSequence(KnotC1, KnotC1Mults, Curve1FlatKnots); KnotC1(1) = 0.0; for (ii = 2; ii <= KnotC1.Length(); ii++) @@ -1266,8 +1243,7 @@ void Geom2dConvert::ConcatC1( KnotC1(ii) = (-b + std::sqrt(b * b - 4 * a * (c - KnotC1(ii)))) / (2 * a); // ifv 17.05.00 buc60667 } - NCollection_Array1 Curve1Poles(1, Curve1->NbPoles()); - Curve1->Poles(Curve1Poles); + NCollection_Array1 Curve1Poles(Curve1->Poles()); for (ii = 1; ii <= Curve1->NbKnots(); ii++) KnotC1Mults(ii) = (Curve1->Degree() + KnotC1Mults(ii)); @@ -1277,10 +1253,9 @@ void Geom2dConvert::ConcatC1( + (Curve1->Degree() * Curve1->NbKnots())); BSplCLib::KnotSequence(KnotC1, KnotC1Mults, FlatKnots); - NCollection_Array1 NewPoles(1, FlatKnots.Length() - (aNewCurveDegree + 1)); - int aStatus; - NCollection_Array1 Curve1Weights(1, Curve1->NbPoles()); - Curve1->Weights(Curve1Weights); + NCollection_Array1 NewPoles(1, FlatKnots.Length() - (aNewCurveDegree + 1)); + int aStatus; + const NCollection_Array1& Curve1Weights = Curve1->WeightsArray(); for (ii = 1; ii <= Curve1->NbPoles(); ii++) for (jj = 1; jj <= 2; jj++) Curve1Poles(ii).SetCoord(jj, Curve1Poles(ii).Coord(jj) * Curve1Weights(ii)); @@ -1381,17 +1356,14 @@ void Geom2dConvert::C0BSplineToC1BSplineCurve(occ::handle& const double tolerance) { - NCollection_Array1 BSMults(1, BS->NbKnots()); - NCollection_Array1 BSKnots(1, BS->NbKnots()); - int i, j, nbcurveC1 = 1; - double U1, U2; - bool closed_flag = false; - gp_Pnt2d point1, point2; - gp_Vec2d V1, V2; - bool fusion; - - BS->Knots(BSKnots); - BS->Multiplicities(BSMults); + const NCollection_Array1& BSMults = BS->Multiplicities(); + const NCollection_Array1& BSKnots = BS->Knots(); + int i, j, nbcurveC1 = 1; + double U1, U2; + bool closed_flag = false; + gp_Pnt2d point1, point2; + gp_Vec2d V1, V2; + bool fusion; for (i = BS->FirstUKnotIndex() + 1; i <= (BS->LastUKnotIndex() - 1); i++) { if (BSMults(i) == BS->Degree()) @@ -1476,17 +1448,14 @@ void Geom2dConvert::C0BSplineToArrayOfC1BSplineCurve( const double Tolerance) { - NCollection_Array1 BSMults(1, BS->NbKnots()); - NCollection_Array1 BSKnots(1, BS->NbKnots()); - int i, j, nbcurveC1 = 1; - double U1, U2; - bool closed_flag = false; - gp_Pnt2d point1, point2; - gp_Vec2d V1, V2; + const NCollection_Array1& BSMults = BS->Multiplicities(); + const NCollection_Array1& BSKnots = BS->Knots(); + int i, j, nbcurveC1 = 1; + double U1, U2; + bool closed_flag = false; + gp_Pnt2d point1, point2; + gp_Vec2d V1, V2; // bool fusion; - - BS->Knots(BSKnots); - BS->Multiplicities(BSMults); for (i = BS->FirstUKnotIndex(); i <= (BS->LastUKnotIndex() - 1); i++) { if (BSMults(i) == BS->Degree()) diff --git a/src/ModelingData/TKGeomBase/Geom2dConvert/Geom2dConvert_BSplineCurveKnotSplitting.cxx b/src/ModelingData/TKGeomBase/Geom2dConvert/Geom2dConvert_BSplineCurveKnotSplitting.cxx index 574b71f521..9e940f39e9 100644 --- a/src/ModelingData/TKGeomBase/Geom2dConvert/Geom2dConvert_BSplineCurveKnotSplitting.cxx +++ b/src/ModelingData/TKGeomBase/Geom2dConvert/Geom2dConvert_BSplineCurveKnotSplitting.cxx @@ -47,10 +47,8 @@ Geom2dConvert_BSplineCurveKnotSplitting::Geom2dConvert_BSplineCurveKnotSplitting } else { - int NbKnots = BasisCurve->NbKnots(); - Array1OfInteger Mults(1, NbKnots); - BasisCurve->Multiplicities(Mults); - int Mmax = BSplCLib::MaxKnotMult(Mults, FirstIndex, LastIndex); + const Array1OfInteger& Mults = BasisCurve->Multiplicities(); + int Mmax = BSplCLib::MaxKnotMult(Mults, FirstIndex, LastIndex); if (Degree - Mmax >= ContinuityRange) { splitIndexes = new HArray1OfInteger(1, 2); diff --git a/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert.cxx b/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert.cxx index bbccaa65f2..502c963010 100644 --- a/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert.cxx +++ b/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert.cxx @@ -286,21 +286,17 @@ occ::handle GeomConvert::CurveToBSplineCurve( occ::handle CBez = occ::down_cast(Curv->Copy()); CBez->Segment(U1, U2); - int NbPoles = CBez->NbPoles(); - int Degree = CBez->Degree(); - NCollection_Array1 Poles(1, NbPoles); - NCollection_Array1 Knots(1, 2); - NCollection_Array1 Mults(1, 2); + int Degree = CBez->Degree(); + const NCollection_Array1& Poles = CBez->Poles(); + NCollection_Array1 Knots(1, 2); + NCollection_Array1 Mults(1, 2); Knots(1) = 0.0; Knots(2) = 1.0; Mults(1) = Degree + 1; Mults(2) = Degree + 1; - CBez->Poles(Poles); if (CBez->IsRational()) { - NCollection_Array1 Weights(1, NbPoles); - CBez->Weights(Weights); - TheCurve = new Geom_BSplineCurve(Poles, Weights, Knots, Mults, Degree); + TheCurve = new Geom_BSplineCurve(Poles, CBez->WeightsArray(), Knots, Mults, Degree); } else { @@ -391,22 +387,18 @@ occ::handle GeomConvert::CurveToBSplineCurve( else if (C->IsKind(STANDARD_TYPE(Geom_BezierCurve))) { - occ::handle CBez = occ::down_cast(C); - int NbPoles = CBez->NbPoles(); - int Degree = CBez->Degree(); - NCollection_Array1 Poles(1, NbPoles); - NCollection_Array1 Knots(1, 2); - NCollection_Array1 Mults(1, 2); + occ::handle CBez = occ::down_cast(C); + int Degree = CBez->Degree(); + const NCollection_Array1& Poles = CBez->Poles(); + NCollection_Array1 Knots(1, 2); + NCollection_Array1 Mults(1, 2); Knots(1) = 0.0; Knots(2) = 1.0; Mults(1) = Degree + 1; Mults(2) = Degree + 1; - CBez->Poles(Poles); if (CBez->IsRational()) { - NCollection_Array1 Weights(1, NbPoles); - CBez->Weights(Weights); - TheCurve = new Geom_BSplineCurve(Poles, Weights, Knots, Mults, Degree); + TheCurve = new Geom_BSplineCurve(Poles, CBez->WeightsArray(), Knots, Mults, Degree); } else { @@ -484,14 +476,11 @@ static occ::handle MultNumandDenom(const occ::handle& BS) { - NCollection_Array1 aKnots(1, a->NbKnots()); - NCollection_Array1 BSKnots(1, BS->NbKnots()); - NCollection_Array1 BSFlatKnots(1, BS->NbPoles() + BS->Degree() + 1); - NCollection_Array1 BSWeights(1, BS->NbPoles()); - NCollection_Array1 aMults(1, a->NbKnots()); - NCollection_Array1 BSMults(1, BS->NbKnots()); - NCollection_Array1 aPoles(1, a->NbPoles()); - NCollection_Array1 BSPoles(1, BS->NbPoles()); + const NCollection_Array1& BSKnots = BS->Knots(); + const NCollection_Array1& BSMults = BS->Multiplicities(); + NCollection_Array1 BSPoles(BS->Poles()); + const NCollection_Array1& BSWeights = BS->WeightsArray(); + const NCollection_Array1& BSFlatKnots = BS->KnotSequence(); occ::handle res; occ::handle> resKnots; occ::handle> resMults; @@ -499,19 +488,14 @@ static occ::handle MultNumandDenom(const occ::handleKnots(BSKnots); // storage of the two BSpline - BS->Multiplicities(BSMults); // features - BS->Poles(BSPoles); - BS->Weights(BSWeights); - BS->KnotSequence(BSFlatKnots); start_value = BSKnots(1); end_value = BSKnots(BS->NbKnots()); if ((end_value - start_value) / 5 < tolerance) tolerance = (end_value - start_value) / 5; - a->Knots(aKnots); - a->Poles(aPoles); - a->Multiplicities(aMults); + NCollection_Array1 aKnots(a->Knots()); + const NCollection_Array1& aPoles = a->Poles(); + const NCollection_Array1& aMults = a->Multiplicities(); BSplCLib::Reparametrize(BS->FirstParameter(), BS->LastParameter(), aKnots); occ::handle anAncore = new Geom2d_BSplineCurve(aPoles, aKnots, aMults, a->Degree()); @@ -600,10 +584,9 @@ static void Pretreatment(NCollection_Array1>& tab static bool NeedToBeTreated(const occ::handle& BS) { - NCollection_Array1 tabWeights(1, BS->NbPoles()); if (BS->IsRational()) { - BS->Weights(tabWeights); + const NCollection_Array1& tabWeights = BS->WeightsArray(); return (BSplCLib::IsRational(tabWeights, 1, BS->NbPoles())) && ((BS->Weight(1) < (1 - Precision::Confusion())) || (BS->Weight(1) > (1 + Precision::Confusion())) @@ -848,8 +831,7 @@ void GeomConvert::ConcatG1( Curve2->D1(Curve2->LastParameter(), Pint, Vec1); Curve1->D1(Curve1->FirstParameter(), Pint, Vec2); lambda = Vec2.Magnitude() / Vec1.Magnitude(); - NCollection_Array1 KnotC1(1, Curve1->NbKnots()); - Curve1->Knots(KnotC1); + NCollection_Array1 KnotC1(Curve1->Knots()); Curve1->D1(Curve1->LastParameter(), Pint, Vec2); ArrayOfCurves(0)->D1(ArrayOfCurves(0)->FirstParameter(), Pint, Vec1); double lambda2 = Vec1.Magnitude() / Vec2.Magnitude(); @@ -862,8 +844,7 @@ void GeomConvert::ConcatG1( c = umin; aPolynomialCoefficient[0] = c; NCollection_Array1 Curve1FlatKnots(1, Curve1->NbPoles() + Curve1->Degree() + 1); - NCollection_Array1 KnotC1Mults(1, Curve1->NbKnots()); - Curve1->Multiplicities(KnotC1Mults); + NCollection_Array1 KnotC1Mults(Curve1->Multiplicities()); BSplCLib::KnotSequence(KnotC1, KnotC1Mults, Curve1FlatKnots); KnotC1(1) = 0.0; for (ii = 2; ii <= KnotC1.Length(); ii++) @@ -871,8 +852,7 @@ void GeomConvert::ConcatG1( KnotC1(ii) = (-b + std::sqrt(b * b - 4 * a * (c - KnotC1(ii)))) / (2 * a); // ifv 17.05.00 buc60667 } - NCollection_Array1 Curve1Poles(1, Curve1->NbPoles()); - Curve1->Poles(Curve1Poles); + NCollection_Array1 Curve1Poles(Curve1->Poles()); for (ii = 1; ii <= Curve1->NbKnots(); ii++) KnotC1Mults(ii) = (Curve1->Degree() + KnotC1Mults(ii)); @@ -884,8 +864,7 @@ void GeomConvert::ConcatG1( BSplCLib::KnotSequence(KnotC1, KnotC1Mults, FlatKnots); NCollection_Array1 NewPoles(1, FlatKnots.Length() - (2 * Curve1->Degree() + 1)); int aStatus; - NCollection_Array1 Curve1Weights(1, Curve1->NbPoles()); - Curve1->Weights(Curve1Weights); + const NCollection_Array1& Curve1Weights = Curve1->WeightsArray(); for (ii = 1; ii <= Curve1->NbPoles(); ii++) for (jj = 1; jj <= 3; jj++) Curve1Poles(ii).SetCoord(jj, Curve1Poles(ii).Coord(jj) * Curve1Weights(ii)); @@ -1097,8 +1076,7 @@ void GeomConvert::ConcatC1( Curve2->D1(Curve2->LastParameter(), Pint, Vec1); Curve1->D1(Curve1->FirstParameter(), Pint, Vec2); lambda = Vec2.Magnitude() / Vec1.Magnitude(); - NCollection_Array1 KnotC1(1, Curve1->NbKnots()); - Curve1->Knots(KnotC1); + NCollection_Array1 KnotC1(Curve1->Knots()); Curve1->D1(Curve1->LastParameter(), Pint, Vec2); ArrayOfCurves(0)->D1(ArrayOfCurves(0)->FirstParameter(), Pint, Vec1); double lambda2 = Vec1.Magnitude() / Vec2.Magnitude(); @@ -1111,8 +1089,7 @@ void GeomConvert::ConcatC1( c = umin; aPolynomialCoefficient[0] = c; NCollection_Array1 Curve1FlatKnots(1, Curve1->NbPoles() + Curve1->Degree() + 1); - NCollection_Array1 KnotC1Mults(1, Curve1->NbKnots()); - Curve1->Multiplicities(KnotC1Mults); + NCollection_Array1 KnotC1Mults(Curve1->Multiplicities()); BSplCLib::KnotSequence(KnotC1, KnotC1Mults, Curve1FlatKnots); KnotC1(1) = 0.0; for (ii = 2; ii <= KnotC1.Length(); ii++) @@ -1120,8 +1097,7 @@ void GeomConvert::ConcatC1( KnotC1(ii) = (-b + std::sqrt(b * b - 4 * a * (c - KnotC1(ii)))) / (2 * a); // ifv 17.05.00 buc60667 } - NCollection_Array1 Curve1Poles(1, Curve1->NbPoles()); - Curve1->Poles(Curve1Poles); + NCollection_Array1 Curve1Poles(Curve1->Poles()); for (ii = 1; ii <= Curve1->NbKnots(); ii++) KnotC1Mults(ii) = (Curve1->Degree() + KnotC1Mults(ii)); @@ -1133,8 +1109,7 @@ void GeomConvert::ConcatC1( BSplCLib::KnotSequence(KnotC1, KnotC1Mults, FlatKnots); NCollection_Array1 NewPoles(1, FlatKnots.Length() - (2 * Curve1->Degree() + 1)); int aStatus; - NCollection_Array1 Curve1Weights(1, Curve1->NbPoles()); - Curve1->Weights(Curve1Weights); + const NCollection_Array1& Curve1Weights = Curve1->WeightsArray(); for (ii = 1; ii <= Curve1->NbPoles(); ii++) for (jj = 1; jj <= 3; jj++) Curve1Poles(ii).SetCoord(jj, Curve1Poles(ii).Coord(jj) * Curve1Weights(ii)); @@ -1273,17 +1248,13 @@ void GeomConvert::C0BSplineToArrayOfC1BSplineCurve( const double tolerance) { - NCollection_Array1 BSMults(1, BS->NbKnots()); - NCollection_Array1 BSKnots(1, BS->NbKnots()); - int i, j, nbcurveC1 = 1; - double U1, U2; - bool closed_flag = false; - gp_Pnt point; - gp_Vec V1, V2; - // bool fusion; - - BS->Knots(BSKnots); - BS->Multiplicities(BSMults); + const NCollection_Array1& BSMults = BS->Multiplicities(); + const NCollection_Array1& BSKnots = BS->Knots(); + int i, j, nbcurveC1 = 1; + double U1, U2; + bool closed_flag = false; + gp_Pnt point; + gp_Vec V1, V2; // clang-format off for (i=BS->FirstUKnotIndex() ;i<=(BS->LastUKnotIndex()-1);i++){ //give the number of C1 curves // clang-format on diff --git a/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_1.cxx b/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_1.cxx index f31cd03a07..81a2d02e86 100644 --- a/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_1.cxx +++ b/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_1.cxx @@ -515,17 +515,13 @@ occ::handle GeomConvert::SurfaceToBSplineSurface( C = GeomConvert::CurveToBSplineCurve(CT); } int NbUPoles, NbUKnots; - int NbVPoles, NbVKnots; + int NbVPoles; bool periodic = false; // Poles of meridian = Vpoles NbVPoles = C->NbPoles(); - NCollection_Array1 Poles(1, NbVPoles); - C->Poles(Poles); - NCollection_Array1 Weights(1, NbVPoles); - Weights.Init(1.); - if (C->IsRational()) - C->Weights(Weights); + NCollection_Array1 Poles(C->Poles()); + const NCollection_Array1& Weights = C->WeightsArray(); double AlfaU; if (Strim->IsUPeriodic()) @@ -557,11 +553,8 @@ occ::handle GeomConvert::SurfaceToBSplineSurface( UMults(1)++; UMults(NbUKnots)++; } - NbVKnots = C->NbKnots(); - NCollection_Array1 VKnots(1, NbVKnots); - NCollection_Array1 VMults(1, NbVKnots); - C->Knots(VKnots); - C->Multiplicities(VMults); + const NCollection_Array1& VKnots = C->Knots(); + const NCollection_Array1& VMults = C->Multiplicities(); // Compute the poles. NCollection_Array2 NewPoles(1, NbUPoles, 1, NbVPoles); @@ -624,13 +617,11 @@ occ::handle GeomConvert::SurfaceToBSplineSurface( occ::handle CT = new Geom_TrimmedCurve(Meridian, UFirst, ULast); C = GeomConvert::CurveToBSplineCurve(CT); } - NCollection_Array2 Poles(1, C->NbPoles(), 1, 2); - NCollection_Array2 Weights(1, C->NbPoles(), 1, 2); - NCollection_Array1 UKnots(1, C->NbKnots()); - C->Knots(UKnots); - NCollection_Array1 UMults(1, C->NbKnots()); - C->Multiplicities(UMults); - NCollection_Array1 VKnots(1, 2); + NCollection_Array2 Poles(1, C->NbPoles(), 1, 2); + NCollection_Array2 Weights(1, C->NbPoles(), 1, 2); + const NCollection_Array1& UKnots = C->Knots(); + const NCollection_Array1& UMults = C->Multiplicities(); + NCollection_Array1 VKnots(1, 2); VKnots(1) = VFirst; VKnots(2) = VLast; NCollection_Array1 VMults(1, 2); @@ -663,35 +654,36 @@ occ::handle GeomConvert::SurfaceToBSplineSurface( occ::handle SBez = occ::down_cast(Surf->Copy()); SBez->Segment(U1, U2, V1, V2); - int NbUPoles = SBez->NbUPoles(); - int NbVPoles = SBez->NbVPoles(); - int UDegree = SBez->UDegree(); - int VDegree = SBez->VDegree(); - NCollection_Array2 Poles(1, NbUPoles, 1, NbVPoles); + int UDegree = SBez->UDegree(); + int VDegree = SBez->VDegree(); NCollection_Array1 UKnots(1, 2); NCollection_Array1 UMults(1, 2); NCollection_Array1 VKnots(1, 2); NCollection_Array1 VMults(1, 2); - UKnots(1) = 0.0; - UKnots(2) = 1.0; - UMults(1) = UDegree + 1; - UMults(2) = UDegree + 1; - VKnots(1) = 0.0; - VKnots(2) = 1.0; - VMults(1) = VDegree + 1; - VMults(2) = VDegree + 1; - SBez->Poles(Poles); + UKnots(1) = 0.0; + UKnots(2) = 1.0; + UMults(1) = UDegree + 1; + UMults(2) = UDegree + 1; + VKnots(1) = 0.0; + VKnots(2) = 1.0; + VMults(1) = VDegree + 1; + VMults(2) = VDegree + 1; + const NCollection_Array2& aPoles = SBez->Poles(); if (SBez->IsURational() || SBez->IsVRational()) { - NCollection_Array2 Weights(1, NbUPoles, 1, NbVPoles); - SBez->Weights(Weights); - TheSurface = - new Geom_BSplineSurface(Poles, Weights, UKnots, VKnots, UMults, VMults, UDegree, VDegree); + TheSurface = new Geom_BSplineSurface(aPoles, + SBez->WeightsArray(), + UKnots, + VKnots, + UMults, + VMults, + UDegree, + VDegree); } else { TheSurface = - new Geom_BSplineSurface(Poles, UKnots, VKnots, UMults, VMults, UDegree, VDegree); + new Geom_BSplineSurface(aPoles, UKnots, VKnots, UMults, VMults, UDegree, VDegree); } } @@ -768,17 +760,13 @@ occ::handle GeomConvert::SurfaceToBSplineSurface( occ::handle C = GeomConvert::CurveToBSplineCurve(Meridian); int NbUPoles, NbUKnots; - int NbVPoles, NbVKnots; + int NbVPoles; bool periodic = true; // Poles of meridian = Vpoles NbVPoles = C->NbPoles(); - NCollection_Array1 Poles(1, NbVPoles); - C->Poles(Poles); - NCollection_Array1 Weights(1, NbVPoles); - Weights.Init(1.); - if (C->IsRational()) - C->Weights(Weights); + NCollection_Array1 Poles(C->Poles()); + const NCollection_Array1& Weights = C->WeightsArray(); double AlfaU; NbUKnots = 4; @@ -794,11 +782,8 @@ occ::handle GeomConvert::SurfaceToBSplineSurface( UKnots(i) = UFirst + (i - 1) * 2 * AlfaU; UMults(i) = 2; } - NbVKnots = C->NbKnots(); - NCollection_Array1 VKnots(1, NbVKnots); - NCollection_Array1 VMults(1, NbVKnots); - C->Knots(VKnots); - C->Multiplicities(VMults); + const NCollection_Array1& VKnots = C->Knots(); + const NCollection_Array1& VMults = C->Multiplicities(); // Compute the poles. NCollection_Array2 NewPoles(1, NbUPoles, 1, NbVPoles); @@ -850,35 +835,36 @@ occ::handle GeomConvert::SurfaceToBSplineSurface( occ::handle SBez = occ::down_cast(S); - int NbUPoles = SBez->NbUPoles(); - int NbVPoles = SBez->NbVPoles(); - int UDegree = SBez->UDegree(); - int VDegree = SBez->VDegree(); - NCollection_Array2 Poles(1, NbUPoles, 1, NbVPoles); + int UDegree = SBez->UDegree(); + int VDegree = SBez->VDegree(); NCollection_Array1 UKnots(1, 2); NCollection_Array1 UMults(1, 2); NCollection_Array1 VKnots(1, 2); NCollection_Array1 VMults(1, 2); - UKnots(1) = 0.0; - UKnots(2) = 1.0; - UMults(1) = UDegree + 1; - UMults(2) = UDegree + 1; - VKnots(1) = 0.0; - VKnots(2) = 1.0; - VMults(1) = VDegree + 1; - VMults(2) = VDegree + 1; - SBez->Poles(Poles); + UKnots(1) = 0.0; + UKnots(2) = 1.0; + UMults(1) = UDegree + 1; + UMults(2) = UDegree + 1; + VKnots(1) = 0.0; + VKnots(2) = 1.0; + VMults(1) = VDegree + 1; + VMults(2) = VDegree + 1; + const NCollection_Array2& aPoles = SBez->Poles(); if (SBez->IsURational() || SBez->IsVRational()) { - NCollection_Array2 Weights(1, NbUPoles, 1, NbVPoles); - SBez->Weights(Weights); - TheSurface = - new Geom_BSplineSurface(Poles, Weights, UKnots, VKnots, UMults, VMults, UDegree, VDegree); + TheSurface = new Geom_BSplineSurface(aPoles, + SBez->WeightsArray(), + UKnots, + VKnots, + UMults, + VMults, + UDegree, + VDegree); } else { TheSurface = - new Geom_BSplineSurface(Poles, UKnots, VKnots, UMults, VMults, UDegree, VDegree); + new Geom_BSplineSurface(aPoles, UKnots, VKnots, UMults, VMults, UDegree, VDegree); } } diff --git a/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_BSplineCurveKnotSplitting.cxx b/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_BSplineCurveKnotSplitting.cxx index e215616294..037c4de629 100644 --- a/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_BSplineCurveKnotSplitting.cxx +++ b/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_BSplineCurveKnotSplitting.cxx @@ -47,10 +47,8 @@ GeomConvert_BSplineCurveKnotSplitting::GeomConvert_BSplineCurveKnotSplitting( } else { - int NbKnots = BasisCurve->NbKnots(); - Array1OfInteger Mults(1, NbKnots); - BasisCurve->Multiplicities(Mults); - int Mmax = BSplCLib::MaxKnotMult(Mults, FirstIndex, LastIndex); + const Array1OfInteger& Mults = BasisCurve->Multiplicities(); + int Mmax = BSplCLib::MaxKnotMult(Mults, FirstIndex, LastIndex); if (Degree - Mmax >= ContinuityRange) { splitIndexes = new HArray1OfInteger(1, 2); diff --git a/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_BSplineSurfaceKnotSplitting.cxx b/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_BSplineSurfaceKnotSplitting.cxx index ec6c28d48d..7716c6ea07 100644 --- a/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_BSplineSurfaceKnotSplitting.cxx +++ b/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_BSplineSurfaceKnotSplitting.cxx @@ -53,10 +53,8 @@ GeomConvert_BSplineSurfaceKnotSplitting::GeomConvert_BSplineSurfaceKnotSplitting } else { - int NbUKnots = BasisSurface->NbUKnots(); - Array1OfInteger UMults(1, NbUKnots); - BasisSurface->UMultiplicities(UMults); - int Mmax = BSplCLib::MaxKnotMult(UMults, FirstUIndex, LastUIndex); + const Array1OfInteger& UMults = BasisSurface->UMultiplicities(); + int Mmax = BSplCLib::MaxKnotMult(UMults, FirstUIndex, LastUIndex); if (UDegree - Mmax >= UContinuityRange) { usplitIndexes = new HArray1OfInteger(1, 2); @@ -97,10 +95,8 @@ GeomConvert_BSplineSurfaceKnotSplitting::GeomConvert_BSplineSurfaceKnotSplitting } else { - int NbVKnots = BasisSurface->NbVKnots(); - Array1OfInteger VMults(1, NbVKnots); - BasisSurface->VMultiplicities(VMults); - int Mmax = BSplCLib::MaxKnotMult(VMults, FirstVIndex, LastVIndex); + const Array1OfInteger& VMults = BasisSurface->VMultiplicities(); + int Mmax = BSplCLib::MaxKnotMult(VMults, FirstVIndex, LastVIndex); if (VDegree - Mmax >= VContinuityRange) { usplitIndexes = new HArray1OfInteger(1, 2); diff --git a/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_CompBezierSurfacesToBSplineSurface.cxx b/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_CompBezierSurfacesToBSplineSurface.cxx index 23e12a3f13..0ff8ce8913 100644 --- a/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_CompBezierSurfacesToBSplineSurface.cxx +++ b/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_CompBezierSurfacesToBSplineSurface.cxx @@ -220,18 +220,11 @@ GeomConvert_CompBezierSurfacesToBSplineSurface::GeomConvert_CompBezierSurfacesTo } // Les nouveaux champs sont arrivees .... - myPoles = new (NCollection_HArray2)(1, Surface->NbUPoles(), 1, Surface->NbVPoles()); - Surface->Poles(myPoles->ChangeArray2()); - - myUMults = new (NCollection_HArray1)(1, Surface->NbUKnots()); - myVMults = new (NCollection_HArray1)(1, Surface->NbVKnots()); - myUKnots = new (NCollection_HArray1)(1, Surface->NbUKnots()); - myVKnots = new (NCollection_HArray1)(1, Surface->NbVKnots()); - - Surface->UMultiplicities(myUMults->ChangeArray1()); - Surface->VMultiplicities(myVMults->ChangeArray1()); - Surface->UKnots(myUKnots->ChangeArray1()); - Surface->VKnots(myVKnots->ChangeArray1()); + myPoles = new NCollection_HArray2(Surface->Poles()); + myUMults = new NCollection_HArray1(Surface->UMultiplicities()); + myVMults = new NCollection_HArray1(Surface->VMultiplicities()); + myUKnots = new NCollection_HArray1(Surface->UKnots()); + myVKnots = new NCollection_HArray1(Surface->VKnots()); } // ============================================================================ @@ -344,10 +337,9 @@ GeomConvert_CompBezierSurfacesToBSplineSurface::GeomConvert_CompBezierSurfacesTo } // Les nouveaux champs sont arrivees .... - myPoles = new (NCollection_HArray2)(1, Surface->NbUPoles(), 1, Surface->NbVPoles()); - Surface->Poles(myPoles->ChangeArray2()); - Surface->UMultiplicities(myUMults->ChangeArray1()); - Surface->VMultiplicities(myVMults->ChangeArray1()); + myPoles = new NCollection_HArray2(Surface->Poles()); + myUMults = new NCollection_HArray1(Surface->UMultiplicities()); + myVMults = new NCollection_HArray1(Surface->VMultiplicities()); } } diff --git a/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_CurveToAnaCurve.cxx b/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_CurveToAnaCurve.cxx index 42ce7a9d69..7aa9dc2e1f 100644 --- a/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_CurveToAnaCurve.cxx +++ b/src/ModelingData/TKGeomBase/GeomConvert/GeomConvert_CurveToAnaCurve.cxx @@ -189,8 +189,7 @@ occ::handle GeomConvert_CurveToAnaCurve::ComputeLine( if (!bsc.IsNull()) { nbPoles = bsc->NbPoles(); - Poles = new NCollection_HArray1(1, nbPoles); - bsc->Poles(Poles->ChangeArray1()); + Poles = new NCollection_HArray1(bsc->Poles()); } else { @@ -198,8 +197,7 @@ occ::handle GeomConvert_CurveToAnaCurve::ComputeLine( if (!bzc.IsNull()) { nbPoles = bzc->NbPoles(); - Poles = new NCollection_HArray1(1, nbPoles); - bzc->Poles(Poles->ChangeArray1()); + Poles = new NCollection_HArray1(bzc->Poles()); } else { diff --git a/src/ModelingData/TKGeomBase/GeomLib/GeomLib.cxx b/src/ModelingData/TKGeomBase/GeomLib/GeomLib.cxx index 0b538f9e38..9ef64b6047 100644 --- a/src/ModelingData/TKGeomBase/GeomLib/GeomLib.cxx +++ b/src/ModelingData/TKGeomBase/GeomLib/GeomLib.cxx @@ -591,11 +591,10 @@ occ::handle GeomLib::To3d(const gp_Ax2& Position, } else if (KindOfCurve == STANDARD_TYPE(Geom2d_BezierCurve)) { - occ::handle CBez2d = occ::down_cast(Curve2d); - int Nbpoles = CBez2d->NbPoles(); - NCollection_Array1 Poles2d(1, Nbpoles); - CBez2d->Poles(Poles2d); - NCollection_Array1 Poles3d(1, Nbpoles); + occ::handle CBez2d = occ::down_cast(Curve2d); + const NCollection_Array1& Poles2d = CBez2d->Poles(); + const int Nbpoles = Poles2d.Length(); + NCollection_Array1 Poles3d(1, Nbpoles); for (int i = 1; i <= Nbpoles; i++) { Poles3d(i) = ElCLib::To3d(Position, Poles2d(i)); @@ -603,9 +602,7 @@ occ::handle GeomLib::To3d(const gp_Ax2& Position, occ::handle CBez3d; if (CBez2d->IsRational()) { - NCollection_Array1 TheWeights(1, Nbpoles); - CBez2d->Weights(TheWeights); - CBez3d = new Geom_BezierCurve(Poles3d, TheWeights); + CBez3d = new Geom_BezierCurve(Poles3d, CBez2d->WeightsArray()); } else { @@ -615,29 +612,27 @@ occ::handle GeomLib::To3d(const gp_Ax2& Position, } else if (KindOfCurve == STANDARD_TYPE(Geom2d_BSplineCurve)) { - occ::handle CBSpl2d = occ::down_cast(Curve2d); - int Nbpoles = CBSpl2d->NbPoles(); - int Nbknots = CBSpl2d->NbKnots(); - int TheDegree = CBSpl2d->Degree(); - bool IsPeriodic = CBSpl2d->IsPeriodic(); - NCollection_Array1 Poles2d(1, Nbpoles); - CBSpl2d->Poles(Poles2d); - NCollection_Array1 Poles3d(1, Nbpoles); + occ::handle CBSpl2d = occ::down_cast(Curve2d); + const int TheDegree = CBSpl2d->Degree(); + const bool IsPeriodic = CBSpl2d->IsPeriodic(); + const NCollection_Array1& Poles2d = CBSpl2d->Poles(); + const int Nbpoles = Poles2d.Length(); + NCollection_Array1 Poles3d(1, Nbpoles); for (int i = 1; i <= Nbpoles; i++) { Poles3d(i) = ElCLib::To3d(Position, Poles2d(i)); } - NCollection_Array1 TheKnots(1, Nbknots); - NCollection_Array1 TheMults(1, Nbknots); - CBSpl2d->Knots(TheKnots); - CBSpl2d->Multiplicities(TheMults); - occ::handle CBSpl3d; + const NCollection_Array1& TheKnots = CBSpl2d->Knots(); + const NCollection_Array1& TheMults = CBSpl2d->Multiplicities(); + occ::handle CBSpl3d; if (CBSpl2d->IsRational()) { - NCollection_Array1 TheWeights(1, Nbpoles); - CBSpl2d->Weights(TheWeights); - CBSpl3d = - new Geom_BSplineCurve(Poles3d, TheWeights, TheKnots, TheMults, TheDegree, IsPeriodic); + CBSpl3d = new Geom_BSplineCurve(Poles3d, + CBSpl2d->WeightsArray(), + TheKnots, + TheMults, + TheDegree, + IsPeriodic); } else { @@ -806,9 +801,8 @@ occ::handle GeomLib::GTransform(const occ::handle& C // de la courbe de base. occ::handle C = occ::down_cast(Curve->Copy()); - int NbPoles = C->NbPoles(); - NCollection_Array1 Poles(1, NbPoles); - C->Poles(Poles); + const int NbPoles = C->NbPoles(); + NCollection_Array1 Poles(C->Poles()); for (int i = 1; i <= NbPoles; i++) { Poles(i).SetXY(GTrsf.Transformed(Poles(i).XY())); @@ -822,9 +816,8 @@ occ::handle GeomLib::GTransform(const occ::handle& C // Voir commentaire pour les Bezier. occ::handle C = occ::down_cast(Curve->Copy()); - int NbPoles = C->NbPoles(); - NCollection_Array1 Poles(1, NbPoles); - C->Poles(Poles); + const int NbPoles = C->NbPoles(); + NCollection_Array1 Poles(C->Poles()); for (int i = 1; i <= NbPoles; i++) { Poles(i).SetXY(GTrsf.Transformed(Poles(i).XY())); @@ -930,8 +923,7 @@ void GeomLib::SameRange(const double Tolerance, new Geom2d_TrimmedCurve(CurvePtr, FirstOnCurve, LastOnCurve); occ::handle BS = Geom2dConvert::CurveToBSplineCurve(TC); - NCollection_Array1 Knots(1, BS->NbKnots()); - BS->Knots(Knots); + NCollection_Array1 Knots(BS->Knots()); BSplCLib::Reparametrize(RequestedFirst, RequestedLast, Knots); @@ -978,8 +970,7 @@ void GeomLib::SameRange(const double Tolerance, // occ::handle BS = Geom2dConvert::CurveToBSplineCurve(TC); - NCollection_Array1 Knots(1, BS->NbKnots()); - BS->Knots(Knots); + NCollection_Array1 Knots(BS->Knots()); BSplCLib::Reparametrize(RequestedFirst, RequestedLast, Knots); @@ -1562,12 +1553,11 @@ void GeomLib::ExtendSurfByLength(occ::handle& Surface, } // the flat knots - Ksize = NbP + Cdeg + 1; - FKnots = new (NCollection_HArray1)(1, Ksize); + Ksize = NbP + Cdeg + 1; if (InU) - BS->UKnotSequence(FKnots->ChangeArray1()); + FKnots = new NCollection_HArray1(BS->UKnotSequence()); else - BS->VKnotSequence(FKnots->ChangeArray1()); + FKnots = new NCollection_HArray1(BS->VKnotSequence()); // the parameter of the connection knot if (After) @@ -1897,18 +1887,18 @@ void GeomLib::ExtendSurfByLength(occ::handle& Surface, UDeg = Cdeg; UMults(Usize) = UDeg + 1; // Petite verrue utile quand la continuite // n'est pas ok. - BS->VKnots(VKnots); - BS->VMultiplicities(VMults); - VDeg = BS->VDegree(); + VKnots = BS->VKnots(); + VMults = BS->VMultiplicities(); + VDeg = BS->VDegree(); } else { BSplCLib::Knots(FKRes, VKnots, VMults); VDeg = Cdeg; VMults(Vsize) = VDeg + 1; - BS->UKnots(UKnots); - BS->UMultiplicities(UMults); - UDeg = BS->UDegree(); + UKnots = BS->UKnots(); + UMults = BS->UMultiplicities(); + UDeg = BS->UDegree(); } // construction de la surface BSpline resultat @@ -2301,23 +2291,16 @@ static void FunctionMultiply(occ::handle& BSurf, const double knotmax) { - NCollection_Array1 surface_u_knots(1, BSurf->NbUKnots()); - NCollection_Array1 surface_u_mults(1, BSurf->NbUKnots()); - NCollection_Array1 surface_v_knots(1, BSurf->NbVKnots()); - NCollection_Array1 surface_v_mults(1, BSurf->NbVKnots()); - NCollection_Array2 surface_poles(1, BSurf->NbUPoles(), 1, BSurf->NbVPoles()); - NCollection_Array2 surface_weights(1, BSurf->NbUPoles(), 1, BSurf->NbVPoles()); - int i, j, k, status, new_num_u_poles, new_num_v_poles, length = 0; + const NCollection_Array1& surface_u_knots = BSurf->UKnots(); + const NCollection_Array1& surface_u_mults = BSurf->UMultiplicities(); + const NCollection_Array1& surface_v_knots = BSurf->VKnots(); + const NCollection_Array1& surface_v_mults = BSurf->VMultiplicities(); + const NCollection_Array2& surface_poles = BSurf->Poles(); + const NCollection_Array2* surface_weights = BSurf->Weights(); + int i, j, k, status, new_num_u_poles, new_num_v_poles, length = 0; occ::handle> newuknots, newvknots; occ::handle> newumults, newvmults; - BSurf->UKnots(surface_u_knots); - BSurf->UMultiplicities(surface_u_mults); - BSurf->VKnots(surface_v_knots); - BSurf->VMultiplicities(surface_v_mults); - BSurf->Poles(surface_poles); - BSurf->Weights(surface_weights); - NCollection_Array1 Knots(1, 2); NCollection_Array1 Mults(1, 2); occ::handle> NewKnots; @@ -2379,7 +2362,7 @@ static void FunctionMultiply(occ::handle& BSurf, &surface_u_mults, &surface_v_mults, surface_poles, - &surface_weights, + surface_weights, newuflatknots, newvflatknots, BSurf->UDegree() + 3, @@ -2417,23 +2400,22 @@ static void FunctionMultiply(occ::handle& BSurf, static void CancelDenominatorDerivative1D(occ::handle& BSurf) { - int i, j; - double uknotmin = 1.0, uknotmax = 0.0, x, y, startu_value, endu_value; - NCollection_Array1 BSurf_u_knots(1, BSurf->NbUKnots()); + int i, j; + double uknotmin = 1.0, uknotmax = 0.0, x, y, startu_value, endu_value; startu_value = BSurf->UKnot(1); endu_value = BSurf->UKnot(BSurf->NbUKnots()); - BSurf->UKnots(BSurf_u_knots); + NCollection_Array1 BSurf_u_knots(BSurf->UKnots()); BSplCLib::Reparametrize(0.0, 1.0, BSurf_u_knots); BSurf->SetUKnots(BSurf_u_knots); // reparametrisation of the surface occ::handle BCurve; NCollection_Array1 BCurveWeights(1, BSurf->NbUPoles()); NCollection_Array1 BCurvePoles(1, BSurf->NbUPoles()); - NCollection_Array1 BCurveKnots(1, BSurf->NbUKnots()); - NCollection_Array1 BCurveMults(1, BSurf->NbUKnots()); if (CanBeTreated(BSurf)) { + const NCollection_Array1& BCurveKnots = BSurf->UKnots(); + const NCollection_Array1& BCurveMults = BSurf->UMultiplicities(); for (i = 1; i <= BSurf->NbVPoles(); i++) { // loop on each pole function x = 1.0; @@ -2443,8 +2425,6 @@ static void CancelDenominatorDerivative1D(occ::handle& BSur BCurveWeights(j) = BSurf->Weight(j, i); BCurvePoles(j) = BSurf->Pole(j, i); } - BSurf->UKnots(BCurveKnots); - BSurf->UMultiplicities(BCurveMults); BCurve = new Geom_BSplineCurve(BCurvePoles, // building of a pole function BCurveWeights, BCurveKnots, @@ -2463,7 +2443,7 @@ static void CancelDenominatorDerivative1D(occ::handle& BSur FunctionMultiply(BSurf, uknotmin, uknotmax); // multiplication - BSurf->UKnots(BSurf_u_knots); + BSurf_u_knots = BSurf->UKnots(); BSplCLib::Reparametrize(startu_value, endu_value, BSurf_u_knots); BSurf->SetUKnots(BSurf_u_knots); } diff --git a/src/ModelingData/TKGeomBase/GeomLib/GeomLib_DenominatorMultiplier.cxx b/src/ModelingData/TKGeomBase/GeomLib/GeomLib_DenominatorMultiplier.cxx index f07abd25b7..9daf3c1c45 100644 --- a/src/ModelingData/TKGeomBase/GeomLib/GeomLib_DenominatorMultiplier.cxx +++ b/src/ModelingData/TKGeomBase/GeomLib/GeomLib_DenominatorMultiplier.cxx @@ -47,32 +47,24 @@ double GeomLib_DenominatorMultiplier::Value(const double UParameter, const doubl { double Dumaxv, Duminv, dDduumaxv, dDduuminv, Dv, Buv = 0.0; // gp_Pnt HermPnt; - gp_Pnt N; - gp_Vec Nu, Nv; - NCollection_Array2 surface_poles(1, mySurface->NbUPoles(), 1, mySurface->NbVPoles()); - NCollection_Array2 surface_weights(1, mySurface->NbUPoles(), 1, mySurface->NbVPoles()); - NCollection_Array1 surface_u_knots(1, mySurface->NbUKnots()); - NCollection_Array1 surface_u_mults(1, mySurface->NbUKnots()); + gp_Pnt N; + gp_Vec Nu, Nv; - NCollection_Array1 surface_v_knots(1, mySurface->NbVKnots()); - NCollection_Array1 surface_v_mults(1, mySurface->NbVKnots()); - int udegree, vdegree; - - mySurface->UKnots(surface_u_knots); - mySurface->UMultiplicities(surface_u_mults); - mySurface->Poles(surface_poles); - mySurface->Weights(surface_weights); - mySurface->VKnots(surface_v_knots); - mySurface->VMultiplicities(surface_v_mults); - udegree = mySurface->UDegree(); - vdegree = mySurface->VDegree(); + const NCollection_Array2& surface_poles = mySurface->Poles(); + const NCollection_Array2* surface_weights = mySurface->Weights(); + const NCollection_Array1& surface_u_knots = mySurface->UKnots(); + const NCollection_Array1& surface_u_mults = mySurface->UMultiplicities(); + const NCollection_Array1& surface_v_knots = mySurface->VKnots(); + const NCollection_Array1& surface_v_mults = mySurface->VMultiplicities(); + int udegree = mySurface->UDegree(); + int vdegree = mySurface->VDegree(); BSplSLib::HomogeneousD1(mySurface->UKnot(mySurface->LastUKnotIndex()), VParameter, 0, 0, surface_poles, - &surface_weights, + surface_weights, surface_u_knots, surface_v_knots, &surface_u_mults, @@ -94,7 +86,7 @@ double GeomLib_DenominatorMultiplier::Value(const double UParameter, const doubl 0, 0, surface_poles, - &surface_weights, + surface_weights, surface_u_knots, surface_v_knots, &surface_u_mults, diff --git a/src/ModelingData/TKGeomBase/Hermit/Hermit.cxx b/src/ModelingData/TKGeomBase/Hermit/Hermit.cxx index 504d754592..3d4e0149d4 100644 --- a/src/ModelingData/TKGeomBase/Hermit/Hermit.cxx +++ b/src/ModelingData/TKGeomBase/Hermit/Hermit.cxx @@ -36,9 +36,9 @@ static void HermiteCoeff(const occ::handle& BS, NCollection_Array1& TAB) { - NCollection_Array1 Knots(1, BS->NbKnots()); - NCollection_Array1 Weights(1, BS->NbPoles()); - NCollection_Array1 Mults(1, BS->NbKnots()); + NCollection_Array1 Knots(BS->Knots()); + const NCollection_Array1& Weights = BS->WeightsArray(); + const NCollection_Array1& Mults = BS->Multiplicities(); // clang-format off int Degree,Index0,Index1; // denominateur value for u=0 & u=1 double Denom0,Denom1, // denominator value for u=0 & u=1 @@ -46,15 +46,16 @@ static void HermiteCoeff(const occ::handle& BS, NCollection_A // clang-format on bool Periodic; - BS->Knots(Knots); BSplCLib::Reparametrize(0.0, 1.0, Knots); // affinity on the nodal vector - BS->Weights(Weights); - BS->Multiplicities(Mults); Degree = BS->Degree(); Periodic = BS->IsPeriodic(); Index0 = BS->FirstUKnotIndex(); Index1 = BS->LastUKnotIndex() - 1; + // Evaluate the weight function w(u) = sum_i N_i,p(u) * w_i and its derivative + // at u=0 and u=1. The weight function of a rational BSpline is itself a polynomial + // BSpline of the same degree, with weight values as scalar "poles" and no rational + // denominator -- hence Weights is passed as Poles, with NoWeights() for unweighted evaluation. BSplCLib::D1(0.0, Index0, Degree, @@ -91,25 +92,26 @@ static void HermiteCoeff(const occ::handle& BS, NCollection_Array1& TAB) { - NCollection_Array1 Knots(1, BS->NbKnots()); - NCollection_Array1 Weights(1, BS->NbPoles()); - NCollection_Array1 Mults(1, BS->NbKnots()); - int Degree, Index0, Index1; - double Denom0, Denom1, // denominateur value for u=0 & u=1 - // clang-format off + NCollection_Array1 Knots(BS->Knots()); + const NCollection_Array1& Weights = BS->WeightsArray(); + const NCollection_Array1& Mults = BS->Multiplicities(); + int Degree, Index0, Index1; + double Denom0, Denom1, // denominateur value for u=0 & u=1 + // clang-format off Deriv0,Deriv1 ; // denominator value for u=0 & u=1 bool Periodic; // derivative denominatur value for u=0 & 1 - // clang-format on + // clang-format on - BS->Knots(Knots); BSplCLib::Reparametrize(0.0, 1.0, Knots); // affinity on the nodal vector - BS->Weights(Weights); - BS->Multiplicities(Mults); Degree = BS->Degree(); Periodic = BS->IsPeriodic(); Index0 = BS->FirstUKnotIndex(); Index1 = BS->LastUKnotIndex() - 1; + // Evaluate the weight function w(u) = sum_i N_i,p(u) * w_i and its derivative + // at u=0 and u=1. The weight function of a rational BSpline is itself a polynomial + // BSpline of the same degree, with weight values as scalar "poles" and no rational + // denominator -- hence Weights is passed as Poles, with NoWeights() for unweighted evaluation. BSplCLib::D1(0.0, Index0, Degree, @@ -307,7 +309,7 @@ static void PolyTest(const NCollection_Array1& Herm, double Pole0, Pole3; Pole0 = Polesinit(0).Y(); Pole3 = Polesinit(3).Y(); - if (Pole0 < 3) + if (Pole0 < Pole3) { a = std::log10(Pole3 / Pole0); if (boucle == 2) @@ -318,7 +320,7 @@ static void PolyTest(const NCollection_Array1& Herm, Polesinit(i).Y() - (Pole3 * (std::pow(10.0, (-0.5 * std::log10(TolPoles) - a / 2.0))))); } - if (boucle == 1) + else if (boucle == 1) { for (i = 0; i <= 3; i++) Polesinit(i).SetCoord( @@ -339,7 +341,7 @@ static void PolyTest(const NCollection_Array1& Herm, Polesinit(i).Y() - (Pole0 * (std::pow(10.0, (-0.5 * std::log10(TolPoles) - a / 2.0))))); } - if (boucle == 1) + else if (boucle == 1) { for (i = 0; i <= 3; i++) Polesinit(i).SetCoord( @@ -570,7 +572,7 @@ static void PolyTest(const NCollection_Array1& Herm, double Pole0, Pole3; Pole0 = Polesinit(0).Y(); Pole3 = Polesinit(3).Y(); - if (Pole0 < 3) + if (Pole0 < Pole3) { a = std::log10(Pole3 / Pole0); if (boucle == 2) @@ -581,7 +583,7 @@ static void PolyTest(const NCollection_Array1& Herm, Polesinit(i).Y() - (Pole3 * (std::pow(10.0, (-0.5 * std::log10(TolPoles) - a / 2.0))))); } - if (boucle == 1) + else if (boucle == 1) { for (i = 0; i <= 3; i++) Polesinit(i).SetCoord( diff --git a/src/ModelingData/TKGeomBase/ProjLib/ProjLib_ComputeApprox.cxx b/src/ModelingData/TKGeomBase/ProjLib/ProjLib_ComputeApprox.cxx index a1c5aec274..f4a8c3c7a2 100644 --- a/src/ModelingData/TKGeomBase/ProjLib/ProjLib_ComputeApprox.cxx +++ b/src/ModelingData/TKGeomBase/ProjLib/ProjLib_ComputeApprox.cxx @@ -1132,14 +1132,10 @@ void ProjLib_ComputeApprox::Perform(const occ::handle& C, { // get the poles and eventually the weights - occ::handle BS = C->BSpline(); - NbPoles = BS->NbPoles(); - NCollection_Array1 P3d(1, NbPoles); - NCollection_Array1 Poles(1, NbPoles); - NCollection_Array1 Weights(1, NbPoles); - if (BS->IsRational()) - BS->Weights(Weights); - BS->Poles(P3d); + occ::handle BS = C->BSpline(); + NbPoles = BS->NbPoles(); + const NCollection_Array1& P3d = BS->Poles(); + NCollection_Array1 Poles(1, NbPoles); // Project poles onto plane using optimized projector (avoids gp_Trsf per point) const PlaneProjector aProj(S->Plane().Position()); @@ -1147,16 +1143,17 @@ void ProjLib_ComputeApprox::Perform(const occ::handle& C, { Poles.SetValue(i, aProj.Project(P3d(i))); } - NbKnots = BS->NbKnots(); - NCollection_Array1 Knots(1, NbKnots); - NCollection_Array1 Mults(1, NbKnots); - BS->Knots(Knots); - BS->Multiplicities(Mults); + const NCollection_Array1& Knots = BS->Knots(); + const NCollection_Array1& Mults = BS->Multiplicities(); // get the knots and mults if BSplineCurve if (BS->IsRational()) { - myBSpline = - new Geom2d_BSplineCurve(Poles, Weights, Knots, Mults, BS->Degree(), BS->IsPeriodic()); + myBSpline = new Geom2d_BSplineCurve(Poles, + BS->WeightsArray(), + Knots, + Mults, + BS->Degree(), + BS->IsPeriodic()); } else { @@ -1169,14 +1166,8 @@ void ProjLib_ComputeApprox::Perform(const occ::handle& C, // get the poles and eventually the weights occ::handle BezierCurvePtr = C->Bezier(); NbPoles = BezierCurvePtr->NbPoles(); - NCollection_Array1 P3d(1, NbPoles); - NCollection_Array1 Poles(1, NbPoles); - NCollection_Array1 Weights(1, NbPoles); - if (BezierCurvePtr->IsRational()) - { - BezierCurvePtr->Weights(Weights); - } - BezierCurvePtr->Poles(P3d); + const NCollection_Array1& P3d = BezierCurvePtr->Poles(); + NCollection_Array1 Poles(1, NbPoles); // Project poles onto plane using optimized projector (avoids gp_Trsf per point) const PlaneProjector aProj(S->Plane().Position()); @@ -1186,7 +1177,7 @@ void ProjLib_ComputeApprox::Perform(const occ::handle& C, } if (BezierCurvePtr->IsRational()) { - myBezier = new Geom2d_BezierCurve(Poles, Weights); + myBezier = new Geom2d_BezierCurve(Poles, BezierCurvePtr->WeightsArray()); } else { diff --git a/src/ModelingData/TKGeomBase/ProjLib/ProjLib_ComputeApproxOnPolarSurface.cxx b/src/ModelingData/TKGeomBase/ProjLib/ProjLib_ComputeApproxOnPolarSurface.cxx index 509bd7fa1f..32b478c350 100644 --- a/src/ModelingData/TKGeomBase/ProjLib/ProjLib_ComputeApproxOnPolarSurface.cxx +++ b/src/ModelingData/TKGeomBase/ProjLib/ProjLib_ComputeApproxOnPolarSurface.cxx @@ -612,18 +612,12 @@ static occ::handle Concat(const occ::handle K1(1, nk1); - C1->Knots(K1); - NCollection_Array1 M1(1, nk1); - C1->Multiplicities(M1); - NCollection_Array1 P1(1, np1); - C1->Poles(P1); - NCollection_Array1 K2(1, nk2); - C2->Knots(K2); - NCollection_Array1 M2(1, nk2); - C2->Multiplicities(M2); - NCollection_Array1 P2(1, np2); - C2->Poles(P2); + const NCollection_Array1& K1 = C1->Knots(); + const NCollection_Array1& M1 = C1->Multiplicities(); + const NCollection_Array1& P1 = C1->Poles(); + const NCollection_Array1& K2 = C2->Knots(); + const NCollection_Array1& M2 = C2->Multiplicities(); + const NCollection_Array1& P2 = C2->Poles(); // Compute the new BSplineCurve NCollection_Array1 K(1, nk); @@ -1685,20 +1679,20 @@ occ::handle ProjLib_ComputeApproxOnPolarSurface::ProjectUsi ElSLib::Parameters(Plane, BSC->Pole(i), S, T); Poles2d(i).SetCoord(S, T); } - NCollection_Array1 Knots(1, BSC->NbKnots()); - BSC->Knots(Knots); - NCollection_Array1 Mults(1, BSC->NbKnots()); - BSC->Multiplicities(Mults); + const NCollection_Array1& Knots = BSC->Knots(); + const NCollection_Array1& Mults = BSC->Multiplicities(); if (BSC->IsRational()) { - NCollection_Array1 Weights(1, BSC->NbPoles()); - BSC->Weights(Weights); - return new Geom2d_BSplineCurve(Poles2d, - Weights, - Knots, - Mults, - BSC->Degree(), - BSC->IsPeriodic()); + const NCollection_Array1* pWeights = BSC->Weights(); + if (pWeights) + { + return new Geom2d_BSplineCurve(Poles2d, + *pWeights, + Knots, + Mults, + BSC->Degree(), + BSC->IsPeriodic()); + } } return new Geom2d_BSplineCurve(Poles2d, Knots, Mults, BSC->Degree(), BSC->IsPeriodic()); } @@ -1719,14 +1713,16 @@ occ::handle ProjLib_ComputeApproxOnPolarSurface::ProjectUsi Mults.Init(BC->NbPoles()); if (BC->IsRational()) { - NCollection_Array1 Weights(1, BC->NbPoles()); - BC->Weights(Weights); - return new Geom2d_BSplineCurve(Poles2d, - Weights, - Knots, - Mults, - BC->Degree(), - BC->IsPeriodic()); + const NCollection_Array1* pWeights = BC->Weights(); + if (pWeights) + { + return new Geom2d_BSplineCurve(Poles2d, + *pWeights, + Knots, + Mults, + BC->Degree(), + BC->IsPeriodic()); + } } return new Geom2d_BSplineCurve(Poles2d, Knots, Mults, BC->Degree(), BC->IsPeriodic()); } @@ -1778,16 +1774,12 @@ occ::handle ProjLib_ComputeApproxOnPolarSurface::ProjectUsi } if (myProjIsDone) { - NCollection_Array1 Knots(1, BSC->NbKnots()); - BSC->Knots(Knots); - NCollection_Array1 Mults(1, BSC->NbKnots()); - BSC->Multiplicities(Mults); + const NCollection_Array1& Knots = BSC->Knots(); + const NCollection_Array1& Mults = BSC->Multiplicities(); if (BSC->IsRational()) { - NCollection_Array1 Weights(1, BSC->NbPoles()); - BSC->Weights(Weights); return new Geom2d_BSplineCurve(Poles2d, - Weights, + BSC->WeightsArray(), Knots, Mults, BSC->Degree(), @@ -1836,10 +1828,8 @@ occ::handle ProjLib_ComputeApproxOnPolarSurface::ProjectUsi Mults.Init(BC->NbPoles()); if (BC->IsRational()) { - NCollection_Array1 Weights(1, BC->NbPoles()); - BC->Weights(Weights); return new Geom2d_BSplineCurve(Poles2d, - Weights, + BC->WeightsArray(), Knots, Mults, BC->Degree(), @@ -1900,16 +1890,12 @@ occ::handle ProjLib_ComputeApproxOnPolarSurface::ProjectUsi } if (myProjIsDone) { - NCollection_Array1 Knots(1, BSC->NbKnots()); - BSC->Knots(Knots); - NCollection_Array1 Mults(1, BSC->NbKnots()); - BSC->Multiplicities(Mults); + const NCollection_Array1& Knots = BSC->Knots(); + const NCollection_Array1& Mults = BSC->Multiplicities(); if (BSC->IsRational()) { - NCollection_Array1 Weights(1, BSC->NbPoles()); - BSC->Weights(Weights); return new Geom2d_BSplineCurve(Poles2d, - Weights, + BSC->WeightsArray(), Knots, Mults, BSC->Degree(), @@ -1958,10 +1944,8 @@ occ::handle ProjLib_ComputeApproxOnPolarSurface::ProjectUsi Mults.Init(BC->NbPoles()); if (BC->IsRational()) { - NCollection_Array1 Weights(1, BC->NbPoles()); - BC->Weights(Weights); return new Geom2d_BSplineCurve(Poles2d, - Weights, + BC->WeightsArray(), Knots, Mults, BC->Degree(), diff --git a/src/ModelingData/TKGeomBase/ProjLib/ProjLib_ProjectOnPlane.cxx b/src/ModelingData/TKGeomBase/ProjLib/ProjLib_ProjectOnPlane.cxx index a212b6e365..a4768d8347 100644 --- a/src/ModelingData/TKGeomBase/ProjLib/ProjLib_ProjectOnPlane.cxx +++ b/src/ModelingData/TKGeomBase/ProjLib/ProjLib_ProjectOnPlane.cxx @@ -553,7 +553,6 @@ void ProjLib_ProjectOnPlane::Load(const occ::handle& C, gp_Elips Elips; // gp_Hypr Hypr ; - int num_knots; GeomAbs_CurveType Type = C->GetType(); gp_Ax2 Axis; @@ -639,9 +638,7 @@ void ProjLib_ProjectOnPlane::Load(const occ::handle& C, occ::handle NewCurvePtr = GeomConvert::CurveToBSplineCurve(NewTrimCurvePtr); - num_knots = NewCurvePtr->NbKnots(); - NCollection_Array1 BsplineKnots(1, num_knots); - NewCurvePtr->Knots(BsplineKnots); + NCollection_Array1 BsplineKnots(NewCurvePtr->Knots()); BSplCLib::Reparametrize(myCurve->FirstParameter(), myCurve->LastParameter(), diff --git a/src/Visualization/TKV3d/StdPrs/StdPrs_WFPoleSurface.cxx b/src/Visualization/TKV3d/StdPrs/StdPrs_WFPoleSurface.cxx index 3982575120..e669b038fd 100644 --- a/src/Visualization/TKV3d/StdPrs/StdPrs_WFPoleSurface.cxx +++ b/src/Visualization/TKV3d/StdPrs/StdPrs_WFPoleSurface.cxx @@ -63,23 +63,16 @@ void StdPrs_WFPoleSurface::Add(const occ::handle& aPresentat GeomAbs_SurfaceType SType = aSurface.GetType(); if (SType == GeomAbs_BezierSurface || SType == GeomAbs_BSplineSurface) { - int n, m; if (SType == GeomAbs_BezierSurface) { - occ::handle B = aSurface.Bezier(); - n = aSurface.NbUPoles(); - m = aSurface.NbVPoles(); - NCollection_Array2 A(1, n, 1, m); - (aSurface.Bezier())->Poles(A); + occ::handle B = aSurface.Bezier(); + const NCollection_Array2& A = B->Poles(); AddPoles(aPresentation, A, aDrawer); } else if (SType == GeomAbs_BSplineSurface) { - occ::handle B = aSurface.BSpline(); - n = (aSurface.BSpline())->NbUPoles(); - m = (aSurface.BSpline())->NbVPoles(); - NCollection_Array2 A(1, n, 1, m); - (aSurface.BSpline())->Poles(A); + occ::handle B = aSurface.BSpline(); + const NCollection_Array2& A = B->Poles(); AddPoles(aPresentation, A, aDrawer); } }