summaryrefslogtreecommitdiff
path: root/inc/IntCurveSurface_Polygon.gxx
blob: fdc18303b202506b1ed342a8970775b97b50eb89 (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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// File:	IntCurveSurface_Polygon.gxx
// Created:	Mon Oct 12 17:17:30 1992
// Author:	Laurent BUCHARD
//		<lbr@sdsun2>



#include <Standard_ConstructionError.hxx>
#include <Bnd_Box.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <gp_Lin.hxx>
#include <gp_Vec.hxx>
#include <gp_Dir.hxx>


//======================================================================
//== On echantillonne sur le Domain de la Curve  NbPts Points 
//== a parametres constants.
//== 
//== On estime la fleche maximum en prenant la distance maxi entre la 
//== droite Curve.Value(X(i))-->Curve.Value(X(i+1)) 
//== et le point Curve.Value(X(i+1/2))
//======================================================================
IntCurveSurface_Polygon::IntCurveSurface_Polygon(const TheCurve&        C,
						 const Standard_Integer tNbPts):
       ThePnts(1,(tNbPts<5)? 5 : tNbPts) 
{ 
  Standard_Integer NbPts = (tNbPts<5)? 5 : tNbPts;
  NbPntIn = NbPts;
  Binf = TheCurveTool::FirstParameter(C);
  Bsup = TheCurveTool::LastParameter(C);
  Init(C); 
}



IntCurveSurface_Polygon::IntCurveSurface_Polygon(const TheCurve&        C,
						 const Standard_Real    U1,
						 const Standard_Real    U2,
						 const Standard_Integer tNbPts):
       ThePnts(1,(tNbPts<5)? 5 : tNbPts) , Binf(U1) , Bsup(U2)
{ 
  
  
  Standard_Integer NbPts = (tNbPts<5)? 5 : tNbPts;
  NbPntIn = NbPts;
  Init(C);
}

//=======================================================================
//function : IntCurveSurface_Polygon
//purpose  : 
//=======================================================================

IntCurveSurface_Polygon::IntCurveSurface_Polygon(const TheCurve&        C,
						 const TColStd_Array1OfReal& Upars):
       ThePnts(1,Upars.Length()) , Binf(Upars(Upars.Lower())) , Bsup(Upars(Upars.Upper()))
{ 
  
  //ddout << "IntCurveSurface_Polygon::IntCurveSurface_Polygon" << endl;
  Standard_Integer NbPts = Upars.Length();
  //ddout << "NbPts :" << NbPts << endl;
  NbPntIn = NbPts;
  Init(C, Upars);
}


void IntCurveSurface_Polygon::Init(const TheCurve&        C) { 
  
  Standard_Real u=Binf; 
  Standard_Real u1=Bsup;
  Standard_Real du=(u1-u)/(Standard_Real)(NbPntIn-1);
  Standard_Integer i=1;
  gp_Pnt P;
  do {
    TheCurveTool::D0(C,u,P);
    TheBnd.Add(P);
    ThePnts.SetValue(i,P);             
    u+=du;
    i++;
  }
  while(i<=NbPntIn);


  //-----------------------------------------------------
  //--- Calcul d un majorant de fleche approche
  //---
  TheDeflection = 0.0;

  if(NbPntIn>3) { 
    
    i=1;
    u=Binf;
    u+=du * 0.5;
    
    do {
      gp_Pnt Pm=TheCurveTool::Value(C,u);
      gp_Pnt P1=ThePnts.Value(i);
      gp_Pnt P2=ThePnts.Value(i+1);
      gp_Lin L(P1,gp_Dir(gp_Vec(P1,P2)));
      Standard_Real t=L.Distance(Pm);
      
      if(t>TheDeflection) {
	TheDeflection = t;
      }
      u+=du;
      i++;
    }
    while(i<NbPntIn);
    
    TheBnd.Enlarge(1.5*TheDeflection);
  }
  else { 
    TheBnd.Enlarge(1e-10);
  }
  ClosedPolygon = Standard_False;
}

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

void IntCurveSurface_Polygon::Init(const TheCurve&        C,
				   const TColStd_Array1OfReal& Upars) { 

  //ddout << "IntCurveSurface_Polygon::Init" << endl;
  Standard_Real u=Binf; 
  Standard_Integer i=1, i0 = Upars.Lower()-1;
  gp_Pnt P;

  myParams = new TColStd_HArray1OfReal(1, Upars.Length());
  do {
    //ddout << "-------------Parameter : " << i << " " << Upars(i+i0) << endl;
    myParams->SetValue(i, Upars(i+i0));
    TheCurveTool::D0(C,Upars(i+i0),P);
    //ddout << "P : " << P.X() << " " << P.Y() << " " << P.Z() << endl;
    TheBnd.Add(P);
    ThePnts.SetValue(i,P);             
    i++;
  }
  while(i<=NbPntIn);


  //-----------------------------------------------------
  //--- Calcul d un majorant de fleche approche
  //---
  TheDeflection = 0.0;

  if(NbPntIn>3) { 
    
    i=1;
    //ddout << "Deflection estimation" << endl;
    do {
      u = 0.5*(Upars(i0+i)+Upars(i0+i+1));
      //ddout << "===========Parameter : " << i << " " << u << endl;
      gp_Pnt Pm=TheCurveTool::Value(C,u);
      //ddout << "Pm : " << Pm.X() << " " << Pm.Y() << " " << Pm.Z() << endl;
      gp_Pnt P1=ThePnts.Value(i);
      //ddout << "P1 : " << P1.X() << " " << P1.Y() << " " << P1.Z() << endl;
      gp_Pnt P2=ThePnts.Value(i+1);
      //ddout << "P2 : " << P2.X() << " " << P2.Y() << " " << P2.Z() << endl;
      gp_Lin L(P1,gp_Dir(gp_Vec(P1,P2)));
      Standard_Real t=L.Distance(Pm);
      //ddout << "Distance " << t << endl;
      if(t>TheDeflection) {
	TheDeflection = t;
      }
      i++;
    }
    while(i<NbPntIn);
    //ddout << " TheDeflection = " << TheDeflection << endl;
    TheBnd.Enlarge(1.5*TheDeflection);
  }
  else { 
    TheBnd.Enlarge(1e-10);
  }
  ClosedPolygon = Standard_False;
}


//======================================================================
Standard_Real IntCurveSurface_Polygon::ApproxParamOnCurve(const Standard_Integer TheIndex,
							  const Standard_Real    TheParamOnLine) const
{
  //ddout << "IntCurveSurface_Polygon::ApproxParamOnCurve" << endl;
  if(TheParamOnLine < 0.0 || TheParamOnLine >1.0) { 
    cout<<" ParamOnLine  =  "<<TheParamOnLine<<"  avec Index = "
      <<TheIndex<<"  dans IntCurveSurface_Polygon::ApproxParamOnCurve"<<endl;
    return(Binf+(TheParamOnLine*(Bsup-Binf))/(Standard_Real)(NbPntIn-1));
  }

  Standard_Integer Index = TheIndex;
  Standard_Real    ParamOnLine = TheParamOnLine;
  if (Index > NbPntIn) {
    cout << "OutOfRange Polygon::ApproxParamOnCurve " <<endl;
  }
  if((Index == NbPntIn) && (ParamOnLine == 0.0)) { 
    Index--; ParamOnLine=1.0;
  }

  Standard_Real du, u;
  if (myParams.IsNull())
    {
      du = (Bsup-Binf)/(Standard_Real)(NbPntIn-1);
      u  = Binf + du * (Standard_Real)(Index-1);
    }
  else
    {
      du = myParams->Value(Index+1) - myParams->Value(Index);
      u  = myParams->Value(Index);
    }

  u += du * ParamOnLine;
  return (u);
}
 

//======================================================================
void IntCurveSurface_Polygon::Dump(void) const {
#if 0  
  static Standard_Integer Compteur=0;
  char tamp[100];
  Compteur++;
  sprintf(tamp,"Poly%d",Compteur);
  cout<<"  @@@@@@@@@@@ F i c h i e r   :   "<<tamp<<" @@@@@@@@@@"<<endl;
  FILE *fp;
  fp=fopen(tamp,"w");
  if(fp==NULL) {
    cout<<"PolyGonGen::Erreur en Ouverture Fichier"<<tamp<<endl;
    return;
  }
  fprintf(fp,"\n#Discretisation de : %f ---> %f \n",Binf,Bsup);
  fprintf(fp,"\npol %d %d %f",Compteur,NbPntIn,TheDeflection);
  gp_Pnt p1,p2;
  for (Standard_Integer iObje=1; iObje<=NbSegments(); iObje++) {
    p1=BeginOfSeg(iObje);
    fprintf(fp,"\npnt %d %f %f",Compteur,p1.X(),p1.Y());
  }
  p1=EndOfSeg(NbSegments());
  fprintf(fp,"\npnt %d %f %f",Compteur,p1.X(),p1.Y());
  fprintf(fp,"\ndispol %d\n#\n",Compteur);
  fclose(fp);
#endif
}
//======================================================================
//======================================================================