1 //-- File: Contap_HContToolGen.cdl
2 //-- Created: Fri Jul 2 13:19:22 1995
3 //-- Author: Laurent BUCHARD
5 //---Copyright: Matra Datavision 1995
9 #include <Extrema_EPCOfExtPC2d.hxx>
10 #include <Extrema_POnCurv2d.hxx>
12 #include <GeomAbs_SurfaceType.hxx>
13 #include <Standard_OutOfRange.hxx>
15 #include <Handle_Geom_BezierSurface.hxx>
16 #include <Handle_Geom_BSplineSurface.hxx>
17 #include <Handle_Geom2d_BezierCurve.hxx>
18 #include <Handle_Geom2d_BSplineCurve.hxx>
20 #include <Geom_BezierSurface.hxx>
21 #include <Geom_BSplineSurface.hxx>
22 #include <Geom2d_BezierCurve.hxx>
23 #include <Geom2d_BSplineCurve.hxx>
25 static Standard_Real uinf,vinf,usup,vsup;
27 #include TheHSurface_hxx
28 #include TheHCurve2d_hxx
29 #include TheHVertex_hxx
32 Standard_Integer Contap_HContToolGen::NbSamplesV
33 (const TheHSurface& S,
38 GeomAbs_SurfaceType typS = S->GetType();
45 case GeomAbs_BezierSurface:
47 nbs = 3 + S->NbVPoles();
50 case GeomAbs_BSplineSurface:
52 //-- Handle_Geom_BSplineSurface& HBS=S->BSpline();
59 case GeomAbs_Cylinder:
63 case GeomAbs_SurfaceOfRevolution:
64 case GeomAbs_SurfaceOfExtrusion:
79 Standard_Integer Contap_HContToolGen::NbSamplesU
80 (const TheHSurface& S,
85 GeomAbs_SurfaceType typS = S->GetType();
92 case GeomAbs_BezierSurface:
94 nbs = 3 + S->NbUPoles();
97 case GeomAbs_BSplineSurface:
99 //-- Handle_Geom_BSplineSurface& HBS=S->BSpline();
111 case GeomAbs_Cylinder:
114 case GeomAbs_SurfaceOfRevolution:
115 case GeomAbs_SurfaceOfExtrusion:
130 Standard_Integer Contap_HContToolGen::NbSamplePoints
131 (const TheHSurface& S)
133 uinf = S->FirstUParameter();
134 usup = S->LastUParameter();
135 vinf = S->FirstVParameter();
136 vsup = S->LastVParameter();
139 Standard_Real temp = uinf;
144 Standard_Real temp = vinf;
148 if (uinf == RealFirst() && usup == RealLast()) {
152 else if (uinf == RealFirst()) {
155 else if (usup == RealLast()) {
159 if (vinf == RealFirst() && vsup == RealLast()) {
163 else if (vinf == RealFirst()) {
166 else if (vsup == RealLast()) {
169 if(S->GetType() == GeomAbs_BSplineSurface) {
170 Standard_Integer m = (NbSamplesU(S,uinf,usup)/3) * (NbSamplesV(S,vinf,vsup)/3);
178 void Contap_HContToolGen::SamplePoint (const TheHSurface& S,
179 const Standard_Integer Index,
183 if(S->GetType() == GeomAbs_BSplineSurface) {
184 Standard_Integer nbIntU = NbSamplesU(S,uinf,usup)/3;
185 Standard_Integer nbIntV = NbSamplesV(S,vinf,vsup)/3;
186 if(nbIntU * nbIntV >5) {
187 Standard_Integer indU = (Index-1)/nbIntU; //---- 0 --> nbIntV
188 Standard_Integer indV = (Index-1) - indU*nbIntU; //---- 0 --> nbIntU
190 U = uinf + ((usup-uinf)/((Standard_Real)(nbIntU+1)))*(Standard_Real)(indU+1);
191 V = vinf + ((vsup-vinf)/((Standard_Real)(nbIntV+2)))*(Standard_Real)(indV+1);
193 //-- cout<<"Index :"<<Index<<" uinf:"<<uinf<<" usup:"<<usup<<" vinf:"<<vinf<<" vsup:"<<vsup<<" ";
194 //-- cout<<" ("<<indU<<"/"<<nbIntU<<" ->U:"<<U<<" ";
195 //-- cout<<" ("<<indV<<"/"<<nbIntV<<" ->V:"<<V<<endl;
202 U = 0.75*uinf + 0.25*usup; //0.25;
203 V = 0.75*vinf + 0.25*vsup; //0.25;
206 U = 0.75*uinf + 0.25*usup; //0.25;
207 V = 0.25*vinf + 0.75*vsup; //0.75;
210 U = 0.25*uinf + 0.75*usup; //0.75;
211 V = 0.75*vinf + 0.25*vsup; //0.25;
214 U = 0.25*uinf + 0.75*usup; //0.75;
215 V = 0.25*vinf + 0.75*vsup; //0.75;
218 U = 0.5*(uinf+usup); //0.5;
219 V = 0.5*(vinf+vsup); //0.5;
224 Standard_Integer Contap_HContToolGen::NbSamplesOnArc
225 (const TheHCurve2d& A) {
227 GeomAbs_CurveType CurveType = A->GetType();
229 Standard_Real nbsOnC = 5;
235 case GeomAbs_Ellipse:
236 case GeomAbs_Hyperbola:
237 case GeomAbs_Parabola:
240 case GeomAbs_BezierCurve:
241 nbsOnC = A->NbPoles();
243 case GeomAbs_BSplineCurve: {
244 //-- Handle_Geom2d_BSplineCurve& BSC=A->BSpline();
245 nbsOnC = 2 + A->NbKnots() * A->Degree();
252 return (Standard_Integer)(nbsOnC);
259 void Contap_HContToolGen::Bounds(const TheHCurve2d& A,
260 Standard_Real& Ufirst,
261 Standard_Real& Ulast)
263 Ufirst = A->FirstParameter();
264 Ulast = A->LastParameter();
268 Standard_Boolean Contap_HContToolGen::Project (const TheHCurve2d& C,
270 Standard_Real& Paramproj,
275 Standard_Real epsX = 1.e-8;
276 Standard_Integer Nbu = 20;
277 Standard_Real Tol = 1.e-5;
280 Extrema_EPCOfExtPC2d extrema(P,C->Curve2d(),Nbu,epsX,Tol);
281 if (!extrema.IsDone()) {
282 return Standard_False;
284 Standard_Integer Nbext = extrema.NbExt();
286 return Standard_False;
288 Standard_Integer indexmin = 1;
289 Dist2 = extrema.SquareDistance(1);
290 for (Standard_Integer i=2; i<=Nbext; i++) {
291 if (extrema.SquareDistance(i) < Dist2) {
293 Dist2 = extrema.SquareDistance(i);
296 Paramproj = extrema.Point(indexmin).Parameter();
297 Ptproj = extrema.Point(indexmin).Value();
298 return Standard_True;
302 Standard_Real Contap_HContToolGen::Tolerance (const TheHVertex& V,
303 const TheHCurve2d& C)
305 // return BRepAdaptor2d_Curve2dTool::Resolution(C,BRep_Tool::Tolerance(V));
306 return V->Resolution(C);
309 Standard_Real Contap_HContToolGen::Parameter (const TheHVertex& V,
310 const TheHCurve2d& C)
312 // return BRep_Tool::Parameter(V,C.Edge());
313 return V->Parameter(C);
318 Standard_Boolean Contap_HContToolGen::HasBeenSeen
321 return Standard_False;
324 Standard_Integer Contap_HContToolGen::NbPoints(const TheHCurve2d&)
329 void Contap_HContToolGen::Value(const TheHCurve2d&,
330 const Standard_Integer,
335 Standard_OutOfRange::Raise();
338 Standard_Boolean Contap_HContToolGen::IsVertex(const TheHCurve2d&,
339 const Standard_Integer)
341 return Standard_False;
344 void Contap_HContToolGen::Vertex(const TheHCurve2d&,
345 const Standard_Integer,
348 Standard_OutOfRange::Raise();
351 Standard_Integer Contap_HContToolGen::NbSegments(const TheHCurve2d&)
356 Standard_Boolean Contap_HContToolGen::HasFirstPoint
358 const Standard_Integer,
361 Standard_OutOfRange::Raise();
362 return Standard_False;
365 Standard_Boolean Contap_HContToolGen::HasLastPoint
367 const Standard_Integer,
370 Standard_OutOfRange::Raise();
371 return Standard_False;
374 Standard_Boolean Contap_HContToolGen::IsAllSolution
378 return Standard_False;