+ Handle(HYDROData_Stream) aStream =
+ Handle(HYDROData_Stream)::DownCast( GetFatherObject() );
+ if ( aStream.IsNull() )
+ return aResAltitude;
+
+ TopoDS_Shape aStreamShape = aStream->GetTopShape();
+ if ( aStreamShape.IsNull() )
+ return aResAltitude;
+
+ TopExp_Explorer aStreamFaceExp( aStreamShape, TopAbs_FACE );
+ if ( !aStreamFaceExp.More() )
+ return aResAltitude;
+
+ // Get only face because of 2d profile wires is in compound
+ TopoDS_Face aStreamFace = TopoDS::Face( aStreamFaceExp.Current() );
+
+ // Check if point is inside of stream presentation
+ TopAbs_State aPointState = HYDROData_Tool::ComputePointState(thePoint, aStreamFace);
+
+#ifdef DEB_CLASS2D
+ cout << "Point status is = " << aPointState <<endl;
+ TopoDS_Compound aCmp;
+ BRep_Builder aBB;
+ aBB.MakeCompound(aCmp);
+ aBB.Add(aCmp, aStreamFace);
+ gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
+ BRepBuilderAPI_MakeVertex aMk(aPnt);
+ aBB.Add(aCmp, aMk.Vertex());
+ BRepTools::Write(aCmp, "FCL2d.brep");
+#endif
+ if ( aPointState == TopAbs_OUT )
+ return aResAltitude;
+
+ // Find the two profiles between which the point is lies
+ Handle(HYDROData_Profile) aLeftProfile, aRightProfile;
+ if ( !getBoundaryProfilesForPoint( thePoint, aLeftProfile, aRightProfile ) )
+ return aResAltitude;
+
+ // Find the projections of point to borders of stream
+ gp_XYZ aPointToTest( thePoint.X(), thePoint.Y(), 0.0 );
+
+ TopoDS_Edge aStreamLeftEdge = TopoDS::Edge( aStream->GetLeftShape() );
+ TopoDS_Edge aStreamRightEdge = TopoDS::Edge( aStream->GetRightShape() );
+
+ Standard_Real aFirst = 0.0, aLast = 0.0;
+ Handle(Geom_Curve) anEdgeLeftCurve = BRep_Tool::Curve( aStreamLeftEdge, aFirst, aLast );
+ Handle(Geom_Curve) anEdgeRightCurve = BRep_Tool::Curve( aStreamRightEdge, aFirst, aLast );
+
+ GeomAPI_ProjectPointOnCurve aLeftProject( aPointToTest, anEdgeLeftCurve );
+ GeomAPI_ProjectPointOnCurve aRightProject( aPointToTest, anEdgeRightCurve );
+
+ Standard_Real aLeftDist = aLeftProject.LowerDistance();
+ Standard_Real aRightDist = aRightProject.LowerDistance();
+
+ // Find the altitude in profiles
+ Standard_Real aLeftAlt = getAltitudeFromProfile( aLeftProfile, aLeftDist, aRightDist );
+ Standard_Real aRightAlt = getAltitudeFromProfile( aRightProfile, aLeftDist, aRightDist );
+
+ // Interpolate altitudes
+ // Left profile line ( the segment between the firts and the last profile point )
+ HYDROData_Profile::ProfilePoints aLeftProfilePoints = aLeftProfile->GetProfilePoints( false );
+ gp_Pnt aLeftProfileP1( aLeftProfilePoints.First() );
+ aLeftProfileP1.SetZ( 0 );
+ gp_Pnt aLeftProfileP2( aLeftProfilePoints.Last() );
+ aLeftProfileP2.SetZ( 0 );
+ gp_Vec aLeftProfileVec( aLeftProfileP1, aLeftProfileP2 );
+ Handle(Geom_Line) aLeftProfileLine = new Geom_Line( gp_Ax1( aLeftProfileP1, aLeftProfileVec ) );
+ // Right profile line
+ HYDROData_Profile::ProfilePoints aRightProfilePoints = aRightProfile->GetProfilePoints( false );
+ gp_Pnt aRightProfileP1( aRightProfilePoints.First() );
+ aRightProfileP1.SetZ( 0 );
+ gp_Pnt aRightProfileP2( aRightProfilePoints.Last() );
+ aRightProfileP2.SetZ( 0 );
+ gp_Vec aRightProfileVec( aRightProfileP1, aRightProfileP2 );
+ Handle(Geom_Line) aRightProfileLine = new Geom_Line( gp_Ax1( aRightProfileP1, aRightProfileVec ) );
+ // The point projections on the left and right profiles
+ GeomAPI_ProjectPointOnCurve aLeftProfileProject( aPointToTest, aLeftProfileLine );
+ GeomAPI_ProjectPointOnCurve aRightProfileProject( aPointToTest, aRightProfileLine );
+ // The point distance to the left and right profiles
+ Standard_Real aLeftProfileDist = aLeftProfileProject.LowerDistance();
+ Standard_Real aRightProfileDist = aRightProfileProject.LowerDistance();
+ // The coefficients
+ Standard_Real aFirstCoeff = aLeftProfileDist / ( aLeftProfileDist + aRightProfileDist );
+ Standard_Real aSecCoeff = aRightProfileDist / ( aLeftProfileDist + aRightProfileDist );
+
+ aResAltitude = aLeftAlt * ( 1 - aFirstCoeff ) + aRightAlt * ( 1 - aSecCoeff );
+