]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
debug split polylines, OK with type POLYLINE, still too many points with SPLINE
authorPaul RASCLE <paul.rascle@edf.fr>
Wed, 15 Jun 2016 16:41:23 +0000 (18:41 +0200)
committerPaul RASCLE <paul.rascle@edf.fr>
Wed, 15 Jun 2016 16:41:23 +0000 (18:41 +0200)
src/HYDROData/HYDROData_PolylineOperator.cxx
src/HYDROData/HYDROData_PolylineOperator.h
src/HYDROData/HYDROData_PolylineXY.cxx
src/HYDROData/HYDROData_PolylineXY.h
src/HYDROData/HYDROData_TopoCurve.cxx
src/HYDROData/HYDROData_TopoCurve.h

index b991bf7f6992a0728f13c55e2e93e11940eb3cea..2e4ffff3315ad5fc26c2634915bcfd4868664d98 100644 (file)
 #include <QColor>
 #include <Geom_BSplineCurve.hxx>
 
+#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+#include <BRepTools.hxx>
+#include <sstream>
+
 template<class T> void append( std::vector<T>& theList, const std::vector<T>& theList2 )
 {
   int aSize = theList.size();
@@ -211,6 +216,7 @@ bool HYDROData_PolylineOperator::split( const Handle( HYDROData_Document )& theD
   for (int aPSI = 0; aPSI < aPSCount; ++aPSI)
   {
     HYDROData_TopoCurve aCurve;
+    DEBTRACE("Initialize curve " << aPSI);
     if (!aCurve.Initialize(aCurves[aPSI]))
     {
       continue;
@@ -228,13 +234,19 @@ bool HYDROData_PolylineOperator::split( const Handle( HYDROData_Document )& theD
       aSplitCurves.begin();
     std::deque<HYDROData_TopoCurve>::const_iterator aLastCIt =
       aSplitCurves.end();
-    for (; aCIt != aLastCIt; ++aCIt)
+    for (int iw=0; aCIt != aLastCIt; ++aCIt, iw++)
     {
-      aResult.push_back(aCIt->Wire());
+        std::stringstream brepName;
+        brepName << "theSplitWire_";
+        brepName << iw;
+        brepName << ".brep";
+        BRepTools::Write(aCIt->Wire() , brepName.str().c_str() );
+     aResult.push_back(aCIt->Wire());
     }
   }
 
   CreatePolylines( theDoc, thePolyline->GetName(), aResult, true, thePolyline->GetWireColor() );
+  //CreatePolylinesSplit( theDoc, thePolyline, aResult, true );
   return true;
 }
 
@@ -283,6 +295,56 @@ void HYDROData_PolylineOperator::Split(
   }
 }
 
+//bool HYDROData_PolylineOperator::CreatePolylinesSplit(const Handle( HYDROData_Document )& theDoc,
+//                                                      const Handle( HYDROData_PolylineXY )& thePolyline,
+//                                                      const std::vector<TopoDS_Shape>& theShapes, bool isUseIndices)
+//{
+//
+//  if (theDoc.IsNull())
+//    return false;
+//
+//  int nbSections = thePolyline->NbSections();
+//  const QString& theNamePrefix = thePolyline->GetName();
+//  const QColor& theColor = thePolyline->GetWireColor();
+//
+//  int n = theShapes.size();
+//  DEBTRACE("theShapes.size() "<< n);
+//  int anIndex = 1;
+//  for (int i = 0; i < n; i++)
+//    {
+//      Handle( HYDROData_PolylineXY ) aPolyline =
+//      Handle( HYDROData_PolylineXY )::DownCast(theDoc->CreateObject(KIND_POLYLINEXY));
+//      if (aPolyline.IsNull())
+//        return false;
+//
+//      for (int isec = 0; isec < nbSections; isec++)
+//        {
+//          gp_XY p = gp_XY(0, 0);
+//          //double d = thePolyline->GetMinDistance(isec, p);
+//        }
+//
+//      if (isUseIndices)
+//        {
+//          QString aNewName = theNamePrefix + "_" + QString::number(anIndex);
+//          while (!theDoc->FindObjectByName(aNewName).IsNull())  // the object with such a name is not found
+//            {
+//              anIndex++;
+//              aNewName = theNamePrefix + "_" + QString::number(anIndex);
+//            }
+//          aPolyline->SetName(aNewName);
+//        }
+//      else
+//        {
+//          aPolyline->SetName(theNamePrefix);
+//        }
+//
+//      if (theColor.isValid())
+//        aPolyline->SetWireColor(theColor);
+//    }
+//  return true;
+//
+//}
+
 bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Document )& theDoc,
                                                   const QString& theNamePrefix,
                                                   const std::vector<TopoDS_Shape>& theShapes,
@@ -293,6 +355,7 @@ bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Docume
     return false;
 
   int n = theShapes.size();
+  DEBTRACE("theShapes.size() "<< n);
   int anIndex = 1;
   for( int i=0; i<n; i++ )
   {
@@ -301,7 +364,9 @@ bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Docume
     if( aPolyline.IsNull() )
       return false;
 
-    aPolyline->SetShape( theShapes[i] );
+    aPolyline->ImportShape(theShapes[i], false);
+    //aPolyline->SetShape( theShapes[i] );
+
 
     if( isUseIndices )
     {
index eefac88bad05e67ac5c3237f353eeda87b97c04d..a710e72ad9628c866ee2254cbfeaf4d1754cd1cf 100644 (file)
@@ -82,6 +82,11 @@ protected:
     double theTolerance,
     std::vector<TopoDS_Shape>& theWires);
 
+//  static bool CreatePolylinesSplit( const Handle( HYDROData_Document )& theDoc,
+//                                    const Handle( HYDROData_PolylineXY )& thePolyline,
+//                                    const std::vector<TopoDS_Shape>& theShapes,
+//                                    bool isUseIndices);
+
   static bool CreatePolylines( const Handle( HYDROData_Document )& theDoc,
                                const QString& theNamePrefix,
                                const std::vector<TopoDS_Shape>& theShape,
index dab82b849536bc774dc1511410937e670e311993..0acdacdf811e897b7714fcc372055939a6687142 100644 (file)
@@ -22,6 +22,8 @@
 #include "HYDROData_Document.h"
 #include "HYDROData_ShapesTool.h"
 #include "HYDROData_Tool.h"
+#include "HYDROData_PolylineOperator.h"
+#include "HYDROData_TopoCurve.h"
 
 #include <BRep_Builder.hxx>
 #include <BRepBuilderAPI_MakeEdge.hxx>
@@ -42,6 +44,7 @@
 
 #include <GCPnts_AbscissaPoint.hxx>
 #include <GCPnts_QuasiUniformDeflection.hxx>
+#include <GCPnts_UniformDeflection.hxx>
 
 #include <ImageComposer_MetaTypes.h>
 
 #include <QPainterPath>
 #include <QVariant>
 
+#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+#include <BRepTools.hxx>
+#include <sstream>
+
 static const Standard_GUID GUID_IS_UNEDITABLE("e5799736-9030-4051-91a4-2e58321fa153");
 
 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
@@ -293,6 +301,7 @@ bool convertEdgeToSection( const TopoDS_Edge&
 
     BRepAdaptor_Curve anAdaptorCurve( theEdge );
     GCPnts_QuasiUniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
+    //GCPnts_UniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
 
     int aNbPoints = aDiscrete.NbPoints();
 
@@ -325,10 +334,157 @@ bool convertEdgeToSection( const TopoDS_Edge&
   return true;
 }
 
+
+bool convertEdgesToSections( const TopoDS_Edge&                                       theEdge,
+                             NCollection_Sequence<TCollection_AsciiString>&           theSectNames,
+                             NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
+                             NCollection_Sequence<bool>&                              theSectClosures,
+                             NCollection_Sequence<HYDROData_PolylineXY::PointsList>&  theSectPoints,
+                             bool                                                     IsCanBeClosed,
+                             bool                                                     IsInterpolationAllowed,
+                             double                                                   theDeflection )
+{
+  DEBTRACE("convertEdgesToSections")
+  Standard_Real aFirst = 0.0, aLast = 0.0;
+  Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
+  if ( anEdgeGeomCurve.IsNull() )
+    return false;
+
+  bool isPrevious = (theSectTypes.Size() > 0);
+  DEBTRACE("nb sections: " << theSectTypes.Size());
+  HYDROData_PolylineXY::SectionType prevSectType = HYDROData_PolylineXY::SECTION_SPLINE;;
+  HYDROData_PolylineXY::PointsList prevPointList;
+  bool isPrevClosed = true;
+  if (isPrevious)
+    {
+       prevSectType = theSectTypes.Last();
+       prevPointList = theSectPoints.Last();
+       isPrevClosed = theSectClosures.Last();
+    }
+
+  bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
+  HYDROData_PolylineXY::SectionType aSectionType ;
+  if( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
+    {
+      aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
+    }
+  else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) || IsInterpolationAllowed )
+    {
+      aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
+    }
+  else
+    {
+      // Other curve types are not supported
+      return false;
+    }
+
+  bool isNewSection = !isPrevious || isPrevClosed || anIsEdgeClosed || prevSectType != aSectionType;
+  DEBTRACE(isNewSection <<": " << !isPrevious << " " << isPrevClosed << " " << anIsEdgeClosed << " " << (prevSectType != aSectionType));
+
+  HYDROData_PolylineXY::PointsList aPointsList;
+  if (!isNewSection)
+    {
+      aPointsList = prevPointList;
+    }
+
+  if( aSectionType == HYDROData_PolylineXY::SECTION_POLYLINE )
+    {
+      DEBTRACE("SECTION_POLYLINE");
+      Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
+
+      gp_Pnt aFirstPoint, aLastPoint;
+      aGeomLine->D0( aFirst, aFirstPoint );
+      aGeomLine->D0( aLast, aLastPoint );
+      HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
+      HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
+     if (!isNewSection)
+        {
+          if (aSectFirstPoint == prevPointList.Last())
+            {
+              DEBTRACE("points shared: a");//aPointsList.Append( aSectFirstPoint );
+              aPointsList.Append( aSectLastPoint );
+            }
+          else if (aSectLastPoint == prevPointList.Last())
+            {
+              DEBTRACE("points shared: b");//aPointsList.Append( aSectLastPoint );
+              aPointsList.Append( aSectFirstPoint );
+            }
+          else if (aSectFirstPoint == prevPointList.First())
+            {
+              DEBTRACE("points shared: c");//aPointsList.Prepend( aSectFirstPoint );
+              aPointsList.Prepend( aSectLastPoint );
+            }
+          else if (aSectLastPoint == prevPointList.First())
+            {
+              DEBTRACE("points shared: d");//aPointsList.Prepend( aSectLastPoint );
+              aPointsList.Prepend( aSectFirstPoint );
+            }
+          else
+            {
+              DEBTRACE("no point shared")
+              isNewSection = true; // no point shared, new section
+              aPointsList.Clear();
+              aPointsList.Append( aSectFirstPoint );
+              aPointsList.Append( aSectLastPoint );
+            }
+        }
+     else
+       {
+         DEBTRACE("new section");
+         aPointsList.Append( aSectFirstPoint );
+         aPointsList.Append( aSectLastPoint );
+       }
+    }
+  else // aSectionType == HYDROData_PolylineXY::SECTION_SPLINE
+    {
+      DEBTRACE("SECTION_SPLINE");
+      isNewSection = true;
+      aPointsList.Clear();
+
+      BRepAdaptor_Curve anAdaptorCurve( theEdge );
+      GCPnts_QuasiUniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
+
+      int aNbPoints = aDiscrete.NbPoints();
+
+      // Decrease the number of imported poles because of last one
+      // pole is the closing point which are the start point
+      if ( anIsEdgeClosed ) aNbPoints--;
+
+      for ( int i = 1; i <= aNbPoints; ++i )
+      {
+        const gp_Pnt& aPoint = aDiscrete.Value( i );
+
+        HYDROData_PolylineXY::Point aSectPoint( aPoint.X(), aPoint.Y() );
+        aPointsList.Append( aSectPoint );
+      }
+    }
+
+  if ( aPointsList.IsEmpty() )
+    return false;
+
+  TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
+  if (isNewSection)
+    {
+      DEBTRACE("isNewSection");
+      theSectNames.Append( aSectName );
+      theSectTypes.Append( aSectionType );
+      theSectClosures.Append( anIsEdgeClosed );
+      theSectPoints.Append( aPointsList );
+    }
+  else
+    {
+      DEBTRACE("sameSection");
+      theSectPoints.SetValue(theSectPoints.Length(), aPointsList);
+    }
+
+  return true;
+}
+
 bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape,
                                         bool IsInterpolationAllowed,
                                         double theDeviation )
 {
+  DEBTRACE("ImportShape");
   if ( theShape.IsNull() )
     return false;
 
@@ -343,12 +499,14 @@ bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape,
 
   if ( theShape.ShapeType() == TopAbs_EDGE )
   {
+      DEBTRACE("TopAbs_EDGE");
     TopoDS_Edge anEdge = TopoDS::Edge( theShape );
     anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes,
       aSectClosures, aSectPoints, true, IsInterpolationAllowed, theDeviation );
   }
   else if ( theShape.ShapeType() == TopAbs_WIRE )
   {
+      DEBTRACE("TopAbs_WIRE");
     TopTools_SequenceOfShape anEdges;
     HYDROData_ShapesTool::ExploreShapeToShapes( theShape, TopAbs_EDGE, anEdges );
 
@@ -356,7 +514,7 @@ bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape,
     for ( int i = 1, n = anEdges.Length(); i <= n && anIsCanBeImported; ++i )
     {
       TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
-      anIsCanBeImported = convertEdgeToSection( aWireEdge, aSectNames, aSectTypes,
+      anIsCanBeImported = convertEdgesToSections( aWireEdge, aSectNames, aSectTypes,
         aSectClosures, aSectPoints, false, IsInterpolationAllowed, theDeviation );
     }
   }
@@ -683,6 +841,38 @@ double HYDROData_PolylineXY::GetDistance( const int theSectionIndex,
   return aResDistance;
 }
 
+//double HYDROData_PolylineXY::GetMinDistance( const int theSectionIndex,
+//                                             const Point& thePoint ) const
+//{
+//  double aResDistance = -1;
+//  if ( theSectionIndex < 0 || theSectionIndex >= NbSections() )
+//    return aResDistance;
+//
+//  std::vector<TopoDS_Wire> aCurves;
+//  HYDROData_PolylineOperator::GetWires(this, aCurves);
+//  if (aCurves.size() != NbSections())
+//    {
+//      DEBTRACE("nbCurves != nbSections " << aCurves.size() << " " << NbSections());
+//      return aResDistance;
+//    }
+//  TopoDS_Wire aWire = aCurves[theSectionIndex];
+//  TopTools_SequenceOfShape anEdges;
+//  HYDROData_ShapesTool::ExploreShapeToShapes( aWire, TopAbs_EDGE, anEdges );
+//  for ( int i = 1, n = anEdges.Length(); i <= n; ++i )
+//    {
+//      DEBTRACE("i: "<< i);
+//      TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
+//      gp_XYZ aPointz = gp_XYZ(thePoint.X(), thePoint.Y(), 0);
+//      Adaptor3d_Curve theCurve = BRepAdaptor_Curve(aWireEdge);
+//      double theParameter = -1;
+//      double d = ProjectPointToCurve(aPointz, theCurve, theParameter);
+//      if (d<aResDistance) aResDistance = d;
+//      DEBTRACE("d[" << i <<"]=" << d);
+//    }
+//  DEBTRACE("distance section "<<theSectionIndex<<" point="<<aResDistance<<" ("<<thePoint.X()<<", "<< thePoint.Y()<<")");
+//  return aResDistance;
+//}
+
 int HYDROData_PolylineXY::NbSections() const
 {
   Handle(TDataStd_ExtStringList) aNamesList;
index e052a1c3aac0af7c39db43bff214673031e70ab0..aa6ab4a27e251c9b3cc421b0a44b9b8a84747748 100644 (file)
@@ -156,6 +156,12 @@ public:
   HYDRODATA_EXPORT double GetDistance( const int theSectionIndex,
                                        const int thePointIndex ) const;
 
+  /**
+  * Returns the distance between a section and a point
+  */
+// HYDRODATA_EXPORT double GetMinDistance( const int theSectionIndex,
+//                                         const Point& thePoint ) const;
+
 
   /**
    * Returns number of sections.
index c58da31f3d95520e991c45f20a39c3ccf4aae12e..fce5201ade18cb254d39d20b916ff6314e49da0f 100644 (file)
 #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>
@@ -369,6 +373,7 @@ bool HYDROData_TopoCurve::Initialize(const TopoDS_Wire& theWire)
   TopExp::MapShapesAndAncestors(theWire,
     TopAbs_VERTEX, TopAbs_EDGE, aVertexToEdges);
   const int aVCount = aVertexToEdges.Extent();
+  DEBTRACE("initialize VCount= "<< aVCount);
   if (aVCount == 0)
   {
     return false;
@@ -454,13 +459,13 @@ bool HYDROData_TopoCurve::Initialize(const TopoDS_Wire& theWire)
 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;
 }
@@ -497,6 +502,7 @@ bool HYDROData_TopoCurve::Cut(
     aParamI ^= 1;
   }
   const bool isClosed = IsClosed();
+  DEBTRACE("aParamI: " << aParamI << " isClosed: "<< isClosed);
   if (aParamI < 0)
   {
     aEdge.Orientation(TopAbs_FORWARD);
@@ -654,6 +660,10 @@ int HYDROData_TopoCurve::Intersect(
   const TopoDS_Wire& theWire,
   std::deque<std::list<double> >& theParameters) const
 {
+  std::string brepName = "theWireToIntersect";
+  brepName += ".brep";
+  BRepTools::Write( theWire, brepName.c_str() );
+
   int aIntCount = 0;
   theParameters.resize(myEdges.size());
   std::list<TopoDS_Edge>::const_iterator aEIt = myEdges.begin();
@@ -669,6 +679,7 @@ int HYDROData_TopoCurve::Intersect(
       aIntCount += IntersectEdge(aEdge,TopoDS::Edge(aEIt2.Current()), aParams);
     }
   }
+  DEBTRACE("aIntCount " << aIntCount);
   return aIntCount;
 }
 
index 1f1025d962d18ed73b574800265e116c4614285a..a1db81e7e7178443fef11af8cee9d014cd6704de 100644 (file)
 #include <TopExp.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS_Vertex.hxx>
+//#include <gp_XYZ.hxx>
+//#include <Adaptor3d_Curve.hxx>
 
 class TopoDS_Wire;
 
+//double ProjectPointToCurve(const gp_XYZ& thePoint,
+//                           const Adaptor3d_Curve& theCurve,
+//                           double& theParameter);
+
 //! The type represents a 1 monifold connected topo curve
 //! with forward orientation.
 class HYDROData_TopoCurve