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.
18 #include <BSplCLib.hxx>
19 #include <Law_BSpline.hxx>
20 #include <Law_BSplineKnotSplitting.hxx>
21 #include <Standard_DimensionError.hxx>
22 #include <Standard_RangeError.hxx>
24 typedef TColStd_Array1OfInteger Array1OfInteger;
25 typedef TColStd_HArray1OfInteger HArray1OfInteger;
27 Law_BSplineKnotSplitting::
28 Law_BSplineKnotSplitting (const Handle(Law_BSpline)& BasisCurve,
29 const Standard_Integer ContinuityRange)
31 if (ContinuityRange < 0) throw Standard_RangeError();
33 Standard_Integer FirstIndex = BasisCurve->FirstUKnotIndex();
34 Standard_Integer LastIndex = BasisCurve->LastUKnotIndex();
36 Standard_Integer Degree = BasisCurve->Degree();
38 if (ContinuityRange == 0) {
39 splitIndexes = new HArray1OfInteger (1, 2);
40 splitIndexes->SetValue (1, FirstIndex);
41 splitIndexes->SetValue (2, LastIndex);
44 Standard_Integer NbKnots = BasisCurve->NbKnots();
45 Array1OfInteger Mults (1, NbKnots);
46 BasisCurve->Multiplicities (Mults);
47 Standard_Integer Mmax = BSplCLib::MaxKnotMult (Mults, FirstIndex, LastIndex);
48 if (Degree - Mmax >= ContinuityRange) {
49 splitIndexes = new HArray1OfInteger (1, 2);
50 splitIndexes->SetValue (1, FirstIndex);
51 splitIndexes->SetValue (2, LastIndex);
54 Array1OfInteger Split (1, LastIndex - FirstIndex + 1);
55 Standard_Integer NbSplit = 1;
56 Standard_Integer Index = FirstIndex;
57 Split (NbSplit) = Index;
60 while (Index < LastIndex) {
61 if (Degree - Mults (Index) < ContinuityRange) {
62 Split (NbSplit) = Index;
67 Split (NbSplit) = Index;
68 splitIndexes = new HArray1OfInteger (1, NbSplit);
69 for (Standard_Integer i = 1; i <= NbSplit; i++) {
70 splitIndexes->SetValue (i, Split (i));
78 Standard_Integer Law_BSplineKnotSplitting::NbSplits () const {
80 return splitIndexes->Length();
84 Standard_Integer Law_BSplineKnotSplitting::SplitValue (
86 const Standard_Integer Index
90 Standard_RangeError_Raise_if (
91 Index < 1 || Index > splitIndexes->Length(), " ");
92 return splitIndexes->Value (Index);
98 void Law_BSplineKnotSplitting::Splitting (
100 Array1OfInteger& SplitValues
104 for (Standard_Integer i = 1; i <= splitIndexes->Length(); i++){
105 SplitValues (i) = splitIndexes->Value (i);