0023022: This is desirable to access OpenGl extensions and core API (1.2+) in one...
[occt.git] / src / Law / Law_BSplineKnotSplitting.cxx
CommitLineData
7fd59977 1// File: Law_BSplineKnotSplitting.cxx
2// Created: Fri Jan 17 15:23:19 1997
3// Author: Philippe MANGIN
4// <pmn@sgi29>
5
6
7#include <Law_BSplineKnotSplitting.ixx>
8
9
10#include <Law_BSplineKnotSplitting.ixx>
11#include <Standard_RangeError.hxx>
12
13#include <BSplCLib.hxx>
14
15typedef Handle(Law_BSpline) Handle(BSplineCurve);
16typedef TColStd_Array1OfInteger Array1OfInteger;
17typedef TColStd_HArray1OfInteger HArray1OfInteger;
18
19
20
21
22Law_BSplineKnotSplitting::
23Law_BSplineKnotSplitting (
24
25const Handle(BSplineCurve)& BasisCurve,
26const Standard_Integer ContinuityRange
27
28) {
29
30
31 if (ContinuityRange < 0) Standard_RangeError::Raise();
32
33 Standard_Integer FirstIndex = BasisCurve->FirstUKnotIndex();
34 Standard_Integer LastIndex = BasisCurve->LastUKnotIndex();
35
36 Standard_Integer Degree = BasisCurve->Degree();
37
38 if (ContinuityRange == 0) {
39 splitIndexes = new HArray1OfInteger (1, 2);
40 splitIndexes->SetValue (1, FirstIndex);
41 splitIndexes->SetValue (2, LastIndex);
42 }
43 else {
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);
52 }
53 else {
54 Array1OfInteger Split (1, LastIndex - FirstIndex + 1);
55 Standard_Integer NbSplit = 1;
56 Standard_Integer Index = FirstIndex;
57 Split (NbSplit) = Index;
58 Index++;
59 NbSplit++;
60 while (Index < LastIndex) {
61 if (Degree - Mults (Index) < ContinuityRange) {
62 Split (NbSplit) = Index;
63 NbSplit++;
64 }
65 Index++;
66 }
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));
71 }
72 }
73 }
74}
75
76
77
78Standard_Integer Law_BSplineKnotSplitting::NbSplits () const {
79
80 return splitIndexes->Length();
81}
82
83
84Standard_Integer Law_BSplineKnotSplitting::SplitValue (
85
86const Standard_Integer Index
87
88) const {
89
90 Standard_RangeError_Raise_if (
91 Index < 1 || Index > splitIndexes->Length(), " ");
92 return splitIndexes->Value (Index);
93}
94
95
96
97
98void Law_BSplineKnotSplitting::Splitting (
99
100Array1OfInteger& SplitValues
101
102) const {
103
104 for (Standard_Integer i = 1; i <= splitIndexes->Length(); i++){
105 SplitValues (i) = splitIndexes->Value (i);
106 }
107}