mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-07-05 12:15:50 +03:00
Macros ending on "DEB" are replaced by OCCT_DEBUG across OCCT code; new macros described in documentation. Macros starting with DEB are changed to start with "OCCT_DEBUG_". Some code cleaned.
140 lines
4.9 KiB
Plaintext
140 lines
4.9 KiB
Plaintext
// Created on: 1993-07-02
|
|
// Created by: Martine LANGLOIS
|
|
// Copyright (c) 1993-1999 Matra Datavision
|
|
// Copyright (c) 1999-2014 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.
|
|
|
|
{
|
|
Handle(StepGeom_BSplineCurveWithKnots) BSCW;
|
|
Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve) BSCWR;
|
|
|
|
if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve))) {
|
|
BSCWR =
|
|
Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)
|
|
::DownCast(SC);
|
|
BSCW =
|
|
Handle(StepGeom_BSplineCurveWithKnots)
|
|
::DownCast(BSCWR->BSplineCurveWithKnots());
|
|
}
|
|
else
|
|
BSCW = Handle(StepGeom_BSplineCurveWithKnots)::DownCast(SC);
|
|
|
|
const Standard_Integer Deg = BSCW->Degree();
|
|
const Standard_Integer NbPoles = BSCW->NbControlPointsList();
|
|
const Standard_Integer NbKnots = BSCW->NbKnotMultiplicities();
|
|
|
|
//aKnotMultiplicities = new TColStd_HArray1OfInteger(1,NbKnots);
|
|
const Handle(TColStd_HArray1OfInteger)& aKnotMultiplicities = BSCW->KnotMultiplicities();
|
|
//aKnots = new TColStd_HArray1OfReal(1,NbKnots);
|
|
const Handle(TColStd_HArray1OfReal)& aKnots = BSCW->Knots();
|
|
|
|
// Count number of unique knots
|
|
Standard_Integer i;
|
|
Standard_Integer NbUniqueKnots = 0;
|
|
Standard_Real lastKnot = RealFirst();
|
|
for (i=1; i<=NbKnots; ++i) {
|
|
if (aKnots->Value(i) - lastKnot > Epsilon (Abs(lastKnot))) {
|
|
NbUniqueKnots++;
|
|
lastKnot = aKnots->Value(i);
|
|
}
|
|
}
|
|
|
|
TColStd_Array1OfReal Kn(1,NbUniqueKnots);
|
|
TColStd_Array1OfInteger Mult(1,NbUniqueKnots);
|
|
lastKnot = aKnots->Value(1);
|
|
Kn.SetValue(1, aKnots->Value(1));
|
|
Mult.SetValue(1, aKnotMultiplicities->Value(1));
|
|
Standard_Integer pos = 1;
|
|
for (i=2; i<=NbKnots; i++) {
|
|
if (aKnots->Value(i) - lastKnot > Epsilon (Abs(lastKnot))) {
|
|
pos++;
|
|
Kn.SetValue(pos, aKnots->Value(i));
|
|
Mult.SetValue(pos, aKnotMultiplicities->Value(i));
|
|
lastKnot = aKnots->Value(i);
|
|
}
|
|
else {
|
|
// Knot not unique, increase multiplicity
|
|
Standard_Integer curMult = Mult.Value(pos);
|
|
Mult.SetValue(pos, curMult + aKnotMultiplicities->Value(i));
|
|
}
|
|
}
|
|
|
|
Standard_Integer aFMulDiff = 0,aLMulDiff = 0;
|
|
for (i=1; i<=NbUniqueKnots; ++i) {
|
|
Standard_Integer aCurrentVal = Mult.Value(i);
|
|
if (aCurrentVal > Deg + 1)
|
|
{
|
|
if (i == 1) aFMulDiff = aCurrentVal - Deg - 1;
|
|
if (i == NbKnots) aLMulDiff = aCurrentVal - Deg - 1;
|
|
#ifdef OCCT_DEBUG
|
|
cout << "\nWrong multiplicity " << aCurrentVal << " on " << i
|
|
<< " knot!" << "\nChanged to " << Deg + 1 << endl;
|
|
#endif
|
|
aCurrentVal = Deg + 1;
|
|
}
|
|
Mult.SetValue(i,aCurrentVal);
|
|
}
|
|
|
|
//aControlPointsList = new StepGeom_HArray1OfCartesianPoint(1,NbPoles);
|
|
const Handle(StepGeom_HArray1OfCartesianPoint)& aControlPointsList = BSCW->ControlPointsList();
|
|
Standard_Integer aSumMulDiff = aFMulDiff + aLMulDiff;
|
|
Array1OfPnt_gen Poles(1,NbPoles - aSumMulDiff);
|
|
CartesianPoint_gen P;
|
|
|
|
for (i = 1 + aFMulDiff; i<= NbPoles - aLMulDiff; ++i)
|
|
{
|
|
if (StepToGeom_MakeCartesianPoint_gen::Convert(aControlPointsList->Value(i),P))
|
|
Poles.SetValue(i - aFMulDiff,P->Pnt_fonc());
|
|
else
|
|
return Standard_False;
|
|
}
|
|
|
|
// --- Does the Curve descriptor LOOKS like a periodic descriptor ? ---
|
|
|
|
Standard_Integer SumMult = 0;
|
|
for (i=1; i<=NbUniqueKnots; i++) {
|
|
SumMult += Mult.Value(i);
|
|
}
|
|
|
|
Standard_Boolean shouldBePeriodic;
|
|
if (SumMult == (NbPoles + Deg + 1)) {
|
|
shouldBePeriodic = Standard_False;
|
|
}
|
|
else if ((Mult.Value(1) ==
|
|
Mult.Value(NbUniqueKnots)) &&
|
|
((SumMult - Mult.Value(1)) == NbPoles)) {
|
|
shouldBePeriodic = Standard_True;
|
|
}
|
|
else { // --- What is that ??? ---
|
|
shouldBePeriodic = Standard_False;
|
|
//cout << "Strange BSpline Curve Descriptor" << endl;
|
|
}
|
|
|
|
if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve))) {
|
|
const Handle(TColStd_HArray1OfReal)& aWeight = BSCWR->WeightsData();
|
|
TColStd_Array1OfReal W(1,NbPoles);
|
|
for (i=1; i<=NbPoles; i++)
|
|
W.SetValue(i,aWeight->Value(i));
|
|
CC = new BSplineCurve_gen(Poles, W, Kn, Mult, Deg, shouldBePeriodic);
|
|
}
|
|
else
|
|
CC = new BSplineCurve_gen(Poles, Kn, Mult, Deg, shouldBePeriodic);
|
|
|
|
// abv 04.07.00 CAX-IF TRJ4: trj4_k1_top-md-203.stp #716 (face #581):
|
|
// force periodicity on closed curves
|
|
if ( SC->ClosedCurve() && CC->Degree() >1 && CC->IsClosed() ) {
|
|
CC->SetPeriodic();
|
|
}
|
|
return Standard_True;
|
|
}
|