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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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>
26 //=======================================================================
27 //function : GeomConvert_BSplineSurfaceToBezierSurface
29 //=======================================================================
30 GeomConvert_BSplineSurfaceToBezierSurface::GeomConvert_BSplineSurfaceToBezierSurface(const Handle(Geom_BSplineSurface)& BasisSurface)
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());
45 //=======================================================================
46 //function : GeomConvert_BSplineSurfaceToBezierSurface
48 //=======================================================================
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)
58 if ( (U2 - U1 < ParametricTolerance) ||
59 (V2 - V1 < ParametricTolerance) )
60 throw Standard_DomainError("GeomConvert_BSplineSurfaceToBezierSurface");
62 Standard_Real Uf=U1, Ul=U2, Vf=V1, Vl=V2, PTol = ParametricTolerance/2;
63 Standard_Integer I1, I2;
65 mySurface = Handle(Geom_BSplineSurface)::DownCast(BasisSurface->Copy());
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);
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);
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);
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);
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());
97 //=======================================================================
100 //=======================================================================
102 Handle(Geom_BezierSurface) GeomConvert_BSplineSurfaceToBezierSurface::Patch
103 (const Standard_Integer UIndex,
104 const Standard_Integer VIndex)
106 if (UIndex < 1 || UIndex > mySurface->NbUKnots()-1 ||
107 VIndex < 1 || VIndex > mySurface->NbVKnots()-1 ) {
108 throw Standard_OutOfRange("GeomConvert_BSplineSurfaceToBezierSurface");
110 Standard_Integer UDeg = mySurface->UDegree();
111 Standard_Integer VDeg = mySurface->VDegree();
113 TColgp_Array2OfPnt Poles(1,UDeg+1,1,VDeg+1);
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));
125 S = new Geom_BezierSurface(Poles,Weights);
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));
134 S = new Geom_BezierSurface(Poles);
140 //=======================================================================
143 //=======================================================================
145 void GeomConvert_BSplineSurfaceToBezierSurface::Patches
146 (TColGeom_Array2OfBezierSurface& Surfaces)
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);
157 //=======================================================================
160 //=======================================================================
162 void GeomConvert_BSplineSurfaceToBezierSurface::UKnots
163 (TColStd_Array1OfReal& TKnots) const
165 Standard_Integer ii, kk;
166 for (ii = 1, kk = TKnots.Lower();
167 ii <= mySurface->NbUKnots(); ii++, kk++)
168 TKnots(kk) = mySurface->UKnot(ii);
171 //=======================================================================
174 //=======================================================================
176 void GeomConvert_BSplineSurfaceToBezierSurface::VKnots
177 (TColStd_Array1OfReal& TKnots) const
179 Standard_Integer ii, kk;
180 for (ii = 1, kk = TKnots.Lower();
181 ii <= mySurface->NbVKnots(); ii++, kk++)
182 TKnots(kk) = mySurface->VKnot(ii);
185 //=======================================================================
186 //function : NbUPatches
188 //=======================================================================
190 Standard_Integer GeomConvert_BSplineSurfaceToBezierSurface::NbUPatches() const
192 return (mySurface->NbUKnots()-1);
196 //=======================================================================
197 //function : NbVPatches
199 //=======================================================================
201 Standard_Integer GeomConvert_BSplineSurfaceToBezierSurface::NbVPatches() const
203 return (mySurface->NbVKnots()-1);