summaryrefslogtreecommitdiff
path: root/src/GeomFill/GeomFill_Stretch.cxx
blob: f8cb4d40298471580e812eda6a8ecaa59dbb9b0b (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
// File:	GeomFill_Stretch.cxx
// Created:	Tue Sep 28 17:58:37 1993
// Author:	Bruno DUMORTIER
//		<dub@sdsun1>

#include <GeomFill_Stretch.ixx>

#include <gp_Pnt.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColgp_HArray2OfPnt.hxx>
#include <TColStd_HArray2OfReal.hxx>


//=======================================================================
//function : GeomFill_Stretch
//purpose  : 
//=======================================================================

GeomFill_Stretch::GeomFill_Stretch()
{
}


//=======================================================================
//function : GeomFill_Stretch
//purpose  : 
//=======================================================================

GeomFill_Stretch::GeomFill_Stretch(const TColgp_Array1OfPnt& P1, 
			     const TColgp_Array1OfPnt& P2, 
			     const TColgp_Array1OfPnt& P3, 
			     const TColgp_Array1OfPnt& P4)
{
  Init(P1, P2, P3, P4);
}


//=======================================================================
//function : GeomFill_Stretch
//purpose  : 
//=======================================================================

GeomFill_Stretch::GeomFill_Stretch(const TColgp_Array1OfPnt&   P1, 
			     const TColgp_Array1OfPnt&   P2, 
			     const TColgp_Array1OfPnt&   P3, 
			     const TColgp_Array1OfPnt&   P4,
			     const TColStd_Array1OfReal& W1,
			     const TColStd_Array1OfReal& W2,
			     const TColStd_Array1OfReal& W3,
			     const TColStd_Array1OfReal& W4)
{
  Init(P1, P2, P3, P4, W1, W2, W3, W4);
}


//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

void  GeomFill_Stretch::Init(const TColgp_Array1OfPnt& P1, 
			  const TColgp_Array1OfPnt& P2, 
			  const TColgp_Array1OfPnt& P3, 
			  const TColgp_Array1OfPnt& P4)
{
  Standard_DomainError_Raise_if
    ( P1.Length() != P3.Length() || P2.Length() != P4.Length()," ");

  Standard_Integer NPolU = P1.Length();
  Standard_Integer NPolV = P2.Length();

  IsRational = Standard_False;

  Standard_Real NU = NPolU - 1;
  Standard_Real NV = NPolV - 1;
  myPoles = new TColgp_HArray2OfPnt( 1, NPolU, 1, NPolV);
  
  // The boundaries are not modified
  Standard_Integer i,j,k;
  for ( i=1; i<=NPolU; i++) {
    myPoles->SetValue( i, 1    , P1(i));
    myPoles->SetValue( i, NPolV, P3(i));
  }
  Standard_Real PU,PU1,PV,PV1;
  
  for ( j=2; j<=NPolV-1; j++) {
    PV  = (j-1)/NV;
    PV1 = 1 - PV;
    myPoles->SetValue( 1    , j, P4(j));
    myPoles->SetValue( NPolU, j, P2(j));

    for ( i=2; i<=NPolU-1; i++) {
      PU  = (i-1)/NU;
      PU1 = 1 - PU;
      
      gp_Pnt P;
      for (k=1; k<=3; k++) {
	P.SetCoord(k, 
		   PV1 * P1(i).Coord(k) + PV  * P3(i).Coord(k) +
		   PU  * P2(j).Coord(k) + PU1 * P4(j).Coord(k) -
		   ( PU1 * PV1 * P1(1).Coord(k)     +
		     PU  * PV1 * P2(1).Coord(k)     +
		     PU  * PV  * P3(NPolU).Coord(k) +
		     PU1 * PV  * P4(NPolV).Coord(k)   )          );
      }
      myPoles->SetValue(i,j,P);
    }
  }
}


//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

void  GeomFill_Stretch::Init(const TColgp_Array1OfPnt&   P1, 
			  const TColgp_Array1OfPnt&   P2, 
			  const TColgp_Array1OfPnt&   P3, 
			  const TColgp_Array1OfPnt&   P4,
			  const TColStd_Array1OfReal& W1,
			  const TColStd_Array1OfReal& W2,
			  const TColStd_Array1OfReal& W3,
			  const TColStd_Array1OfReal& W4)
{
  Standard_DomainError_Raise_if
    ( W1.Length() != W3.Length() || W2.Length() != W4.Length()," ");
  Standard_DomainError_Raise_if
    ( W1.Length() != P1.Length() || 
      W2.Length() != P2.Length() || 
      W3.Length() != P3.Length() || 
      W4.Length() != P4.Length()   , " ");

  Init(P1,P2,P3,P4);
  IsRational = Standard_True;

  Standard_Integer NPolU = W1.Length();
  Standard_Integer NPolV = W2.Length();

  Standard_Real NU = NPolU - 1;
  Standard_Real NV = NPolV - 1;
  myWeights = new TColStd_HArray2OfReal( 1, NPolU, 1, NPolV);
  
  // The boundaries are not modified
  Standard_Integer i,j;
  for ( i=1; i<=NPolU; i++) {
    myWeights->SetValue( i, 1    , W1(i));
    myWeights->SetValue( i, NPolV, W3(i));
  }
  Standard_Real PU,PU1,PV,PV1;
  
  for ( j=2; j<=NPolV-1; j++) {
    PV  = (j-1)/NV;
    PV1 = 1 - PV;
    myWeights->SetValue( 1    , j, W4(j));
    myWeights->SetValue( NPolU, j, W2(j));

    for ( i=2; i<=NPolU-1; i++) {
      PU  = (i-1)/NU;
      PU1 = 1 - PU;

      Standard_Real W = 0.5 * ( PV1 * W1(i) + PV  * W3(i) +
			        PU  * W2(j) + PU1 * W4(j)  );

//      Standard_Real W = PV1 * W1(i) + PV  * W3(i) +
//	                PU  * W2(j) + PU1 * W4(j) -
//	              ( PU1 * PV1 * W1(1)     +
//	                PU  * PV1 * W2(1)     +
//	                PU  * PV  * W3(NPolU) +
//	                PU1 * PV  * W4(NPolV)   );
      myWeights->SetValue(i,j,W);
    }
  }
}