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 <Geom2d_BSplineCurve.hxx>
20 #include <Geom2dConvert_BSplineCurveKnotSplitting.hxx>
21 #include <Standard_DimensionError.hxx>
22 #include <Standard_RangeError.hxx>
24 typedef TColStd_Array1OfInteger Array1OfInteger;
25 typedef TColStd_HArray1OfInteger HArray1OfInteger;
27 Geom2dConvert_BSplineCurveKnotSplitting::
28 Geom2dConvert_BSplineCurveKnotSplitting (
30 const Handle(Geom2d_BSplineCurve)& BasisCurve,
31 const Standard_Integer ContinuityRange
36 if (ContinuityRange < 0) throw Standard_RangeError();
38 Standard_Integer FirstIndex = BasisCurve->FirstUKnotIndex();
39 Standard_Integer LastIndex = BasisCurve->LastUKnotIndex();
41 Standard_Integer Degree = BasisCurve->Degree();
43 if (ContinuityRange == 0) {
44 splitIndexes = new HArray1OfInteger (1, 2);
45 splitIndexes->SetValue (1, FirstIndex);
46 splitIndexes->SetValue (2, LastIndex);
49 Standard_Integer NbKnots = BasisCurve->NbKnots();
50 Array1OfInteger Mults (1, NbKnots);
51 BasisCurve->Multiplicities (Mults);
52 Standard_Integer Mmax = BSplCLib::MaxKnotMult (Mults, FirstIndex, LastIndex);
53 if (Degree - Mmax >= ContinuityRange) {
54 splitIndexes = new HArray1OfInteger (1, 2);
55 splitIndexes->SetValue (1, FirstIndex);
56 splitIndexes->SetValue (2, LastIndex);
59 Array1OfInteger Split (1, LastIndex - FirstIndex + 1);
60 Standard_Integer NbSplit = 1;
61 Standard_Integer Index = FirstIndex;
62 Split (NbSplit) = Index;
65 while (Index < LastIndex) {
66 if (Degree - Mults (Index) < ContinuityRange) {
67 Split (NbSplit) = Index;
72 Split (NbSplit) = Index;
73 splitIndexes = new HArray1OfInteger (1, NbSplit);
74 for (Standard_Integer i = 1; i <= NbSplit; i++) {
75 splitIndexes->SetValue (i, Split (i));
83 Standard_Integer Geom2dConvert_BSplineCurveKnotSplitting::NbSplits () const {
85 return splitIndexes->Length();
89 Standard_Integer Geom2dConvert_BSplineCurveKnotSplitting::SplitValue (
91 const Standard_Integer Index
95 Standard_RangeError_Raise_if (
96 Index < 1 || Index > splitIndexes->Length(), " ");
97 return splitIndexes->Value (Index);
103 void Geom2dConvert_BSplineCurveKnotSplitting::Splitting (
105 Array1OfInteger& SplitValues
109 for (Standard_Integer i = 1; i <= splitIndexes->Length(); i++){
110 SplitValues (i) = splitIndexes->Value (i);