Salome HOME
Merge branch 'BR_LAND_COVER_MAP' of ssh://git.salome-platform.org/modules/hydro into...
[modules/hydro.git] / src / HYDROData / HYDROData_IProfilesInterpolator.cxx
index f0c8d42027730a4e6f2d50aef8897d3bc2ff2112..05cb3729bbffd10a1a1289eee6ad8a62ac00e712 100644 (file)
@@ -1,8 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// Copyright (C) 2014-2015  EDF-R&D
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
@@ -21,7 +17,8 @@
 //
 
 #include "HYDROData_IProfilesInterpolator.h"
-
+#include <cstdlib>
+#include <gp_XYZ.hxx>
 
 const int DEFAULT_RESULT_PROFILES_NB = 1; ///< default number of results profiles
 
@@ -35,15 +32,37 @@ HYDROData_IProfilesInterpolator::~HYDROData_IProfilesInterpolator()
 {
 }
 
-void HYDROData_IProfilesInterpolator::SetProfiles( const std::vector<double> theProfile1, const std::vector<double> theProfile2 )
+void HYDROData_IProfilesInterpolator::SetProfiles( const std::vector<double> theProfile1, 
+                                                   const std::vector<double> theProfile2 )
 {
   myProfile1 = theProfile1;
   myProfile2 = theProfile2;
 }
 
-void HYDROData_IProfilesInterpolator::SetParameter( const std::string& theName, const std::string& theValue )
+void HYDROData_IProfilesInterpolator::SetProfiles( const NCollection_Sequence<gp_XYZ>& theProfile1, 
+                                                   const NCollection_Sequence<gp_XYZ>& theProfile2 )
+{
+  // The first profile
+  for ( int i = theProfile1.Lower(); i <= theProfile1.Upper(); i++ ) {
+    const gp_XYZ& aPnt = theProfile1.Value( i );
+    myProfile1.push_back( aPnt.X() );
+    myProfile1.push_back( aPnt.Y() );
+    myProfile1.push_back( aPnt.Z() );
+  }
+
+  // The second profile
+  for ( int i = theProfile2.Lower(); i <= theProfile2.Upper(); i++ ) {
+    const gp_XYZ& aPnt = theProfile2.Value( i );
+    myProfile2.push_back( aPnt.X() );
+    myProfile2.push_back( aPnt.Y() );
+    myProfile2.push_back( aPnt.Z() );
+  }
+}
+
+void HYDROData_IProfilesInterpolator::SetParameter( const TCollection_AsciiString& theName, 
+                                                    const TCollection_AsciiString& theValue )
 {
-  myParameters[theName] = theValue;
+  myParameters[theName.ToCString()] = theValue.ToCString();
 }
 
 InterpolationError HYDROData_IProfilesInterpolator::GetErrorCode() const
@@ -56,9 +75,9 @@ void HYDROData_IProfilesInterpolator::SetErrorCode( const InterpolationError& th
   myErrorCode = theError;
 }
 
-std::string HYDROData_IProfilesInterpolator::GetErrorMessage() const
+TCollection_AsciiString HYDROData_IProfilesInterpolator::GetErrorMessage() const
 {
-  return myErrorMessage;
+  return TCollection_AsciiString(myErrorMessage.c_str());
 }
 
 void HYDROData_IProfilesInterpolator::SetErrorMessage( const std::string& theMessage )
@@ -76,27 +95,100 @@ int HYDROData_IProfilesInterpolator::GetCalculatedProfilesNumber() const
   return myResultProfiles.size();
 }
 
-std::vector<double> HYDROData_IProfilesInterpolator::GetResultProfile( const int theProfileIndex ) const
+std::vector<double> HYDROData_IProfilesInterpolator::GetResultProfileCoords( const int theProfileIndex ) const
 {
   std::vector<double> aResultProfile;
 
-  if ( theProfileIndex > 0 && theProfileIndex < (int) myResultProfiles.size() ) {
+  if ( theProfileIndex >= 0 && theProfileIndex < (int) myResultProfiles.size() ) {
     aResultProfile = myResultProfiles.at( theProfileIndex );
   }
 
   return aResultProfile;
 }
 
+NCollection_Sequence<gp_XYZ> HYDROData_IProfilesInterpolator::GetResultProfilePoints( const int theProfileIndex ) const
+{
+  return GetPoints( GetResultProfileCoords( theProfileIndex ) );
+}
+
 void HYDROData_IProfilesInterpolator::Reset()
 {
+  // Reset input parameters
   myProfile1.clear();  
   myProfile2.clear();  
   myParameters.clear();
 
   SetResultProfilesNumber( DEFAULT_RESULT_PROFILES_NB );
   
+  // Reset result data
+  ClearResults();
+}
+
+std::vector<double> HYDROData_IProfilesInterpolator::GetFirstProfileCoords() const
+{
+  return myProfile1;
+}
+
+std::vector<double> HYDROData_IProfilesInterpolator::GetSecondProfileCoords() const
+{
+  return myProfile2;
+}
+
+void HYDROData_IProfilesInterpolator::ClearResults()
+{
+  // Clear result data
   myResultProfiles.clear();
 
+  // Reset errors
   SetErrorCode( OK );
   SetErrorMessage( "" );
-}
\ No newline at end of file
+}
+
+int HYDROData_IProfilesInterpolator::GetNbProfilesToCompute() const
+{
+  return myResultProfilesNumber;
+}
+
+void HYDROData_IProfilesInterpolator::InsertResultProfile( const std::vector<double>& theProfile )
+{
+  myResultProfiles.push_back( theProfile );
+}
+
+void HYDROData_IProfilesInterpolator::InsertResultProfile( const NCollection_Sequence<gp_XYZ>& theProfile )
+{
+  std::vector<double> aCoords;
+
+  for ( int i = theProfile.Lower(); i <= theProfile.Upper(); i++ ) {
+    const gp_XYZ& aPnt = theProfile.Value( i );
+    aCoords.push_back( aPnt.X() );
+    aCoords.push_back( aPnt.Y() );
+    aCoords.push_back( aPnt.Z() );
+  }
+
+  myResultProfiles.push_back( aCoords );
+}
+
+NCollection_Sequence<gp_XYZ> HYDROData_IProfilesInterpolator::GetFirstProfilePoints() const
+{
+  return GetPoints( GetFirstProfileCoords() );
+}
+
+NCollection_Sequence<gp_XYZ> HYDROData_IProfilesInterpolator::GetSecondProfilePoints() const
+{
+  return GetPoints( GetSecondProfileCoords() );
+}
+
+NCollection_Sequence<gp_XYZ> HYDROData_IProfilesInterpolator::GetPoints( const std::vector<double>& theCoords ) const
+{
+  NCollection_Sequence<gp_XYZ> aProfilePoints;
+
+  int aNbCoords = (int) theCoords.size();
+  div_t aDiv = std::div( aNbCoords, 3 );
+  if ( aDiv.rem == 0 ) {
+    for ( int i = 0; i < aNbCoords; i += 3 ) {
+      aProfilePoints.Append( gp_XYZ( theCoords[i], theCoords[i+1], theCoords[i+2] ) );
+    }
+  }
+
+  return aProfilePoints;
+}