summaryrefslogtreecommitdiff
path: root/src/IntPatch/IntPatch_HInterTool.cxx
blob: d48e7fb32d78dfbd4a3ca42520b98d55a4d6ad93 (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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
// File      : IntPatch_HInterTool.cxx
// Created   : Fri Jul  2 13:19:22 1995
// Author    : Laurent BUCHARD
// Copyright : OPEN CASCADE 1995

#include <IntPatch_HInterTool.ixx>

#include <Extrema_EPCOfExtPC2d.hxx>
#include <Extrema_POnCurv2d.hxx>

#include <GeomAbs_SurfaceType.hxx>
#include <Standard_OutOfRange.hxx>

#include <Handle_Geom_BezierSurface.hxx>
#include <Handle_Geom_BSplineSurface.hxx>
#include <Handle_Geom2d_BezierCurve.hxx>
#include <Handle_Geom2d_BSplineCurve.hxx>

#include <Geom_BezierSurface.hxx>
#include <Geom_BSplineSurface.hxx>
#include <Geom2d_BezierCurve.hxx>
#include <Geom2d_BSplineCurve.hxx>

static Standard_Real uinf,vinf,usup,vsup;


Standard_Integer IntPatch_HInterTool::NbSamplesV (const Handle(Adaptor3d_HSurface)& S,
                                                  const Standard_Real, const Standard_Real)
{
  switch (S->GetType())
  {
    case GeomAbs_Plane: return 2;
    case GeomAbs_BezierSurface: return (3 + S->NbVPoles());
    case GeomAbs_BSplineSurface: 
    {
      Standard_Integer nbs = S->NbVKnots();
      nbs *= S->VDegree();
      if (!S->IsVRational()) nbs *= 2;
      if (nbs < 4) nbs = 4;
	  return nbs;
    }
    break;
    case GeomAbs_Cylinder:
    case GeomAbs_Cone:
    case GeomAbs_Sphere:
    case GeomAbs_Torus:
    case GeomAbs_SurfaceOfRevolution:
    case GeomAbs_SurfaceOfExtrusion: return 15;
    default: /* do nothing */ break;
  }
  return 10;
}

Standard_Integer IntPatch_HInterTool::NbSamplesU (const Handle(Adaptor3d_HSurface)& S,
                                                  const Standard_Real, const Standard_Real)
{
  switch (S->GetType())
  {
    case GeomAbs_Plane: return 2;
    case GeomAbs_BezierSurface: return (3 + S->NbUPoles());
    case GeomAbs_BSplineSurface:
    {
      Standard_Integer nbs = S->NbUKnots();
      nbs *= S->UDegree();
      if (!S->IsURational()) nbs *= 2;
      if (nbs < 4) nbs = 4;
      return nbs;
	}
    case GeomAbs_Torus: return 20;
    //case GeomAbs_Cylinder:
    //case GeomAbs_Cone:
    //case GeomAbs_Sphere:
    //case GeomAbs_SurfaceOfRevolution:
    //case GeomAbs_SurfaceOfExtrusion: return 10;
    default: /* Do nothing */ break;
  }
  return 10;
}

Standard_Integer IntPatch_HInterTool::NbSamplePoints (const Handle(Adaptor3d_HSurface)& S)
{
  uinf = S->FirstUParameter();
  usup = S->LastUParameter();
  vinf = S->FirstVParameter();
  vsup = S->LastVParameter();

  if (usup < uinf) {
    Standard_Real temp = uinf;
    uinf = usup;
    usup = temp;
    }
    if (vsup < vinf) {
    Standard_Real temp = vinf;
    vinf = vsup;
    vsup = temp;
  }
  if (uinf == RealFirst() && usup == RealLast()) {
    uinf = -1.e5;
    usup =  1.e5;
  }
  else if (uinf == RealFirst()) {
    uinf = usup - 2.e5;
  }
  else if (usup == RealLast()) {
    usup = uinf + 2.e5;
  }
  
  if (vinf == RealFirst() && vsup == RealLast()) {
    vinf = -1.e5;
    vsup =  1.e5;
  }
  else if (vinf == RealFirst()) {
    vinf = vsup - 2.e5;
  }
  else if (vsup == RealLast()) {
    vsup = vinf + 2.e5;
  }
  const Standard_Integer m = (1+NbSamplesU(S,uinf,usup)/2) * (1+NbSamplesV(S,vinf,vsup)/2);
  return(m);
}

void IntPatch_HInterTool::SamplePoint (const Handle(Adaptor3d_HSurface)& S,
                                       const Standard_Integer Index,
                                       Standard_Real& U,
                                       Standard_Real& V )
{
  Standard_Integer nbIntU = 1+NbSamplesU(S,uinf,usup);
  nbIntU>>=1;
  Standard_Integer nbIntV = 1+NbSamplesV(S,vinf,vsup);     
  nbIntV>>=1;
  
  if(nbIntU * nbIntV >5) {
    
    Standard_Integer NV = (Index-1) / nbIntU;
    Standard_Integer NU = (Index-1) - NV * nbIntU;
    Standard_Real du = ((usup-uinf)/((Standard_Real)(nbIntU+1)));
    Standard_Real dv = ((vsup-vinf)/((Standard_Real)(nbIntV+1)));
    
    Standard_Integer perturb=(NU+NV) & 3;

    //-- petite perturbation pou eviter les pbs de symetrie avec Les recherches de points int. 

    switch(perturb) { 
    case 1: dv*=1.001;  dv*=0.999; break;
    case 2: du*=1.001;  dv*=1.001; break;
    case 3: du*=0.999;             break;
    default: break;
    }
    
    U = uinf + du*(Standard_Real)(NU+1);
    V = vinf + dv*(Standard_Real)(NV+1);
    return;
  }
  
  
  switch (Index) {
  case 1:
    U = 0.76*uinf + 0.24*usup;
    V = 0.74*vinf + 0.26*vsup;
    break;
  case 2:
    U = 0.73*uinf + 0.27*usup;
    V = 0.24*vinf + 0.76*vsup;
    break;
  case 3:
    U = 0.25*uinf + 0.75*usup;
    V = 0.76*vinf + 0.24*vsup;
    break;
  case 4:
    U = 0.26*uinf + 0.74*usup;
    V = 0.25*vinf + 0.75*vsup;
    break;
  default:
    U = 0.51*uinf+0.49*usup; 
    V = 0.49*vinf+0.51*vsup;
  }
}


Standard_Integer IntPatch_HInterTool::NbSamplesOnArc (const Handle(Adaptor2d_HCurve2d)& A)
{
  GeomAbs_CurveType CurveType  = A->GetType();

//  Standard_Real nbsOnC = 5;
  Standard_Integer nbsOnC = 5;
  switch(CurveType) { 
  case GeomAbs_Line:
    nbsOnC = 2;
    break;
  case GeomAbs_Circle:
  case GeomAbs_Ellipse:
  case GeomAbs_Hyperbola:
  case GeomAbs_Parabola:
    nbsOnC = 10;
    break;
  case GeomAbs_BezierCurve:
    nbsOnC = A->NbPoles();
    break;
  case GeomAbs_BSplineCurve: { 
    //-- Handle_Geom2d_BSplineCurve& BSC=A->BSpline();
    nbsOnC = 2 + A->NbKnots() * A->Degree();
    break;
  }
  default:
    nbsOnC = 10;
  } 
  return(nbsOnC);
}

void IntPatch_HInterTool::Bounds(const Handle(Adaptor2d_HCurve2d)& A,
                                 Standard_Real& Ufirst,
                                 Standard_Real& Ulast)
{
  Ufirst = A->FirstParameter();
  Ulast  = A->LastParameter();
}

Standard_Boolean IntPatch_HInterTool::Project (const Handle(Adaptor2d_HCurve2d)& C,
                                               const gp_Pnt2d& P,
                                               Standard_Real& Paramproj,
                                               gp_Pnt2d& Ptproj)
{
  Standard_Real epsX = 1.e-8;
  Standard_Integer Nbu = 20;
  Standard_Real Tol = 1.e-5;
  Standard_Real Dist2;

  Extrema_EPCOfExtPC2d extrema(P,C->Curve2d(),Nbu,epsX,Tol);
  if (!extrema.IsDone()) {
    return Standard_False;
  }
  Standard_Integer Nbext = extrema.NbExt();
  if (Nbext == 0) {
    return Standard_False;
  }
  Standard_Integer indexmin = 1;
  Dist2 = extrema.SquareDistance(1);
  for (Standard_Integer i=2; i<=Nbext; i++) {
    if (extrema.SquareDistance(i) < Dist2) {
      indexmin = i;
      Dist2 = extrema.SquareDistance(i);
    }
  }
  Paramproj = extrema.Point(indexmin).Parameter();
  Ptproj = extrema.Point(indexmin).Value();
  return Standard_True;
}

Standard_Real IntPatch_HInterTool::Tolerance (const Handle(Adaptor3d_HVertex)& V,
                                              const Handle(Adaptor2d_HCurve2d)& C)
{
  return V->Resolution(C);
}

Standard_Real IntPatch_HInterTool::Parameter (const Handle(Adaptor3d_HVertex)& V,
                                              const Handle(Adaptor2d_HCurve2d)& C)
{
  return V->Parameter(C);
}

Standard_Boolean IntPatch_HInterTool::HasBeenSeen(const Handle(Adaptor2d_HCurve2d)&)
{
  return Standard_False;
}

Standard_Integer IntPatch_HInterTool::NbPoints(const Handle(Adaptor2d_HCurve2d)&)
{
  return 0;
}

void IntPatch_HInterTool::Value(const Handle(Adaptor2d_HCurve2d)&,
                                const Standard_Integer,
                                gp_Pnt&,
                                Standard_Real&,
                                Standard_Real&)
{
  Standard_OutOfRange::Raise();
}

Standard_Boolean IntPatch_HInterTool::IsVertex(const Handle(Adaptor2d_HCurve2d)&,
                                               const Standard_Integer)
{
  return Standard_False;
}

void IntPatch_HInterTool::Vertex(const Handle(Adaptor2d_HCurve2d)&,
                                 const Standard_Integer,
                                 Handle(Adaptor3d_HVertex)&)
{
  Standard_OutOfRange::Raise();
}

Standard_Integer IntPatch_HInterTool::NbSegments(const Handle(Adaptor2d_HCurve2d)&)
{
  return 0;
}

Standard_Boolean IntPatch_HInterTool::HasFirstPoint (const Handle(Adaptor2d_HCurve2d)&,
                                                     const Standard_Integer,
                                                     Standard_Integer&)
{
  Standard_OutOfRange::Raise();
  return Standard_False;
}

Standard_Boolean IntPatch_HInterTool::HasLastPoint (const Handle(Adaptor2d_HCurve2d)&,
                                                    const Standard_Integer,
                                                    Standard_Integer&)
{
  Standard_OutOfRange::Raise();
  return Standard_False;
}

Standard_Boolean IntPatch_HInterTool::IsAllSolution (const Handle(Adaptor2d_HCurve2d)&)
{
  return Standard_False;
}