0024750: Replace instantiations of TCollection generic classes by NCollection templat...
[occt.git] / src / Contap / Contap_HContTool.cxx
CommitLineData
b311480e 1// Created on: 1995-07-02
2// Created by: Laurent BUCHARD
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
e2065c2f 17#include <Contap_HContTool.ixx>
18
7fd59977 19#include <Extrema_EPCOfExtPC2d.hxx>
20#include <Extrema_POnCurv2d.hxx>
21
7fd59977 22static Standard_Real uinf,vinf,usup,vsup;
23
e2065c2f 24Standard_Integer Contap_HContTool::NbSamplesV
25(const Handle(Adaptor3d_HSurface)& S,
26 const Standard_Real ,
27 const Standard_Real )
7fd59977 28{
29 Standard_Integer nbs;
30 GeomAbs_SurfaceType typS = S->GetType();
31 switch(typS) {
32 case GeomAbs_Plane:
33 {
34 nbs = 2;
35 }
36 break;
37 case GeomAbs_BezierSurface:
38 {
39 nbs = 3 + S->NbVPoles();
40 }
41 break;
42 case GeomAbs_BSplineSurface:
43 {
857ffd5e 44 //-- Handle(Geom_BSplineSurface)& HBS=S->BSpline();
7fd59977 45 nbs = S->NbVKnots();
46 nbs*= S->VDegree();
47 if(nbs < 2) nbs=2;
e2065c2f 48
7fd59977 49 }
50 break;
51 case GeomAbs_Cylinder:
52 case GeomAbs_Cone:
53 case GeomAbs_Sphere:
54 case GeomAbs_Torus:
55 case GeomAbs_SurfaceOfRevolution:
56 case GeomAbs_SurfaceOfExtrusion:
57 {
58 nbs = 15;
59 }
60 break;
e2065c2f 61
7fd59977 62 default:
63 {
64 nbs = 10;
65 }
66 break;
67 }
68 return(nbs);
69}
70
e2065c2f 71Standard_Integer Contap_HContTool::NbSamplesU
72(const Handle(Adaptor3d_HSurface)& S,
73 const Standard_Real ,
74 const Standard_Real )
7fd59977 75{
76 Standard_Integer nbs;
77 GeomAbs_SurfaceType typS = S->GetType();
78 switch(typS) {
79 case GeomAbs_Plane:
80 {
81 nbs = 2;
82 }
83 break;
84 case GeomAbs_BezierSurface:
85 {
86 nbs = 3 + S->NbUPoles();
87 }
88 break;
89 case GeomAbs_BSplineSurface:
90 {
857ffd5e 91 //-- Handle(Geom_BSplineSurface)& HBS=S->BSpline();
7fd59977 92 nbs = S->NbUKnots();
93 nbs*= S->UDegree();
94 if(nbs < 2) nbs=2;
e2065c2f 95
7fd59977 96 }
97 break;
98 case GeomAbs_Torus:
99 {
100 nbs = 20;
101 }
102 break;
103 case GeomAbs_Cylinder:
104 case GeomAbs_Cone:
105 case GeomAbs_Sphere:
106 case GeomAbs_SurfaceOfRevolution:
107 case GeomAbs_SurfaceOfExtrusion:
108 {
109 nbs = 10;
110 }
111 break;
e2065c2f 112
7fd59977 113 default:
114 {
115 nbs = 10;
116 }
117 break;
118 }
119 return(nbs);
120}
121
e2065c2f 122Standard_Integer Contap_HContTool::NbSamplePoints
123(const Handle(Adaptor3d_HSurface)& S)
7fd59977 124{
125 uinf = S->FirstUParameter();
126 usup = S->LastUParameter();
127 vinf = S->FirstVParameter();
128 vsup = S->LastVParameter();
129
130 if (usup < uinf) {
131 Standard_Real temp = uinf;
132 uinf = usup;
133 usup = temp;
e2065c2f 134 }
135 if (vsup < vinf) {
7fd59977 136 Standard_Real temp = vinf;
137 vinf = vsup;
138 vsup = temp;
139 }
140 if (uinf == RealFirst() && usup == RealLast()) {
141 uinf = -1.e5;
142 usup = 1.e5;
143 }
144 else if (uinf == RealFirst()) {
145 uinf = usup - 2.e5;
146 }
147 else if (usup == RealLast()) {
148 usup = uinf + 2.e5;
149 }
e2065c2f 150
7fd59977 151 if (vinf == RealFirst() && vsup == RealLast()) {
152 vinf = -1.e5;
153 vsup = 1.e5;
154 }
155 else if (vinf == RealFirst()) {
156 vinf = vsup - 2.e5;
157 }
158 else if (vsup == RealLast()) {
159 vsup = vinf + 2.e5;
160 }
161 if(S->GetType() == GeomAbs_BSplineSurface) {
162 Standard_Integer m = (NbSamplesU(S,uinf,usup)/3) * (NbSamplesV(S,vinf,vsup)/3);
163 if(m>5) return(m);
164 else return(5);
165 }
166 else
167 return 5;
168}
169
e2065c2f 170void Contap_HContTool::SamplePoint (const Handle(Adaptor3d_HSurface)& S,
171 const Standard_Integer Index,
172 Standard_Real& U,
173 Standard_Real& V )
7fd59977 174{
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
e2065c2f 181
7fd59977 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);
e2065c2f 184
7fd59977 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;
188 return;
189 }
190 }
e2065c2f 191
7fd59977 192 switch (Index) {
193 case 1:
194 U = 0.75*uinf + 0.25*usup; //0.25;
195 V = 0.75*vinf + 0.25*vsup; //0.25;
196 break;
197 case 2:
198 U = 0.75*uinf + 0.25*usup; //0.25;
199 V = 0.25*vinf + 0.75*vsup; //0.75;
200 break;
201 case 3:
202 U = 0.25*uinf + 0.75*usup; //0.75;
203 V = 0.75*vinf + 0.25*vsup; //0.25;
204 break;
205 case 4:
206 U = 0.25*uinf + 0.75*usup; //0.75;
207 V = 0.25*vinf + 0.75*vsup; //0.75;
208 break;
209 default:
210 U = 0.5*(uinf+usup); //0.5;
211 V = 0.5*(vinf+vsup); //0.5;
212 }
213}
214
215
e2065c2f 216Standard_Integer Contap_HContTool::NbSamplesOnArc
217(const Handle(Adaptor2d_HCurve2d)& A) {
7fd59977 218
219 GeomAbs_CurveType CurveType = A->GetType();
220
221 Standard_Real nbsOnC = 5;
222 switch(CurveType) {
223 case GeomAbs_Line:
224 nbsOnC = 2;
225 break;
226 case GeomAbs_Circle:
227 case GeomAbs_Ellipse:
228 case GeomAbs_Hyperbola:
229 case GeomAbs_Parabola:
230 nbsOnC = 10;
231 break;
232 case GeomAbs_BezierCurve:
233 nbsOnC = A->NbPoles();
234 break;
235 case GeomAbs_BSplineCurve: {
857ffd5e 236 //-- Handle(Geom2d_BSplineCurve)& BSC=A->BSpline();
7fd59977 237 nbsOnC = 2 + A->NbKnots() * A->Degree();
238 break;
e2065c2f 239 }
7fd59977 240 default:
241 nbsOnC = 10;
242 }
7fd59977 243 return (Standard_Integer)(nbsOnC);
7fd59977 244}
245
246
e2065c2f 247void Contap_HContTool::Bounds(const Handle(Adaptor2d_HCurve2d)& A,
248 Standard_Real& Ufirst,
249 Standard_Real& Ulast)
7fd59977 250{
251 Ufirst = A->FirstParameter();
252 Ulast = A->LastParameter();
253}
254
255
e2065c2f 256Standard_Boolean Contap_HContTool::Project (const Handle(Adaptor2d_HCurve2d)& C,
257 const gp_Pnt2d& P,
258 Standard_Real& Paramproj,
259 gp_Pnt2d& Ptproj)
7fd59977 260
261{
262
263 Standard_Real epsX = 1.e-8;
264 Standard_Integer Nbu = 20;
265 Standard_Real Tol = 1.e-5;
266 Standard_Real Dist2;
267
268 Extrema_EPCOfExtPC2d extrema(P,C->Curve2d(),Nbu,epsX,Tol);
269 if (!extrema.IsDone()) {
270 return Standard_False;
271 }
272 Standard_Integer Nbext = extrema.NbExt();
273 if (Nbext == 0) {
274 return Standard_False;
275 }
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) {
280 indexmin = i;
281 Dist2 = extrema.SquareDistance(i);
282 }
283 }
284 Paramproj = extrema.Point(indexmin).Parameter();
285 Ptproj = extrema.Point(indexmin).Value();
286 return Standard_True;
287}
288
289
e2065c2f 290Standard_Real Contap_HContTool::Tolerance (const Handle(Adaptor3d_HVertex)& V,
291 const Handle(Adaptor2d_HCurve2d)& C)
7fd59977 292{
e2065c2f 293 // return BRepAdaptor2d_Curve2dTool::Resolution(C,BRep_Tool::Tolerance(V));
7fd59977 294 return V->Resolution(C);
295}
296
e2065c2f 297Standard_Real Contap_HContTool::Parameter (const Handle(Adaptor3d_HVertex)& V,
298 const Handle(Adaptor2d_HCurve2d)& C)
7fd59977 299{
e2065c2f 300 // return BRep_Tool::Parameter(V,C.Edge());
7fd59977 301 return V->Parameter(C);
302}
303
304
305
e2065c2f 306Standard_Boolean Contap_HContTool::HasBeenSeen
307(const Handle(Adaptor2d_HCurve2d)&)
7fd59977 308{
309 return Standard_False;
310}
311
e2065c2f 312Standard_Integer Contap_HContTool::NbPoints(const Handle(Adaptor2d_HCurve2d)&)
7fd59977 313{
314 return 0;
315}
316
e2065c2f 317void Contap_HContTool::Value(const Handle(Adaptor2d_HCurve2d)&,
318 const Standard_Integer,
319 gp_Pnt&,
320 Standard_Real&,
321 Standard_Real&)
7fd59977 322{
323 Standard_OutOfRange::Raise();
324}
325
e2065c2f 326Standard_Boolean Contap_HContTool::IsVertex(const Handle(Adaptor2d_HCurve2d)&,
327 const Standard_Integer)
7fd59977 328{
329 return Standard_False;
330}
331
e2065c2f 332void Contap_HContTool::Vertex(const Handle(Adaptor2d_HCurve2d)&,
333 const Standard_Integer,
334 Handle(Adaptor3d_HVertex)&)
7fd59977 335{
336 Standard_OutOfRange::Raise();
337}
338
e2065c2f 339Standard_Integer Contap_HContTool::NbSegments(const Handle(Adaptor2d_HCurve2d)&)
7fd59977 340{
341 return 0;
342}
343
e2065c2f 344Standard_Boolean Contap_HContTool::HasFirstPoint
345(const Handle(Adaptor2d_HCurve2d)&,
346 const Standard_Integer,
347 Standard_Integer&)
7fd59977 348{
349 Standard_OutOfRange::Raise();
e2065c2f 350 return Standard_False;
7fd59977 351}
352
e2065c2f 353Standard_Boolean Contap_HContTool::HasLastPoint
354(const Handle(Adaptor2d_HCurve2d)&,
355 const Standard_Integer,
356 Standard_Integer&)
7fd59977 357{
358 Standard_OutOfRange::Raise();
e2065c2f 359 return Standard_False;
7fd59977 360}
361
e2065c2f 362Standard_Boolean Contap_HContTool::IsAllSolution
363(const Handle(Adaptor2d_HCurve2d)&)
7fd59977 364
365{
366 return Standard_False;
367}
368