1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 //Jean-Claude Vauthier 27 November 1991
16 //Passage sur C1 Aout 1992
18 #include <BSplCLib.hxx>
19 #include <Geom_BSplineCurve.hxx>
20 #include <GeomConvert_BSplineCurveKnotSplitting.hxx>
21 #include <Standard_DimensionError.hxx>
22 #include <Standard_RangeError.hxx>
24 typedef TColStd_Array1OfInteger Array1OfInteger;
25 typedef TColStd_HArray1OfInteger HArray1OfInteger;
27 GeomConvert_BSplineCurveKnotSplitting::GeomConvert_BSplineCurveKnotSplitting (
29 const Handle(Geom_BSplineCurve)& BasisCurve,
30 const Standard_Integer ContinuityRange
35 if (ContinuityRange < 0) throw Standard_RangeError();
37 Standard_Integer FirstIndex = BasisCurve->FirstUKnotIndex();
38 Standard_Integer LastIndex = BasisCurve->LastUKnotIndex();
40 Standard_Integer Degree = BasisCurve->Degree();
42 if (ContinuityRange == 0) {
43 splitIndexes = new HArray1OfInteger (1, 2);
44 splitIndexes->SetValue (1, FirstIndex);
45 splitIndexes->SetValue (2, LastIndex);
48 Standard_Integer NbKnots = BasisCurve->NbKnots();
49 Array1OfInteger Mults (1, NbKnots);
50 BasisCurve->Multiplicities (Mults);
51 Standard_Integer Mmax = BSplCLib::MaxKnotMult (Mults, FirstIndex, LastIndex);
52 if (Degree - Mmax >= ContinuityRange) {
53 splitIndexes = new HArray1OfInteger (1, 2);
54 splitIndexes->SetValue (1, FirstIndex);
55 splitIndexes->SetValue (2, LastIndex);
58 Array1OfInteger Split (1, LastIndex - FirstIndex + 1);
59 Standard_Integer NbSplit = 1;
60 Standard_Integer Index = FirstIndex;
61 Split (NbSplit) = Index;
64 while (Index < LastIndex) {
65 if (Degree - Mults (Index) < ContinuityRange) {
66 Split (NbSplit) = Index;
71 Split (NbSplit) = Index;
72 splitIndexes = new HArray1OfInteger (1, NbSplit);
73 for (Standard_Integer i = 1; i <= NbSplit; i++) {
74 splitIndexes->SetValue (i, Split (i));
81 Standard_Integer GeomConvert_BSplineCurveKnotSplitting::NbSplits () const {
83 return splitIndexes->Length();
87 Standard_Integer GeomConvert_BSplineCurveKnotSplitting::SplitValue (
89 const Standard_Integer Index
93 Standard_RangeError_Raise_if (
94 Index < 1 || Index > splitIndexes->Length(), " ");
95 return splitIndexes->Value (Index);
100 void GeomConvert_BSplineCurveKnotSplitting::Splitting (
102 Array1OfInteger& SplitValues
106 for (Standard_Integer i = 1; i <= splitIndexes->Length(); i++){
107 SplitValues (i) = splitIndexes->Value (i);