0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / Geom2dConvert / Geom2dConvert_BSplineCurveKnotSplitting.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 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
973c2be1 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15//Jean-Claude Vauthier 27 November 1991
16//Passage sur C1 Aout 1992
17
7fd59977 18#include <BSplCLib.hxx>
42cf5bc1 19#include <Geom2d_BSplineCurve.hxx>
20#include <Geom2dConvert_BSplineCurveKnotSplitting.hxx>
42cf5bc1 21#include <Standard_RangeError.hxx>
7fd59977 22
7fd59977 23typedef TColStd_Array1OfInteger Array1OfInteger;
24typedef TColStd_HArray1OfInteger HArray1OfInteger;
25
7fd59977 26Geom2dConvert_BSplineCurveKnotSplitting::
27Geom2dConvert_BSplineCurveKnotSplitting (
28
c04c30b3 29const Handle(Geom2d_BSplineCurve)& BasisCurve,
7fd59977 30const Standard_Integer ContinuityRange
31
32) {
33
34
9775fa61 35 if (ContinuityRange < 0) throw Standard_RangeError();
7fd59977 36
37 Standard_Integer FirstIndex = BasisCurve->FirstUKnotIndex();
38 Standard_Integer LastIndex = BasisCurve->LastUKnotIndex();
39
40 Standard_Integer Degree = BasisCurve->Degree();
41
42 if (ContinuityRange == 0) {
43 splitIndexes = new HArray1OfInteger (1, 2);
44 splitIndexes->SetValue (1, FirstIndex);
45 splitIndexes->SetValue (2, LastIndex);
46 }
47 else {
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);
56 }
57 else {
58 Array1OfInteger Split (1, LastIndex - FirstIndex + 1);
59 Standard_Integer NbSplit = 1;
60 Standard_Integer Index = FirstIndex;
61 Split (NbSplit) = Index;
62 Index++;
63 NbSplit++;
64 while (Index < LastIndex) {
65 if (Degree - Mults (Index) < ContinuityRange) {
66 Split (NbSplit) = Index;
67 NbSplit++;
68 }
69 Index++;
70 }
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));
75 }
76 }
77 }
78}
79
80
81
82Standard_Integer Geom2dConvert_BSplineCurveKnotSplitting::NbSplits () const {
83
84 return splitIndexes->Length();
85}
86
87
88Standard_Integer Geom2dConvert_BSplineCurveKnotSplitting::SplitValue (
89
90const Standard_Integer Index
91
92) const {
93
94 Standard_RangeError_Raise_if (
95 Index < 1 || Index > splitIndexes->Length(), " ");
96 return splitIndexes->Value (Index);
97}
98
99
100
101
102void Geom2dConvert_BSplineCurveKnotSplitting::Splitting (
103
104Array1OfInteger& SplitValues
105
106) const {
107
108 for (Standard_Integer i = 1; i <= splitIndexes->Length(); i++){
109 SplitValues (i) = splitIndexes->Value (i);
110 }
111}