1 // Copyright (C) 2007-2016 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"
34 using namespace INTERP_KERNEL;
36 MergePoints::MergePoints():_ass1Start1(0),_ass1End1(0),_ass1Start2(0),_ass1End2(0),
37 _ass2Start1(0),_ass2End1(0),_ass2Start2(0),_ass2End2(0)
41 void MergePoints::start1Replaced()
43 unsigned nbOfAsso=getNumberOfAssociations();
50 void MergePoints::end1Replaced()
52 unsigned nbOfAsso=getNumberOfAssociations();
59 void MergePoints::start1OnStart2()
61 unsigned nbOfAsso=getNumberOfAssociations();
74 void MergePoints::start1OnEnd2()
76 unsigned nbOfAsso=getNumberOfAssociations();
89 void MergePoints::end1OnStart2()
91 unsigned nbOfAsso=getNumberOfAssociations();
104 void MergePoints::end1OnEnd2()
106 unsigned nbOfAsso=getNumberOfAssociations();
119 bool MergePoints::isStart1(unsigned rk) const
127 bool MergePoints::isEnd1(unsigned rk) const
135 bool MergePoints::isStart2(unsigned rk) const
143 bool MergePoints::isEnd2(unsigned rk) const
151 void MergePoints::clear()
153 _ass1Start1=0;_ass1End1=0;_ass1Start2=0;_ass1End2=0;
154 _ass2Start1=0;_ass2End1=0;_ass2Start2=0;_ass2End2=0;
157 unsigned MergePoints::getNumberOfAssociations() const
160 unsigned subTot=_ass1Start1+_ass1End1+_ass1Start2+_ass1End2;
163 subTot=_ass2Start1+_ass2End1+_ass2Start2+_ass2End2;
169 void MergePoints::PushInMap(int key, int value, std::map<int,int>& mergedNodes)
171 if(key!=-1 && value!=-1)
172 mergedNodes[key]=value;
175 void MergePoints::updateMergedNodes(int e1Start, int e1End, int e2Start, int e2End, std::map<int,int>& mergedNodes)
177 unsigned subTot(_ass1Start1+_ass1End1+_ass1Start2+_ass1End2);
180 if(_ass1Start1 && _ass1Start2)
181 PushInMap(e2Start,e1Start,mergedNodes);
182 if(_ass1Start1 && _ass1End2)
183 PushInMap(e2End,e1Start,mergedNodes);
184 if(_ass1End1 && _ass1Start2)
185 PushInMap(e2Start,e1End,mergedNodes);
186 if(_ass1End1 && _ass1End2)
187 PushInMap(e2End,e1End,mergedNodes);
189 subTot=_ass2Start1+_ass2End1+_ass2Start2+_ass2End2;
192 if(_ass2Start1 && _ass2Start2)
193 PushInMap(e2Start,e1Start,mergedNodes);
194 if(_ass2Start1 && _ass2End2)
195 PushInMap(e2End,e1Start,mergedNodes);
196 if(_ass2End1 && _ass2Start2)
197 PushInMap(e2Start,e1End,mergedNodes);
198 if(_ass2End1 && _ass2End2)
199 PushInMap(e2End,e1End,mergedNodes);
203 IntersectElement::IntersectElement(double val1, double val2, bool start1, bool end1, bool start2, bool end2, Node *node
204 , const Edge& e1, const Edge& e2, bool keepOrder):_1S(keepOrder?start1:start2),
205 _1E(keepOrder?end1:end2),
206 _2S(keepOrder?start2:start1),
207 _2E(keepOrder?end2:end1),
208 _chararct_val_for_e1(keepOrder?val1:val2),
209 _chararct_val_for_e2(keepOrder?val2:val1),
210 _node(node),_loc_of_node(node->getLoc()),_e1(keepOrder?e1:e2),
215 IntersectElement::IntersectElement(const IntersectElement& other):_1S(other._1S),_1E(other._1E),_2S(other._2S),_2E(other._2E),
216 _chararct_val_for_e1(other._chararct_val_for_e1),
217 _chararct_val_for_e2(other._chararct_val_for_e2),_node(other._node),
218 _loc_of_node(other._loc_of_node),_e1(other._e1), _e2(other._e2)
224 IntersectElement& IntersectElement::operator=(const IntersectElement& other)
226 _1S=other._1S;_1E=other._1E; _2S=other._2S; _2E=other._2E;
227 _chararct_val_for_e1=other._chararct_val_for_e1;
228 _chararct_val_for_e2=other._chararct_val_for_e2;
229 setNode(other._node);
233 bool IntersectElement::operator<(const IntersectElement& other) const
235 return _e1.isLower(_chararct_val_for_e1,other._chararct_val_for_e1);
238 IntersectElement::~IntersectElement()
247 bool IntersectElement::isOnMergedExtremity() const
249 if( (_1S && _2S) || (_1S && _2E) || (_1E && _2S) || (_1E && _2E) )
255 * To call if isOnMergedExtremity returned true.
257 void IntersectElement::performMerging(MergePoints& commonNode) const
261 if(_e1.changeStartNodeWith(_e2.getStartNode()))
263 _e2.getStartNode()->declareOnLim();
264 commonNode.start1OnStart2();
269 if(_e1.changeStartNodeWith(_e2.getEndNode()))
271 _e2.getEndNode()->declareOnLim();
272 commonNode.start1OnEnd2();
277 if(_e1.changeEndNodeWith(_e2.getStartNode()))
279 _e2.getStartNode()->declareOnLim();
280 commonNode.end1OnStart2();
285 if(_e1.changeEndNodeWith(_e2.getEndNode()))
287 _e2.getEndNode()->declareOnLim();
288 commonNode.end1OnEnd2();
294 * This method is const because 'node' is supposed to be equal geometrically to _node.
296 void IntersectElement::setNode(Node *node) const
301 ((Node *)_node)->decrRef();
302 (const_cast<IntersectElement *>(this))->_node=node;
308 bool IntersectElement::isLowerOnOther(const IntersectElement& other) const
310 return _e2.isLower(_chararct_val_for_e2,other._chararct_val_for_e2);
313 unsigned IntersectElement::isOnExtrForAnEdgeAndInForOtherEdge() const
315 if(( _1S && !(_2S || _2E) ) || ( _1E && !(_2S || _2E) ))
317 if(_1S && !(_2S || _2E))
318 setNode(_e1.getStartNode());
320 setNode(_e1.getEndNode());
321 if(_e2.isIn(_chararct_val_for_e2))
325 if(( _2S && !(_1S || _1E) ) || ( _2E && !(_1S || _1E)))
327 if(_2S && !(_1S || _1E))
328 setNode(_e2.getStartNode());
330 setNode(_e2.getEndNode());
331 if(_e1.isIn(_chararct_val_for_e1))
338 bool IntersectElement::isIncludedByBoth() const
340 return _e1.isIn(_chararct_val_for_e1) && _e2.isIn(_chararct_val_for_e2);
343 bool EdgeIntersector::intersect(const Bounds *whereToFind, std::vector<Node *>& newNodes, bool& order, MergePoints& commonNode)
345 std::list< IntersectElement > listOfIntesc=getIntersectionsCharacteristicVal();
346 std::list< IntersectElement >::iterator iter;
347 for(iter=listOfIntesc.begin();iter!=listOfIntesc.end();)
349 if((*iter).isOnMergedExtremity())
351 (*iter).performMerging(commonNode);
352 iter=listOfIntesc.erase(iter);
355 unsigned tmp=(*iter).isOnExtrForAnEdgeAndInForOtherEdge();
356 if(tmp==IntersectElement::LIMIT_ALONE)
358 iter=listOfIntesc.erase(iter);
361 else if(tmp==IntersectElement::LIMIT_ON)
367 if(!(*iter).isIncludedByBoth())
369 iter=listOfIntesc.erase(iter);
375 if(listOfIntesc.size()==0)
377 if(listOfIntesc.size()==1)
380 newNodes.push_back(listOfIntesc.front().getNodeAndReleaseIt());
384 std::vector<IntersectElement> vecOfIntesc(listOfIntesc.begin(),listOfIntesc.end());
385 listOfIntesc.clear();
386 sort(vecOfIntesc.begin(),vecOfIntesc.end());
387 for(std::vector<IntersectElement>::iterator iterV=vecOfIntesc.begin();iterV!=vecOfIntesc.end();iterV++)
388 newNodes.push_back((*iterV).getNodeAndReleaseIt());
389 order=vecOfIntesc.front().isLowerOnOther(vecOfIntesc.back());
395 * Locates 'node' regarding edge this->_e1. If node is located close to (with distant lt epsilon) start or end point of _e1,
396 * 'node' takes its place. In this case 'obvious' is set to true and 'commonNode' stores information of merge point and finally 'where' is set.
397 * Furthermore 'node' is declared as ON LIMIT to indicate in locating process that an absolute location computation will have to be done.
398 * If 'node' is not close to start or end point of _e1, 'obvious' is set to false and 'commonNode' and 'where' are let unchanged.
400 void EdgeIntersector::obviousCaseForCurvAbscisse(Node *node, TypeOfLocInEdge& where, MergePoints& commonNode, bool& obvious) const
403 if(node->isEqual(*_e1.getStartNode()))
406 if(_e1.changeStartNodeWith(node))
408 commonNode.start1Replaced();
409 node->declareOnLim();
413 if(node->isEqual(*_e1.getEndNode()))
416 if(_e1.changeEndNodeWith(node))
418 commonNode.end1Replaced();
419 node->declareOnLim();
426 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))
439 bool ret=(--_cnt==0);
445 void Edge::declareOn() const
447 if(_loc==FULL_UNKNOWN)
455 void Edge::declareIn() const
457 if(_loc==FULL_UNKNOWN)
465 void Edge::declareOut() const
467 if(_loc==FULL_UNKNOWN)
470 _start->declareOut();
475 void Edge::fillXfigStreamForLoc(std::ostream& stream) const
480 stream << '2';//Green
483 stream << '1';//Bleue
493 bool Edge::changeStartNodeWith(Node *otherStartNode) const
495 if(_start==otherStartNode)
497 if(_start->isEqual(*otherStartNode))
499 ((const_cast<Edge *>(this))->_start)->decrRef();//un-const cast Ok thanks to 2 lines above.
500 ((const_cast<Edge *>(this))->_start)=otherStartNode;
507 bool Edge::changeStartNodeWithAndKeepTrack(Node *otherStartNode, std::vector<Node *>& track) const
509 if(_start==otherStartNode)
511 if(_start->isEqualAndKeepTrack(*otherStartNode,track))
513 ((const_cast<Edge *>(this))->_start)->decrRef();//un-const cast Ok thanks to 2 lines above.
514 ((const_cast<Edge *>(this))->_start)=otherStartNode;
515 otherStartNode->incrRef();
521 bool Edge::changeEndNodeWith(Node *otherEndNode) const
523 if(_end==otherEndNode)
525 if(_end->isEqual(*otherEndNode))
527 ((const_cast<Edge *>(this))->_end)->decrRef();
528 ((const_cast<Edge *>(this))->_end)=otherEndNode;
535 bool Edge::changeEndNodeWithAndKeepTrack(Node *otherEndNode, std::vector<Node *>& track) const
537 if(_end==otherEndNode)
539 if(_end->isEqualAndKeepTrack(*otherEndNode,track))
541 ((const_cast<Edge *>(this))->_end)->decrRef();
542 ((const_cast<Edge *>(this))->_end)=otherEndNode;
543 otherEndNode->incrRef();
550 * Precondition : 'start' and 'end' are lying on the same curve than 'this'.
551 * Add in vec the sub edge lying on this.
552 * If 'start' is equal (by pointer) to '_end' and 'end' is equal to '_end' too nothing is added.
553 * If 'start' is equal (by pointer) to '_start' and 'end' is equal to '_start' too nothing is added.
554 * If 'start' is equal (by pointer) to '_start' and 'end' is equal to '_end' this is added in vec.
556 void Edge::addSubEdgeInVector(Node *start, Node *end, ComposedEdge& vec) const
558 if((start==_start && end==_start) || (start==_end && end==_end))
560 if(start==_start && end==_end)
563 vec.pushBack(const_cast<Edge *>(this));
566 vec.pushBack(buildEdgeLyingOnMe(start,end,true));
570 * Retrieves a vector 'vectOutput' that is normal to 'this'. 'vectOutput' is normalized.
572 void Edge::getNormalVector(double *vectOutput) const
574 std::copy((const double *)(*_end),(const double *)(*_end)+2,vectOutput);
575 std::transform(vectOutput,vectOutput+2,(const double *)(*_start),vectOutput,std::minus<double>());
576 double norm=1./Node::norm(vectOutput);
577 std::transform(vectOutput,vectOutput+2,vectOutput,bind2nd(std::multiplies<double>(),norm));
578 double tmp=vectOutput[0];
579 vectOutput[0]=vectOutput[1];
583 Edge *Edge::BuildEdgeFrom3Points(const double *start, const double *middle, const double *end)
585 Node *b(new Node(start[0],start[1])),*m(new Node(middle[0],middle[1])),*e(new Node(end[0],end[1]));
586 EdgeLin *e1(new EdgeLin(b,m)),*e2(new EdgeLin(m,e));
587 SegSegIntersector inters(*e1,*e2); bool colinearity=inters.areColinears(); delete e1; delete e2;
590 ret=new EdgeLin(b,e);
592 ret=new EdgeArcCircle(b,m,e);
593 b->decrRef(); m->decrRef(); e->decrRef();
597 Edge *Edge::BuildEdgeFrom(Node *start, Node *end)
599 return new EdgeLin(start,end);
602 Edge *Edge::BuildFromXfigLine(std::istream& str)
607 return new EdgeLin(str);
609 return new EdgeArcCircle(str);
612 std::cerr << "Unknown line found...";
618 * \param other The Edge with which we are going to intersect.
619 * \param commonNode Output. The common nodes found during operation of intersecting.
620 * \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.
621 * \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.
622 * return true if the intersection between this.
624 bool Edge::intersectWith(const Edge *other, MergePoints& commonNode,
625 ComposedEdge& outVal1, ComposedEdge& outVal2) const
628 Bounds *merge=_bounds.nearlyAmIIntersectingWith(other->getBounds());
633 EdgeIntersector *intersector=BuildIntersectorWith(this,other);
634 ret=Intersect(this,other,intersector,merge,commonNode,outVal1,outVal2);
639 bool Edge::IntersectOverlapped(const Edge *f1, const Edge *f2, EdgeIntersector *intersector, MergePoints& commonNode,
640 ComposedEdge& outValForF1, ComposedEdge& outValForF2)
642 bool rev=intersector->haveTheySameDirection();
643 Node *f2Start=f2->getNode(rev?START:END);
644 Node *f2End=f2->getNode(rev?END:START);
645 TypeOfLocInEdge place1, place2;
646 intersector->getPlacements(f2Start,f2End,place1,place2,commonNode);
647 int codeForIntersectionCase=CombineCodes(place1,place2);
648 return SplitOverlappedEdges(f1,f2,f2Start,f2End,rev,codeForIntersectionCase,outValForF1,outValForF2);
652 * Perform 1D linear interpolation. Warning distrib1 and distrib2 are expected to be in ascending mode.
654 void Edge::Interpolate1DLin(const std::vector<double>& distrib1, const std::vector<double>& distrib2, std::map<int, std::map<int,double> >& result)
656 int nbOfV1=distrib1.size()-1;
657 int nbOfV2=distrib2.size()-1;
658 Node *n1=new Node(0.,0.); Node *n3=new Node(0.,0.);
659 Node *n2=new Node(0.,0.); Node *n4=new Node(0.,0.);
660 MergePoints commonNode;
661 for(int i=0;i<nbOfV1;i++)
663 std::vector<double>::const_iterator iter=find_if(distrib2.begin()+1,distrib2.end(),bind2nd(std::greater_equal<double>(),distrib1[i]));
664 if(iter!=distrib2.end())
666 for(int j=(iter-1)-distrib2.begin();j<nbOfV2;j++)
668 if(distrib2[j]<=distrib1[i+1])
670 EdgeLin *e1=new EdgeLin(n1,n2); EdgeLin *e2=new EdgeLin(n3,n4);
671 n1->setNewCoords(distrib1[i],0.); n2->setNewCoords(distrib1[i+1],0.);
672 n3->setNewCoords(distrib2[j],0.); n4->setNewCoords(distrib2[j+1],0.);
673 ComposedEdge *f1=new ComposedEdge;
674 ComposedEdge *f2=new ComposedEdge;
675 SegSegIntersector inters(*e1,*e2);
677 inters.areOverlappedOrOnlyColinears(0,b1,b2);
678 if(IntersectOverlapped(e1,e2,&inters,commonNode,*f1,*f2))
680 result[i][j]=f1->getCommonLengthWith(*f2)/e1->getCurveLength();
682 ComposedEdge::Delete(f1); ComposedEdge::Delete(f2);
683 e1->decrRef(); e2->decrRef();
688 n1->decrRef(); n2->decrRef(); n3->decrRef(); n4->decrRef();
691 EdgeIntersector *Edge::BuildIntersectorWith(const Edge *e1, const Edge *e2)
693 EdgeIntersector *ret=0;
694 const EdgeLin *tmp1=0;
695 const EdgeArcCircle *tmp2=0;
696 unsigned char type1=e1->getTypeOfFunc();
697 e1->dynCastFunction(tmp1,tmp2);
698 unsigned char type2=e2->getTypeOfFunc();
699 e2->dynCastFunction(tmp1,tmp2);
703 case 1:// Intersection seg/seg
704 ret=new SegSegIntersector((const EdgeLin &)(*e1),(const EdgeLin &)(*e2));
706 case 5:// Intersection seg/arc of circle
707 ret=new ArcCSegIntersector(*tmp2,*tmp1,tmp2==e1);
709 case 4:// Intersection arc/arc of circle
710 ret=new ArcCArcCIntersector((const EdgeArcCircle &)(*e1),(const EdgeArcCircle &)(*e2));
713 //Should never happen
714 throw Exception("A non managed association of edge has been detected. Go work for intersection computation implementation.");
720 * See Node::applySimilarity to see signification of params.
722 void Edge::applySimilarity(double xBary, double yBary, double dimChar)
724 _bounds.applySimilarity(xBary,yBary,dimChar);
727 void Edge::unApplySimilarity(double xBary, double yBary, double dimChar)
729 _bounds.unApplySimilarity(xBary,yBary,dimChar);
732 void Edge::getMiddleOfPointsOriented(const double *p1, const double *p2, double *mid) const
734 return getMiddleOfPoints(p1, p2, mid);
737 bool Edge::Intersect(const Edge *f1, const Edge *f2, EdgeIntersector *intersector, const Bounds *whereToFind, MergePoints& commonNode,
738 ComposedEdge& outValForF1, ComposedEdge& outValForF2)
740 bool obviousNoIntersection;
742 intersector->areOverlappedOrOnlyColinears(whereToFind,obviousNoIntersection,areOverlapped);
744 return IntersectOverlapped(f1,f2,intersector,commonNode,outValForF1,outValForF2);
745 if(obviousNoIntersection)
747 std::vector<Node *> newNodes;
749 if(intersector->intersect(whereToFind,newNodes,order,commonNode))
752 throw Exception("Internal error occurred - error in intersector implementation!");// This case should never happen
753 std::vector<Node *>::iterator iter=newNodes.begin();
754 std::vector<Node *>::reverse_iterator iterR=newNodes.rbegin();
755 f1->addSubEdgeInVector(f1->getStartNode(),*iter,outValForF1);
756 f2->addSubEdgeInVector(f2->getStartNode(),order?*iter:*iterR,outValForF2);
757 for(std::vector<Node *>::iterator iter2=newNodes.begin();iter2!=newNodes.end();iter2++,iterR++)
759 if((iter2+1)==newNodes.end())
761 f1->addSubEdgeInVector(*iter2,f1->getEndNode(),outValForF1);
763 f2->addSubEdgeInVector(order?*iter2:*iterR,f2->getEndNode(),outValForF2);
767 f1->addSubEdgeInVector(*iter2,*(iter2+1),outValForF1);
769 f2->addSubEdgeInVector(order?*iter2:*iterR,order?*(iter2+1):*(iterR+1),outValForF2);
774 else//no intersection inside whereToFind
778 int Edge::CombineCodes(TypeOfLocInEdge code1, TypeOfLocInEdge code2)
781 ret*=OFFSET_FOR_TYPEOFLOCINEDGE;
787 * This method splits e1 and e2 into pieces as much sharable as possible. The precondition to the call of this method
788 * is that e1 and e2 have been declared as overlapped by corresponding intersector built from e1 and e2 type.
790 * @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.
791 * @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.
792 * @param direction is param that specifies if e2 and e1 have same directions (true) or opposed (false).
793 * @param code is the code returned by method Edge::combineCodes.
795 bool Edge::SplitOverlappedEdges(const Edge *e1, const Edge *e2, Node *nS, Node *nE, bool direction, int code,
796 ComposedEdge& outVal1, ComposedEdge& outVal2)
801 case OUT_BEFORE*OFFSET_FOR_TYPEOFLOCINEDGE+START: // OUT_BEFORE - START
802 case OUT_BEFORE*OFFSET_FOR_TYPEOFLOCINEDGE+OUT_BEFORE: // OUT_BEFORE - OUT_BEFORE
803 case OUT_AFTER*OFFSET_FOR_TYPEOFLOCINEDGE+OUT_AFTER: // OUT_AFTER - OUT_AFTER
804 case END*OFFSET_FOR_TYPEOFLOCINEDGE+OUT_AFTER: // END - OUT_AFTER
805 case END*OFFSET_FOR_TYPEOFLOCINEDGE+START: // END - START
807 case INSIDE*OFFSET_FOR_TYPEOFLOCINEDGE+OUT_AFTER: // INSIDE - OUT_AFTER
808 outVal1.pushBack(e1->buildEdgeLyingOnMe(e1->getStartNode(),nS,true));
809 tmp=e1->buildEdgeLyingOnMe(nS,e1->getEndNode()); tmp->incrRef();
810 outVal1.pushBack(tmp);
812 outVal2.setValueAt(direction?0:1,tmp,direction); tmp->declareOn();
813 outVal2.setValueAt(direction?1:0,e1->buildEdgeLyingOnMe(e1->getEndNode(),nE,direction));
815 case INSIDE*OFFSET_FOR_TYPEOFLOCINEDGE+INSIDE: // INSIDE - INSIDE
817 if(!e2->isIn(e2->getCharactValue(*(e1->getStartNode()))))
819 e2->incrRef(); e2->incrRef();
821 outVal1.setValueAt(0,e1->buildEdgeLyingOnMe(e1->getStartNode(),nS));
822 outVal1.setValueAt(1,const_cast<Edge*>(e2),direction);
823 outVal1.setValueAt(2,e1->buildEdgeLyingOnMe(nE,e1->getEndNode()));
824 outVal2.pushBack(const_cast<Edge*>(e2)); e2->declareOn();
831 tmp=e1->buildEdgeLyingOnMe(e1->getStartNode(),nE); tmp->incrRef(); tmp->declareOn();
832 outVal1.setValueAt(0,tmp,true); outVal2.setValueAt(direction?2:0,tmp,direction);
833 outVal1.setValueAt(1,e1->buildEdgeLyingOnMe(nE,nS));
834 tmp=e1->buildEdgeLyingOnMe(nS,e1->getEndNode()); tmp->incrRef(); tmp->declareOn();
835 outVal1.setValueAt(2,tmp,true); outVal2.setValueAt(direction?0:2,tmp,direction);
836 tmp=e1->buildEdgeLyingOnMe(e1->getEndNode(),e1->getStartNode());
837 outVal2.setValueAt(1,tmp,direction);
841 case OUT_BEFORE*OFFSET_FOR_TYPEOFLOCINEDGE+INSIDE: // OUT_BEFORE - INSIDE
843 tmp=e1->buildEdgeLyingOnMe(e1->getStartNode(),nE); tmp->incrRef();
844 outVal1.pushBack(tmp);
845 outVal1.pushBack(e1->buildEdgeLyingOnMe(nE,e1->getEndNode()));
847 outVal2.setValueAt(direction?0:1,e1->buildEdgeLyingOnMe(nS,e1->getStartNode(),direction));
848 outVal2.setValueAt(direction?1:0,tmp,direction); tmp->declareOn();
851 case OUT_BEFORE*OFFSET_FOR_TYPEOFLOCINEDGE+OUT_AFTER: // OUT_BEFORE - OUT_AFTER
853 e1->incrRef(); e1->incrRef();
854 outVal1.pushBack(const_cast<Edge*>(e1));
856 outVal2.setValueAt(direction?0:2,e1->buildEdgeLyingOnMe(nS,e1->getStartNode(),direction));
857 outVal2.setValueAt(1,const_cast<Edge*>(e1),direction); e1->declareOn();
858 outVal2.setValueAt(direction?2:0,e1->buildEdgeLyingOnMe(e1->getEndNode(),nE,direction));
861 case START*OFFSET_FOR_TYPEOFLOCINEDGE+END: // START - END
863 e1->incrRef(); e1->incrRef();
864 outVal1.pushBack(const_cast<Edge*>(e1));
865 outVal2.pushBack(const_cast<Edge*>(e1),direction); e1->declareOn();
868 case START*OFFSET_FOR_TYPEOFLOCINEDGE+OUT_AFTER: // START - OUT_AFTER
870 e1->incrRef(); e1->incrRef();
871 outVal1.pushBack(const_cast<Edge*>(e1));
873 outVal2.setValueAt(direction?0:1,const_cast<Edge*>(e1),direction); e1->declareOn();
874 outVal2.setValueAt(direction?1:0,e1->buildEdgeLyingOnMe(e1->getEndNode(),nE,direction));
877 case INSIDE*OFFSET_FOR_TYPEOFLOCINEDGE+END: // INSIDE - END
879 e2->incrRef(); e2->incrRef();
880 outVal1.pushBack(e1->buildEdgeLyingOnMe(e1->getStartNode(),nS,true));
881 outVal1.pushBack(const_cast<Edge*>(e2),direction);
882 outVal2.pushBack(const_cast<Edge*>(e2)); e2->declareOn();
885 case OUT_BEFORE*OFFSET_FOR_TYPEOFLOCINEDGE+END: // OUT_BEFORE - END
887 e1->incrRef(); e1->incrRef();
888 outVal1.pushBack(const_cast<Edge*>(e1));
890 outVal2.setValueAt(direction?0:1,e1->buildEdgeLyingOnMe(nS,e1->getStartNode(),direction));
891 outVal2.setValueAt(direction?1:0,const_cast<Edge*>(e1),direction); e1->declareOn();
894 case START*OFFSET_FOR_TYPEOFLOCINEDGE+INSIDE: // START - INSIDE
896 e2->incrRef(); e2->incrRef();
897 outVal1.pushBack(const_cast<Edge*>(e2),direction);
898 outVal1.pushBack(e1->buildEdgeLyingOnMe(nE,e1->getEndNode()));
899 outVal2.pushBack(const_cast<Edge*>(e2)); e2->declareOn();
902 case INSIDE*OFFSET_FOR_TYPEOFLOCINEDGE+START: // INSIDE - START
906 tmp=e1->buildEdgeLyingOnMe(nS,e1->getEndNode()); tmp->incrRef(); tmp->declareOn();
907 outVal1.setValueAt(0,e1->buildEdgeLyingOnMe(e1->getStartNode(),nS));
908 outVal1.setValueAt(1,tmp);
909 outVal2.setValueAt(direction?0:1,tmp,direction);
910 outVal2.setValueAt(direction?1:0,e1->buildEdgeLyingOnMe(e1->getEndNode(),nE,direction));
913 case END*OFFSET_FOR_TYPEOFLOCINEDGE+INSIDE: // END - INSIDE
917 tmp=e1->buildEdgeLyingOnMe(e1->getStartNode(),nE); tmp->incrRef(); tmp->declareOn();
918 outVal1.setValueAt(0,tmp);
919 outVal1.setValueAt(1,e1->buildEdgeLyingOnMe(nE,e1->getEndNode()));
920 outVal2.setValueAt(direction?0:1,e1->buildEdgeLyingOnMe(e1->getEndNode(),e1->getStartNode(),direction));
921 outVal2.setValueAt(direction?1:0,tmp,direction);
925 throw Exception("Unexpected situation of overlapping edges : internal error occurs ! ");
929 void Edge::dumpToCout(const std::map<INTERP_KERNEL::Node *,int>& mapp, int index) const
931 auto sI(mapp.find(getStartNode())), eI(mapp.find(getEndNode()));
932 int start = (sI == mapp.end() ? -1 : sI->second), end = (eI == mapp.end() ? -1 : eI->second);
936 case FULL_IN_1: locs="FULL_IN_1"; break;
937 case FULL_ON_1: locs="FULL_ON_1"; break;
938 case FULL_OUT_1: locs="FULL_OUT_1"; break;
939 case FULL_UNKNOWN: locs="FULL_UNKNOWN"; break;
940 default: locs="oh my God! This is so wrong.";
942 std::cout << "Edge [" << index << "] : ("<< std::hex << this << std::dec << ") -> (" << start << ", " << end << ")\t" << locs << std::endl;
945 bool Edge::isEqual(const Edge& other) const
947 return _start->isEqual(*other._start) && _end->isEqual(*other._end);
951 * This method takes in input nodes in \a subNodes (using \a coo)
953 * \param [in,out] subNodes to be sorted
954 * \return true if a reordering was necessary false if not.
956 bool Edge::sortSubNodesAbs(const double *coo, std::vector<int>& subNodes)
959 b.prepareForAggregation();
960 b.aggregate(getBounds());
962 double dimChar(b.getCaracteristicDim());
963 b.getBarycenter(xBary,yBary);
964 applySimilarity(xBary,yBary,dimChar);
965 _start->applySimilarity(xBary,yBary,dimChar);
966 _end->applySimilarity(xBary,yBary,dimChar);
968 std::size_t sz(subNodes.size()),i(0);
969 std::vector< std::pair<double,Node *> > an2(sz);
970 std::map<Node *, int> m;
971 for(std::vector<int>::const_iterator it=subNodes.begin();it!=subNodes.end();it++,i++)
973 Node *n(new Node(coo[2*(*it)],coo[2*(*it)+1]));
974 n->applySimilarity(xBary,yBary,dimChar);
976 an2[i]=std::pair<double,Node *>(getCharactValueBtw0And1(*n),n);
978 std::sort(an2.begin(),an2.end());
983 int id(m[an2[i].second]);
985 { subNodes[i]=id; ret=true; }
988 for(std::map<INTERP_KERNEL::Node *,int>::const_iterator it2=m.begin();it2!=m.end();it2++)
989 (*it2).first->decrRef();
994 * Sort nodes so that they all lie consecutively on the edge that has been cut.
996 void Edge::sortIdsAbs(const std::vector<INTERP_KERNEL::Node *>& addNodes, const std::map<INTERP_KERNEL::Node *, int>& mapp1,
997 const std::map<INTERP_KERNEL::Node *, int>& mapp2, std::vector<int>& edgesThis)
999 int startId=(*mapp1.find(_start)).second;
1000 int endId=(*mapp1.find(_end)).second;
1001 if (! addNodes.size()) // quick way out, no new node to add.
1003 edgesThis.push_back(startId);
1004 edgesThis.push_back(endId);
1009 b.prepareForAggregation();
1010 b.aggregate(getBounds());
1012 double dimChar=b.getCaracteristicDim();
1013 b.getBarycenter(xBary,yBary);
1014 for(std::vector<Node *>::const_iterator iter=addNodes.begin();iter!=addNodes.end();iter++)
1015 (*iter)->applySimilarity(xBary,yBary,dimChar);
1016 applySimilarity(xBary,yBary,dimChar);
1017 _start->applySimilarity(xBary,yBary,dimChar);
1018 _end->applySimilarity(xBary,yBary,dimChar);
1019 std::size_t sz=addNodes.size();
1020 std::vector< std::pair<double,Node *> > an2(sz);
1021 for(std::size_t i=0;i<sz;i++)
1022 an2[i]=std::pair<double,Node *>(getCharactValueBtw0And1(*addNodes[i]),addNodes[i]);
1023 std::sort(an2.begin(),an2.end());
1024 std::vector<int> tmpp;
1025 for(std::vector< std::pair<double,Node *> >::const_iterator it=an2.begin();it!=an2.end();it++)
1027 int idd=(*mapp2.find((*it).second)).second;
1028 if((*it).first<QuadraticPlanarPrecision::getPrecision())
1033 if((*it).first>1-QuadraticPlanarPrecision::getPrecision())
1038 tmpp.push_back(idd);
1040 std::vector<int> tmpp2(tmpp.size()+2);
1042 std::copy(tmpp.begin(),tmpp.end(),tmpp2.begin()+1);
1043 tmpp2[tmpp.size()+1]=endId;
1044 std::vector<int>::iterator itt=std::unique(tmpp2.begin(),tmpp2.end());
1045 tmpp2.resize(std::distance(tmpp2.begin(),itt));
1046 int nbOfEdges=tmpp2.size()-1;
1047 for(int i=0;i<nbOfEdges;i++)
1049 edgesThis.push_back(tmpp2[i]);
1050 edgesThis.push_back(tmpp2[i+1]);
1054 void Edge::fillGlobalInfoAbs(bool direction, const std::map<INTERP_KERNEL::Node *,int>& mapThis, const std::map<INTERP_KERNEL::Node *,int>& mapOther, int offset1, int offset2, double fact, double baryX, double baryY,
1055 std::vector<int>& edgesThis, std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int> mapAddCoo) const
1058 _start->fillGlobalInfoAbs(mapThis,mapOther,offset1,offset2,fact,baryX,baryY,addCoo,mapAddCoo,tmp);
1059 _end->fillGlobalInfoAbs(mapThis,mapOther,offset1,offset2,fact,baryX,baryY,addCoo,mapAddCoo,tmp+1);
1062 edgesThis.push_back(tmp[0]);
1063 edgesThis.push_back(tmp[1]);
1067 edgesThis.push_back(tmp[1]);
1068 edgesThis.push_back(tmp[0]);
1072 void Edge::fillGlobalInfoAbs2(const std::map<INTERP_KERNEL::Node *,int>& mapThis, const std::map<INTERP_KERNEL::Node *,int>& mapOther, int offset1, int offset2, double fact, double baryX, double baryY,
1073 std::vector<int>& edgesOther, std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int>& mapAddCoo) const
1075 _start->fillGlobalInfoAbs2(mapThis,mapOther,offset1,offset2,fact,baryX,baryY,addCoo,mapAddCoo,edgesOther);
1076 _end->fillGlobalInfoAbs2(mapThis,mapOther,offset1,offset2,fact,baryX,baryY,addCoo,mapAddCoo,edgesOther);