Salome HOME
Selection for image presentation & updates for interpolated stream profiles and stream.
[modules/hydro.git] / src / HYDROData / HYDROData_Stream.cxx
index bf517b24aaff52ad5f92fe495056e6122d597043..33de721c8aa96391b7a28711c81311c0ea71f950 100644 (file)
@@ -29,6 +29,7 @@
 #include "HYDROData_ShapesGroup.h"
 #include "HYDROData_ShapesTool.h"
 #include "HYDROData_IAltitudeObject.h"
+#include "HYDROData_IProfilesInterpolator.h"
 #include "HYDROData_Tool.h"
 
 #include <TDataStd_RealArray.hxx>
@@ -1122,8 +1123,66 @@ Handle(HYDROData_Polyline3D) HYDROData_Stream::GetBottomPolyline() const
            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;
+}