0024830: Remove redundant keyword 'mutable' in CDL declarations
[occt.git] / src / ShapeUpgrade / ShapeUpgrade.cxx
CommitLineData
b311480e 1// Created on: 1998-11-12
2// Created by: data exchange team
3// Copyright (c) 1998-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.
b311480e 16
7fd59977 17// abv 24.05.99 S4174: methods Debug() commented
18
19#include <ShapeUpgrade.ixx>
20#include <TColgp_Array1OfPnt.hxx>
21#include <TColStd_Array1OfReal.hxx>
22#include <BSplCLib.hxx>
23#include <TColStd_Array1OfInteger.hxx>
24
25/*
26// Debug state= True / False.
27static Standard_Boolean Dbg=Standard_False;
28
29void ShapeUpgrade::SetDebug(const Standard_Boolean State)
30{
31 Dbg=State;
32}
33
34Standard_Boolean ShapeUpgrade::Debug()
35{
36 return Dbg;
37}
38*/
39
40//=======================================================================
41//function : C0BSplineToSequenceOfC1BSplineCurve
42//purpose :
43//=======================================================================
44
45 Standard_Boolean ShapeUpgrade::C0BSplineToSequenceOfC1BSplineCurve(const Handle(Geom_BSplineCurve)& BS,
46 Handle(TColGeom_HSequenceOfBoundedCurve)& seqBS)
47{
48 if (BS.IsNull() || (BS->IsCN (1))) return Standard_False;
49
50 seqBS = new TColGeom_HSequenceOfBoundedCurve;
51 BS->SetNotPeriodic(); //to have equation NbPoles = NbKnots with Multiplicities - degree - 1
52
53 Standard_Integer deg = BS->Degree();
54 Standard_Integer NbKnots = BS->NbKnots();
55 Standard_Integer NbPoles = BS->NbPoles();
56 TColgp_Array1OfPnt Poles (1, NbPoles);
57 TColStd_Array1OfReal Weights (1, NbPoles);
58 TColStd_Array1OfReal Knots (1, NbKnots);
59 TColStd_Array1OfInteger Mults (1, NbKnots);
60 TColStd_Array1OfReal KnotSequence (1, NbPoles + deg + 1);
61
62 BS->Poles(Poles);
63 if (BS->IsRational())
64 BS->Weights(Weights);
65 else
66 Weights.Init(1.);
67 BS->Knots(Knots);
68 BS->Multiplicities(Mults);
69 BS->KnotSequence (KnotSequence);
70
71 Standard_Integer StartKnotIndex, EndKnotIndex, j;
72
73 StartKnotIndex = BS->FirstUKnotIndex();
74 for ( EndKnotIndex = StartKnotIndex + 1; EndKnotIndex <= BS->LastUKnotIndex(); EndKnotIndex++ ) {
75 if ( ( Mults (EndKnotIndex) < deg ) && ( EndKnotIndex < BS->LastUKnotIndex() ) ) continue;
76
77 Standard_Integer StartFlatIndex = BSplCLib::FlatIndex (deg, StartKnotIndex, Mults, Standard_False);
78// StartFlatIndex += Mults (StartKnotIndex) - 1;
79 Standard_Integer EndFlatIndex = BSplCLib::FlatIndex (deg, EndKnotIndex, Mults, Standard_False);
80 EndFlatIndex -= Mults (EndKnotIndex) - 1;
81
82 TColStd_Array1OfReal TempKnots (1, NbKnots);
83 TColStd_Array1OfInteger TempMults (1, NbKnots);
84 TempMults.Init (1);
85 Standard_Integer TempKnotIndex = 1;
86 TempKnots (TempKnotIndex) = KnotSequence (StartFlatIndex - deg);
87
88 for ( j = StartFlatIndex - deg + 1; j <= EndFlatIndex + deg; j++ )
89 if (Abs (KnotSequence (j) - KnotSequence (j - 1)) <= gp::Resolution())
90 TempMults (TempKnotIndex) ++;
91 else
92 TempKnots (++TempKnotIndex) = KnotSequence (j);
93
94 Standard_Integer TempStartIndex = 1, TempEndIndex = TempKnotIndex;
95 if (TempMults (TempStartIndex) == 1)
96 TempMults (++TempStartIndex) ++;
97 if (TempMults (TempEndIndex) == 1)
98 TempMults (--TempEndIndex) ++;
99
100 Standard_Integer NewNbKnots = TempEndIndex - TempStartIndex + 1;
101 TColStd_Array1OfInteger newMults (1, NewNbKnots);
102 TColStd_Array1OfReal newKnots (1, NewNbKnots);
103 for ( j = 1; j <= NewNbKnots; j++ ) {
104 newMults (j) = TempMults (j + TempStartIndex - 1);
105 newKnots (j) = TempKnots (j + TempStartIndex - 1);
106 }
107
108 Standard_Integer NewNbPoles = BSplCLib::NbPoles(deg, Standard_False, newMults);
109 TColgp_Array1OfPnt newPoles (1, NewNbPoles);
110 TColStd_Array1OfReal newWeights (1, NewNbPoles);
111 Standard_Integer PoleIndex = StartFlatIndex - deg;//Index of starting pole when splitting B-Spline is an index of starting knot
112 for (j = 1; j <= NewNbPoles; j++) {
113 newWeights (j) = Weights (j + PoleIndex - 1);
114 newPoles (j) = Poles (j + PoleIndex - 1);
115 }
116
117 Handle(Geom_BSplineCurve) newC = new Geom_BSplineCurve
118 (newPoles, newWeights, newKnots, newMults,deg);
119 seqBS->Append (newC);
120
121 StartKnotIndex = EndKnotIndex;
122 }
123 return Standard_True;
124}
125
126//=======================================================================
127//function : C0BSplineToSequenceOfC1BSplineCurve
128//purpose :
129//=======================================================================
130
131static Handle(Geom_BSplineCurve) BSplineCurve2dTo3d (const Handle(Geom2d_BSplineCurve)& BS)
132{
133 Standard_Integer deg = BS->Degree();
134 Standard_Integer NbKnots = BS->NbKnots();
135 Standard_Integer NbPoles = BS->NbPoles();
136 TColgp_Array1OfPnt2d Poles2d (1,NbPoles);
137 TColStd_Array1OfReal Weights (1,NbPoles);
138 TColStd_Array1OfReal Knots (1,NbKnots);
139 TColStd_Array1OfInteger Mults (1,NbKnots);
140
141 BS->Poles(Poles2d);
142 if (BS->IsRational())
143 BS->Weights(Weights);
144 else
145 Weights.Init (1);
146 BS->Knots (Knots);
147 BS->Multiplicities (Mults);
148
149 TColgp_Array1OfPnt Poles3d (1,NbPoles);
150 for (Standard_Integer i = 1; i <= NbPoles; i++)
151 Poles3d (i) = gp_Pnt (Poles2d (i).X(), Poles2d (i).Y(), 0);
152
153 Handle(Geom_BSplineCurve) BS3d = new Geom_BSplineCurve (Poles3d, Weights,
154 Knots, Mults, deg, BS->IsPeriodic());
155 return BS3d;
156}
157
158static Handle(Geom2d_BSplineCurve) BSplineCurve3dTo2d (const Handle(Geom_BSplineCurve)& BS)
159{
160 Standard_Integer deg = BS->Degree();
161 Standard_Integer NbKnots = BS->NbKnots();
162 Standard_Integer NbPoles = BS->NbPoles();
163 TColgp_Array1OfPnt Poles3d (1, NbPoles);
164 TColStd_Array1OfReal Weights (1, NbPoles);
165 TColStd_Array1OfReal Knots (1, NbKnots);
166 TColStd_Array1OfInteger Mults (1, NbKnots);
167
168 BS->Poles(Poles3d);
169 if (BS->IsRational())
170 BS->Weights(Weights);
171 else
172 Weights.Init (1);
173 BS->Knots (Knots);
174 BS->Multiplicities (Mults);
175
176 TColgp_Array1OfPnt2d Poles2d (1,NbPoles);
177 for (Standard_Integer i = 1; i <= NbPoles; i++)
178 Poles2d (i) = gp_Pnt2d (Poles3d (i).X(), Poles3d (i).Y());
179
180 Handle(Geom2d_BSplineCurve) BS2d = new Geom2d_BSplineCurve (Poles2d, Weights,
181 Knots, Mults, deg, BS->IsPeriodic());
182 return BS2d;
183}
184
185 Standard_Boolean ShapeUpgrade::C0BSplineToSequenceOfC1BSplineCurve(const Handle(Geom2d_BSplineCurve)& BS,
186 Handle(TColGeom2d_HSequenceOfBoundedCurve)& seqBS)
187{
188 if (BS.IsNull() || (BS->IsCN (1))) return Standard_False;
189
190 Handle(Geom_BSplineCurve) BS3d = BSplineCurve2dTo3d (BS);
191 Handle(TColGeom_HSequenceOfBoundedCurve) seqBS3d;
192 Standard_Boolean result = C0BSplineToSequenceOfC1BSplineCurve (BS3d, seqBS3d);
193 if (result) {
194 seqBS = new TColGeom2d_HSequenceOfBoundedCurve;
195 for (Standard_Integer i = 1; i <= seqBS3d->Length(); i++)
196 seqBS->Append (BSplineCurve3dTo2d (Handle(Geom_BSplineCurve)::DownCast (seqBS3d->Value (i))));
197 }
198 return result;
199}
200