From: Paul RASCLE Date: Wed, 15 Jun 2016 16:41:23 +0000 (+0200) Subject: debug split polylines, OK with type POLYLINE, still too many points with SPLINE X-Git-Tag: v1.6~107 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3509da2a6b8ca29cbbee410486f3fa8efaa3e448;p=modules%2Fhydro.git debug split polylines, OK with type POLYLINE, still too many points with SPLINE --- diff --git a/src/HYDROData/HYDROData_PolylineOperator.cxx b/src/HYDROData/HYDROData_PolylineOperator.cxx index b991bf7f..2e4ffff3 100644 --- a/src/HYDROData/HYDROData_PolylineOperator.cxx +++ b/src/HYDROData/HYDROData_PolylineOperator.cxx @@ -51,6 +51,11 @@ #include #include +#define _DEVDEBUG_ +#include "HYDRO_trace.hxx" +#include +#include + template void append( std::vector& theList, const std::vector& 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::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& 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& 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; iSetShape( theShapes[i] ); + aPolyline->ImportShape(theShapes[i], false); + //aPolyline->SetShape( theShapes[i] ); + if( isUseIndices ) { diff --git a/src/HYDROData/HYDROData_PolylineOperator.h b/src/HYDROData/HYDROData_PolylineOperator.h index eefac88b..a710e72a 100644 --- a/src/HYDROData/HYDROData_PolylineOperator.h +++ b/src/HYDROData/HYDROData_PolylineOperator.h @@ -82,6 +82,11 @@ protected: double theTolerance, std::vector& theWires); +// static bool CreatePolylinesSplit( const Handle( HYDROData_Document )& theDoc, +// const Handle( HYDROData_PolylineXY )& thePolyline, +// const std::vector& theShapes, +// bool isUseIndices); + static bool CreatePolylines( const Handle( HYDROData_Document )& theDoc, const QString& theNamePrefix, const std::vector& theShape, diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index dab82b84..0acdacdf 100644 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -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 #include @@ -42,6 +44,7 @@ #include #include +#include #include @@ -79,6 +82,11 @@ #include #include +#define _DEVDEBUG_ +#include "HYDRO_trace.hxx" +#include +#include + 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& theSectNames, + NCollection_Sequence& theSectTypes, + NCollection_Sequence& theSectClosures, + NCollection_Sequence& 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 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 #include +#define _DEVDEBUG_ +#include "HYDRO_trace.hxx" +#include + //! The type is intended to traverse the container //! either from the begin to the end or vice versa. template @@ -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::const_iterator aEItLast = myEdges.end(); std::list::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 >& theParameters) const { + std::string brepName = "theWireToIntersect"; + brepName += ".brep"; + BRepTools::Write( theWire, brepName.c_str() ); + int aIntCount = 0; theParameters.resize(myEdges.size()); std::list::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; } diff --git a/src/HYDROData/HYDROData_TopoCurve.h b/src/HYDROData/HYDROData_TopoCurve.h index 1f1025d9..a1db81e7 100644 --- a/src/HYDROData/HYDROData_TopoCurve.h +++ b/src/HYDROData/HYDROData_TopoCurve.h @@ -26,9 +26,15 @@ #include #include #include +//#include +//#include 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