Salome HOME
Intersec bug fix: point not added properly inserted in splitting.
[tools/medcoupling.git] / src / INTERP_KERNEL / Geometric2D / InterpKernelGeo2DEdge.cxx
index 27a9acb993a4c16b1eb59736f53e7cafdcd77525..d2a31d0cef8335edfa796785ac762fffb654cbcd 100644 (file)
@@ -28,6 +28,9 @@
 
 #include <algorithm>
 
+#include <functional>
+
+
 using namespace INTERP_KERNEL;
 
 MergePoints::MergePoints():_ass1Start1(0),_ass1End1(0),_ass1Start2(0),_ass1End2(0),
@@ -923,14 +926,25 @@ bool Edge::SplitOverlappedEdges(const Edge *e1, const Edge *e2, Node *nS, Node *
   }
 }
 
-bool Edge::isEqual(const Edge& other) const
+void Edge::dumpToCout(const std::map<INTERP_KERNEL::Node *,int>& mapp, int index) const
 {
-  return _start->isEqual(*other._start) && _end->isEqual(*other._end);
+  auto sI(mapp.find(getStartNode())), eI(mapp.find(getEndNode()));
+  int start = (sI == mapp.end() ? -1 : sI->second), end = (eI == mapp.end() ? -1 : eI->second);
+  std::string locs;
+  switch (getLoc())
+  {
+    case FULL_IN_1: locs="FULL_IN_1"; break;
+    case FULL_ON_1: locs="FULL_ON_1"; break;
+    case FULL_OUT_1: locs="FULL_OUT_1"; break;
+    case FULL_UNKNOWN: locs="FULL_UNKNOWN"; break;
+    default: locs="oh my God! This is so wrong.";
+  }
+  std::cout << "Edge [" << index << "] : ("<<  std::hex << this << std::dec << ") -> (" << start << ", " << end << ")\t" << locs << std::endl;
 }
 
-inline bool eqpair(const std::pair<double,Node *>& p1, const std::pair<double,Node *>& p2)
+bool Edge::isEqual(const Edge& other) const
 {
-  return fabs(p1.first-p2.first)<QuadraticPlanarPrecision::getPrecision();
+  return _start->isEqual(*other._start) && _end->isEqual(*other._end);
 }
 
 /**
@@ -982,6 +996,15 @@ bool Edge::sortSubNodesAbs(const double *coo, std::vector<int>& subNodes)
 void Edge::sortIdsAbs(const std::vector<INTERP_KERNEL::Node *>& addNodes, const std::map<INTERP_KERNEL::Node *, int>& mapp1,
                       const std::map<INTERP_KERNEL::Node *, int>& mapp2, std::vector<int>& edgesThis)
 {
+  int startId=(*mapp1.find(_start)).second;
+  int endId=(*mapp1.find(_end)).second;
+  if (! addNodes.size()) // quick way out, no new node to add.
+    {
+      edgesThis.push_back(startId);
+      edgesThis.push_back(endId);
+      return;
+    }
+
   Bounds b;
   b.prepareForAggregation();
   b.aggregate(getBounds());
@@ -998,11 +1021,8 @@ void Edge::sortIdsAbs(const std::vector<INTERP_KERNEL::Node *>& addNodes, const
   for(std::size_t i=0;i<sz;i++)
     an2[i]=std::pair<double,Node *>(getCharactValueBtw0And1(*addNodes[i]),addNodes[i]);
   std::sort(an2.begin(),an2.end());
-  int startId=(*mapp1.find(_start)).second;
-  int endId=(*mapp1.find(_end)).second;
   std::vector<int> tmpp;
-  std::vector< std::pair<double,Node *> >::const_iterator itend=std::unique(an2.begin(),an2.end(),eqpair);
-  for(std::vector< std::pair<double,Node *> >::const_iterator it=an2.begin();it!=itend;it++)
+  for(std::vector< std::pair<double,Node *> >::const_iterator it=an2.begin();it!=an2.end();it++)
     {
       int idd=(*mapp2.find((*it).second)).second;
       if((*it).first<QuadraticPlanarPrecision::getPrecision())
@@ -1030,3 +1050,31 @@ void Edge::sortIdsAbs(const std::vector<INTERP_KERNEL::Node *>& addNodes, const
       edgesThis.push_back(tmpp2[i+1]);
     }
 }
+
+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,
+                                std::vector<int>& edgesThis, std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int> mapAddCoo) const
+{
+  int tmp[2];
+  _start->fillGlobalInfoAbs(mapThis,mapOther,offset1,offset2,fact,baryX,baryY,addCoo,mapAddCoo,tmp);
+  _end->fillGlobalInfoAbs(mapThis,mapOther,offset1,offset2,fact,baryX,baryY,addCoo,mapAddCoo,tmp+1);
+  if(direction)
+    {
+      edgesThis.push_back(tmp[0]);
+      edgesThis.push_back(tmp[1]);
+    }
+  else
+    {
+      edgesThis.push_back(tmp[1]);
+      edgesThis.push_back(tmp[0]);
+    }
+}
+
+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,
+                              unsigned skipStartOrEnd,
+                              std::vector<int>& edgesOther, std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int>& mapAddCoo) const
+{
+  if (skipStartOrEnd != 1) // see meaning in splitAbs()
+    _start->fillGlobalInfoAbs2(mapThis,mapOther,offset1,offset2,fact,baryX,baryY,addCoo,mapAddCoo,edgesOther);
+  if (skipStartOrEnd != 2)
+  _end->fillGlobalInfoAbs2(mapThis,mapOther,offset1,offset2,fact,baryX,baryY,addCoo,mapAddCoo,edgesOther);
+}