]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Intersect2DMeshWith1DLine: variable name formatting + introducing reverse intersect_1D_OK
authorabn <adrien.bruneton@cea.fr>
Thu, 12 Jun 2014 13:36:55 +0000 (15:36 +0200)
committerabn <adrien.bruneton@cea.fr>
Thu, 12 Jun 2014 13:36:55 +0000 (15:36 +0200)
iterator on ComposedEdge.

src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DAbstractEdge.cxx
src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DAbstractEdge.hxx
src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.hxx
src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.cxx
src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.hxx
src/MEDCoupling/MEDCouplingUMesh.cxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index c688752980115439824dd8b5fa616238c55c1f06..8059388e5bc40f1c67a55224c9ea72cb216d7b64 100644 (file)
@@ -116,3 +116,41 @@ void IteratorOnComposedEdge::insertElemEdges(ComposedEdge *elems, bool changeMyS
     }
 }
 
+
+ReverseIteratorOnComposedEdge::ReverseIteratorOnComposedEdge():_list_handle(0)
+{
+}
+
+ReverseIteratorOnComposedEdge::ReverseIteratorOnComposedEdge(ComposedEdge *compEdges):_list_handle(compEdges->getListBehind())
+{
+  first();
+}
+
+void ReverseIteratorOnComposedEdge::operator=(const ReverseIteratorOnComposedEdge& other)
+{
+  _deep_it = other._deep_it;
+  _list_handle = other._list_handle;
+}
+
+void ReverseIteratorOnComposedEdge::last()
+{
+  _deep_it = _list_handle->rend();
+  _deep_it--;
+}
+
+void ReverseIteratorOnComposedEdge::nextLoop()
+{
+  _deep_it++;
+  if(_deep_it == _list_handle->rend())
+    first();
+}
+
+void ReverseIteratorOnComposedEdge::previousLoop()
+{
+  if(_deep_it != _list_handle->rbegin())
+    _deep_it--;
+  else
+    last();
+}
+
+
index 952262ef3236cc46ad7df19710fff5920158621c..c99ea5edeec0bb7c0ec11bf102a1e241bfd101cd 100644 (file)
@@ -63,6 +63,35 @@ namespace INTERP_KERNEL
     std::list<ElementaryEdge *>::iterator _deep_it;
     std::list<ElementaryEdge *>* _list_handle;
   };
+
+  /**
+   * Reverse iterator on a composed edge. The looping goes from first to last.
+   * nextLoop() moves in the direction first->last, and prevLoop iterates in the direction
+   * last->first.
+   */
+  class ReverseIteratorOnComposedEdge
+  {
+    friend class ComposedEdge;
+    friend class ElementaryEdge;
+    friend class QuadraticPolygon;
+  public:
+    INTERPKERNEL_EXPORT ReverseIteratorOnComposedEdge();
+    INTERPKERNEL_EXPORT ReverseIteratorOnComposedEdge(ComposedEdge *compEdges);
+    INTERPKERNEL_EXPORT bool isValid() const { return _list_handle!=0; }
+    INTERPKERNEL_EXPORT void operator=(const ReverseIteratorOnComposedEdge& other);
+    INTERPKERNEL_EXPORT void first() { _deep_it=_list_handle->rbegin(); }
+    INTERPKERNEL_EXPORT void next() { _deep_it++; }
+    INTERPKERNEL_EXPORT void last();
+    INTERPKERNEL_EXPORT void nextLoop();
+    INTERPKERNEL_EXPORT void previousLoop();
+    INTERPKERNEL_EXPORT bool finished() const { return _deep_it==_list_handle->rend(); }
+    INTERPKERNEL_EXPORT ElementaryEdge *current() { return *_deep_it; }
+  private:
+    std::list<ElementaryEdge *>::reverse_iterator _deep_it;
+    std::list<ElementaryEdge *>* _list_handle;
+  };
+
 }
 
+
 #endif
