19 #include <CGAL/IO/Polyhedron_iostream.h>
21 #include <CGAL/AABB_tree.h>
22 #include <CGAL/AABB_triangle_primitive.h>
23 #include <CGAL/AABB_traits.h>
30 #include <CGAL/boost/graph/copy_face_graph.h>
31 #include <CGAL/boost/graph/helpers.h>
33 #include <boost/graph/graph_traits.hpp>
45 typedef typename EnrichedPolyhedron::HalfedgeDS
HDS;
69 typedef AABB_Kernel::FT
FT;
77 to_K(_f->facet_begin()->vertex()->point() +
78 (_f->facet_begin()->vertex()->point() -
79 _f->facet_begin()->
next()->vertex()->point()) /
81 to_K(_f->facet_begin()->
next()->vertex()->point() +
82 (_f->facet_begin()->
next()->vertex()->point() -
83 _f->facet_begin()->
next()->
next()->vertex()->point()) /
85 to_K(_f->facet_begin()->
next()->
next()->vertex()->point() +
86 (_f->facet_begin()->
next()->
next()->vertex()->point() -
87 _f->facet_begin()->vertex()->point()) /
102 template <
typename Po
int3d >
119 typedef CGAL::AABB_triangle_primitive<
AABB_Kernel,
120 std::list< Triangle >::iterator >
124 typedef CGAL::AABB_traits< AABB_Kernel, AABB_Primitive >
AABB_Traits;
132 template<
typename HalfedgeGraph >
147 std::vector< std::vector< InterId > >
CutList;
202 HalfedgeGraph &_g_out,
206 #ifdef BOOLEAN_OPERATIONS_TIME
207 auto time_total_start = std::chrono::steady_clock::now();
208 auto time_start = time_total_start;
209 #endif // BOOLEAN_OPERATIONS_TIME
212 if(!(CGAL::is_closed(_gA) && CGAL::is_closed(_gB)))
214 throw std::runtime_error(
215 "Boolean Operation: only closed meshes are allowed.");
221 CGAL::copy_face_graph(_gA, gA);
222 CGAL::copy_face_graph(_gB, gB);
224 #ifdef BOOLEAN_OPERATIONS_TIME
226 #endif // BOOLEAN_OPERATIONS_TIME
228 #ifdef BOOLEAN_OPERATIONS_DEBUG
230 std::ofstream ofstrMA(
"boolean_operation__input_A.off");
232 std::ofstream ofstrMB(
"boolean_operation__input_B.off");
235 #endif // BOOLEAN_OPERATIONS_DEBUG
239 #ifdef BOOLEAN_OPERATIONS_TIME
241 #endif // BOOLEAN_OPERATIONS_TIME
245 #ifdef BOOLEAN_OPERATIONS_TIME
247 #endif // BOOLEAN_OPERATIONS_TIME
253 #ifdef BOOLEAN_OPERATIONS_TIME
255 #endif // BOOLEAN_OPERATIONS_TIME
259 #ifdef BOOLEAN_OPERATIONS_TIME
261 #endif // BOOLEAN_OPERATIONS_TIME
265 #ifdef BOOLEAN_OPERATIONS_TIME
267 #endif // BOOLEAN_OPERATIONS_TIME
273 #ifdef BOOLEAN_OPERATIONS_TIME
275 #endif // BOOLEAN_OPERATIONS_TIME
277 #ifdef BOOLEAN_OPERATIONS_DEBUG
278 std::ofstream ofstrMS(
"boolean_operation_output.off");
282 std::ofstream ofstrColorInput(
"boolean_operation__input_A_colorized.off");
283 ofstrColorInput << gA;
284 #endif // BOOLEAN_OPERATIONS_DEBUG
288 CGAL::copy_face_graph(g_out, _g_out);
290 #ifdef BOOLEAN_OPERATIONS_TIME
295 std::cout <<
"Computation time :" << std::endl;
296 std::cout <<
" + Copying input meshes : "
300 std::cout <<
" + Initialization : "
304 std::cout <<
" + Finding the Intersections : "
308 std::cout <<
" + Compute the Intersections : "
312 std::cout <<
" + Cut the Intersected Facets : "
316 std::cout <<
" + Complete the result : "
320 std::cout <<
" + Create the polyhedron : "
324 std::cout <<
" + Copying output mesh : "
328 std::cout <<
"---------------------------------------"
330 std::cout <<
" Total : "
335 std::cout << std::endl;
336 std::cout <<
"Details :" << std::endl;
337 std::cout << std::endl;
338 std::cout <<
"Polyedron A :" << std::endl;
339 std::cout <<
"Number of Facets : "
340 <<
m_pA->size_of_facets() << std::endl;
341 std::cout << std::endl;
342 std::cout <<
"Polyedron B :" << std::endl;
343 std::cout <<
"Number of Facets : "
344 <<
m_pB->size_of_facets() << std::endl;
345 std::cout << std::endl;
346 std::cout <<
"Result :" << std::endl;
347 std::cout <<
"Number of Facets : "
348 << g_out.size_of_facets() << std::endl;
349 #endif // BOOLEAN_OPERATIONS_TIME
370 if(!
m_pA->is_pure_triangle())
372 if(!
m_pB->is_pure_triangle())
377 pVertex !=
m_pA->vertices_end();
380 pVertex->Label = 0xFFFFFFFF;
383 pVertex !=
m_pB->vertices_end();
386 pVertex->Label = 0xFFFFFFFF;
389 pFacet !=
m_pA->facets_end();
392 pFacet->Label = 0xFFFFFFFF;
393 pFacet->IsExt =
false;
394 pFacet->IsOK =
false;
397 pFacet !=
m_pB->facets_end();
400 pFacet->Label = 0xFFFFFFFF;
401 pFacet->IsExt =
false;
402 pFacet->IsOK =
false;
405 #ifdef BOOLEAN_OPERATIONS_DEBUG_VERBOSE
409 EnrichedPolyhedron::Halfedge_iterator pHe;
410 for(pHe =
m_pA->halfedges_begin(); pHe !=
m_pA->halfedges_end(); pHe++)
411 pHe->Label = 42424242;
412 for(pHe =
m_pB->halfedges_begin(); pHe !=
m_pB->halfedges_end(); pHe++)
413 pHe->Label = 42424242;
415 #endif //BOOLEAN_OPERATIONS_DEBUG_VERBOSE
423 #ifdef BOOLEAN_OPERATIONS_DEBUG_VERBOSE
425 std::cout <<
"Triangulating mesh..." << std::endl;
426 std::cout <<
"before triangulating mesh:" << std::endl;
427 std::cout <<
" size_of_vertices = " << m->size_of_vertices() << std::endl;
428 std::cout <<
" size_of_halfedges = " << m->size_of_halfedges() << std::endl;
429 std::cout <<
" size_of_facets = " << m->size_of_facets() << std::endl;
431 #endif //BOOLEAN_OPERATIONS_DEBUG_VERBOSE
438 if(f == m->facets_end())
444 if(!(f->is_triangle()))
446 int num = (int)(f->facet_degree() - 3);
472 #ifdef BOOLEAN_OPERATIONS_DEBUG_VERBOSE
474 std::cout <<
"after triangulating mesh:" << std::endl;
475 std::cout <<
" size_of_vertices = " << m->size_of_vertices() << std::endl;
476 std::cout <<
" size_of_halfedges = " << m->size_of_halfedges() << std::endl;
477 std::cout <<
" size_of_facets = " << m->size_of_facets() << std::endl;
479 #endif //BOOLEAN_OPERATIONS_DEBUG_VERBOSE
489 std::list<AABB_Tree::Primitive_id> primitives;
490 std::list<Triangle> triangles;
496 if(
m_pA->size_of_facets() <
m_pB->size_of_facets())
499 for(pFacet =
m_pA->facets_begin(); pFacet !=
m_pA->facets_end(); pFacet++) triangles.push_back(
Triangle(pFacet));
500 tree.rebuild(triangles.begin(),triangles.end());
503 for (pFacet =
m_pB->facets_begin(); pFacet !=
m_pB->facets_end(); pFacet++)
506 tree.all_intersected_primitives(
Triangle(pFacet), std::back_inserter(primitives));
507 if(primitives.size() !=0)
512 pFacet->facet_begin()->Label = i++;
513 pFacet->facet_begin()->next()->Label = i++;
514 pFacet->facet_begin()->next()->next()->Label = i++;
519 if(primitives.back()->facet()->Label == 0xFFFFFFFF)
522 primitives.back()->facet()->Label = j++;
523 primitives.back()->facet()->facet_begin()->Label = i++;
524 primitives.back()->facet()->facet_begin()->next()->Label = i++;
525 primitives.back()->facet()->facet_begin()->next()->next()->Label = i++;
529 m_Couples[primitives.back()->facet()->Label].insert(pFacet->Label);
530 primitives.pop_back();
532 while(primitives.size() != 0);
539 for(pFacet =
m_pB->facets_begin(); pFacet !=
m_pB->facets_end(); pFacet++) triangles.push_back(
Triangle(pFacet));
540 tree.rebuild(triangles.begin(),triangles.end());
543 for (pFacet =
m_pA->facets_begin(); pFacet !=
m_pA->facets_end(); pFacet++)
546 tree.all_intersected_primitives(
Triangle(pFacet), std::back_inserter(primitives));
547 if(primitives.size() !=0)
552 pFacet->facet_begin()->Label = i++;
553 pFacet->facet_begin()->next()->Label = i++;
554 pFacet->facet_begin()->next()->next()->Label = i++;
559 if(primitives.back()->facet()->Label == 0xFFFFFFFF)
562 primitives.back()->facet()->Label = j++;
563 primitives.back()->facet()->facet_begin()->Label = i++;
564 primitives.back()->facet()->facet_begin()->next()->Label = i++;
565 primitives.back()->facet()->facet_begin()->next()->next()->Label = i++;
569 m_Couples[pFacet->Label].insert(primitives.back()->facet()->Label);
570 primitives.pop_back();
572 while(primitives.size() != 0);
577 #ifdef BOOLEAN_OPERATIONS_DEBUG_VERBOSE
579 std::cout <<
"end of FindCouples(), mesh A, face Label property:" << std::endl;
580 for(pFacet =
m_pA->facets_begin(); pFacet !=
m_pA->facets_end(); pFacet++)
581 std::cout << pFacet->Label << std::endl;
582 std::cout <<
"end of FindCouples(), mesh B, face Label property:" << std::endl;
583 for(pFacet =
m_pB->facets_begin(); pFacet !=
m_pB->facets_end(); pFacet++)
584 std::cout << pFacet->Label << std::endl;
585 std::cout <<
"end of FindCouples(), mesh A, halfedge Label property:" << std::endl;
586 EnrichedPolyhedron::Halfedge_iterator pHe;
587 for(pHe =
m_pA->halfedges_begin(); pHe !=
m_pA->halfedges_end(); pHe++)
588 std::cout << pHe->Label << std::endl;
589 std::cout <<
"end of FindCouples(), mesh B, halfedge Label property:" << std::endl;
590 for(pHe =
m_pB->halfedges_begin(); pHe !=
m_pB->halfedges_end(); pHe++)
591 std::cout << pHe->Label << std::endl;
593 #endif //BOOLEAN_OPERATIONS_DEBUG_VERBOSE
628 for(std::set<InterId>::iterator i = TriCut.
PtList.begin();i != TriCut.
PtList.end();++i)
633 for(
int i = 0;i!=(int)TriCut.
CutList.size();++i)
645 if(IsExt[0]) he->opposite()->facet()->IsExt =
true;
646 if(IsExt[1]) he->next()->opposite()->facet()->IsExt =
true;
647 if(IsExt[2]) he->next()->next()->opposite()->facet()->IsExt =
true;
657 std::stack<Facet_handle> tmpTriangles;
660 for (pFacet =
m_pA->facets_begin(); pFacet !=
m_pA->facets_end(); pFacet++)
662 if(pFacet->IsOK) tmpTriangles.push(pFacet);
668 while(!tmpTriangles.empty())
670 f = tmpTriangles.top();
672 nf = f->facet_begin()->opposite()->facet();
676 tmpTriangles.push(nf);
679 nf = f->facet_begin()->next()->opposite()->facet();
683 tmpTriangles.push(nf);
686 nf = f->facet_begin()->next()->next()->opposite()->facet();
690 tmpTriangles.push(nf);
696 for (pFacet =
m_pB->facets_begin(); pFacet !=
m_pB->facets_end(); pFacet++)
698 if(pFacet->IsOK) tmpTriangles.push(pFacet);
701 while(!tmpTriangles.empty())
703 f = tmpTriangles.top();
705 nf = f->facet_begin()->opposite()->facet();
709 tmpTriangles.push(nf);
712 nf = f->facet_begin()->next()->opposite()->facet();
716 tmpTriangles.push(nf);
719 nf = f->facet_begin()->next()->next()->opposite()->facet();
723 tmpTriangles.push(nf);
755 heA[0] = fA->facet_begin();
756 heA[1] = heA[0]->next();
757 heA[2] = heA[1]->next();
758 heB[0] = fB->facet_begin();
759 heB[1] = heB[0]->next();
760 heB[2] = heB[1]->next();
775 posA[0] = nB * (ptA[0] - ptB[0]);
776 posA[1] = nB * (ptA[1] - ptB[0]);
777 posA[2] = nB * (ptA[2] - ptB[0]);
778 posB[0] = nA * (ptB[0] - ptA[0]);
779 posB[1] = nA * (ptB[1] - ptA[0]);
780 posB[2] = nA * (ptB[2] - ptA[0]);
784 unsigned short posAbin, posBbin;
785 posAbin = ( (posA[0] > 0)? 32 : 0 )
786 + ( (posA[0] < 0)? 16 : 0 )
787 + ( (posA[1] > 0)? 8 : 0 )
788 + ( (posA[1] < 0)? 4 : 0 )
789 + ( (posA[2] > 0)? 2 : 0 )
790 + ( (posA[2] < 0)? 1 : 0 );
792 posBbin = ( (posB[0] > 0)? 32 : 0 )
793 + ( (posB[0] < 0)? 16 : 0 )
794 + ( (posB[1] > 0)? 8 : 0 )
795 + ( (posB[1] < 0)? 4 : 0 )
796 + ( (posB[2] > 0)? 2 : 0 )
797 + ( (posB[2] < 0)? 1 : 0 );
801 if(posAbin == 5 || posAbin == 10 || posAbin == 17 || posAbin == 34 || posAbin == 20 || posAbin == 40
802 || posBbin == 5 || posBbin == 10 || posBbin == 17 || posBbin == 34 || posBbin == 20 || posBbin == 40)
return;
804 if(posAbin == 42 || posAbin == 21
805 || posBbin == 42 || posBbin == 21)
return;
807 if(posAbin == 0)
return;
817 unsigned short edgeA = 3, edgeB = 3;
818 if( posAbin == 1 || posAbin == 2 ) edgeA = 1;
819 else if(posAbin == 16 || posAbin == 32) edgeA = 2;
820 else if(posAbin == 4 || posAbin == 8 ) edgeA = 0;
821 if( posBbin == 1 || posBbin == 2 ) edgeB = 1;
822 else if(posBbin == 16 || posBbin == 32) edgeB = 2;
823 else if(posBbin == 4 || posBbin == 8 ) edgeB = 0;
827 bool invert_direction =
false;
831 if(edgeA != 3 && edgeB == 3)
833 fA2 = heA[edgeA]->opposite()->facet();
838 if(p < 0) stop =
true;
847 if(posA[(edgeA+1)%3] * (nA2 * nB) > 0) stop =
true;
850 if(posA[(edgeA+1)%3] > 0) stop =
true;
853 if(posA[(edgeA+1)%3] * (nA2 * nB) < 0) stop =
true;
861 else if(edgeA == 3 && edgeB != 3)
863 fB2 = heB[edgeB]->opposite()->facet();
868 if(p < 0) stop =
true;
877 if(posB[(edgeB+1)%3] < 0) stop =
true;
880 if(posB[(edgeB+1)%3] * (nB2 * nA) < 0) stop =
true;
883 if(posB[(edgeB+1)%3] > 0) stop =
true;
891 else if(edgeA != 3 && edgeB != 3)
896 bool Intersection =
false;
899 num_type posA2_A, posB_A, posB2_A, posB_B2, posA_B, posB2_B, posB_A2, posB2_A2, posA2_B, posA2_B2;
902 fA2 = heA[edgeA]->opposite()->facet();
903 fB2 = heB[edgeB]->opposite()->facet();
917 posA_B = posA[(edgeA+1)%3];
918 posB_A = posB[(edgeB+1)%3];
919 posB_A2 = nA2 * (ptB[(edgeB+1)%3] - ptA[edgeA]);
920 posB_B2 = nB2 * (ptB[(edgeB+1)%3] - ptA[edgeA]);
921 posA2_A = nA * (ptA2 - ptA[edgeA]);
922 posA2_B = nB * (ptA2 - ptA[edgeA]);
923 posA2_B2 = nB2 * (ptA2 - ptA[edgeA]);
924 posB2_A = nA * (ptB2 - ptA[edgeA]);
925 posB2_A2 = nA2 * (ptB2 - ptA[edgeA]);
926 posB2_B = nB * (ptB2 - ptA[edgeA]);
928 if(nAcnB2 == CGAL::NULL_VECTOR && nA2cnB == CGAL::NULL_VECTOR
929 && nAnB2 * nA2nB > 0) stop =
true;
933 if(posB_A * posB2_A > 0)
935 if(posB_B2 > 0) Intersection =
true;
937 else if(posB_A * posB2_A < 0)
939 if(posA_B < 0) Intersection =
true;
943 if(posA_B * posB2_B < 0)
945 if(posB_B2 > 0) Intersection =
true;
962 if(posB_A2 * posB2_A2 > 0)
964 if(posB_B2 > 0) Intersection = !Intersection;
966 else if(posB_A2 * posB2_A2 < 0)
968 if(posA2_B < 0) Intersection = !Intersection;
970 else if(posB2_A2 == 0)
972 if(posA2_B * posB2_B < 0)
974 if(posB_B2 > 0) Intersection = !Intersection;
990 if(posA2_B2 * posB_B2 < 0)
992 if(posB_B2 > 0) Intersection = !Intersection;
1008 if(!Intersection) stop =
true;
1016 if(posB_A * posA2_A > 0 && posB_A * posB2_A >= 0 && posB2_B * posA_B > 0) invert_direction =
true;
1035 inter[0].
he = heB[0];
1037 inter[1].
he = heB[1];
1042 inter[0].
he = heB[1];
1044 inter[1].
he = heB[2];
1049 inter[0].
he = heB[2];
1051 inter[1].
he = heB[0];
1057 inter[0].
he = heB[2];
1059 inter[1].
he = heB[0];
1064 inter[0].
he = heB[0];
1066 inter[1].
he = heB[1];
1071 inter[0].
he = heB[1];
1073 inter[1].
he = heB[2];
1079 inter[0].
he = heB[0];
1081 inter[1].
he = heB[2]->opposite();
1086 inter[0].
he = heB[1];
1088 inter[1].
he = heB[0]->opposite();
1093 inter[0].
he = heB[2];
1095 inter[1].
he = heB[1]->opposite();
1107 inter[2].
he = heA[0];
1109 inter[3].
he = heA[1];
1114 inter[2].
he = heA[1];
1116 inter[3].
he = heA[2];
1121 inter[2].
he = heA[2];
1123 inter[3].
he = heA[0];
1129 inter[2].
he = heA[2];
1131 inter[3].
he = heA[0];
1136 inter[2].
he = heA[0];
1138 inter[3].
he = heA[1];
1143 inter[2].
he = heA[1];
1145 inter[3].
he = heA[2];
1151 inter[2].
he = heA[0];
1153 inter[3].
he = heA[2]->opposite();
1158 inter[2].
he = heA[1];
1160 inter[3].
he = heA[0]->opposite();
1165 inter[2].
he = heA[2];
1167 inter[3].
he = heA[1]->opposite();
1178 std::vector<InterId> ptInter;
1181 std::vector<InterId> ptInterInv;
1182 ptInterInv.push_back(ptInter[1]);
1183 ptInterInv.push_back(ptInter[0]);
1191 m_Inter_tri[fA->Label].CutList.push_back(ptInter);
1192 if(edgeA != 3)
m_Inter_tri[fA2->Label].CutList.push_back(ptInter);
1193 m_Inter_tri[fB->Label].CutList.push_back(ptInterInv);
1194 if(edgeB != 3)
m_Inter_tri[fB2->Label].CutList.push_back(ptInterInv);
1197 m_Inter_tri[fA->Label].CutList.push_back(ptInterInv);
1198 if(edgeA != 3)
m_Inter_tri[fA2->Label].CutList.push_back(ptInterInv);
1199 m_Inter_tri[fB->Label].CutList.push_back(ptInter);
1200 if(edgeB != 3)
m_Inter_tri[fB2->Label].CutList.push_back(ptInter);
1203 m_Inter_tri[fA->Label].CutList.push_back(ptInter);
1204 if(edgeA != 3)
m_Inter_tri[fA2->Label].CutList.push_back(ptInter);
1205 m_Inter_tri[fB->Label].CutList.push_back(ptInter);
1206 if(edgeB != 3)
m_Inter_tri[fB2->Label].CutList.push_back(ptInter);
1215 m_Inter_tri[fA->Label].CutList.push_back(ptInterInv);
1216 if(edgeA != 3)
m_Inter_tri[fA2->Label].CutList.push_back(ptInterInv);
1217 m_Inter_tri[fB->Label].CutList.push_back(ptInter);
1218 if(edgeB != 3)
m_Inter_tri[fB2->Label].CutList.push_back(ptInter);
1221 m_Inter_tri[fA->Label].CutList.push_back(ptInter);
1222 if(edgeA != 3)
m_Inter_tri[fA2->Label].CutList.push_back(ptInter);
1223 m_Inter_tri[fB->Label].CutList.push_back(ptInterInv);
1224 if(edgeB != 3)
m_Inter_tri[fB2->Label].CutList.push_back(ptInterInv);
1227 m_Inter_tri[fA->Label].CutList.push_back(ptInterInv);
1228 if(edgeA != 3)
m_Inter_tri[fA2->Label].CutList.push_back(ptInterInv);
1229 m_Inter_tri[fB->Label].CutList.push_back(ptInterInv);
1230 if(edgeB != 3)
m_Inter_tri[fB2->Label].CutList.push_back(ptInterInv);
1245 if(
m_Inter_tri[f->Label].RefInter.count(he->Label) != 0)
1255 inter->
Id = 0xFFFFFFFF;
1296 inter->
pt = s1+(tmp*e2*q)*dir;
1300 if(u == 0) inter->
res += 1;
1301 if(v == 0) inter->
res += 2;
1302 if(u+v == 1) inter->
res += 4;
1313 if(
m_Inter_tri[f->Label].RefInter.count(he->Label) != 0)
1323 inter->
Id = 0xFFFFFFFF;
1360 if(u == 0) inter->
res += 1;
1361 if(v == 0) inter->
res += 2;
1362 if(w == 0) inter->
res += 4;
1374 unsigned long Id = 0;
1378 if(inter[0].Id != 0xFFFFFFFF)
1385 else if(inter[0].res != 7)
1393 if(inter[1].Id != 0xFFFFFFFF)
1400 if(point ||
id)
return true;
1404 else if(inter[1].res != 7)
1411 if(point ||
id)
return true;
1416 if(inter[2].Id != 0xFFFFFFFF)
1423 if(point || (
id && Id != inter[2].Id))
return true;
1427 else if(inter[2].res != 7)
1434 if((point && pt != inter[2].pt) ||
id)
return true;
1439 if(inter[3].Id != 0xFFFFFFFF)
1446 if(point || (
id && Id != inter[3].Id))
return true;
1448 else if(inter[3].res != 7)
1455 if((point && pt != inter[3].pt) ||
id)
return true;
1467 for(
unsigned int i = 0;i != 4;++i)
1470 if(inter[i].Id != 0xFFFFFFFF)
1473 if(I.size() == 0 || I[0] != inter[i].
Id) I.push_back(inter[i].Id);
1476 else if(inter[i].res != 7)
1483 I.push_back(inter[i].Id);
1487 if(I.size() == 2)
return;
1511 if(inter->
IsOnVertex) he->vertex()->Label = I;
1523 m_Inter_tri[f->Label].RefInter[he->opposite()->Label] = I;
1529 m_Inter_tri[f->Label].RefInter[H_circ->Label] = I;
1530 m_Inter_tri[f->Label].RefInter[H_circ->opposite()->Label] = I;
1532 }
while(H_circ != H_end);
1539 m_Inter_tri[f->facet_begin()->opposite()->facet()->Label].PtList.insert(I);
1543 m_Inter_tri[he->opposite()->facet()->Label].PtList.insert(I);
1545 m_Inter_tri[f->Label].RefInter[he->opposite()->Label] = I;
1546 m_Inter_tri[f->facet_begin()->opposite()->facet()->Label].RefInter[he->Label] = I;
1547 m_Inter_tri[f->facet_begin()->opposite()->facet()->Label].RefInter[he->opposite()->Label] = I;
1548 m_Inter_tri[he->facet()->Label].RefInter[f->facet_begin()->Label] = I;
1549 m_Inter_tri[he->facet()->Label].RefInter[f->facet_begin()->opposite()->Label] = I;
1550 m_Inter_tri[he->opposite()->facet()->Label].RefInter[f->facet_begin()->Label] = I;
1551 m_Inter_tri[he->opposite()->facet()->Label].RefInter[f->facet_begin()->opposite()->Label] = I;
1557 m_Inter_tri[f->Label].RefInter[H_circ->Label] = I;
1558 m_Inter_tri[f->Label].RefInter[H_circ->opposite()->Label] = I;
1559 m_Inter_tri[f->facet_begin()->opposite()->facet()->Label].RefInter[H_circ->Label] = I;
1560 m_Inter_tri[f->facet_begin()->opposite()->facet()->Label].RefInter[H_circ->opposite()->Label] = I;
1561 m_Inter_tri[H_circ->facet()->Label].RefInter[f->facet_begin()->Label] = I;
1562 m_Inter_tri[H_circ->facet()->Label].RefInter[f->facet_begin()->opposite()->Label] = I;
1564 }
while(H_circ != H_end);
1571 m_Inter_tri[f->facet_begin()->next()->opposite()->facet()->Label].PtList.insert(I);
1575 m_Inter_tri[he->opposite()->facet()->Label].PtList.insert(I);
1577 m_Inter_tri[f->Label].RefInter[he->opposite()->Label] = I;
1578 m_Inter_tri[f->facet_begin()->next()->opposite()->facet()->Label].RefInter[he->Label] = I;
1579 m_Inter_tri[f->facet_begin()->next()->opposite()->facet()->Label].RefInter[he->opposite()->Label] = I;
1580 m_Inter_tri[he->facet()->Label].RefInter[f->facet_begin()->next()->Label] = I;
1581 m_Inter_tri[he->facet()->Label].RefInter[f->facet_begin()->next()->opposite()->Label] = I;
1582 m_Inter_tri[he->opposite()->facet()->Label].RefInter[f->facet_begin()->next()->Label] = I;
1583 m_Inter_tri[he->opposite()->facet()->Label].RefInter[f->facet_begin()->next()->opposite()->Label] = I;
1589 m_Inter_tri[f->Label].RefInter[H_circ->Label] = I;
1590 m_Inter_tri[f->Label].RefInter[H_circ->opposite()->Label] = I;
1591 m_Inter_tri[f->facet_begin()->next()->opposite()->facet()->Label].RefInter[H_circ->Label] = I;
1592 m_Inter_tri[f->facet_begin()->next()->opposite()->facet()->Label].RefInter[H_circ->opposite()->Label] = I;
1593 m_Inter_tri[H_circ->facet()->Label].RefInter[f->facet_begin()->next()->Label] = I;
1594 m_Inter_tri[H_circ->facet()->Label].RefInter[f->facet_begin()->next()->opposite()->Label] = I;
1596 }
while(H_circ != H_end);
1603 f->facet_begin()->vertex()->Label = I;
1607 m_Inter_tri[he->opposite()->facet()->Label].PtList.insert(I);
1610 H_end = f->facet_begin()->vertex_begin();
1612 m_Inter_tri[H_circ->facet()->Label].RefInter[he->Label] = I;
1613 m_Inter_tri[H_circ->facet()->Label].RefInter[he->opposite()->Label] = I;
1614 m_Inter_tri[he->facet()->Label].RefInter[H_circ->Label] = I;
1615 m_Inter_tri[he->facet()->Label].RefInter[H_circ->opposite()->Label] = I;
1616 m_Inter_tri[he->opposite()->facet()->Label].RefInter[H_circ->Label] = I;
1617 m_Inter_tri[he->opposite()->facet()->Label].RefInter[H_circ->opposite()->Label] = I;
1619 }
while(H_circ != H_end);
1624 H_end = he->vertex_begin();
1627 F_end = f->facet_begin()->vertex_begin();
1629 m_Inter_tri[F_circ->facet()->Label].RefInter[H_circ->Label] = I;
1630 m_Inter_tri[F_circ->facet()->Label].RefInter[H_circ->opposite()->Label] = I;
1631 m_Inter_tri[H_circ->facet()->Label].RefInter[F_circ->Label] = I;
1632 m_Inter_tri[H_circ->facet()->Label].RefInter[F_circ->opposite()->Label] = I;
1634 }
while(F_circ != F_end);
1636 }
while(H_circ != H_end);
1643 m_Inter_tri[f->facet_begin()->next()->next()->opposite()->facet()->Label].PtList.insert(I);
1647 m_Inter_tri[he->opposite()->facet()->Label].PtList.insert(I);
1649 m_Inter_tri[f->Label].RefInter[he->opposite()->Label] = I;
1650 m_Inter_tri[f->facet_begin()->next()->next()->opposite()->facet()->Label].RefInter[he->Label] = I;
1651 m_Inter_tri[f->facet_begin()->next()->next()->opposite()->facet()->Label].RefInter[he->opposite()->Label] = I;
1652 m_Inter_tri[he->facet()->Label].RefInter[f->facet_begin()->next()->next()->Label] = I;
1653 m_Inter_tri[he->facet()->Label].RefInter[f->facet_begin()->next()->next()->opposite()->Label] = I;
1654 m_Inter_tri[he->opposite()->facet()->Label].RefInter[f->facet_begin()->next()->next()->Label] = I;
1655 m_Inter_tri[he->opposite()->facet()->Label].RefInter[f->facet_begin()->next()->next()->opposite()->Label] = I;
1661 m_Inter_tri[f->Label].RefInter[H_circ->Label] = I;
1662 m_Inter_tri[f->Label].RefInter[H_circ->opposite()->Label] = I;
1663 m_Inter_tri[f->facet_begin()->next()->next()->opposite()->facet()->Label].RefInter[H_circ->Label] = I;
1664 m_Inter_tri[f->facet_begin()->next()->next()->opposite()->facet()->Label].RefInter[H_circ->opposite()->Label] = I;
1665 m_Inter_tri[H_circ->facet()->Label].RefInter[f->facet_begin()->next()->next()->Label] = I;
1666 m_Inter_tri[H_circ->facet()->Label].RefInter[f->facet_begin()->next()->next()->opposite()->Label] = I;
1668 }
while(H_circ != H_end);
1675 f->facet_begin()->next()->next()->vertex()->Label = I;
1679 m_Inter_tri[he->opposite()->facet()->Label].PtList.insert(I);
1682 H_end = f->facet_begin()->next()->next()->vertex_begin();
1684 m_Inter_tri[H_circ->facet()->Label].RefInter[he->Label] = I;
1685 m_Inter_tri[H_circ->facet()->Label].RefInter[he->opposite()->Label] = I;
1686 m_Inter_tri[he->facet()->Label].RefInter[H_circ->Label] = I;
1687 m_Inter_tri[he->facet()->Label].RefInter[H_circ->opposite()->Label] = I;
1688 m_Inter_tri[he->opposite()->facet()->Label].RefInter[H_circ->Label] = I;
1689 m_Inter_tri[he->opposite()->facet()->Label].RefInter[H_circ->opposite()->Label] = I;
1691 }
while(H_circ != H_end);
1696 H_end = he->vertex_begin();
1699 F_end = f->facet_begin()->next()->next()->vertex_begin();
1701 m_Inter_tri[F_circ->facet()->Label].RefInter[H_circ->Label] = I;
1702 m_Inter_tri[F_circ->facet()->Label].RefInter[H_circ->opposite()->Label] = I;
1703 m_Inter_tri[H_circ->facet()->Label].RefInter[F_circ->Label] = I;
1704 m_Inter_tri[H_circ->facet()->Label].RefInter[F_circ->opposite()->Label] = I;
1706 }
while(F_circ != F_end);
1708 }
while(H_circ != H_end);
1715 f->facet_begin()->next()->vertex()->Label = I;
1719 m_Inter_tri[he->opposite()->facet()->Label].PtList.insert(I);
1722 H_end = f->facet_begin()->next()->vertex_begin();
1724 m_Inter_tri[H_circ->facet()->Label].RefInter[he->Label] = I;
1725 m_Inter_tri[H_circ->facet()->Label].RefInter[he->opposite()->Label] = I;
1726 m_Inter_tri[he->facet()->Label].RefInter[H_circ->Label] = I;
1727 m_Inter_tri[he->facet()->Label].RefInter[H_circ->opposite()->Label] = I;
1728 m_Inter_tri[he->opposite()->facet()->Label].RefInter[H_circ->Label] = I;
1729 m_Inter_tri[he->opposite()->facet()->Label].RefInter[H_circ->opposite()->Label] = I;
1731 }
while(H_circ != H_end);
1736 H_end = he->vertex_begin();
1739 F_end = f->facet_begin()->next()->vertex_begin();
1741 m_Inter_tri[F_circ->facet()->Label].RefInter[H_circ->Label] = I;
1742 m_Inter_tri[F_circ->facet()->Label].RefInter[H_circ->opposite()->Label] = I;
1743 m_Inter_tri[H_circ->facet()->Label].RefInter[F_circ->Label] = I;
1744 m_Inter_tri[H_circ->facet()->Label].RefInter[F_circ->opposite()->Label] = I;
1746 }
while(F_circ != F_end);
1748 }
while(H_circ != H_end);
1770 for(std::set<InterId>::iterator i = TriCut.
PtList.begin();i != TriCut.
PtList.end();++i)
1784 else ppbuilder.add_triangle(pFacet,
false);
1787 pFacet->facet_begin()->opposite()->facet()->IsExt =
true;
1788 pFacet->facet_begin()->next()->opposite()->facet()->IsExt =
true;
1789 pFacet->facet_begin()->next()->next()->opposite()->facet()->IsExt =
true;
1792 #ifdef BOOLEAN_OPERATIONS_DEBUG
1799 #if 0//TODO-elo-restore
1801 for(pFacet =
m_pA->facets_begin(); pFacet !=
m_pA->facets_end(); pFacet++)
1804 pFacet->color(1.0, 0.0, 0.0);
1805 else if(pFacet->IsExt)
1806 pFacet->color(0.0, 1.0, 0.0);
1808 pFacet->color(0.0, 0.0, 1.0);
1810 for(pFacet =
m_pB->facets_begin(); pFacet !=
m_pB->facets_end(); pFacet++)
1813 pFacet->color(1.0, 0.0, 0.0);
1814 else if(pFacet->IsExt)
1815 pFacet->color(0.0, 1.0, 0.0);
1817 pFacet->color(0.0, 0.0, 1.0);
1827 std::size_t N_IFA = 0;
1828 std::size_t N_FFA = 0;
1829 std::size_t N_LFFA = 0;
1830 std::size_t N_IFB = 0;
1831 std::size_t N_FFB = 0;
1832 std::size_t N_LFFB = 0;
1838 else if(pFacet->IsExt) N_FFA++;
1844 else if(pFacet->IsExt) N_FFB++;
1847 N_CF = m_out.size_of_facets() - N_FFA - N_FFB;
1849 std::ofstream ofstrtime(
"boolean_operation_time.txt");
1851 ofstrtime <<
"Computation time :" << std::endl;
1852 ofstrtime << std::endl;
1853 ofstrtime <<
"Algorithm" << std::endl;
1854 ofstrtime <<
" Initialization : "
1858 ofstrtime <<
" + Finding the Intersections : "
1862 ofstrtime <<
" + Compute the Intersections : "
1866 ofstrtime <<
" + Cut the Intersected Facets : "
1870 ofstrtime <<
" + Complete the result : "
1874 ofstrtime <<
" + Create the polyhedron : "
1878 ofstrtime <<
"---------------------------------------"
1880 ofstrtime <<
" Total : "
1885 ofstrtime << std::endl;
1886 ofstrtime << std::endl;
1887 ofstrtime <<
"Details :" << std::endl;
1888 ofstrtime << std::endl;
1889 ofstrtime <<
"Polyedron A :" << std::endl;
1890 ofstrtime <<
"Number of Facets : "
1891 <<
m_pA->size_of_facets() << std::endl;
1892 ofstrtime <<
"Number of Intersected Facets : " << N_IFA << std::endl;
1893 ofstrtime <<
"Number of Facets not in the result : " << N_LFFA << std::endl;
1894 ofstrtime << std::endl;
1895 ofstrtime <<
"Polyedron B :" << std::endl;
1896 ofstrtime <<
"Number of Facets : "
1897 <<
m_pB->size_of_facets() << std::endl;
1898 ofstrtime <<
"Number of Intersected Facets : " << N_IFB << std::endl;
1899 ofstrtime <<
"Number of Facets not in the result : " << N_LFFB << std::endl;
1900 ofstrtime << std::endl;
1901 ofstrtime <<
"Result :" << std::endl;
1902 ofstrtime <<
"Number of Facets : "
1903 << m_out.size_of_facets() << std::endl;
1904 ofstrtime <<
"Number of Facets from A : " << N_FFA << std::endl;
1905 ofstrtime <<
"Number of Facets from B : " << N_FFB << std::endl;
1906 ofstrtime <<
"Number of Created Facets : " << N_CF << std::endl;
1908 #endif // BOOLEAN_OPERATIONS_DEBUG