summaryrefslogtreecommitdiff
path: root/src/GeomConvert/GeomConvert_BSplineSurfaceToBezierSurface.cxx
blob: c8b48b3aef1bf4e6c3716e81c743ec5e51b83557 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// File:	GeomConvert_BSplineSurfaceToBezierSurface.cxx
// Created:	Tue Mar 12 17:33:28 1996
// Author:	Bruno DUMORTIER
//		<dub@fuegox>


#include <GeomConvert_BSplineSurfaceToBezierSurface.ixx>

#include <TColgp_Array2OfPnt.hxx>
#include <TColStd_Array2OfReal.hxx>


//=======================================================================
//function : GeomConvert_BSplineSurfaceToBezierSurface
//purpose  : 
//=======================================================================

GeomConvert_BSplineSurfaceToBezierSurface::GeomConvert_BSplineSurfaceToBezierSurface(const Handle(Geom_BSplineSurface)& BasisSurface)
{
  mySurface = Handle(Geom_BSplineSurface)::DownCast(BasisSurface->Copy());
  Standard_Real U1,U2,V1,V2;
  mySurface->Bounds(U1,U2,V1,V2);
  mySurface->Segment(U1,U2,V1,V2);
  mySurface->IncreaseUMultiplicity(mySurface->FirstUKnotIndex(),
				   mySurface->LastUKnotIndex(),
				   mySurface->UDegree());
  mySurface->IncreaseVMultiplicity(mySurface->FirstVKnotIndex(),
				   mySurface->LastVKnotIndex(),
				   mySurface->VDegree());
}


//=======================================================================
//function : GeomConvert_BSplineSurfaceToBezierSurface
//purpose  : 
//=======================================================================

GeomConvert_BSplineSurfaceToBezierSurface::GeomConvert_BSplineSurfaceToBezierSurface
(const Handle(Geom_BSplineSurface)& BasisSurface,
 const Standard_Real U1, 
 const Standard_Real U2, 
 const Standard_Real V1, 
 const Standard_Real V2, 
 const Standard_Real ParametricTolerance)
{
  if ( (U2 - U1 <  ParametricTolerance) ||
       (V2 - V1 <  ParametricTolerance) )
      Standard_DomainError::Raise("GeomConvert_BSplineSurfaceToBezierSurface");

  Standard_Real Uf=U1, Ul=U2, Vf=V1, Vl=V2, PTol = ParametricTolerance/2;
  Standard_Integer I1, I2;

  mySurface = Handle(Geom_BSplineSurface)::DownCast(BasisSurface->Copy());

  mySurface->LocateU(U1, PTol, I1, I2);
  if (I1==I2) { // On est sur le noeud
    if ( mySurface->UKnot(I1) > U1) Uf = mySurface->UKnot(I1);
  }    

  mySurface->LocateU(U2, PTol, I1, I2);
  if (I1==I2) { // On est sur le noeud
    if ( mySurface->UKnot(I1) < U2) Ul = mySurface->UKnot(I1);
  }

  mySurface->LocateV(V1, PTol, I1, I2);
  if (I1==I2) { // On est sur le noeud
    if ( mySurface->VKnot(I1) > V1) Vf = mySurface->VKnot(I1);
  }    

  mySurface->LocateV(V2, PTol, I1, I2);
  if (I1==I2) { // On est sur le noeud
    if ( mySurface->VKnot(I1) < V2) Vl = mySurface->VKnot(I1);
  }

  mySurface->Segment(Uf, Ul, Vf, Vl);
  mySurface->IncreaseUMultiplicity(mySurface->FirstUKnotIndex(),
				   mySurface->LastUKnotIndex(),
				   mySurface->UDegree());
  mySurface->IncreaseVMultiplicity(mySurface->FirstVKnotIndex(),
				   mySurface->LastVKnotIndex(),
				   mySurface->VDegree());
}


//=======================================================================
//function : Patch
//purpose  : 
//=======================================================================

Handle(Geom_BezierSurface) GeomConvert_BSplineSurfaceToBezierSurface::Patch
(const Standard_Integer UIndex,
 const Standard_Integer VIndex)
{
  if (UIndex < 1 || UIndex > mySurface->NbUKnots()-1 ||
      VIndex < 1 || VIndex > mySurface->NbVKnots()-1   ) {
    Standard_OutOfRange::Raise("GeomConvert_BSplineSurfaceToBezierSurface");
  }
  Standard_Integer UDeg = mySurface->UDegree();
  Standard_Integer VDeg = mySurface->VDegree();

  TColgp_Array2OfPnt Poles(1,UDeg+1,1,VDeg+1);

  Handle(Geom_BezierSurface) S;
  if ( mySurface->IsURational() || mySurface->IsVRational()) {
    TColStd_Array2OfReal Weights(1,UDeg+1,1,VDeg+1);
    for ( Standard_Integer i = 1; i <= UDeg+1; i++) {
      Standard_Integer CurI = i+UDeg*(UIndex-1);
      for ( Standard_Integer j = 1; j <= VDeg+1; j++) {
	Poles(i,j)   = mySurface->Pole(CurI,j+VDeg*(VIndex-1));
	Weights(i,j) = mySurface->Weight(CurI,j+VDeg*(VIndex-1));
      }
    }
    S = new Geom_BezierSurface(Poles,Weights);
  }
  else {
    for ( Standard_Integer i = 1; i <= UDeg+1; i++) {
      Standard_Integer CurI = i+UDeg*(UIndex-1);
      for ( Standard_Integer j = 1; j <= VDeg+1; j++) {
	Poles(i,j)   = mySurface->Pole(CurI,j+VDeg*(VIndex-1));
      }
    }
    S = new Geom_BezierSurface(Poles);
  }
  return S;
}


//=======================================================================
//function : Patches
//purpose  : 
//=======================================================================

void GeomConvert_BSplineSurfaceToBezierSurface::Patches
(TColGeom_Array2OfBezierSurface& Surfaces)
{
  Standard_Integer NbU = NbUPatches();
  Standard_Integer NbV = NbVPatches();
  for (Standard_Integer i = 1; i <= NbU; i++) {
    for (Standard_Integer j = 1; j <= NbV; j++) {
      Surfaces(i,j) = Patch(i,j);
    }
  }
}

//=======================================================================
//function : UKnots
//purpose  : 
//=======================================================================

void GeomConvert_BSplineSurfaceToBezierSurface::UKnots
     (TColStd_Array1OfReal& TKnots) const
{
 Standard_Integer ii, kk;
  for (ii = 1, kk = TKnots.Lower();
       ii <= mySurface->NbUKnots(); ii++, kk++)
    TKnots(kk) = mySurface->UKnot(ii);
}

//=======================================================================
//function : VKnots
//purpose  : 
//=======================================================================

void GeomConvert_BSplineSurfaceToBezierSurface::VKnots
     (TColStd_Array1OfReal& TKnots) const
{
 Standard_Integer ii, kk;
  for (ii = 1, kk = TKnots.Lower();
       ii <= mySurface->NbVKnots(); ii++, kk++)
    TKnots(kk) = mySurface->VKnot(ii);
}

//=======================================================================
//function : NbUPatches
//purpose  : 
//=======================================================================

Standard_Integer GeomConvert_BSplineSurfaceToBezierSurface::NbUPatches() const 
{
  return (mySurface->NbUKnots()-1);
}


//=======================================================================
//function : NbVPatches
//purpose  : 
//=======================================================================

Standard_Integer GeomConvert_BSplineSurfaceToBezierSurface::NbVPatches() const 
{
  return (mySurface->NbVKnots()-1);
}