From: asl Date: Thu, 22 Sep 2016 11:39:27 +0000 (+0300) Subject: Lot 7: profiles projection X-Git-Tag: v1.6~71 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a281a05224fc77473553733f334efff430af12e5;p=modules%2Fhydro.git Lot 7: profiles projection --- diff --git a/src/HYDROData/HYDROData_Profile.cxx b/src/HYDROData/HYDROData_Profile.cxx index 1faa2960..10f9e237 100644 --- a/src/HYDROData/HYDROData_Profile.cxx +++ b/src/HYDROData/HYDROData_Profile.cxx @@ -35,6 +35,9 @@ #include #include #include +#include +#include +#include #include #include @@ -477,7 +480,8 @@ TCollection_AsciiString HYDROData_Profile::GetFilePath() const int HYDROData_Profile::ImportFromFile( const Handle(HYDROData_Document)& theDoc, const TCollection_AsciiString& theFileName, - NCollection_Sequence& theBadProfilesIds ) + NCollection_Sequence& theBadProfilesIds, + bool isToProject ) { if ( theDoc.IsNull() || theFileName.IsEmpty() ) return 0; @@ -500,7 +504,7 @@ int HYDROData_Profile::ImportFromFile( const Handle(HYDROData_Document)& theDoc, aNewProfile = Handle(HYDROData_Profile)::DownCast( theDoc->CreateObject( KIND_PROFILE ) ); bool anIsRead = false; - if ( aNewProfile->ImportFromFile( aFile, &anIsRead ) ) + if ( aNewProfile->ImportFromFile( aFile, isToProject, &anIsRead ) ) { aCreatedProfiles.Append( aNewProfile ); aNewProfile.Nullify(); @@ -533,10 +537,11 @@ int HYDROData_Profile::ImportFromFile( const Handle(HYDROData_Document)& theDoc, } bool HYDROData_Profile::ImportFromFile( const TCollection_AsciiString& theFileName, - bool* theIsRead ) + bool isToProject, + bool* isNotEmpty ) { - if ( theIsRead ) - *theIsRead = false; + if( isNotEmpty ) + *isNotEmpty = false; // Try to open the file OSD_File aFile( theFileName ); @@ -547,7 +552,7 @@ bool HYDROData_Profile::ImportFromFile( const TCollection_AsciiString& theFileNa if ( !aFile.IsOpen() ) return false; - bool aRes = ImportFromFile( aFile, theIsRead ); + bool aRes = ImportFromFile( aFile, isToProject, isNotEmpty ); // Close the file aFile.Close(); @@ -562,10 +567,11 @@ bool HYDROData_Profile::ImportFromFile( const TCollection_AsciiString& theFileNa } bool HYDROData_Profile::ImportFromFile( OSD_File& theFile, - bool* theIsRead ) + bool isToProject, + bool* isNotEmpty ) { - if ( theIsRead ) - *theIsRead = false; + if( isNotEmpty ) + *isNotEmpty = false; if ( !theFile.IsOpen() ) return false; @@ -595,8 +601,8 @@ bool HYDROData_Profile::ImportFromFile( OSD_File& theFile, } // Set flag of read status to true - if ( theIsRead ) - *theIsRead = true; + if( isNotEmpty ) + *isNotEmpty = true; TCollection_AsciiString aValX = aLine.Token( " \t", 1 ); TCollection_AsciiString aValY = aLine.Token( " \t", 2 ); @@ -664,6 +670,8 @@ bool HYDROData_Profile::ImportFromFile( OSD_File& theFile, } else if ( anIsGeoref ) { + if( isToProject ) + ProjectProfilePoints( aPointsXYZ ); SetProfilePoints( aPointsXYZ, true ); } @@ -778,4 +786,21 @@ HYDROData_Profile::ProfilePoint HYDROData_Profile::GetBottomPoint() const } return aMiddlePoint; - } \ No newline at end of file + } + +void HYDROData_Profile::ProjectProfilePoints( ProfilePoints& thePoints ) +{ + int low = thePoints.Lower(), up = thePoints.Upper(); + gp_Pnt aFirst = thePoints.Value( low ); + gp_Pnt aLast = thePoints.Value( up ); + gp_Vec d( aFirst, aLast ); + gp_Vec n( d.Y(), -d.X(), 0 ); + + Handle(Geom_Plane) aPlane = new Geom_Plane( aFirst, gp_Dir( n ) ); + for( int i=low; i<=up; i++ ) + { + gp_XYZ p = thePoints.Value( i ); + gp_Pnt pp = GeomAPI_ProjectPointOnSurf( p, aPlane ); + thePoints.SetValue( i, pp.XYZ() ); + } +} diff --git a/src/HYDROData/HYDROData_Profile.h b/src/HYDROData/HYDROData_Profile.h index f35b5c00..a1571150 100644 --- a/src/HYDROData/HYDROData_Profile.h +++ b/src/HYDROData/HYDROData_Profile.h @@ -226,7 +226,8 @@ public: */ HYDRODATA_EXPORT static int ImportFromFile( const Handle(HYDROData_Document)& theDoc, const TCollection_AsciiString& theFileName, - NCollection_Sequence& theBadProfilesIds ); + NCollection_Sequence& theBadProfilesIds, + bool isToProject = true ); /** * Imports Profile data from file. @@ -235,7 +236,8 @@ public: * \return \c true if file has been successfully read */ HYDRODATA_EXPORT virtual bool ImportFromFile( const TCollection_AsciiString& theFileName, - bool* theIsRead = 0 ); + bool isToProject = true, + bool* isNotEmpty = 0 ); /** * Imports Profile data from file. @@ -244,7 +246,8 @@ public: * \return \c true if file has been successfully read */ HYDRODATA_EXPORT virtual bool ImportFromFile( OSD_File& theFile, - bool* theIsRead = 0 ); + bool isToProject = true, + bool* isNotEmpty = 0 ); protected: /** @@ -255,6 +258,8 @@ protected: TopoDS_Shape CreateProfileWire( bool canUseDefaultPoints ) const; + static void ProjectProfilePoints( ProfilePoints& thePoints ); + protected: friend class HYDROData_Iterator; diff --git a/src/HYDROPy/HYDROData_Profile.sip b/src/HYDROPy/HYDROData_Profile.sip index 9ecd88d0..601be203 100644 --- a/src/HYDROPy/HYDROData_Profile.sip +++ b/src/HYDROPy/HYDROData_Profile.sip @@ -172,13 +172,14 @@ public: */ static int ImportFromFile( HYDROData_Document theDoc, const TCollection_AsciiString& theFileName, - NCollection_Sequence& theBadProfilesIds ) + NCollection_Sequence& theBadProfilesIds, + bool isToProject = true ) [int ( const Handle_HYDROData_Document&, const TCollection_AsciiString&, NCollection_Sequence& )]; %MethodCode Py_BEGIN_ALLOW_THREADS - sipRes = HYDROData_Profile::ImportFromFile( a0, *a1, *a2 ); + sipRes = HYDROData_Profile::ImportFromFile( a0, *a1, *a2, a3 ); Py_END_ALLOW_THREADS %End @@ -189,7 +190,8 @@ public: * \return \c true if file has been successfully read */ virtual bool ImportFromFile( const TCollection_AsciiString& theFileName, - bool* theIsRead = 0 ); + bool isToProject = true, + bool* isNotEmpty = 0 ); protected: /** diff --git a/src/HYDRO_tests/reference_data/profiles1.xyz b/src/HYDRO_tests/reference_data/profiles1.xyz new file mode 100644 index 00000000..87d75afc --- /dev/null +++ b/src/HYDRO_tests/reference_data/profiles1.xyz @@ -0,0 +1,6 @@ +1 2 5 +2 4.1 4 +3 5.9 3 +4 8.2 3 +5 9.8 4 +6 12 5 diff --git a/src/HYDRO_tests/test_HYDROData_CalcCase.cxx b/src/HYDRO_tests/test_HYDROData_CalcCase.cxx index 42ad3731..fdec7023 100644 --- a/src/HYDRO_tests/test_HYDROData_CalcCase.cxx +++ b/src/HYDRO_tests/test_HYDROData_CalcCase.cxx @@ -35,7 +35,7 @@ #include -const QString REF_DATA_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/bin/salome/test"; +QString REF_DATA_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/bin/salome/test"; void test_HYDROData_CalcCase::test_add_int_wires() diff --git a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx index 8b0fed78..07474877 100644 --- a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx +++ b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx @@ -49,7 +49,7 @@ #define _DEVDEBUG_ #include "HYDRO_trace.hxx" -const QString REF_DATA_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/bin/salome/test"; +extern QString REF_DATA_PATH; const QString DEF_STR_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/share/salome/resources/hydro/def_strickler_table.txt"; void test_HYDROData_LandCoverMap::test_add_2_objects() diff --git a/src/HYDRO_tests/test_HYDROData_Profile.cxx b/src/HYDRO_tests/test_HYDROData_Profile.cxx index cc3d3da0..ee40097f 100644 --- a/src/HYDRO_tests/test_HYDROData_Profile.cxx +++ b/src/HYDRO_tests/test_HYDROData_Profile.cxx @@ -31,8 +31,10 @@ #include #include #include +#include const double EPS = 1E-2; +extern QString REF_DATA_PATH; bool test_HYDROData_Profile::createTestFile( const QString& theFileName, const bool theIsParametric ) @@ -87,7 +89,7 @@ void test_HYDROData_Profile::testFileImport() TCollection_AsciiString aFileName( aParamFileName.toStdString().c_str() ); NCollection_Sequence aBadProfilesList; - CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName, aBadProfilesList ) ); + CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName, aBadProfilesList, true ) ); int aProfileCount = 0; HYDROData_Iterator aDocIter( aDoc, KIND_PROFILE ); @@ -110,7 +112,9 @@ void test_HYDROData_Profile::testFileImport() Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); aFileName = TCollection_AsciiString( aGeorefFileName.toStdString().c_str() ); - CPPUNIT_ASSERT( aGeorefProfile->ImportFromFile( aFileName ) ); + bool notEmpty = false; + CPPUNIT_ASSERT( aGeorefProfile->ImportFromFile( aFileName, true, ¬Empty ) ); + CPPUNIT_ASSERT( notEmpty ); // Check validity of imported profile CPPUNIT_ASSERT( aGeorefProfile->IsValid() ); @@ -145,8 +149,10 @@ void test_HYDROData_Profile::testCopy() if ( anIsFileCreated ) { + bool notEmpty = false; TCollection_AsciiString anAsciiFileName( aFileName.toStdString().c_str() ); - CPPUNIT_ASSERT( aProfile1->ImportFromFile( anAsciiFileName ) ); + CPPUNIT_ASSERT( aProfile1->ImportFromFile( anAsciiFileName, true, ¬Empty ) ); + CPPUNIT_ASSERT( notEmpty ); CPPUNIT_ASSERT( aProfile1->IsValid() ); CPPUNIT_ASSERT( aProfile1->NbPoints() == 5 ); @@ -165,3 +171,59 @@ void test_HYDROData_Profile::testCopy() aDoc->Close(); } + +void operator << ( std::ostream& s, const gp_XYZ& p ) +{ + s << "(" << p.X() << "; " << p.Y() << "; " << p.Z() << ") "; +} + +bool operator == ( const gp_XYZ& p1, const gp_XYZ& p2 ) +{ + return fabs(p1.X()-p2.X()) aBadProfilesList; + CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName, aBadProfilesList, false ) ); + CPPUNIT_ASSERT( HYDROData_Profile::ImportFromFile( aDoc, aFileName, aBadProfilesList, true ) ); + + HYDROData_Iterator it( aDoc, KIND_PROFILE ); + CPPUNIT_ASSERT( it.More() ); + Handle(HYDROData_Profile) p1 = Handle(HYDROData_Profile)::DownCast( it.Current() ); it.Next(); + CPPUNIT_ASSERT( it.More() ); + Handle(HYDROData_Profile) p2 = Handle(HYDROData_Profile)::DownCast( it.Current() ); it.Next(); + CPPUNIT_ASSERT( !it.More() ); + + CPPUNIT_ASSERT_EQUAL( QString( "Profile_1" ), p1->GetName() ); + CPPUNIT_ASSERT_EQUAL( QString( "Profile_2" ), p2->GetName() ); + + HYDROData_Profile::ProfilePoints pp1 = p1->GetProfilePoints(); + int low1 = pp1.Lower(), up1 = pp1.Upper(); + CPPUNIT_ASSERT_EQUAL( 1, low1 ); + CPPUNIT_ASSERT_EQUAL( 6, up1 ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 1.0, 2.0, 5.0 ), pp1.Value( 1 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 2.04019, 4.0838, 4.0 ), pp1.Value( 2 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 2.9601, 5.9202, 3.0 ), pp1.Value( 3 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 4.08026, 8.16052, 3.0 ), pp1.Value( 4 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 4.9202, 9.84041, 4.0 ), pp1.Value( 5 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 6.0, 12.0, 5.0 ), pp1.Value( 6 ) ); + + HYDROData_Profile::ProfilePoints pp2 = p2->GetProfilePoints(); + int low2 = pp2.Lower(), up2 = pp2.Upper(); + CPPUNIT_ASSERT_EQUAL( 1, low2 ); + CPPUNIT_ASSERT_EQUAL( 6, up2 ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 1.0, 2.0, 5.0 ), pp2.Value( 1 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 2.04019, 4.0838, 4.0 ), pp2.Value( 2 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 2.9601, 5.9202, 3.0 ), pp2.Value( 3 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 4.08, 8.16, 3.0 ), pp2.Value( 4 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 4.92, 9.84, 4.0 ), pp2.Value( 5 ) ); + CPPUNIT_ASSERT_EQUAL( gp_XYZ( 6.0, 12.0, 5.0 ), pp2.Value( 6 ) ); + + aDoc->Close(); +} diff --git a/src/HYDRO_tests/test_HYDROData_Profile.h b/src/HYDRO_tests/test_HYDROData_Profile.h index 9785cf72..9707ce22 100644 --- a/src/HYDRO_tests/test_HYDROData_Profile.h +++ b/src/HYDRO_tests/test_HYDROData_Profile.h @@ -23,8 +23,9 @@ class QString; class test_HYDROData_Profile : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(test_HYDROData_Profile); - CPPUNIT_TEST(testFileImport); - CPPUNIT_TEST(testCopy); + CPPUNIT_TEST( testFileImport ); + CPPUNIT_TEST( testCopy ); + CPPUNIT_TEST( testProjection ); CPPUNIT_TEST_SUITE_END(); private: @@ -44,6 +45,7 @@ public: // checks the copy/paste mechanism void testCopy(); + void testProjection(); }; CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_Profile);