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