1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-06-15 11:44:07 +03:00
occt/src/StepToGeom/StepToGeom_MakeBSplineCurve.pxx
bugmster 973c2be1e1 0024428: Implementation of LGPL license
The copying permission statements at the beginning of source files updated to refer to LGPL.
Copyright dates extended till 2014 in advance.
2013-12-17 12:42:41 +04:00

119 lines
4.2 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 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();
Standard_Integer i;
Standard_Integer aFMulDiff = 0,aLMulDiff = 0;
TColStd_Array1OfInteger Mult(1,NbKnots);
for (i=1; i<=NbKnots; ++i) {
Standard_Integer aCurrentVal = aKnotMultiplicities->Value(i);
if (aCurrentVal > Deg + 1)
{
if (i == 1) aFMulDiff = aCurrentVal - Deg - 1;
if (i == NbKnots) aLMulDiff = aCurrentVal - Deg - 1;
#ifdef DEB
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;
}
//aKnots = new TColStd_HArray1OfReal(1,NbKnots);
const Handle(TColStd_HArray1OfReal)& aKnots = BSCW->Knots();
TColStd_Array1OfReal Kn(1,NbKnots);
for (i=1; i<=NbKnots; i++) {
Kn.SetValue(i,aKnots->Value(i));
}
// --- Does the Curve descriptor LOOKS like a periodic descriptor ? ---
Standard_Integer SumMult = 0;
for (i=1; i<=NbKnots; i++) {
SumMult += aKnotMultiplicities->Value(i);
}
Standard_Boolean shouldBePeriodic;
if (SumMult == (NbPoles + Deg + 1)) {
shouldBePeriodic = Standard_False;
}
else if ((aKnotMultiplicities->Value(1) ==
aKnotMultiplicities->Value(NbKnots)) &&
((SumMult - aKnotMultiplicities->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();
//#ifdef DEB
// cout << "Warning: "__FILE__": Closed curve made periodic" << endl;
//#endif
}
return Standard_True;
}