b311480e |
1 | // Created on: 1992-04-06 |
2 | // Created by: Jacques GOUSSARD |
3 | // Copyright (c) 1992-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 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <Adaptor2d_HCurve2d.hxx> |
19 | #include <IntPatch_Point.hxx> |
20 | #include <IntPatch_RLine.hxx> |
21 | #include <IntSurf_LineOn2S.hxx> |
7fd59977 |
22 | #include <IntSurf_PntOn2S.hxx> |
23 | #include <Precision.hxx> |
42cf5bc1 |
24 | #include <Standard_DomainError.hxx> |
25 | #include <Standard_OutOfRange.hxx> |
26 | #include <Standard_Type.hxx> |
7fd59977 |
27 | |
92efcf78 |
28 | IMPLEMENT_STANDARD_RTTIEXT(IntPatch_RLine,IntPatch_PointLine) |
29 | |
7fd59977 |
30 | IntPatch_RLine::IntPatch_RLine (const Standard_Boolean Tang, |
d4b867e6 |
31 | const IntSurf_TypeTrans Trans1, |
32 | const IntSurf_TypeTrans Trans2) : |
d533dafb |
33 | IntPatch_PointLine(Tang,Trans1,Trans2), |
34 | ParamInf1(0.0), |
35 | ParamSup1(0.0), |
36 | ParamInf2(0.0), |
37 | ParamSup2(0.0), |
38 | fipt(Standard_False), |
39 | lapt(Standard_False), |
40 | indf(0), |
41 | indl(0) |
7fd59977 |
42 | { |
43 | typ = IntPatch_Restriction; |
44 | onS2=Standard_False; |
45 | onS1=Standard_False; |
46 | } |
47 | |
48 | |
49 | IntPatch_RLine::IntPatch_RLine (const Standard_Boolean Tang, |
d4b867e6 |
50 | const IntSurf_Situation Situ1, |
51 | const IntSurf_Situation Situ2) : |
d533dafb |
52 | IntPatch_PointLine(Tang,Situ1,Situ2), |
53 | ParamInf1(0.0), |
54 | ParamSup1(0.0), |
55 | ParamInf2(0.0), |
56 | ParamSup2(0.0), |
57 | fipt(Standard_False), |
58 | lapt(Standard_False), |
59 | indf(0), |
60 | indl(0) |
7fd59977 |
61 | { |
62 | typ = IntPatch_Restriction; |
63 | onS2=Standard_False; |
64 | onS1=Standard_False; |
65 | } |
66 | |
67 | |
68 | IntPatch_RLine::IntPatch_RLine (const Standard_Boolean Tang) : |
d533dafb |
69 | IntPatch_PointLine(Tang), |
70 | ParamInf1(0.0), |
71 | ParamSup1(0.0), |
72 | ParamInf2(0.0), |
73 | ParamSup2(0.0), |
74 | fipt(Standard_False), |
75 | lapt(Standard_False), |
76 | indf(0), |
77 | indl(0) |
7fd59977 |
78 | { |
79 | typ = IntPatch_Restriction; |
80 | onS2=Standard_False; |
81 | onS1=Standard_False; |
82 | } |
83 | |
84 | void IntPatch_RLine::ParamOnS1(Standard_Real& a,Standard_Real& b) const { |
85 | if(onS1) { |
86 | a=RealLast(); b=-a; |
87 | for(Standard_Integer i=svtx.Length();i>=1;i--) { |
88 | Standard_Real p=svtx(i).ParameterOnLine(); |
89 | if(p<a) a=p; |
90 | if(p>b) b=p; |
91 | } |
92 | } |
93 | else { |
94 | a=b=0.0; |
95 | } |
96 | } |
97 | |
98 | void IntPatch_RLine::ParamOnS2(Standard_Real& a,Standard_Real& b) const { |
99 | if(onS2) { |
100 | a=RealLast(); b=-a; |
101 | for(Standard_Integer i=svtx.Length();i>=1;i--) { |
102 | Standard_Real p=svtx(i).ParameterOnLine(); |
103 | if(p<a) a=p; |
104 | if(p>b) b=p; |
105 | } |
106 | } |
107 | else { |
108 | a=b=0.0; |
109 | } |
110 | } |
111 | |
112 | |
113 | void IntPatch_RLine::SetArcOnS1(const Handle(Adaptor2d_HCurve2d)& A) { |
114 | theArcOnS1 = A; |
115 | onS1=Standard_True; |
116 | } |
117 | |
118 | void IntPatch_RLine::SetArcOnS2(const Handle(Adaptor2d_HCurve2d)& A) { |
119 | theArcOnS2 = A; |
120 | onS2=Standard_True; |
121 | } |
122 | |
123 | |
124 | void IntPatch_RLine::SetPoint(const Standard_Integer Index, |
125 | const IntPatch_Point& thepoint) { |
126 | curv->Value(Index,thepoint.PntOn2S()); |
127 | } |
128 | |
129 | //void IntPatch_RLine::ComputeVertexParameters(const Standard_Real Tol) |
130 | void IntPatch_RLine::ComputeVertexParameters(const Standard_Real ) |
131 | { |
132 | Standard_Integer i,j,nbvtx;//k; |
133 | |
7fd59977 |
134 | Standard_Boolean APointDeleted = Standard_False; |
135 | //---------------------------------------------------------- |
136 | //-- F i l t r e s u r r e s t r i c t i o n s -- |
137 | //---------------------------------------------------------- |
138 | //-- deux vertex sur la meme restriction et seulement |
139 | //-- sur celle ci ne doivent pas avoir le meme parametre |
140 | //-- |
141 | nbvtx = NbVertex(); |
142 | do { |
143 | APointDeleted = Standard_False; |
144 | for(i=1; (i<=nbvtx) && (APointDeleted==Standard_False) ;i++) { |
145 | const IntPatch_Point& VTXi = svtx.Value(i); |
146 | if((VTXi.IsOnDomS1()==Standard_True) && (VTXi.IsOnDomS2()==Standard_False)) { |
147 | for(j=1; (j<=nbvtx) && (APointDeleted==Standard_False) ;j++) { |
148 | if(i!=j) { |
149 | const IntPatch_Point& VTXj = svtx.Value(j); |
150 | if((VTXj.IsOnDomS1()==Standard_True) && (VTXj.IsOnDomS2()==Standard_False)) { |
151 | if(VTXi.ParameterOnLine() == VTXj.ParameterOnLine()) { |
152 | if(VTXi.ArcOnS1() == VTXj.ArcOnS1()) { |
153 | if(VTXi.ParameterOnArc1() == VTXj.ParameterOnArc1()) { |
154 | svtx.Remove(j); |
155 | nbvtx--; |
156 | if(lapt) { if(indl>=j) indl--; } |
157 | if(fipt) { if(indf>=j) indf--; } |
158 | APointDeleted = Standard_True; |
159 | } |
160 | } |
161 | } |
162 | } |
163 | } |
164 | } |
165 | } |
166 | } |
167 | } |
168 | while(APointDeleted == Standard_True); |
169 | |
170 | do { |
171 | APointDeleted = Standard_False; |
172 | for(i=1; (i<=nbvtx) && (APointDeleted==Standard_False) ;i++) { |
173 | const IntPatch_Point& VTXi = svtx.Value(i); |
174 | if((VTXi.IsOnDomS2()==Standard_True) && (VTXi.IsOnDomS1()==Standard_False)) { |
175 | for(j=1; (j<=nbvtx) && (APointDeleted==Standard_False) ;j++) { |
176 | if(i!=j) { |
177 | const IntPatch_Point& VTXj = svtx.Value(j); |
178 | if((VTXj.IsOnDomS2()==Standard_True) && (VTXj.IsOnDomS1()==Standard_False)) { |
179 | if(VTXi.ParameterOnLine() == VTXj.ParameterOnLine()) { |
180 | if(VTXi.ArcOnS2() == VTXj.ArcOnS2()) { |
181 | if(VTXi.ParameterOnArc2() == VTXj.ParameterOnArc2()) { |
182 | svtx.Remove(j); |
183 | nbvtx--; |
184 | if(lapt) { if(indl>=j) indl--; } |
185 | if(fipt) { if(indf>=j) indf--; } |
186 | APointDeleted = Standard_True; |
187 | } |
188 | } |
189 | } |
190 | } |
191 | } |
192 | } |
193 | } |
194 | } |
195 | } |
196 | while(APointDeleted == Standard_True); |
197 | |
198 | nbvtx = NbVertex(); |
199 | |
200 | //---------------------------------------------------- |
201 | //-- On trie les Vertex |
202 | Standard_Boolean SortIsOK; |
203 | do { |
204 | SortIsOK = Standard_True; |
205 | for(i=2; i<=nbvtx; i++) { |
206 | if(svtx.Value(i-1).ParameterOnLine() > svtx.Value(i).ParameterOnLine()) { |
207 | SortIsOK = Standard_False; |
208 | svtx.Exchange(i-1,i); |
209 | } |
210 | } |
211 | } |
212 | while(!SortIsOK); |
213 | |
214 | do { |
215 | APointDeleted = Standard_False; |
216 | Standard_Boolean restrdiff; |
217 | for(i=1; i<=nbvtx && (APointDeleted == Standard_False); i++) { |
218 | const IntPatch_Point& VTX = svtx.Value(i); |
219 | for(j=1; j<=nbvtx && (APointDeleted == Standard_False) ; j++) { |
220 | if(i!=j) { |
221 | const IntPatch_Point& VTXM1 = svtx.Value(j); |
222 | |
223 | Standard_Boolean kill = Standard_False; |
224 | Standard_Boolean killm1 = Standard_False; |
225 | |
226 | if(VTXM1.ParameterOnLine() == VTX.ParameterOnLine()) { |
227 | restrdiff=Standard_False; |
228 | if(VTXM1.IsOnDomS1() && VTX.IsOnDomS1()) { //-- OnS1 OnS1 |
229 | if(VTXM1.ArcOnS1() == VTX.ArcOnS1()) { //-- OnS1 == OnS1 |
230 | if(VTX.ParameterOnArc1() == VTXM1.ParameterOnArc1()) { |
231 | if(VTXM1.IsOnDomS2()) { //-- OnS1 == OnS1 OnS2 |
232 | if(VTX.IsOnDomS2()==Standard_False) { //-- OnS1 == OnS1 OnS2 PasOnS2 |
233 | kill=Standard_True; |
234 | } |
235 | else { |
236 | if(VTXM1.ArcOnS2() == VTX.ArcOnS2()) { //-- OnS1 == OnS1 OnS2 == OnS2 |
237 | if(VTX.ParameterOnArc2() == VTXM1.ParameterOnArc2()) { |
238 | kill=Standard_True; |
239 | } |
240 | } |
241 | } |
242 | } |
243 | else { //-- OnS1 == OnS1 PasOnS2 |
244 | if(VTX.IsOnDomS2()) { //-- OnS1 == OnS1 PasOnS2 OnS2 |
245 | killm1=Standard_True; |
246 | } |
247 | } |
248 | } |
249 | } |
250 | else { |
251 | restrdiff=Standard_True; |
252 | } |
253 | } |
254 | |
255 | if((restrdiff==Standard_False) && (!(kill || killm1))) { |
256 | if(VTXM1.IsOnDomS2() && VTX.IsOnDomS2()) { //-- OnS2 OnS2 |
257 | if(VTXM1.ArcOnS2() == VTX.ArcOnS2()) { //-- OnS2 == OnS2 |
258 | if(VTX.ParameterOnArc2() == VTXM1.ParameterOnArc2()) { |
259 | if(VTXM1.IsOnDomS1()) { //-- OnS2 == OnS2 OnS1 |
260 | if(VTX.IsOnDomS1()==Standard_False) { //-- OnS2 == OnS2 OnS1 PasOnS1 |
261 | kill=Standard_True; |
262 | } |
263 | else { |
264 | if(VTXM1.ArcOnS1() == VTX.ArcOnS1()) { //-- OnS2 == OnS2 OnS1 == OnS1 |
265 | if(VTX.ParameterOnArc1() == VTXM1.ParameterOnArc1()) { |
266 | kill=Standard_True; |
267 | } |
268 | } |
269 | } |
270 | } |
271 | else { //-- OnS2 == OnS2 PasOnS1 |
272 | if(VTX.IsOnDomS1()) { //-- OnS2 == OnS2 PasOnS1 OnS1 |
273 | killm1=Standard_True; |
274 | } |
275 | } |
276 | } |
277 | } |
278 | else { |
279 | restrdiff=Standard_True; |
280 | } |
281 | } |
282 | } |
283 | if(restrdiff==Standard_False) { |
284 | if(kill) { |
285 | APointDeleted = Standard_True; |
286 | svtx.Remove(i); |
287 | nbvtx--; |
288 | } |
289 | else if(killm1) { |
290 | APointDeleted = Standard_True; |
291 | svtx.Remove(j); |
292 | nbvtx--; |
293 | } |
294 | } |
295 | } |
296 | } |
297 | } |
298 | } |
299 | } |
300 | while(APointDeleted == Standard_True); |
301 | |
302 | do { |
303 | SortIsOK = Standard_True; |
304 | for(i=2; i<=nbvtx && SortIsOK; i++) { |
305 | const IntPatch_Point& Pim1=svtx.Value(i-1); |
306 | const IntPatch_Point& Pii =svtx.Value(i); |
307 | if(Pim1.ParameterOnLine()==Pii.ParameterOnLine()) { |
308 | if( (Pii.IsOnDomS1() == Standard_False) |
309 | && (Pii.IsOnDomS2() == Standard_False)) { |
310 | SortIsOK = Standard_False; |
311 | svtx.Remove(i); |
312 | nbvtx--; |
313 | } |
314 | else { |
315 | if( (Pim1.IsOnDomS1() == Standard_False) |
316 | && (Pim1.IsOnDomS2() == Standard_False)) { |
317 | SortIsOK = Standard_False; |
318 | svtx.Remove(i-1); |
319 | nbvtx--; |
320 | } |
321 | } |
322 | } |
323 | } |
324 | } |
325 | while(!SortIsOK); |
326 | |
327 | //---------------------------------------------------- |
328 | //-- On trie les Vertex ( Cas Bizarre ) |
329 | nbvtx = NbVertex(); |
330 | do { |
331 | SortIsOK = Standard_True; |
332 | for(i=2; i<=nbvtx; i++) { |
333 | if(svtx.Value(i-1).ParameterOnLine() > svtx.Value(i).ParameterOnLine()) { |
334 | SortIsOK = Standard_False; |
335 | svtx.Exchange(i-1,i); |
336 | } |
337 | } |
338 | } |
339 | while(!SortIsOK); |
340 | |
341 | |
342 | SetFirstPoint(1); |
343 | SetLastPoint(nbvtx); |
344 | |
345 | |
346 | #if 0 |
347 | Standard_Boolean SortIsOK; |
348 | Standard_Integer nbvtx = NbVertex(); |
349 | do { |
350 | SortIsOK = Standard_True; |
351 | for(Standard_Integer i=2; i<=nbvtx; i++) { |
352 | if(svtx.Value(i-1).ParameterOnLine() > svtx.Value(i).ParameterOnLine()) { |
353 | SortIsOK = Standard_False; |
354 | svtx.Exchange(i,i-1); |
355 | if(fipt) { |
356 | if(indf == i) indf = i-1; |
357 | else if(indf == (i-1)) indf = i; |
358 | } |
359 | if(lapt) { |
360 | if(indl == i) indl = i-1; |
361 | else if(indl == (i-1)) indl = i; |
362 | } |
363 | } |
364 | } |
365 | } |
366 | while(!SortIsOK); |
367 | #endif |
368 | } |
369 | |
77dbd1f1 |
370 | void IntPatch_RLine::Dump(const Standard_Integer theMode) const |
371 | { |
04232180 |
372 | std::cout<<" ----------- D u m p I n t P a t c h _ R L i n e -(begin)------"<<std::endl; |
77dbd1f1 |
373 | const Standard_Integer aNbPoints = NbPnts(); |
374 | const Standard_Integer aNbVertex = NbVertex(); |
7fd59977 |
375 | |
77dbd1f1 |
376 | switch(theMode) |
377 | { |
378 | case 0: |
379 | printf("Num [X Y Z] [U1 V1] [U2 V2]\n"); |
380 | for(Standard_Integer i=1; i<=aNbPoints; i++) |
381 | { |
382 | Standard_Real u1,v1,u2,v2; |
383 | Point(i).Parameters(u1,v1,u2,v2); |
384 | printf("%4d [%+10.20f %+10.20f %+10.20f] [%+10.20f %+10.20f] [%+10.20f %+10.20f]\n", |
385 | i,Point(i).Value().X(),Point(i).Value().Y(),Point(i).Value().Z(), |
386 | u1,v1,u2,v2); |
387 | } |
388 | |
389 | for(Standard_Integer i=1;i<=aNbVertex;i++) |
390 | { |
391 | Vertex(i).Dump(); |
392 | Standard_Real polr = Vertex(i).ParameterOnLine(); |
393 | Standard_Integer pol = static_cast<Standard_Integer>(polr); |
394 | |
395 | if(pol>=1 && pol<=aNbVertex) |
396 | { |
04232180 |
397 | std::cout<<"----> IntSurf_PntOn2S : "<< |
77dbd1f1 |
398 | polr <<", Pnt (" << Vertex(pol).Value().X() << "," << |
399 | Vertex(pol).Value().Y() << "," << |
04232180 |
400 | Vertex(pol).Value().Z() <<")" <<std::endl; |
77dbd1f1 |
401 | } |
402 | } |
403 | |
404 | break; |
405 | case 1: |
406 | for(Standard_Integer i = 1; i <= aNbPoints; i++) |
407 | { |
408 | Standard_Real u1,v1,u2,v2; |
409 | Point(i).Parameters(u1,v1,u2,v2); |
410 | printf("point p%d %+10.20f %+10.20f %+10.20f\n", |
411 | i,Point(i).Value().X(),Point(i).Value().Y(),Point(i).Value().Z()); |
412 | } |
7fd59977 |
413 | |
77dbd1f1 |
414 | break; |
415 | case 2: |
416 | for(Standard_Integer i = 1; i <= aNbPoints; i++) |
417 | { |
418 | Standard_Real u1,v1,u2,v2; |
419 | Point(i).Parameters(u1,v1,u2,v2); |
420 | printf("point p%d %+10.20f %+10.20f\n", i, u1, v1); |
421 | } |
422 | |
423 | break; |
424 | default: |
425 | for(Standard_Integer i = 1; i <= aNbPoints; i++) |
426 | { |
427 | Standard_Real u1,v1,u2,v2; |
428 | Point(i).Parameters(u1,v1,u2,v2); |
429 | printf("point p%d %+10.20f %+10.20f\n", i, u2, v2); |
430 | } |
431 | |
432 | break; |
433 | } |
04232180 |
434 | std::cout<<"\n--------------------------------------------------- (end) -------"<<std::endl; |
77dbd1f1 |
435 | } |
7fd59977 |
436 | |