1 // Created on: 1995-07-02
2 // Created by: Laurent BUCHARD
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <IntPatch_HInterTool.ixx>
24 #include <Extrema_EPCOfExtPC2d.hxx>
25 #include <Extrema_POnCurv2d.hxx>
27 #include <GeomAbs_SurfaceType.hxx>
28 #include <Standard_OutOfRange.hxx>
30 #include <Handle_Geom_BezierSurface.hxx>
31 #include <Handle_Geom_BSplineSurface.hxx>
32 #include <Handle_Geom2d_BezierCurve.hxx>
33 #include <Handle_Geom2d_BSplineCurve.hxx>
35 #include <Geom_BezierSurface.hxx>
36 #include <Geom_BSplineSurface.hxx>
37 #include <Geom2d_BezierCurve.hxx>
38 #include <Geom2d_BSplineCurve.hxx>
40 IntPatch_HInterTool::IntPatch_HInterTool() :
41 uinf (0.), vinf (0.), usup (0.), vsup (0.)
45 Standard_Integer IntPatch_HInterTool::NbSamplesV (const Handle(Adaptor3d_HSurface)& S,
46 const Standard_Real, const Standard_Real)
50 case GeomAbs_Plane: return 2;
51 case GeomAbs_BezierSurface: return (3 + S->NbVPoles());
52 case GeomAbs_BSplineSurface:
54 Standard_Integer nbs = S->NbVKnots();
56 if (!S->IsVRational()) nbs *= 2;
61 case GeomAbs_Cylinder:
65 case GeomAbs_SurfaceOfRevolution:
66 case GeomAbs_SurfaceOfExtrusion: return 15;
68 case GeomAbs_OffsetSurface:
69 case GeomAbs_OtherSurface: return 10;
74 Standard_Integer IntPatch_HInterTool::NbSamplesU (const Handle(Adaptor3d_HSurface)& S,
75 const Standard_Real, const Standard_Real)
79 case GeomAbs_Plane: return 2;
80 case GeomAbs_BezierSurface: return (3 + S->NbUPoles());
81 case GeomAbs_BSplineSurface:
83 Standard_Integer nbs = S->NbUKnots();
85 if (!S->IsURational()) nbs *= 2;
89 case GeomAbs_Torus: return 20;
91 case GeomAbs_Cylinder:
94 case GeomAbs_SurfaceOfRevolution:
95 case GeomAbs_SurfaceOfExtrusion:
96 case GeomAbs_OffsetSurface:
97 case GeomAbs_OtherSurface: return 10;
102 Standard_Integer IntPatch_HInterTool::NbSamplePoints (const Handle(Adaptor3d_HSurface)& S)
104 uinf = S->FirstUParameter();
105 usup = S->LastUParameter();
106 vinf = S->FirstVParameter();
107 vsup = S->LastVParameter();
110 Standard_Real temp = uinf;
115 Standard_Real temp = vinf;
119 if (uinf == RealFirst() && usup == RealLast()) {
123 else if (uinf == RealFirst()) {
126 else if (usup == RealLast()) {
130 if (vinf == RealFirst() && vsup == RealLast()) {
134 else if (vinf == RealFirst()) {
137 else if (vsup == RealLast()) {
140 const Standard_Integer m = (1+NbSamplesU(S,uinf,usup)/2) * (1+NbSamplesV(S,vinf,vsup)/2);
144 void IntPatch_HInterTool::SamplePoint (const Handle(Adaptor3d_HSurface)& S,
145 const Standard_Integer Index,
147 Standard_Real& V ) const
149 Standard_Integer nbIntU = 1+NbSamplesU(S,uinf,usup);
151 Standard_Integer nbIntV = 1+NbSamplesV(S,vinf,vsup);
154 if(nbIntU * nbIntV >5) {
156 Standard_Integer NV = (Index-1) / nbIntU;
157 Standard_Integer NU = (Index-1) - NV * nbIntU;
158 Standard_Real du = ((usup-uinf)/((Standard_Real)(nbIntU+1)));
159 Standard_Real dv = ((vsup-vinf)/((Standard_Real)(nbIntV+1)));
161 Standard_Integer perturb=(NU+NV) & 3;
163 //-- petite perturbation pou eviter les pbs de symetrie avec Les recherches de points int.
166 case 1: dv*=1.001; dv*=0.999; break;
167 case 2: du*=1.001; dv*=1.001; break;
168 case 3: du*=0.999; break;
172 U = uinf + du*(Standard_Real)(NU+1);
173 V = vinf + dv*(Standard_Real)(NV+1);
180 U = 0.76*uinf + 0.24*usup;
181 V = 0.74*vinf + 0.26*vsup;
184 U = 0.73*uinf + 0.27*usup;
185 V = 0.24*vinf + 0.76*vsup;
188 U = 0.25*uinf + 0.75*usup;
189 V = 0.76*vinf + 0.24*vsup;
192 U = 0.26*uinf + 0.74*usup;
193 V = 0.25*vinf + 0.75*vsup;
196 U = 0.51*uinf+0.49*usup;
197 V = 0.49*vinf+0.51*vsup;
202 Standard_Integer IntPatch_HInterTool::NbSamplesOnArc (const Handle(Adaptor2d_HCurve2d)& A)
204 GeomAbs_CurveType CurveType = A->GetType();
206 // Standard_Real nbsOnC = 5;
207 Standard_Integer nbsOnC = 5;
213 case GeomAbs_Ellipse:
214 case GeomAbs_Hyperbola:
215 case GeomAbs_Parabola:
218 case GeomAbs_BezierCurve:
219 nbsOnC = A->NbPoles();
221 case GeomAbs_BSplineCurve: {
222 //-- Handle_Geom2d_BSplineCurve& BSC=A->BSpline();
223 nbsOnC = 2 + A->NbKnots() * A->Degree();
232 void IntPatch_HInterTool::Bounds(const Handle(Adaptor2d_HCurve2d)& A,
233 Standard_Real& Ufirst,
234 Standard_Real& Ulast)
236 Ufirst = A->FirstParameter();
237 Ulast = A->LastParameter();
240 Standard_Boolean IntPatch_HInterTool::Project (const Handle(Adaptor2d_HCurve2d)& C,
242 Standard_Real& Paramproj,
245 Standard_Real epsX = 1.e-8;
246 Standard_Integer Nbu = 20;
247 Standard_Real Tol = 1.e-5;
250 Extrema_EPCOfExtPC2d extrema(P,C->Curve2d(),Nbu,epsX,Tol);
251 if (!extrema.IsDone()) {
252 return Standard_False;
254 Standard_Integer Nbext = extrema.NbExt();
256 return Standard_False;
258 Standard_Integer indexmin = 1;
259 Dist2 = extrema.SquareDistance(1);
260 for (Standard_Integer i=2; i<=Nbext; i++) {
261 if (extrema.SquareDistance(i) < Dist2) {
263 Dist2 = extrema.SquareDistance(i);
266 Paramproj = extrema.Point(indexmin).Parameter();
267 Ptproj = extrema.Point(indexmin).Value();
268 return Standard_True;
271 Standard_Real IntPatch_HInterTool::Tolerance (const Handle(Adaptor3d_HVertex)& V,
272 const Handle(Adaptor2d_HCurve2d)& C)
274 return V->Resolution(C);
277 Standard_Real IntPatch_HInterTool::Parameter (const Handle(Adaptor3d_HVertex)& V,
278 const Handle(Adaptor2d_HCurve2d)& C)
280 return V->Parameter(C);
283 Standard_Boolean IntPatch_HInterTool::HasBeenSeen(const Handle(Adaptor2d_HCurve2d)&)
285 return Standard_False;
288 Standard_Integer IntPatch_HInterTool::NbPoints(const Handle(Adaptor2d_HCurve2d)&)
293 void IntPatch_HInterTool::Value(const Handle(Adaptor2d_HCurve2d)&,
294 const Standard_Integer,
299 Standard_OutOfRange::Raise();
302 Standard_Boolean IntPatch_HInterTool::IsVertex(const Handle(Adaptor2d_HCurve2d)&,
303 const Standard_Integer)
305 return Standard_False;
308 void IntPatch_HInterTool::Vertex(const Handle(Adaptor2d_HCurve2d)&,
309 const Standard_Integer,
310 Handle(Adaptor3d_HVertex)&)
312 Standard_OutOfRange::Raise();
315 Standard_Integer IntPatch_HInterTool::NbSegments(const Handle(Adaptor2d_HCurve2d)&)
320 Standard_Boolean IntPatch_HInterTool::HasFirstPoint (const Handle(Adaptor2d_HCurve2d)&,
321 const Standard_Integer,
324 Standard_OutOfRange::Raise();
325 return Standard_False;
328 Standard_Boolean IntPatch_HInterTool::HasLastPoint (const Handle(Adaptor2d_HCurve2d)&,
329 const Standard_Integer,
332 Standard_OutOfRange::Raise();
333 return Standard_False;
336 Standard_Boolean IntPatch_HInterTool::IsAllSolution (const Handle(Adaptor2d_HCurve2d)&)
338 return Standard_False;