#include "HYDROData_ShapesGroup.h"
#include "HYDROData_ShapesTool.h"
#include "HYDROData_IAltitudeObject.h"
+#include "HYDROData_IProfilesInterpolator.h"
#include "HYDROData_Tool.h"
#include <TDataStd_RealArray.hxx>
GetReferenceObject( DataTag_BottomPolyline ) );
}
-bool HYDROData_Stream::Interpolate( const HYDROData_IProfilesInterpolator* theInterpolator )
+bool HYDROData_Stream::Interpolate( HYDROData_IProfilesInterpolator* theInterpolator )
{
- ///< \todo this is just a stub
- return true;
-}
\ No newline at end of file
+ // Get the document
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+ if ( aDocument.IsNull() ) {
+ return false;
+ }
+
+ if ( theInterpolator->GetCalculatedProfilesNumber() < 1 ) {
+ theInterpolator->Calculate();
+ }
+
+ if ( theInterpolator->GetErrorCode() != OK ) {
+ return false;
+ }
+
+ bool isOK = true;
+
+ for ( int aProfileInd = 0; aProfileInd < theInterpolator->GetCalculatedProfilesNumber(); aProfileInd++ ) {
+ // Get calculated point coordinates
+ std::vector<double> aResultCoords = theInterpolator->GetResultProfile( aProfileInd );
+ div_t aDiv = std::div( aResultCoords.size(), 3 );
+ if ( aDiv.rem != 0 ) {
+ isOK = false;
+ continue;
+ }
+
+ // Create profile object
+ Handle(HYDROData_Profile) aProfile =
+ Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
+ QString aBaseName = GetName() + "_interp_profile";
+ QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName );
+ aProfile->SetName( aName );
+
+ // Fill the profile with points
+ HYDROData_Profile::ProfilePoints aProfilePoints;
+
+ int aPointsNb = aDiv.quot;
+ for ( int aPointInd = 0; aPointInd <= aPointsNb - 1; aPointInd++ ) {
+ int anXindex = aPointInd * 3;
+ double anX = aResultCoords[ anXindex ];
+ double anY = aResultCoords[ anXindex + 1 ];
+ double aZ = aResultCoords[ anXindex + 2 ];
+
+ aProfilePoints.Append( gp_XYZ( anX, anY, aZ ) );
+ }
+
+ aProfile->SetProfilePoints( aProfilePoints );
+
+ // Add profile to the stream
+ bool isAdded = AddProfile( aProfile );
+ if ( !isAdded ) {
+ aProfile->Remove();
+ }
+ else
+ aProfile->Update();
+ }
+
+ if ( isOK )
+ Update();
+
+ return isOK;
+}