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