From 2094b7bae56036bb85d97092c8cb3ecaedb853ca Mon Sep 17 00:00:00 2001 From: asl Date: Tue, 23 Jun 2015 17:38:17 +0300 Subject: [PATCH] draft split/merge --- src/HYDROData/HYDROData_PolylineOperator.cxx | 104 +++++++++++++++++-- src/HYDROData/HYDROData_PolylineOperator.h | 15 ++- 2 files changed, 111 insertions(+), 8 deletions(-) diff --git a/src/HYDROData/HYDROData_PolylineOperator.cxx b/src/HYDROData/HYDROData_PolylineOperator.cxx index 2256a906..61c835f6 100644 --- a/src/HYDROData/HYDROData_PolylineOperator.cxx +++ b/src/HYDROData/HYDROData_PolylineOperator.cxx @@ -17,29 +17,121 @@ // #include +#include +#include + +template void append( std::vector& theList, const std::vector& theList2 ) +{ + int aSize = theList.size(); + int aNewSize = aSize + theList2.size(); + + if( aSize==aNewSize ) + return; + + theList.resize( aNewSize ); + for( int i=aSize, j=0; i aPointsList( 1 ); + aPointsList[0] = thePoint; + std::vector aCurves = GetCurves( thePolyline ); + bool isOK = true; + for( int i=0, n=aCurves.size(); i aCurvesList = Split( aCurves[i], aPointsList ); + bool isLocalOK = CreatePolylines( aCurvesList ); + isOK = isOK && isLocalOK; + } + return isOK; } bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& thePolyline, - const Handle( HYDROData_PolylineXY )& theTool ) const + const Handle( HYDROData_PolylineXY )& theTool ) const { - //TODO - return true; + std::vector aCurves = GetCurves( thePolyline ); + std::vector aToolCurves = GetCurves( theTool ); + bool isOK = true; + for( int i=0, n=aCurves.size(); i aPointsList = Intersection( aCurves[i], aToolCurves[j] ); + std::vector aCurvesList = Split( aCurves[i], aPointsList ); + bool isLocalOK = CreatePolylines( aCurvesList ); + isOK = isOK && isLocalOK; + } + return isOK; } bool HYDROData_PolylineOperator::Split( const HYDROData_SequenceOfObjects& thePolylines ) +{ + int f = thePolylines.Lower(), l = thePolylines.Upper(); + bool isOK = true; + std::vector anAllCurves; + for( int i=f; i<=l; i++ ) + { + Handle( HYDROData_PolylineXY ) aPolyline = Handle( HYDROData_PolylineXY )::DownCast( thePolylines.Value( i ) ); + std::vector aCurves = GetCurves( aPolyline ); + append( anAllCurves, aCurves ); + } + + for( int i=0, n=anAllCurves.size(); i aCompletePointsList; + for( int j=0; j aPointsList = Intersection( anAllCurves[i], anAllCurves[j] ); + append( aCompletePointsList, aPointsList ); + } + std::vector aCurvesList = Split( anAllCurves[i], aCompletePointsList ); + bool isLocalOK = CreatePolylines( aCurvesList ); + isOK = isOK && isLocalOK; + } + return isOK; +} + +bool HYDROData_PolylineOperator::Merge( const HYDROData_SequenceOfObjects& thePolylines ) { //TODO return true; } -bool HYDROData_PolylineOperator::Merge( const HYDROData_SequenceOfObjects& thePolylines ) +std::vector HYDROData_PolylineOperator::GetCurves( const Handle( HYDROData_PolylineXY )& thePolyline ) { + std::vector aResult; //TODO + return aResult; +} + +std::vector HYDROData_PolylineOperator::Intersection( const Handle( Geom2d_Curve )& theCurve, + const Handle( Geom2d_Curve )& theTool ) +{ + std::vector aResult; + //TODO + return aResult; +} + +std::vector HYDROData_PolylineOperator::Split( const Handle( Geom2d_Curve )& theCurve, + const std::vector& thePoints ) +{ + std::vector aResult; + //TODO + return aResult; +} + +bool HYDROData_PolylineOperator::CreatePolylines( const std::vector& theCurves ) +{ + int n = theCurves.size(); + for( int i=0; i - -class gp_Pnt2d; +#include +#include +#include class HYDROData_PolylineOperator { @@ -32,6 +33,16 @@ public: const Handle( HYDROData_PolylineXY )& theTool ) const; HYDRODATA_EXPORT bool Split( const HYDROData_SequenceOfObjects& thePolylines ); HYDRODATA_EXPORT bool Merge( const HYDROData_SequenceOfObjects& thePolylines ); + + static HYDRODATA_EXPORT std::vector GetCurves( const Handle( HYDROData_PolylineXY )& thePolyline ); + + static HYDRODATA_EXPORT std::vector Intersection( const Handle( Geom2d_Curve )& theCurve, + const Handle( Geom2d_Curve )& theTool ); + + static HYDRODATA_EXPORT std::vector Split( const Handle( Geom2d_Curve )& theCurve, + const std::vector& thePoints ); + + static HYDRODATA_EXPORT bool CreatePolylines( const std::vector& theCurves ); }; #endif -- 2.39.2