1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "InterpKernelGeo2DQuadraticPolygon.hxx"
22 #include "InterpKernelGeo2DElementaryEdge.hxx"
23 #include "InterpKernelGeo2DEdgeArcCircle.hxx"
24 #include "InterpKernelGeo2DAbstractEdge.hxx"
25 #include "InterpKernelGeo2DEdgeLin.hxx"
26 #include "InterpKernelGeo2DBounds.hxx"
27 #include "InterpKernelGeo2DEdge.txx"
29 #include "NormalizedUnstructuredMesh.hxx"
37 using namespace INTERP_KERNEL;
39 namespace INTERP_KERNEL
41 const unsigned MAX_SIZE_OF_LINE_XFIG_FILE=1024;
44 QuadraticPolygon::QuadraticPolygon(const char *file)
46 char currentLine[MAX_SIZE_OF_LINE_XFIG_FILE];
47 std::ifstream stream(file);
48 stream.exceptions(std::ios_base::eofbit);
52 stream.getline(currentLine,MAX_SIZE_OF_LINE_XFIG_FILE);
53 while(strcmp(currentLine,"1200 2")!=0);
56 Edge *newEdge=Edge::BuildFromXfigLine(stream);
58 newEdge->changeStartNodeWith(back()->getEndNode());
63 catch(std::ifstream::failure&)
66 front()->changeStartNodeWith(back()->getEndNode());
69 QuadraticPolygon::~QuadraticPolygon()
73 QuadraticPolygon *QuadraticPolygon::BuildLinearPolygon(std::vector<Node *>& nodes)
75 QuadraticPolygon *ret(new QuadraticPolygon);
76 std::size_t size=nodes.size();
77 for(std::size_t i=0;i<size;i++)
79 ret->pushBack(new EdgeLin(nodes[i],nodes[(i+1)%size]));
85 QuadraticPolygon *QuadraticPolygon::BuildArcCirclePolygon(std::vector<Node *>& nodes)
87 QuadraticPolygon *ret(new QuadraticPolygon);
88 std::size_t size=nodes.size();
89 for(std::size_t i=0;i<size/2;i++)
93 e1=new EdgeLin(nodes[i],nodes[i+size/2]);
94 e2=new EdgeLin(nodes[i+size/2],nodes[(i+1)%(size/2)]);
95 SegSegIntersector inters(*e1,*e2);
96 bool colinearity=inters.areColinears();
99 ret->pushBack(new EdgeLin(nodes[i],nodes[(i+1)%(size/2)]));
101 ret->pushBack(new EdgeArcCircle(nodes[i],nodes[i+size/2],nodes[(i+1)%(size/2)]));
102 nodes[i]->decrRef(); nodes[i+size/2]->decrRef();
107 Edge *QuadraticPolygon::BuildLinearEdge(std::vector<Node *>& nodes)
110 throw INTERP_KERNEL::Exception("QuadraticPolygon::BuildLinearEdge : input vector is expected to be of size 2 !");
111 Edge *ret(new EdgeLin(nodes[0],nodes[1]));
112 nodes[0]->decrRef(); nodes[1]->decrRef();
116 Edge *QuadraticPolygon::BuildArcCircleEdge(std::vector<Node *>& nodes)
119 throw INTERP_KERNEL::Exception("QuadraticPolygon::BuildArcCircleEdge : input vector is expected to be of size 3 !");
120 EdgeLin *e1(new EdgeLin(nodes[0],nodes[2])),*e2(new EdgeLin(nodes[2],nodes[1]));
121 SegSegIntersector inters(*e1,*e2);
122 bool colinearity=inters.areColinears();
123 delete e1; delete e2;
126 ret=new EdgeLin(nodes[0],nodes[1]);
128 ret=new EdgeArcCircle(nodes[0],nodes[2],nodes[1]);
129 nodes[0]->decrRef(); nodes[1]->decrRef(); nodes[2]->decrRef();
133 void QuadraticPolygon::BuildDbgFile(const std::vector<Node *>& nodes, const char *fileName)
135 std::ofstream file(fileName);
136 file << std::setprecision(16);
137 file << " double coords[]=" << std::endl << " { ";
138 for(std::vector<Node *>::const_iterator iter=nodes.begin();iter!=nodes.end();iter++)
140 if(iter!=nodes.begin())
141 file << "," << std::endl << " ";
142 file << (*(*iter))[0] << ", " << (*(*iter))[1];
144 file << "};" << std::endl;
147 void QuadraticPolygon::closeMe() const
149 if(!front()->changeStartNodeWith(back()->getEndNode()))
150 throw(Exception("big error: not closed polygon..."));
153 void QuadraticPolygon::circularPermute()
155 if(_sub_edges.size()>1)
157 ElementaryEdge *first=_sub_edges.front();
158 _sub_edges.pop_front();
159 _sub_edges.push_back(first);
163 bool QuadraticPolygon::isButterflyAbs()
165 INTERP_KERNEL::Bounds b;
167 b.prepareForAggregation();
169 double dimChar=b.getCaracteristicDim();
170 b.getBarycenter(xBary,yBary);
171 applyGlobalSimilarity(xBary,yBary,dimChar);
173 return isButterfly();
176 bool QuadraticPolygon::isButterfly() const
178 for(std::list<ElementaryEdge *>::const_iterator it=_sub_edges.begin();it!=_sub_edges.end();it++)
180 Edge *e1=(*it)->getPtr();
181 std::list<ElementaryEdge *>::const_iterator it2=it;
183 for(;it2!=_sub_edges.end();it2++)
185 MergePoints commonNode;
186 ComposedEdge *outVal1=new ComposedEdge;
187 ComposedEdge *outVal2=new ComposedEdge;
188 Edge *e2=(*it2)->getPtr();
189 if(e1->intersectWith(e2,commonNode,*outVal1,*outVal2))
202 void QuadraticPolygon::dumpInXfigFileWithOther(const ComposedEdge& other, const char *fileName) const
204 std::ofstream file(fileName);
205 const int resolution=1200;
207 box.prepareForAggregation();
209 other.fillBounds(box);
210 dumpInXfigFile(file,resolution,box);
211 other.ComposedEdge::dumpInXfigFile(file,resolution,box);
214 void QuadraticPolygon::dumpInXfigFile(const char *fileName) const
216 std::ofstream file(fileName);
217 const int resolution=1200;
219 box.prepareForAggregation();
221 dumpInXfigFile(file,resolution,box);
224 void QuadraticPolygon::dumpInXfigFile(std::ostream& stream, int resolution, const Bounds& box) const
226 stream << "#FIG 3.2 Produced by xfig version 3.2.5-alpha5" << std::endl;
227 stream << "Landscape" << std::endl;
228 stream << "Center" << std::endl;
229 stream << "Metric" << std::endl;
230 stream << "Letter" << std::endl;
231 stream << "100.00" << std::endl;
232 stream << "Single" << std::endl;
233 stream << "-2" << std::endl;
234 stream << resolution << " 2" << std::endl;
235 ComposedEdge::dumpInXfigFile(stream,resolution,box);
239 * Warning contrary to intersectWith method this method is \b NOT const. 'this' and 'other' are modified after call of this method.
241 double QuadraticPolygon::intersectWithAbs(QuadraticPolygon& other)
243 double ret=0.,xBaryBB,yBaryBB;
244 double fact=normalize(&other,xBaryBB,yBaryBB);
245 std::vector<QuadraticPolygon *> polygs=intersectMySelfWith(other);
246 for(std::vector<QuadraticPolygon *>::iterator iter=polygs.begin();iter!=polygs.end();iter++)
248 ret+=fabs((*iter)->getArea());
251 return ret*fact*fact;
255 * This method splits 'this' with 'other' into smaller pieces localizable. 'mapThis' is a map that gives the correspondance
256 * between nodes contained in 'this' and node ids in a global mesh.
257 * In the same way, 'mapOther' gives the correspondance between nodes contained in 'other' and node ids in a
258 * global mesh from wich 'other' is extracted.
259 * This method has 1 out paramater : 'edgesThis', After the call of this method, it contains the nodal connectivity (including type)
260 * of 'this' into globlal "this mesh".
261 * This method has 2 in/out parameters : 'subDivOther' and 'addCoo'.'otherEdgeIds' is useful to put values in
262 * 'edgesThis', 'subDivOther' and 'addCoo'.
263 * Size of 'otherEdgeIds' has to be equal to number of ElementaryEdges in 'other'. No check of that will be done.
264 * The term 'abs' in the name recalls that we normalize the mesh (spatially) so that node coordinates fit into [0;1].
265 * @param offset1 is the number of nodes contained in global mesh from which 'this' is extracted.
266 * @param offset2 is the sum of nodes contained in global mesh from which 'this' is extracted and 'other' is extracted.
267 * @param edgesInOtherColinearWithThis will be appended at the end of the vector with colinear edge ids of other (if any)
268 * @param otherEdgeIds is a vector with the same size than other before calling this method. It gives in the same order
269 * the cell id in global other mesh.
271 void QuadraticPolygon::splitAbs(QuadraticPolygon& other,
272 const std::map<INTERP_KERNEL::Node *,int>& mapThis, const std::map<INTERP_KERNEL::Node *,int>& mapOther,
273 int offset1, int offset2 ,
274 const std::vector<int>& otherEdgeIds,
275 std::vector<int>& edgesThis, int cellIdThis,
276 std::vector< std::vector<int> >& edgesInOtherColinearWithThis, std::vector< std::vector<int> >& subDivOther,
277 std::vector<double>& addCoo)
279 double xBaryBB, yBaryBB;
280 double fact=normalizeExt(&other, xBaryBB, yBaryBB);
282 IteratorOnComposedEdge it1(this),it3(&other);
284 ComposedEdge *c1=new ComposedEdge;
285 ComposedEdge *c2=new ComposedEdge;
287 std::map<INTERP_KERNEL::Node *,int> mapAddCoo;
288 for(it3.first();!it3.finished();it3.next(),i++)//iteration over 'other' _sub_edges
290 QuadraticPolygon otherTmp;
291 ElementaryEdge* curE3=it3.current();
292 otherTmp.pushBack(new ElementaryEdge(curE3->getPtr(),curE3->getDirection())); curE3->getPtr()->incrRef();
293 IteratorOnComposedEdge it2(&otherTmp);
294 for(it2.first();!it2.finished();it2.next())//iteration on subedges of 'other->_sub_edge'
296 ElementaryEdge* curE2=it2.current();
297 if(!curE2->isThereStartPoint())
300 it1=curE2->getIterator();
301 for(;!it1.finished();)//iteration over 'this' _sub_edges
303 ElementaryEdge* curE1=it1.current();
305 if(curE1->getPtr()->intersectWith(curE2->getPtr(),merge,*c1,*c2))
307 if(!curE1->getDirection()) c1->reverse();
308 if(!curE2->getDirection()) c2->reverse();
309 UpdateNeighbours(merge,it1,it2,c1,c2);
310 //Substitution of simple edge by sub-edges.
311 delete curE1; // <-- destroying simple edge coming from pol1
312 delete curE2; // <-- destroying simple edge coming from pol2
313 it1.insertElemEdges(c1,true);// <-- 2nd param is true to go next.
314 it2.insertElemEdges(c2,false);// <-- 2nd param is false to avoid to go next.
317 it1.assignMySelfToAllElems(c2);//To avoid that others
325 UpdateNeighbours(merge,it1,it2,curE1,curE2);
330 if(otherTmp.presenceOfOn())
331 edgesInOtherColinearWithThis[otherEdgeIds[i]].push_back(cellIdThis);
332 if(otherTmp._sub_edges.size()>1)
334 for(std::list<ElementaryEdge *>::const_iterator it=otherTmp._sub_edges.begin();it!=otherTmp._sub_edges.end();it++)
335 (*it)->fillGlobalInfoAbs2(mapThis,mapOther,offset1,offset2,/**/fact,xBaryBB,yBaryBB,/**/subDivOther[otherEdgeIds[i]],addCoo,mapAddCoo);
341 for(std::list<ElementaryEdge *>::const_iterator it=_sub_edges.begin();it!=_sub_edges.end();it++)
342 (*it)->fillGlobalInfoAbs(mapThis,mapOther,offset1,offset2,/**/fact,xBaryBB,yBaryBB,/**/edgesThis,addCoo,mapAddCoo);
347 * This method builds 'this' from its descending conn stored in crude mode (MEDCoupling).
348 * Descending conn is in FORTRAN relative mode in order to give the
349 * orientation of edge (see buildDescendingConnectivity2() method).
350 * See appendEdgeFromCrudeDataArray() for params description.
352 void QuadraticPolygon::buildFromCrudeDataArray(const std::map<int,INTERP_KERNEL::Node *>& mapp, bool isQuad, const int *nodalBg, const double *coords,
353 const int *descBg, const int *descEnd, const std::vector<std::vector<int> >& intersectEdges)
355 std::size_t nbOfSeg=std::distance(descBg,descEnd);
356 for(std::size_t i=0;i<nbOfSeg;i++)
358 appendEdgeFromCrudeDataArray(i,mapp,isQuad,nodalBg,coords,descBg,descEnd,intersectEdges);
362 void QuadraticPolygon::appendEdgeFromCrudeDataArray(std::size_t edgePos, const std::map<int,INTERP_KERNEL::Node *>& mapp, bool isQuad,
363 const int *nodalBg, const double *coords,
364 const int *descBg, const int *descEnd, const std::vector<std::vector<int> >& intersectEdges)
368 bool direct=descBg[edgePos]>0;
369 int edgeId=abs(descBg[edgePos])-1; // back to C indexing mode
370 const std::vector<int>& subEdge=intersectEdges[edgeId];
371 std::size_t nbOfSubEdges=subEdge.size()/2;
372 for(std::size_t j=0;j<nbOfSubEdges;j++)
373 appendSubEdgeFromCrudeDataArray(0,j,direct,edgeId,subEdge,mapp);
377 std::size_t nbOfSeg=std::distance(descBg,descEnd);
378 const double *st=coords+2*(nodalBg[edgePos]);
379 INTERP_KERNEL::Node *st0=new INTERP_KERNEL::Node(st[0],st[1]);
380 const double *endd=coords+2*(nodalBg[(edgePos+1)%nbOfSeg]);
381 INTERP_KERNEL::Node *endd0=new INTERP_KERNEL::Node(endd[0],endd[1]);
382 const double *middle=coords+2*(nodalBg[edgePos+nbOfSeg]);
383 INTERP_KERNEL::Node *middle0=new INTERP_KERNEL::Node(middle[0],middle[1]);
385 e1=new EdgeLin(st0,middle0);
386 e2=new EdgeLin(middle0,endd0);
387 SegSegIntersector inters(*e1,*e2);
388 bool colinearity=inters.areColinears();
389 delete e1; delete e2;
391 bool direct=descBg[edgePos]>0;
392 int edgeId=abs(descBg[edgePos])-1;
393 const std::vector<int>& subEdge=intersectEdges[edgeId];
394 std::size_t nbOfSubEdges=subEdge.size()/2;
397 for(std::size_t j=0;j<nbOfSubEdges;j++)
398 appendSubEdgeFromCrudeDataArray(0,j,direct,edgeId,subEdge,mapp);
402 Edge *e=new EdgeArcCircle(st0,middle0,endd0,true);
403 for(std::size_t j=0;j<nbOfSubEdges;j++)
404 appendSubEdgeFromCrudeDataArray(e,j,direct,edgeId,subEdge,mapp);
407 st0->decrRef(); endd0->decrRef(); middle0->decrRef();
411 void QuadraticPolygon::appendSubEdgeFromCrudeDataArray(Edge *baseEdge, std::size_t j, bool direct, int edgeId, const std::vector<int>& subEdge, const std::map<int,INTERP_KERNEL::Node *>& mapp)
413 std::size_t nbOfSubEdges=subEdge.size()/2;
415 {//it is not a quadratic subedge
416 Node *start=(*mapp.find(direct?subEdge[2*j]:subEdge[2*nbOfSubEdges-2*j-1])).second;
417 Node *end=(*mapp.find(direct?subEdge[2*j+1]:subEdge[2*nbOfSubEdges-2*j-2])).second;
418 ElementaryEdge *e=ElementaryEdge::BuildEdgeFromCrudeDataArray(true,start,end);
422 {//it is a quadratic subedge
423 Node *start=(*mapp.find(direct?subEdge[2*j]:subEdge[2*nbOfSubEdges-2*j-1])).second;
424 Node *end=(*mapp.find(direct?subEdge[2*j+1]:subEdge[2*nbOfSubEdges-2*j-2])).second;
425 Edge *ee=baseEdge->buildEdgeLyingOnMe(start,end);
426 ElementaryEdge *eee=new ElementaryEdge(ee,true);
432 * This method builds from descending conn of a quadratic polygon stored in crude mode (MEDCoupling). Descending conn is in FORTRAN relative mode in order to give the
433 * orientation of edge.
435 void QuadraticPolygon::buildFromCrudeDataArray2(const std::map<int,INTERP_KERNEL::Node *>& mapp, bool isQuad, const int *nodalBg, const double *coords, const int *descBg, const int *descEnd, const std::vector<std::vector<int> >& intersectEdges,
436 const INTERP_KERNEL::QuadraticPolygon& pol1, const int *descBg1, const int *descEnd1, const std::vector<std::vector<int> >& intersectEdges1,
437 const std::vector< std::vector<int> >& colinear1,
438 std::map<int,std::vector<INTERP_KERNEL::ElementaryEdge *> >& alreadyExistingIn2)
440 std::size_t nbOfSeg=std::distance(descBg,descEnd);
441 for(std::size_t i=0;i<nbOfSeg;i++)//loop over all edges of pol2
443 bool direct=descBg[i]>0;
444 int edgeId=abs(descBg[i])-1;//current edge id of pol2
445 std::map<int,std::vector<INTERP_KERNEL::ElementaryEdge *> >::const_iterator it1=alreadyExistingIn2.find(descBg[i]),it2=alreadyExistingIn2.find(-descBg[i]);
446 if(it1!=alreadyExistingIn2.end() || it2!=alreadyExistingIn2.end())
448 bool sameDir=(it1!=alreadyExistingIn2.end());
449 const std::vector<INTERP_KERNEL::ElementaryEdge *>& edgesAlreadyBuilt=sameDir?(*it1).second:(*it2).second;
452 for(std::vector<INTERP_KERNEL::ElementaryEdge *>::const_iterator it3=edgesAlreadyBuilt.begin();it3!=edgesAlreadyBuilt.end();it3++)
454 Edge *ee=(*it3)->getPtr(); ee->incrRef();
455 pushBack(new ElementaryEdge(ee,(*it3)->getDirection()));
460 for(std::vector<INTERP_KERNEL::ElementaryEdge *>::const_reverse_iterator it4=edgesAlreadyBuilt.rbegin();it4!=edgesAlreadyBuilt.rend();it4++)
462 Edge *ee=(*it4)->getPtr(); ee->incrRef();
463 pushBack(new ElementaryEdge(ee,!(*it4)->getDirection()));
468 bool directos=colinear1[edgeId].empty();
469 std::vector<std::pair<int,std::pair<bool,int> > > idIns1;
472 {// if the current edge of pol2 has one or more colinear edges part into pol1
473 const std::vector<int>& c=colinear1[edgeId];
474 std::size_t nbOfEdgesIn1=std::distance(descBg1,descEnd1);
475 for(std::size_t j=0;j<nbOfEdgesIn1;j++)
477 int edgeId1=abs(descBg1[j])-1;
478 if(std::find(c.begin(),c.end(),edgeId1)!=c.end())
480 idIns1.push_back(std::pair<int,std::pair<bool,int> >(edgeId1,std::pair<bool,int>(descBg1[j]>0,offset1)));// it exists an edge into pol1 given by tuple (idIn1,direct1) that is colinear at edge 'edgeId' in pol2
481 //std::pair<edgeId1); direct1=descBg1[j]>0;
483 offset1+=intersectEdges1[edgeId1].size()/2;//offset1 is used to find the INTERP_KERNEL::Edge * instance into pol1 that will be part of edge into pol2
485 directos=idIns1.empty();
488 {//no subpart of edge 'edgeId' of pol2 is in pol1 so let's operate the same thing that QuadraticPolygon::buildFromCrudeDataArray method
489 std::size_t oldSz=_sub_edges.size();
490 appendEdgeFromCrudeDataArray(i,mapp,isQuad,nodalBg,coords,descBg,descEnd,intersectEdges);
491 std::size_t newSz=_sub_edges.size();
492 std::size_t zeSz=newSz-oldSz;
493 alreadyExistingIn2[descBg[i]].resize(zeSz);
494 std::list<ElementaryEdge *>::const_reverse_iterator it5=_sub_edges.rbegin();
495 for(std::size_t p=0;p<zeSz;p++,it5++)
496 alreadyExistingIn2[descBg[i]][zeSz-p-1]=*it5;
499 {//there is subpart of edge 'edgeId' of pol2 inside pol1
500 const std::vector<int>& subEdge=intersectEdges[edgeId];
501 std::size_t nbOfSubEdges=subEdge.size()/2;
502 for(std::size_t j=0;j<nbOfSubEdges;j++)
504 int idBg=direct?subEdge[2*j]:subEdge[2*nbOfSubEdges-2*j-1];
505 int idEnd=direct?subEdge[2*j+1]:subEdge[2*nbOfSubEdges-2*j-2];
506 bool direction11,found=false;
507 bool direct1;//store if needed the direction in 1
509 std::size_t nbOfSubEdges1;
510 for(std::vector<std::pair<int,std::pair<bool,int> > >::const_iterator it=idIns1.begin();it!=idIns1.end() && !found;it++)
512 int idIn1=(*it).first;//store if needed the cell id in 1
513 direct1=(*it).second.first;
514 offset1=(*it).second.second;
515 const std::vector<int>& subEdge1PossiblyAlreadyIn1=intersectEdges1[idIn1];
516 nbOfSubEdges1=subEdge1PossiblyAlreadyIn1.size()/2;
518 for(std::size_t k=0;k<nbOfSubEdges1 && !found;k++)
519 {//perform a loop on all subedges of pol1 that includes edge 'edgeId' of pol2. For the moment we iterate only on subedges of ['idIn1']... To improve
520 if(subEdge1PossiblyAlreadyIn1[2*k]==idBg && subEdge1PossiblyAlreadyIn1[2*k+1]==idEnd)
521 { direction11=true; found=true; }
522 else if(subEdge1PossiblyAlreadyIn1[2*k]==idEnd && subEdge1PossiblyAlreadyIn1[2*k+1]==idBg)
523 { direction11=false; found=true; }
529 {//the current subedge of edge 'edgeId' of pol2 is not a part of the colinear edge 'idIn1' of pol1 -> build new Edge instance
530 //appendEdgeFromCrudeDataArray(j,mapp,isQuad,nodalBg,coords,descBg,descEnd,intersectEdges);
531 Node *start=(*mapp.find(idBg)).second;
532 Node *end=(*mapp.find(idEnd)).second;
533 ElementaryEdge *e=ElementaryEdge::BuildEdgeFromCrudeDataArray(true,start,end);
535 alreadyExistingIn2[descBg[i]].push_back(e);
538 {//the current subedge of edge 'edgeId' of pol2 is part of the colinear edge 'idIn1' of pol1 -> reuse Edge instance of pol1
539 ElementaryEdge *e=pol1[offset1+(direct1?offset2:nbOfSubEdges1-offset2-1)];
540 Edge *ee=e->getPtr();
542 ElementaryEdge *e2=new ElementaryEdge(ee,!(direct1^direction11));
544 alreadyExistingIn2[descBg[i]].push_back(e2);
552 * Method expected to be called on pol2. Every params not suffixed by numbered are supposed to refer to pol2 (this).
553 * Method to find edges that are ON.
555 void QuadraticPolygon::updateLocOfEdgeFromCrudeDataArray2(const int *descBg, const int *descEnd, const std::vector<std::vector<int> >& intersectEdges,
556 const INTERP_KERNEL::QuadraticPolygon& pol1, const int *descBg1, const int *descEnd1,
557 const std::vector<std::vector<int> >& intersectEdges1, const std::vector< std::vector<int> >& colinear1) const
559 std::size_t nbOfSeg=std::distance(descBg,descEnd);
560 for(std::size_t i=0;i<nbOfSeg;i++)//loop over all edges of pol2
562 bool direct=descBg[i]>0;
563 int edgeId=abs(descBg[i])-1;//current edge id of pol2
564 const std::vector<int>& c=colinear1[edgeId];
567 const std::vector<int>& subEdge=intersectEdges[edgeId];
568 std::size_t nbOfSubEdges=subEdge.size()/2;
570 std::size_t nbOfEdgesIn1=std::distance(descBg1,descEnd1);
572 for(std::size_t j=0;j<nbOfEdgesIn1;j++)
574 int edgeId1=abs(descBg1[j])-1;
575 if(std::find(c.begin(),c.end(),edgeId1)!=c.end())
577 for(std::size_t k=0;k<nbOfSubEdges;k++)
579 int idBg=direct?subEdge[2*k]:subEdge[2*nbOfSubEdges-2*k-1];
580 int idEnd=direct?subEdge[2*k+1]:subEdge[2*nbOfSubEdges-2*k-2];
582 bool direct1=descBg1[j]>0;
583 const std::vector<int>& subEdge1PossiblyAlreadyIn1=intersectEdges1[idIn1];
584 std::size_t nbOfSubEdges1=subEdge1PossiblyAlreadyIn1.size()/2;
587 for(std::size_t kk=0;kk<nbOfSubEdges1 && !found;kk++)
589 found=(subEdge1PossiblyAlreadyIn1[2*kk]==idBg && subEdge1PossiblyAlreadyIn1[2*kk+1]==idEnd) || (subEdge1PossiblyAlreadyIn1[2*kk]==idEnd && subEdge1PossiblyAlreadyIn1[2*kk+1]==idBg);
595 ElementaryEdge *e=pol1[offset1+(direct1?offset2:nbOfSubEdges1-offset2-1)];
596 e->getPtr()->declareOn();
600 offset1+=intersectEdges1[edgeId1].size()/2;//offset1 is used to find the INTERP_KERNEL::Edge * instance into pol1 that will be part of edge into pol2
605 void QuadraticPolygon::appendCrudeData(const std::map<INTERP_KERNEL::Node *,int>& mapp, double xBary, double yBary, double fact, int offset, std::vector<double>& addCoordsQuadratic, std::vector<int>& conn, std::vector<int>& connI) const
608 bool presenceOfQuadratic=presenceOfQuadraticEdge();
609 conn.push_back(presenceOfQuadratic?NORM_QPOLYG:NORM_POLYGON);
610 for(std::list<ElementaryEdge *>::const_iterator it=_sub_edges.begin();it!=_sub_edges.end();it++)
613 tmp=(*it)->getStartNode();
614 std::map<INTERP_KERNEL::Node *,int>::const_iterator it1=mapp.find(tmp);
615 conn.push_back((*it1).second);
618 if(presenceOfQuadratic)
621 int off=offset+((int)addCoordsQuadratic.size())/2;
622 for(std::list<ElementaryEdge *>::const_iterator it=_sub_edges.begin();it!=_sub_edges.end();it++,j++,nbOfNodesInPg++)
624 INTERP_KERNEL::Node *node=(*it)->getPtr()->buildRepresentantOfMySelf();
625 node->unApplySimilarity(xBary,yBary,fact);
626 addCoordsQuadratic.push_back((*node)[0]);
627 addCoordsQuadratic.push_back((*node)[1]);
628 conn.push_back(off+j);
632 connI.push_back(connI.back()+nbOfNodesInPg+1);
636 * This method make the hypothesis that 'this' and 'other' are splited at the minimum into edges that are fully IN, OUT or ON.
637 * This method returns newly created polygons in 'conn' and 'connI' and the corresponding ids ('idThis','idOther') are stored respectively into 'nbThis' and 'nbOther'.
638 * @param [in,out] edgesThis, parameter that keep informed the caller abount the edges in this not shared by the result of intersection of \a this with \a other
639 * @param [in,out] edgesBoundaryOther, parameter that strores all edges in result of intersection that are not
641 void QuadraticPolygon::buildPartitionsAbs(QuadraticPolygon& other, std::set<INTERP_KERNEL::Edge *>& edgesThis, std::set<INTERP_KERNEL::Edge *>& edgesBoundaryOther, const std::map<INTERP_KERNEL::Node *,int>& mapp, int idThis, int idOther, int offset, std::vector<double>& addCoordsQuadratic, std::vector<int>& conn, std::vector<int>& connI, std::vector<int>& nbThis, std::vector<int>& nbOther)
643 double xBaryBB, yBaryBB;
644 double fact=normalizeExt(&other, xBaryBB, yBaryBB);
645 //Locate 'this' relative to 'other'
646 other.performLocatingOperationSlow(*this); // without any assumption
647 std::vector<QuadraticPolygon *> res=buildIntersectionPolygons(other,*this);
648 for(std::vector<QuadraticPolygon *>::iterator it=res.begin();it!=res.end();it++)
650 (*it)->appendCrudeData(mapp,xBaryBB,yBaryBB,fact,offset,addCoordsQuadratic,conn,connI);
651 INTERP_KERNEL::IteratorOnComposedEdge it1(*it);
652 for(it1.first();!it1.finished();it1.next())
654 Edge *e=it1.current()->getPtr();
655 if(edgesThis.find(e)!=edgesThis.end())
659 if(edgesBoundaryOther.find(e)!=edgesBoundaryOther.end())
660 edgesBoundaryOther.erase(e);
662 edgesBoundaryOther.insert(e);
665 nbThis.push_back(idThis);
666 nbOther.push_back(idOther);
669 unApplyGlobalSimilarityExt(other,xBaryBB,yBaryBB,fact);
673 * Warning This method is \b NOT const. 'this' and 'other' are modified after call of this method.
674 * 'other' is a QuadraticPolygon of \b non closed edges.
676 double QuadraticPolygon::intersectWithAbs1D(QuadraticPolygon& other, bool& isColinear)
678 double ret = 0., xBaryBB, yBaryBB;
679 double fact = normalize(&other, xBaryBB, yBaryBB);
681 QuadraticPolygon cpyOfThis(*this);
682 QuadraticPolygon cpyOfOther(other);
684 SplitPolygonsEachOther(cpyOfThis, cpyOfOther, nbOfSplits);
685 //At this point cpyOfThis and cpyOfOther have been splited at maximum edge so that in/out can been done.
686 performLocatingOperation(cpyOfOther);
688 for(std::list<ElementaryEdge *>::const_iterator it=cpyOfOther._sub_edges.begin();it!=cpyOfOther._sub_edges.end();it++)
690 switch((*it)->getLoc())
694 ret += fabs((*it)->getPtr()->getCurveLength());
700 ret += fabs((*it)->getPtr()->getCurveLength());
712 * Warning contrary to intersectWith method this method is \b NOT const. 'this' and 'other' are modified after call of this method.
714 double QuadraticPolygon::intersectWithAbs(QuadraticPolygon& other, double* barycenter)
716 double ret=0.,bary[2],area,xBaryBB,yBaryBB;
717 barycenter[0] = barycenter[1] = 0.;
718 double fact=normalize(&other,xBaryBB,yBaryBB);
719 std::vector<QuadraticPolygon *> polygs=intersectMySelfWith(other);
720 for(std::vector<QuadraticPolygon *>::iterator iter=polygs.begin();iter!=polygs.end();iter++)
722 area=fabs((*iter)->getArea());
723 (*iter)->getBarycenter(bary);
726 barycenter[0] += bary[0]*area;
727 barycenter[1] += bary[1]*area;
729 if ( ret > std::numeric_limits<double>::min() )
731 barycenter[0]=barycenter[0]/ret*fact+xBaryBB;
732 barycenter[1]=barycenter[1]/ret*fact+yBaryBB;
735 return ret*fact*fact;
739 * \b WARNING this method is const and other is const too. \b BUT location of Edges in 'this' and 'other' are nevertheless modified.
740 * This is possible because loc attribute in Edge class is mutable.
741 * This implies that if 'this' or/and 'other' are reused for intersect* method initLocations has to be called on each of this/them.
743 double QuadraticPolygon::intersectWith(const QuadraticPolygon& other) const
746 std::vector<QuadraticPolygon *> polygs=intersectMySelfWith(other);
747 for(std::vector<QuadraticPolygon *>::iterator iter=polygs.begin();iter!=polygs.end();iter++)
749 ret+=fabs((*iter)->getArea());
756 * \b WARNING this method is const and other is const too. \b BUT location of Edges in 'this' and 'other' are nevertheless modified.
757 * This is possible because loc attribute in Edge class is mutable.
758 * This implies that if 'this' or/and 'other' are reused for intersect* method initLocations has to be called on each of this/them.
760 double QuadraticPolygon::intersectWith(const QuadraticPolygon& other, double* barycenter) const
762 double ret=0., bary[2];
763 barycenter[0] = barycenter[1] = 0.;
764 std::vector<QuadraticPolygon *> polygs=intersectMySelfWith(other);
765 for(std::vector<QuadraticPolygon *>::iterator iter=polygs.begin();iter!=polygs.end();iter++)
767 double area = fabs((*iter)->getArea());
768 (*iter)->getBarycenter(bary);
771 barycenter[0] += bary[0]*area;
772 barycenter[1] += bary[1]*area;
774 if ( ret > std::numeric_limits<double>::min() )
776 barycenter[0] /= ret;
777 barycenter[1] /= ret;
783 * \b WARNING this method is const and other is const too. \b BUT location of Edges in 'this' and 'other' are nevertheless modified.
784 * This is possible because loc attribute in Edge class is mutable.
785 * This implies that if 'this' or/and 'other' are reused for intersect* method initLocations has to be called on each of this/them.
787 void QuadraticPolygon::intersectForPerimeter(const QuadraticPolygon& other, double& perimeterThisPart, double& perimeterOtherPart, double& perimeterCommonPart) const
789 perimeterThisPart=0.; perimeterOtherPart=0.; perimeterCommonPart=0.;
790 QuadraticPolygon cpyOfThis(*this);
791 QuadraticPolygon cpyOfOther(other); int nbOfSplits=0;
792 SplitPolygonsEachOther(cpyOfThis,cpyOfOther,nbOfSplits);
793 performLocatingOperation(cpyOfOther);
794 other.performLocatingOperation(cpyOfThis);
795 cpyOfThis.dispatchPerimeterExcl(perimeterThisPart,perimeterCommonPart);
796 cpyOfOther.dispatchPerimeterExcl(perimeterOtherPart,perimeterCommonPart);
797 perimeterCommonPart/=2.;
801 * \b WARNING this method is const and other is const too. \b BUT location of Edges in 'this' and 'other' are nevertheless modified.
802 * This is possible because loc attribute in Edge class is mutable.
803 * This implies that if 'this' or/and 'other' are reused for intersect* method initLocations has to be called on each of this/them.
805 * polThis.size()==this->size() and polOther.size()==other.size().
806 * For each ElementaryEdge of 'this', the corresponding contribution in resulting polygon is in 'polThis'.
807 * For each ElementaryEdge of 'other', the corresponding contribution in resulting polygon is in 'polOther'.
808 * As consequence common part are counted twice (in polThis \b and in polOther).
810 void QuadraticPolygon::intersectForPerimeterAdvanced(const QuadraticPolygon& other, std::vector< double >& polThis, std::vector< double >& polOther) const
812 polThis.resize(size());
813 polOther.resize(other.size());
814 IteratorOnComposedEdge it1(const_cast<QuadraticPolygon *>(this));
816 for(it1.first();!it1.finished();it1.next(),edgeId++)
818 ElementaryEdge* curE1=it1.current();
819 QuadraticPolygon cpyOfOther(other);
820 QuadraticPolygon tmp;
821 tmp.pushBack(curE1->clone());
823 SplitPolygonsEachOther(tmp,cpyOfOther,tmp2);
824 other.performLocatingOperation(tmp);
825 tmp.dispatchPerimeter(polThis[edgeId]);
828 IteratorOnComposedEdge it2(const_cast<QuadraticPolygon *>(&other));
830 for(it2.first();!it2.finished();it2.next(),edgeId++)
832 ElementaryEdge* curE2=it2.current();
833 QuadraticPolygon cpyOfThis(*this);
834 QuadraticPolygon tmp;
835 tmp.pushBack(curE2->clone());
837 SplitPolygonsEachOther(tmp,cpyOfThis,tmp2);
838 performLocatingOperation(tmp);
839 tmp.dispatchPerimeter(polOther[edgeId]);
845 * numberOfCreatedPointsPerEdge is resized to the number of edges of 'this'.
846 * This method returns in ordered maner the number of newly created points per edge.
847 * This method performs a split process between 'this' and 'other' that gives the result PThis.
848 * Then for each edges of 'this' this method counts how many edges in Pthis have the same id.
850 void QuadraticPolygon::intersectForPoint(const QuadraticPolygon& other, std::vector< int >& numberOfCreatedPointsPerEdge) const
852 numberOfCreatedPointsPerEdge.resize(size());
853 IteratorOnComposedEdge it1(const_cast<QuadraticPolygon *>(this));
855 for(it1.first();!it1.finished();it1.next(),edgeId++)
857 ElementaryEdge* curE1=it1.current();
858 QuadraticPolygon cpyOfOther(other);
859 QuadraticPolygon tmp;
860 tmp.pushBack(curE1->clone());
862 SplitPolygonsEachOther(tmp,cpyOfOther,tmp2);
863 numberOfCreatedPointsPerEdge[edgeId]=tmp.recursiveSize()-1;
868 * \b WARNING this method is const and other is const too. \b BUT location of Edges in 'this' and 'other' are nevertheless modified.
869 * This is possible because loc attribute in Edge class is mutable.
870 * This implies that if 'this' or/and 'other' are reused for intersect* method initLocations has to be called on each of this/them.
872 std::vector<QuadraticPolygon *> QuadraticPolygon::intersectMySelfWith(const QuadraticPolygon& other) const
874 QuadraticPolygon cpyOfThis(*this);
875 QuadraticPolygon cpyOfOther(other); int nbOfSplits=0;
876 SplitPolygonsEachOther(cpyOfThis,cpyOfOther,nbOfSplits);
877 //At this point cpyOfThis and cpyOfOther have been splited at maximum edge so that in/out can been done.
878 performLocatingOperation(cpyOfOther);
879 return other.buildIntersectionPolygons(cpyOfThis,cpyOfOther);
883 * This method is typically the first step of boolean operations between pol1 and pol2.
884 * This method perform the minimal splitting so that at the end each edges constituting pol1 are fully either IN or OUT or ON.
885 * @param pol1 IN/OUT param that is equal to 'this' when called.
887 void QuadraticPolygon::SplitPolygonsEachOther(QuadraticPolygon& pol1, QuadraticPolygon& pol2, int& nbOfSplits)
889 IteratorOnComposedEdge it1(&pol1),it2(&pol2);
891 ComposedEdge *c1=new ComposedEdge;
892 ComposedEdge *c2=new ComposedEdge;
893 for(it2.first();!it2.finished();it2.next())
895 ElementaryEdge* curE2=it2.current();
896 if(!curE2->isThereStartPoint())
899 it1=curE2->getIterator();
900 for(;!it1.finished();)
903 ElementaryEdge* curE1=it1.current();
904 merge.clear(); nbOfSplits++;
905 if(curE1->getPtr()->intersectWith(curE2->getPtr(),merge,*c1,*c2))
907 if(!curE1->getDirection()) c1->reverse();
908 if(!curE2->getDirection()) c2->reverse();
909 UpdateNeighbours(merge,it1,it2,c1,c2);
910 //Substitution of simple edge by sub-edges.
911 delete curE1; // <-- destroying simple edge coming from pol1
912 delete curE2; // <-- destroying simple edge coming from pol2
913 it1.insertElemEdges(c1,true);// <-- 2nd param is true to go next.
914 it2.insertElemEdges(c2,false);// <-- 2nd param is false to avoid to go next.
917 it1.assignMySelfToAllElems(c2);//To avoid that others
925 UpdateNeighbours(merge,it1,it2,curE1,curE2);
934 void QuadraticPolygon::performLocatingOperation(QuadraticPolygon& pol2) const
936 IteratorOnComposedEdge it(&pol2);
937 TypeOfEdgeLocInPolygon loc=FULL_ON_1;
938 for(it.first();!it.finished();it.next())
940 ElementaryEdge *cur=it.current();
941 loc=cur->locateFullyMySelf(*this,loc);
945 void QuadraticPolygon::performLocatingOperationSlow(QuadraticPolygon& pol2) const
947 IteratorOnComposedEdge it(&pol2);
948 for(it.first();!it.finished();it.next())
950 ElementaryEdge *cur=it.current();
951 cur->locateFullyMySelfAbsolute(*this);
956 * Given 2 polygons 'pol1' and 'pol2' (localized) the resulting polygons are returned.
958 * this : pol2 simplified.
959 * @param pol1 pol1 split.
960 * @param pol2 pol2 split.
962 std::vector<QuadraticPolygon *> QuadraticPolygon::buildIntersectionPolygons(const QuadraticPolygon& pol1, const QuadraticPolygon& pol2) const
964 std::vector<QuadraticPolygon *> ret;
965 std::list<QuadraticPolygon *> pol2Zip=pol2.zipConsecutiveInSegments();
967 closePolygons(pol2Zip,pol1,ret);
969 {//borders of pol2 do not cross pol1,and pol2 borders are outside of pol1. That is to say, either pol2 and pol1
970 //do not overlap or pol1 is fully inside pol2. So in the first case no intersection, in the other case
971 //the intersection is pol1.
972 ElementaryEdge *e1FromPol1=pol1[0];
973 TypeOfEdgeLocInPolygon loc=FULL_ON_1;
974 loc=e1FromPol1->locateFullyMySelf(*this,loc);
976 ret.push_back(new QuadraticPolygon(pol1));
982 * Returns parts of potentially non closed-polygons. Each returned polygons are not mergeable.
983 * this : pol2 split and locallized.
985 std::list<QuadraticPolygon *> QuadraticPolygon::zipConsecutiveInSegments() const
987 std::list<QuadraticPolygon *> ret;
988 IteratorOnComposedEdge it(const_cast<QuadraticPolygon *>(this));
989 int nbOfTurns=recursiveSize();
991 if(!it.goToNextInOn(false,i,nbOfTurns))
997 QuadraticPolygon *tmp1=new QuadraticPolygon;
998 TypeOfEdgeLocInPolygon loc=it.current()->getLoc();
999 while(loc!=FULL_OUT_1 && i<nbOfTurns)
1001 ElementaryEdge *tmp3=it.current()->clone();
1002 tmp1->pushBack(tmp3);
1004 loc=it.current()->getLoc();
1011 ret.push_back(tmp1);
1012 it.goToNextInOn(true,i,nbOfTurns);
1018 * 'this' should be considered as pol2Simplified.
1019 * @param pol2zip is a list of set of edges (openned polygon) coming from split polygon 2.
1020 * @param pol1 is split pol1.
1021 * @param results the resulting \b CLOSED polygons.
1023 void QuadraticPolygon::closePolygons(std::list<QuadraticPolygon *>& pol2Zip, const QuadraticPolygon& pol1,
1024 std::vector<QuadraticPolygon *>& results) const
1026 bool directionKnownInPol1=false;
1027 bool directionInPol1;
1028 for(std::list<QuadraticPolygon *>::iterator iter=pol2Zip.begin();iter!=pol2Zip.end();)
1030 if((*iter)->completed())
1032 results.push_back(*iter);
1033 directionKnownInPol1=false;
1034 iter=pol2Zip.erase(iter);
1037 if(!directionKnownInPol1)
1039 if(!(*iter)->amIAChanceToBeCompletedBy(pol1,*this,directionInPol1))
1040 { delete *iter; iter=pol2Zip.erase(iter); continue; }
1042 directionKnownInPol1=true;
1044 std::list<QuadraticPolygon *>::iterator iter2=iter; iter2++;
1045 std::list<QuadraticPolygon *>::iterator iter3=(*iter)->fillAsMuchAsPossibleWith(pol1,iter2,pol2Zip.end(),directionInPol1);
1046 if(iter3!=pol2Zip.end())
1048 (*iter)->pushBack(*iter3);
1050 pol2Zip.erase(iter3);
1056 * 'this' is expected to be set of edges (not closed) of pol2 split.
1058 bool QuadraticPolygon::amIAChanceToBeCompletedBy(const QuadraticPolygon& pol1Splitted,const QuadraticPolygon& pol2NotSplitted, bool& direction)
1060 IteratorOnComposedEdge it(const_cast<QuadraticPolygon *>(&pol1Splitted));
1062 Node *n=getEndNode();
1063 ElementaryEdge *cur=it.current();
1064 for(it.first();!it.finished() && !found;)
1067 found=(cur->getStartNode()==n);
1072 throw Exception("Internal error : polygons uncompatible each others. Should never happend");
1073 //Ok we found correspondance between this and pol1. Searching for right direction to close polygon.
1074 ElementaryEdge *e=_sub_edges.back();
1075 if(e->getLoc()==FULL_ON_1)
1077 if(e->getPtr()==cur->getPtr())
1082 Node *repr=cur->getPtr()->buildRepresentantOfMySelf();
1083 bool ret=pol2NotSplitted.isInOrOut(repr);
1090 Node *repr=cur->getPtr()->buildRepresentantOfMySelf();
1091 bool ret=pol2NotSplitted.isInOrOut(repr);
1097 direction=cur->locateFullyMySelfAbsolute(pol2NotSplitted)==FULL_IN_1;
1102 * This method fills as much as possible 'this' (part of pol2 split) with edges of 'pol1Splitted'.
1104 std::list<QuadraticPolygon *>::iterator QuadraticPolygon::fillAsMuchAsPossibleWith(const QuadraticPolygon& pol1Splitted,
1105 std::list<QuadraticPolygon *>::iterator iStart,
1106 std::list<QuadraticPolygon *>::iterator iEnd,
1109 IteratorOnComposedEdge it(const_cast<QuadraticPolygon *>(&pol1Splitted));
1111 Node *n=getEndNode();
1112 ElementaryEdge *cur;
1113 for(it.first();!it.finished() && !found;)
1116 found=(cur->getStartNode()==n);
1123 int szMax(pol1Splitted.size()+1),ii(0);// here a protection against agressive users of IntersectMeshes of invalid input meshes
1124 std::list<QuadraticPolygon *>::iterator ret;
1128 ElementaryEdge *tmp=cur->clone();
1132 nodeToTest=tmp->getEndNode();
1133 direction?it.nextLoop():it.previousLoop();
1134 ret=CheckInList(nodeToTest,iStart,iEnd);
1139 while(ret==iEnd && ii<szMax);
1140 if(ii==szMax)// here a protection against agressive users of IntersectMeshes of invalid input meshes
1141 throw INTERP_KERNEL::Exception("QuadraticPolygon::fillAsMuchAsPossibleWith : Something is invalid with input polygons !");
1145 std::list<QuadraticPolygon *>::iterator QuadraticPolygon::CheckInList(Node *n, std::list<QuadraticPolygon *>::iterator iStart,
1146 std::list<QuadraticPolygon *>::iterator iEnd)
1148 for(std::list<QuadraticPolygon *>::iterator iter=iStart;iter!=iEnd;iter++)
1149 if((*iter)->isNodeIn(n))
1154 void QuadraticPolygon::ComputeResidual(const QuadraticPolygon& pol1, const std::set<Edge *>& notUsedInPol1, const std::set<Edge *>& edgesInPol2OnBoundary, const std::map<INTERP_KERNEL::Node *,int>& mapp, int offset, int idThis,
1155 std::vector<double>& addCoordsQuadratic, std::vector<int>& conn, std::vector<int>& connI, std::vector<int>& nb1, std::vector<int>& nb2)
1157 pol1.initLocations();
1158 for(std::set<Edge *>::const_iterator it9=notUsedInPol1.begin();it9!=notUsedInPol1.end();it9++)
1159 { (*it9)->initLocs(); (*it9)->declareOn(); }
1160 for(std::set<Edge *>::const_iterator itA=edgesInPol2OnBoundary.begin();itA!=edgesInPol2OnBoundary.end();itA++)
1161 { (*itA)->initLocs(); (*itA)->declareIn(); }
1163 std::set<Edge *> notUsedInPol1L(notUsedInPol1);
1164 IteratorOnComposedEdge it(const_cast<QuadraticPolygon *>(&pol1));
1166 std::list<QuadraticPolygon *> pol1Zip;
1167 if(pol1.size()==(int)notUsedInPol1.size() && edgesInPol2OnBoundary.empty())
1169 pol1.appendCrudeData(mapp,0.,0.,1.,offset,addCoordsQuadratic,conn,connI); nb1.push_back(idThis); nb2.push_back(-1);
1172 while(!notUsedInPol1L.empty())
1174 for(int i=0;i<sz && (it.current()->getStartNode()->getLoc()!=IN_1 || it.current()->getLoc()!=FULL_ON_1);i++)
1176 if(it.current()->getStartNode()->getLoc()!=IN_1 || it.current()->getLoc()!=FULL_ON_1)
1177 throw INTERP_KERNEL::Exception("Presence of a target polygon fully included in source polygon ! The partition of this leads to a non simply connex cell (with hole) ! Impossible ! Such resulting cell cannot be stored in MED cell format !");
1178 QuadraticPolygon *tmp1=new QuadraticPolygon;
1181 Edge *ee=it.current()->getPtr();
1182 if(ee->getLoc()==FULL_ON_1)
1184 ee->incrRef(); notUsedInPol1L.erase(ee);
1185 tmp1->pushBack(new ElementaryEdge(ee,it.current()->getDirection()));
1189 while(it.current()->getStartNode()->getLoc()!=IN_1 && !notUsedInPol1L.empty());
1190 pol1Zip.push_back(tmp1);
1193 std::list<QuadraticPolygon *> retPolsUnderContruction;
1194 std::list<Edge *> edgesInPol2OnBoundaryL(edgesInPol2OnBoundary.begin(),edgesInPol2OnBoundary.end());
1195 std::map<QuadraticPolygon *, std::list<QuadraticPolygon *> > pol1ZipConsumed;
1196 std::size_t maxNbOfTurn=edgesInPol2OnBoundaryL.size(),nbOfTurn=0,iiMNT=0;
1197 for(std::list<QuadraticPolygon *>::const_iterator itMNT=pol1Zip.begin();itMNT!=pol1Zip.end();itMNT++,iiMNT++)
1198 nbOfTurn+=(*itMNT)->size();
1199 maxNbOfTurn=maxNbOfTurn*nbOfTurn; maxNbOfTurn*=maxNbOfTurn;
1201 while(nbOfTurn<maxNbOfTurn && ((!pol1Zip.empty() || !edgesInPol2OnBoundaryL.empty())))
1203 for(std::list<QuadraticPolygon *>::iterator it1=retPolsUnderContruction.begin();it1!=retPolsUnderContruction.end();)
1205 if((*it1)->getStartNode()==(*it1)->getEndNode())
1210 Node *curN=(*it1)->getEndNode();
1211 bool smthHappened=false;
1212 for(std::list<Edge *>::iterator it2=edgesInPol2OnBoundaryL.begin();it2!=edgesInPol2OnBoundaryL.end();)
1214 if(curN==(*it2)->getStartNode())
1215 { (*it2)->incrRef(); (*it1)->pushBack(new ElementaryEdge(*it2,true)); curN=(*it2)->getEndNode(); smthHappened=true; it2=edgesInPol2OnBoundaryL.erase(it2); }
1216 else if(curN==(*it2)->getEndNode())
1217 { (*it2)->incrRef(); (*it1)->pushBack(new ElementaryEdge(*it2,false)); curN=(*it2)->getStartNode(); smthHappened=true; it2=edgesInPol2OnBoundaryL.erase(it2); }
1223 for(std::list<QuadraticPolygon *>::iterator it3=pol1Zip.begin();it3!=pol1Zip.end();)
1225 if(curN==(*it3)->getStartNode())
1227 for(std::list<ElementaryEdge *>::const_iterator it4=(*it3)->_sub_edges.begin();it4!=(*it3)->_sub_edges.end();it4++)
1228 { (*it4)->getPtr()->incrRef(); bool dir=(*it4)->getDirection(); (*it1)->pushBack(new ElementaryEdge((*it4)->getPtr(),dir)); }
1230 pol1ZipConsumed[*it1].push_back(*it3);
1231 curN=(*it3)->getEndNode();
1232 it3=pol1Zip.erase(it3);
1240 for(std::list<ElementaryEdge *>::const_iterator it5=(*it1)->_sub_edges.begin();it5!=(*it1)->_sub_edges.end();it5++)
1242 Edge *ee=(*it5)->getPtr();
1243 if(edgesInPol2OnBoundary.find(ee)!=edgesInPol2OnBoundary.end())
1244 edgesInPol2OnBoundaryL.push_back(ee);
1246 for(std::list<QuadraticPolygon *>::iterator it6=pol1ZipConsumed[*it1].begin();it6!=pol1ZipConsumed[*it1].end();it6++)
1247 pol1Zip.push_front(*it6);
1248 pol1ZipConsumed.erase(*it1);
1250 it1=retPolsUnderContruction.erase(it1);
1253 if(!pol1Zip.empty())
1255 QuadraticPolygon *tmp=new QuadraticPolygon;
1256 QuadraticPolygon *first=*(pol1Zip.begin());
1257 for(std::list<ElementaryEdge *>::const_iterator it4=first->_sub_edges.begin();it4!=first->_sub_edges.end();it4++)
1258 { (*it4)->getPtr()->incrRef(); bool dir=(*it4)->getDirection(); tmp->pushBack(new ElementaryEdge((*it4)->getPtr(),dir)); }
1259 pol1ZipConsumed[tmp].push_back(first);
1260 retPolsUnderContruction.push_back(tmp);
1261 pol1Zip.erase(pol1Zip.begin());
1265 if(nbOfTurn==maxNbOfTurn)
1267 std::ostringstream oss; oss << "Error during reconstruction of residual of cell ! It appears that either source or/and target mesh is/are not conform !";
1268 oss << " Number of turns is = " << nbOfTurn << " !";
1269 throw INTERP_KERNEL::Exception(oss.str().c_str());
1271 for(std::list<QuadraticPolygon *>::iterator it1=retPolsUnderContruction.begin();it1!=retPolsUnderContruction.end();it1++)
1273 if((*it1)->getStartNode()==(*it1)->getEndNode())
1275 (*it1)->appendCrudeData(mapp,0.,0.,1.,offset,addCoordsQuadratic,conn,connI); nb1.push_back(idThis); nb2.push_back(-1);
1276 for(std::list<QuadraticPolygon *>::iterator it6=pol1ZipConsumed[*it1].begin();it6!=pol1ZipConsumed[*it1].end();it6++)