summaryrefslogtreecommitdiff
path: root/src/StepToGeom/StepToGeom_MakeBSplineSurface.cxx
blob: 2e69738ccfe53953d5824ec60c89b9d91eb18fed (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
// File:	StepToGeom_MakeBSplineSurface.cxx
// Created:	Fri Jul  2 12:05:11 1993
// Author:	Martine LANGLOIS

#include <StepToGeom_MakeBSplineSurface.ixx>
#include <StepGeom_BSplineSurfaceWithKnots.hxx>
#include <StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColgp_Array2OfPnt.hxx>
#include <TColStd_HArray1OfInteger.hxx>
#include <TColStd_HArray1OfReal.hxx>
#include <TColStd_HArray2OfReal.hxx>
#include <StepGeom_HArray2OfCartesianPoint.hxx>
#include <StepGeom_CartesianPoint.hxx>
#include <StepToGeom_MakeCartesianPoint.hxx>
#include <Geom_CartesianPoint.hxx>
#include <gp_Pnt.hxx>

//=============================================================================
// Creation d' une BSplineSurface de Geom a partir d' une
// BSplineSurface de Step
//=============================================================================

Standard_Boolean StepToGeom_MakeBSplineSurface::Convert
    (const Handle(StepGeom_BSplineSurface)& SS,
     Handle(Geom_BSplineSurface)& CS)
{
  Standard_Integer                    i, j;
  Handle(StepGeom_BSplineSurfaceWithKnots) BS;
  Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface) BSR;

  if (SS->
      IsKind(STANDARD_TYPE(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface))) {
    BSR = 
      Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface)
	::DownCast(SS);
    BS = 
      Handle(StepGeom_BSplineSurfaceWithKnots)
	::DownCast(BSR->BSplineSurfaceWithKnots());
  }
  else
    BS = Handle(StepGeom_BSplineSurfaceWithKnots)::DownCast(SS);

  const Standard_Integer UDeg = BS->UDegree();
  const Standard_Integer VDeg = BS->VDegree();
  const Standard_Integer NUPoles = BS->NbControlPointsListI();
  const Standard_Integer NVPoles = BS->NbControlPointsListJ();
  const Handle(StepGeom_HArray2OfCartesianPoint)& aControlPointsList = BS->ControlPointsList();
  Handle(Geom_CartesianPoint) P;
  TColgp_Array2OfPnt Poles(1,NUPoles,1,NVPoles);
  for (i=1; i<=NUPoles; i++) {
    for (j=1; j<=NVPoles; j++) {
      if (StepToGeom_MakeCartesianPoint::Convert(aControlPointsList->Value(i,j),P))
        Poles.SetValue(i,j,P->Pnt());
	  else
        return Standard_False;
    }
  }
  const Standard_Integer NUKnots = BS->NbUMultiplicities();
  const Handle(TColStd_HArray1OfInteger)& aUMultiplicities = BS->UMultiplicities();
  TColStd_Array1OfInteger UMult(1,NUKnots);
  for (i=1; i<=NUKnots; i++) {
    UMult.SetValue(i,aUMultiplicities->Value(i));
  }
  const Standard_Integer NVKnots = BS->NbVMultiplicities();
  const Handle(TColStd_HArray1OfInteger)& aVMultiplicities = BS->VMultiplicities();
  TColStd_Array1OfInteger VMult(1,NVKnots);
  for (i=1; i<=NVKnots; i++) {
    VMult.SetValue(i,aVMultiplicities->Value(i));
  }
  const Handle(TColStd_HArray1OfReal)& aUKnots = BS->UKnots();
  TColStd_Array1OfReal KUn(1,NUKnots);
  for (i=1; i<=NUKnots; i++) {
    KUn.SetValue(i,aUKnots->Value(i));
  }
  const Handle(TColStd_HArray1OfReal)& aVKnots = BS->VKnots();
  TColStd_Array1OfReal KVn(1,NVKnots);
  for (i=1; i<=NVKnots; i++) {
    KVn.SetValue(i,aVKnots->Value(i));
  }
  
  // --- Does the Surface Descriptor LOOKS like a U and/or V Periodic ---
  // --- Descriptor ? ---
  
  // --- U Periodic ? ---
  
  Standard_Integer SumMult = 0;
  for (i=1; i<=NUKnots; i++) {
    SumMult += aUMultiplicities->Value(i);
  }
  
  Standard_Boolean shouldBeUPeriodic = Standard_False;
  if (SumMult == (NUPoles + UDeg + 1)) {
    //shouldBeUPeriodic = Standard_False;
  }
  else if ((aUMultiplicities->Value(1) == 
	    aUMultiplicities->Value(NUKnots)) &&
	   ((SumMult - aUMultiplicities->Value(1))== NUPoles)) {
    shouldBeUPeriodic = Standard_True;
  }
  /*else {  // --- What is that ??? ---
    shouldBeUPeriodic = Standard_False;
#ifdef DEBUG
    cout << "Strange BSpline Surface Descriptor" << endl;
#endif
  }*/
  
  // --- V Periodic ? ---
  
  SumMult = 0;
  for (i=1; i<=NVKnots; i++) {
    SumMult += aVMultiplicities->Value(i);
  }
  
  Standard_Boolean shouldBeVPeriodic = Standard_False;
  if (SumMult == (NVPoles + VDeg + 1)) {
    //shouldBeVPeriodic = Standard_False;
  }
  else if ((aVMultiplicities->Value(1) == 
	    aVMultiplicities->Value(NVKnots)) &&
	   ((SumMult - aVMultiplicities->Value(1)) == NVPoles)) {
    shouldBeVPeriodic = Standard_True;
  }
  /*else {  // --- What is that ??? ---
    shouldBeVPeriodic = Standard_False;
#ifdef DEBUG
    cout << "Strange BSpline Surface Descriptor" << endl;
#endif
  }*/
  
  if (SS->IsKind(STANDARD_TYPE(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface))) {
    const Handle(TColStd_HArray2OfReal)& aWeight = BSR->WeightsData();
    TColStd_Array2OfReal W(1,NUPoles,1,NVPoles);
    for (i=1; i<=NUPoles; i++) {
      for (j=1; j<=NVPoles; j++) {
        W.SetValue(i,j,aWeight->Value(i,j));
      }
    }
    CS = new Geom_BSplineSurface(Poles, W, KUn, KVn, UMult,
                                 VMult, UDeg, VDeg,
                                 shouldBeUPeriodic,
                                 shouldBeVPeriodic);
  }
  else
    CS = new Geom_BSplineSurface(Poles, KUn, KVn, UMult,
                                 VMult, UDeg, VDeg,
                                 shouldBeUPeriodic,
                                 shouldBeVPeriodic);
  return Standard_True;
}