voidSurface_Modelisation_Plugin::mergeVolumes(MapHandlerGen*mhg){MapHandler<PFP2>*mh=static_cast<MapHandler<PFP2>*>(mhg);PFP2::MAP*map=mh->getMap();constMapParameters&p=h_parameterSet[mhg];if(p.edgeSelector&&!p.edgeSelector->getSelectedCells().empty()&&(p.edgeSelector->getSelectedCells().size()==2)){conststd::vector<Dart>&selectedDarts=p.edgeSelector->getSelectedCells();Dartd=selectedDarts[0];Darte=selectedDarts[1];inti=1;intj=1;while(map->phi1(d)!=selectedDarts[0]){i++;d=map->phi1(d);}while(map->phi1(e)!=selectedDarts[1]){j++;e=map->phi1(e);}if(d==e){map->mergeVolumes(selectedDarts[0],selectedDarts[1]);mh->notifyConnectivityModification();}elseQMessageBox::information(0,"Attention","Selected faces should have the same number of edges");}}voidSurface_Modelisation_Plugin::splitSurface(MapHandlerGen*mhg){MapHandler<PFP2>*mh=static_cast<MapHandler<PFP2>*>(mhg);PFP2::MAP*map=mh->getMap();constMapParameters&p=h_parameterSet[mhg];if(p.edgeSelector&&!p.edgeSelector->getSelectedCells().empty()){std::vector<Dart>selectedDarts=p.edgeSelector->getSelectedCells();if(map->checkSimpleOrientedPath(selectedDarts)){map->splitSurface(selectedDarts);mh->notifyConnectivityModification();}elseQMessageBox::information(0,"Attention","To split surface you need to select edges in order and first edge should be connected with last one");}}voidSurface_Modelisation_Plugin::extrudeRegion(MapHandlerGen*mhg){MapHandler<PFP2>*mh=static_cast<MapHandler<PFP2>*>(mhg);PFP2::MAP*map=mh->getMap();MapParameters&p=h_parameterSet[mhg];if(p.faceSelector&&!p.faceSelector->getSelectedCells().empty()){conststd::vector<Dart>&selectedDarts=p.faceSelector->getSelectedCells();Algo::Surface::Modelisation::extrudeRegion<PFP2>(*map,p.positionAttribute,selectedDarts[0],p.faceSelector->getMarker());mh->notifyConnectivityModification();mh->notifyAttributeModification(p.positionAttribute);mh->updateBB(p.positionAttribute);}}/* ------------------- operations with vertices ----------------------------*/voidSurface_Modelisation_Plugin::splitVertex(MapHandlerGen*mhg){MapHandler<PFP2>*mh=static_cast<MapHandler<PFP2>*>(mhg);PFP2::MAP*map=mh->getMap();MapParameters&p=h_parameterSet[mhg];if(p.edgeSelector&&!p.edgeSelector->getSelectedCells().empty()&&(p.edgeSelector->getSelectedCells().size()==2)){conststd::vector<Dart>&selectedEdges=p.edgeSelector->getSelectedCells();Dartd0,d1;unsignedintv00=map->getEmbedding<VERTEX>(selectedEdges[0]);unsignedintv01=map->getEmbedding<VERTEX>(map->phi2(selectedEdges[0]));unsignedintv10=map->getEmbedding<VERTEX>(selectedEdges[1]);unsignedintv11=map->getEmbedding<VERTEX>(map->phi2(selectedEdges[1]));if(v00==v10){d0=selectedEdges[0];d1=selectedEdges[1];}elseif(v00==v11){d0=selectedEdges[0];d1=map->phi2(selectedEdges[1]);}elseif(v01==v10){d0=map->phi2(selectedEdges[0]);d1=selectedEdges[1];}elseif(v01==v11){d0=map->phi2(selectedEdges[0]);d1=map->phi2(selectedEdges[1]);}else{QMessageBox::information(0,"Attention","Selected edges don't belong to the same vertex");return;}intn=3;PFP2::VEC3pos0=p.positionAttribute[d0]+p.positionAttribute[map->phi1(d0)];Dartd=map->phi_1(d0);while(d!=map->phi2(d1)){pos0+=p.positionAttribute[d];d=map->phi_1(map->phi2(d));n++;}pos0+=p.positionAttribute[d];pos0=pos0/n;n=3;PFP2::VEC3pos1=p.positionAttribute[d1]+p.positionAttribute[map->phi1(d1)];d=map->phi_1(d1);while(d!=map->phi2(d0)){pos1+=p.positionAttribute[d];d=map->phi_1(map->phi2(d));n++;}pos1+=p.positionAttribute[d];pos1=pos1/n;map->splitVertex(d0,d1);p.positionAttribute[d0]=pos0;p.positionAttribute[d1]=pos1;mh->notifyAttributeModification(p.positionAttribute);mh->notifyConnectivityModification();}}voidSurface_Modelisation_Plugin::deleteVertex(MapHandlerGen*mhg){MapHandler<PFP2>*mh=static_cast<MapHandler<PFP2>*>(mhg);PFP2::MAP*map=mh->getMap();constMapParameters&p=h_parameterSet[mhg];if(p.vertexSelector&&!p.vertexSelector->getSelectedCells().empty()){conststd::vector<Dart>&darts=p.vertexSelector->getSelectedCells();map->deleteVertex(darts[0]);mh->notifyAttributeModification(p.positionAttribute);mh->notifyConnectivityModification();}}/* ------------------- operations with edges ----------------------------*/voidSurface_Modelisation_Plugin::cutEdge(MapHandlerGen*mhg){MapHandler<PFP2>*mh=static_cast<MapHandler<PFP2>*>(mhg);PFP2::MAP*map=mh->getMap();MapParameters&p=h_parameterSet[mhg];if(p.edgeSelector&&!p.edgeSelector->getSelectedCells().empty()){conststd::vector<Dart>&edge=p.edgeSelector->getSelectedCells();map->cutEdge(edge[0]);p.positionAttribute[map->phi1(edge[0])]=(p.positionAttribute[edge[0]]+p.positionAttribute[map->phi1(map->phi1(edge[0]))])/2;mh->notifyAttributeModification(p.positionAttribute);mh->notifyConnectivityModification();}}voidSurface_Modelisation_Plugin::uncutEdge(MapHandlerGen*mhg){MapHandler<PFP2>*mh=static_cast<MapHandler<PFP2>*>(mhg);PFP2::MAP*map=mh->getMap();constMapParameters&p=h_parameterSet[mhg];if(p.edgeSelector&&!p.edgeSelector->getSelectedCells().empty()){conststd::vector<Dart>&edge=p.edgeSelector->getSelectedCells();if(!map->uncutEdge(edge[0]))map->uncutEdge(map->phi2(edge[0]));mh->notifyAttributeModification(p.positionAttribute);mh->notifyConnectivityModification();}}voidSurface_Modelisation_Plugin::collapseEdge(MapHandlerGen*mhg){MapHandler<PFP2>*mh=static_cast<MapHandler<PFP2>*>(mhg);PFP2::MAP*map=mh->getMap();constMapParameters&p=h_parameterSet[mhg];if(p.edgeSelector&&!p.edgeSelector->getSelectedCells().empty()){conststd::vector<Dart>&edge=p.edgeSelector->getSelectedCells();map->collapseEdge(edge[0]);mh->notifyAttributeModification(p.positionAttribute);mh->notifyConnectivityModification();}

}voidSurface_Modelisation_Plugin::flipBackEdge(MapHandlerGen*mhg){MapHandler<PFP2>*mh=static_cast<MapHandler<PFP2>*>(mhg);PFP2::MAP*map=mh->getMap();constMapParameters&p=h_parameterSet[mhg];if(p.edgeSelector&&!p.edgeSelector->getSelectedCells().empty()){conststd::vector<Dart>&edge=p.edgeSelector->getSelectedCells();map->flipBackEdge(edge[0]);mh->notifyConnectivityModification();}}/* ------------------- operations with faces ----------------------------*/voidSurface_Modelisation_Plugin::splitFace(MapHandlerGen*mhg){MapHandler<PFP2>*mh=static_cast<MapHandler<PFP2>*>(mhg);PFP2::MAP*map=mh->getMap();constMapParameters&p=h_parameterSet[mhg];if(p.vertexSelector&&!p.vertexSelector->getSelectedCells().empty()&&(p.vertexSelector->getSelectedCells().size()==2)){conststd::vector<Dart>&selectedDarts=p.vertexSelector->getSelectedCells();boolsameFace=false;Dartd=selectedDarts[0];Dartit=d;Dartit2;do{Darte=selectedDarts[1];it2=e;do{if(map->sameFace(it,it2)){sameFace=true;break;}it2=map->phi2(map->phi_1(it2));}while(it2!=e);if(sameFace)break;it=map->phi2(map->phi_1(it));}while(it!=d);if(sameFace){map->splitFace(it,it2);mh->notifyConnectivityModification();}elseQMessageBox::information(0,"Attention","Selected points don't belong to the same face");}elseQMessageBox::information(0,"Attention","To split a face select 2 points of the same face");}voidSurface_Modelisation_Plugin::mergeFaces(MapHandlerGen*mhg){MapHandler<PFP2>*mh=static_cast<MapHandler<PFP2>*>(mhg);PFP2::MAP*map=mh->getMap();constMapParameters&p=h_parameterSet[mhg];if(p.edgeSelector&&!p.edgeSelector->getSelectedCells().empty()){conststd::vector<Dart>&edge=p.edgeSelector->getSelectedCells();map->mergeFaces(edge[0]);mh->notifyConnectivityModification();}}