0024023: Revamp the OCCT Handle -- general
[occt.git] / src / Law / Law_BSplineKnotSplitting.cxx
CommitLineData
b311480e 1// Created on: 1997-01-17
2// Created by: Philippe MANGIN
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <Law_BSplineKnotSplitting.ixx>
18
19
20#include <Law_BSplineKnotSplitting.ixx>
21#include <Standard_RangeError.hxx>
22
23#include <BSplCLib.hxx>
24
7fd59977 25typedef TColStd_Array1OfInteger Array1OfInteger;
26typedef TColStd_HArray1OfInteger HArray1OfInteger;
27
7fd59977 28Law_BSplineKnotSplitting::
c04c30b3 29Law_BSplineKnotSplitting (const Handle(Law_BSpline)& BasisCurve,
30 const Standard_Integer ContinuityRange)
31{
7fd59977 32 if (ContinuityRange < 0) Standard_RangeError::Raise();
33
34 Standard_Integer FirstIndex = BasisCurve->FirstUKnotIndex();
35 Standard_Integer LastIndex = BasisCurve->LastUKnotIndex();
36
37 Standard_Integer Degree = BasisCurve->Degree();
38
39 if (ContinuityRange == 0) {
40 splitIndexes = new HArray1OfInteger (1, 2);
41 splitIndexes->SetValue (1, FirstIndex);
42 splitIndexes->SetValue (2, LastIndex);
43 }
44 else {
45 Standard_Integer NbKnots = BasisCurve->NbKnots();
46 Array1OfInteger Mults (1, NbKnots);
47 BasisCurve->Multiplicities (Mults);
48 Standard_Integer Mmax = BSplCLib::MaxKnotMult (Mults, FirstIndex, LastIndex);
49 if (Degree - Mmax >= ContinuityRange) {
50 splitIndexes = new HArray1OfInteger (1, 2);
51 splitIndexes->SetValue (1, FirstIndex);
52 splitIndexes->SetValue (2, LastIndex);
53 }
54 else {
55 Array1OfInteger Split (1, LastIndex - FirstIndex + 1);
56 Standard_Integer NbSplit = 1;
57 Standard_Integer Index = FirstIndex;
58 Split (NbSplit) = Index;
59 Index++;
60 NbSplit++;
61 while (Index < LastIndex) {
62 if (Degree - Mults (Index) < ContinuityRange) {
63 Split (NbSplit) = Index;
64 NbSplit++;
65 }
66 Index++;
67 }
68 Split (NbSplit) = Index;
69 splitIndexes = new HArray1OfInteger (1, NbSplit);
70 for (Standard_Integer i = 1; i <= NbSplit; i++) {
71 splitIndexes->SetValue (i, Split (i));
72 }
73 }
74 }
75}
76
77
78
79Standard_Integer Law_BSplineKnotSplitting::NbSplits () const {
80
81 return splitIndexes->Length();
82}
83
84
85Standard_Integer Law_BSplineKnotSplitting::SplitValue (
86
87const Standard_Integer Index
88
89) const {
90
91 Standard_RangeError_Raise_if (
92 Index < 1 || Index > splitIndexes->Length(), " ");
93 return splitIndexes->Value (Index);
94}
95
96
97
98
99void Law_BSplineKnotSplitting::Splitting (
100
101Array1OfInteger& SplitValues
102
103) const {
104
105 for (Standard_Integer i = 1; i <= splitIndexes->Length(); i++){
106 SplitValues (i) = splitIndexes->Value (i);
107 }
108}