0023024: Update headers of OCCT files
[occt.git] / src / AppParCurves / AppParCurves_Variational_5.gxx
CommitLineData
b311480e 1// Created on: 1998-12-10
2// Created by: Igor FEOKTISTOV
3// Copyright (c) 1998-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22#include <SortTools_ShellSortOfReal.hxx>
23#include <TCollection_CompareOfReal.hxx>
24#include <PLib_Base.hxx>
25
26//----------------------------------------------------------//
27// Standard_Integer NearIndex //
28// Purpose: searching nearest index of TabPar corresponding //
29// given value T (is similar to fortran routine MSRRE2) //
30//----------------------------------------------------------//
31
32static Standard_Integer NearIndex(const Standard_Real T,
33 const TColStd_Array1OfReal& TabPar,
34 const Standard_Real Eps, Standard_Integer& Flag)
35{
36 Standard_Integer Loi = TabPar.Lower(), Upi = TabPar.Upper();
37
38 Flag = 0;
39
40 if(T < TabPar(Loi)) { Flag = -1; return Loi;}
41 if(T > TabPar(Upi)) { Flag = 1; return Upi;}
42
43 Standard_Integer Ibeg = Loi, Ifin = Upi, Imidl;
44
45 while(Ibeg + 1 != Ifin) {
46 Imidl = (Ibeg + Ifin) / 2;
47 if((T >= TabPar(Ibeg)) && (T <= TabPar(Imidl)))
48 Ifin = Imidl;
49 else
50 Ibeg = Imidl;
51 }
52
53 if(Abs(T - TabPar(Ifin)) < Eps) return Ifin;
54
55 return Ibeg;
56}
57
58
59//----------------------------------------------------------//
60// void GettingKnots //
61// Purpose: calculating values of new Knots for elements //
62// with degree that is equal Deg //
63//----------------------------------------------------------//
64
65static void GettingKnots(const TColStd_Array1OfReal& TabPar,
66 const Handle(FEmTool_Curve)& InCurve,
67 const Standard_Integer Deg,
68 Standard_Integer& NbElm,
69 TColStd_Array1OfReal& NewKnots)
70
71{
72
73 const Standard_Real Eps = 1.e-12;
74
75 TColStd_Array1OfReal& OldKnots = InCurve->Knots();
76 Standard_Integer NbMaxOld = InCurve->NbElements();
77 Standard_Integer NbMax = NewKnots.Upper(), Ipt, Ipt1, Ipt2;
78 Standard_Integer el = 0, i1 = OldKnots.Lower(), i0 = i1 - 1, Flag;
79 Standard_Real TPar;
80
81 while((NbElm < NbMax) && (el < NbMaxOld)) {
82
83 el++; i0++; i1++; // i0, i1 are indexes of left and right knots of element el
84
85 if(InCurve->Degree(el) == Deg) {
86
87 NbElm++;
88
89 Ipt1 = NearIndex(OldKnots(i0), TabPar, Eps, Flag);
90 if(Flag != 0) Ipt1 = TabPar.Lower();
91 Ipt2 = NearIndex(OldKnots(i1), TabPar, Eps, Flag);
92 if(Flag != 0) Ipt2 = TabPar.Upper();
93
94 if(Ipt2 - Ipt1 >= 1) {
95
96 Ipt = (Ipt1 + Ipt2) / 2;
97 if(2 * Ipt == Ipt1 + Ipt2)
98 TPar = 2. * TabPar(Ipt);
99 else
100 TPar = TabPar(Ipt) + TabPar(Ipt + 1);
101
102 NewKnots(NbElm) = (OldKnots(i0) + OldKnots(i1) + TPar) / 4.;
103 }
104 else
105 NewKnots(NbElm) = (OldKnots(i0) + OldKnots(i1)) / 2.;
106 }
107 }
108}
109
110void AppParCurves_Variational::SplitCurve(const Handle(FEmTool_Curve)& InCurve,
111 const TColStd_Array1OfReal& Ti,
112 const Standard_Real CurveTol,
113 Handle(FEmTool_Curve)& OutCurve,
114 Standard_Boolean& iscut) const
115{
116 Standard_Integer NbElmOld = InCurve->NbElements();
117
118 if(NbElmOld >= myMaxSegment) {iscut = Standard_False; return;}
119#ifdef DEB
120 Standard_Integer MaxDegree =
121#endif
122 InCurve->Base()->WorkDegree();
123 Standard_Integer NbElm = NbElmOld;
124 TColStd_Array1OfReal NewKnots(NbElm + 1, myMaxSegment);
125#ifndef DEB
126 GettingKnots(Ti, InCurve, InCurve->Base()->WorkDegree(), NbElm, NewKnots);
127 GettingKnots(Ti, InCurve, InCurve->Base()->WorkDegree() - 1, NbElm, NewKnots);
128#else
129 GettingKnots(Ti, InCurve, MaxDegree, NbElm, NewKnots);
130 GettingKnots(Ti, InCurve, MaxDegree - 1, NbElm, NewKnots);
131
132#endif
133 if(NbElm > NbElmOld) {
134
135 iscut = Standard_True;
136
137 OutCurve = new FEmTool_Curve(InCurve->Dimension(), NbElm, InCurve->Base(), CurveTol);
138 TColStd_Array1OfReal& OutKnots = OutCurve->Knots();
139 TColStd_Array1OfReal& InKnots = InCurve->Knots();
140
141 Standard_Integer i, i0 = OutKnots.Lower();
142 for(i = InKnots.Lower(); i <= InKnots.Upper(); i++) OutKnots(i) = InKnots(i);
143 for(i = NbElmOld + 1; i <= NbElm; i++) OutKnots(i + i0) = NewKnots(i);
144
145// SortTools_ShellSortOfReal Sort;
146 TCollection_CompareOfReal CompReal;
147
148// Sort.Sort(OutKnots, CompReal);
149 SortTools_ShellSortOfReal::Sort(OutKnots, CompReal);
150 }
151 else
152 iscut = Standard_False;
153
154}
155
156
157