28 using namespace GMap3d;
41 int AMarkNumber,
bool ADeleteDarts)
43 assert(ADim==1 || ADim==2);
113 CDart* current = NULL;
116 std::stack<CDart*> FToTreat;
117 bool dangling =
false;
118 unsigned int nbRemove = 0;
120 int toDelete0 = (AMark0==-1?toDelete:AMark0);
121 int toDelete1 = (AMark1==-1?toDelete:AMark1);
122 int toDelete2 = (AMark2==-1?toDelete:AMark2);
126 if ( indexVol!=-1 && indexFace!=-1 )
130 std::cout<<
"Not enough directInfo to use union-find trees."<<std::endl;
139 if ( ! FToTreat.empty() )
143 current = FToTreat.top();
148 while ( !dangling && ! FToTreat.empty() );
154 if ( !
isMarked(current,toDelete2) &&
155 (dangling || !
isMarked(current, treated)) )
166 for ( ; itFace.
cont(); ++itFace )
178 for ( itFace.
reinit(); itFace.
cont(); ++itFace )
184 FToTreat.push(
alpha2(*itFace));
188 t1 =
alpha(*itFace, 2);
197 if ( t2 !=
alpha(t1, 2) )
201 if (t1!=t2)
sew2(t1,t2);
212 for ( ; itFace.
cont(); ++itFace )
222 for ( ; itFace.
cont(); ++itFace )
231 save(
"after-remove-faces.moka");
237 if ( ! FToTreat.empty() )
239 current = FToTreat.top();
250 (dangling || !
isMarked(current, treated)) )
264 for ( ; itEdge.
cont(); ++itEdge )
276 for ( itEdge.
reinit(); itEdge.
cont(); ++itEdge )
282 FToTreat.push(
alpha1(*itEdge));
286 t1 =
alpha(*itEdge, 1);
295 if ( t2 !=
alpha(t1, 1) )
316 for ( ; itEdge.
cont(); ++itEdge )
326 for ( ; itEdge.
cont(); ++itEdge )
335 save(
"after-remove-edges.moka");
346 bool deleteVertex =
true;
348 for ( ; itVertex.
cont(); ++itVertex )
357 deleteVertex =
false;
363 for ( itVertex.
reinit(); itVertex.
cont(); ++itVertex )
365 setMark( *itVertex, toDelete0 );
371 for ( itVertex.
reinit(); itVertex.
cont(); ++itVertex )
373 t1 =
alpha(*itVertex, 0);
382 if ( t2 !=
alpha(t1, 0) )
386 if (t1!=t2)
sew0(t1, t2);
394 save(
"after-all-removals.moka");
407 if (
isMarked(current, toDelete0) ||
437 CDart* current = NULL;
440 std::stack<CDart*> FToTreat;
441 bool dangling =
false;
442 unsigned int nbRemove = 0;
446 if ( indexVol!=-1 && indexFace!=-1 )
450 std::cout<<
"Not enough directInfo to use union-find trees."<<std::endl;
454 CDart* firstDeleteDart = NULL;
463 if ( ! FToTreat.empty() )
467 current = FToTreat.top();
472 while ( !dangling && ! FToTreat.empty() );
479 (dangling || !
isMarked(current, treated)) )
490 for ( ; itFace.
cont(); ++itFace )
503 for ( itFace.
reinit(); itFace.
cont(); ++itFace )
507 (*itFace)->setNext(
alpha3(*itFace));
509 firstDeleteDart=*itFace;
549 for ( itFace.
reinit(); itFace.
cont(); ++itFace )
555 FToTreat.push(
alpha2(*itFace));
559 t1 =
alpha(*itFace, 2);
568 if ( t2 !=
alpha(t1, 2) )
583 itFace.
cont(); ++itFace )
593 itFace.
cont(); ++itFace )
611 if ( ! FToTreat.empty() )
613 current = FToTreat.top();
623 if ( !
isMarked(current, toDelete) &&
624 (dangling || !
isMarked(current, treated)) )
638 for ( ; itEdge.
cont(); ++itEdge )
651 for ( itEdge.
reinit(); itEdge.
cont(); ++itEdge )
657 (*itEdge)->setNext(
alpha3(*itEdge));
661 (*itEdge)->setNext(firstDeleteDart);
662 firstDeleteDart=*itEdge;
697 for ( itEdge.
reinit(); itEdge.
cont(); ++itEdge )
703 FToTreat.push(
alpha1(*itEdge));
707 t1 =
alpha(*itEdge, 1);
716 if ( t2 !=
alpha(t1, 1) )
740 itEdge.
cont(); ++itEdge )
750 itEdge.
cont(); ++itEdge )
764 if ( optosimplify & VERTEX_REMOVAL )
773 bool deleteVertex =
true;
775 for ( ; itVertex.
cont(); ++itVertex )
784 deleteVertex =
false;
790 for ( itVertex.
reinit(); itVertex.
cont(); ++itVertex )
792 setMark( *itVertex, toDelete );
800 for ( itVertex.
reinit(); itVertex.
cont(); ++itVertex )
804 (*itVertex)->setNext(
alpha1(*itVertex));
806 firstDeleteDart=*itVertex;
816 for ( itVertex.
reinit(); itVertex.
cont(); ++itVertex )
818 t1 =
alpha(*itVertex, 0);
827 if ( t2 !=
alpha(t1, 0) )
844 while ( firstDeleteDart!=NULL )
846 t1 = firstDeleteDart->
getNext();
848 firstDeleteDart = t1;
880 CDart* current = NULL;
883 std::stack<CDart*> FToTreat;
884 bool dangling =
false;
885 unsigned int nbRemove = 0;
889 if ( indexVertex!=-1 && indexEdge!=-1 )
893 std::cout<<
"Not enough directInfo to use union-find trees."<<std::endl;
897 CDart* firstDeleteDart = NULL;
912 bool toremove =
true;
914 for ( ; itEdge.
cont(); ++itEdge)
937 for ( itEdge.
reinit(); itEdge.
cont(); ++itEdge )
948 std::vector<CDart*> vertex;
950 itvertex.
cont(); ++itvertex)
952 vertex.push_back(*itvertex);
955 itvertex.
cont(); ++itvertex)
957 vertex.push_back(*itvertex);
959 std::sort(vertex.begin(), vertex.end());
961 std::vector<std::vector<CDart*> > faces;
963 for ( itEdge.
reinit(); itEdge.
cont(); ++itEdge )
966 faces.push_back(std::vector<CDart*>());
967 std::vector<std::vector<CDart*> >::iterator lastface=faces.end()-1;
969 itface.
cont(); ++itface)
971 (*lastface).push_back(*itface);
974 std::sort(lastface->begin(), lastface->end());
991 for ( itEdge.
reinit(); itEdge.
cont(); ++itEdge )
1017 std::vector<std::pair<CDart*,CDart*> > sews;
1029 t1 =
alpha(*itEdge2, 1);
1040 if ( t2 !=
alpha(t1, 1) )
1042 sews.push_back(std::pair<CDart*,CDart*>(t1,
alpha1(t1)));
1047 sews.push_back(std::pair<CDart*,CDart*>(t2,
alpha1(t2)));
1051 if (t1!=t2 && !
isMarked(t1, toDelete))
1064 std::vector<CDart*>::iterator itcell, itcell2;
1065 std::vector<CDart*> cellafter;
1066 bool disconnection =
false;
1067 itcell=vertex.begin();
1068 while( itcell!=vertex.end() &&
isMarked(*itcell, toDelete) )
1077 if ( itcell==vertex.end() )
1079 disconnection =
true;
1087 cellafter.push_back(*itv);
1089 std::sort(cellafter.begin(), cellafter.end() );
1097 itcell2 = cellafter.begin();
1098 while ( !disconnection && itcell2!=cellafter.end() )
1100 while ( itcell!=vertex.end() &&
1104 if ( itcell==vertex.end() )
1107 disconnection =
true;
1109 else if ( (*itcell)!=(*itcell2) )
1112 disconnection =
true;
1121 if ( !disconnection )
1123 while ( itcell!=vertex.end() &&
1126 if ( itcell!=vertex.end() )
1128 disconnection =
true;
1138 if ( !disconnection )
1140 for ( std::vector<std::vector<CDart*> >::iterator itfaces=faces.begin(),
1141 itfacesend=faces.end(); itfaces!=itfacesend; ++itfaces )
1143 itcell=(*itfaces).begin();
1144 while( itcell!=(*itfaces).end() &&
isMarked(*itcell, toDelete) )
1150 if ( itcell==(*itfaces).end() )
1152 disconnection =
true;
1160 cellafter.push_back(*itv);
1162 std::sort(cellafter.begin(), cellafter.end() );
1164 itcell2 = cellafter.begin();
1165 while ( !disconnection && itcell2!=cellafter.end() )
1167 while ( itcell!=(*itfaces).end() &&
1174 if ( itcell==(*itfaces).end() )
1177 disconnection =
true;
1179 else if ( (*itcell)!=(*itcell2) )
1183 disconnection =
true;
1193 if ( !disconnection )
1195 while ( itcell!=(*itfaces).end() &&
1201 if ( itcell!=(*itfaces).end() )
1203 disconnection =
true;
1209 while ( itcell!=(*itfaces).end() )
1218 for ( std::vector<std::vector<CDart*> >::iterator itfaces=faces.begin(),
1219 itfacesend=faces.end(); itfaces!=itfacesend; ++itfaces )
1221 for ( itcell=(*itfaces).begin(); itcell!=(*itfaces).end();
1260 if ( !disconnection )
1266 for ( itEdge.
reinit(); itEdge.
cont(); ++itEdge )
1270 (*itEdge)->setNext(
alpha0(*itEdge));
1272 firstDeleteDart=*itEdge;
1284 for ( itEdge.
reinit(); itEdge.
cont(); ++itEdge )
1294 std::vector<std::pair<CDart*,CDart*> >::iterator sewsit;
1295 for ( sewsit=sews.begin(); sewsit!=sews.end(); ++sewsit )
1298 if (
alpha1((*sewsit).first)!=((*sewsit).second) )
1300 if ( !
isFree1((*sewsit).first) )
1303 if ( !
isFree1((*sewsit).second) )
1306 linkAlpha1((*sewsit).first, (*sewsit).second);
1344 while ( cov.
cont() )
1348 if ( !
isMarked(current, toDelete) &&
1365 for ( ; itFace.
cont(); ++itFace)
1368 assert ( !
isMarked(*itFace, treated) );
1379 std::vector<CDart*> vertex;
1381 itvertex.
cont(); ++itvertex)
1383 vertex.push_back(*itvertex);
1385 std::vector<CDart*> vertex2;
1387 itvertex.
cont(); ++itvertex)
1389 vertex2.push_back(*itvertex);
1457 std::vector<std::pair<CDart*,CDart*> > sews;
1464 for ( itFace.
reinit(); itFace.
cont(); ++itFace )
1468 t1 =
alpha(*itFace, 2);
1479 if ( t2 !=
alpha(t1, 2) )
1481 sews.push_back(std::pair<CDart*,CDart*>(t1,
alpha2(t1)));
1485 sews.push_back(std::pair<CDart*,CDart*>(t2,
alpha2(t2)));
1488 if (t1!=t2 && !
isMarked(t1, toDelete))
1500 std::vector<CDart*>::iterator itcell;
1501 std::set<CDart*> cellafter;
1502 bool disconnection =
false;
1503 for (itcell=vertex.begin(); itcell!=vertex.end(); ++itcell)
1505 if ( !
isMarked(*itcell, toDelete) )
1507 if ( cellafter.empty() )
1509 itcell2.
cont(); ++itcell2)
1511 cellafter.insert(*itcell2);
1515 if ( cellafter.find(*itcell)==cellafter.end() )
1517 disconnection =
true;
1525 if ( cellafter.empty() ) disconnection=
true;
1526 else cellafter.clear();
1527 for (itcell=vertex2.begin(); itcell!=vertex2.end(); ++itcell)
1529 if ( !
isMarked(*itcell, toDelete) )
1531 if ( cellafter.empty() )
1533 itcell2.
cont(); ++itcell2)
1535 cellafter.insert(*itcell2);
1539 if ( cellafter.find(*itcell)==cellafter.end() )
1541 disconnection =
true;
1549 if ( cellafter.empty() ) disconnection=
true;
1550 else cellafter.clear();
1606 if ( !disconnection )
1612 for ( itFace.
reinit(); itFace.
cont(); ++itFace )
1616 (*itFace)->setNext(
alpha0(*itFace));
1618 firstDeleteDart=*itFace;
1630 for ( itFace.
reinit(); itFace.
cont(); ++itFace )
1640 std::vector<std::pair<CDart*,CDart*> >::iterator sewsit;
1641 for ( sewsit=sews.begin(); sewsit!=sews.end(); ++sewsit )
1644 if (
alpha2((*sewsit).first)!=((*sewsit).second) )
1646 if ( !
isFree2((*sewsit).first) )
1648 if ( !
isFree2((*sewsit).second) )
1649 unsew2((*sewsit).second);
1650 sew2((*sewsit).first, (*sewsit).second);
1676 itFace.
cont(); ++itFace )
1789 while ( firstDeleteDart!=NULL )
1791 t1 = firstDeleteDart->
getNext();
1793 firstDeleteDart = t1;
1829 CDart* current = NULL;
1832 std::stack<CDart*> FToTreat;
1833 bool dangling =
false;
1834 unsigned int nbRemove = 0;
1836 int toDelete0 = (AMark0==-1?toDelete:AMark0);
1837 int toDelete1 = (AMark1==-1?toDelete:AMark1);
1840 if ( indexFace!=-1 )
1844 std::cout<<
"Not enough directInfo to use union-find trees."<<std::endl;
1850 while ( cov.
cont() )
1852 if ( ! FToTreat.empty() )
1854 current = FToTreat.top();
1864 if ( !
isMarked(current, toDelete1) &&
1865 (dangling || !
isMarked(current, treated)) )
1879 for ( ; itEdge.
cont(); ++itEdge )
1885 setMark( *itEdge, toDelete1 );
1893 for ( itEdge.
reinit(); itEdge.
cont(); ++itEdge )
1900 FToTreat.push(
alpha1(*itEdge));
1904 t1 =
alpha(*itEdge, 1);
1913 if ( t2 !=
alpha(t1, 1) )
1917 if (t1!=t2)
sew(t1, t2, 1);
1928 for ( ; itEdge.
cont(); ++itEdge )
1938 for ( ; itEdge.
cont(); ++itEdge )
1950 while ( cov.
cont() )
1957 bool deleteVertex =
true;
1959 for ( ; itVertex.
cont(); ++itVertex )
1961 setMark( *itVertex, treated );
1969 deleteVertex =
false;
1975 for ( itVertex.
reinit(); itVertex.
cont(); ++itVertex )
1977 setMark( *itVertex, toDelete0 );
1983 for ( itVertex.
reinit(); itVertex.
cont(); ++itVertex )
1985 t1 =
alpha(*itVertex, 0);
1994 if ( t2 !=
alpha(t1, 0) )
1998 if (t1!=t2)
sew(t1, t2, 0);
2019 if (
isMarked(current, toDelete0) ||
2047 CDart* current = NULL;
2050 std::stack<CDart*> FToTreat;
2051 bool dangling =
false;
2052 unsigned int nbRemove = 0;
2055 if ( indexFace!=-1 )
2059 std::cout<<
"Not enough directInfo to use union-find trees."<<std::endl;
2063 CDart* firstDeleteDart = NULL;
2070 while ( cov.
cont() )
2072 if ( ! FToTreat.empty() )
2074 current = FToTreat.top();
2084 if ( !
isMarked(current, toDelete) &&
2085 (dangling || !
isMarked(current, treated)) )
2099 for ( ; itEdge.
cont(); ++itEdge )
2112 for ( itEdge.
reinit(); itEdge.
cont(); ++itEdge )
2118 (*itEdge)->setNext(
alpha3(*itEdge));
2122 (*itEdge)->setNext(firstDeleteDart);
2123 firstDeleteDart=*itEdge;
2158 for ( itEdge.
reinit(); itEdge.
cont(); ++itEdge )
2164 FToTreat.push(
alpha1(*itEdge));
2168 t1 =
alpha(*itEdge, 1);
2177 if ( t2 !=
alpha(t1, 1) )
2205 itEdge.
cont(); ++itEdge )
2215 itEdge.
cont(); ++itEdge )
2229 if ( optosimplify & VERTEX_REMOVAL )
2232 while ( cov.
cont() )
2238 assert( !
isMarked(current, toDelete) );
2239 bool deleteVertex =
true;
2241 for ( ; itVertex.
cont(); ++itVertex )
2243 setMark( *itVertex, treated );
2251 deleteVertex =
false;
2257 for ( itVertex.
reinit(); itVertex.
cont(); ++itVertex )
2259 setMark( *itVertex, toDelete );
2267 for ( itVertex.
reinit(); itVertex.
cont(); ++itVertex )
2271 (*itVertex)->setNext(
alpha1(*itVertex));
2273 firstDeleteDart=*itVertex;
2283 for ( itVertex.
reinit(); itVertex.
cont(); ++itVertex )
2285 t1 =
alpha(*itVertex, 0);
2294 if ( t2 !=
alpha(t1, 0) )
2316 while ( firstDeleteDart!=NULL )
2318 t1 = firstDeleteDart->
getNext();
2320 firstDeleteDart = t1;
2350 CDart* current = NULL;
2353 std::stack<CDart*> FToTreat;
2354 bool dangling =
false;
2355 unsigned int nbRemove = 0;
2359 if ( indexVertex!=-1 && indexEdge!=-1 )
2363 std::cout<<
"Not enough directInfo to use union-find trees."<<std::endl;
2367 CDart* firstDeleteDart = NULL;
2374 while ( cov.
cont() )
2379 if ( !
isMarked(current,toDelete) &&
2391 for ( ; itEdge.
cont(); ++itEdge)
2403 std::vector<CDart*> vertex;
2405 itvertex.
cont(); ++itvertex)
2407 vertex.push_back(*itvertex);
2410 itvertex.
cont(); ++itvertex)
2412 vertex.push_back(*itvertex);
2415 std::vector<CDart*> face;
2417 itface.
cont(); ++itface)
2419 face.push_back(*itface);
2429 for ( itEdge.
reinit(); itEdge.
cont(); ++itEdge )
2455 std::vector<std::pair<CDart*,CDart*> > sews;
2467 t1 =
alpha(*itEdge, 1);
2478 if ( t2 !=
alpha(t1, 1) )
2480 sews.push_back(std::pair<CDart*,CDart*>(t1,
alpha1(t1)));
2485 sews.push_back(std::pair<CDart*,CDart*>(t2,
alpha1(t2)));
2489 if (t1!=t2 && !
isMarked(t1, toDelete))
2502 std::vector<CDart*>::iterator itcell;
2503 std::set<CDart*> cellafter;
2504 bool disconnection =
false;
2505 for (itcell=vertex.begin(); itcell!=vertex.end(); ++itcell)
2507 if ( !
isMarked(*itcell, toDelete) )
2509 if ( cellafter.empty() )
2511 itcell2.
cont(); ++itcell2)
2513 cellafter.insert(*itcell2);
2517 if ( cellafter.find(*itcell)==cellafter.end() )
2519 disconnection =
true;
2527 if ( cellafter.empty() ) disconnection=
true;
2528 else cellafter.clear();
2529 if ( !disconnection )
2531 for (itcell=face.begin(); itcell!=face.end(); ++itcell)
2533 if ( !
isMarked(*itcell, toDelete) )
2535 if ( cellafter.empty() )
2537 itcell2.
cont(); ++itcell2)
2539 cellafter.insert(*itcell2);
2543 if ( cellafter.find(*itcell)==cellafter.end() )
2545 disconnection =
true;
2554 if ( cellafter.empty() ) disconnection=
true;
2555 else cellafter.clear();
2557 if ( !disconnection )
2563 for ( itEdge.
reinit(); itEdge.
cont(); ++itEdge )
2567 (*itEdge)->setNext(
alpha0(*itEdge));
2569 firstDeleteDart=*itEdge;
2581 for ( itEdge.
reinit(); itEdge.
cont(); ++itEdge )
2591 std::vector<std::pair<CDart*,CDart*> >::iterator sewsit;
2592 for ( sewsit=sews.begin(); sewsit!=sews.end(); ++sewsit )
2595 if (
alpha1((*sewsit).first)!=((*sewsit).second) )
2597 if ( !
isFree1((*sewsit).first) )
2600 if ( !
isFree1((*sewsit).second) )
2603 linkAlpha1((*sewsit).first, (*sewsit).second);
2629 itEdge.
cont(); ++itEdge )
2639 itEdge.
cont(); ++itEdge )
2659 while ( cov.
cont() )
2663 if ( !
isMarked(current, toDelete) &&
2680 for ( ; itFace.
cont(); ++itFace)
2683 assert ( !
isMarked(*itFace, treated) );
2694 std::vector<CDart*> vertex;
2696 itvertex.
cont(); ++itvertex)
2698 vertex.push_back(*itvertex);
2700 std::vector<CDart*> vertex2;
2702 itvertex.
cont(); ++itvertex)
2704 vertex2.push_back(*itvertex);
2772 std::vector<std::pair<CDart*,CDart*> > sews;
2779 for ( itFace.
reinit(); itFace.
cont(); ++itFace )
2783 t1 =
alpha(*itFace, 2);
2794 if ( t2 !=
alpha(t1, 2) )
2796 sews.push_back(std::pair<CDart*,CDart*>(t1,
alpha2(t1)));
2800 sews.push_back(std::pair<CDart*,CDart*>(t2,
alpha2(t2)));
2803 if (t1!=t2 && !
isMarked(t1, toDelete))
2815 std::vector<CDart*>::iterator itcell;
2816 std::set<CDart*> cellafter;
2817 bool disconnection =
false;
2818 for (itcell=vertex.begin(); itcell!=vertex.end(); ++itcell)
2820 if ( !
isMarked(*itcell, toDelete) )
2822 if ( cellafter.empty() )
2824 itcell2.
cont(); ++itcell2)
2826 cellafter.insert(*itcell2);
2830 if ( cellafter.find(*itcell)==cellafter.end() )
2832 disconnection =
true;
2840 if ( cellafter.empty() ) disconnection=
true;
2841 else cellafter.clear();
2842 for (itcell=vertex2.begin(); itcell!=vertex2.end(); ++itcell)
2844 if ( !
isMarked(*itcell, toDelete) )
2846 if ( cellafter.empty() )
2848 itcell2.
cont(); ++itcell2)
2850 cellafter.insert(*itcell2);
2854 if ( cellafter.find(*itcell)==cellafter.end() )
2856 disconnection =
true;
2864 if ( cellafter.empty() ) disconnection=
true;
2865 else cellafter.clear();
2921 if ( !disconnection )
2927 for ( itFace.
reinit(); itFace.
cont(); ++itFace )
2931 (*itFace)->setNext(
alpha0(*itFace));
2933 firstDeleteDart=*itFace;
2945 for ( itFace.
reinit(); itFace.
cont(); ++itFace )
2955 std::vector<std::pair<CDart*,CDart*> >::iterator sewsit;
2956 for ( sewsit=sews.begin(); sewsit!=sews.end(); ++sewsit )
2959 if (
alpha2((*sewsit).first)!=((*sewsit).second) )
2961 if ( !
isFree2((*sewsit).first) )
2963 if ( !
isFree2((*sewsit).second) )
2964 unsew2((*sewsit).second);
2965 sew2((*sewsit).first, (*sewsit).second);
2991 itFace.
cont(); ++itFace )
3008 while ( firstDeleteDart!=NULL )
3010 t1 = firstDeleteDart->
getNext();
3012 firstDeleteDart = t1;