From 3874a2c420b60f4cdcfe90d3286472165ed93405 Mon Sep 17 00:00:00 2001 From: isn Date: Thu, 8 Dec 2016 17:49:52 +0300 Subject: [PATCH] debug of interpolations --- src/HYDROData/HYDROData_Bathymetry.cxx | 2 +- src/HYDROData/HYDROData_DTM.cxx | 82 ++++++++++++++++++++++---- src/HYDROData/HYDROData_DTM.h | 1 - src/HYDROData/HYDROData_Profile.cxx | 4 +- src/HYDROData/HYDROData_Profile.h | 2 +- src/HYDRO_tests/test_HYDROData_DTM.cxx | 6 +- 6 files changed, 76 insertions(+), 21 deletions(-) diff --git a/src/HYDROData/HYDROData_Bathymetry.cxx b/src/HYDROData/HYDROData_Bathymetry.cxx index f0a871a3..742acbd5 100644 --- a/src/HYDROData/HYDROData_Bathymetry.cxx +++ b/src/HYDROData/HYDROData_Bathymetry.cxx @@ -86,7 +86,7 @@ double HYDROData_Bathymetry::AltitudePoint::SquareDistance( const HYDROData_Bath double d = 0; d += sqr( X - p.X ); d += sqr( Y - p.Y ); - d += sqr( Z - p.Z ); + //d += sqr( Z - p.Z ); return d; } diff --git a/src/HYDROData/HYDROData_DTM.cxx b/src/HYDROData/HYDROData_DTM.cxx index df831b61..a41dc277 100644 --- a/src/HYDROData/HYDROData_DTM.cxx +++ b/src/HYDROData/HYDROData_DTM.cxx @@ -529,7 +529,6 @@ void HYDROData_DTM::CreateProfiles(const std::vector& void HYDROData_DTM::GetProperties( const Handle_HYDROData_Profile& theProfile, gp_Pnt& theLowestPoint, gp_Vec2d& theDir, - bool isNormalDir, double& theZMin, double& theZMax ) { theLowestPoint = theProfile->GetBottomPoint(); @@ -539,10 +538,7 @@ void HYDROData_DTM::GetProperties( const Handle_HYDROData_Profile& theProfile, theProfile->GetRightPoint( aRight, true, true ); double x = aRight.X()-aLeft.X(); double y = aRight.Y()-aLeft.Y(); - if( isNormalDir ) - theDir = gp_Vec2d( -y, x ); - else - theDir = gp_Vec2d( x, y ); + theDir = gp_Vec2d( x, y ); HYDROData_Profile::ProfilePoints points = theProfile->GetProfilePoints(); int lo = points.Lower(); @@ -618,11 +614,39 @@ Handle(Geom2d_Curve) CurveTo2D( const Handle(Geom_Curve)& theCurve, return Handle(Geom2d_Curve)(); } +#include +#include +bool IsCooriented( const Handle_HYDROData_Profile& theProfile1, + const Handle_HYDROData_Profile& theProfile2 ) +{ + if( theProfile1==theProfile2 ) + return true; + + gp_XY lp1, rp1, lp2, rp2; + theProfile1->GetLeftPoint(lp1); + theProfile1->GetRightPoint(rp1); + theProfile2->GetLeftPoint(lp2); + theProfile2->GetRightPoint(rp2); + + GCE2d_MakeSegment s1(lp1, lp2); + GCE2d_MakeSegment s2(rp1, rp2); + + Geom2dAPI_InterCurveCurve inter; + inter.Init(s1, s2); + if (inter.NbPoints() == 0) + return true; + else + return false; +} + Handle_Geom2d_BSplineCurve HYDROData_DTM::CreateHydraulicAxis( const std::vector& theProfiles, std::vector& theDistances ) { size_t n = theProfiles.size(); + if( n==1 ) + Handle_Geom2d_BSplineCurve(); + Handle_Geom2d_BSplineCurve aResult; Handle(TColgp_HArray1OfPnt2d) points = new TColgp_HArray1OfPnt2d( 1, (int)n ); @@ -632,16 +656,48 @@ Handle_Geom2d_BSplineCurve HYDROData_DTM::CreateHydraulicAxis( for( size_t i = 1; i <= n; i++ ) { Handle_HYDROData_Profile aProfile = theProfiles[i-1]; + Handle_HYDROData_Profile aPrevProfile = i==1 ? theProfiles[i-1] : theProfiles[i-2]; + Handle_HYDROData_Profile aNextProfile = i==n ? theProfiles[i-1] : theProfiles[i]; + + if( !IsCooriented( aProfile, aNextProfile ) ) + { + gp_XY lp, rp; + aProfile->GetLeftPoint( lp, true ); + aProfile->GetRightPoint( rp, true ); + aProfile->SetLeftPoint( rp, true ); + aProfile->SetRightPoint( lp, true ); + } aProfile->Update(); gp_Pnt aLowest; - gp_Vec2d aTangent; + gp_Vec2d aNormal; double zmin, zmax; - GetProperties( aProfile, aLowest, aTangent, true, zmin, zmax ); - aTangent.Normalize(); + + gp_XYZ curP = aProfile->GetBottomPoint(); + gp_XY curP2d = gp_XY(curP.X(), curP.Y()); + + gp_XYZ nextP; + if( i==n ) + nextP = aPrevProfile->GetBottomPoint(true); + else + nextP = aNextProfile->GetBottomPoint(true); + + gp_XY nextP2d = gp_XY(nextP.X(), nextP.Y()); + + gp_Vec2d aPrTangent; + GetProperties( aProfile, aLowest, aPrTangent, zmin, zmax ); + aNormal.SetCoord( -aPrTangent.Y(), aPrTangent.X() ); + + gp_Vec2d aDirToNextProfile(nextP2d.X() - curP2d.X(), nextP2d.Y() - curP2d.Y() ); + if( i==n ) + aDirToNextProfile.Reverse(); + if (aNormal.Dot(aDirToNextProfile) < 0) + aNormal.Reverse(); + + aNormal.Normalize(); points->SetValue( (int)i, gp_Pnt2d( aLowest.X(), aLowest.Y() ) ); - tangents.SetValue( (int)i, aTangent ); + tangents.SetValue( (int)i, aNormal ); flags->SetValue( (int)i, Standard_True ); } @@ -679,7 +735,7 @@ std::vector HYDROData_DTM::ProfileToParametric( // Transformation of the coordinate systems gp_Pnt aLowest; double zmin, zmax; - GetProperties( theProfile, aLowest, theDir, false, zmin, zmax ); + GetProperties( theProfile, aLowest, theDir, zmin, zmax ); gp_Ax3 aStd3d( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ), gp_Dir( 1, 0, 0 ) ); gp_Ax3 aLocal( gp_Pnt( aLowest.X(), aLowest.Y(), 0 ), gp_Dir( 0, 0, 1 ), gp_Dir( theDir.X(), theDir.Y(), 0 ) ); @@ -896,8 +952,8 @@ std::vector HYDROData_DTM::Interpolate gp_Pnt lowestA, lowestB; gp_Vec2d dirA, dirB; - GetProperties( theProfileA, lowestA, dirA, false, zminA, zmaxA ); - GetProperties( theProfileB, lowestB, dirB, false, zminB, zmaxB ); + GetProperties( theProfileA, lowestA, dirA, zminA, zmaxA ); + GetProperties( theProfileB, lowestB, dirB, zminB, zmaxB ); double hmax = max( zmaxA-zminA, zmaxB-zminB ); @@ -1018,7 +1074,7 @@ int HYDROData_DTM::EstimateNbPoints( const std::vector gp_Pnt aLowest; gp_Vec2d aDir; double aZMin, aZMax; - GetProperties( theProfiles[0], aLowest, aDir, true, aZMin, aZMax ); + GetProperties( theProfiles[0], aLowest, aDir, aZMin, aZMax ); int aNbZSteps = (aZMax-aZMin)/theDDZ; if( aNbSteps > ( 1<<16 ) || aNbZSteps > ( 1<<16 ) ) diff --git a/src/HYDROData/HYDROData_DTM.h b/src/HYDROData/HYDROData_DTM.h index 0e4f746c..0ac618d4 100644 --- a/src/HYDROData/HYDROData_DTM.h +++ b/src/HYDROData/HYDROData_DTM.h @@ -121,7 +121,6 @@ protected: static void GetProperties( const Handle_HYDROData_Profile& theProfile, gp_Pnt& theLowestPoint, gp_Vec2d& theDir, - bool isNormalDir, double& theZMin, double& theZMax ); static void ProfileDiscretization( const Handle_HYDROData_Profile& theProfile, diff --git a/src/HYDROData/HYDROData_Profile.cxx b/src/HYDROData/HYDROData_Profile.cxx index 10f9e237..eec72e7b 100644 --- a/src/HYDROData/HYDROData_Profile.cxx +++ b/src/HYDROData/HYDROData_Profile.cxx @@ -695,7 +695,7 @@ void HYDROData_Profile::UpdateLocalCS( double theDx, double theDy ) SetRightPoint( aPnt, false ); } -HYDROData_Profile::ProfilePoint HYDROData_Profile::GetBottomPoint() const +HYDROData_Profile::ProfilePoint HYDROData_Profile::GetBottomPoint(bool IsConvertToGlobal) const { ProfilePoint aBottom; @@ -742,7 +742,7 @@ HYDROData_Profile::ProfilePoint HYDROData_Profile::GetBottomPoint() const } // Find the corresponding profile point - ProfilePoints aProfilePoints = GetProfilePoints( false ); + ProfilePoints aProfilePoints = GetProfilePoints( IsConvertToGlobal ); if ( aBottomIndex >= 1 && aBottomIndex <= aProfilePoints.Length() ) { aBottom = aProfilePoints.Value( aBottomIndex ); } diff --git a/src/HYDROData/HYDROData_Profile.h b/src/HYDROData/HYDROData_Profile.h index a1571150..cc18e1ab 100644 --- a/src/HYDROData/HYDROData_Profile.h +++ b/src/HYDROData/HYDROData_Profile.h @@ -194,7 +194,7 @@ public: * Return profile point with minimal Z value. * \return non-parametric profile point */ - HYDRODATA_EXPORT ProfilePoint GetBottomPoint() const; + HYDRODATA_EXPORT ProfilePoint GetBottomPoint(bool IsConvertToGlobal = false) const; /** * Return profile middle point. diff --git a/src/HYDRO_tests/test_HYDROData_DTM.cxx b/src/HYDRO_tests/test_HYDROData_DTM.cxx index 175b42b8..3cf271fd 100644 --- a/src/HYDRO_tests/test_HYDROData_DTM.cxx +++ b/src/HYDRO_tests/test_HYDROData_DTM.cxx @@ -305,7 +305,7 @@ void test_HYDROData_DTM::test_profile_properties() gp_Pnt lp; gp_Vec2d dd; double zmin, zmax; - HYDROData_DTM::GetProperties( aProfile, lp, dd, false, zmin, zmax ); + HYDROData_DTM::GetProperties( aProfile, lp, dd, zmin, zmax ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS ); @@ -314,14 +314,14 @@ void test_HYDROData_DTM::test_profile_properties() CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS ); - HYDROData_DTM::GetProperties( aProfile, lp, dd, true, zmin, zmax ); + /* HYDROData_DTM::GetProperties( aProfile, lp, dd, true, zmin, zmax ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, dd.X(), EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 10, dd.Y(), EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS ); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );*/ aDoc->Close(); } -- 2.39.2