Salome HOME
comments and debug traces on split polylines
[modules/hydro.git] / src / HYDROData / HYDROData_TopoCurve.cxx
index 1d69ddb2e58e1322d0781564c7e3969e8b9faf4b..54888d1c532d6d60b2f30e7a69e0a17933b14f72 100644 (file)
@@ -1,8 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// Copyright (C) 2014-2015  EDF-R&D
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
 #include <TopTools_ListOfShape.hxx>
 
+#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+#include <BRepTools.hxx>
+
 //! The type is intended to traverse the container
 //! either from the begin to the end or vice versa.
 template<typename ContainerType, typename IteratorType>
@@ -134,7 +134,7 @@ static TopoDS_Edge ReplaceVertex(
 }
 
 // Projects the point to the curve.
-static double ProjectPointToCurve(
+double ProjectPointToCurve(
   const gp_XYZ& thePoint,
   const Adaptor3d_Curve& theCurve,
   double& theParameter)
@@ -283,12 +283,13 @@ static int IntersectCurve(
     if (ProjectPointToCurve(aEndPs[aPI], theCurve1, aParameter) <=
       Precision::SquareConfusion())
     {
+      DEBTRACE("aParameter " << aParameter);
       aIntCount += AddParameter(theCurve1, aParameter, theParameters);
     }
   }
 
   // Process the internal extremums.
-  Extrema_ExtCC aAlgo(theCurve1, theCurve2);
+  Extrema_ExtCC aAlgo(theCurve1, theCurve2); //, 1.e-6, 1.e-6);
   if (aAlgo.IsDone())
   {
     const int aECount = aAlgo.NbExt();
@@ -296,9 +297,11 @@ static int IntersectCurve(
     {
       Extrema_POnCurv aP1, aP2;
       aAlgo.Points(aEN, aP1, aP2);
+      DEBTRACE("SquareDistance " << aP1.Value().SquareDistance(aP2.Value()));
       if (aP1.Value().SquareDistance(aP2.Value()) <=
         Precision::SquareConfusion())
       {
+        DEBTRACE("aP1.Parameter() " << aP1.Parameter());
         aIntCount += AddParameter(theCurve1, aP1.Parameter(), theParameters);
       }
     }
@@ -367,12 +370,13 @@ static bool Interpolate(
 
 bool HYDROData_TopoCurve::Initialize(const TopoDS_Wire& theWire)
 {
-  // Check for nonemptiness.
+  // Check for non-emptiness.
   myEdges.clear();
   TopTools_IndexedDataMapOfShapeListOfShape aVertexToEdges;
   TopExp::MapShapesAndAncestors(theWire,
     TopAbs_VERTEX, TopAbs_EDGE, aVertexToEdges);
-  const int aVCount = aVertexToEdges.Extent();
+  const int aVCount = aVertexToEdges.Extent();   // number of edges (an edge can be a spline with intermediate vertices)
+  DEBTRACE("initialize VCount= "<< aVCount);
   if (aVCount == 0)
   {
     return false;
@@ -400,8 +404,11 @@ bool HYDROData_TopoCurve::Initialize(const TopoDS_Wire& theWire)
       return false;
     }
   }
+  std::string brepName = "theWireToSplit";
+  brepName += ".brep";
+  BRepTools::Write( theWire, brepName.c_str() );
 
-  // Find the start.
+  // Find the start, i.e. the end which is the first vertex (or just the first vertex when closed) ==> aVN
   int aVN = 1;
   if (!isClosed)
   {
@@ -424,19 +431,19 @@ bool HYDROData_TopoCurve::Initialize(const TopoDS_Wire& theWire)
     }
   }
 
-  // Calculate the edge order.
-  TopTools_ListOfShape* aEdges = &aVertexToEdges.ChangeFromIndex(aVN);
+  // Calculate the edge order ==> list in myEdges
+  TopTools_ListOfShape* aEdges = &aVertexToEdges.ChangeFromIndex(aVN); // 1 or 2 edges from first vertex
   while (!aEdges->IsEmpty())
   {
     const TopoDS_Edge aEdge = TopoDS::Edge(aEdges->First());
     aEdges->RemoveFirst();
-    myEdges.push_back(aEdge);
+    myEdges.push_back(aEdge);                                          // add an edge in the list
     int aVN2 = aVertexToEdges.FindIndex(TopExp::FirstVertex(aEdge));
     if (aVN2 == aVN)
     {
       aVN2 = aVertexToEdges.FindIndex(TopExp::LastVertex(aEdge));
     }
-    aVN = aVN2;
+    aVN = aVN2;                                                        // next vertex
 
     aEdges = &aVertexToEdges.ChangeFromIndex(aVN2);
     const TopoDS_Edge aEdge2 = TopoDS::Edge(aEdges->First());
@@ -447,24 +454,24 @@ bool HYDROData_TopoCurve::Initialize(const TopoDS_Wire& theWire)
     else
     {
       aEdges->Clear();
-      aEdges->Append(aEdge2);
+      aEdges->Append(aEdge2);                                          // next edge
     }
   }
 
   // Check for connectedness and free vertex.
-  return aVCount - myEdges.size() == (isClosed ? 0 : 1);
+  return (aVCount - myEdges.size()) == (isClosed ? 0 : 1);
 }
 
 TopoDS_Wire HYDROData_TopoCurve::Wire() const
 {
   TopoDS_Wire aWire;
-  BRep_Builder aBulder;
-  aBulder.MakeWire(aWire);
+  BRep_Builder aBuilder;
+  aBuilder.MakeWire(aWire);
   std::list<TopoDS_Edge>::const_iterator aEItLast = myEdges.end();
   std::list<TopoDS_Edge>::const_iterator aEIt = myEdges.begin();
   for (; aEIt != aEItLast; ++aEIt)
   {
-    aBulder.Add(aWire, *aEIt);
+    aBuilder.Add(aWire, *aEIt);
   }
   return aWire;
 }
@@ -501,6 +508,7 @@ bool HYDROData_TopoCurve::Cut(
     aParamI ^= 1;
   }
   const bool isClosed = IsClosed();
+  DEBTRACE("aParamI: " << aParamI << " isClosed: "<< isClosed);
   if (aParamI < 0)
   {
     aEdge.Orientation(TopAbs_FORWARD);
@@ -658,21 +666,29 @@ int HYDROData_TopoCurve::Intersect(
   const TopoDS_Wire& theWire,
   std::deque<std::list<double> >& theParameters) const
 {
+  std::string brepName = "theWireTool";
+  brepName += ".brep";
+  BRepTools::Write( theWire, brepName.c_str() );
+
   int aIntCount = 0;
   theParameters.resize(myEdges.size());
+  DEBTRACE("myEdges.size() " << myEdges.size());
   std::list<TopoDS_Edge>::const_iterator aEIt = myEdges.begin();
   std::list<TopoDS_Edge>::const_iterator aLastEIt = myEdges.end();
   std::deque<std::list<double> >::iterator aPIt = theParameters.begin();
   for (; aEIt != aLastEIt; ++aPIt, ++aEIt)
   {
+    DEBTRACE("---");
     const TopoDS_Edge& aEdge = *aEIt;
     std::list<double>& aParams = *aPIt;
     TopExp_Explorer aEIt2(theWire, TopAbs_EDGE);
     for (; aEIt2.More(); aEIt2.Next())
     {
       aIntCount += IntersectEdge(aEdge,TopoDS::Edge(aEIt2.Current()), aParams);
+      DEBTRACE("aParams.size() " << aParams.size());
     }
   }
+  DEBTRACE("aIntCount " << aIntCount);
   return aIntCount;
 }