0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / IGESConvGeom / IGESConvGeom.cxx
CommitLineData
b311480e 1// Created on: 1994-09-01
2// Created by: Christian CAILLET
3// Copyright (c) 1994-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
ce7fe22d 17#include <IGESConvGeom.hxx>
7fd59977 18
7fd59977 19#include <BSplCLib.hxx>
7fd59977 20#include <BSplSLib.hxx>
42cf5bc1 21#include <Geom2d_BSplineCurve.hxx>
22#include <Geom_BSplineCurve.hxx>
23#include <Geom_BSplineSurface.hxx>
7fd59977 24#include <gp_GTrsf.hxx>
25#include <gp_Trsf.hxx>
42cf5bc1 26#include <IGESData_ToolLocation.hxx>
27#include <IGESGeom_SplineCurve.hxx>
28#include <IGESGeom_SplineSurface.hxx>
7fd59977 29#include <PLib.hxx>
7fd59977 30#include <TColgp_HArray1OfPnt.hxx>
7fd59977 31#include <TColStd_Array1OfInteger.hxx>
32#include <TColStd_Array1OfReal.hxx>
33#include <TColStd_HArray1OfReal.hxx>
34
7fd59977 35//=======================================================================
36//function : IGESConvGeom::SplineCurveFromIGES
37//purpose :
38//=======================================================================
39Standard_Integer IGESConvGeom::SplineCurveFromIGES
40 (const Handle(IGESGeom_SplineCurve)& st,
41 const Standard_Real /*epscoef*/, const Standard_Real epsgeom,
42 Handle(Geom_BSplineCurve)& res)
43{
44 Standard_Integer returned = 0;
45
46 // on recupere le degre
47 Standard_Integer degree = st->SplineType();
48 if (degree > 3) degree = 3;
49
50 // on recupere le nombre de segments.
51 Standard_Integer nbSegs = st->NbSegments();
52 if (nbSegs < 1) return 5; // FAIL : no segment
53
54 Standard_Integer nbKnots = nbSegs+1;
55
56 // Array of multiplicities.
57 TColStd_Array1OfInteger multi(1, nbKnots);
58 multi.Init(degree);
59 multi.SetValue(multi.Lower(), degree+1);
60 multi.SetValue(multi.Upper(), degree+1);
61
62 // Array of knots.
63 TColStd_Array1OfReal knots(1, nbKnots);
64 TColStd_Array1OfReal delta(1, nbSegs);
65 Standard_Integer i; // svv Jan 10 2000 : porting on DEC
66 for (i = 1; i<= nbKnots; i++)
67 knots.SetValue(i, st->BreakPoint(i));
68
69 for (i = 1; i <= nbSegs; i++)
70 delta.SetValue(i, st->BreakPoint(i+1) - st->BreakPoint(i));
71
72 TColgp_Array1OfPnt bspoles(1, nbSegs*degree+1);
73 Standard_Integer ibspole = bspoles.Lower()-1; // Bspole Index.
74 // il faut reparametrer avant de passer dans PLib.
75 // on est entre[0, T(i+1)-T(i)] et on veut [0,1]
76
77 for (i = 1; i <= nbSegs; i++) {
78 Standard_Real AX,BX,CX,DX,AY,BY,CY,DY,AZ,BZ,CZ,DZ;
79 st->XCoordPolynomial(i, AX, BX, CX, DX);
80 st->YCoordPolynomial(i, AY, BY, CY, DY);
81 st->ZCoordPolynomial(i, AZ, BZ, CZ, DZ);
82 if (st->NbDimensions() == 2 ) BZ=0.,CZ=0.,DZ=0.;
83 Standard_Real Di = delta(i);
84 Standard_Real Di2 = delta(i)*delta(i);
85 Standard_Real Di3 = delta(i)*delta(i)*delta(i);
86
87 TColgp_Array1OfPnt coeff(0, degree);
88 switch (degree) {
89 case 3 :
90 coeff.SetValue(coeff.Lower()+3, gp_Pnt(DX*Di3, DY*Di3, DZ*Di3));
b1811c1d 91 Standard_FALLTHROUGH
7fd59977 92 case 2 :
93 coeff.SetValue(coeff.Lower()+2, gp_Pnt(CX*Di2, CY*Di2, CZ*Di2));
b1811c1d 94 Standard_FALLTHROUGH
7fd59977 95 case 1 :
96 coeff.SetValue(coeff.Lower()+1, gp_Pnt(BX*Di, BY*Di, BZ*Di));
97 coeff.SetValue(coeff.Lower()+0, gp_Pnt(AX, AY, AZ));
98 break;
99 default:
100 break;
101 }
102
103
104 TColgp_Array1OfPnt bzpoles(0, degree);
105 PLib::CoefficientsPoles(coeff,PLib::NoWeights(),bzpoles,PLib::NoWeights());
106
107 // C0 test.
108 // Not to check the first pole of the first segment.
109 if (ibspole > bspoles.Lower()) {
110 Standard_Integer bzlow = bzpoles.Lower();
111 if (!(bspoles.Value(ibspole).IsEqual(bzpoles.Value(bzlow), epsgeom))) {
112 returned = 1;
113 // Medium point computing.
114 bspoles.SetValue (ibspole,
115 gp_Pnt((bspoles.Value(ibspole).X() + bzpoles.Value(bzlow).X())/2.,
116 (bspoles.Value(ibspole).Y() + bzpoles.Value(bzlow).Y())/2.,
117 (bspoles.Value(ibspole).Z() + bzpoles.Value(bzlow).Z())/2.));
118 }
119 }
120 if (i == 1) bspoles.SetValue(++ibspole, bzpoles.Value(bzpoles.Lower()));
121
122 for (Standard_Integer j = bzpoles.Lower()+1; j <= bzpoles.Upper(); j++)
123 bspoles.SetValue(++ibspole, bzpoles.Value(j));
124 }
125 if (ibspole != bspoles.Upper()) {
126 // Just to be sure.
127 return 3; // FAIL : Error during creation of control points
128 }
129
130 // Building result taking into account transformation if any :
131 // ===========================================================
132
133 //%13 pdn 12.02.99 USA60293
134// if (st->HasTransf()) {
135// gp_Trsf trsf;
136// Standard_Real epsilon = 1.E-04;
137// if (IGESData_ToolLocation::ConvertLocation
138// (epsilon,st->CompoundLocation(),trsf)) {
139// for (Standard_Integer i = bspoles.Lower(); i <= bspoles.Upper(); i++)
140// bspoles.SetValue(i, bspoles.Value(i).Transformed(trsf));
141// }
142// else
143// AddFail(st, "Transformation : not a similarity");
144// }
145 res = new Geom_BSplineCurve (bspoles, knots, multi, degree);
146// GeomConvert_CompCurveToBSplineCurve CompCurve =
147// GeomConvert_CompCurveToBSplineCurve(res);
148// res = CompCurve.BSplineCurve();
149 return returned;
150}
151
152
153
154//=======================================================================
155//function : IGESConvGeom::IncreaseCurveContinuity
156//purpose :
157//=======================================================================
158Standard_Integer IGESConvGeom::IncreaseCurveContinuity (const Handle(Geom_BSplineCurve)& res,
159 const Standard_Real epsgeom,
160 const Standard_Integer continuity)
161{
162 if (continuity < 1) return continuity;
163 Standard_Boolean isC1 = Standard_True, isC2 = Standard_True;
164 Standard_Integer degree = res->Degree();
165
166
167 Standard_Boolean isModified;
168 do {
169 isModified = Standard_False;
170 for (Standard_Integer i = res->FirstUKnotIndex()+1; i < res->LastUKnotIndex(); i++)
171 if(degree - res->Multiplicity(i) < continuity) {
172 if (continuity >= 2) {
173 if (!res->RemoveKnot(i, degree-2, epsgeom)) {
174 isC2 = Standard_False;
175 Standard_Boolean locOK = res->RemoveKnot(i, degree-1, epsgeom); // is C1 ?
176 isC1 &= locOK;
177 isModified |= locOK;
178 }
179 else
180 isModified = Standard_True;
181 }
182 else {
183 Standard_Boolean locOK = res->RemoveKnot(i, degree-1, epsgeom); // is C1 ?
184 isC1 &= locOK;
185 isModified |= locOK;
186 }
187 }
188 }
189 while (isModified);
190
191 if (!isC1) return 0;
192 if (continuity >= 2 && !isC2) return 1;
193 return continuity;
194}
195
196//=======================================================================
197//function : IncreaseCurveContinuity
198//purpose :
199//=======================================================================
200
201Standard_Integer IGESConvGeom::IncreaseCurveContinuity (const Handle(Geom2d_BSplineCurve)& res,
202 const Standard_Real epsgeom,
203 const Standard_Integer continuity)
204{
205 if (continuity < 1) return continuity;
206 Standard_Boolean isC1 = Standard_True, isC2 = Standard_True;
207 Standard_Integer degree = res->Degree();
208
209 Standard_Boolean isModified;
210 do {
211 isModified = Standard_False;
212 for (Standard_Integer i = res->FirstUKnotIndex()+1; i < res->LastUKnotIndex(); i++)
213 if(degree - res->Multiplicity(i) < continuity) {
214 if (continuity >= 2) {
215 if (!res->RemoveKnot(i, degree-2, epsgeom)) {
216 isC2 = Standard_False;
217 Standard_Boolean locOK = res->RemoveKnot(i, degree-1, epsgeom); // is C1 ?
218 isC1 &= locOK;
219 isModified |= locOK;
220 }
221 else
222 isModified = Standard_True;
223 }
224 else {
225 Standard_Boolean locOK = res->RemoveKnot(i, degree-1, epsgeom); // is C1 ?
226 isC1 &= locOK;
227 isModified |= locOK;
228 }
229 }
230 }
231 while (isModified);
232
233 if (!isC1) return 0;
234 if (continuity >= 2 && !isC2) return 1;
235 return continuity;
236}
237
238
239//=======================================================================
240//function : IGESConvGeom::SplineSurfaceFromIGES
241//purpose :
242//=======================================================================
243Standard_Integer IGESConvGeom::SplineSurfaceFromIGES
244 (const Handle(IGESGeom_SplineSurface)& st,
245 const Standard_Real /*epscoef*/, const Standard_Real epsgeom,
246 Handle(Geom_BSplineSurface)& res)
247{
248 Standard_Integer returned = 0;
249 Standard_Integer degree = st->BoundaryType();
250 if (degree > 3) degree = 3;
251 Standard_Integer DegreeU = degree;
252 Standard_Integer DegreeV = degree;
253
254 Standard_Integer NbUSeg = st->NbUSegments();
255 Standard_Integer NbVSeg = st->NbVSegments();
256
257 if ((NbUSeg < 1) || (NbVSeg < 1)) return 5;
258
259 // Output BSpline knots & multiplicities arraies for U & V :
260 // =========================================================
261
262 TColStd_Array1OfReal UKnot(1,NbUSeg+1);
263 TColStd_Array1OfReal VKnot(1,NbVSeg+1);
264 TColStd_Array1OfReal deltaU(1,NbUSeg);
265 TColStd_Array1OfReal deltaV(1,NbVSeg);
266
267 Standard_Integer i; // svv Jan 10 2000 : porting on DEC
268 for (i=1; i <= NbUSeg+1; i++)
269 UKnot.SetValue(i, st->UBreakPoint(i));
270
271 for (i=1; i <= NbUSeg; i++)
272 deltaU.SetValue(i, st->UBreakPoint(i+1)- st->UBreakPoint(i));
273
274 for (i=1; i <= NbVSeg+1; i++)
275 VKnot.SetValue(i, st->VBreakPoint(i));
276
277 for (i=1; i <= NbVSeg; i++)
278 deltaV.SetValue(i, st->VBreakPoint(i+1)- st->VBreakPoint(i));
279
280 TColStd_Array1OfInteger UMult(1,NbUSeg+1); UMult.Init(DegreeU);
281 UMult.SetValue(UMult.Lower(),DegreeU+1);
282 UMult.SetValue(UMult.Upper(),DegreeU+1);
283
284 TColStd_Array1OfInteger VMult(1,NbVSeg+1); VMult.Init(DegreeV);
285 VMult.SetValue(VMult.Lower(),DegreeV+1);
286 VMult.SetValue(VMult.Upper(),DegreeV+1);
287
288
289 // Poles computing
290 // ===============
291
292 Standard_Integer NbUPoles = NbUSeg * DegreeU + 1;
293 Standard_Integer NbVPoles = NbVSeg * DegreeV + 1;
294
295 TColgp_Array2OfPnt BsPole(1, NbUPoles, 1, NbVPoles);
296
297 Standard_Integer iBs, jBs, iBz, jBz;
298 Standard_Boolean wasC0 = Standard_True;
299
300 // Patch (1,1)
301 // ===========
302 Standard_Integer USeg, VSeg, j;
303 USeg = 1;
304 VSeg = 1;
305
306 Handle(TColStd_HArray1OfReal) XPoly = st->XPolynomial(USeg, VSeg);
307 Handle(TColStd_HArray1OfReal) YPoly = st->YPolynomial(USeg, VSeg);
308 Handle(TColStd_HArray1OfReal) ZPoly = st->ZPolynomial(USeg, VSeg);
309
310 TColgp_Array2OfPnt Coef(1, DegreeU+1, 1, DegreeV+1);
311 Standard_Real ParamU, ParamV;
312 ParamU = 1.;
313 for (i=1; i<=DegreeU+1; i++) {
314 ParamV = 1.;
315 for (j=1; j<=DegreeV+1; j++) {
316 Standard_Integer PolyIndex = i + 4*(j-1);
317 gp_Pnt aPoint(XPoly->Value(PolyIndex)*ParamU*ParamV,
318 YPoly->Value(PolyIndex)*ParamU*ParamV,
319 ZPoly->Value(PolyIndex)*ParamU*ParamV);
320 Coef.SetValue(i, j, aPoint);
321 ParamV = ParamV *deltaV(VSeg);
322 }
323 ParamU = ParamU * deltaU(USeg);
324 }
325 TColgp_Array2OfPnt BzPole(1, DegreeU+1, 1, DegreeV+1);
326 PLib::CoefficientsPoles(Coef,PLib::NoWeights2(),BzPole,PLib::NoWeights2());
327
328 iBs = BsPole.LowerRow();
329 jBs = BsPole.LowerCol();
330
331 // Making output BSpline poles array :
332 for (iBz=BzPole.LowerRow(); iBz<=BzPole.UpperRow(); iBz++) {
333 for (jBz=BzPole.LowerCol(); jBz<=BzPole.UpperCol(); jBz++)
334 BsPole.SetValue(iBs, jBs++, BzPole.Value(iBz,jBz));
335 jBs = BsPole.LowerCol();
336 iBs++;
337 }
338
339
340 // Patches (1<USeg<NbUSeg, 1)
341 // ==========================
342
343 VSeg = 1;
344 for (USeg=2; USeg<=NbUSeg; USeg++) {
345 XPoly = st->XPolynomial(USeg, VSeg);
346 YPoly = st->YPolynomial(USeg, VSeg);
347 ZPoly = st->ZPolynomial(USeg, VSeg);
7fd59977 348 ParamU = 1.;
349 for (i=Coef.LowerRow(); i<=Coef.UpperRow(); i++) {
350 ParamV = 1.;
351 for (j=Coef.LowerCol(); j<=Coef.UpperCol(); j++) {
352 Standard_Integer PolyIndex = i + 4*(j-1);
353 gp_Pnt aPoint;
354 aPoint.SetCoord(XPoly->Value(PolyIndex)*ParamU*ParamV,
355 YPoly->Value(PolyIndex)*ParamU*ParamV,
356 ZPoly->Value(PolyIndex)*ParamU*ParamV);
357 Coef.SetValue(i, j, aPoint);
358 ParamV = ParamV *deltaV(VSeg);
359 }
360 ParamU = ParamU * deltaU(USeg);
361 }
362 PLib::CoefficientsPoles(Coef,PLib::NoWeights2(),BzPole,PLib::NoWeights2());
363
364 // C0 check and correction for poles lying on isoparametrics U=0 & V=0
51740958 365 Standard_Integer iBsPole = BsPole.LowerRow() + (USeg-1)*DegreeU;
366 Standard_Integer jBsPole = BsPole.LowerCol();
7fd59977 367 iBz = BzPole.LowerRow();
368 for (jBz=BzPole.LowerCol(); jBz<=BzPole.UpperCol(); jBz++) {
51740958 369 if (!BzPole.Value(iBz,jBz).IsEqual(BsPole.Value(iBsPole,jBsPole), epsgeom)) {
7fd59977 370 wasC0=Standard_False;
371 gp_Pnt MidPoint;
372 Standard_Real XCoord =
51740958 373 0.5 * (BzPole.Value(iBz,jBz).X() + BsPole.Value(iBsPole,jBsPole).X());
7fd59977 374 Standard_Real YCoord =
51740958 375 0.5 * (BzPole.Value(iBz,jBz).Y() + BsPole.Value(iBsPole,jBsPole).Y());
7fd59977 376 Standard_Real ZCoord =
51740958 377 0.5 * (BzPole.Value(iBz,jBz).Z() + BsPole.Value(iBsPole,jBsPole).Z());
7fd59977 378 MidPoint.SetCoord(XCoord, YCoord, ZCoord);
51740958 379 BsPole.SetValue(iBsPole, jBsPole++, MidPoint);
7fd59977 380 }
381 else {
51740958 382 BsPole.SetValue(iBsPole, jBsPole++, BzPole.Value(iBz,jBz));
7fd59977 383 }
384 }
385
386 // Other poles (no check about C0) :
51740958 387 iBsPole++;
388 jBsPole = BsPole.LowerCol();
7fd59977 389 for (iBz=BzPole.LowerRow()+1; iBz<=BzPole.UpperRow(); iBz++) {
390 for (jBz=BzPole.LowerCol(); jBz<=BzPole.UpperCol(); jBz++)
51740958 391 BsPole.SetValue(iBsPole, jBsPole++, BzPole.Value(iBz,jBz));
392 iBsPole++;
393 jBsPole = BsPole.LowerCol();
7fd59977 394 }
395 }
396
397
398
399 // Patches (1, 1<VSeg<NbVSeg)
400 // ==========================
401
402 USeg = 1;
403 for (VSeg=2; VSeg <= NbVSeg; VSeg++) {
404 XPoly = st->XPolynomial(USeg, VSeg);
405 YPoly = st->YPolynomial(USeg, VSeg);
406 ZPoly = st->ZPolynomial(USeg, VSeg);
7fd59977 407 ParamU = 1.;
408 for (i=Coef.LowerRow(); i<=Coef.UpperRow(); i++) {
409 ParamV = 1.;
410 for (j=Coef.LowerCol(); j<=Coef.UpperCol(); j++) {
411 Standard_Integer PolyIndex = i + 4*(j-1);
412 gp_Pnt aPoint;
413 aPoint.SetCoord(XPoly->Value(PolyIndex)*ParamU*ParamV,
414 YPoly->Value(PolyIndex)*ParamU*ParamV,
415 ZPoly->Value(PolyIndex)*ParamU*ParamV);
416 Coef.SetValue(i, j, aPoint);
417 ParamV = ParamV *deltaV(VSeg);
418 }
419 ParamU = ParamU * deltaU(USeg);
420 }
421 PLib::CoefficientsPoles(Coef,PLib::NoWeights2(),BzPole,PLib::NoWeights2());
422
423 // C0 check and correction for poles lying on isoparametrics U=0 & V=0
424 iBs = BsPole.LowerRow();
425 jBs = BsPole.LowerCol() + (VSeg-1)*DegreeV;
426 jBz = BzPole.LowerCol();
427 for (iBz=BzPole.LowerRow(); iBz<=BzPole.UpperRow(); iBz++) {
428 if (!BzPole.Value(iBz,jBz).IsEqual(BsPole.Value(iBs,jBs), epsgeom)) {
429 wasC0=Standard_False;
430 gp_Pnt MidPoint;
431 Standard_Real XCoord = 0.5 *
432 (BzPole.Value(iBz,jBz).X() + BsPole.Value(iBs,jBs).X());
433 Standard_Real YCoord = 0.5 *
434 (BzPole.Value(iBz,jBz).Y() + BsPole.Value(iBs,jBs).Y());
435 Standard_Real ZCoord = 0.5 *
436 (BzPole.Value(iBz,jBz).Z() + BsPole.Value(iBs,jBs).Z());
437 MidPoint.SetCoord(XCoord, YCoord, ZCoord);
438 BsPole.SetValue(iBs++, jBs, MidPoint);
439 }
440 else{
441 BsPole.SetValue(iBs++, jBs, BzPole.Value(iBz,jBz));
442 }
443 }
444
445 jBs++;
446 iBs = BsPole.LowerRow();
447 for (jBz=BzPole.LowerCol()+1; jBz<=BzPole.UpperCol(); jBz++) {
448 for (iBz=BzPole.LowerRow(); iBz<=BzPole.UpperRow(); iBz++)
449 BsPole.SetValue(iBs++, jBs, BzPole.Value(iBz,jBz));
450 iBs = BsPole.LowerRow();
451 jBs++;
452 }
453 }
454
455
456 // Patches (1<USeg<NbUSeg, 1<VSeg<NbVSeg)
457 // ======================================
458
459 for (VSeg=2; VSeg <= NbVSeg; VSeg++) {
460 for (USeg=2; USeg <= NbUSeg; USeg++) {
461 XPoly = st->XPolynomial(USeg, VSeg);
462 YPoly = st->YPolynomial(USeg, VSeg);
463 ZPoly = st->ZPolynomial(USeg, VSeg);
7fd59977 464 ParamU = 1.;
465 for (i=Coef.LowerRow(); i<=Coef.UpperRow(); i++) {
466 ParamV = 1.;
467 for (j=Coef.LowerCol(); j<=Coef.UpperCol(); j++) {
468 Standard_Integer PolyIndex = i + 4*(j-1);
469 gp_Pnt aPoint;
470 aPoint.SetCoord(XPoly->Value(PolyIndex)*ParamU*ParamV,
471 YPoly->Value(PolyIndex)*ParamU*ParamV,
472 ZPoly->Value(PolyIndex)*ParamU*ParamV);
473 Coef.SetValue(i, j, aPoint);
474 ParamV = ParamV *deltaV(VSeg);
475 }
476 ParamU = ParamU * deltaU(USeg);
477 }
478 PLib::CoefficientsPoles(Coef,PLib::NoWeights2(),BzPole,PLib::NoWeights2());
479
480 // C0 check and correction for poles lying on isoparametrics U=0 & V=0
481 iBs = (USeg-1)*DegreeU + BsPole.LowerRow();
482 jBs = (VSeg-1)*DegreeV + BsPole.LowerCol();
483 jBz = BzPole.LowerCol();
484 for (iBz=BzPole.LowerRow(); iBz<=BzPole.UpperRow(); iBz++) {
485 if (!BzPole.Value(iBz,jBz).IsEqual(BsPole.Value(iBs,jBs), epsgeom)) {
486 wasC0=Standard_False;
487 gp_Pnt MidPoint;
488 Standard_Real XCoord = 0.5 *
489 (BzPole.Value(iBz,jBz).X() + BsPole.Value(iBs,jBs).X());
490 Standard_Real YCoord = 0.5 *
491 (BzPole.Value(iBz,jBz).Y() + BsPole.Value(iBs,jBs).Y());
492 Standard_Real ZCoord = 0.5 *
493 (BzPole.Value(iBz,jBz).Z() + BsPole.Value(iBs,jBs).Z());
494 MidPoint.SetCoord(XCoord, YCoord, ZCoord);
495 BsPole.SetValue(iBs++, jBs, MidPoint);
496 }
497 else
498 BsPole.SetValue(iBs++, jBs, BzPole.Value(iBz,jBz));
499 }
500
501 iBs = (USeg-1)*DegreeU + BsPole.LowerRow();
502 iBz = BzPole.LowerRow();
503 for (jBz=BzPole.LowerCol(); jBz<=BzPole.UpperCol(); jBz++) {
504 // C0 check and correction for poles lying on isoparametrics U=0 & V=0
505 if (!BzPole.Value(iBz,jBz).IsEqual(BsPole.Value(iBs,jBs), epsgeom)) {
506 wasC0=Standard_False;
507 gp_Pnt MidPoint;
508 Standard_Real XCoord = 0.5 *
509 (BzPole.Value(iBz,jBz).X() + BsPole.Value(iBs,jBs).X());
510 Standard_Real YCoord = 0.5 *
511 (BzPole.Value(iBz,jBz).Y() + BsPole.Value(iBs,jBs).Y());
512 Standard_Real ZCoord = 0.5 *
513 (BzPole.Value(iBz,jBz).Z() + BsPole.Value(iBs,jBs).Z());
514 MidPoint.SetCoord(XCoord, YCoord, ZCoord);
515 BsPole.SetValue(iBs, jBs++, MidPoint);
516 }
517 else
518 BsPole.SetValue(iBs, jBs++, BzPole.Value(iBz,jBz));
519 }
520
521 iBs = BsPole.LowerRow() + (USeg-1)*DegreeU + 1;
522 jBs = BsPole.LowerCol() + (VSeg-1)*DegreeV + 1;
523 for (iBz=BzPole.LowerRow()+1; iBz<=BzPole.UpperRow(); iBz++) {
524 for (jBz=BzPole.LowerCol()+1; jBz<=BzPole.UpperCol(); jBz++)
525 BsPole.SetValue(iBs, jBs++, BzPole.Value(iBz,jBz));
526 jBs = BsPole.LowerCol() + (VSeg-1)*DegreeV + 1;
527 iBs++;
528 }
529 }
530 }
531
532 // Building result taking into account transformation if any :
533 // ===========================================================
534
535 if (st->HasTransf()) {
536 gp_GTrsf GSplTrsf(st->CompoundLocation());
537 gp_Trsf SplTrsf;
538 Standard_Real epsilon = 1.E-04;
539 if (IGESData_ToolLocation::ConvertLocation(epsilon,GSplTrsf,SplTrsf))
540 for (iBs=BsPole.LowerRow(); iBs<=BsPole.UpperRow(); iBs++)
541 for (jBs=BsPole.LowerCol(); jBs<=BsPole.UpperCol(); jBs++)
542 BsPole.SetValue(iBs, jBs, BsPole.Value(iBs,jBs).Transformed(SplTrsf));
543// else
544// AddWarning(start, "Transformation skipped : Not a similarity");
545 }
546
547 res = new Geom_BSplineSurface
548 (BsPole, UKnot, VKnot, UMult, VMult, DegreeU, DegreeV);
549 if (wasC0) returned += 1;
550 return returned;
551}
552
553
554//=======================================================================
555//function : IGESConvGeom::IncreaseSurfaceContinuity
556//purpose :
557//=======================================================================
558Standard_Integer IGESConvGeom::IncreaseSurfaceContinuity (const Handle(Geom_BSplineSurface)& res,
559 const Standard_Real epsgeom,
560 const Standard_Integer continuity)
561{
562 if (continuity < 1) return continuity;
563 Standard_Boolean isC1 = Standard_True, isC2 = Standard_True;
7fd59977 564 Standard_Integer DegreeU = res->UDegree();
565
566 Standard_Boolean isModified;
567 do {
568 isModified = Standard_False;
96a95605 569 for (Standard_Integer i = res->FirstUKnotIndex()+1; i < res->LastUKnotIndex(); i++)
7fd59977 570 if(DegreeU - res->UMultiplicity(i) < continuity) {
571 if (continuity >= 2) {
572 if (!res->RemoveUKnot(i, DegreeU-2, epsgeom)) {
573 isC2 = Standard_False;
574 Standard_Boolean locOK = res->RemoveUKnot(i, DegreeU-1, epsgeom); // is C1 ?
575 isC1 &= locOK;
576 isModified |= locOK;
577 }
578 else
579 isModified = Standard_True;
580 }
581 else {
582 Standard_Boolean locOK = res->RemoveUKnot(i, DegreeU-1, epsgeom); // is C1 ?
583 isC1 &= locOK;
584 isModified |= locOK;
585 }
586 }
587 }
588 while (isModified);
589
590 Standard_Integer DegreeV = res->VDegree();
591 do {
592 isModified = Standard_False;
96a95605 593 for (Standard_Integer i = res->FirstVKnotIndex()+1; i < res->LastVKnotIndex(); i++)
7fd59977 594 if(DegreeV - res->VMultiplicity(i) < continuity) {
595 if (continuity >= 2) {
596 if (!res->RemoveVKnot(i, DegreeV-2, epsgeom)) {
597 isC2 = Standard_False;
598 Standard_Boolean locOK = res->RemoveVKnot(i, DegreeV-1, epsgeom); // is C1 ?
599 isC1 &= locOK;
600 isModified |= locOK;
601 }
602 else
603 isModified = Standard_True;
604 }
605 else {
606 Standard_Boolean locOK = res->RemoveVKnot(i, DegreeV-1, epsgeom); // is C1 ?
607 isC1 &= locOK;
608 isModified |= locOK;
609 }
610 }
611 }
612 while (isModified);
613
614 /*
615 while (--i > j) { // from 2 to NbKnots-1
616 if (continuity >= 2) {
617 if (!res->RemoveUKnot(i, DegreeU-2, epsgeom)) { // is C2 ?
618 isC2 = Standard_False;
619 isC1 &= res->RemoveUKnot(i, DegreeU-1, epsgeom); // is C1 ?
620 }
621 }
622 else {
623 isC1 &= res->RemoveUKnot(i, DegreeU-1, epsgeom); // is C1 ?
624 }
625 }
626
627 i = res->LastVKnotIndex(); //knots.Upper();
628 j = res->FirstVKnotIndex(); //knots.Lower();
629 Standard_Integer DegreeV = res->VDegree();
630 while (--i > j) { // from 2 to NbKnots-1
631 if (continuity >= 2) {
632 if (!res->RemoveVKnot(i, DegreeV-2, epsgeom)) { // is C2 ?
633 isC2 = Standard_False;
634 isC1 &= res->RemoveVKnot(i, DegreeV-1, epsgeom); // is C1 ?
635 }
636 }
637 else {
638 isC1 &= res->RemoveVKnot(i, DegreeV-1, epsgeom); // is C1 ?
639 }
640 }*/
641
642
643 if (!isC1) return 0;
644 if (continuity >= 2 && !isC2) return 1;
645 return continuity;
646}
647