index 8d815c5016ffe70cc5b402f3e0795c7c4455af32..efcb4055d5c923c45b58e676dbfa3ce1da71dbba 100644 (file)
@@ -45,6 +45,7 @@ namespace INTERP_KERNEL
   class ComposedEdge
   {
     friend class IteratorOnComposedEdge;
+    friend class ReverseIteratorOnComposedEdge;
   public:
     INTERPKERNEL_EXPORT ComposedEdge() { }
     INTERPKERNEL_EXPORT ComposedEdge(const ComposedEdge& other);
index e5eac67e56afbf0c0be2966000adf0b7c30481be..b0ca34748f931d3931f04a2b42bed847fa11fd31 100644 (file)
@@ -708,7 +708,7 @@ void QuadraticPolygon::buildPartitionsAbs(QuadraticPolygon& other, std::set<INTE
     }
 }
 
-void QuadraticPolygon::BuildPartitionFromZipList(const QuadraticPolygon & pol1, const std::list<INTERP_KERNEL::QuadraticPolygon *> & zip_list,
+void QuadraticPolygon::BuildPartitionFromZipList(const QuadraticPolygon & pol1, const std::list<INTERP_KERNEL::QuadraticPolygon *> & zipList,
                                                  std::set<INTERP_KERNEL::Edge *> & edgesThis, std::set<INTERP_KERNEL::Edge *> & edgesBoundaryOther,
                                                  const std::map<INTERP_KERNEL::Node *,int>& mapp,
                                                  const int idThis, const std::vector<std::vector<int> > & mapZipTo2,
@@ -717,8 +717,8 @@ void QuadraticPolygon::BuildPartitionFromZipList(const QuadraticPolygon & pol1,
                                                  std::vector<int>& nbThis, std::vector<int>& nbOther, std::vector<int>& nbOtherI)
 {
   std::vector<QuadraticPolygon *> res;
-  if(!zip_list.empty())
-    ClosePolygonsSimple(pol1, zip_list, res, mapZipTo2, nbOther,nbOtherI);
+  if(!zipList.empty())
+    ClosePolygonsSimple(pol1, zipList, res, mapZipTo2, nbOther,nbOtherI);
 
   for(std::vector<QuadraticPolygon *>::iterator it=res.begin();it!=res.end();it++)
     {
@@ -1206,23 +1206,23 @@ void QuadraticPolygon::ClosePolygons(std::list<QuadraticPolygon *>& pol2Zip, con
     }
 }
 
-void QuadraticPolygon::ClosePolygonsSimple(const QuadraticPolygon& pol1, const std::list<QuadraticPolygon *> & zip_list,
+void QuadraticPolygon::ClosePolygonsSimple(const QuadraticPolygon& pol1, const std::list<QuadraticPolygon *> & zipList,
                                      std::vector<QuadraticPolygon *>& results,const std::vector<std::vector<int> > & mapZipTo2,
                                      std::vector<int>& nbOther, std::vector<int>& nbOtherI)
 {
   // Register all edges of pol1 as 'alive' to start with. They will be consumed as they are
-  // added to the newly formed cells. Edges of pol2s (in zip_list) might be used more than once.
-  std::set<ElementaryEdge *> edges1_alive;
+  // added to the newly formed cells. Edges of pol2s (in zipList) might be used more than once.
+  std::set<ElementaryEdge *> edges1Alive;
   IteratorOnComposedEdge it(const_cast<QuadraticPolygon *>(&pol1));
   for(; !it.finished(); it.next())
-    edges1_alive.insert(it.current());
+    edges1Alive.insert(it.current());
 
-  int inf_loop_detect, i;
+  int infLoopDetect, i;
   std::list<QuadraticPolygon *>::const_iterator itt;
-  for (inf_loop_detect = pol1.recursiveSize() + 1, itt = zip_list.begin(); itt != zip_list.end(); itt++)
-    inf_loop_detect += 2*(*itt)->recursiveSize();
+  for (infLoopDetect = pol1.recursiveSize() + 1, itt = zipList.begin(); itt != zipList.end(); itt++)
+    infLoopDetect += 2*(*itt)->recursiveSize();
 
-  for (i = 0, it.first(); !edges1_alive.empty() && i <= inf_loop_detect;)
+  for (i = 0, it.first(); !edges1Alive.empty() && i <= infLoopDetect;)
     {
       QuadraticPolygon * qp = new QuadraticPolygon();
       results.push_back(qp);
@@ -1230,23 +1230,23 @@ void QuadraticPolygon::ClosePolygonsSimple(const QuadraticPolygon& pol1, const s
       int nbElemFrom2 = 0;
       // Start anywhere valid (=alive) on pol1
       ElementaryEdge * startE;
-      for (startE = it.current(); edges1_alive.find(it.current()) == edges1_alive.end(); it.nextLoop(), startE = it.current());
+      for (startE = it.current(); edges1Alive.find(it.current()) == edges1Alive.end(); it.nextLoop(), startE = it.current());
 
       // Close the new cell:
       do
         {
-          ElementaryEdge *tmp_e = it.current();
-          qp->pushBack(tmp_e->clone());
-          edges1_alive.erase(tmp_e);
-          Node * nodeToTest = tmp_e->getEndNode();
+          ElementaryEdge *tmpEd = it.current();
+          qp->pushBack(tmpEd->clone());
+          edges1Alive.erase(tmpEd);
+          Node * nodeToTest = tmpEd->getEndNode();
           it.nextLoop(); i++;
           // Try to match the end node of the latest added edge from pol1 with one of the node from
-          // one of the ComposedEdge in zip_list
+          // one of the ComposedEdge in zipList
           std::list<QuadraticPolygon *>::const_iterator ret;
           bool direction;
           int idx; // for mapping
-          ret = CheckInList2(nodeToTest, zip_list, direction, idx);
-          if (ret == zip_list.end())
+          ret = CheckInList2(nodeToTest, zipList, direction, idx);
+          if (ret == zipList.end())
             continue;
           size_t oldSz = nbOther.size();
           size_t addSz = std::distance(mapZipTo2[idx].begin(), mapZipTo2[idx].end());
@@ -1255,33 +1255,33 @@ void QuadraticPolygon::ClosePolygonsSimple(const QuadraticPolygon& pol1, const s
           nbElemFrom2 += addSz;
           if (!direction)
             (*ret)->reverse();  // TODO: discuss with Anthony - API of IteratorOnComposedEdge should allow an easy reverse looping?
-          // Switch to zip_list
-          IteratorOnComposedEdge it_pol2(*ret);
-          ElementaryEdge *tmp_e2;
-          for(/* it_pol2.first() */; !it_pol2.finished(); it_pol2.next(), i++)
+          // Switch to zipList
+          IteratorOnComposedEdge itPol2(*ret);
+          ElementaryEdge *tmpEd2;
+          for(/* itPol2.first() */; !itPol2.finished(); itPol2.next(), i++)
             {
-              tmp_e2 = it_pol2.current();
-              qp->pushBack(tmp_e2->clone());
+              tmpEd2 = itPol2.current();
+              qp->pushBack(tmpEd2->clone());
             }
           // search where we landed on pol1 to resume looping on it.
-          if (!edges1_alive.empty())
+          if (!edges1Alive.empty())
             {
               int j;
-              for(j = 0; it.current()->getStartNode() != tmp_e2->getEndNode() && j < inf_loop_detect; j++) // better way of doing this?
+              for(j = 0; it.current()->getStartNode() != tmpEd2->getEndNode() && j < infLoopDetect; j++) // better way of doing this?
                 it.nextLoop();
-              if (j >= inf_loop_detect) // could be a bit more precise and stop before ...
+              if (j >= infLoopDetect) // could be a bit more precise and stop before ...
                 throw Exception("QuadraticPolygon::ClosePolygonsSimple() - Internal error - 1D intersection was looping infinitely!");
               // sanity check - if we are not done with the cell completion, we should land
               // on a live edge.
-              if(edges1_alive.find(it.current()) == edges1_alive.end() && it.current() != startE)
+              if(edges1Alive.find(it.current()) == edges1Alive.end() && it.current() != startE)
                 throw Exception("QuadraticPolygon::ClosePolygonsSimple() - Internal error ! Should never happen.");
             }
         }
-      while(it.current() != startE && !edges1_alive.empty() && i < inf_loop_detect);
+      while(it.current() != startE && !edges1Alive.empty() && i < infLoopDetect);
       // Complete mapping
       nbOtherI.push_back(nbElemFrom2+nbOtherI.back());
     }
-  if (i >= inf_loop_detect)
+  if (i >= infLoopDetect)
     throw Exception("QuadraticPolygon::ClosePolygonsSimple() - Internal error - 1D intersection was looping infinitely!");
 }
 
@@ -1384,12 +1384,12 @@ std::list<QuadraticPolygon *>::iterator QuadraticPolygon::CheckInList(Node *n, s
   return iEnd;
 }
 
-std::list<QuadraticPolygon *>::const_iterator QuadraticPolygon::CheckInList2(Node *n, const std::list<QuadraticPolygon *> & zip_list,
+std::list<QuadraticPolygon *>::const_iterator QuadraticPolygon::CheckInList2(Node *n, const std::list<QuadraticPolygon *> & zipList,
                                                                              bool & direction, int & index)
 {
   direction = true;
   index = 0;
-  for(std::list<QuadraticPolygon *>::const_iterator iter = zip_list.begin(); iter!=zip_list.end(); iter++, index++)
+  for(std::list<QuadraticPolygon *>::const_iterator iter = zipList.begin(); iter!=zipList.end(); iter++, index++)
     {
       if ((*iter)->front()->getStartNode() == n)
         return iter;
@@ -1402,7 +1402,7 @@ std::list<QuadraticPolygon *>::const_iterator QuadraticPolygon::CheckInList2(Nod
             }
         }
     }
-  return zip_list.end();
+  return zipList.end();
 }
 
 
index b44dd3b5acc5ec43027d0cd1d4eeeb0a00c17eb3..da2cf12f17a00cf3604c10b05da8645aaaceaf30 100644 (file)
@@ -84,7 +84,7 @@ namespace INTERP_KERNEL
     INTERPKERNEL_EXPORT void appendCrudeData(const std::map<INTERP_KERNEL::Node *,int>& mapp, int offset, std::vector<double>& addCoordsQuadratic, std::vector<int>& conn, std::vector<int>& connI) const;
     INTERPKERNEL_EXPORT void 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>& nb1, std::vector<int>& nb2);
-    INTERPKERNEL_EXPORT static void BuildPartitionFromZipList(const QuadraticPolygon & pol1, const std::list<INTERP_KERNEL::QuadraticPolygon *> & zip_list,
+    INTERPKERNEL_EXPORT static void BuildPartitionFromZipList(const QuadraticPolygon & pol1, const std::list<INTERP_KERNEL::QuadraticPolygon *> & zipList,
                                                               std::set<INTERP_KERNEL::Edge *> & edgesThis, std::set<INTERP_KERNEL::Edge *> & edgesBoundaryOther,
                                                               const std::map<INTERP_KERNEL::Node *,int>& mapp,
                                                               const int idThis, const std::vector<std::vector<int> > & mapZipTo2,
@@ -133,7 +133,7 @@ namespace INTERP_KERNEL
     std::list<QuadraticPolygon *> zipConsecutiveInSegments() const;
     void dumpInXfigFile(std::ostream& stream, int resolution, const Bounds& box) const;
     static void ClosePolygons(std::list<QuadraticPolygon *>& pol2Zip, const QuadraticPolygon& pol1, const QuadraticPolygon& pol2, std::vector<QuadraticPolygon *>& results);
-    static void ClosePolygonsSimple(const QuadraticPolygon& pol1, const std::list<INTERP_KERNEL::QuadraticPolygon *> & zip_list,
+    static void ClosePolygonsSimple(const QuadraticPolygon& pol1, const std::list<INTERP_KERNEL::QuadraticPolygon *> & zipList,
                                          std::vector<QuadraticPolygon *>& results, const std::vector<std::vector<int> > & mapZipTo2,
                                          std::vector<int>& nbOther, std::vector<int>& nbOtherI);
     template<class EDGES>
@@ -146,7 +146,7 @@ namespace INTERP_KERNEL
                                                                      bool direction);
     static std::list<QuadraticPolygon *>::iterator CheckInList(Node *n, std::list<QuadraticPolygon *>::iterator iStart,
                                                                std::list<QuadraticPolygon *>::iterator iEnd);
-    static std::list<QuadraticPolygon *>::const_iterator CheckInList2(Node *n, const std::list<QuadraticPolygon *> & zip_list,
+    static std::list<QuadraticPolygon *>::const_iterator CheckInList2(Node *n, const std::list<QuadraticPolygon *> & zipList,
                                                                       bool & direction, int & index);
   };
 }
index c98ad71599be4741a040d5b48a526624470396a3..e163c9a4070e4e5ef165704e44e33baafc29ef23 100644 (file)
@@ -8972,10 +8972,10 @@ void MEDCouplingUMesh::Build2DCellsFrom1DCut(double eps, const MEDCouplingUMesh
       // Zip consecutive IN segments from the list of candidates, and discard the pieces which are ending nowhere (e.g. an IN polyline
       // with an end-point in the middle of the cell).
       std::vector<std::vector<int> > mapZipTo2;
-      std::list<INTERP_KERNEL::QuadraticPolygon *> zip_list = INTERP_KERNEL::QuadraticPolygon::ZipConsecutiveSegments2(candidates2, pol2s, mapZipTo2);
+      std::list<INTERP_KERNEL::QuadraticPolygon *> zipList = INTERP_KERNEL::QuadraticPolygon::ZipConsecutiveSegments2(candidates2, pol2s, mapZipTo2);
 
       // Now the core of the algo - main output is in cr, crI, cNb1, cNb2 and cNbI2.
-      INTERP_KERNEL::QuadraticPolygon::BuildPartitionFromZipList(pol1, zip_list, edges1, edgesBoundary2, mapp, i, mapZipTo2,
+      INTERP_KERNEL::QuadraticPolygon::BuildPartitionFromZipList(pol1, zipList, edges1, edgesBoundary2, mapp, i, mapZipTo2,
                                                                  offset3,addCoordsQuadratic,cr,crI, cNb1,cNb2, cNbI2);
       // Deals with remaining (non-consumed) edges from m1: these are the edges that were never touched
       // by m2 but that we still want to keep in the final result.
@@ -8994,7 +8994,7 @@ void MEDCouplingUMesh::Build2DCellsFrom1DCut(double eps, const MEDCouplingUMesh
       // Memory clean-up
       for(std::map<int,INTERP_KERNEL::Node *>::const_iterator it=mappRev.begin();it!=mappRev.end();it++)
         (*it).second->decrRef();
-      for (std::list<INTERP_KERNEL::QuadraticPolygon *>::const_iterator itt = zip_list.begin(); itt != zip_list.end(); itt++)
+      for (std::list<INTERP_KERNEL::QuadraticPolygon *>::const_iterator itt = zipList.begin(); itt != zipList.end(); itt++)
         delete(*itt);
     }
 }
index a9888ec30799d09f9b75ae87d59b5bb27f55398f..44dcae4994d069b2e9f959b5f3a6a96b3bb8898e 100644 (file)
@@ -14742,9 +14742,9 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         m2.setConnectivity(conn2, connI2)
 
         # End of construction of input meshes m1bis and m2 -> start of specific part of the test
-        m3, map1, map2, mapI2 = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m1, m2, 1e-10)
+        m3, map1, map2, mapI2 = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m1, m2, 1e-10)        
         m3.mergeNodes(1.0e-8)
-                
+
         self.assertEqual(3,m3.getNumberOfCells())
         self.assertEqual(20,m3.getNumberOfNodes())
         self.assertEqual(2,m3.getSpaceDimension())