]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
implementation of the strickler types (integer codes) for points
authorasl <asl@opencascade.com>
Fri, 9 Dec 2016 11:16:12 +0000 (14:16 +0300)
committerasl <asl@opencascade.com>
Fri, 9 Dec 2016 11:16:12 +0000 (14:16 +0300)
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDROData/HYDROData_CalculationCase.h
src/HYDROData/HYDROData_LandCoverMap.cxx
src/HYDROData/HYDROData_LandCoverMap.h
src/HYDROPy/HYDROData_CalculationCase.sip
src/HYDRO_tests/test_HYDROData_DTM.cxx

index 53270245fb077ef0b26e611e8b39b9646fddcb9f..8dee02d603b4778ae61dbeb2f4a1a0ccaa45f9e0 100644 (file)
@@ -932,6 +932,18 @@ std::vector<double> HYDROData_CalculationCase::GetStricklerCoefficientForPoints(
   return theCoeffs;
 }
 
+std::vector<int> HYDROData_CalculationCase::GetStricklerTypeForPoints( const std::vector<gp_XY>& thePoints ) const
+{
+  Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
+  Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
+  std::vector<int> types;
+  if( aLCM.IsNull() || aTable.IsNull() )
+    return types;
+
+  aLCM->ClassifyPoints(thePoints, aTable, types );
+  return types;
+}
+
 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
 {
   Handle(HYDROData_Region) aResRegion;
index b88a108ea4b7bdd4f63ef35784acfd20972718c7..458d6e8a94f298a3c636f96199859aa51412d557 100644 (file)
@@ -346,6 +346,8 @@ public:
                                                                         double DefValue,
                                                                         bool UseMax ) const;
 
+  HYDRODATA_EXPORT std::vector<int> GetStricklerTypeForPoints( const std::vector<gp_XY>& thePoints ) const;
+
   /**
    * Returns altitudes for given points on given region.
    * \param thePoints the points to examine
index 1ecf2586848aa701f27cc82bfbe4946822b6095e..3d166025115e53269bfaa2b1a7f044b08d9c24b5 100644 (file)
@@ -1273,14 +1273,38 @@ void HYDROData_LandCoverMap::UpdateLocalCS( double theDx, double theDy )
   SetShape( aLocatedShape );
 }
 
-void HYDROData_LandCoverMap::ClassifyPoints( const std::vector<gp_XY>& thePoints, std::vector<std::set <QString> >& theTypes ) const
+void HYDROData_LandCoverMap::ClassifyPoints( const std::vector<gp_XY>& thePoints,
+                                             std::vector<std::set <QString> >& theTypes ) const
 {
   HYDROData_LCM_FaceClassifier FC(this);
   FC.Classify(thePoints, theTypes, NULL);
 }
 
+void HYDROData_LandCoverMap::ClassifyPoints( const std::vector<gp_XY>& thePoints,
+                                             const Handle(HYDROData_StricklerTable)& theTable,
+                                             std::vector<int>& theTypes ) const
+{
+  std::vector<std::set <QString> > types;
+  HYDROData_LCM_FaceClassifier FC(this);
+  FC.Classify(thePoints, types, NULL);
+
+  size_t n = types.size();
+  theTypes.resize( n );
+  for( size_t i=0; i<n; i++ )
+  {
+    const std::set<QString>& sub_types = types[i];
+    int aType = 0;
+    if( !sub_types.empty() )
+    {
+      const QString& aSType = *sub_types.begin();
+      aType = theTable->GetAttrValue( aSType ).toInt();
+    }
+    theTypes[i] = aType;
+  }
+}
+
 void HYDROData_LandCoverMap::ClassifyPoints( const std::vector<gp_XY>& thePoints,  
-  Handle(HYDROData_StricklerTable) theTable, 
+  const Handle(HYDROData_StricklerTable)& theTable, 
   std::vector<double>& theCoeffs, double DefValue, bool UseMax ) const
 {
   std::vector<std::set <QString> > Types;
index f6e681b04bff09cdf79d04060799c3d498635004..1e05c6f3121dbdddc0a95f90d6db8afb94be7342 100644 (file)
@@ -151,11 +151,16 @@ public:
 
   HYDRODATA_EXPORT virtual void UpdateLocalCS( double theDx, double theDy );
 
-  HYDRODATA_EXPORT void ClassifyPoints( const std::vector<gp_XY>& thePoints, std::vector<std::set <QString> >& theTypes ) const;
+  HYDRODATA_EXPORT void ClassifyPoints( const std::vector<gp_XY>& thePoints,
+                                        std::vector<std::set <QString> >& theTypes ) const;
+
+  HYDRODATA_EXPORT void ClassifyPoints( const std::vector<gp_XY>& thePoints,
+                                        const Handle(HYDROData_StricklerTable)& theTable,
+                                        std::vector<int>& theTypes ) const;
 
   HYDRODATA_EXPORT void ClassifyPoints( const std::vector<gp_XY>& thePoints,
-    Handle(HYDROData_StricklerTable) theTable, 
-    std::vector<double>& theCoeffs, double DefValue, bool UseMax ) const;
+                                        const Handle(HYDROData_StricklerTable)& theTable, 
+                                        std::vector<double>& theCoeffs, double DefValue, bool UseMax ) const;
 
 protected:
   void SetShape( const TopoDS_Shape& );
index 1bbc51e6c12e7324d616b1777c770f8887699d8a..5f7d254dc628c3d657fb8aea836461952543d2c9 100644 (file)
@@ -479,6 +479,26 @@ public:
   %End
 
 
+  std::vector<int> GetStricklerTypeForPoints( const NCollection_Sequence<double>& theCoordsX,
+                                              const NCollection_Sequence<double>& theCoordsY ) const
+  [std::vector<int>( const NCollection_Sequence<gp_XY>& )];
+  %MethodCode
+  std::vector<gp_XY> aPnts;
+  int aLen = qMin( a0->Length(), a1->Length() );
+  for ( int i = 1; i <= aLen; ++i )
+  {
+    gp_XY aPnt( a0->Value( i ), a1->Value( i ) );
+    aPnts.push_back( aPnt );
+  }
+  std::vector<int> aRes;
+  Py_BEGIN_ALLOW_THREADS
+  aRes = sipSelfWasArg ? sipCpp->HYDROData_CalculationCase::GetStricklerTypeForPoints( aPnts ) : 
+                         sipCpp->GetStricklerTypeForPoints( aPnts );
+  Py_END_ALLOW_THREADS
+  sipRes = new std::vector<int>( aRes );
+  %End
+
+
   /**
    * Returns altitudes for given points on given zone.
    * \param thePoints the points to examine
index c9934653c6cc5a1d3af64f02cf33d60b13b08d0c..66547b5e7b219dad8730e955c5684129e679c710 100644 (file)
@@ -645,6 +645,12 @@ void test_HYDROData_DTM::test_classifier_1()
   CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0123, values[1], EPS );
   CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0221, values[2], EPS );
 
+  std::vector<int> types = aCase->GetStricklerTypeForPoints( points );
+  CPPUNIT_ASSERT_EQUAL( 3, (int)types.size() );
+  CPPUNIT_ASSERT_EQUAL( 123, types[0] );
+  CPPUNIT_ASSERT_EQUAL( 123, types[1] );
+  CPPUNIT_ASSERT_EQUAL( 221, types[2] );
+
   aDoc->Close();
 }