1 // Created on: 1995-07-02
2 // Created by: Laurent BUCHARD
3 // Copyright (c) 1995-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.
18 #include <Adaptor2d_HCurve2d.hxx>
19 #include <Adaptor3d_HSurface.hxx>
20 #include <Adaptor3d_HVertex.hxx>
21 #include <Extrema_EPCOfExtPC2d.hxx>
22 #include <Extrema_POnCurv2d.hxx>
23 #include <Geom2d_BezierCurve.hxx>
24 #include <Geom2d_BSplineCurve.hxx>
25 #include <Geom_BezierSurface.hxx>
26 #include <Geom_BSplineSurface.hxx>
27 #include <GeomAbs_SurfaceType.hxx>
29 #include <gp_Pnt2d.hxx>
30 #include <IntPatch_HInterTool.hxx>
31 #include <Standard_OutOfRange.hxx>
33 IntPatch_HInterTool::IntPatch_HInterTool() :
34 uinf (0.), vinf (0.), usup (0.), vsup (0.)
38 Standard_Integer IntPatch_HInterTool::NbSamplesV (const Handle(Adaptor3d_HSurface)& S,
39 const Standard_Real, const Standard_Real)
43 case GeomAbs_Plane: return 2;
44 case GeomAbs_BezierSurface: return (3 + S->NbVPoles());
45 case GeomAbs_BSplineSurface:
47 Standard_Integer nbs = S->NbVKnots();
49 if (!S->IsVRational()) nbs *= 2;
54 case GeomAbs_Cylinder:
58 case GeomAbs_SurfaceOfRevolution:
59 case GeomAbs_SurfaceOfExtrusion: return 15;
61 case GeomAbs_OffsetSurface:
62 case GeomAbs_OtherSurface: return 10;
67 Standard_Integer IntPatch_HInterTool::NbSamplesU (const Handle(Adaptor3d_HSurface)& S,
68 const Standard_Real, const Standard_Real)
72 case GeomAbs_Plane: return 2;
73 case GeomAbs_BezierSurface: return (3 + S->NbUPoles());
74 case GeomAbs_BSplineSurface:
76 Standard_Integer nbs = S->NbUKnots();
78 if (!S->IsURational()) nbs *= 2;
82 case GeomAbs_Torus: return 20;
84 case GeomAbs_Cylinder:
87 case GeomAbs_SurfaceOfRevolution:
88 case GeomAbs_SurfaceOfExtrusion:
89 case GeomAbs_OffsetSurface:
90 case GeomAbs_OtherSurface: return 10;
95 Standard_Integer IntPatch_HInterTool::NbSamplePoints (const Handle(Adaptor3d_HSurface)& S)
97 uinf = S->FirstUParameter();
98 usup = S->LastUParameter();
99 vinf = S->FirstVParameter();
100 vsup = S->LastVParameter();
103 Standard_Real temp = uinf;
108 Standard_Real temp = vinf;
112 if (uinf == RealFirst() && usup == RealLast()) {
116 else if (uinf == RealFirst()) {
119 else if (usup == RealLast()) {
123 if (vinf == RealFirst() && vsup == RealLast()) {
127 else if (vinf == RealFirst()) {
130 else if (vsup == RealLast()) {
133 const Standard_Integer m = (1+NbSamplesU(S,uinf,usup)/2) * (1+NbSamplesV(S,vinf,vsup)/2);
137 void IntPatch_HInterTool::SamplePoint (const Handle(Adaptor3d_HSurface)& S,
138 const Standard_Integer Index,
140 Standard_Real& V ) const
142 Standard_Integer nbIntU = 1+NbSamplesU(S,uinf,usup);
144 Standard_Integer nbIntV = 1+NbSamplesV(S,vinf,vsup);
147 if(nbIntU * nbIntV >5) {
149 Standard_Integer NV = (Index-1) / nbIntU;
150 Standard_Integer NU = (Index-1) - NV * nbIntU;
151 Standard_Real du = ((usup-uinf)/((Standard_Real)(nbIntU+1)));
152 Standard_Real dv = ((vsup-vinf)/((Standard_Real)(nbIntV+1)));
154 Standard_Integer perturb=(NU+NV) & 3;
156 //-- petite perturbation pou eviter les pbs de symetrie avec Les recherches de points int.
159 case 1: dv*=1.001; dv*=0.999; break;
160 case 2: du*=1.001; dv*=1.001; break;
161 case 3: du*=0.999; break;
165 U = uinf + du*(Standard_Real)(NU+1);
166 V = vinf + dv*(Standard_Real)(NV+1);
173 U = 0.76*uinf + 0.24*usup;
174 V = 0.74*vinf + 0.26*vsup;
177 U = 0.73*uinf + 0.27*usup;
178 V = 0.24*vinf + 0.76*vsup;
181 U = 0.25*uinf + 0.75*usup;
182 V = 0.76*vinf + 0.24*vsup;
185 U = 0.26*uinf + 0.74*usup;
186 V = 0.25*vinf + 0.75*vsup;
189 U = 0.51*uinf+0.49*usup;
190 V = 0.49*vinf+0.51*vsup;
195 Standard_Integer IntPatch_HInterTool::NbSamplesOnArc (const Handle(Adaptor2d_HCurve2d)& A)
197 GeomAbs_CurveType CurveType = A->GetType();
199 // Standard_Real nbsOnC = 5;
200 Standard_Integer nbsOnC = 5;
206 case GeomAbs_Ellipse:
207 case GeomAbs_Hyperbola:
208 case GeomAbs_Parabola:
211 case GeomAbs_BezierCurve:
212 nbsOnC = A->NbPoles();
214 case GeomAbs_BSplineCurve: {
215 //-- Handle(Geom2d_BSplineCurve)& BSC=A->BSpline();
216 nbsOnC = 2 + A->NbKnots() * A->Degree();
225 void IntPatch_HInterTool::Bounds(const Handle(Adaptor2d_HCurve2d)& A,
226 Standard_Real& Ufirst,
227 Standard_Real& Ulast)
229 Ufirst = A->FirstParameter();
230 Ulast = A->LastParameter();
233 Standard_Boolean IntPatch_HInterTool::Project (const Handle(Adaptor2d_HCurve2d)& C,
235 Standard_Real& Paramproj,
238 Standard_Real epsX = 1.e-8;
239 Standard_Integer Nbu = 20;
240 Standard_Real Tol = 1.e-5;
243 Extrema_EPCOfExtPC2d extrema(P,C->Curve2d(),Nbu,epsX,Tol);
244 if (!extrema.IsDone()) {
245 return Standard_False;
247 Standard_Integer Nbext = extrema.NbExt();
249 return Standard_False;
251 Standard_Integer indexmin = 1;
252 Dist2 = extrema.SquareDistance(1);
253 for (Standard_Integer i=2; i<=Nbext; i++) {
254 if (extrema.SquareDistance(i) < Dist2) {
256 Dist2 = extrema.SquareDistance(i);
259 Paramproj = extrema.Point(indexmin).Parameter();
260 Ptproj = extrema.Point(indexmin).Value();
261 return Standard_True;
264 Standard_Real IntPatch_HInterTool::Tolerance (const Handle(Adaptor3d_HVertex)& V,
265 const Handle(Adaptor2d_HCurve2d)& C)
267 return V->Resolution(C);
270 Standard_Real IntPatch_HInterTool::Parameter (const Handle(Adaptor3d_HVertex)& V,
271 const Handle(Adaptor2d_HCurve2d)& C)
273 return V->Parameter(C);
276 Standard_Boolean IntPatch_HInterTool::HasBeenSeen(const Handle(Adaptor2d_HCurve2d)&)
278 return Standard_False;
281 Standard_Integer IntPatch_HInterTool::NbPoints(const Handle(Adaptor2d_HCurve2d)&)
286 void IntPatch_HInterTool::Value(const Handle(Adaptor2d_HCurve2d)&,
287 const Standard_Integer,
292 throw Standard_OutOfRange();
295 Standard_Boolean IntPatch_HInterTool::IsVertex(const Handle(Adaptor2d_HCurve2d)&,
296 const Standard_Integer)
298 return Standard_False;
301 void IntPatch_HInterTool::Vertex(const Handle(Adaptor2d_HCurve2d)&,
302 const Standard_Integer,
303 Handle(Adaptor3d_HVertex)&)
305 throw Standard_OutOfRange();
308 Standard_Integer IntPatch_HInterTool::NbSegments(const Handle(Adaptor2d_HCurve2d)&)
313 Standard_Boolean IntPatch_HInterTool::HasFirstPoint (const Handle(Adaptor2d_HCurve2d)&,
314 const Standard_Integer,
317 throw Standard_OutOfRange();
320 Standard_Boolean IntPatch_HInterTool::HasLastPoint (const Handle(Adaptor2d_HCurve2d)&,
321 const Standard_Integer,
324 throw Standard_OutOfRange();
327 Standard_Boolean IntPatch_HInterTool::IsAllSolution (const Handle(Adaptor2d_HCurve2d)&)
329 return Standard_False;