7fd59977 |
1 | // File: MAT_Mat.gxx |
2 | // Created: Tue Sep 22 17:54:07 1992 |
3 | // Author: Gilles DEBARBOUILLE |
4 | // <gde@bravox> |
5 | |
6 | |
7 | #include <MAT_Edge.hxx> |
8 | #include <MAT_ListOfEdge.hxx> |
9 | #include <MAT_Bisector.hxx> |
10 | #include <MAT_ListOfBisector.hxx> |
11 | #include <TColStd_DataMapOfIntegerInteger.hxx> |
12 | #include <TColStd_Array1OfInteger.hxx> |
13 | #include <MAT_DataMapOfIntegerBisector.hxx> |
14 | #include <Precision.hxx> |
15 | |
16 | //======================================================================== |
17 | // function : MAT_Mat |
18 | // purpose : |
19 | //======================================================================== |
20 | |
21 | MAT_Mat::MAT_Mat() |
22 | { |
23 | thenumberofbisectors = 0; |
24 | thenumberofedges = 0; |
25 | } |
26 | |
27 | |
28 | //======================================================================== |
29 | // function : CreateMat |
30 | // purpose : Calcul des lieux Bisecteurs. |
31 | // |
32 | // Structure de la carte. |
33 | // ====================== |
34 | // La carte des lieux bisecteurs se presente sous la forme d un ou plusieurs |
35 | // arbres de bisectrices. |
36 | // ( un arbre, si calcul a l interieur du contour, plusieurs sinon). |
37 | // |
38 | // Les branches de plus bas niveau de l arbre separent deux elements voisins |
39 | // du contour. |
40 | // |
41 | // Principe de l algorithme. |
42 | // ------------------------- |
43 | // l arbre est construit des branches les plus basses vers les plus hautes. |
44 | // |
45 | // 0 . Calcul des bisectrices entre elements voisins du contour. |
46 | // 1 . Elimination de certains element du contour => nouveau contour |
47 | // 2 . Retour en 0. |
48 | // |
49 | // Principales etapes de l algorithme. |
50 | // =================================== |
51 | // |
52 | // etape 1: Initialisation de l algorithme . |
53 | // ----------------------------------------- |
54 | // Recuperation via le tool du nombre d'elements sur le contour |
55 | // Initialisation de <theedgelist>, un edge correspond a chaque |
56 | // element du contour. |
57 | // |
58 | // etape 2 : Boucle principale. |
59 | // ---------------------------- |
60 | // 0 - Tant que Nombre d'edge > 1 |
61 | // |
62 | // 1. Pour chaque edge: construction de la bissectrice entre l edge |
63 | // et l edge suivante. |
64 | // La bissectrice est semi_infinie, elle est soit trimmee par le |
65 | // point commun des deux edges, soit par l intersection de deux |
66 | // bissectrices antecedentes. |
67 | // |
68 | // 2. Intersection des Bisectrices issue du meme edge |
69 | // => une bisectrice est intersectee avec sa voisine a gauche |
70 | // et sa voisine a droite. |
71 | // |
72 | // 3. Analyse des intersections. |
73 | // Si pas d'intersection entre deux bisectrices B1 et B2 |
74 | // - Recherche de l intersection la plus basse de B1 avec les |
75 | // Bisectrices antecedentes a B2 du cote de B1. Soit Bi la |
76 | // bissectrice intersectee. Toutes les bissectrices constituant la |
77 | // branche qui relie B2 a Bi sont marquees a effacer |
78 | // - idem pour B2. |
79 | // |
80 | // 4. Suppresion des bisectrices a effacer. |
81 | // une bisectrise est a effacer : |
82 | // - Anulation de l intersection dont la bissectrice est issue |
83 | // => Prolongement des deux bisectrices posterieures. |
84 | // - Reinsertion des edge correspondant dans <theedgelist>. |
85 | // |
86 | // 5. Pour chaque edge, analyse des distances entre les points d inter |
87 | // section et l edge. |
88 | // B1 B2 les bisectrices liee a l edge |
89 | // Soit P0 le point d intersection des bissectrices . |
90 | // Soit P1 le point d intersection de B1 avec son autre voisine . |
91 | // Soit P2 le point d intersection de B2 avec son autre voisine . |
92 | // |
93 | // si sur B1 le parametre de P0 < parametre de P1 et |
94 | // si sur B2 le parametre de P0 < parametre de P2 |
95 | // alors suppression de l edge de la liste des edges <theedgelist>. |
96 | // |
97 | // rq: le parametre sur une bissectirce est croissant par rapport |
98 | // a la distance du point courant aux edges. |
99 | |
100 | // 6. Si aucune edge est elimine alors sortie de la boucle principale. |
101 | // |
102 | // 7. Retour en 0. |
103 | // |
104 | // etape 3 : Creation des racines des arbres de bisectrices. |
105 | // --------------------------------------------------------- |
106 | // Recuperation des bissectrices calculees lors du dernier passage |
107 | // dans la boucle. |
108 | // |
109 | //======================================================================== |
110 | void MAT_Mat::CreateMat(Tool& atool) |
111 | { |
112 | |
113 | #ifdef ICONTINUE |
114 | Standard_Boolean Icontinue; |
115 | #endif |
116 | |
117 | Standard_Boolean interrupt = Standard_False; |
118 | |
119 | Handle(MAT_Edge) edgetoremove; |
120 | Handle(MAT_Edge) previousedge,currentedge; |
121 | |
122 | Standard_Integer noofbisectorstoremove; |
123 | Handle(MAT_Bisector) firstbisector,secondbisector; |
124 | Handle(MAT_Edge) edge; |
125 | Standard_Integer intersectionpoint; |
126 | Standard_Integer beginbisector; |
127 | Standard_Integer noofbisectors; |
128 | |
129 | Standard_Integer NbIterBis = 0; |
130 | Standard_Integer EvenNbIterBis = 10; |
131 | Standard_Integer aControlSum = 0; |
132 | TColStd_Array1OfInteger ControlSums(1, EvenNbIterBis+1); |
133 | Standard_Integer PrevEdgeNumber; |
134 | Standard_Boolean ToNullifyNoofbisectorstoremove = Standard_False; |
135 | |
136 | Handle(MAT_ListOfBisector) currentbisectorlist; |
137 | |
138 | Handle(MAT_Bisector) bisectortoremove,lastbisector,currentbisector; |
139 | Handle(MAT_Bisector) previousbisector; |
140 | |
141 | Standard_Integer i,j,k,narea,shift,compact,all; |
142 | Standard_Integer noofedges; |
143 | Standard_Integer NumberMaxOfIte; |
144 | Standard_Real toleranceofconfusion; |
145 | |
146 | noofedges = atool.NumberOfItems(); |
147 | toleranceofconfusion = atool.ToleranceOfConfusion(); |
148 | NumberMaxOfIte = noofedges*noofedges; |
149 | |
150 | Standard_Integer* firstarea = new Standard_Integer[noofedges]; |
151 | Standard_Integer* lastarea = new Standard_Integer[noofedges]; |
152 | Standard_Integer* noofarea = new Standard_Integer[noofedges]; |
153 | |
154 | if (noofarea == 0) { |
155 | cout <<" Erreur d allocation "<<endl; |
156 | return; |
157 | } |
158 | |
159 | Standard_Integer parama[2]; |
160 | Standard_Integer paramb[2]; |
161 | |
162 | // ----------------------------------------- |
163 | // Initialisation et remise a zero des maps. |
164 | // ----------------------------------------- |
165 | bisectoronetoremove.Clear(); |
166 | bisectortwotoremove.Clear(); |
167 | typeofbisectortoremove.Clear(); |
168 | bisectormap.Clear(); |
169 | |
170 | isDone = Standard_True; |
171 | noofbisectors = noofedges; |
172 | beginbisector = 0; |
173 | |
174 | // -------------------------------------------------------------------- |
175 | // Construction de <theedgelist> un edge correspond a un element simple |
176 | // du contour. |
177 | // -------------------------------------------------------------------- |
178 | theedgelist = new MAT_ListOfEdge(); |
179 | |
180 | for(i=0; i<noofedges; i++) { |
181 | edge = new MAT_Edge(); |
182 | edge->EdgeNumber(i+1); |
183 | edge->Distance(-1); |
184 | theedgelist->BackAdd(edge); |
185 | } |
186 | |
187 | theedgelist->Loop(); |
188 | |
189 | //--------------------------------------------------- |
190 | // Initialisation des bissectrices issues du contour. |
191 | //--------------------------------------------------- |
192 | Standard_Real Dist; |
193 | theedgelist->First(); |
194 | |
195 | for(i=0; i<theedgelist->Number(); i++) { |
196 | bisectormap.Bind(i,new MAT_Bisector()); |
197 | bisectormap(i)->IndexNumber(i); |
198 | bisectormap(i)->FirstEdge(theedgelist->Current()); |
199 | bisectormap(i)->FirstVector |
200 | (atool.TangentBefore(theedgelist->Current()->EdgeNumber())); |
201 | theedgelist->Next(); |
202 | bisectormap(i)->SecondEdge(theedgelist->Current()); |
203 | bisectormap(i)->IssuePoint |
204 | (atool.FirstPoint(theedgelist->Current()->EdgeNumber(),Dist)); |
205 | bisectormap(i)->DistIssuePoint(Dist); |
206 | bisectormap(i)->SecondVector |
207 | (atool.TangentAfter(theedgelist->Current()->EdgeNumber())); |
208 | } |
209 | |
210 | //---------------------------------------------------- |
211 | // Affectation a chaque edge de ses deux bissectrices. |
212 | //---------------------------------------------------- |
213 | theedgelist->First(); |
214 | |
215 | for(i=0; i<theedgelist->Number(); i++) { |
216 | theedgelist->Current()->FirstBisector |
217 | (bisectormap((i-1+noofbisectors)%noofbisectors)); |
218 | theedgelist->Current()->SecondBisector |
219 | (bisectormap(i)); |
220 | theedgelist->Next(); |
221 | } |
222 | |
223 | //=========================================================================== |
224 | // Boucle Principale (etape 2) |
225 | //=========================================================================== |
226 | Standard_Integer NumberOfIte = 0; |
227 | |
228 | PrevEdgeNumber = theedgelist->Number(); |
229 | |
230 | while(theedgelist->Number()>1) { |
231 | |
232 | |
233 | // ------------------------------------------------------------------ |
234 | // Creation des geometries des bissectrices via le tool. (etape 2.1) |
235 | // ------------------------------------------------------------------- |
236 | |
237 | for(i=beginbisector; i<noofbisectors; i++) { |
238 | |
239 | atool.CreateBisector(bisectormap(i)); |
240 | thenumberofbisectors++; |
241 | |
242 | #ifdef DEBUG_Mat |
243 | atool.Dump(bisectormap(i)->BisectorNumber(),1); |
244 | #ifdef ICONTINUE |
245 | cin>>Icontinue; |
246 | #endif |
247 | #endif |
248 | } |
249 | |
250 | // --------------------------------------------- |
251 | // Condition de sortie de la boucle principale. |
252 | // --------------------------------------------- |
253 | |
254 | // Modified by Sergey KHROMOV - Fri Nov 17 10:28:28 2000 Begin |
255 | if (theedgelist->Number() < 3) |
256 | break; |
257 | // Modified by Sergey KHROMOV - Fri Nov 17 10:28:37 2000 End |
258 | |
259 | //--------------------------------------------------- |
260 | // boucle 2 Tant qu il y a des bisectrices a effacer. |
261 | //--------------------------------------------------- |
262 | while(Standard_True) { |
263 | NbIterBis++; |
264 | |
265 | noofbisectorstoremove = 0; |
266 | theedgelist->First(); |
267 | |
268 | //-------------------------------------------------------------- |
269 | // Calcul des intersections des bisectrices voisines.(etape 2.2) |
270 | //-------------------------------------------------------------- |
271 | |
272 | aControlSum += theedgelist->Number() - PrevEdgeNumber; |
273 | if (NbIterBis <= EvenNbIterBis+1) |
274 | ControlSums(NbIterBis) = aControlSum; |
275 | else |
276 | { |
277 | for (k = 1; k <= EvenNbIterBis; k++) |
278 | ControlSums(k) = ControlSums(k+1); |
279 | ControlSums(EvenNbIterBis+1) = aControlSum; |
280 | } |
281 | if (ControlSums(EvenNbIterBis+1) == ControlSums(1)) |
282 | ToNullifyNoofbisectorstoremove = Standard_True; |
283 | |
284 | for(i=0; i<theedgelist->Number(); i++) { |
285 | edge = theedgelist->Current(); |
286 | if(edge->Distance() == -1.) { |
287 | firstbisector = edge->FirstBisector(); |
288 | secondbisector = edge->SecondBisector(); |
289 | edge->Distance(atool.IntersectBisector |
290 | (firstbisector,secondbisector,intersectionpoint)); |
291 | edge->IntersectionPoint(intersectionpoint); |
292 | |
293 | if(edge->Distance() == Precision::Infinite()) { |
294 | if(firstbisector->IndexNumber() >= beginbisector || |
295 | secondbisector->IndexNumber() >= beginbisector) |
296 | Intersect(atool,0,noofbisectorstoremove, |
297 | firstbisector,secondbisector ); |
298 | } |
299 | else { |
300 | if(firstbisector->IndexNumber() >= beginbisector) { |
301 | Intersect(atool,1,noofbisectorstoremove, |
302 | firstbisector,secondbisector ); |
303 | } |
304 | if(secondbisector->IndexNumber() >= beginbisector) { |
305 | Intersect(atool,2,noofbisectorstoremove, |
306 | firstbisector,secondbisector ); |
307 | } |
308 | } |
309 | } |
310 | theedgelist->Next(); |
311 | } |
312 | |
313 | //------------------------------- |
314 | // Test de sortie de la boucle 2. |
315 | //------------------------------- |
316 | |
317 | PrevEdgeNumber = theedgelist->Number(); |
318 | if (ToNullifyNoofbisectorstoremove) |
319 | noofbisectorstoremove = 0; |
320 | if(noofbisectorstoremove == 0) break; |
321 | |
322 | //--------------------------------------------------- |
323 | // Annulation des bissectrices a effacer. (etape 2.4) |
324 | //--------------------------------------------------- |
325 | |
326 | for(i=0; i<noofbisectorstoremove; i++) { |
327 | |
328 | bisectortoremove = bisectoronetoremove(i); |
329 | |
330 | //--------------------------------------------------------------- |
331 | // Destruction des bisectrices descendantes de <bisectortoremove> |
332 | // On descend dans l arbre jusqu a ce qu on atteigne |
333 | // <bisectortwotoremove(i). |
334 | //--------------------------------------------------------------- |
335 | |
336 | while(Standard_True){ |
337 | |
338 | #ifdef DEBUG_Mat |
339 | atool.Dump(bisectortoremove->BisectorNumber(),0); |
340 | #endif |
341 | // ---------------------------------- |
342 | // Annulation de <bisectortoremove>. |
343 | // ---------------------------------- |
344 | thenumberofbisectors--; |
345 | currentbisectorlist = bisectortoremove->List(); |
346 | currentbisectorlist->First(); |
347 | currentbisector = currentbisectorlist->FirstItem(); |
348 | previousedge = currentbisector->FirstEdge(); |
349 | theedgelist->Init(previousedge); |
350 | previousedge->Distance(-1.); |
351 | previousedge->FirstBisector()->SecondParameter(Precision::Infinite()); |
352 | previousedge->SecondBisector()->FirstParameter(Precision::Infinite()); |
353 | |
354 | //------------------------------------------ |
355 | // Annulation des fils de <currentbisector>. |
356 | //------------------------------------------ |
357 | |
358 | while(currentbisectorlist->More()) { |
359 | currentbisector = currentbisectorlist->Current(); |
360 | currentedge = currentbisector->SecondEdge(); |
361 | |
362 | //--------------------------------------- |
363 | // Reinsertion de l edge dans le contour. |
364 | //--------------------------------------- |
365 | theedgelist->LinkAfter(currentedge); |
366 | theedgelist->Next(); |
367 | |
368 | currentedge->FirstBisector(currentbisector); |
369 | previousedge->SecondBisector(currentbisector); |
370 | #ifdef DEBUG_Mat |
371 | atool.Dump(currentbisector->BisectorNumber(),0); |
372 | #endif |
373 | |
374 | //------------------------------------------------------ |
375 | // Annulation de l intersection ie les fils qui |
376 | // ont generes l intersection sont prolonges a l infini. |
377 | //------------------------------------------------------ |
378 | |
379 | currentbisector->FirstParameter (Precision::Infinite()); |
380 | currentbisector->SecondParameter(Precision::Infinite()); |
381 | |
382 | atool.TrimBisector(currentbisector); |
383 | |
384 | #ifdef DEBUG_Mat |
385 | atool.Dump(currentbisector->BisectorNumber(),1); |
386 | #endif |
387 | currentedge->Distance(-1.); |
388 | currentedge->FirstBisector()->SecondParameter(Precision::Infinite()); |
389 | currentedge->SecondBisector()->FirstParameter(Precision::Infinite()); |
390 | |
391 | previousedge = currentedge; |
392 | currentbisectorlist->Next(); |
393 | } |
394 | |
395 | theedgelist->Unlink(); |
396 | |
397 | //----------------------------------------------------------- |
398 | // Test de sortie de la boucle d annulation des bissectrices. |
399 | //----------------------------------------------------------- |
400 | |
401 | if(bisectortoremove->BisectorNumber() == |
402 | bisectortwotoremove(i)->BisectorNumber()) break; |
403 | |
404 | //----------------------- |
405 | // Descente dans l arbre. |
406 | //----------------------- |
407 | |
408 | if(typeofbisectortoremove(i) == 1) |
409 | bisectortoremove = bisectortoremove->FirstBisector(); |
410 | else |
411 | bisectortoremove = bisectortoremove->LastBisector(); |
412 | |
413 | } //---------------------------------------------------- |
414 | // Fin boucle d annulation des bissectrices issue de |
415 | // <bisectoronetoremove(i)>. |
416 | //---------------------------------------------------- |
417 | |
418 | } //------------------------------------------ |
419 | // Fin boucle d annulation des bissectrices. |
420 | //------------------------------------------- |
421 | |
422 | #ifdef ICONTINUE |
423 | cin>>Icontinue; |
424 | #endif |
425 | } //-------------- |
426 | // Fin Boucle 2. |
427 | //-------------- |
428 | |
429 | // ---------------------------------------------------------------------- |
430 | // Analyse des parametres des intersections sur les bisectrices de chaque |
431 | // edge et determination des portions de contour a supprimees. (etape 2.5) |
432 | // ---------------------------------------------------------------------- |
433 | |
434 | theedgelist->First(); |
435 | |
436 | currentbisector = theedgelist->Current()->FirstBisector(); |
437 | if (currentbisector->FirstParameter() == Precision::Infinite() && |
438 | currentbisector->SecondParameter() == Precision::Infinite()) { |
439 | parama[0] = -1; |
440 | paramb[0] = -1; |
441 | } |
442 | else if(currentbisector->FirstParameter() == Precision::Infinite()) { |
443 | parama[0] = -1; |
444 | paramb[0] = 1; |
445 | } |
446 | else if(currentbisector->SecondParameter() == Precision::Infinite()) { |
447 | paramb[0] = -1; |
448 | parama[0] = 1; |
449 | } |
450 | else if (atool.Distance(currentbisector, |
451 | currentbisector->FirstParameter(), |
452 | currentbisector->SecondParameter()) |
453 | > toleranceofconfusion) { |
454 | if((currentbisector->FirstParameter() - |
455 | currentbisector->SecondParameter()) |
456 | *currentbisector->Sense() > 0.) { |
457 | parama[0] = -1; |
458 | paramb[0] = 1; |
459 | } |
460 | else { |
461 | paramb[0] = -1; |
462 | parama[0] = 1; |
463 | } |
464 | } |
465 | else { |
466 | parama[0] = 1; |
467 | paramb[0] = 1; |
468 | } |
469 | |
470 | narea = -1; |
471 | |
472 | for(i=0; i<theedgelist->Number(); i++) { |
473 | currentbisector = theedgelist->Current()->SecondBisector(); |
474 | if (currentbisector->FirstParameter() == Precision::Infinite() && |
475 | currentbisector->SecondParameter() == Precision::Infinite()) { |
476 | parama[1] = -1; |
477 | paramb[1] = -1; |
478 | } |
479 | else if(currentbisector->FirstParameter() == Precision::Infinite()) { |
480 | parama[1] = -1; |
481 | paramb[1] = 1; |
482 | } |
483 | else if(currentbisector->SecondParameter() == Precision::Infinite()) { |
484 | paramb[1] = -1; |
485 | parama[1] = 1; |
486 | } |
487 | else if (atool.Distance(currentbisector, |
488 | currentbisector->FirstParameter(), |
489 | currentbisector->SecondParameter()) |
490 | > toleranceofconfusion) { |
491 | if((currentbisector->FirstParameter() - |
492 | currentbisector->SecondParameter()) |
493 | *currentbisector->Sense() > 0.) { |
494 | parama[1] = -1; |
495 | paramb[1] = 1; |
496 | } |
497 | else { |
498 | paramb[1] = -1; |
499 | parama[1] = 1; |
500 | } |
501 | } |
502 | else { |
503 | parama[1] = 1; |
504 | paramb[1] = 1; |
505 | } |
506 | |
507 | //----------------------------------------------------------------- |
508 | // Test si l edge est a enlever du contour |
509 | // Construction des portions de contour a eliminer. |
510 | // |
511 | // narea : nombre de portions continues du contour a eliminer. |
512 | // firstarea[i] : indice premier edge de la portion i. |
513 | // lastarea[i] : indice dernier edge de la portion i. |
514 | //----------------------------------------------------------------- |
515 | |
516 | #ifdef DEBUG_Mat |
517 | cout <<" Test sur les parametres pour elimination"<<endl; |
518 | cout << " Edge number :"<<theedgelist->Current()->EdgeNumber()<<endl; |
519 | #endif |
520 | |
521 | if(paramb[0] > 0 && parama[1] > 0) { |
522 | |
523 | #ifdef DEBUG_Mat |
524 | cout <<" A ELIMINER "<<endl; |
525 | #endif |
526 | if(narea < 0) { |
527 | firstarea[++narea] = theedgelist->Index(); |
528 | lastarea[narea] = firstarea[narea]; |
529 | noofarea[narea] = 1; |
530 | } |
531 | else { |
532 | if(theedgelist->Index() == lastarea[narea]+1) { |
533 | lastarea[narea]++; |
534 | noofarea[narea]++; |
535 | } |
536 | else { |
537 | firstarea[++narea] = theedgelist->Index(); |
538 | lastarea[narea] = firstarea[narea]; |
539 | noofarea[narea] = 1; |
540 | } |
541 | } |
542 | } |
543 | parama[0] = parama[1]; |
544 | paramb[0] = paramb[1]; |
545 | theedgelist->Next(); |
546 | |
547 | } |
548 | |
549 | compact = 0; |
550 | if(narea > 0) { |
551 | if(lastarea[narea] == theedgelist->Number() && firstarea[0] == 1) { |
552 | firstarea[0] = firstarea[narea]; |
553 | noofarea[0] = noofarea[0]+noofarea[narea]; |
554 | compact = noofarea[narea]; |
555 | narea--; |
556 | } |
557 | } |
558 | |
559 | narea++; |
560 | |
561 | //------------------------------------------------------------------ |
562 | // Sortie de la boucle principale si il n y a pas d edge a eliminer. |
563 | // (etape 2.6) |
564 | //------------------------------------------------------------------ |
565 | if(narea == 0) { |
566 | interrupt = Standard_True; |
567 | break; |
568 | } |
569 | |
570 | |
571 | //---------------------------------------------------------------- |
572 | // Elimination des edges a enlever du contour |
573 | // => Mise a jour du nouveau contour. |
574 | // => Creation des bissectrices entre les nouvelles edges voisines. |
575 | //---------------------------------------------------------------- |
576 | |
577 | beginbisector = noofbisectors; |
578 | shift = 0; |
579 | all = 0; |
580 | if(narea == 1 && noofarea[0] == theedgelist->Number()) all = 1; |
581 | |
582 | for(i=0; i<narea; i++) { |
583 | if(i == 1)shift = shift-compact; |
584 | theedgelist->First(); |
585 | edgetoremove = theedgelist->Brackets(firstarea[i]-shift); |
586 | |
587 | edgetoremove->FirstBisector()->EndPoint(edgetoremove |
588 | ->IntersectionPoint()); |
589 | |
590 | #ifdef DEBUG_Mat |
591 | atool.Dump(edgetoremove->FirstBisector()->BisectorNumber(),0); |
592 | #endif |
593 | |
594 | edgetoremove->FirstBisector()->FirstParameter |
595 | (edgetoremove->FirstBisector()->SecondParameter()); |
596 | |
597 | #ifdef DEBUG_Mat |
598 | if(atool.TrimBisector(edgetoremove->FirstBisector())) |
599 | atool.Dump(edgetoremove->FirstBisector()->BisectorNumber(),1); |
600 | #else |
601 | atool.TrimBisector(edgetoremove->FirstBisector()); |
602 | #endif |
603 | |
604 | bisectormap.Bind(noofbisectors,new MAT_Bisector()); |
605 | bisectormap(noofbisectors)->IndexNumber(noofbisectors); |
606 | bisectormap(noofbisectors)->DistIssuePoint(edgetoremove->Distance()); |
607 | bisectormap(noofbisectors)->IssuePoint(edgetoremove |
608 | ->IntersectionPoint()); |
609 | bisectormap(noofbisectors)->FirstEdge(theedgelist->PreviousItem()); |
610 | bisectormap(noofbisectors)->AddBisector(edgetoremove |
611 | ->FirstBisector()); |
612 | |
613 | for(j=0; j<noofarea[i]; j++) { |
614 | theedgelist->Unlink(); |
615 | theedgelist->Next(); |
616 | shift++; |
617 | |
618 | #ifdef DEBUG_Mat |
619 | cout<<" Suppression de l'arete : "<<edgetoremove->EdgeNumber()<<endl; |
620 | #endif |
621 | |
622 | if(all == 0 || j+1 != noofarea[i]) { |
623 | bisectormap(noofbisectors)->AddBisector(edgetoremove |
624 | ->SecondBisector()); |
625 | } |
626 | edgetoremove->SecondBisector()->EndPoint(edgetoremove |
627 | ->IntersectionPoint()); |
628 | |
629 | #ifdef DEBUG_Mat |
630 | atool.Dump(edgetoremove->SecondBisector()->BisectorNumber(),0); |
631 | #endif |
632 | |
633 | edgetoremove->SecondBisector()->SecondParameter |
634 | (edgetoremove->SecondBisector()->FirstParameter()); |
635 | #ifdef DEBUG_Mat |
636 | if(atool.TrimBisector(edgetoremove->SecondBisector())) |
637 | atool.Dump(edgetoremove->SecondBisector()->BisectorNumber(),1); |
638 | #else |
639 | atool.TrimBisector(edgetoremove->SecondBisector()); |
640 | #endif |
641 | edgetoremove = theedgelist->Current(); |
642 | } |
643 | bisectormap(noofbisectors)->SecondEdge(theedgelist->Current()); |
644 | |
645 | theedgelist->PreviousItem() |
646 | ->SecondBisector(bisectormap(noofbisectors)); |
647 | theedgelist->Current()->FirstBisector(bisectormap(noofbisectors)); |
648 | |
649 | bisectormap(noofbisectors)->FirstVector |
650 | (atool.Tangent |
651 | (bisectormap(noofbisectors)->FirstBisector() |
652 | ->BisectorNumber())); |
653 | |
654 | bisectormap(noofbisectors)->SecondVector |
655 | (atool.Tangent |
656 | (bisectormap(noofbisectors)->LastBisector() |
657 | ->BisectorNumber())); |
658 | |
659 | noofbisectors++; |
660 | |
661 | theedgelist->PreviousItem()->Distance(-1); |
662 | theedgelist->Current()->Distance(-1); |
663 | |
664 | theedgelist->PreviousItem()->FirstBisector() |
665 | ->SecondParameter(Precision::Infinite()); |
666 | theedgelist->Current()->SecondBisector()->FirstParameter(Precision::Infinite()); |
667 | } |
668 | |
669 | //----------------------------------------------------------------------- |
670 | // Test sur le nombre d iterations : |
671 | // A chaque iteration est elimine un element du contour qui ne sera plus |
672 | // reinsere par la suite => le nombre d iterartions doit etre < au nombre |
673 | // d elements. |
674 | // Le nombre d iteration maximum est fixe a numberofedges*numberofedges. |
675 | //----------------------------------------------------------------------- |
676 | if (NumberOfIte > NumberMaxOfIte) { |
677 | isDone = Standard_False; //Echec calcul de la carte. |
678 | break; |
679 | } |
680 | NumberOfIte++; |
681 | |
682 | } //=============================================== |
683 | // Fin Boucle Principale. |
684 | //=============================================== |
685 | |
686 | //---------- |
687 | // etape 3. |
688 | //---------- |
689 | |
690 | |
691 | //---------------------------------------------- |
692 | // interupt = True => bissectrices semi_infinies. |
693 | //---------------------------------------------- |
694 | |
695 | if(interrupt) |
696 | semiInfinite = Standard_True; |
697 | else { |
698 | semiInfinite = Standard_False; |
699 | |
700 | //------------------------------------------------------------------ |
701 | // Si le nombre d edge > 1 => le nombre d edge = 2 |
702 | // (cf test sortie boucle principale) |
703 | // Les deux dernieres bisectrices separent les memes edges . |
704 | // Soit elles sont confondues si calcul a l interieur, soit elles |
705 | // sont semi-Infinies (exemple : contour compose seulement de deux |
706 | // arcs de cercles). |
707 | //------------------------------------------------------------------ |
708 | |
709 | if(theedgelist->Number() > 1) { //Now this branch is never reachable |
710 | //because the case edgenumber = 2 is processed in the main loop |
711 | theedgelist->First(); |
712 | edge = theedgelist->Current(); |
713 | if(edge->FirstBisector()->IndexNumber() == noofbisectors-1) { |
714 | // Modified by skv - Tue Sep 13 12:13:28 2005 IDEM Begin |
715 | if (atool.TrimBisector(edge->SecondBisector(), |
716 | edge->FirstBisector()->IssuePoint())) { |
717 | if (edge->SecondBisector()->EndPoint() == 0) |
718 | edge->SecondBisector()->EndPoint(edge->FirstBisector()->IssuePoint()); |
719 | bisectormap(noofbisectors-1)->AddBisector(edge->SecondBisector()); |
720 | } else |
721 | semiInfinite = Standard_True; |
722 | // Modified by skv - Tue Sep 13 12:13:28 2005 IDEM End |
723 | } |
724 | else { |
725 | // Modified by skv - Tue Sep 13 12:13:28 2005 IDEM Begin |
726 | if (atool.TrimBisector(edge->FirstBisector(), |
727 | edge->SecondBisector()->IssuePoint())) { |
728 | if (edge->FirstBisector()->EndPoint() == 0) |
729 | edge->FirstBisector()->EndPoint(edge->SecondBisector()->IssuePoint()); |
730 | bisectormap(noofbisectors-1)->AddBisector(edge->FirstBisector()); |
731 | } else |
732 | semiInfinite = Standard_True; |
733 | // Modified by skv - Tue Sep 13 12:13:28 2005 IDEM End |
734 | } |
735 | if (!semiInfinite) { |
736 | thenumberofbisectors--; |
737 | bisectormap(noofbisectors-1)->SecondEdge(edge); |
738 | bisectormap(noofbisectors-1)->BisectorNumber(-1); |
739 | } |
740 | } |
741 | } |
742 | if(semiInfinite) { |
743 | beginbisector = noofbisectors; |
744 | theedgelist->First(); |
745 | for(i=0; i<theedgelist->Number(); i++) { |
746 | edge = theedgelist->Current(); |
747 | bisectormap.Bind(noofbisectors,edge->SecondBisector()); |
748 | noofbisectors++; |
749 | theedgelist->Next(); |
750 | } |
751 | |
752 | } |
753 | |
754 | //--------------------------- |
755 | // Recuperations des racines. |
756 | //--------------------------- |
757 | |
758 | roots = new MAT_ListOfBisector; |
759 | |
760 | if (bisectormap(noofbisectors-1)->BisectorNumber() == -1) { |
761 | roots = bisectormap(noofbisectors-1)->List(); |
762 | roots->First(); |
763 | roots->Current()->FirstEdge() |
764 | ->Distance(bisectormap(noofbisectors-1)->DistIssuePoint()); |
765 | } |
766 | else { |
767 | for (i=beginbisector;i<noofbisectors;i++) { |
768 | roots->BackAdd(bisectormap(i)); |
769 | } |
770 | } |
771 | |
772 | //------------------------------------- |
773 | // Destruction des tableaux dynamiques. |
774 | //------------------------------------- |
775 | delete [] firstarea; |
776 | delete [] lastarea ; |
777 | delete [] noofarea ; |
778 | } |
779 | |
780 | //======================================================================== |
781 | // function : LoadBisectorsToRemove |
782 | // purpose : Chargement des bisectrices a effacer. |
783 | //======================================================================== |
784 | void MAT_Mat::LoadBisectorsToRemove |
785 | ( Standard_Integer& noofbisectorstoremove, |
786 | const Standard_Real distance1, |
787 | const Standard_Real distance2, |
788 | const Handle(MAT_Bisector)& firstbisectortoremove1, |
789 | const Handle(MAT_Bisector)& firstbisectortoremove2, |
790 | const Handle(MAT_Bisector)& lastbisectortoremove1, |
791 | const Handle(MAT_Bisector)& lastbisectortoremove2 ) |
792 | { |
793 | |
794 | Standard_Integer found,index; |
795 | Handle(MAT_Bisector) firstbisectortoremove[2]; |
796 | Handle(MAT_Bisector) lastbisectortoremove[2]; |
797 | |
798 | firstbisectortoremove[0] = firstbisectortoremove1; |
799 | firstbisectortoremove[1] = firstbisectortoremove2; |
800 | lastbisectortoremove[0] = lastbisectortoremove1; |
801 | lastbisectortoremove[1] = lastbisectortoremove2; |
802 | |
803 | if (distance1 < Precision::Infinite() && |
804 | distance2 == Precision::Infinite() ) index = 0; |
805 | else if(distance2 < Precision::Infinite() && |
806 | distance1 == Precision::Infinite() ) index = 1; |
807 | else index = -1; |
808 | |
809 | if(index != -1) { |
810 | found = noofbisectorstoremove; |
811 | for(int j=0; j<noofbisectorstoremove; j++) { |
812 | if(bisectoronetoremove(j)->BisectorNumber() == |
813 | firstbisectortoremove[index]->BisectorNumber()) { |
814 | found = j; |
815 | if(bisectortwotoremove(j)->BisectorNumber() < |
816 | lastbisectortoremove[index]->BisectorNumber())found = -1; |
817 | break; |
818 | } |
819 | } |
820 | |
821 | if(found != -1) { |
822 | #ifdef DEBUG_Mat |
823 | cout<<" first last bisector to remove :"<< |
824 | firstbisectortoremove[index]->BisectorNumber()<<" "<< |
825 | lastbisectortoremove[index]->BisectorNumber()<<endl; |
826 | #endif |
827 | bisectoronetoremove.Bind(found,firstbisectortoremove[index]); |
828 | bisectortwotoremove.Bind(found,lastbisectortoremove[index]); |
829 | typeofbisectortoremove.Bind(found,index+1); |
830 | |
831 | if(found == noofbisectorstoremove)noofbisectorstoremove++; |
832 | } |
833 | } |
834 | } |
835 | |
836 | //======================================================================== |
837 | // function : Intersect |
838 | // purpose : Si <aside=0> Intersection de <firstbisector> avec les |
839 | // descendants de <secondbisector> les plus a gauche |
840 | // (ie secondbisector->FirstBisector()->FirstBisector...) |
841 | // Intersection de <secondbisector> avec les |
842 | // descendants de <firstbisector> les plus a droite |
843 | // (ie firstbisector->LastBisector()->LastBisector...) |
844 | // |
845 | // Si <aside=1> Intersection de <firstbisector> avec ses |
846 | // descendants les plus a gauche et les plus a droite. |
847 | // |
848 | // Si <aside=2> Intersection de <secondbisector> avec ses |
849 | // descendants les plus a gauche et les plus a droite. |
850 | //========================================================================v |
851 | void MAT_Mat::Intersect( Tool& atool, |
852 | const Standard_Integer aside, |
853 | Standard_Integer& noofbisectortoremove, |
854 | const Handle(MAT_Bisector)& firstbisector, |
855 | const Handle(MAT_Bisector)& secondbisector) |
856 | { |
857 | Standard_Integer bisectornumber; |
858 | Standard_Real distant,saveparameter; |
859 | Standard_Real distance[2]; |
860 | Standard_Integer intersectionpoint; |
861 | Handle(MAT_Bisector) lastbisector,previousbisector; |
862 | Handle(MAT_Bisector) firstbisectortoremove[2]; |
863 | Handle(MAT_Bisector) lastbisectortoremove[2]; |
864 | |
865 | distance[0] = Precision::Infinite(); |
866 | distance[1] = Precision::Infinite(); |
867 | |
868 | for(bisectornumber = 0; bisectornumber<2; bisectornumber++) { |
869 | if(aside == 0) { |
870 | if(bisectornumber == 0) |
871 | firstbisectortoremove[bisectornumber] = secondbisector; |
872 | else |
873 | firstbisectortoremove[bisectornumber] = firstbisector; |
874 | } |
875 | else if(aside == 1) { |
876 | firstbisectortoremove[bisectornumber] = firstbisector; |
877 | } |
878 | else { |
879 | firstbisectortoremove[bisectornumber] = secondbisector; |
880 | } |
881 | |
882 | lastbisector = firstbisectortoremove[bisectornumber]; |
883 | |
884 | if(aside == 0) { |
885 | previousbisector = firstbisectortoremove[bisectornumber]; |
886 | } |
887 | else { |
888 | if(firstbisectortoremove[bisectornumber]->List()->IsEmpty())continue; |
889 | |
890 | if(bisectornumber == 0) |
891 | previousbisector = firstbisectortoremove[bisectornumber] |
892 | ->FirstBisector(); |
893 | else |
894 | previousbisector = firstbisectortoremove[bisectornumber] |
895 | ->LastBisector(); |
896 | } |
897 | |
898 | distant = distance[bisectornumber]; |
899 | while(!previousbisector->List()->IsEmpty()) { |
900 | |
901 | if(bisectornumber == 0) |
902 | previousbisector = previousbisector->FirstBisector(); |
903 | else |
904 | previousbisector = previousbisector->LastBisector(); |
905 | |
906 | if(aside == 1 || (aside == 0 && bisectornumber == 0)) { |
907 | saveparameter = previousbisector->FirstParameter(); |
908 | distant = atool.IntersectBisector |
909 | (firstbisector,previousbisector,intersectionpoint); |
910 | previousbisector->FirstParameter(saveparameter); |
911 | } |
912 | else { |
913 | saveparameter = previousbisector->SecondParameter(); |
914 | distant = atool.IntersectBisector |
915 | (previousbisector,secondbisector,intersectionpoint); |
916 | previousbisector->SecondParameter(saveparameter); |
917 | } |
918 | |
919 | if(distant < Precision::Infinite()) { |
920 | distance[bisectornumber] = distant; |
921 | lastbisectortoremove[bisectornumber] = lastbisector; |
922 | } |
923 | |
924 | lastbisector = previousbisector; |
925 | } |
926 | } |
927 | |
928 | //--------------------------------------- |
929 | // Chargement des bissectrices a effacer. |
930 | //--------------------------------------- |
931 | |
932 | LoadBisectorsToRemove(noofbisectortoremove, |
933 | distance[0],distance[1], |
934 | firstbisectortoremove[0],firstbisectortoremove[1], |
935 | lastbisectortoremove[0] ,lastbisectortoremove[1]); |
936 | } |
937 | |
938 | //======================================================================== |
939 | // function : Init |
940 | // purpose : |
941 | //======================================================================== |
942 | void MAT_Mat::Init() |
943 | { |
944 | roots->First(); |
945 | } |
946 | |
947 | //======================================================================== |
948 | // function : More |
949 | // purpose : |
950 | //======================================================================== |
951 | Standard_Boolean MAT_Mat::More() const |
952 | { |
953 | return roots->More(); |
954 | } |
955 | |
956 | //======================================================================== |
957 | // function : Next |
958 | // purpose : |
959 | //======================================================================== |
960 | void MAT_Mat::Next() |
961 | { |
962 | roots->Next(); |
963 | } |
964 | |
965 | //======================================================================== |
966 | // function : Bisector |
967 | // purpose : |
968 | //======================================================================== |
969 | Handle(MAT_Bisector) MAT_Mat::Bisector() const |
970 | { |
971 | return roots->Current(); |
972 | } |
973 | |
974 | //======================================================================== |
975 | // function : NumberOfBisectors |
976 | // purpose : |
977 | //======================================================================== |
978 | Standard_Integer MAT_Mat::NumberOfBisectors() const |
979 | { |
980 | return thenumberofbisectors; |
981 | } |
982 | |
983 | //======================================================================== |
984 | // function : SemiInfinite |
985 | // purpose : |
986 | //======================================================================== |
987 | Standard_Boolean MAT_Mat::SemiInfinite() const |
988 | { |
989 | return semiInfinite; |
990 | } |
991 | |
992 | //======================================================================== |
993 | // function : IsDone |
994 | // purpose : |
995 | //======================================================================== |
996 | Standard_Boolean MAT_Mat::IsDone() const |
997 | { |
998 | return isDone; |
999 | } |
1000 | |