X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_IProfilesInterpolator.cxx;h=05cb3729bbffd10a1a1289eee6ad8a62ac00e712;hb=f86cf7ecf17dbae2a1d84e0ebbab07c732208c2f;hp=6a5ef3b4e9e16eb6c6264e92c2f38bf398f1f3c3;hpb=a7828fda5a124d2019a6682b4394781ee7292edd;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_IProfilesInterpolator.cxx b/src/HYDROData/HYDROData_IProfilesInterpolator.cxx index 6a5ef3b4..05cb3729 100644 --- a/src/HYDROData/HYDROData_IProfilesInterpolator.cxx +++ b/src/HYDROData/HYDROData_IProfilesInterpolator.cxx @@ -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 +#include 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 theProfile1, const std::vector theProfile2 ) +void HYDROData_IProfilesInterpolator::SetProfiles( const std::vector theProfile1, + const std::vector theProfile2 ) { myProfile1 = theProfile1; myProfile2 = theProfile2; } -void HYDROData_IProfilesInterpolator::SetParameter( const std::string& theName, const std::string& theValue ) +void HYDROData_IProfilesInterpolator::SetProfiles( const NCollection_Sequence& theProfile1, + const NCollection_Sequence& 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 ) @@ -71,27 +90,105 @@ void HYDROData_IProfilesInterpolator::SetResultProfilesNumber( const int theNumb myResultProfilesNumber = theNumber; } -std::vector HYDROData_IProfilesInterpolator::GetResultProfile( const int theProfileIndex ) const +int HYDROData_IProfilesInterpolator::GetCalculatedProfilesNumber() const +{ + return myResultProfiles.size(); +} + +std::vector HYDROData_IProfilesInterpolator::GetResultProfileCoords( const int theProfileIndex ) const { std::vector aResultProfile; - if ( theProfileIndex > 0 && theProfileIndex < (int) myResultProfiles.size() ) { + if ( theProfileIndex >= 0 && theProfileIndex < (int) myResultProfiles.size() ) { aResultProfile = myResultProfiles.at( theProfileIndex ); } return aResultProfile; } +NCollection_Sequence 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 HYDROData_IProfilesInterpolator::GetFirstProfileCoords() const +{ + return myProfile1; +} + +std::vector 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& theProfile ) +{ + myResultProfiles.push_back( theProfile ); +} + +void HYDROData_IProfilesInterpolator::InsertResultProfile( const NCollection_Sequence& theProfile ) +{ + std::vector 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 HYDROData_IProfilesInterpolator::GetFirstProfilePoints() const +{ + return GetPoints( GetFirstProfileCoords() ); +} + +NCollection_Sequence HYDROData_IProfilesInterpolator::GetSecondProfilePoints() const +{ + return GetPoints( GetSecondProfileCoords() ); +} + +NCollection_Sequence HYDROData_IProfilesInterpolator::GetPoints( const std::vector& theCoords ) const +{ + NCollection_Sequence 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; +}