Modeling Data, Algorithms - Always-populated weights, direct array access migration, Hermit bug fix (#1058)

Introduce always-populated weight arrays in BSpline/Bezier curve and surface
classes using non-owning views over a static unit-weights buffer. Migrate
~100 callers across the codebase from deprecated copy-out APIs to direct
const-reference array access. Fix a long-standing typo bug in Hermit.cxx.

Infrastructure (BSplCLib, BSplSLib):
- Add BSplCLib::UnitWeights(n) returning a non-owning NCollection_Array1
  view over a compile-time-initialized static array of 2049 ones; falls
  back to heap allocation for larger sizes.
- Add BSplCLib::MaxUnitWeightsSize() (constexpr 2049) and
  BSplCLib::UnitWeightsData() exposing the raw pointer for BSplSLib.
- Add BSplSLib::UnitWeights(nU, nV) returning a non-owning
  NCollection_Array2 view when nU*nV <= 2049, heap-allocated otherwise.

Always-populated myWeights (Geom/Geom2d curve and surface classes):
- myWeights is now always sized to match poles count.
  Non-rational: non-owning view via UnitWeights (zero allocation).
  Rational: owning array with actual weight values.
- Add WeightsArray() returning const NCollection_Array1<double>& (curves)
  or const NCollection_Array2<double>& (surfaces) that is always valid.
- Update all constructors, copy constructors, and restructuring operations
  (IncreaseDegree, InsertKnots, RemoveKnot, Segment, SetPeriodic,
  SetOrigin, SetNotPeriodic, ExchangeUV, etc.) to maintain the invariant.
- SetWeight: copies non-owning view to owned array before mutation when
  transitioning to rational; assigns UnitWeights when becoming non-rational.
- Remove myRational derivation from myWeights.Size() in updateKnots();
  rationality is now tracked explicitly via the myRational flag only.
- Fix Geom2d_BSplineCurve::InsertPoleAfter missing myRational update
  after inserting a weighted pole.
- Fix Geom_BSplineCurve::DumpJson stale myWeights.Size() > 0 guard
  (changed to myRational, matching all other classes).

Caller migration to direct array access (~100 files):
- Replace deprecated copy-out pattern (allocate temp + call Foo(temp))
  with const-reference access for Poles(), Knots(), Multiplicities(),
  UKnots(), VKnots(), UMultiplicities(), VMultiplicities(),
  KnotSequence(), UKnotSequence(), VKnotSequence().
- Replace Weights() null-pointer patterns with WeightsArray() const-ref
  or *Weights() dereference where null check is still appropriate.
- Affected modules: GeomConvert, Geom2dConvert, GeomLib, GeomFill,
  ProjLib, ShapeUpgrade, ShapeCustom, ShapeConstruct, ShapeAnalysis,
  ShapeAlgo, BRepLib, BRepGProp, HLRBRep, ChFi3d, ChFiKPart, BlendFunc,
  FairCurve, IntTools, TopOpeBRepTool, TopOpeBRepBuild, LocOpe,
  BRepOffset, Adaptor3d, GeomAdaptor, Geom2dAdaptor, BndLib, Extrema,
  DrawTrSurf, GeometryTest, GeomliteTest, SWDRAW, QABugs,
  GeomToIGES, IGESToBRep, GeomToStep, StdPrs.

Bug fix in Hermit.cxx (PolyTest, both 3D and 2D overloads):
- Fix typo: "Pole0 < 3" changed to "Pole0 < Pole3" — was comparing
  a double variable against the integer literal 3 instead of the
  variable Pole3 holding the endpoint weight value.
- Fix logic: "if (boucle == 1)" changed to "else if (boucle == 1)"
  to make the boucle==1 and boucle==2 branches mutually exclusive.
- Add explanatory comments on BSplCLib::D1 calls that intentionally
  pass weight values as scalar "poles" to evaluate the weight function.

NCollection_PackedMapAlgo migration (TDataStd, QABugs):
- Replace deprecated member functions (IsSubset, Subtraction, Subtract,
  Unite, Intersect, IsEqual) with NCollection_PackedMapAlgo free functions.

GTests:
- New BSplCLib_Test.cxx: 5 tests for UnitWeights API.
- New BSplSLib_Test.cxx: 5 tests for surface UnitWeights API.
- New Hermit_Test.cxx: 11 tests for Hermit::Solution (3D/2D) and
  Hermit::Solutionbis covering uniform, distinct, high-ratio, reversed,
  symmetric weights and positive-poles invariant.
- Add WeightsArray tests to Geom_BSplineCurve_Test, Geom_BezierCurve_Test,
  Geom_BSplineSurface_Test, Geom_BezierSurface_Test (2 tests each)
  verifying const-ref return, non-owning for non-rational, owning for
  rational.
This commit is contained in:
Pasukhin Dmitry
2026-02-10 18:41:34 +00:00
committed by GitHub
parent 8949fd25f9
commit 964a2c75df
125 changed files with 2024 additions and 1678 deletions
@@ -61,8 +61,7 @@ static void GeomLib_ChangeUBounds(occ::handle<Geom_BSplineSurface>& aSurface,
const double newU1,
const double newU2)
{
NCollection_Array1<double> knots(1, aSurface->NbUKnots());
aSurface->UKnots(knots);
NCollection_Array1<double> knots(aSurface->UKnots());
BSplCLib::Reparametrize(newU1, newU2, knots);
aSurface->SetUKnots(knots);
}
@@ -71,8 +70,7 @@ static void GeomLib_ChangeVBounds(occ::handle<Geom_BSplineSurface>& aSurface,
const double newV1,
const double newV2)
{
NCollection_Array1<double> knots(1, aSurface->NbVKnots());
aSurface->VKnots(knots);
NCollection_Array1<double> 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<double> knots(1, BC->NbKnots());
BC->Knots(knots);
NCollection_Array1<double> knots(BC->Knots());
BSplCLib::Reparametrize(f, l, knots);
BC->SetKnots(knots);
}
@@ -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));
}
}
TEST_F(Geom2d_BSplineCurve_Test, WeightsArray_NonRational_ReturnsUnitWeights)
{
ASSERT_FALSE(myOriginalCurve->IsRational());
const NCollection_Array1<double>& 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<gp_Pnt2d> 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<double> aWeightsIn(1, 4);
aWeightsIn(1) = 1.0;
aWeightsIn(2) = 2.0;
aWeightsIn(3) = 3.0;
aWeightsIn(4) = 1.0;
NCollection_Array1<double> aKnots(1, 2);
aKnots(1) = 0.0;
aKnots(2) = 1.0;
NCollection_Array1<int> aMults(1, 2);
aMults(1) = 4;
aMults(2) = 4;
occ::handle<Geom2d_BSplineCurve> aRational =
new Geom2d_BSplineCurve(aPoles, aWeightsIn, aKnots, aMults, 3);
ASSERT_TRUE(aRational->IsRational());
const NCollection_Array1<double>& 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());
}
@@ -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));
}
}
TEST_F(Geom2d_BezierCurve_Test, WeightsArray_NonRational_ReturnsUnitWeights)
{
ASSERT_FALSE(myOriginalCurve->IsRational());
const NCollection_Array1<double>& 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<gp_Pnt2d> aPoles(1, 3);
aPoles(1) = gp_Pnt2d(0, 0);
aPoles(2) = gp_Pnt2d(1, 1);
aPoles(3) = gp_Pnt2d(2, 0);
NCollection_Array1<double> aWeightsIn(1, 3);
aWeightsIn(1) = 1.0;
aWeightsIn(2) = 2.0;
aWeightsIn(3) = 1.0;
occ::handle<Geom2d_BezierCurve> aRational = new Geom2d_BezierCurve(aPoles, aWeightsIn);
ASSERT_TRUE(aRational->IsRational());
const NCollection_Array1<double>& 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());
}
@@ -97,7 +97,8 @@ occ::handle<Geom2d_Geometry> Geom2d_BSplineCurve::Copy() const
Geom2d_BSplineCurve::Geom2d_BSplineCurve(const Geom2d_BSplineCurve& theOther)
: myPoles(theOther.myPoles),
myWeights(theOther.myWeights),
myWeights(theOther.myRational ? NCollection_Array1<double>(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<gp_Pnt2d>& 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<gp_Pnt2d>& 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<double>& 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<double>(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<double>();
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;
@@ -818,6 +818,13 @@ public:
//! Returns the weights of the B-spline curve;
Standard_EXPORT const NCollection_Array1<double>* 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<double>& WeightsArray() const { return myWeights; }
//! Applies the transformation T to this BSpline curve.
Standard_EXPORT void Transform(const gp_Trsf2d& T) override;
@@ -103,7 +103,8 @@ Geom2d_BezierCurve::Geom2d_BezierCurve(const NCollection_Array1<gp_Pnt2d>& Poles
Geom2d_BezierCurve::Geom2d_BezierCurve(const Geom2d_BezierCurve& theOther)
: myPoles(theOther.myPoles),
myWeights(theOther.myWeights),
myWeights(theOther.myRational ? NCollection_Array1<double>(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<double>(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<double>();
myWeights = BSplCLib::UnitWeights(nbpoles);
}
else
myRational = true;
@@ -619,13 +619,13 @@ void Geom2d_BezierCurve::init(const NCollection_Array1<gp_Pnt2d>& thePoles,
myRational = Rational(myWeights);
if (!myRational)
{
myWeights = NCollection_Array1<double>();
myWeights = BSplCLib::UnitWeights(nbpoles);
}
}
else
{
myRational = false;
myWeights = NCollection_Array1<double>();
myWeights = BSplCLib::UnitWeights(nbpoles);
}
myMaxDerivInv = 0.0;
@@ -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<double>& WeightsArray() const { return myWeights; }
//! Applies the transformation T to this Bezier curve.
Standard_EXPORT void Transform(const gp_Trsf2d& T) override;
@@ -109,15 +109,13 @@ occ::handle<Adaptor2d_Curve2d> 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<BSplineData>(myCurveData).Curve;
int Nb = aBSpline->NbKnots();
int Index1 = 0;
int Index2 = 0;
double newFirst, newLast;
NCollection_Array1<double> TK(1, Nb);
NCollection_Array1<int> TM(1, Nb);
aBSpline->Knots(TK);
aBSpline->Multiplicities(TM);
const auto& aBSpline = std::get<BSplineData>(myCurveData).Curve;
int Nb = aBSpline->NbKnots();
int Index1 = 0;
int Index2 = 0;
double newFirst, newLast;
const NCollection_Array1<double>& TK = aBSpline->Knots();
const NCollection_Array1<int>& TM = aBSpline->Multiplicities();
BSplCLib::LocateParameter(aBSpline->Degree(),
TK,
TM,
@@ -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<double> 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<double>& 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<double> Arr1(1, BSplS->NbUKnots());
BSplS->UKnots(Arr1); // Up1=Arr1.Upper(); Down1=Arr1.Lower();
const NCollection_Array1<double>& Arr1 = BSplS->UKnots();
FindBounds(Arr1, cur, DUV.X(), Bnd1, Bnd2, DIsNull);
}
else if (Index == 2)
{
NCollection_Array1<double> Arr2(1, BSplS->NbVKnots());
BSplS->VKnots(Arr2); // Up2=Arr2.Upper(); Down2=Arr2.Lower();
const NCollection_Array1<double>& Arr2 = BSplS->VKnots();
FindBounds(Arr2, cur, DUV.Y(), Bnd1, Bnd2, DIsNull);
}
@@ -1456,9 +1453,8 @@ occ::handle<Geom_BezierCurve> Adaptor3d_CurveOnSurface::Bezier() const
if (Bez2d->IsRational())
{
NCollection_Array1<double> Weights(1, NbPoles);
Bez2d->Weights(Weights);
Bez = new Geom_BezierCurve(Poles, Weights);
const NCollection_Array1<double>& Weights = Bez2d->WeightsArray();
Bez = new Geom_BezierCurve(Poles, Weights);
}
else
{
@@ -1485,17 +1481,14 @@ occ::handle<Geom_BSplineCurve> Adaptor3d_CurveOnSurface::BSpline() const
Poles(i) = to3d(Plane, Bsp2d->Pole(i));
}
NCollection_Array1<double> Knots(1, Bsp2d->NbKnots());
NCollection_Array1<int> Mults(1, Bsp2d->NbKnots());
Bsp2d->Knots(Knots);
Bsp2d->Multiplicities(Mults);
const NCollection_Array1<double>& Knots = Bsp2d->Knots();
const NCollection_Array1<int>& Mults = Bsp2d->Multiplicities();
occ::handle<Geom_BSplineCurve> Bsp;
if (Bsp2d->IsRational())
{
NCollection_Array1<double> Weights(1, NbPoles);
Bsp2d->Weights(Weights);
const NCollection_Array1<double>& 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<double> ArrU(1, BSplS->NbUKnots());
BSplS->UKnots(ArrU);
const NCollection_Array1<double>& ArrU = BSplS->UKnots();
Locate2Coord(1, UV, DUV, BSplS, ArrU, LeftBot, RightTop);
}
else if ((DVIsNull) && (!DUIsNull))
{
NCollection_Array1<double> ArrV(1, BSplS->NbVKnots());
BSplS->VKnots(ArrV);
const NCollection_Array1<double>& ArrV = BSplS->VKnots();
Locate2Coord(2, UV, DUV, BSplS, ArrV, LeftBot, RightTop);
}
}
@@ -849,11 +849,10 @@ void Adaptor3d_TopolTool::ComputeSamplePoints()
{
if (nbsu > 8 || nbsv > 8)
{
const occ::handle<Geom_BSplineSurface>& Bspl = myS->BSpline();
int nbup = Bspl->NbUPoles();
int nbvp = Bspl->NbVPoles();
NCollection_Array2<gp_Pnt> array2(1, nbup, 1, nbvp);
Bspl->Poles(array2);
const occ::handle<Geom_BSplineSurface>& Bspl = myS->BSpline();
const NCollection_Array2<gp_Pnt>& 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<Geom_BezierSurface>& Bez = myS->Bezier();
int nbup = Bez->NbUPoles();
int nbvp = Bez->NbVPoles();
NCollection_Array2<gp_Pnt> array2(1, nbup, 1, nbvp);
Bez->Poles(array2);
const occ::handle<Geom_BezierSurface>& Bez = myS->Bezier();
const NCollection_Array2<gp_Pnt>& array2 = Bez->Poles();
int nbup = array2.NbRows();
int nbvp = array2.NbColumns();
Analyse(array2, nbup, nbvp, nbsu, nbsv);
}
}
@@ -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);
}
}
TEST_F(Geom_BSplineCurve_Test, WeightsArray_NonRational_ReturnsUnitWeights)
{
ASSERT_FALSE(myOriginalCurve->IsRational());
const NCollection_Array1<double>& 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<gp_Pnt> 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<double> aWeightsIn(1, 4);
aWeightsIn(1) = 1.0;
aWeightsIn(2) = 2.0;
aWeightsIn(3) = 3.0;
aWeightsIn(4) = 1.0;
NCollection_Array1<double> aKnots(1, 2);
aKnots(1) = 0.0;
aKnots(2) = 1.0;
NCollection_Array1<int> aMults(1, 2);
aMults(1) = 4;
aMults(2) = 4;
occ::handle<Geom_BSplineCurve> aRational =
new Geom_BSplineCurve(aPoles, aWeightsIn, aKnots, aMults, 3);
ASSERT_TRUE(aRational->IsRational());
const NCollection_Array1<double>& 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());
}
@@ -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);
}
}
TEST_F(Geom_BSplineSurface_Test, WeightsArray_NonRational_ReturnsUnitWeights)
{
ASSERT_FALSE(myOriginalSurface->IsURational());
ASSERT_FALSE(myOriginalSurface->IsVRational());
const NCollection_Array2<double>& 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<gp_Pnt> aPoles(1, 3, 1, 3);
NCollection_Array2<double> 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<double> aKnotsU(1, 2), aKnotsV(1, 2);
aKnotsU(1) = 0.0;
aKnotsU(2) = 1.0;
aKnotsV(1) = 0.0;
aKnotsV(2) = 1.0;
NCollection_Array1<int> aMultsU(1, 2), aMultsV(1, 2);
aMultsU(1) = 3;
aMultsU(2) = 3;
aMultsV(1) = 3;
aMultsV(2) = 3;
occ::handle<Geom_BSplineSurface> aRational =
new Geom_BSplineSurface(aPoles, aWeightsIn, aKnotsU, aKnotsV, aMultsU, aMultsV, 2, 2);
const NCollection_Array2<double>& 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());
}
@@ -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);
}
}
TEST_F(Geom_BezierCurve_Test, WeightsArray_NonRational_ReturnsUnitWeights)
{
ASSERT_FALSE(myOriginalCurve->IsRational());
const NCollection_Array1<double>& 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<gp_Pnt> 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<double> aWeightsIn(1, 3);
aWeightsIn(1) = 1.0;
aWeightsIn(2) = 2.0;
aWeightsIn(3) = 1.0;
occ::handle<Geom_BezierCurve> aRational = new Geom_BezierCurve(aPoles, aWeightsIn);
ASSERT_TRUE(aRational->IsRational());
const NCollection_Array1<double>& 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());
}
@@ -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);
}
}
TEST_F(Geom_BezierSurface_Test, WeightsArray_NonRational_ReturnsUnitWeights)
{
ASSERT_FALSE(myOriginalSurface->IsURational());
ASSERT_FALSE(myOriginalSurface->IsVRational());
const NCollection_Array2<double>& 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<gp_Pnt> aPoles(1, 2, 1, 2);
NCollection_Array2<double> 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<Geom_BezierSurface> aRational = new Geom_BezierSurface(aPoles, aWeightsIn);
const NCollection_Array2<double>& 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());
}
@@ -100,7 +100,8 @@ occ::handle<Geom_Geometry> Geom_BSplineCurve::Copy() const
Geom_BSplineCurve::Geom_BSplineCurve(const Geom_BSplineCurve& theOther)
: myPoles(theOther.myPoles),
myWeights(theOther.myWeights),
myWeights(theOther.myRational ? NCollection_Array1<double>(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<gp_Pnt>& 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<gp_Pnt>& 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<double>& 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<double>(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<double>();
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())
@@ -784,6 +784,13 @@ public:
//! Returns the weights of the B-spline curve;
Standard_EXPORT const NCollection_Array1<double>* 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<double>& WeightsArray() const { return myWeights; }
//! Applies the transformation T to this BSpline curve.
Standard_EXPORT void Transform(const gp_Trsf& T) override;
@@ -132,7 +132,10 @@ occ::handle<Geom_Geometry> 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<double>(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<gp_Pnt>& 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<gp_Pnt>& 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<double>(myWeights);
}
myWeights(UIndex + myWeights.LowerRow() - 1, VIndex + myWeights.LowerCol() - 1) = Weight;
Rational(myWeights, myURational, myVRational);
if (!myURational && !myVRational)
myWeights = NCollection_Array2<double>();
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<double>(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<double>();
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<double>(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<double>();
myWeights = BSplSLib::UnitWeights(myPoles.ColLength(), myPoles.RowLength());
myMaxDerivInvOk = false;
}
@@ -1072,6 +1072,13 @@ public:
Standard_DEPRECATED("use Weights() returning const pointer instead")
Standard_EXPORT void Weights(NCollection_Array2<double>& 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<double>& WeightsArray() const { return myWeights; }
//! Returns the weights of the B-spline surface.
//! value and derivatives computation
Standard_EXPORT const NCollection_Array2<double>* Weights() const;
@@ -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<double>& 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<double>& 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);
@@ -63,7 +63,8 @@ static bool Rational(const NCollection_Array1<double>& W)
Geom_BezierCurve::Geom_BezierCurve(const Geom_BezierCurve& theOther)
: myPoles(theOther.myPoles),
myWeights(theOther.myWeights),
myWeights(theOther.myRational ? NCollection_Array1<double>(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<double>(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<double>();
myWeights = BSplCLib::UnitWeights(nbpoles);
}
else
myRational = true;
@@ -659,13 +659,13 @@ void Geom_BezierCurve::init(const NCollection_Array1<gp_Pnt>& thePoles,
myRational = Rational(myWeights);
if (!myRational)
{
myWeights = NCollection_Array1<double>();
myWeights = BSplCLib::UnitWeights(nbpoles);
}
}
else
{
myRational = false;
myWeights = NCollection_Array1<double>();
myWeights = BSplCLib::UnitWeights(nbpoles);
}
myMaxDerivInv = 0.0;
@@ -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<double>& WeightsArray() const { return myWeights; }
//! Applies the transformation T to this Bezier curve.
Standard_EXPORT void Transform(const gp_Trsf& T) override;
@@ -359,7 +359,10 @@ static void DeleteRatPoleRow(const NCollection_Array2<gp_Pnt>& Poles,
Geom_BezierSurface::Geom_BezierSurface(const Geom_BezierSurface& theOther)
: myPoles(theOther.myPoles),
myWeights(theOther.myWeights),
myWeights(
(theOther.myURational || theOther.myVRational)
? NCollection_Array2<double>(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<double>();
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<double>(myWeights);
}
NCollection_Array2<gp_Pnt> 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<double>(myWeights);
}
NCollection_Array2<gp_Pnt> 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<double>();
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<double>();
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<double>(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<double>();
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<double>(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<double>();
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<double>(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<double>();
myWeights = BSplSLib::UnitWeights(myPoles.ColLength(), myPoles.RowLength());
}
myMaxDerivInvOk = false;
}
@@ -1922,14 +1940,14 @@ void Geom_BezierSurface::init(const NCollection_Array2<gp_Pnt>& thePoles,
Rational(myWeights, myURational, myVRational);
if (!(myURational || myVRational))
{
myWeights = NCollection_Array2<double>();
myWeights = BSplSLib::UnitWeights(NbUPoles, NbVPoles);
}
}
else
{
myURational = false;
myVRational = false;
myWeights = NCollection_Array2<double>();
myWeights = BSplSLib::UnitWeights(NbUPoles, NbVPoles);
}
myMaxDerivInvOk = false;
@@ -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<double>& 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.
@@ -463,11 +463,8 @@ GeomAbs_Shape GeomAdaptor_Surface::UContinuity() const
{
case GeomAbs_BSplineSurface: {
const auto& aBSpl = std::get<BSplineData>(mySurfaceData).Surface;
const int N = aBSpl->NbUKnots();
NCollection_Array1<double> TK(1, N);
NCollection_Array1<int> TM(1, N);
aBSpl->UKnots(TK);
aBSpl->UMultiplicities(TM);
NCollection_Array1<double> TK(aBSpl->UKnots());
NCollection_Array1<int> 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<BSplineData>(mySurfaceData).Surface;
const int N = aBSpl->NbVKnots();
NCollection_Array1<double> TK(1, N);
NCollection_Array1<int> TM(1, N);
aBSpl->VKnots(TK);
aBSpl->VMultiplicities(TM);
NCollection_Array1<double> TK(aBSpl->VKnots());
NCollection_Array1<int> TM(aBSpl->VMultiplicities());
return LocalContinuity(aBSpl->VDegree(),
aBSpl->NbVKnots(),
TK,
@@ -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<double> 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<double>& Knots = Bs->Knots();
GeomAdaptor_Curve GACurve(Bs);
double first = Knots(k1), last;
for (k = k1 + 1; k <= k2; k++)
{
last = Knots(k);
@@ -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<int> aMults(1, aBS->NbUKnots());
NCollection_Array1<double> aKnots(1, aBS->NbUKnots());
aBS->UKnots(aKnots);
aBS->UMultiplicities(aMults);
const NCollection_Array1<int>& aMults = aBS->UMultiplicities();
const NCollection_Array1<double>& 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<int> aMults(1, aBS->NbVKnots());
NCollection_Array1<double> aKnots(1, aBS->NbVKnots());
aBS->VKnots(aKnots);
aBS->VMultiplicities(aMults);
const NCollection_Array1<int>& aMults = aBS->VMultiplicities();
const NCollection_Array1<double>& aKnots = aBS->VKnots();
ComputePolesIndexes(aKnots,
aMults,
@@ -188,10 +188,10 @@ public:
return;
}
case GeomAbs_BSplineCurve: {
const int aFirstIdx = TheCurveTool::BSpline(aCurve)->FirstUKnotIndex(),
aLastIdx = TheCurveTool::BSpline(aCurve)->LastUKnotIndex();
NCollection_Array1<double> 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<double>& 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)
{
@@ -370,10 +370,8 @@ void Extrema_GenExtPS::GetGridPoints(const Adaptor3d_Surface& theSurf)
occ::handle<Geom_BSplineSurface> aBspl = theSurf.BSpline();
if (!aBspl.IsNull())
{
NCollection_Array1<double> aUKnots(1, aBspl->NbUKnots());
aBspl->UKnots(aUKnots);
NCollection_Array1<double> aVKnots(1, aBspl->NbVKnots());
aBspl->VKnots(aVKnots);
const NCollection_Array1<double>& aUKnots = aBspl->UKnots();
const NCollection_Array1<double>& 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<Geom_BSplineCurve> aBspl = theSurf.BasisCurve()->BSpline();
if (!aBspl.IsNull())
{
anArrKnots = new NCollection_HArray1<double>(1, aBspl->NbKnots());
aBspl->Knots(anArrKnots->ChangeArray1());
aDegree = aBspl->Degree();
anArrKnots = new NCollection_HArray1<double>(aBspl->Knots());
aDegree = aBspl->Degree();
}
}
if (theSurf.BasisCurve()->GetType() == GeomAbs_BezierCurve)
@@ -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
)
@@ -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 <gtest/gtest.h>
#include <Hermit.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <Geom_BSplineCurve.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pnt2d.hxx>
#include <NCollection_Array1.hxx>
#include <Precision.hxx>
// 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<gp_Pnt> 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<double> aWeights(1, 3);
aWeights(1) = theW1;
aWeights(2) = theW2;
aWeights(3) = theW3;
NCollection_Array1<double> aKnots(1, 2);
aKnots(1) = 0.0;
aKnots(2) = 1.0;
NCollection_Array1<int> 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<gp_Pnt2d> 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<double> aWeights(1, 3);
aWeights(1) = theW1;
aWeights(2) = theW2;
aWeights(3) = theW3;
NCollection_Array1<double> aKnots(1, 2);
aKnots(1) = 0.0;
aKnots(2) = 1.0;
NCollection_Array1<int> 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);
}
@@ -310,21 +310,17 @@ occ::handle<Geom2d_BSplineCurve> Geom2dConvert::CurveToBSplineCurve(
occ::handle<Geom2d_BezierCurve> CBez = occ::down_cast<Geom2d_BezierCurve>(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<Geom2d_BSplineCurve> Geom2dConvert::CurveToBSplineCurve(
{
occ::handle<Geom2d_BezierCurve> CBez = occ::down_cast<Geom2d_BezierCurve>(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<Geom2d_BSplineCurve> MultNumandDenom(const occ::handle<Geom2d
const occ::handle<Geom2d_BSplineCurve>& BS)
{
NCollection_Array1<double> aKnots(1, a->NbKnots());
NCollection_Array1<double> BSKnots(1, BS->NbKnots());
NCollection_Array1<double> BSFlatKnots(1, BS->NbPoles() + BS->Degree() + 1);
NCollection_Array1<double> BSWeights(1, BS->NbPoles());
NCollection_Array1<int> aMults(1, a->NbKnots());
NCollection_Array1<int> BSMults(1, BS->NbKnots());
NCollection_Array1<gp_Pnt2d> aPoles(1, a->NbPoles());
NCollection_Array1<gp_Pnt2d> BSPoles(1, BS->NbPoles());
occ::handle<Geom2d_BSplineCurve> res;
occ::handle<NCollection_HArray1<double>> resKnots;
occ::handle<NCollection_HArray1<int>> 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<double>& BSKnots = BS->Knots();
const NCollection_Array1<int>& BSMults = BS->Multiplicities();
NCollection_Array1<gp_Pnt2d> BSPoles(BS->Poles());
const NCollection_Array1<double>& BSWeights = BS->WeightsArray();
const NCollection_Array1<double>& 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<double> aKnots(a->Knots());
const NCollection_Array1<gp_Pnt2d>& aPoles = a->Poles();
const NCollection_Array1<int>& aMults = a->Multiplicities();
BSplCLib::Reparametrize(BS->FirstParameter(), BS->LastParameter(), aKnots);
occ::handle<Geom2d_BSplineCurve> anAncore =
new Geom2d_BSplineCurve(aPoles, aKnots, aMults, a->Degree());
@@ -586,10 +570,9 @@ static void Pretreatment(NCollection_Array1<occ::handle<Geom2d_BSplineCurve>>& t
static bool NeedToBeTreated(const occ::handle<Geom2d_BSplineCurve>& BS)
{
NCollection_Array1<double> tabWeights(1, BS->NbPoles());
if (BS->IsRational())
{
BS->Weights(tabWeights);
const NCollection_Array1<double>& 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<double> KnotC1(1, Curve1->NbKnots());
Curve1->Knots(KnotC1);
NCollection_Array1<double> 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<double> Curve1FlatKnots(1, Curve1->NbPoles() + Curve1->Degree() + 1);
NCollection_Array1<int> KnotC1Mults(1, Curve1->NbKnots());
Curve1->Multiplicities(KnotC1Mults);
NCollection_Array1<int> 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<gp_Pnt2d> Curve1Poles(1, Curve1->NbPoles());
Curve1->Poles(Curve1Poles);
NCollection_Array1<gp_Pnt2d> 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<gp_Pnt2d> NewPoles(1, FlatKnots.Length() - (2 * Curve1->Degree() + 1));
int aStatus;
NCollection_Array1<double> Curve1Weights(1, Curve1->NbPoles());
Curve1->Weights(Curve1Weights);
const NCollection_Array1<double>& 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<double> KnotC1(1, Curve1->NbKnots());
Curve1->Knots(KnotC1);
NCollection_Array1<double> 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<double> Curve1FlatKnots(1, Curve1->NbPoles() + Curve1->Degree() + 1);
NCollection_Array1<int> KnotC1Mults(1, Curve1->NbKnots());
Curve1->Multiplicities(KnotC1Mults);
NCollection_Array1<int> 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<gp_Pnt2d> Curve1Poles(1, Curve1->NbPoles());
Curve1->Poles(Curve1Poles);
NCollection_Array1<gp_Pnt2d> 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<gp_Pnt2d> NewPoles(1, FlatKnots.Length() - (aNewCurveDegree + 1));
int aStatus;
NCollection_Array1<double> Curve1Weights(1, Curve1->NbPoles());
Curve1->Weights(Curve1Weights);
NCollection_Array1<gp_Pnt2d> NewPoles(1, FlatKnots.Length() - (aNewCurveDegree + 1));
int aStatus;
const NCollection_Array1<double>& 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<Geom2d_BSplineCurve>&
const double tolerance)
{
NCollection_Array1<int> BSMults(1, BS->NbKnots());
NCollection_Array1<double> 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<int>& BSMults = BS->Multiplicities();
const NCollection_Array1<double>& 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<int> BSMults(1, BS->NbKnots());
NCollection_Array1<double> 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<int>& BSMults = BS->Multiplicities();
const NCollection_Array1<double>& 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())
@@ -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);
@@ -286,21 +286,17 @@ occ::handle<Geom_BSplineCurve> GeomConvert::CurveToBSplineCurve(
occ::handle<Geom_BezierCurve> CBez = occ::down_cast<Geom_BezierCurve>(Curv->Copy());
CBez->Segment(U1, U2);
int NbPoles = CBez->NbPoles();
int Degree = CBez->Degree();
NCollection_Array1<gp_Pnt> Poles(1, NbPoles);
NCollection_Array1<double> Knots(1, 2);
NCollection_Array1<int> Mults(1, 2);
int Degree = CBez->Degree();
const NCollection_Array1<gp_Pnt>& Poles = CBez->Poles();
NCollection_Array1<double> Knots(1, 2);
NCollection_Array1<int> 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<double> 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<Geom_BSplineCurve> GeomConvert::CurveToBSplineCurve(
else if (C->IsKind(STANDARD_TYPE(Geom_BezierCurve)))
{
occ::handle<Geom_BezierCurve> CBez = occ::down_cast<Geom_BezierCurve>(C);
int NbPoles = CBez->NbPoles();
int Degree = CBez->Degree();
NCollection_Array1<gp_Pnt> Poles(1, NbPoles);
NCollection_Array1<double> Knots(1, 2);
NCollection_Array1<int> Mults(1, 2);
occ::handle<Geom_BezierCurve> CBez = occ::down_cast<Geom_BezierCurve>(C);
int Degree = CBez->Degree();
const NCollection_Array1<gp_Pnt>& Poles = CBez->Poles();
NCollection_Array1<double> Knots(1, 2);
NCollection_Array1<int> 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<double> 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<Geom_BSplineCurve> MultNumandDenom(const occ::handle<Geom2d_B
const occ::handle<Geom_BSplineCurve>& BS)
{
NCollection_Array1<double> aKnots(1, a->NbKnots());
NCollection_Array1<double> BSKnots(1, BS->NbKnots());
NCollection_Array1<double> BSFlatKnots(1, BS->NbPoles() + BS->Degree() + 1);
NCollection_Array1<double> BSWeights(1, BS->NbPoles());
NCollection_Array1<int> aMults(1, a->NbKnots());
NCollection_Array1<int> BSMults(1, BS->NbKnots());
NCollection_Array1<gp_Pnt2d> aPoles(1, a->NbPoles());
NCollection_Array1<gp_Pnt> BSPoles(1, BS->NbPoles());
const NCollection_Array1<double>& BSKnots = BS->Knots();
const NCollection_Array1<int>& BSMults = BS->Multiplicities();
NCollection_Array1<gp_Pnt> BSPoles(BS->Poles());
const NCollection_Array1<double>& BSWeights = BS->WeightsArray();
const NCollection_Array1<double>& BSFlatKnots = BS->KnotSequence();
occ::handle<Geom_BSplineCurve> res;
occ::handle<NCollection_HArray1<double>> resKnots;
occ::handle<NCollection_HArray1<int>> resMults;
@@ -499,19 +488,14 @@ static occ::handle<Geom_BSplineCurve> MultNumandDenom(const occ::handle<Geom2d_B
double tolerance = Precision::PConfusion();
int resNbPoles, degree, ii, jj, aStatus;
BS->Knots(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<double> aKnots(a->Knots());
const NCollection_Array1<gp_Pnt2d>& aPoles = a->Poles();
const NCollection_Array1<int>& aMults = a->Multiplicities();
BSplCLib::Reparametrize(BS->FirstParameter(), BS->LastParameter(), aKnots);
occ::handle<Geom2d_BSplineCurve> anAncore =
new Geom2d_BSplineCurve(aPoles, aKnots, aMults, a->Degree());
@@ -600,10 +584,9 @@ static void Pretreatment(NCollection_Array1<occ::handle<Geom_BSplineCurve>>& tab
static bool NeedToBeTreated(const occ::handle<Geom_BSplineCurve>& BS)
{
NCollection_Array1<double> tabWeights(1, BS->NbPoles());
if (BS->IsRational())
{
BS->Weights(tabWeights);
const NCollection_Array1<double>& 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<double> KnotC1(1, Curve1->NbKnots());
Curve1->Knots(KnotC1);
NCollection_Array1<double> 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<double> Curve1FlatKnots(1, Curve1->NbPoles() + Curve1->Degree() + 1);
NCollection_Array1<int> KnotC1Mults(1, Curve1->NbKnots());
Curve1->Multiplicities(KnotC1Mults);
NCollection_Array1<int> 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<gp_Pnt> Curve1Poles(1, Curve1->NbPoles());
Curve1->Poles(Curve1Poles);
NCollection_Array1<gp_Pnt> 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<gp_Pnt> NewPoles(1, FlatKnots.Length() - (2 * Curve1->Degree() + 1));
int aStatus;
NCollection_Array1<double> Curve1Weights(1, Curve1->NbPoles());
Curve1->Weights(Curve1Weights);
const NCollection_Array1<double>& 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<double> KnotC1(1, Curve1->NbKnots());
Curve1->Knots(KnotC1);
NCollection_Array1<double> 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<double> Curve1FlatKnots(1, Curve1->NbPoles() + Curve1->Degree() + 1);
NCollection_Array1<int> KnotC1Mults(1, Curve1->NbKnots());
Curve1->Multiplicities(KnotC1Mults);
NCollection_Array1<int> 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<gp_Pnt> Curve1Poles(1, Curve1->NbPoles());
Curve1->Poles(Curve1Poles);
NCollection_Array1<gp_Pnt> 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<gp_Pnt> NewPoles(1, FlatKnots.Length() - (2 * Curve1->Degree() + 1));
int aStatus;
NCollection_Array1<double> Curve1Weights(1, Curve1->NbPoles());
Curve1->Weights(Curve1Weights);
const NCollection_Array1<double>& 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<int> BSMults(1, BS->NbKnots());
NCollection_Array1<double> 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<int>& BSMults = BS->Multiplicities();
const NCollection_Array1<double>& 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
@@ -515,17 +515,13 @@ occ::handle<Geom_BSplineSurface> 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<gp_Pnt> Poles(1, NbVPoles);
C->Poles(Poles);
NCollection_Array1<double> Weights(1, NbVPoles);
Weights.Init(1.);
if (C->IsRational())
C->Weights(Weights);
NCollection_Array1<gp_Pnt> Poles(C->Poles());
const NCollection_Array1<double>& Weights = C->WeightsArray();
double AlfaU;
if (Strim->IsUPeriodic())
@@ -557,11 +553,8 @@ occ::handle<Geom_BSplineSurface> GeomConvert::SurfaceToBSplineSurface(
UMults(1)++;
UMults(NbUKnots)++;
}
NbVKnots = C->NbKnots();
NCollection_Array1<double> VKnots(1, NbVKnots);
NCollection_Array1<int> VMults(1, NbVKnots);
C->Knots(VKnots);
C->Multiplicities(VMults);
const NCollection_Array1<double>& VKnots = C->Knots();
const NCollection_Array1<int>& VMults = C->Multiplicities();
// Compute the poles.
NCollection_Array2<gp_Pnt> NewPoles(1, NbUPoles, 1, NbVPoles);
@@ -624,13 +617,11 @@ occ::handle<Geom_BSplineSurface> GeomConvert::SurfaceToBSplineSurface(
occ::handle<Geom_TrimmedCurve> CT = new Geom_TrimmedCurve(Meridian, UFirst, ULast);
C = GeomConvert::CurveToBSplineCurve(CT);
}
NCollection_Array2<gp_Pnt> Poles(1, C->NbPoles(), 1, 2);
NCollection_Array2<double> Weights(1, C->NbPoles(), 1, 2);
NCollection_Array1<double> UKnots(1, C->NbKnots());
C->Knots(UKnots);
NCollection_Array1<int> UMults(1, C->NbKnots());
C->Multiplicities(UMults);
NCollection_Array1<double> VKnots(1, 2);
NCollection_Array2<gp_Pnt> Poles(1, C->NbPoles(), 1, 2);
NCollection_Array2<double> Weights(1, C->NbPoles(), 1, 2);
const NCollection_Array1<double>& UKnots = C->Knots();
const NCollection_Array1<int>& UMults = C->Multiplicities();
NCollection_Array1<double> VKnots(1, 2);
VKnots(1) = VFirst;
VKnots(2) = VLast;
NCollection_Array1<int> VMults(1, 2);
@@ -663,35 +654,36 @@ occ::handle<Geom_BSplineSurface> GeomConvert::SurfaceToBSplineSurface(
occ::handle<Geom_BezierSurface> SBez = occ::down_cast<Geom_BezierSurface>(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<gp_Pnt> Poles(1, NbUPoles, 1, NbVPoles);
int UDegree = SBez->UDegree();
int VDegree = SBez->VDegree();
NCollection_Array1<double> UKnots(1, 2);
NCollection_Array1<int> UMults(1, 2);
NCollection_Array1<double> VKnots(1, 2);
NCollection_Array1<int> 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<gp_Pnt>& aPoles = SBez->Poles();
if (SBez->IsURational() || SBez->IsVRational())
{
NCollection_Array2<double> 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<Geom_BSplineSurface> GeomConvert::SurfaceToBSplineSurface(
occ::handle<Geom_BSplineCurve> C = GeomConvert::CurveToBSplineCurve(Meridian);
int NbUPoles, NbUKnots;
int NbVPoles, NbVKnots;
int NbVPoles;
bool periodic = true;
// Poles of meridian = Vpoles
NbVPoles = C->NbPoles();
NCollection_Array1<gp_Pnt> Poles(1, NbVPoles);
C->Poles(Poles);
NCollection_Array1<double> Weights(1, NbVPoles);
Weights.Init(1.);
if (C->IsRational())
C->Weights(Weights);
NCollection_Array1<gp_Pnt> Poles(C->Poles());
const NCollection_Array1<double>& Weights = C->WeightsArray();
double AlfaU;
NbUKnots = 4;
@@ -794,11 +782,8 @@ occ::handle<Geom_BSplineSurface> GeomConvert::SurfaceToBSplineSurface(
UKnots(i) = UFirst + (i - 1) * 2 * AlfaU;
UMults(i) = 2;
}
NbVKnots = C->NbKnots();
NCollection_Array1<double> VKnots(1, NbVKnots);
NCollection_Array1<int> VMults(1, NbVKnots);
C->Knots(VKnots);
C->Multiplicities(VMults);
const NCollection_Array1<double>& VKnots = C->Knots();
const NCollection_Array1<int>& VMults = C->Multiplicities();
// Compute the poles.
NCollection_Array2<gp_Pnt> NewPoles(1, NbUPoles, 1, NbVPoles);
@@ -850,35 +835,36 @@ occ::handle<Geom_BSplineSurface> GeomConvert::SurfaceToBSplineSurface(
occ::handle<Geom_BezierSurface> SBez = occ::down_cast<Geom_BezierSurface>(S);
int NbUPoles = SBez->NbUPoles();
int NbVPoles = SBez->NbVPoles();
int UDegree = SBez->UDegree();
int VDegree = SBez->VDegree();
NCollection_Array2<gp_Pnt> Poles(1, NbUPoles, 1, NbVPoles);
int UDegree = SBez->UDegree();
int VDegree = SBez->VDegree();
NCollection_Array1<double> UKnots(1, 2);
NCollection_Array1<int> UMults(1, 2);
NCollection_Array1<double> VKnots(1, 2);
NCollection_Array1<int> 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<gp_Pnt>& aPoles = SBez->Poles();
if (SBez->IsURational() || SBez->IsVRational())
{
NCollection_Array2<double> 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);
}
}
@@ -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);
@@ -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);
@@ -220,18 +220,11 @@ GeomConvert_CompBezierSurfacesToBSplineSurface::GeomConvert_CompBezierSurfacesTo
}
// Les nouveaux champs sont arrivees ....
myPoles = new (NCollection_HArray2<gp_Pnt>)(1, Surface->NbUPoles(), 1, Surface->NbVPoles());
Surface->Poles(myPoles->ChangeArray2());
myUMults = new (NCollection_HArray1<int>)(1, Surface->NbUKnots());
myVMults = new (NCollection_HArray1<int>)(1, Surface->NbVKnots());
myUKnots = new (NCollection_HArray1<double>)(1, Surface->NbUKnots());
myVKnots = new (NCollection_HArray1<double>)(1, Surface->NbVKnots());
Surface->UMultiplicities(myUMults->ChangeArray1());
Surface->VMultiplicities(myVMults->ChangeArray1());
Surface->UKnots(myUKnots->ChangeArray1());
Surface->VKnots(myVKnots->ChangeArray1());
myPoles = new NCollection_HArray2<gp_Pnt>(Surface->Poles());
myUMults = new NCollection_HArray1<int>(Surface->UMultiplicities());
myVMults = new NCollection_HArray1<int>(Surface->VMultiplicities());
myUKnots = new NCollection_HArray1<double>(Surface->UKnots());
myVKnots = new NCollection_HArray1<double>(Surface->VKnots());
}
// ============================================================================
@@ -344,10 +337,9 @@ GeomConvert_CompBezierSurfacesToBSplineSurface::GeomConvert_CompBezierSurfacesTo
}
// Les nouveaux champs sont arrivees ....
myPoles = new (NCollection_HArray2<gp_Pnt>)(1, Surface->NbUPoles(), 1, Surface->NbVPoles());
Surface->Poles(myPoles->ChangeArray2());
Surface->UMultiplicities(myUMults->ChangeArray1());
Surface->VMultiplicities(myVMults->ChangeArray1());
myPoles = new NCollection_HArray2<gp_Pnt>(Surface->Poles());
myUMults = new NCollection_HArray1<int>(Surface->UMultiplicities());
myVMults = new NCollection_HArray1<int>(Surface->VMultiplicities());
}
}
@@ -189,8 +189,7 @@ occ::handle<Geom_Line> GeomConvert_CurveToAnaCurve::ComputeLine(
if (!bsc.IsNull())
{
nbPoles = bsc->NbPoles();
Poles = new NCollection_HArray1<gp_Pnt>(1, nbPoles);
bsc->Poles(Poles->ChangeArray1());
Poles = new NCollection_HArray1<gp_Pnt>(bsc->Poles());
}
else
{
@@ -198,8 +197,7 @@ occ::handle<Geom_Line> GeomConvert_CurveToAnaCurve::ComputeLine(
if (!bzc.IsNull())
{
nbPoles = bzc->NbPoles();
Poles = new NCollection_HArray1<gp_Pnt>(1, nbPoles);
bzc->Poles(Poles->ChangeArray1());
Poles = new NCollection_HArray1<gp_Pnt>(bzc->Poles());
}
else
{
+49 -69
View File
@@ -591,11 +591,10 @@ occ::handle<Geom_Curve> GeomLib::To3d(const gp_Ax2& Position,
}
else if (KindOfCurve == STANDARD_TYPE(Geom2d_BezierCurve))
{
occ::handle<Geom2d_BezierCurve> CBez2d = occ::down_cast<Geom2d_BezierCurve>(Curve2d);
int Nbpoles = CBez2d->NbPoles();
NCollection_Array1<gp_Pnt2d> Poles2d(1, Nbpoles);
CBez2d->Poles(Poles2d);
NCollection_Array1<gp_Pnt> Poles3d(1, Nbpoles);
occ::handle<Geom2d_BezierCurve> CBez2d = occ::down_cast<Geom2d_BezierCurve>(Curve2d);
const NCollection_Array1<gp_Pnt2d>& Poles2d = CBez2d->Poles();
const int Nbpoles = Poles2d.Length();
NCollection_Array1<gp_Pnt> Poles3d(1, Nbpoles);
for (int i = 1; i <= Nbpoles; i++)
{
Poles3d(i) = ElCLib::To3d(Position, Poles2d(i));
@@ -603,9 +602,7 @@ occ::handle<Geom_Curve> GeomLib::To3d(const gp_Ax2& Position,
occ::handle<Geom_BezierCurve> CBez3d;
if (CBez2d->IsRational())
{
NCollection_Array1<double> 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<Geom_Curve> GeomLib::To3d(const gp_Ax2& Position,
}
else if (KindOfCurve == STANDARD_TYPE(Geom2d_BSplineCurve))
{
occ::handle<Geom2d_BSplineCurve> CBSpl2d = occ::down_cast<Geom2d_BSplineCurve>(Curve2d);
int Nbpoles = CBSpl2d->NbPoles();
int Nbknots = CBSpl2d->NbKnots();
int TheDegree = CBSpl2d->Degree();
bool IsPeriodic = CBSpl2d->IsPeriodic();
NCollection_Array1<gp_Pnt2d> Poles2d(1, Nbpoles);
CBSpl2d->Poles(Poles2d);
NCollection_Array1<gp_Pnt> Poles3d(1, Nbpoles);
occ::handle<Geom2d_BSplineCurve> CBSpl2d = occ::down_cast<Geom2d_BSplineCurve>(Curve2d);
const int TheDegree = CBSpl2d->Degree();
const bool IsPeriodic = CBSpl2d->IsPeriodic();
const NCollection_Array1<gp_Pnt2d>& Poles2d = CBSpl2d->Poles();
const int Nbpoles = Poles2d.Length();
NCollection_Array1<gp_Pnt> Poles3d(1, Nbpoles);
for (int i = 1; i <= Nbpoles; i++)
{
Poles3d(i) = ElCLib::To3d(Position, Poles2d(i));
}
NCollection_Array1<double> TheKnots(1, Nbknots);
NCollection_Array1<int> TheMults(1, Nbknots);
CBSpl2d->Knots(TheKnots);
CBSpl2d->Multiplicities(TheMults);
occ::handle<Geom_BSplineCurve> CBSpl3d;
const NCollection_Array1<double>& TheKnots = CBSpl2d->Knots();
const NCollection_Array1<int>& TheMults = CBSpl2d->Multiplicities();
occ::handle<Geom_BSplineCurve> CBSpl3d;
if (CBSpl2d->IsRational())
{
NCollection_Array1<double> 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<Geom2d_Curve> GeomLib::GTransform(const occ::handle<Geom2d_Curve>& C
// de la courbe de base.
occ::handle<Geom2d_BezierCurve> C = occ::down_cast<Geom2d_BezierCurve>(Curve->Copy());
int NbPoles = C->NbPoles();
NCollection_Array1<gp_Pnt2d> Poles(1, NbPoles);
C->Poles(Poles);
const int NbPoles = C->NbPoles();
NCollection_Array1<gp_Pnt2d> Poles(C->Poles());
for (int i = 1; i <= NbPoles; i++)
{
Poles(i).SetXY(GTrsf.Transformed(Poles(i).XY()));
@@ -822,9 +816,8 @@ occ::handle<Geom2d_Curve> GeomLib::GTransform(const occ::handle<Geom2d_Curve>& C
// Voir commentaire pour les Bezier.
occ::handle<Geom2d_BSplineCurve> C = occ::down_cast<Geom2d_BSplineCurve>(Curve->Copy());
int NbPoles = C->NbPoles();
NCollection_Array1<gp_Pnt2d> Poles(1, NbPoles);
C->Poles(Poles);
const int NbPoles = C->NbPoles();
NCollection_Array1<gp_Pnt2d> 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<Geom2d_BSplineCurve> BS = Geom2dConvert::CurveToBSplineCurve(TC);
NCollection_Array1<double> Knots(1, BS->NbKnots());
BS->Knots(Knots);
NCollection_Array1<double> Knots(BS->Knots());
BSplCLib::Reparametrize(RequestedFirst, RequestedLast, Knots);
@@ -978,8 +970,7 @@ void GeomLib::SameRange(const double Tolerance,
//
occ::handle<Geom2d_BSplineCurve> BS = Geom2dConvert::CurveToBSplineCurve(TC);
NCollection_Array1<double> Knots(1, BS->NbKnots());
BS->Knots(Knots);
NCollection_Array1<double> Knots(BS->Knots());
BSplCLib::Reparametrize(RequestedFirst, RequestedLast, Knots);
@@ -1562,12 +1553,11 @@ void GeomLib::ExtendSurfByLength(occ::handle<Geom_BoundedSurface>& Surface,
}
// the flat knots
Ksize = NbP + Cdeg + 1;
FKnots = new (NCollection_HArray1<double>)(1, Ksize);
Ksize = NbP + Cdeg + 1;
if (InU)
BS->UKnotSequence(FKnots->ChangeArray1());
FKnots = new NCollection_HArray1<double>(BS->UKnotSequence());
else
BS->VKnotSequence(FKnots->ChangeArray1());
FKnots = new NCollection_HArray1<double>(BS->VKnotSequence());
// the parameter of the connection knot
if (After)
@@ -1897,18 +1887,18 @@ void GeomLib::ExtendSurfByLength(occ::handle<Geom_BoundedSurface>& 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<Geom_BSplineSurface>& BSurf,
const double knotmax)
{
NCollection_Array1<double> surface_u_knots(1, BSurf->NbUKnots());
NCollection_Array1<int> surface_u_mults(1, BSurf->NbUKnots());
NCollection_Array1<double> surface_v_knots(1, BSurf->NbVKnots());
NCollection_Array1<int> surface_v_mults(1, BSurf->NbVKnots());
NCollection_Array2<gp_Pnt> surface_poles(1, BSurf->NbUPoles(), 1, BSurf->NbVPoles());
NCollection_Array2<double> 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<double>& surface_u_knots = BSurf->UKnots();
const NCollection_Array1<int>& surface_u_mults = BSurf->UMultiplicities();
const NCollection_Array1<double>& surface_v_knots = BSurf->VKnots();
const NCollection_Array1<int>& surface_v_mults = BSurf->VMultiplicities();
const NCollection_Array2<gp_Pnt>& surface_poles = BSurf->Poles();
const NCollection_Array2<double>* surface_weights = BSurf->Weights();
int i, j, k, status, new_num_u_poles, new_num_v_poles, length = 0;
occ::handle<NCollection_HArray1<double>> newuknots, newvknots;
occ::handle<NCollection_HArray1<int>> 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<double> Knots(1, 2);
NCollection_Array1<int> Mults(1, 2);
occ::handle<NCollection_HArray1<double>> NewKnots;
@@ -2379,7 +2362,7 @@ static void FunctionMultiply(occ::handle<Geom_BSplineSurface>& 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<Geom_BSplineSurface>& BSurf,
static void CancelDenominatorDerivative1D(occ::handle<Geom_BSplineSurface>& BSurf)
{
int i, j;
double uknotmin = 1.0, uknotmax = 0.0, x, y, startu_value, endu_value;
NCollection_Array1<double> 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<double> 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<Geom_BSplineCurve> BCurve;
NCollection_Array1<double> BCurveWeights(1, BSurf->NbUPoles());
NCollection_Array1<gp_Pnt> BCurvePoles(1, BSurf->NbUPoles());
NCollection_Array1<double> BCurveKnots(1, BSurf->NbUKnots());
NCollection_Array1<int> BCurveMults(1, BSurf->NbUKnots());
if (CanBeTreated(BSurf))
{
const NCollection_Array1<double>& BCurveKnots = BSurf->UKnots();
const NCollection_Array1<int>& 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<Geom_BSplineSurface>& 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<Geom_BSplineSurface>& 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);
}
@@ -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<gp_Pnt> surface_poles(1, mySurface->NbUPoles(), 1, mySurface->NbVPoles());
NCollection_Array2<double> surface_weights(1, mySurface->NbUPoles(), 1, mySurface->NbVPoles());
NCollection_Array1<double> surface_u_knots(1, mySurface->NbUKnots());
NCollection_Array1<int> surface_u_mults(1, mySurface->NbUKnots());
gp_Pnt N;
gp_Vec Nu, Nv;
NCollection_Array1<double> surface_v_knots(1, mySurface->NbVKnots());
NCollection_Array1<int> 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<gp_Pnt>& surface_poles = mySurface->Poles();
const NCollection_Array2<double>* surface_weights = mySurface->Weights();
const NCollection_Array1<double>& surface_u_knots = mySurface->UKnots();
const NCollection_Array1<int>& surface_u_mults = mySurface->UMultiplicities();
const NCollection_Array1<double>& surface_v_knots = mySurface->VKnots();
const NCollection_Array1<int>& 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,
+23 -21
View File
@@ -36,9 +36,9 @@
static void HermiteCoeff(const occ::handle<Geom_BSplineCurve>& BS, NCollection_Array1<double>& TAB)
{
NCollection_Array1<double> Knots(1, BS->NbKnots());
NCollection_Array1<double> Weights(1, BS->NbPoles());
NCollection_Array1<int> Mults(1, BS->NbKnots());
NCollection_Array1<double> Knots(BS->Knots());
const NCollection_Array1<double>& Weights = BS->WeightsArray();
const NCollection_Array1<int>& 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<Geom_BSplineCurve>& 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<Geom2d_BSplineCurve>& BS,
NCollection_Array1<double>& TAB)
{
NCollection_Array1<double> Knots(1, BS->NbKnots());
NCollection_Array1<double> Weights(1, BS->NbPoles());
NCollection_Array1<int> Mults(1, BS->NbKnots());
int Degree, Index0, Index1;
double Denom0, Denom1, // denominateur value for u=0 & u=1
// clang-format off
NCollection_Array1<double> Knots(BS->Knots());
const NCollection_Array1<double>& Weights = BS->WeightsArray();
const NCollection_Array1<int>& 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<double>& 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<double>& 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<double>& 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<double>& 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<double>& 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(
@@ -1132,14 +1132,10 @@ void ProjLib_ComputeApprox::Perform(const occ::handle<Adaptor3d_Curve>& C,
{
// get the poles and eventually the weights
occ::handle<Geom_BSplineCurve> BS = C->BSpline();
NbPoles = BS->NbPoles();
NCollection_Array1<gp_Pnt> P3d(1, NbPoles);
NCollection_Array1<gp_Pnt2d> Poles(1, NbPoles);
NCollection_Array1<double> Weights(1, NbPoles);
if (BS->IsRational())
BS->Weights(Weights);
BS->Poles(P3d);
occ::handle<Geom_BSplineCurve> BS = C->BSpline();
NbPoles = BS->NbPoles();
const NCollection_Array1<gp_Pnt>& P3d = BS->Poles();
NCollection_Array1<gp_Pnt2d> 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<Adaptor3d_Curve>& C,
{
Poles.SetValue(i, aProj.Project(P3d(i)));
}
NbKnots = BS->NbKnots();
NCollection_Array1<double> Knots(1, NbKnots);
NCollection_Array1<int> Mults(1, NbKnots);
BS->Knots(Knots);
BS->Multiplicities(Mults);
const NCollection_Array1<double>& Knots = BS->Knots();
const NCollection_Array1<int>& 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<Adaptor3d_Curve>& C,
// get the poles and eventually the weights
occ::handle<Geom_BezierCurve> BezierCurvePtr = C->Bezier();
NbPoles = BezierCurvePtr->NbPoles();
NCollection_Array1<gp_Pnt> P3d(1, NbPoles);
NCollection_Array1<gp_Pnt2d> Poles(1, NbPoles);
NCollection_Array1<double> Weights(1, NbPoles);
if (BezierCurvePtr->IsRational())
{
BezierCurvePtr->Weights(Weights);
}
BezierCurvePtr->Poles(P3d);
const NCollection_Array1<gp_Pnt>& P3d = BezierCurvePtr->Poles();
NCollection_Array1<gp_Pnt2d> 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<Adaptor3d_Curve>& C,
}
if (BezierCurvePtr->IsRational())
{
myBezier = new Geom2d_BezierCurve(Poles, Weights);
myBezier = new Geom2d_BezierCurve(Poles, BezierCurvePtr->WeightsArray());
}
else
{
@@ -612,18 +612,12 @@ static occ::handle<Geom2d_BSplineCurve> Concat(const occ::handle<Geom2d_BSplineC
nk = nk1 + nk2 - 1;
np = np1 + np2 - 1;
NCollection_Array1<double> K1(1, nk1);
C1->Knots(K1);
NCollection_Array1<int> M1(1, nk1);
C1->Multiplicities(M1);
NCollection_Array1<gp_Pnt2d> P1(1, np1);
C1->Poles(P1);
NCollection_Array1<double> K2(1, nk2);
C2->Knots(K2);
NCollection_Array1<int> M2(1, nk2);
C2->Multiplicities(M2);
NCollection_Array1<gp_Pnt2d> P2(1, np2);
C2->Poles(P2);
const NCollection_Array1<double>& K1 = C1->Knots();
const NCollection_Array1<int>& M1 = C1->Multiplicities();
const NCollection_Array1<gp_Pnt2d>& P1 = C1->Poles();
const NCollection_Array1<double>& K2 = C2->Knots();
const NCollection_Array1<int>& M2 = C2->Multiplicities();
const NCollection_Array1<gp_Pnt2d>& P2 = C2->Poles();
// Compute the new BSplineCurve
NCollection_Array1<double> K(1, nk);
@@ -1685,20 +1679,20 @@ occ::handle<Geom2d_BSplineCurve> ProjLib_ComputeApproxOnPolarSurface::ProjectUsi
ElSLib::Parameters(Plane, BSC->Pole(i), S, T);
Poles2d(i).SetCoord(S, T);
}
NCollection_Array1<double> Knots(1, BSC->NbKnots());
BSC->Knots(Knots);
NCollection_Array1<int> Mults(1, BSC->NbKnots());
BSC->Multiplicities(Mults);
const NCollection_Array1<double>& Knots = BSC->Knots();
const NCollection_Array1<int>& Mults = BSC->Multiplicities();
if (BSC->IsRational())
{
NCollection_Array1<double> Weights(1, BSC->NbPoles());
BSC->Weights(Weights);
return new Geom2d_BSplineCurve(Poles2d,
Weights,
Knots,
Mults,
BSC->Degree(),
BSC->IsPeriodic());
const NCollection_Array1<double>* 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<Geom2d_BSplineCurve> ProjLib_ComputeApproxOnPolarSurface::ProjectUsi
Mults.Init(BC->NbPoles());
if (BC->IsRational())
{
NCollection_Array1<double> Weights(1, BC->NbPoles());
BC->Weights(Weights);
return new Geom2d_BSplineCurve(Poles2d,
Weights,
Knots,
Mults,
BC->Degree(),
BC->IsPeriodic());
const NCollection_Array1<double>* 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<Geom2d_BSplineCurve> ProjLib_ComputeApproxOnPolarSurface::ProjectUsi
}
if (myProjIsDone)
{
NCollection_Array1<double> Knots(1, BSC->NbKnots());
BSC->Knots(Knots);
NCollection_Array1<int> Mults(1, BSC->NbKnots());
BSC->Multiplicities(Mults);
const NCollection_Array1<double>& Knots = BSC->Knots();
const NCollection_Array1<int>& Mults = BSC->Multiplicities();
if (BSC->IsRational())
{
NCollection_Array1<double> 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<Geom2d_BSplineCurve> ProjLib_ComputeApproxOnPolarSurface::ProjectUsi
Mults.Init(BC->NbPoles());
if (BC->IsRational())
{
NCollection_Array1<double> 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<Geom2d_BSplineCurve> ProjLib_ComputeApproxOnPolarSurface::ProjectUsi
}
if (myProjIsDone)
{
NCollection_Array1<double> Knots(1, BSC->NbKnots());
BSC->Knots(Knots);
NCollection_Array1<int> Mults(1, BSC->NbKnots());
BSC->Multiplicities(Mults);
const NCollection_Array1<double>& Knots = BSC->Knots();
const NCollection_Array1<int>& Mults = BSC->Multiplicities();
if (BSC->IsRational())
{
NCollection_Array1<double> 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<Geom2d_BSplineCurve> ProjLib_ComputeApproxOnPolarSurface::ProjectUsi
Mults.Init(BC->NbPoles());
if (BC->IsRational())
{
NCollection_Array1<double> Weights(1, BC->NbPoles());
BC->Weights(Weights);
return new Geom2d_BSplineCurve(Poles2d,
Weights,
BC->WeightsArray(),
Knots,
Mults,
BC->Degree(),
@@ -553,7 +553,6 @@ void ProjLib_ProjectOnPlane::Load(const occ::handle<Adaptor3d_Curve>& 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<Adaptor3d_Curve>& C,
occ::handle<Geom_BSplineCurve> NewCurvePtr =
GeomConvert::CurveToBSplineCurve(NewTrimCurvePtr);
num_knots = NewCurvePtr->NbKnots();
NCollection_Array1<double> BsplineKnots(1, num_knots);
NewCurvePtr->Knots(BsplineKnots);
NCollection_Array1<double> BsplineKnots(NewCurvePtr->Knots());
BSplCLib::Reparametrize(myCurve->FirstParameter(),
myCurve->LastParameter(),