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 <Contap_HContTool.hxx>
22 #include <Extrema_EPCOfExtPC2d.hxx>
23 #include <Extrema_POnCurv2d.hxx>
25 #include <gp_Pnt2d.hxx>
27 static Standard_Real uinf,vinf,usup,vsup;
29 Standard_Integer Contap_HContTool::NbSamplesV
30 (const Handle(Adaptor3d_HSurface)& S,
35 GeomAbs_SurfaceType typS = S->GetType();
42 case GeomAbs_BezierSurface:
44 nbs = 3 + S->NbVPoles();
47 case GeomAbs_BSplineSurface:
49 //-- Handle(Geom_BSplineSurface)& HBS=S->BSpline();
56 case GeomAbs_Cylinder:
60 case GeomAbs_SurfaceOfRevolution:
61 case GeomAbs_SurfaceOfExtrusion:
76 Standard_Integer Contap_HContTool::NbSamplesU
77 (const Handle(Adaptor3d_HSurface)& S,
82 GeomAbs_SurfaceType typS = S->GetType();
89 case GeomAbs_BezierSurface:
91 nbs = 3 + S->NbUPoles();
94 case GeomAbs_BSplineSurface:
96 //-- Handle(Geom_BSplineSurface)& HBS=S->BSpline();
108 case GeomAbs_Cylinder:
111 case GeomAbs_SurfaceOfRevolution:
112 case GeomAbs_SurfaceOfExtrusion:
127 Standard_Integer Contap_HContTool::NbSamplePoints
128 (const Handle(Adaptor3d_HSurface)& S)
130 uinf = S->FirstUParameter();
131 usup = S->LastUParameter();
132 vinf = S->FirstVParameter();
133 vsup = S->LastVParameter();
136 Standard_Real temp = uinf;
141 Standard_Real temp = vinf;
145 if (uinf == RealFirst() && usup == RealLast()) {
149 else if (uinf == RealFirst()) {
152 else if (usup == RealLast()) {
156 if (vinf == RealFirst() && vsup == RealLast()) {
160 else if (vinf == RealFirst()) {
163 else if (vsup == RealLast()) {
166 if(S->GetType() == GeomAbs_BSplineSurface) {
167 Standard_Integer m = (NbSamplesU(S,uinf,usup)/3) * (NbSamplesV(S,vinf,vsup)/3);
175 void Contap_HContTool::SamplePoint (const Handle(Adaptor3d_HSurface)& S,
176 const Standard_Integer Index,
180 if(S->GetType() == GeomAbs_BSplineSurface) {
181 Standard_Integer nbIntU = NbSamplesU(S,uinf,usup)/3;
182 Standard_Integer nbIntV = NbSamplesV(S,vinf,vsup)/3;
183 if(nbIntU * nbIntV >5) {
184 Standard_Integer indU = (Index-1)/nbIntU; //---- 0 --> nbIntV
185 Standard_Integer indV = (Index-1) - indU*nbIntU; //---- 0 --> nbIntU
187 U = uinf + ((usup-uinf)/((Standard_Real)(nbIntU+1)))*(Standard_Real)(indU+1);
188 V = vinf + ((vsup-vinf)/((Standard_Real)(nbIntV+2)))*(Standard_Real)(indV+1);
190 //-- cout<<"Index :"<<Index<<" uinf:"<<uinf<<" usup:"<<usup<<" vinf:"<<vinf<<" vsup:"<<vsup<<" ";
191 //-- cout<<" ("<<indU<<"/"<<nbIntU<<" ->U:"<<U<<" ";
192 //-- cout<<" ("<<indV<<"/"<<nbIntV<<" ->V:"<<V<<endl;
199 U = 0.75*uinf + 0.25*usup; //0.25;
200 V = 0.75*vinf + 0.25*vsup; //0.25;
203 U = 0.75*uinf + 0.25*usup; //0.25;
204 V = 0.25*vinf + 0.75*vsup; //0.75;
207 U = 0.25*uinf + 0.75*usup; //0.75;
208 V = 0.75*vinf + 0.25*vsup; //0.25;
211 U = 0.25*uinf + 0.75*usup; //0.75;
212 V = 0.25*vinf + 0.75*vsup; //0.75;
215 U = 0.5*(uinf+usup); //0.5;
216 V = 0.5*(vinf+vsup); //0.5;
221 Standard_Integer Contap_HContTool::NbSamplesOnArc
222 (const Handle(Adaptor2d_HCurve2d)& A) {
224 GeomAbs_CurveType CurveType = A->GetType();
226 Standard_Real nbsOnC = 5;
232 case GeomAbs_Ellipse:
233 case GeomAbs_Hyperbola:
234 case GeomAbs_Parabola:
237 case GeomAbs_BezierCurve:
238 nbsOnC = A->NbPoles();
240 case GeomAbs_BSplineCurve: {
241 //-- Handle(Geom2d_BSplineCurve)& BSC=A->BSpline();
242 nbsOnC = 2 + A->NbKnots() * A->Degree();
248 return (Standard_Integer)(nbsOnC);
252 void Contap_HContTool::Bounds(const Handle(Adaptor2d_HCurve2d)& A,
253 Standard_Real& Ufirst,
254 Standard_Real& Ulast)
256 Ufirst = A->FirstParameter();
257 Ulast = A->LastParameter();
261 Standard_Boolean Contap_HContTool::Project (const Handle(Adaptor2d_HCurve2d)& C,
263 Standard_Real& Paramproj,
268 Standard_Real epsX = 1.e-8;
269 Standard_Integer Nbu = 20;
270 Standard_Real Tol = 1.e-5;
273 Extrema_EPCOfExtPC2d extrema(P,C->Curve2d(),Nbu,epsX,Tol);
274 if (!extrema.IsDone()) {
275 return Standard_False;
277 Standard_Integer Nbext = extrema.NbExt();
279 return Standard_False;
281 Standard_Integer indexmin = 1;
282 Dist2 = extrema.SquareDistance(1);
283 for (Standard_Integer i=2; i<=Nbext; i++) {
284 if (extrema.SquareDistance(i) < Dist2) {
286 Dist2 = extrema.SquareDistance(i);
289 Paramproj = extrema.Point(indexmin).Parameter();
290 Ptproj = extrema.Point(indexmin).Value();
291 return Standard_True;
295 Standard_Real Contap_HContTool::Tolerance (const Handle(Adaptor3d_HVertex)& V,
296 const Handle(Adaptor2d_HCurve2d)& C)
298 // return BRepAdaptor2d_Curve2dTool::Resolution(C,BRep_Tool::Tolerance(V));
299 return V->Resolution(C);
302 Standard_Real Contap_HContTool::Parameter (const Handle(Adaptor3d_HVertex)& V,
303 const Handle(Adaptor2d_HCurve2d)& C)
305 // return BRep_Tool::Parameter(V,C.Edge());
306 return V->Parameter(C);
311 Standard_Boolean Contap_HContTool::HasBeenSeen
312 (const Handle(Adaptor2d_HCurve2d)&)
314 return Standard_False;
317 Standard_Integer Contap_HContTool::NbPoints(const Handle(Adaptor2d_HCurve2d)&)
322 void Contap_HContTool::Value(const Handle(Adaptor2d_HCurve2d)&,
323 const Standard_Integer,
328 Standard_OutOfRange::Raise();
331 Standard_Boolean Contap_HContTool::IsVertex(const Handle(Adaptor2d_HCurve2d)&,
332 const Standard_Integer)
334 return Standard_False;
337 void Contap_HContTool::Vertex(const Handle(Adaptor2d_HCurve2d)&,
338 const Standard_Integer,
339 Handle(Adaptor3d_HVertex)&)
341 Standard_OutOfRange::Raise();
344 Standard_Integer Contap_HContTool::NbSegments(const Handle(Adaptor2d_HCurve2d)&)
349 Standard_Boolean Contap_HContTool::HasFirstPoint
350 (const Handle(Adaptor2d_HCurve2d)&,
351 const Standard_Integer,
354 Standard_OutOfRange::Raise();
355 return Standard_False;
358 Standard_Boolean Contap_HContTool::HasLastPoint
359 (const Handle(Adaptor2d_HCurve2d)&,
360 const Standard_Integer,
363 Standard_OutOfRange::Raise();
364 return Standard_False;
367 Standard_Boolean Contap_HContTool::IsAllSolution
368 (const Handle(Adaptor2d_HCurve2d)&)
371 return Standard_False;