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 28 Novembre 1991
16 //Passage sur C1 Aout 1992
18 #include <BSplCLib.hxx>
19 #include <Geom_BSplineSurface.hxx>
20 #include <GeomConvert_BSplineSurfaceKnotSplitting.hxx>
21 #include <Standard_DimensionError.hxx>
22 #include <Standard_RangeError.hxx>
24 typedef TColStd_Array1OfInteger Array1OfInteger;
25 typedef TColStd_HArray1OfInteger HArray1OfInteger;
27 GeomConvert_BSplineSurfaceKnotSplitting::
28 GeomConvert_BSplineSurfaceKnotSplitting (
30 const Handle(Geom_BSplineSurface)& BasisSurface,
31 const Standard_Integer UContinuityRange,
32 const Standard_Integer VContinuityRange
37 if (UContinuityRange < 0 || VContinuityRange < 0) {
38 throw Standard_RangeError();
41 Standard_Integer FirstUIndex = BasisSurface->FirstUKnotIndex ();
42 Standard_Integer LastUIndex = BasisSurface->LastUKnotIndex ();
43 Standard_Integer FirstVIndex = BasisSurface->FirstVKnotIndex ();
44 Standard_Integer LastVIndex = BasisSurface->LastVKnotIndex ();
45 Standard_Integer UDegree = BasisSurface->UDegree ();
46 Standard_Integer VDegree = BasisSurface->VDegree ();
51 if (UContinuityRange == 0) {
52 usplitIndexes = new HArray1OfInteger (1, 2);
53 usplitIndexes->SetValue (1, FirstUIndex);
54 usplitIndexes->SetValue (2, LastUIndex);
57 Standard_Integer NbUKnots = BasisSurface->NbUKnots();
58 Array1OfInteger UMults (1, NbUKnots);
59 BasisSurface->UMultiplicities (UMults);
60 Standard_Integer Mmax = BSplCLib::MaxKnotMult (UMults, FirstUIndex, LastUIndex);
61 if (UDegree - Mmax >= UContinuityRange) {
62 usplitIndexes = new HArray1OfInteger (1, 2);
63 usplitIndexes->SetValue (1, FirstUIndex);
64 usplitIndexes->SetValue (2, LastUIndex);
67 Array1OfInteger USplit (1, LastUIndex - FirstUIndex + 1);
68 Standard_Integer NbUSplit = 1;
69 Standard_Integer UIndex = FirstUIndex;
70 USplit (NbUSplit) = UIndex;
73 while (UIndex < LastUIndex) {
74 if (UDegree - UMults(UIndex) < UContinuityRange) {
75 USplit (NbUSplit) = UIndex;
80 USplit (NbUSplit) = UIndex;
81 usplitIndexes = new HArray1OfInteger (1, NbUSplit);
82 for (i = 1; i <= NbUSplit; i++) {
83 usplitIndexes->SetValue (i, USplit (i));
90 if (VContinuityRange == 0) {
91 vsplitIndexes = new HArray1OfInteger (1, 2);
92 vsplitIndexes->SetValue (1, FirstVIndex);
93 vsplitIndexes->SetValue (2, LastVIndex);
96 Standard_Integer NbVKnots = BasisSurface->NbVKnots();
97 Array1OfInteger VMults (1, NbVKnots);
98 BasisSurface->VMultiplicities (VMults);
99 Standard_Integer Mmax = BSplCLib::MaxKnotMult (VMults, FirstVIndex, LastVIndex);
100 if (VDegree - Mmax >= VContinuityRange) {
101 usplitIndexes = new HArray1OfInteger (1, 2);
102 usplitIndexes->SetValue (1, FirstVIndex);
103 usplitIndexes->SetValue (2, LastVIndex);
106 Array1OfInteger VSplit (1, LastVIndex - FirstVIndex + 1);
107 Standard_Integer NbVSplit = 1;
108 Standard_Integer VIndex = FirstVIndex;
109 VSplit (NbVSplit) = VIndex;
112 while (VIndex < LastVIndex) {
113 if (VDegree - VMults (VIndex) < VContinuityRange) {
114 VSplit (NbVSplit) = VIndex;
119 VSplit (NbVSplit) = VIndex;
120 vsplitIndexes = new HArray1OfInteger (1, NbVSplit);
121 for (i = 1; i <= NbVSplit; i++) {
122 vsplitIndexes->SetValue (i, VSplit (i));
130 Standard_Integer GeomConvert_BSplineSurfaceKnotSplitting::NbUSplits () const {
131 return usplitIndexes->Length();
135 Standard_Integer GeomConvert_BSplineSurfaceKnotSplitting::NbVSplits () const {
136 return vsplitIndexes->Length();
140 Standard_Integer GeomConvert_BSplineSurfaceKnotSplitting::USplitValue (
142 const Standard_Integer UIndex
146 Standard_RangeError_Raise_if (
147 UIndex < 1 || UIndex > usplitIndexes->Length(), " ");
148 return usplitIndexes->Value (UIndex);
153 Standard_Integer GeomConvert_BSplineSurfaceKnotSplitting::VSplitValue (
155 const Standard_Integer VIndex
159 Standard_RangeError_Raise_if (
160 VIndex < 1 || VIndex > vsplitIndexes->Length(), " ");
161 return vsplitIndexes->Value (VIndex);
165 void GeomConvert_BSplineSurfaceKnotSplitting::Splitting (
167 Array1OfInteger& USplit,
168 Array1OfInteger& VSplit
172 for ( i = 1; i <= usplitIndexes->Length(); i++){
173 USplit (i) = usplitIndexes->Value (i);
175 for (i = 1; i <= vsplitIndexes->Length(); i++){
176 VSplit (i) = vsplitIndexes->Value (i);