1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROData_IProfilesInterpolator.h"
27 const int DEFAULT_RESULT_PROFILES_NB = 1; ///< default number of results profiles
29 HYDROData_IProfilesInterpolator::HYDROData_IProfilesInterpolator()
30 : myResultProfilesNumber( DEFAULT_RESULT_PROFILES_NB ),
35 HYDROData_IProfilesInterpolator::~HYDROData_IProfilesInterpolator()
39 void HYDROData_IProfilesInterpolator::SetProfiles( const std::vector<double> theProfile1,
40 const std::vector<double> theProfile2 )
42 myProfile1 = theProfile1;
43 myProfile2 = theProfile2;
46 void HYDROData_IProfilesInterpolator::SetProfiles( const NCollection_Sequence<gp_XYZ>& theProfile1,
47 const NCollection_Sequence<gp_XYZ>& theProfile2 )
50 for ( int i = theProfile1.Lower(); i <= theProfile1.Upper(); i++ ) {
51 const gp_XYZ& aPnt = theProfile1.Value( i );
52 myProfile1.push_back( aPnt.X() );
53 myProfile1.push_back( aPnt.Y() );
54 myProfile1.push_back( aPnt.Z() );
58 for ( int i = theProfile2.Lower(); i <= theProfile2.Upper(); i++ ) {
59 const gp_XYZ& aPnt = theProfile2.Value( i );
60 myProfile2.push_back( aPnt.X() );
61 myProfile2.push_back( aPnt.Y() );
62 myProfile2.push_back( aPnt.Z() );
66 void HYDROData_IProfilesInterpolator::SetParameter( const TCollection_AsciiString& theName,
67 const TCollection_AsciiString& theValue )
69 myParameters[theName.ToCString()] = theValue.ToCString();
72 InterpolationError HYDROData_IProfilesInterpolator::GetErrorCode() const
77 void HYDROData_IProfilesInterpolator::SetErrorCode( const InterpolationError& theError )
79 myErrorCode = theError;
82 TCollection_AsciiString HYDROData_IProfilesInterpolator::GetErrorMessage() const
84 return TCollection_AsciiString(myErrorMessage.c_str());
87 void HYDROData_IProfilesInterpolator::SetErrorMessage( const std::string& theMessage )
89 myErrorMessage = theMessage;
92 void HYDROData_IProfilesInterpolator::SetResultProfilesNumber( const int theNumber )
94 myResultProfilesNumber = theNumber;
97 int HYDROData_IProfilesInterpolator::GetCalculatedProfilesNumber() const
99 return myResultProfiles.size();
102 std::vector<double> HYDROData_IProfilesInterpolator::GetResultProfileCoords( const int theProfileIndex ) const
104 std::vector<double> aResultProfile;
106 if ( theProfileIndex >= 0 && theProfileIndex < (int) myResultProfiles.size() ) {
107 aResultProfile = myResultProfiles.at( theProfileIndex );
110 return aResultProfile;
113 NCollection_Sequence<gp_XYZ> HYDROData_IProfilesInterpolator::GetResultProfilePoints( const int theProfileIndex ) const
115 return GetPoints( GetResultProfileCoords( theProfileIndex ) );
118 void HYDROData_IProfilesInterpolator::Reset()
120 // Reset input parameters
123 myParameters.clear();
125 SetResultProfilesNumber( DEFAULT_RESULT_PROFILES_NB );
131 std::vector<double> HYDROData_IProfilesInterpolator::GetFirstProfileCoords() const
136 std::vector<double> HYDROData_IProfilesInterpolator::GetSecondProfileCoords() const
141 void HYDROData_IProfilesInterpolator::ClearResults()
144 myResultProfiles.clear();
148 SetErrorMessage( "" );
151 int HYDROData_IProfilesInterpolator::GetNbProfilesToCompute() const
153 return myResultProfilesNumber;
156 void HYDROData_IProfilesInterpolator::InsertResultProfile( const std::vector<double>& theProfile )
158 myResultProfiles.push_back( theProfile );
161 void HYDROData_IProfilesInterpolator::InsertResultProfile( const NCollection_Sequence<gp_XYZ>& theProfile )
163 std::vector<double> aCoords;
165 for ( int i = theProfile.Lower(); i <= theProfile.Upper(); i++ ) {
166 const gp_XYZ& aPnt = theProfile.Value( i );
167 aCoords.push_back( aPnt.X() );
168 aCoords.push_back( aPnt.Y() );
169 aCoords.push_back( aPnt.Z() );
172 myResultProfiles.push_back( aCoords );
175 NCollection_Sequence<gp_XYZ> HYDROData_IProfilesInterpolator::GetFirstProfilePoints() const
177 return GetPoints( GetFirstProfileCoords() );
180 NCollection_Sequence<gp_XYZ> HYDROData_IProfilesInterpolator::GetSecondProfilePoints() const
182 return GetPoints( GetSecondProfileCoords() );
185 NCollection_Sequence<gp_XYZ> HYDROData_IProfilesInterpolator::GetPoints( const std::vector<double>& theCoords ) const
187 NCollection_Sequence<gp_XYZ> aProfilePoints;
189 int aNbCoords = (int) theCoords.size();
190 div_t aDiv = std::div( aNbCoords, 3 );
191 if ( aDiv.rem == 0 ) {
192 for ( int i = 0; i < aNbCoords; i += 3 ) {
193 aProfilePoints.Append( gp_XYZ( theCoords[i], theCoords[i+1], theCoords[i+2] ) );
197 return aProfilePoints;