Salome HOME
Refs #289 - Spline profile is represented in OCC view as polyline profile
[modules/hydro.git] / src / HYDROData / HYDROData_Bathymetry.cxx
index 43d484c76bf2c5cfeff34cb1d10d991b2a82de75..8d679bd2173caa35788541263c04e8a1b7d88461 100644 (file)
@@ -2,6 +2,7 @@
 #include "HYDROData_Bathymetry.h"
 #include "HYDROData_Document.h"
 #include "HYDROData_Tool.h"
+#include "HYDROData_PolylineXY.h"
 
 #include <gp_XY.hxx>
 #include <gp_XYZ.hxx>
@@ -16,6 +17,8 @@
 #include <QPolygonF>
 #include <QStringList>
 
+#include <math.h>
+
 #define _TIMER
 #ifdef _TIMER
 #include <OSD_Timer.hxx>
@@ -187,7 +190,8 @@ void interpolateAltitudeForPoints( const gp_XY&                               th
 
 double HYDROData_Bathymetry::GetAltitudeForPoint( const gp_XY& thePoint ) const
 {
-  double aResAltitude = GetInvalidAltitude();
+  double anInvalidAltitude = GetInvalidAltitude();
+  double aResAltitude = anInvalidAltitude;
   
   AltitudePoints anAltitudePoints = GetAltitudePoints();
   if ( anAltitudePoints.isEmpty() )
@@ -199,10 +203,10 @@ double HYDROData_Bathymetry::GetAltitudeForPoint( const gp_XY& thePoint ) const
   // [ 0 (top-left) ]          [ 1 (top-right) ]
   //                  thePoint
   // [ 2 (bot-left) ]          [ 3 (bot-right) ] 
-  AltitudePoint aBounds[ 4 ] = { AltitudePoint( -DBL_MAX, -DBL_MAX, GetInvalidAltitude() ),
-                                 AltitudePoint(  DBL_MAX, -DBL_MAX, GetInvalidAltitude() ),
-                                 AltitudePoint( -DBL_MAX,  DBL_MAX, GetInvalidAltitude() ),
-                                 AltitudePoint(  DBL_MAX,  DBL_MAX, GetInvalidAltitude() ) }; 
+  AltitudePoint aBounds[ 4 ] = { AltitudePoint( -DBL_MAX, -DBL_MAX, anInvalidAltitude ),
+                                 AltitudePoint(  DBL_MAX, -DBL_MAX, anInvalidAltitude ),
+                                 AltitudePoint( -DBL_MAX,  DBL_MAX, anInvalidAltitude ),
+                                 AltitudePoint(  DBL_MAX,  DBL_MAX, anInvalidAltitude ) }; 
 
   AltitudePoints::const_iterator aListItBeg = anAltitudePoints.constBegin();
   AltitudePoints::const_iterator aListItEnd = anAltitudePoints.constEnd();
@@ -288,6 +292,14 @@ double HYDROData_Bathymetry::GetAltitudeForPoint( const gp_XY& thePoint ) const
     aBoundingRect << QPointF( aPoint.X(), aPoint.Y() );
   }
 
+  const double LIMIT = 1E300;
+  if( fabs( aBounds[ 0 ].X() ) > LIMIT || fabs( aBounds[ 0 ].Y() ) > LIMIT ||
+      fabs( aBounds[ 1 ].X() ) > LIMIT || fabs( aBounds[ 1 ].Y() ) > LIMIT ||
+      fabs( aBounds[ 2 ].X() ) > LIMIT || fabs( aBounds[ 2 ].Y() ) > LIMIT ||
+      fabs( aBounds[ 3 ].X() ) > LIMIT || fabs( aBounds[ 3 ].Y() ) > LIMIT )
+    return anInvalidAltitude;
+
+
   // Check if requested point is inside of our bounding rectangle
   if ( !aBoundingRect.boundingRect().contains( thePoint.X(), thePoint.Y() ) )
     return aResAltitude;
@@ -468,5 +480,43 @@ bool HYDROData_Bathymetry::importFromXYZFile( QFile&          theFile,
 }
 
 
+bool HYDROData_Bathymetry::CreateBoundaryPolyline() const
+{
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  Handle_HYDROData_PolylineXY aResult = 
+    Handle_HYDROData_PolylineXY::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
+
+  if( aResult.IsNull() )
+    return false;
 
+  //search free name
+  QString aPolylinePref = GetName() + "_Boundary";
+  QString aPolylineName = HYDROData_Tool::GenerateObjectName( aDocument, aPolylinePref );
+  aResult->SetName( aPolylineName );
 
+  double Xmin = 0.0, Xmax = 0.0, Ymin = 0.0, Ymax = 0.0;
+  bool isFirst = true;
+  AltitudePoints aPoints = GetAltitudePoints();
+  foreach( AltitudePoint aPnt, aPoints )
+  {
+    double x = aPnt.X(), y = aPnt.Y();
+    if( isFirst || x<Xmin )
+      Xmin = x;
+    if( isFirst || x>Xmax )
+      Xmax = x;
+    if( isFirst || y<Ymin )
+      Ymin = y;
+    if( isFirst || y>Ymax )
+      Ymax = y;
+    isFirst = false;
+  }
+
+  aResult->AddSection( "bound", HYDROData_IPolyline::SECTION_POLYLINE, true );
+  aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmin, Ymin ) );
+  aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmin, Ymax ) );
+  aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmax, Ymax ) );
+  aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmax, Ymin ) );
+  aResult->Update();
+
+  return true;
+}