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 "InterpKernelGeo2DEdge.hxx"
22 #include "InterpKernelGeo2DEdgeLin.hxx"
23 #include "InterpKernelGeo2DEdgeInfLin.hxx"
24 //#include "EdgeParabol.hxx"
25 #include "InterpKernelGeo2DEdgeArcCircle.hxx"
26 #include "InterpKernelGeo2DComposedEdge.hxx"
27 #include "InterpKernelException.hxx"
31 using namespace INTERP_KERNEL;
33 MergePoints::MergePoints():_ass1Start1(0),_ass1End1(0),_ass1Start2(0),_ass1End2(0),
34 _ass2Start1(0),_ass2End1(0),_ass2Start2(0),_ass2End2(0)
38 void MergePoints::start1Replaced()
40 unsigned nbOfAsso=getNumberOfAssociations();
47 void MergePoints::end1Replaced()
49 unsigned nbOfAsso=getNumberOfAssociations();
56 void MergePoints::start1OnStart2()
58 unsigned nbOfAsso=getNumberOfAssociations();
71 void MergePoints::start1OnEnd2()
73 unsigned nbOfAsso=getNumberOfAssociations();
86 void MergePoints::end1OnStart2()
88 unsigned nbOfAsso=getNumberOfAssociations();
101 void MergePoints::end1OnEnd2()
103 unsigned nbOfAsso=getNumberOfAssociations();
116 bool MergePoints::isStart1(unsigned rk) const
124 bool MergePoints::isEnd1(unsigned rk) const
132 bool MergePoints::isStart2(unsigned rk) const
140 bool MergePoints::isEnd2(unsigned rk) const
148 void MergePoints::clear()
150 _ass1Start1=0;_ass1End1=0;_ass1Start2=0;_ass1End2=0;
151 _ass2Start1=0;_ass2End1=0;_ass2Start2=0;_ass2End2=0;
154 unsigned MergePoints::getNumberOfAssociations() const
157 unsigned subTot=_ass1Start1+_ass1End1+_ass1Start2+_ass1End2;
160 subTot=_ass2Start1+_ass2End1+_ass2Start2+_ass2End2;
166 IntersectElement::IntersectElement(double val1, double val2, bool start1, bool end1, bool start2, bool end2, Node *node
167 , const Edge& e1, const Edge& e2, bool keepOrder):_1S(keepOrder?start1:start2),
168 _1E(keepOrder?end1:end2),
169 _2S(keepOrder?start2:start1),
170 _2E(keepOrder?end2:end1),
171 _chararct_val_for_e1(keepOrder?val1:val2),
172 _chararct_val_for_e2(keepOrder?val2:val1),
173 _node(node),_loc_of_node(node->getLoc()),_e1(keepOrder?e1:e2),
178 IntersectElement::IntersectElement(const IntersectElement& other):_1S(other._1S),_1E(other._1E),_2S(other._2S),_2E(other._2E),
179 _chararct_val_for_e1(other._chararct_val_for_e1),
180 _chararct_val_for_e2(other._chararct_val_for_e2),_node(other._node),
181 _loc_of_node(other._loc_of_node),_e1(other._e1), _e2(other._e2)
187 IntersectElement& IntersectElement::operator=(const IntersectElement& other)
189 _1S=other._1S;_1E=other._1E; _2S=other._2S; _2E=other._2E;
190 _chararct_val_for_e1=other._chararct_val_for_e1;
191 _chararct_val_for_e2=other._chararct_val_for_e2;
192 setNode(other._node);
196 bool IntersectElement::operator<(const IntersectElement& other) const
198 return _e1.isLower(_chararct_val_for_e1,other._chararct_val_for_e1);
201 IntersectElement::~IntersectElement()
210 bool IntersectElement::isOnMergedExtremity() const
212 if( (_1S && _2S) || (_1S && _2E) || (_1E && _2S) || (_1E && _2E) )
218 * To call if isOnMergedExtremity returned true.
220 void IntersectElement::performMerging(MergePoints& commonNode) const
224 if(_e1.changeStartNodeWith(_e2.getStartNode()))
226 _e2.getStartNode()->declareOnLim();
227 commonNode.start1OnStart2();
232 if(_e1.changeStartNodeWith(_e2.getEndNode()))
234 _e2.getEndNode()->declareOnLim();
235 commonNode.start1OnEnd2();
240 if(_e1.changeEndNodeWith(_e2.getStartNode()))
242 _e2.getStartNode()->declareOnLim();
243 commonNode.end1OnStart2();
248 if(_e1.changeEndNodeWith(_e2.getEndNode()))
250 _e2.getEndNode()->declareOnLim();
251 commonNode.end1OnEnd2();
257 * This methode is const because 'node' is supposed to be equal geomitrically to _node.
259 void IntersectElement::setNode(Node *node) const
264 ((Node *)_node)->decrRef();
265 (const_cast<IntersectElement *>(this))->_node=node;
271 bool IntersectElement::isLowerOnOther(const IntersectElement& other) const
273 return _e2.isLower(_chararct_val_for_e2,other._chararct_val_for_e2);
276 unsigned IntersectElement::isOnExtrForAnEdgeAndInForOtherEdge() const
278 if(( _1S && !(_2S || _2E) ) || ( _1E && !(_2S || _2E) ))
280 if(_1S && !(_2S || _2E))
281 setNode(_e1.getStartNode());
283 setNode(_e1.getEndNode());
284 if(_e2.isIn(_chararct_val_for_e2))
288 if(( _2S && !(_1S || _1E) ) || ( _2E && !(_1S || _1E)))
290 if(_2S && !(_1S || _1E))
291 setNode(_e2.getStartNode());
293 setNode(_e2.getEndNode());
294 if(_e1.isIn(_chararct_val_for_e1))
301 bool IntersectElement::isIncludedByBoth() const
303 return _e1.isIn(_chararct_val_for_e1) && _e2.isIn(_chararct_val_for_e2);
306 bool EdgeIntersector::intersect(const Bounds *whereToFind, std::vector<Node *>& newNodes, bool& order, MergePoints& commonNode)
308 std::list< IntersectElement > listOfIntesc=getIntersectionsCharacteristicVal();
309 std::list< IntersectElement >::iterator iter;
310 for(iter=listOfIntesc.begin();iter!=listOfIntesc.end();)
312 if((*iter).isOnMergedExtremity())
314 (*iter).performMerging(commonNode);
315 iter=listOfIntesc.erase(iter);
318 unsigned tmp=(*iter).isOnExtrForAnEdgeAndInForOtherEdge();
319 if(tmp==IntersectElement::LIMIT_ALONE)
321 iter=listOfIntesc.erase(iter);
324 else if(tmp==IntersectElement::LIMIT_ON)
330 if(!(*iter).isIncludedByBoth())
332 iter=listOfIntesc.erase(iter);
338 if(listOfIntesc.size()==0)
340 if(listOfIntesc.size()==1)
343 newNodes.push_back(listOfIntesc.front().getNodeAndReleaseIt());
347 std::vector<IntersectElement> vecOfIntesc(listOfIntesc.begin(),listOfIntesc.end());
348 listOfIntesc.clear();
349 sort(vecOfIntesc.begin(),vecOfIntesc.end());
350 for(std::vector<IntersectElement>::iterator iterV=vecOfIntesc.begin();iterV!=vecOfIntesc.end();iterV++)
351 newNodes.push_back((*iterV).getNodeAndReleaseIt());
352 order=vecOfIntesc.front().isLowerOnOther(vecOfIntesc.back());
358 * Locates 'node' regarding edge this->_e1. If node is located close to (with distant lt epsilon) start or end point of _e1,
359 * 'node' takes its place. In this case 'obvious' is set to true and 'commonNode' stores information of merge point and finally 'where' is set.
360 * Furthermore 'node' is declared as ON LIMIT to indicate in locating process that an absolute location computation will have to be done.
361 * If 'node' is not close to start or end point of _e1, 'obvious' is set to false and 'commonNode' and 'where' are let unchanged.
363 void EdgeIntersector::obviousCaseForCurvAbscisse(Node *node, TypeOfLocInEdge& where, MergePoints& commonNode, bool& obvious) const
366 if(node->isEqual(*_e1.getStartNode()))
369 if(_e1.changeStartNodeWith(node))
371 commonNode.start1Replaced();
372 node->declareOnLim();
376 if(node->isEqual(*_e1.getEndNode()))
379 if(_e1.changeEndNodeWith(node))
381 commonNode.end1Replaced();
382 node->declareOnLim();
389 Edge::Edge(double sX, double sY, double eX, double eY):_cnt(1),_loc(FULL_UNKNOWN),_start(new Node(sX,sY)),_end(new Node(eX,eY))
402 bool ret=(--_cnt==0);
408 void Edge::declareOn() const
410 if(_loc==FULL_UNKNOWN)
418 void Edge::declareIn() const
420 if(_loc==FULL_UNKNOWN)
428 void Edge::declareOut() const
430 if(_loc==FULL_UNKNOWN)
433 _start->declareOut();
438 void Edge::fillXfigStreamForLoc(std::ostream& stream) const
443 stream << '2';//Green
446 stream << '1';//Bleue
456 bool Edge::changeStartNodeWith(Node *otherStartNode) const
458 if(_start==otherStartNode)
460 if(_start->isEqual(*otherStartNode))
462 ((const_cast<Edge *>(this))->_start)->decrRef();//un-const cast Ok thanks to 2 lines above.
463 ((const_cast<Edge *>(this))->_start)=otherStartNode;
470 bool Edge::changeStartNodeWithAndKeepTrack(Node *otherStartNode, std::vector<Node *>& track) const
472 if(_start==otherStartNode)
474 if(_start->isEqualAndKeepTrack(*otherStartNode,track))
476 ((const_cast<Edge *>(this))->_start)->decrRef();//un-const cast Ok thanks to 2 lines above.
477 ((const_cast<Edge *>(this))->_start)=otherStartNode;
478 otherStartNode->incrRef();
484 bool Edge::changeEndNodeWith(Node *otherEndNode) const
486 if(_end==otherEndNode)
488 if(_end->isEqual(*otherEndNode))
490 ((const_cast<Edge *>(this))->_end)->decrRef();
491 ((const_cast<Edge *>(this))->_end)=otherEndNode;
498 bool Edge::changeEndNodeWithAndKeepTrack(Node *otherEndNode, std::vector<Node *>& track) const
500 if(_end==otherEndNode)
502 if(_end->isEqualAndKeepTrack(*otherEndNode,track))
504 ((const_cast<Edge *>(this))->_end)->decrRef();
505 ((const_cast<Edge *>(this))->_end)=otherEndNode;
506 otherEndNode->incrRef();
513 * Precondition : 'start' and 'end' are lying on the same curve than 'this'.
514 * Add in vec the sub edge lying on this.
515 * If 'start' is equal (by pointer) to '_end' and 'end' is equal to '_end' too nothing is added.
516 * If 'start' is equal (by pointer) to '_start' and 'end' is equal to '_start' too nothing is added.
517 * If 'start' is equal (by pointer) to '_start' and 'end' is equal to '_end' this is added in vec.
519 void Edge::addSubEdgeInVector(Node *start, Node *end, ComposedEdge& vec) const
521 if((start==_start && end==_start) || (start==_end && end==_end))
523 if(start==_start && end==_end)
526 vec.pushBack(const_cast<Edge *>(this));
529 vec.pushBack(buildEdgeLyingOnMe(start,end,true));
533 * Retrieves a vector 'vectOutput' that is normal to 'this'. 'vectOutput' is normalized.
535 void Edge::getNormalVector(double *vectOutput) const
537 std::copy((const double *)(*_end),(const double *)(*_end)+2,vectOutput);
538 std::transform(vectOutput,vectOutput+2,(const double *)(*_start),vectOutput,std::minus<double>());
539 double norm=1./Node::norm(vectOutput);
540 std::transform(vectOutput,vectOutput+2,vectOutput,bind2nd(std::multiplies<double>(),norm));
541 double tmp=vectOutput[0];
542 vectOutput[0]=vectOutput[1];
546 Edge *Edge::BuildEdgeFrom3Points(const double *start, const double *middle, const double *end)
548 Node *b(new Node(start[0],start[1])),*m(new Node(middle[0],middle[1])),*e(new Node(end[0],end[1]));
549 EdgeLin *e1(new EdgeLin(b,m)),*e2(new EdgeLin(m,e));
550 SegSegIntersector inters(*e1,*e2); bool colinearity=inters.areColinears(); delete e1; delete e2;
553 ret=new EdgeLin(b,e);
555 ret=new EdgeArcCircle(b,m,e);
556 b->decrRef(); m->decrRef(); e->decrRef();
560 Edge *Edge::BuildEdgeFrom(Node *start, Node *end)
562 return new EdgeLin(start,end);
565 Edge *Edge::BuildFromXfigLine(std::istream& str)
570 return new EdgeLin(str);
572 return new EdgeArcCircle(str);
575 std::cerr << "Unknown line found...";
581 * \param other The Edge with which we are going to intersect.
582 * \param commonNode Output. The common nodes found during operation of intersecting.
583 * \param outVal1 Output filled in case true is returned. It specifies the new or not new edges by which 'this' is replaced after intersecting op.
584 * \param outVal2 Output filled in case true is returned. It specifies the new or not new edges by which 'other' is replaced after intersecting op.
585 * return true if the intersection between this.
587 bool Edge::intersectWith(const Edge *other, MergePoints& commonNode,
588 ComposedEdge& outVal1, ComposedEdge& outVal2) const
591 Bounds *merge=_bounds.nearlyAmIIntersectingWith(other->getBounds());
596 EdgeIntersector *intersector=BuildIntersectorWith(this,other);
597 ret=Intersect(this,other,intersector,merge,commonNode,outVal1,outVal2);
602 bool Edge::IntersectOverlapped(const Edge *f1, const Edge *f2, EdgeIntersector *intersector, MergePoints& commonNode,
603 ComposedEdge& outValForF1, ComposedEdge& outValForF2)
605 bool rev=intersector->haveTheySameDirection();
606 Node *f2Start=f2->getNode(rev?START:END);
607 Node *f2End=f2->getNode(rev?END:START);
608 TypeOfLocInEdge place1, place2;
609 intersector->getPlacements(f2Start,f2End,place1,place2,commonNode);
610 int codeForIntersectionCase=CombineCodes(place1,place2);
611 return SplitOverlappedEdges(f1,f2,f2Start,f2End,rev,codeForIntersectionCase,outValForF1,outValForF2);
615 * Perform 1D linear interpolation. Warning distrib1 and distrib2 are expected to be in ascending mode.
617 void Edge::Interpolate1DLin(const std::vector<double>& distrib1, const std::vector<double>& distrib2, std::map<int, std::map<int,double> >& result)
619 int nbOfV1=distrib1.size()-1;
620 int nbOfV2=distrib2.size()-1;
621 Node *n1=new Node(0.,0.); Node *n3=new Node(0.,0.);
622 Node *n2=new Node(0.,0.); Node *n4=new Node(0.,0.);
623 MergePoints commonNode;
624 for(int i=0;i<nbOfV1;i++)
626 std::vector<double>::const_iterator iter=find_if(distrib2.begin()+1,distrib2.end(),bind2nd(std::greater_equal<double>(),distrib1[i]));
627 if(iter!=distrib2.end())
629 for(int j=(iter-1)-distrib2.begin();j<nbOfV2;j++)
631 if(distrib2[j]<=distrib1[i+1])
633 EdgeLin *e1=new EdgeLin(n1,n2); EdgeLin *e2=new EdgeLin(n3,n4);
634 n1->setNewCoords(distrib1[i],0.); n2->setNewCoords(distrib1[i+1],0.);
635 n3->setNewCoords(distrib2[j],0.); n4->setNewCoords(distrib2[j+1],0.);
636 ComposedEdge *f1=new ComposedEdge;
637 ComposedEdge *f2=new ComposedEdge;
638 SegSegIntersector inters(*e1,*e2);
640 inters.areOverlappedOrOnlyColinears(0,b1,b2);
641 if(IntersectOverlapped(e1,e2,&inters,commonNode,*f1,*f2))
643 result[i][j]=f1->getCommonLengthWith(*f2)/e1->getCurveLength();
645 ComposedEdge::Delete(f1); ComposedEdge::Delete(f2);
646 e1->decrRef(); e2->decrRef();
651 n1->decrRef(); n2->decrRef(); n3->decrRef(); n4->decrRef();
654 EdgeIntersector *Edge::BuildIntersectorWith(const Edge *e1, const Edge *e2)
656 EdgeIntersector *ret=0;
657 const EdgeLin *tmp1=0;
658 const EdgeArcCircle *tmp2=0;
659 unsigned char type1=e1->getTypeOfFunc();
660 e1->dynCastFunction(tmp1,tmp2);
661 unsigned char type2=e2->getTypeOfFunc();
662 e2->dynCastFunction(tmp1,tmp2);
666 case 1:// Intersection seg/seg
667 ret=new SegSegIntersector((const EdgeLin &)(*e1),(const EdgeLin &)(*e2));
669 case 5:// Intersection seg/arc of circle
670 ret=new ArcCSegIntersector(*tmp2,*tmp1,tmp2==e1);
672 case 4:// Intersection arc/arc of circle
673 ret=new ArcCArcCIntersector((const EdgeArcCircle &)(*e1),(const EdgeArcCircle &)(*e2));
676 //Should never happen
677 throw Exception("A non managed association of edge has been detected. Go work for intersection computation implementation.");
683 * See Node::applySimilarity to see signification of params.
685 void Edge::applySimilarity(double xBary, double yBary, double dimChar)
687 _bounds.applySimilarity(xBary,yBary,dimChar);
690 void Edge::unApplySimilarity(double xBary, double yBary, double dimChar)
692 _bounds.unApplySimilarity(xBary,yBary,dimChar);
695 bool Edge::Intersect(const Edge *f1, const Edge *f2, EdgeIntersector *intersector, const Bounds *whereToFind, MergePoints& commonNode,
696 ComposedEdge& outValForF1, ComposedEdge& outValForF2)
698 bool obviousNoIntersection;
700 intersector->areOverlappedOrOnlyColinears(whereToFind,obviousNoIntersection,areOverlapped);
702 return IntersectOverlapped(f1,f2,intersector,commonNode,outValForF1,outValForF2);
703 if(obviousNoIntersection)
705 std::vector<Node *> newNodes;
707 if(intersector->intersect(whereToFind,newNodes,order,commonNode))
710 throw Exception("Internal error occured - error in intersector implementation!");// This case should never happen
711 std::vector<Node *>::iterator iter=newNodes.begin();
712 std::vector<Node *>::reverse_iterator iterR=newNodes.rbegin();
713 f1->addSubEdgeInVector(f1->getStartNode(),*iter,outValForF1);
714 f2->addSubEdgeInVector(f2->getStartNode(),order?*iter:*iterR,outValForF2);
715 for(std::vector<Node *>::iterator iter2=newNodes.begin();iter2!=newNodes.end();iter2++,iterR++)
717 if((iter2+1)==newNodes.end())
719 f1->addSubEdgeInVector(*iter2,f1->getEndNode(),outValForF1);
721 f2->addSubEdgeInVector(order?*iter2:*iterR,f2->getEndNode(),outValForF2);
725 f1->addSubEdgeInVector(*iter2,*(iter2+1),outValForF1);
727 f2->addSubEdgeInVector(order?*iter2:*iterR,order?*(iter2+1):*(iterR+1),outValForF2);
732 else//no intersection inside whereToFind
736 int Edge::CombineCodes(TypeOfLocInEdge code1, TypeOfLocInEdge code2)
739 ret*=OFFSET_FOR_TYPEOFLOCINEDGE;
745 * This method splits e1 and e2 into pieces as much sharable as possible. The precondition to the call of this method
746 * is that e1 and e2 have been declared as overlapped by corresponding intersector built from e1 and e2 type.
748 * @param nS start node of e2 with the SAME DIRECTION as e1. The pointer nS should be equal to start node of e2 or to its end node.
749 * @param nE end node of e2 with the SAME DIRECTION as e1. The pointer nE should be equal to start node of e2 or to its end node.
750 * @param direction is param that specifies if e2 and e1 have same directions (true) or opposed (false).
751 * @param code is the code returned by method Edge::combineCodes.
753 bool Edge::SplitOverlappedEdges(const Edge *e1, const Edge *e2, Node *nS, Node *nE, bool direction, int code,
754 ComposedEdge& outVal1, ComposedEdge& outVal2)
759 case OUT_BEFORE*OFFSET_FOR_TYPEOFLOCINEDGE+START: // OUT_BEFORE - START
760 case OUT_BEFORE*OFFSET_FOR_TYPEOFLOCINEDGE+OUT_BEFORE: // OUT_BEFORE - OUT_BEFORE
761 case OUT_AFTER*OFFSET_FOR_TYPEOFLOCINEDGE+OUT_AFTER: // OUT_AFTER - OUT_AFTER
762 case END*OFFSET_FOR_TYPEOFLOCINEDGE+OUT_AFTER: // END - OUT_AFTER
763 case END*OFFSET_FOR_TYPEOFLOCINEDGE+START: // END - START
765 case INSIDE*OFFSET_FOR_TYPEOFLOCINEDGE+OUT_AFTER: // INSIDE - OUT_AFTER
766 outVal1.pushBack(e1->buildEdgeLyingOnMe(e1->getStartNode(),nS,true));
767 tmp=e1->buildEdgeLyingOnMe(nS,e1->getEndNode()); tmp->incrRef();
768 outVal1.pushBack(tmp);
770 outVal2.setValueAt(direction?0:1,tmp,direction); tmp->declareOn();
771 outVal2.setValueAt(direction?1:0,e1->buildEdgeLyingOnMe(e1->getEndNode(),nE,direction));
773 case INSIDE*OFFSET_FOR_TYPEOFLOCINEDGE+INSIDE: // INSIDE - INSIDE
775 if(!e2->isIn(e2->getCharactValue(*(e1->getStartNode()))))
777 e2->incrRef(); e2->incrRef();
779 outVal1.setValueAt(0,e1->buildEdgeLyingOnMe(e1->getStartNode(),nS));
780 outVal1.setValueAt(1,const_cast<Edge*>(e2),direction);
781 outVal1.setValueAt(2,e1->buildEdgeLyingOnMe(nE,e1->getEndNode()));
782 outVal2.pushBack(const_cast<Edge*>(e2)); e2->declareOn();
789 tmp=e1->buildEdgeLyingOnMe(e1->getStartNode(),nE); tmp->incrRef(); tmp->declareOn();
790 outVal1.setValueAt(0,tmp,true); outVal2.setValueAt(direction?2:0,tmp,direction);
791 outVal1.setValueAt(1,e1->buildEdgeLyingOnMe(nE,nS));
792 tmp=e1->buildEdgeLyingOnMe(nS,e1->getEndNode()); tmp->incrRef(); tmp->declareOn();
793 outVal1.setValueAt(2,tmp,true); outVal2.setValueAt(direction?0:2,tmp,direction);
794 tmp=e1->buildEdgeLyingOnMe(e1->getEndNode(),e1->getStartNode());
795 outVal2.setValueAt(1,tmp,direction);
799 case OUT_BEFORE*OFFSET_FOR_TYPEOFLOCINEDGE+INSIDE: // OUT_BEFORE - INSIDE
801 tmp=e1->buildEdgeLyingOnMe(e1->getStartNode(),nE); tmp->incrRef();
802 outVal1.pushBack(tmp);
803 outVal1.pushBack(e1->buildEdgeLyingOnMe(nE,e1->getEndNode()));
805 outVal2.setValueAt(direction?0:1,e1->buildEdgeLyingOnMe(nS,e1->getStartNode(),direction));
806 outVal2.setValueAt(direction?1:0,tmp,direction); tmp->declareOn();
809 case OUT_BEFORE*OFFSET_FOR_TYPEOFLOCINEDGE+OUT_AFTER: // OUT_BEFORE - OUT_AFTER
811 e1->incrRef(); e1->incrRef();
812 outVal1.pushBack(const_cast<Edge*>(e1));
814 outVal2.setValueAt(direction?0:2,e1->buildEdgeLyingOnMe(nS,e1->getStartNode(),direction));
815 outVal2.setValueAt(1,const_cast<Edge*>(e1),direction); e1->declareOn();
816 outVal2.setValueAt(direction?2:0,e1->buildEdgeLyingOnMe(e1->getEndNode(),nE,direction));
819 case START*OFFSET_FOR_TYPEOFLOCINEDGE+END: // START - END
821 e1->incrRef(); e1->incrRef();
822 outVal1.pushBack(const_cast<Edge*>(e1));
823 outVal2.pushBack(const_cast<Edge*>(e1),direction); e1->declareOn();
826 case START*OFFSET_FOR_TYPEOFLOCINEDGE+OUT_AFTER: // START - OUT_AFTER
828 e1->incrRef(); e1->incrRef();
829 outVal1.pushBack(const_cast<Edge*>(e1));
831 outVal2.setValueAt(direction?0:1,const_cast<Edge*>(e1),direction); e1->declareOn();
832 outVal2.setValueAt(direction?1:0,e1->buildEdgeLyingOnMe(e1->getEndNode(),nE,direction));
835 case INSIDE*OFFSET_FOR_TYPEOFLOCINEDGE+END: // INSIDE - END
837 e2->incrRef(); e2->incrRef();
838 outVal1.pushBack(e1->buildEdgeLyingOnMe(e1->getStartNode(),nS,true));
839 outVal1.pushBack(const_cast<Edge*>(e2),direction);
840 outVal2.pushBack(const_cast<Edge*>(e2)); e2->declareOn();
843 case OUT_BEFORE*OFFSET_FOR_TYPEOFLOCINEDGE+END: // OUT_BEFORE - END
845 e1->incrRef(); e1->incrRef();
846 outVal1.pushBack(const_cast<Edge*>(e1));
848 outVal2.setValueAt(direction?0:1,e1->buildEdgeLyingOnMe(nS,e1->getStartNode(),direction));
849 outVal2.setValueAt(direction?1:0,const_cast<Edge*>(e1),direction); e1->declareOn();
852 case START*OFFSET_FOR_TYPEOFLOCINEDGE+INSIDE: // START - INSIDE
854 e2->incrRef(); e2->incrRef();
855 outVal1.pushBack(const_cast<Edge*>(e2),direction);
856 outVal1.pushBack(e1->buildEdgeLyingOnMe(nE,e1->getEndNode()));
857 outVal2.pushBack(const_cast<Edge*>(e2)); e2->declareOn();
860 case INSIDE*OFFSET_FOR_TYPEOFLOCINEDGE+START: // INSIDE - START
864 tmp=e1->buildEdgeLyingOnMe(nS,e1->getEndNode()); tmp->incrRef(); tmp->declareOn();
865 outVal1.setValueAt(0,e1->buildEdgeLyingOnMe(e1->getStartNode(),nS));
866 outVal1.setValueAt(1,tmp);
867 outVal2.setValueAt(direction?0:1,tmp,direction);
868 outVal2.setValueAt(direction?1:0,e1->buildEdgeLyingOnMe(e1->getEndNode(),nE,direction));
871 case END*OFFSET_FOR_TYPEOFLOCINEDGE+INSIDE: // END - INSIDE
875 tmp=e1->buildEdgeLyingOnMe(e1->getStartNode(),nE); tmp->incrRef(); tmp->declareOn();
876 outVal1.setValueAt(0,tmp);
877 outVal1.setValueAt(1,e1->buildEdgeLyingOnMe(nE,e1->getEndNode()));
878 outVal2.setValueAt(direction?0:1,e1->buildEdgeLyingOnMe(e1->getEndNode(),e1->getStartNode(),direction));
879 outVal2.setValueAt(direction?1:0,tmp,direction);
883 throw Exception("Unexpected situation of overlapping edges : internal error occurs ! ");
887 bool Edge::isEqual(const Edge& other) const
889 return _start->isEqual(*other._start) && _end->isEqual(*other._end);
892 inline bool eqpair(const std::pair<double,Node *>& p1, const std::pair<double,Node *>& p2)
894 return fabs(p1.first-p2.first)<QUADRATIC_PLANAR::_precision;
898 * This method takes in input nodes in \a subNodes (using \a coo)
900 * \param [in,out] subNodes to be sorted
901 * \return true if a reordering was necessary false if not.
903 bool Edge::sortSubNodesAbs(const double *coo, std::vector<int>& subNodes)
906 b.prepareForAggregation();
907 b.aggregate(getBounds());
909 double dimChar(b.getCaracteristicDim());
910 b.getBarycenter(xBary,yBary);
911 applySimilarity(xBary,yBary,dimChar);
912 _start->applySimilarity(xBary,yBary,dimChar);
913 _end->applySimilarity(xBary,yBary,dimChar);
915 std::size_t sz(subNodes.size()),i(0);
916 std::vector< std::pair<double,Node *> > an2(sz);
917 std::map<Node *, int> m;
918 for(std::vector<int>::const_iterator it=subNodes.begin();it!=subNodes.end();it++,i++)
920 Node *n(new Node(coo[2*(*it)],coo[2*(*it)+1]));
921 n->applySimilarity(xBary,yBary,dimChar);
923 an2[i]=std::pair<double,Node *>(getCharactValueBtw0And1(*n),n);
925 std::sort(an2.begin(),an2.end());
930 int id(m[an2[i].second]);
932 { subNodes[i]=id; ret=true; }
935 for(std::map<INTERP_KERNEL::Node *,int>::const_iterator it2=m.begin();it2!=m.end();it2++)
936 (*it2).first->decrRef();
941 * Sort nodes so that they all lie consecutively on the edge that has been cut.
943 void Edge::sortIdsAbs(const std::vector<INTERP_KERNEL::Node *>& addNodes, const std::map<INTERP_KERNEL::Node *, int>& mapp1,
944 const std::map<INTERP_KERNEL::Node *, int>& mapp2, std::vector<int>& edgesThis)
947 b.prepareForAggregation();
948 b.aggregate(getBounds());
950 double dimChar=b.getCaracteristicDim();
951 b.getBarycenter(xBary,yBary);
952 for(std::vector<Node *>::const_iterator iter=addNodes.begin();iter!=addNodes.end();iter++)
953 (*iter)->applySimilarity(xBary,yBary,dimChar);
954 applySimilarity(xBary,yBary,dimChar);
955 _start->applySimilarity(xBary,yBary,dimChar);
956 _end->applySimilarity(xBary,yBary,dimChar);
957 std::size_t sz=addNodes.size();
958 std::vector< std::pair<double,Node *> > an2(sz);
959 for(std::size_t i=0;i<sz;i++)
960 an2[i]=std::pair<double,Node *>(getCharactValueBtw0And1(*addNodes[i]),addNodes[i]);
961 std::sort(an2.begin(),an2.end());
962 int startId=(*mapp1.find(_start)).second;
963 int endId=(*mapp1.find(_end)).second;
964 std::vector<int> tmpp;
965 std::vector< std::pair<double,Node *> >::const_iterator itend=std::unique(an2.begin(),an2.end(),eqpair);
966 for(std::vector< std::pair<double,Node *> >::const_iterator it=an2.begin();it!=itend;it++)
968 int idd=(*mapp2.find((*it).second)).second;
969 if((*it).first<QUADRATIC_PLANAR::_precision)
974 if((*it).first>1-QUADRATIC_PLANAR::_precision)
981 std::vector<int> tmpp2(tmpp.size()+2);
983 std::copy(tmpp.begin(),tmpp.end(),tmpp2.begin()+1);
984 tmpp2[tmpp.size()+1]=endId;
985 std::vector<int>::iterator itt=std::unique(tmpp2.begin(),tmpp2.end());
986 tmpp2.resize(std::distance(tmpp2.begin(),itt));
987 int nbOfEdges=tmpp2.size()-1;
988 for(int i=0;i<nbOfEdges;i++)
990 edgesThis.push_back(tmpp2[i]);
991 edgesThis.push_back(tmpp2[i+1]);