1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_IProfilesInterpolator.h"
23 const int DEFAULT_RESULT_PROFILES_NB = 1; ///< default number of results profiles
25 HYDROData_IProfilesInterpolator::HYDROData_IProfilesInterpolator()
26 : myResultProfilesNumber( DEFAULT_RESULT_PROFILES_NB ),
31 HYDROData_IProfilesInterpolator::~HYDROData_IProfilesInterpolator()
35 void HYDROData_IProfilesInterpolator::SetProfiles( const std::vector<double> theProfile1,
36 const std::vector<double> theProfile2 )
38 myProfile1 = theProfile1;
39 myProfile2 = theProfile2;
42 void HYDROData_IProfilesInterpolator::SetProfiles( const NCollection_Sequence<gp_XYZ>& theProfile1,
43 const NCollection_Sequence<gp_XYZ>& theProfile2 )
46 for ( int i = theProfile1.Lower(); i <= theProfile1.Upper(); i++ ) {
47 const gp_XYZ& aPnt = theProfile1.Value( i );
48 myProfile1.push_back( aPnt.X() );
49 myProfile1.push_back( aPnt.Y() );
50 myProfile1.push_back( aPnt.Z() );
54 for ( int i = theProfile2.Lower(); i <= theProfile2.Upper(); i++ ) {
55 const gp_XYZ& aPnt = theProfile2.Value( i );
56 myProfile2.push_back( aPnt.X() );
57 myProfile2.push_back( aPnt.Y() );
58 myProfile2.push_back( aPnt.Z() );
62 void HYDROData_IProfilesInterpolator::SetParameter( const TCollection_AsciiString& theName,
63 const TCollection_AsciiString& theValue )
65 myParameters[theName.ToCString()] = theValue.ToCString();
68 InterpolationError HYDROData_IProfilesInterpolator::GetErrorCode() const
73 void HYDROData_IProfilesInterpolator::SetErrorCode( const InterpolationError& theError )
75 myErrorCode = theError;
78 TCollection_AsciiString HYDROData_IProfilesInterpolator::GetErrorMessage() const
80 return TCollection_AsciiString(myErrorMessage.c_str());
83 void HYDROData_IProfilesInterpolator::SetErrorMessage( const std::string& theMessage )
85 myErrorMessage = theMessage;
88 void HYDROData_IProfilesInterpolator::SetResultProfilesNumber( const int theNumber )
90 myResultProfilesNumber = theNumber;
93 int HYDROData_IProfilesInterpolator::GetCalculatedProfilesNumber() const
95 return myResultProfiles.size();
98 std::vector<double> HYDROData_IProfilesInterpolator::GetResultProfileCoords( const int theProfileIndex ) const
100 std::vector<double> aResultProfile;
102 if ( theProfileIndex >= 0 && theProfileIndex < (int) myResultProfiles.size() ) {
103 aResultProfile = myResultProfiles.at( theProfileIndex );
106 return aResultProfile;
109 NCollection_Sequence<gp_XYZ> HYDROData_IProfilesInterpolator::GetResultProfilePoints( const int theProfileIndex ) const
111 return GetPoints( GetResultProfileCoords( theProfileIndex ) );
114 void HYDROData_IProfilesInterpolator::Reset()
116 // Reset input parameters
119 myParameters.clear();
121 SetResultProfilesNumber( DEFAULT_RESULT_PROFILES_NB );
127 std::vector<double> HYDROData_IProfilesInterpolator::GetFirstProfileCoords() const
132 std::vector<double> HYDROData_IProfilesInterpolator::GetSecondProfileCoords() const
137 void HYDROData_IProfilesInterpolator::ClearResults()
140 myResultProfiles.clear();
144 SetErrorMessage( "" );
147 int HYDROData_IProfilesInterpolator::GetNbProfilesToCompute() const
149 return myResultProfilesNumber;
152 void HYDROData_IProfilesInterpolator::InsertResultProfile( const std::vector<double>& theProfile )
154 myResultProfiles.push_back( theProfile );
157 void HYDROData_IProfilesInterpolator::InsertResultProfile( const NCollection_Sequence<gp_XYZ>& theProfile )
159 std::vector<double> aCoords;
161 for ( int i = theProfile.Lower(); i <= theProfile.Upper(); i++ ) {
162 const gp_XYZ& aPnt = theProfile.Value( i );
163 aCoords.push_back( aPnt.X() );
164 aCoords.push_back( aPnt.Y() );
165 aCoords.push_back( aPnt.Z() );
168 myResultProfiles.push_back( aCoords );
171 NCollection_Sequence<gp_XYZ> HYDROData_IProfilesInterpolator::GetFirstProfilePoints() const
173 return GetPoints( GetFirstProfileCoords() );
176 NCollection_Sequence<gp_XYZ> HYDROData_IProfilesInterpolator::GetSecondProfilePoints() const
178 return GetPoints( GetSecondProfileCoords() );
181 NCollection_Sequence<gp_XYZ> HYDROData_IProfilesInterpolator::GetPoints( const std::vector<double>& theCoords ) const
183 NCollection_Sequence<gp_XYZ> aProfilePoints;
185 int aNbCoords = (int) theCoords.size();
186 div_t aDiv = std::div( aNbCoords, 3 );
187 if ( aDiv.rem == 0 ) {
188 for ( int i = 0; i < aNbCoords; i += 3 ) {
189 aProfilePoints.Append( gp_XYZ( theCoords[i], theCoords[i+1], theCoords[i+2] ) );
193 return aProfilePoints;