1 // Created on: 1997-01-17
2 // Created by: Philippe MANGIN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Law_BSplineKnotSplitting.ixx>
20 #include <Law_BSplineKnotSplitting.ixx>
21 #include <Standard_RangeError.hxx>
23 #include <BSplCLib.hxx>
25 typedef Handle(Law_BSpline) Handle(BSplineCurve);
26 typedef TColStd_Array1OfInteger Array1OfInteger;
27 typedef TColStd_HArray1OfInteger HArray1OfInteger;
32 Law_BSplineKnotSplitting::
33 Law_BSplineKnotSplitting (
35 const Handle(BSplineCurve)& BasisCurve,
36 const Standard_Integer ContinuityRange
41 if (ContinuityRange < 0) Standard_RangeError::Raise();
43 Standard_Integer FirstIndex = BasisCurve->FirstUKnotIndex();
44 Standard_Integer LastIndex = BasisCurve->LastUKnotIndex();
46 Standard_Integer Degree = BasisCurve->Degree();
48 if (ContinuityRange == 0) {
49 splitIndexes = new HArray1OfInteger (1, 2);
50 splitIndexes->SetValue (1, FirstIndex);
51 splitIndexes->SetValue (2, LastIndex);
54 Standard_Integer NbKnots = BasisCurve->NbKnots();
55 Array1OfInteger Mults (1, NbKnots);
56 BasisCurve->Multiplicities (Mults);
57 Standard_Integer Mmax = BSplCLib::MaxKnotMult (Mults, FirstIndex, LastIndex);
58 if (Degree - Mmax >= ContinuityRange) {
59 splitIndexes = new HArray1OfInteger (1, 2);
60 splitIndexes->SetValue (1, FirstIndex);
61 splitIndexes->SetValue (2, LastIndex);
64 Array1OfInteger Split (1, LastIndex - FirstIndex + 1);
65 Standard_Integer NbSplit = 1;
66 Standard_Integer Index = FirstIndex;
67 Split (NbSplit) = Index;
70 while (Index < LastIndex) {
71 if (Degree - Mults (Index) < ContinuityRange) {
72 Split (NbSplit) = Index;
77 Split (NbSplit) = Index;
78 splitIndexes = new HArray1OfInteger (1, NbSplit);
79 for (Standard_Integer i = 1; i <= NbSplit; i++) {
80 splitIndexes->SetValue (i, Split (i));
88 Standard_Integer Law_BSplineKnotSplitting::NbSplits () const {
90 return splitIndexes->Length();
94 Standard_Integer Law_BSplineKnotSplitting::SplitValue (
96 const Standard_Integer Index
100 Standard_RangeError_Raise_if (
101 Index < 1 || Index > splitIndexes->Length(), " ");
102 return splitIndexes->Value (Index);
108 void Law_BSplineKnotSplitting::Splitting (
110 Array1OfInteger& SplitValues
114 for (Standard_Integer i = 1; i <= splitIndexes->Length(); i++){
115 SplitValues (i) = splitIndexes->Value (i);