]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Lot 7: profiles projection
authorasl <asl@opencascade.com>
Thu, 22 Sep 2016 11:39:27 +0000 (14:39 +0300)
committerasl <asl@opencascade.com>
Wed, 5 Oct 2016 14:23:52 +0000 (17:23 +0300)
src/HYDROData/HYDROData_Profile.cxx
src/HYDROData/HYDROData_Profile.h
src/HYDROPy/HYDROData_Profile.sip
src/HYDRO_tests/reference_data/profiles1.xyz [new file with mode: 0644]
src/HYDRO_tests/test_HYDROData_CalcCase.cxx
src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx
src/HYDRO_tests/test_HYDROData_Profile.cxx
src/HYDRO_tests/test_HYDROData_Profile.h

index 1faa2960339b8017faeef9f825ab695161c0fee8..10f9e237efa60c53d6e52bfb6bbcce0bf17c0fcd 100644 (file)
@@ -35,6 +35,9 @@
 #include <gp_XY.hxx>
 #include <gp_XYZ.hxx>
 #include <gp_Pnt2d.hxx>
+#include <gp_Ax3.hxx>
+#include <GeomAPI_ProjectPointOnSurf.hxx>
+#include <Geom_Plane.hxx>
 
 #include <TDataStd_AsciiString.hxx>
 #include <TDataStd_RealArray.hxx>
@@ -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<int>&        theBadProfilesIds )
+                                       NCollection_Sequence<int>&        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() );
+  }
+}
index f35b5c00cb495584b368d544a070ae92a3862941..a15711509c2e902ca773dedd23221db17e053430 100644 (file)
@@ -226,7 +226,8 @@ public:
    */
   HYDRODATA_EXPORT static int ImportFromFile( const Handle(HYDROData_Document)& theDoc,
                                                const TCollection_AsciiString&    theFileName,
-                                               NCollection_Sequence<int>&        theBadProfilesIds );
+                                               NCollection_Sequence<int>&        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;
index 9ecd88d0199d901cfdb42b87297148e992e2e4ab..601be2037fbdc60009ace46066764c7a11c64238 100644 (file)
@@ -172,13 +172,14 @@ public:
    */
   static int ImportFromFile( HYDROData_Document             theDoc,
                              const TCollection_AsciiString& theFileName,
-                             NCollection_Sequence<int>&     theBadProfilesIds )
+                             NCollection_Sequence<int>&     theBadProfilesIds,
+                                                        bool isToProject = true )
   [int ( const Handle_HYDROData_Document&,
          const TCollection_AsciiString&,
          NCollection_Sequence<int>& )];
   %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 (file)
index 0000000..87d75af
--- /dev/null
@@ -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
index 42ad3731fbefff3bbb86fa35ac3e84bebbde2c55..fdec7023eea0c18c2751bc5067c5a125fcf87834 100644 (file)
@@ -35,7 +35,7 @@
 #include <BRepTools.hxx>
 
 
-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()
index 8b0fed78a6f510b004093cce123c32c603c17658..074748771701e180e2e8c2073368cd935d4d9486 100644 (file)
@@ -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()
index cc3d3da00660a056f8124fbba4350e34903a937b..ee40097ffef461b39c7e7436083941421065fce5 100644 (file)
 #include <QDir>
 #include <QFile>
 #include <QTextStream>
+#include <QString>
 
 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<int> 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, &notEmpty ) );
+  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, &notEmpty ) );
+    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())<EPS && fabs(p1.Y()-p2.Y())<EPS && fabs(p1.Z()-p2.Z())<EPS;
+}
+
+void test_HYDROData_Profile::testProjection()
+{
+  std::string aPath = ( REF_DATA_PATH+"/profiles1.xyz" ).toStdString();
+
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
+
+  TCollection_AsciiString aFileName( aPath.c_str() );
+  NCollection_Sequence<int> 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();
+}
index 9785cf72bc7fc9240be00e19593dd3e081683b56..9707ce22ef6863cc96190b82c455eaac950607aa 100644 (file)
@@ -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);