1 // Created on: 1993-07-02
2 // Created by: Martine LANGLOIS
3 // Copyright (c) 1993-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.
17 #include <StepToGeom_MakeBSplineSurface.ixx>
18 #include <StepGeom_BSplineSurfaceWithKnots.hxx>
19 #include <StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface.hxx>
20 #include <TColStd_Array1OfInteger.hxx>
21 #include <TColStd_Array1OfReal.hxx>
22 #include <TColgp_Array2OfPnt.hxx>
23 #include <TColStd_HArray1OfInteger.hxx>
24 #include <TColStd_HArray1OfReal.hxx>
25 #include <TColStd_HArray2OfReal.hxx>
26 #include <StepGeom_HArray2OfCartesianPoint.hxx>
27 #include <StepGeom_CartesianPoint.hxx>
28 #include <StepToGeom_MakeCartesianPoint.hxx>
29 #include <Geom_CartesianPoint.hxx>
32 //=============================================================================
33 // Creation d' une BSplineSurface de Geom a partir d' une
34 // BSplineSurface de Step
35 //=============================================================================
37 Standard_Boolean StepToGeom_MakeBSplineSurface::Convert
38 (const Handle(StepGeom_BSplineSurface)& SS,
39 Handle(Geom_BSplineSurface)& CS)
41 Standard_Integer i, j;
42 Handle(StepGeom_BSplineSurfaceWithKnots) BS;
43 Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface) BSR;
46 IsKind(STANDARD_TYPE(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface))) {
48 Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface)
51 Handle(StepGeom_BSplineSurfaceWithKnots)
52 ::DownCast(BSR->BSplineSurfaceWithKnots());
55 BS = Handle(StepGeom_BSplineSurfaceWithKnots)::DownCast(SS);
57 const Standard_Integer UDeg = BS->UDegree();
58 const Standard_Integer VDeg = BS->VDegree();
59 const Standard_Integer NUPoles = BS->NbControlPointsListI();
60 const Standard_Integer NVPoles = BS->NbControlPointsListJ();
61 const Handle(StepGeom_HArray2OfCartesianPoint)& aControlPointsList = BS->ControlPointsList();
62 Handle(Geom_CartesianPoint) P;
63 TColgp_Array2OfPnt Poles(1,NUPoles,1,NVPoles);
64 for (i=1; i<=NUPoles; i++) {
65 for (j=1; j<=NVPoles; j++) {
66 if (StepToGeom_MakeCartesianPoint::Convert(aControlPointsList->Value(i,j),P))
67 Poles.SetValue(i,j,P->Pnt());
69 return Standard_False;
72 const Standard_Integer NUKnots = BS->NbUMultiplicities();
73 const Handle(TColStd_HArray1OfInteger)& aUMultiplicities = BS->UMultiplicities();
74 TColStd_Array1OfInteger UMult(1,NUKnots);
75 for (i=1; i<=NUKnots; i++) {
76 UMult.SetValue(i,aUMultiplicities->Value(i));
78 const Standard_Integer NVKnots = BS->NbVMultiplicities();
79 const Handle(TColStd_HArray1OfInteger)& aVMultiplicities = BS->VMultiplicities();
80 TColStd_Array1OfInteger VMult(1,NVKnots);
81 for (i=1; i<=NVKnots; i++) {
82 VMult.SetValue(i,aVMultiplicities->Value(i));
84 const Handle(TColStd_HArray1OfReal)& aUKnots = BS->UKnots();
85 TColStd_Array1OfReal KUn(1,NUKnots);
86 for (i=1; i<=NUKnots; i++) {
87 KUn.SetValue(i,aUKnots->Value(i));
89 const Handle(TColStd_HArray1OfReal)& aVKnots = BS->VKnots();
90 TColStd_Array1OfReal KVn(1,NVKnots);
91 for (i=1; i<=NVKnots; i++) {
92 KVn.SetValue(i,aVKnots->Value(i));
95 // --- Does the Surface Descriptor LOOKS like a U and/or V Periodic ---
96 // --- Descriptor ? ---
98 // --- U Periodic ? ---
100 Standard_Integer SumMult = 0;
101 for (i=1; i<=NUKnots; i++) {
102 SumMult += aUMultiplicities->Value(i);
105 Standard_Boolean shouldBeUPeriodic = Standard_False;
106 if (SumMult == (NUPoles + UDeg + 1)) {
107 //shouldBeUPeriodic = Standard_False;
109 else if ((aUMultiplicities->Value(1) ==
110 aUMultiplicities->Value(NUKnots)) &&
111 ((SumMult - aUMultiplicities->Value(1))== NUPoles)) {
112 shouldBeUPeriodic = Standard_True;
114 /*else { // --- What is that ??? ---
115 shouldBeUPeriodic = Standard_False;
117 cout << "Strange BSpline Surface Descriptor" << endl;
121 // --- V Periodic ? ---
124 for (i=1; i<=NVKnots; i++) {
125 SumMult += aVMultiplicities->Value(i);
128 Standard_Boolean shouldBeVPeriodic = Standard_False;
129 if (SumMult == (NVPoles + VDeg + 1)) {
130 //shouldBeVPeriodic = Standard_False;
132 else if ((aVMultiplicities->Value(1) ==
133 aVMultiplicities->Value(NVKnots)) &&
134 ((SumMult - aVMultiplicities->Value(1)) == NVPoles)) {
135 shouldBeVPeriodic = Standard_True;
137 /*else { // --- What is that ??? ---
138 shouldBeVPeriodic = Standard_False;
140 cout << "Strange BSpline Surface Descriptor" << endl;
144 if (SS->IsKind(STANDARD_TYPE(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface))) {
145 const Handle(TColStd_HArray2OfReal)& aWeight = BSR->WeightsData();
146 TColStd_Array2OfReal W(1,NUPoles,1,NVPoles);
147 for (i=1; i<=NUPoles; i++) {
148 for (j=1; j<=NVPoles; j++) {
149 W.SetValue(i,j,aWeight->Value(i,j));
152 CS = new Geom_BSplineSurface(Poles, W, KUn, KVn, UMult,
158 CS = new Geom_BSplineSurface(Poles, KUn, KVn, UMult,
162 return Standard_True;