0032951: Coding - get rid of unused headers [GeomConvert to IGESBasic]
[occt.git] / src / GeomConvert / GeomConvert_BSplineSurfaceToBezierSurface.cxx
1 // Created on: 1996-03-12
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Geom_BezierSurface.hxx>
19 #include <Geom_BSplineSurface.hxx>
20 #include <GeomConvert_BSplineSurfaceToBezierSurface.hxx>
21 #include <Standard_DomainError.hxx>
22 #include <Standard_OutOfRange.hxx>
23 #include <TColgp_Array2OfPnt.hxx>
24 #include <TColStd_Array2OfReal.hxx>
25
26 //=======================================================================
27 //function : GeomConvert_BSplineSurfaceToBezierSurface
28 //purpose  : 
29 //=======================================================================
30 GeomConvert_BSplineSurfaceToBezierSurface::GeomConvert_BSplineSurfaceToBezierSurface(const Handle(Geom_BSplineSurface)& BasisSurface)
31 {
32   mySurface = Handle(Geom_BSplineSurface)::DownCast(BasisSurface->Copy());
33   Standard_Real U1,U2,V1,V2;
34   mySurface->Bounds(U1,U2,V1,V2);
35   mySurface->Segment(U1,U2,V1,V2);
36   mySurface->IncreaseUMultiplicity(mySurface->FirstUKnotIndex(),
37                                    mySurface->LastUKnotIndex(),
38                                    mySurface->UDegree());
39   mySurface->IncreaseVMultiplicity(mySurface->FirstVKnotIndex(),
40                                    mySurface->LastVKnotIndex(),
41                                    mySurface->VDegree());
42 }
43
44
45 //=======================================================================
46 //function : GeomConvert_BSplineSurfaceToBezierSurface
47 //purpose  : 
48 //=======================================================================
49
50 GeomConvert_BSplineSurfaceToBezierSurface::GeomConvert_BSplineSurfaceToBezierSurface
51 (const Handle(Geom_BSplineSurface)& BasisSurface,
52  const Standard_Real U1, 
53  const Standard_Real U2, 
54  const Standard_Real V1, 
55  const Standard_Real V2, 
56  const Standard_Real ParametricTolerance)
57 {
58   if ( (U2 - U1 <  ParametricTolerance) ||
59        (V2 - V1 <  ParametricTolerance) )
60       throw Standard_DomainError("GeomConvert_BSplineSurfaceToBezierSurface");
61
62   Standard_Real Uf=U1, Ul=U2, Vf=V1, Vl=V2, PTol = ParametricTolerance/2;
63   Standard_Integer I1, I2;
64
65   mySurface = Handle(Geom_BSplineSurface)::DownCast(BasisSurface->Copy());
66
67   mySurface->LocateU(U1, PTol, I1, I2);
68   if (I1==I2) { // On est sur le noeud
69     if ( mySurface->UKnot(I1) > U1) Uf = mySurface->UKnot(I1);
70   }    
71
72   mySurface->LocateU(U2, PTol, I1, I2);
73   if (I1==I2) { // On est sur le noeud
74     if ( mySurface->UKnot(I1) < U2) Ul = mySurface->UKnot(I1);
75   }
76
77   mySurface->LocateV(V1, PTol, I1, I2);
78   if (I1==I2) { // On est sur le noeud
79     if ( mySurface->VKnot(I1) > V1) Vf = mySurface->VKnot(I1);
80   }    
81
82   mySurface->LocateV(V2, PTol, I1, I2);
83   if (I1==I2) { // On est sur le noeud
84     if ( mySurface->VKnot(I1) < V2) Vl = mySurface->VKnot(I1);
85   }
86
87   mySurface->Segment(Uf, Ul, Vf, Vl);
88   mySurface->IncreaseUMultiplicity(mySurface->FirstUKnotIndex(),
89                                    mySurface->LastUKnotIndex(),
90                                    mySurface->UDegree());
91   mySurface->IncreaseVMultiplicity(mySurface->FirstVKnotIndex(),
92                                    mySurface->LastVKnotIndex(),
93                                    mySurface->VDegree());
94 }
95
96
97 //=======================================================================
98 //function : Patch
99 //purpose  : 
100 //=======================================================================
101
102 Handle(Geom_BezierSurface) GeomConvert_BSplineSurfaceToBezierSurface::Patch
103 (const Standard_Integer UIndex,
104  const Standard_Integer VIndex)
105 {
106   if (UIndex < 1 || UIndex > mySurface->NbUKnots()-1 ||
107       VIndex < 1 || VIndex > mySurface->NbVKnots()-1   ) {
108     throw Standard_OutOfRange("GeomConvert_BSplineSurfaceToBezierSurface");
109   }
110   Standard_Integer UDeg = mySurface->UDegree();
111   Standard_Integer VDeg = mySurface->VDegree();
112
113   TColgp_Array2OfPnt Poles(1,UDeg+1,1,VDeg+1);
114
115   Handle(Geom_BezierSurface) S;
116   if ( mySurface->IsURational() || mySurface->IsVRational()) {
117     TColStd_Array2OfReal Weights(1,UDeg+1,1,VDeg+1);
118     for ( Standard_Integer i = 1; i <= UDeg+1; i++) {
119       Standard_Integer CurI = i+UDeg*(UIndex-1);
120       for ( Standard_Integer j = 1; j <= VDeg+1; j++) {
121         Poles(i,j)   = mySurface->Pole(CurI,j+VDeg*(VIndex-1));
122         Weights(i,j) = mySurface->Weight(CurI,j+VDeg*(VIndex-1));
123       }
124     }
125     S = new Geom_BezierSurface(Poles,Weights);
126   }
127   else {
128     for ( Standard_Integer i = 1; i <= UDeg+1; i++) {
129       Standard_Integer CurI = i+UDeg*(UIndex-1);
130       for ( Standard_Integer j = 1; j <= VDeg+1; j++) {
131         Poles(i,j)   = mySurface->Pole(CurI,j+VDeg*(VIndex-1));
132       }
133     }
134     S = new Geom_BezierSurface(Poles);
135   }
136   return S;
137 }
138
139
140 //=======================================================================
141 //function : Patches
142 //purpose  : 
143 //=======================================================================
144
145 void GeomConvert_BSplineSurfaceToBezierSurface::Patches
146 (TColGeom_Array2OfBezierSurface& Surfaces)
147 {
148   Standard_Integer NbU = NbUPatches();
149   Standard_Integer NbV = NbVPatches();
150   for (Standard_Integer i = 1; i <= NbU; i++) {
151     for (Standard_Integer j = 1; j <= NbV; j++) {
152       Surfaces(i,j) = Patch(i,j);
153     }
154   }
155 }
156
157 //=======================================================================
158 //function : UKnots
159 //purpose  : 
160 //=======================================================================
161
162 void GeomConvert_BSplineSurfaceToBezierSurface::UKnots
163      (TColStd_Array1OfReal& TKnots) const
164 {
165  Standard_Integer ii, kk;
166   for (ii = 1, kk = TKnots.Lower();
167        ii <= mySurface->NbUKnots(); ii++, kk++)
168     TKnots(kk) = mySurface->UKnot(ii);
169 }
170
171 //=======================================================================
172 //function : VKnots
173 //purpose  : 
174 //=======================================================================
175
176 void GeomConvert_BSplineSurfaceToBezierSurface::VKnots
177      (TColStd_Array1OfReal& TKnots) const
178 {
179  Standard_Integer ii, kk;
180   for (ii = 1, kk = TKnots.Lower();
181        ii <= mySurface->NbVKnots(); ii++, kk++)
182     TKnots(kk) = mySurface->VKnot(ii);
183 }
184
185 //=======================================================================
186 //function : NbUPatches
187 //purpose  : 
188 //=======================================================================
189
190 Standard_Integer GeomConvert_BSplineSurfaceToBezierSurface::NbUPatches() const 
191 {
192   return (mySurface->NbUKnots()-1);
193 }
194
195
196 //=======================================================================
197 //function : NbVPatches
198 //purpose  : 
199 //=======================================================================
200
201 Standard_Integer GeomConvert_BSplineSurfaceToBezierSurface::NbVPatches() const 
202 {
203   return (mySurface->NbVKnots()-1);
204 }
205
206