Salome HOME
addition of MEDCouplingUMesh::conformize2D to conformize a 2D mesh
[tools/medcoupling.git] / src / INTERP_KERNEL / Geometric2D / InterpKernelGeo2DEdge.cxx
index 6d2e6ebee85e9519b9a5cd5e5d3b432ee26d076c..f13b409dd5bbc3ca875a15c17db2dfc96a7170d0 100644 (file)
@@ -876,6 +876,49 @@ inline bool eqpair(const std::pair<double,Node *>& p1, const std::pair<double,No
   return fabs(p1.first-p2.first)<QUADRATIC_PLANAR::_precision;
 }
 
+/**
+ * This method takes in input nodes in \a subNodes (using \a coo)
+ *
+ * \param [in,out] subNodes to be sorted
+ * \return true if a reordering was necessary false if not.
+ */
+bool Edge::sortSubNodesAbs(const double *coo, std::vector<int>& subNodes)
+{
+  Bounds b;
+  b.prepareForAggregation();
+  b.aggregate(getBounds());
+  double xBary,yBary;
+  double dimChar(b.getCaracteristicDim());
+  b.getBarycenter(xBary,yBary);
+  applySimilarity(xBary,yBary,dimChar);
+  _start->applySimilarity(xBary,yBary,dimChar);
+  _end->applySimilarity(xBary,yBary,dimChar);
+  //
+  std::size_t sz(subNodes.size()),i(0);
+  std::vector< std::pair<double,Node *> > an2(sz);
+  std::map<Node *, int> m;
+  for(std::vector<int>::const_iterator it=subNodes.begin();it!=subNodes.end();it++,i++)
+    {
+      Node *n(new Node(coo[2*(*it)],coo[2*(*it)+1]));
+      n->applySimilarity(xBary,yBary,dimChar);
+      m[n]=*it;
+      an2[i]=std::pair<double,Node *>(getCharactValueBtw0And1(*n),n);
+    }
+  std::sort(an2.begin(),an2.end());
+  //
+  bool ret(false);
+  for(i=0;i<sz;i++)
+    {
+      int id(m[an2[i].second]);
+      if(id!=subNodes[i])
+        { subNodes[i]=id; ret=true; }
+    }
+  //
+  for(std::map<INTERP_KERNEL::Node *,int>::const_iterator it2=m.begin();it2!=m.end();it2++)
+    (*it2).first->decrRef();
+  return ret;
+}
+
 /**
  * Sort nodes so that they all lie consecutively on the edge that has been cut.
  */