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.
17 #include <Contap_HContTool.ixx>
19 #include <Extrema_EPCOfExtPC2d.hxx>
20 #include <Extrema_POnCurv2d.hxx>
22 static Standard_Real uinf,vinf,usup,vsup;
24 Standard_Integer Contap_HContTool::NbSamplesV
25 (const Handle(Adaptor3d_HSurface)& S,
30 GeomAbs_SurfaceType typS = S->GetType();
37 case GeomAbs_BezierSurface:
39 nbs = 3 + S->NbVPoles();
42 case GeomAbs_BSplineSurface:
44 //-- Handle(Geom_BSplineSurface)& HBS=S->BSpline();
51 case GeomAbs_Cylinder:
55 case GeomAbs_SurfaceOfRevolution:
56 case GeomAbs_SurfaceOfExtrusion:
71 Standard_Integer Contap_HContTool::NbSamplesU
72 (const Handle(Adaptor3d_HSurface)& S,
77 GeomAbs_SurfaceType typS = S->GetType();
84 case GeomAbs_BezierSurface:
86 nbs = 3 + S->NbUPoles();
89 case GeomAbs_BSplineSurface:
91 //-- Handle(Geom_BSplineSurface)& HBS=S->BSpline();
103 case GeomAbs_Cylinder:
106 case GeomAbs_SurfaceOfRevolution:
107 case GeomAbs_SurfaceOfExtrusion:
122 Standard_Integer Contap_HContTool::NbSamplePoints
123 (const Handle(Adaptor3d_HSurface)& S)
125 uinf = S->FirstUParameter();
126 usup = S->LastUParameter();
127 vinf = S->FirstVParameter();
128 vsup = S->LastVParameter();
131 Standard_Real temp = uinf;
136 Standard_Real temp = vinf;
140 if (uinf == RealFirst() && usup == RealLast()) {
144 else if (uinf == RealFirst()) {
147 else if (usup == RealLast()) {
151 if (vinf == RealFirst() && vsup == RealLast()) {
155 else if (vinf == RealFirst()) {
158 else if (vsup == RealLast()) {
161 if(S->GetType() == GeomAbs_BSplineSurface) {
162 Standard_Integer m = (NbSamplesU(S,uinf,usup)/3) * (NbSamplesV(S,vinf,vsup)/3);
170 void Contap_HContTool::SamplePoint (const Handle(Adaptor3d_HSurface)& S,
171 const Standard_Integer Index,
175 if(S->GetType() == GeomAbs_BSplineSurface) {
176 Standard_Integer nbIntU = NbSamplesU(S,uinf,usup)/3;
177 Standard_Integer nbIntV = NbSamplesV(S,vinf,vsup)/3;
178 if(nbIntU * nbIntV >5) {
179 Standard_Integer indU = (Index-1)/nbIntU; //---- 0 --> nbIntV
180 Standard_Integer indV = (Index-1) - indU*nbIntU; //---- 0 --> nbIntU
182 U = uinf + ((usup-uinf)/((Standard_Real)(nbIntU+1)))*(Standard_Real)(indU+1);
183 V = vinf + ((vsup-vinf)/((Standard_Real)(nbIntV+2)))*(Standard_Real)(indV+1);
185 //-- cout<<"Index :"<<Index<<" uinf:"<<uinf<<" usup:"<<usup<<" vinf:"<<vinf<<" vsup:"<<vsup<<" ";
186 //-- cout<<" ("<<indU<<"/"<<nbIntU<<" ->U:"<<U<<" ";
187 //-- cout<<" ("<<indV<<"/"<<nbIntV<<" ->V:"<<V<<endl;
194 U = 0.75*uinf + 0.25*usup; //0.25;
195 V = 0.75*vinf + 0.25*vsup; //0.25;
198 U = 0.75*uinf + 0.25*usup; //0.25;
199 V = 0.25*vinf + 0.75*vsup; //0.75;
202 U = 0.25*uinf + 0.75*usup; //0.75;
203 V = 0.75*vinf + 0.25*vsup; //0.25;
206 U = 0.25*uinf + 0.75*usup; //0.75;
207 V = 0.25*vinf + 0.75*vsup; //0.75;
210 U = 0.5*(uinf+usup); //0.5;
211 V = 0.5*(vinf+vsup); //0.5;
216 Standard_Integer Contap_HContTool::NbSamplesOnArc
217 (const Handle(Adaptor2d_HCurve2d)& A) {
219 GeomAbs_CurveType CurveType = A->GetType();
221 Standard_Real nbsOnC = 5;
227 case GeomAbs_Ellipse:
228 case GeomAbs_Hyperbola:
229 case GeomAbs_Parabola:
232 case GeomAbs_BezierCurve:
233 nbsOnC = A->NbPoles();
235 case GeomAbs_BSplineCurve: {
236 //-- Handle(Geom2d_BSplineCurve)& BSC=A->BSpline();
237 nbsOnC = 2 + A->NbKnots() * A->Degree();
243 return (Standard_Integer)(nbsOnC);
247 void Contap_HContTool::Bounds(const Handle(Adaptor2d_HCurve2d)& A,
248 Standard_Real& Ufirst,
249 Standard_Real& Ulast)
251 Ufirst = A->FirstParameter();
252 Ulast = A->LastParameter();
256 Standard_Boolean Contap_HContTool::Project (const Handle(Adaptor2d_HCurve2d)& C,
258 Standard_Real& Paramproj,
263 Standard_Real epsX = 1.e-8;
264 Standard_Integer Nbu = 20;
265 Standard_Real Tol = 1.e-5;
268 Extrema_EPCOfExtPC2d extrema(P,C->Curve2d(),Nbu,epsX,Tol);
269 if (!extrema.IsDone()) {
270 return Standard_False;
272 Standard_Integer Nbext = extrema.NbExt();
274 return Standard_False;
276 Standard_Integer indexmin = 1;
277 Dist2 = extrema.SquareDistance(1);
278 for (Standard_Integer i=2; i<=Nbext; i++) {
279 if (extrema.SquareDistance(i) < Dist2) {
281 Dist2 = extrema.SquareDistance(i);
284 Paramproj = extrema.Point(indexmin).Parameter();
285 Ptproj = extrema.Point(indexmin).Value();
286 return Standard_True;
290 Standard_Real Contap_HContTool::Tolerance (const Handle(Adaptor3d_HVertex)& V,
291 const Handle(Adaptor2d_HCurve2d)& C)
293 // return BRepAdaptor2d_Curve2dTool::Resolution(C,BRep_Tool::Tolerance(V));
294 return V->Resolution(C);
297 Standard_Real Contap_HContTool::Parameter (const Handle(Adaptor3d_HVertex)& V,
298 const Handle(Adaptor2d_HCurve2d)& C)
300 // return BRep_Tool::Parameter(V,C.Edge());
301 return V->Parameter(C);
306 Standard_Boolean Contap_HContTool::HasBeenSeen
307 (const Handle(Adaptor2d_HCurve2d)&)
309 return Standard_False;
312 Standard_Integer Contap_HContTool::NbPoints(const Handle(Adaptor2d_HCurve2d)&)
317 void Contap_HContTool::Value(const Handle(Adaptor2d_HCurve2d)&,
318 const Standard_Integer,
323 Standard_OutOfRange::Raise();
326 Standard_Boolean Contap_HContTool::IsVertex(const Handle(Adaptor2d_HCurve2d)&,
327 const Standard_Integer)
329 return Standard_False;
332 void Contap_HContTool::Vertex(const Handle(Adaptor2d_HCurve2d)&,
333 const Standard_Integer,
334 Handle(Adaptor3d_HVertex)&)
336 Standard_OutOfRange::Raise();
339 Standard_Integer Contap_HContTool::NbSegments(const Handle(Adaptor2d_HCurve2d)&)
344 Standard_Boolean Contap_HContTool::HasFirstPoint
345 (const Handle(Adaptor2d_HCurve2d)&,
346 const Standard_Integer,
349 Standard_OutOfRange::Raise();
350 return Standard_False;
353 Standard_Boolean Contap_HContTool::HasLastPoint
354 (const Handle(Adaptor2d_HCurve2d)&,
355 const Standard_Integer,
358 Standard_OutOfRange::Raise();
359 return Standard_False;
362 Standard_Boolean Contap_HContTool::IsAllSolution
363 (const Handle(Adaptor2d_HCurve2d)&)
366 return Standard_False;