From: mzn Date: Wed, 2 Sep 2015 14:05:36 +0000 (+0300) Subject: refs #635: Altitude interpolation does not work anymore on channels and embankments. X-Git-Tag: v1.5~147 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5395b3a6f169302c35e0e9683915f1136ba99a0b;p=modules%2Fhydro.git refs #635: Altitude interpolation does not work anymore on channels and embankments. --- diff --git a/src/HYDROData/HYDROData_Channel.cxx b/src/HYDROData/HYDROData_Channel.cxx index a2bb6f47..c78c5e41 100644 --- a/src/HYDROData/HYDROData_Channel.cxx +++ b/src/HYDROData/HYDROData_Channel.cxx @@ -27,6 +27,7 @@ #include "HYDROData_ShapesTool.h" #include "HYDROData_Pipes.h" #include "HYDROData_Stream.h" +#include "HYDROData_Tool.h" #include @@ -456,6 +457,17 @@ void HYDROData_Channel::RemoveProfile() ObjectKind HYDROData_Channel::getAltitudeObjectType() const { - return KIND_OBSTACLE_ALTITUDE; + return KIND_STREAM_ALTITUDE; } +TopoDS_Shape HYDROData_Channel::GetLeftShape() const +{ + HYDROData_SequenceOfObjects aGroups = GetGroups(); + return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 1); +} + +TopoDS_Shape HYDROData_Channel::GetRightShape() const +{ + HYDROData_SequenceOfObjects aGroups = GetGroups(); + return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 2); +} diff --git a/src/HYDROData/HYDROData_Channel.h b/src/HYDROData/HYDROData_Channel.h index a53db842..5b4e694f 100644 --- a/src/HYDROData/HYDROData_Channel.h +++ b/src/HYDROData/HYDROData_Channel.h @@ -100,6 +100,16 @@ public: */ HYDRODATA_EXPORT virtual TopoDS_Shape GetShape3D() const; + /** + * Returns the left edge of the channel. + */ + HYDRODATA_EXPORT virtual TopoDS_Shape GetLeftShape() const; + + /** + * Returns the right edge of the channel. + */ + HYDRODATA_EXPORT virtual TopoDS_Shape GetRightShape() const; + /** * Update the shape presentations of stream. * Call this method whenever you made changes for channel data. diff --git a/src/HYDROData/HYDROData_Stream.cxx b/src/HYDROData/HYDROData_Stream.cxx index 42a62b57..6f77d56d 100644 --- a/src/HYDROData/HYDROData_Stream.cxx +++ b/src/HYDROData/HYDROData_Stream.cxx @@ -303,49 +303,28 @@ bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHyd return true; } -TopoDS_Shape getShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups, - const int theGroupId ) -{ - TopoDS_Shape aResShape; - if ( theGroups.Length() != 4 ) - return aResShape; - - Handle(HYDROData_ShapesGroup) aGroup = - Handle(HYDROData_ShapesGroup)::DownCast( theGroups.Value( theGroupId ) ); - if ( aGroup.IsNull() ) - return aResShape; - - TopTools_SequenceOfShape aGroupShapes; - aGroup->GetShapes( aGroupShapes ); - - if ( !aGroupShapes.IsEmpty() ) - aResShape = aGroupShapes.First(); - - return aResShape; -} - TopoDS_Shape HYDROData_Stream::GetLeftShape() const { HYDROData_SequenceOfObjects aGroups = GetGroups(); - return getShapeFromGroup( aGroups, 1 ); + return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 1); } TopoDS_Shape HYDROData_Stream::GetRightShape() const { HYDROData_SequenceOfObjects aGroups = GetGroups(); - return getShapeFromGroup( aGroups, 2 ); + return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 2); } TopoDS_Shape HYDROData_Stream::GetInletShape() const { HYDROData_SequenceOfObjects aGroups = GetGroups(); - return getShapeFromGroup( aGroups, 3 ); + return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 3); } TopoDS_Shape HYDROData_Stream::GetOutletShape() const { HYDROData_SequenceOfObjects aGroups = GetGroups(); - return getShapeFromGroup( aGroups, 4 ); + return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 4); } QColor HYDROData_Stream::getDefaultFillingColor() const diff --git a/src/HYDROData/HYDROData_StreamAltitude.cxx b/src/HYDROData/HYDROData_StreamAltitude.cxx index 50443a31..60452989 100644 --- a/src/HYDROData/HYDROData_StreamAltitude.cxx +++ b/src/HYDROData/HYDROData_StreamAltitude.cxx @@ -18,6 +18,7 @@ #include "HYDROData_StreamAltitude.h" +#include "HYDROData_Channel.h" #include "HYDROData_Document.h" #include "HYDROData_Profile.h" #include "HYDROData_Stream.h" @@ -37,6 +38,7 @@ #include +#include #include #include @@ -44,6 +46,7 @@ #include #include +#include #include @@ -66,181 +69,200 @@ HYDROData_StreamAltitude::~HYDROData_StreamAltitude() { } -Standard_Real getAltitudeFromProfile( const Handle(HYDROData_Profile)& theProfile, - const Standard_Real& theLeftDist, - const Standard_Real& theRightDist ) +bool IsPointBetweenEdges( const gp_Pnt& aFirstPnt1, const gp_Pnt& aLastPnt1, + const gp_Pnt& aFirstPnt2, const gp_Pnt& aLastPnt2, + const gp_Pnt& thePoint) { + BRepBuilderAPI_MakeEdge aLeftMakeEdge( aFirstPnt1, aLastPnt1 ); + BRepBuilderAPI_MakeEdge aBotMakeEdge( aLastPnt1, aLastPnt2 ); + BRepBuilderAPI_MakeEdge aRightMakeEdge( aLastPnt2, aFirstPnt2 ); + BRepBuilderAPI_MakeEdge aTopMakeEdge( aFirstPnt2, aFirstPnt1 ); + + BRepBuilderAPI_MakeWire aMakeWire( aLeftMakeEdge.Edge(), aBotMakeEdge.Edge(), + aRightMakeEdge.Edge(), aTopMakeEdge.Edge() ); + + BRepBuilderAPI_MakeFace aMakeFace( aMakeWire.Wire() ); + + TopoDS_Face aFace = aMakeFace.Face(); +#ifdef DEB_CLASS2D + TopoDS_Compound aCmp; + BRep_Builder aBB; + aBB.MakeCompound(aCmp); + aBB.Add(aCmp, aFace); + BRepBuilderAPI_MakeVertex aMk(thePoint); + aBB.Add(aCmp, aMk.Vertex()); + BRepTools::Write(aCmp, "ProfileFace.brep"); +#endif + + gp_XY anXY( thePoint.X(), thePoint.Y() ); + TopAbs_State aPointState = HYDROData_Tool::ComputePointState(anXY, aFace); + +#ifdef DEB_CLASS2D + cout << "Point status is = " << aPointState <GetLeftPoint( aFirstPoint, false ) || - !theProfile->GetRightPoint( aLastPoint, false ) ) - return aResAlt; - - gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), 0 ); - gp_Pnt aPnt2( aLastPoint.X(), aLastPoint.Y(), 0 ); - + TopoDS_Vertex aFirstVertex, aLastVertex; + TopExp::Vertices( theWire, aFirstVertex, aLastVertex ); + + gp_Pnt aPnt1( BRep_Tool::Pnt( aFirstVertex ) ); + aPnt1.SetZ( 0 ); + gp_Pnt aPnt2( BRep_Tool::Pnt( aLastVertex ) ); + aPnt2.SetZ( 0 ); + Standard_Real aProfileDist = aPnt1.Distance( aPnt2 ); Standard_Real aCoeff = aProfileDist / ( theLeftDist + theRightDist ); gp_Pnt anIntPoint( aPnt1.XYZ() + ( aCoeff * theLeftDist ) * gp_Dir( gp_Vec( aPnt1, aPnt2 ) ).XYZ() ); - gp_Lin aPointLine( anIntPoint, gp::DZ() ); - - gp_Pnt aPrevPoint; - gp_Lin aPrevNormal; - HYDROData_Profile::ProfilePoints aProfilePoints = theProfile->GetProfilePoints( false ); - for ( int i = 1, n = aProfilePoints.Length(); i <= n; ++i ) - { - gp_Pnt aProfPoint( aProfilePoints.Value( i ) ); - - Standard_Real aDist = aPointLine.Distance( aProfPoint ); - if ( aDist <= gp::Resolution() ) - { - // We found the intersected point - aResAlt = aProfPoint.Z(); - break; - } - - gp_Lin aNormal = aPointLine.Normal( aProfPoint ); - if ( i == 1 ) - { - aPrevNormal = aNormal; - aPrevPoint = aProfPoint; - continue; - } - - if ( aPrevNormal.Direction().Dot( aNormal.Direction() ) < 0 ) - { - // We found the intersected edge - gp_Lin anEdgeLine( aPrevPoint, gp_Dir( gp_Vec( aPrevPoint, aProfPoint ) ) ); - - Extrema_ExtElC anExtrema( aPointLine, anEdgeLine, Precision::Angular() ); - if ( !anExtrema.IsParallel() ) - { - Extrema_POnCurv aFirstPnt, aSecPnt; - anExtrema.Points( 1, aFirstPnt, aSecPnt ); - - const gp_Pnt& anIntPnt = aSecPnt.Value(); - aResAlt = anIntPnt.Z(); - - break; - } - } - - aPrevNormal = aNormal; - aPrevPoint = aProfPoint; - } - - return aResAlt; + return HYDROData_Tool::GetAltitudeForWire( theWire, + gp_XY(anIntPoint.X(), anIntPoint.Y()), + 1E-2, + 1E-2, + HYDROData_IAltitudeObject::GetInvalidAltitude() ); } -bool HYDROData_StreamAltitude::getBoundaryProfilesForPoint( - const gp_XY& thePoint, - Handle(HYDROData_Profile)& theLeftProfile, - Handle(HYDROData_Profile)& theRightProfile ) const +bool HYDROData_StreamAltitude::getBoundaryWiresForPoint( + const gp_XY& thePoint, + TopoDS_Wire& theLeftWire, + TopoDS_Wire& theRightWire ) const { - Handle(HYDROData_Stream) aStream = - Handle(HYDROData_Stream)::DownCast( GetFatherObject() ); - if ( aStream.IsNull() ) - return false; + gp_Pnt aTestPnt( thePoint.X(), thePoint.Y(), 0 ); - HYDROData_SequenceOfObjects aStreamProfiles = aStream->GetProfiles(); - if ( aStreamProfiles.Length() < 2 ) + Handle(HYDROData_Object) anObject = + Handle(HYDROData_Object)::DownCast( GetFatherObject() ); + if ( anObject.IsNull() ) { return false; + } - Handle(HYDROData_Profile) aPrevProfile; - gp_Pnt aPrevPnt1, aPrevPnt2; - for ( int i = 1, n = aStreamProfiles.Length(); i <= n; ++i ) - { - Handle(HYDROData_Profile) aProfile = - Handle(HYDROData_Profile)::DownCast( aStreamProfiles.Value( i ) ); - if ( aProfile.IsNull() ) - continue; - - gp_XY aFirstPoint, aLastPoint; - if ( !aProfile->GetLeftPoint( aFirstPoint, false ) || - !aProfile->GetRightPoint( aLastPoint, false ) ) - continue; + if ( anObject->GetKind() == KIND_STREAM ) { + Handle(HYDROData_Stream) aStream = Handle(HYDROData_Stream)::DownCast( anObject ); + if ( aStream.IsNull() ) + return false; - gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), 0 ); - gp_Pnt aPnt2( aLastPoint.X(), aLastPoint.Y(), 0 ); + HYDROData_SequenceOfObjects aStreamProfiles = aStream->GetProfiles(); + if ( aStreamProfiles.Length() < 2 ) + return false; - if ( !aPrevProfile.IsNull() ) + Handle(HYDROData_Profile) aPrevProfile; + gp_Pnt aPrevPnt1, aPrevPnt2; + for ( int i = 1, n = aStreamProfiles.Length(); i <= n; ++i ) { - BRepBuilderAPI_MakeEdge aLeftMakeEdge( aPrevPnt1, aPrevPnt2 ); - BRepBuilderAPI_MakeEdge aBotMakeEdge( aPrevPnt2, aPnt2 ); - BRepBuilderAPI_MakeEdge aRightMakeEdge( aPnt2, aPnt1 ); - BRepBuilderAPI_MakeEdge aTopMakeEdge( aPnt1, aPrevPnt1 ); - - BRepBuilderAPI_MakeWire aMakeWire( aLeftMakeEdge.Edge(), aBotMakeEdge.Edge(), - aRightMakeEdge.Edge(), aTopMakeEdge.Edge() ); - - BRepBuilderAPI_MakeFace aMakeFace( aMakeWire.Wire() ); - - TopoDS_Face aProfilesFace = aMakeFace.Face(); -#ifdef DEB_CLASS2D - TopoDS_Compound aCmp; - BRep_Builder aBB; - aBB.MakeCompound(aCmp); - aBB.Add(aCmp, aProfilesFace); - gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.); - BRepBuilderAPI_MakeVertex aMk(aPnt); - aBB.Add(aCmp, aMk.Vertex()); - BRepTools::Write(aCmp, "ProfileFace.brep"); -#endif - - TopAbs_State aPointState = HYDROData_Tool::ComputePointState(thePoint, aProfilesFace); + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aStreamProfiles.Value( i ) ); + if ( aProfile.IsNull() ) + continue; + + gp_XY aFirstPoint, aLastPoint; + if ( !aProfile->GetLeftPoint( aFirstPoint, false ) || + !aProfile->GetRightPoint( aLastPoint, false ) ) + continue; + + gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), 0 ); + gp_Pnt aPnt2( aLastPoint.X(), aLastPoint.Y(), 0 ); + + if ( !aPrevProfile.IsNull() ) + { + if ( IsPointBetweenEdges( aPrevPnt1, aPrevPnt2, aPnt1, aPnt2, aTestPnt ) ) + { + theLeftWire = TopoDS::Wire( aPrevProfile->GetShape3D() ); + theRightWire = TopoDS::Wire( aProfile->GetShape3D() ); + break; + } + } -#ifdef DEB_CLASS2D - cout << "Point status is = " << aPointState <GetKind() == KIND_CHANNEL ) { + Handle(HYDROData_Channel) aChannel = Handle(HYDROData_Channel)::DownCast( anObject ); + if ( aChannel.IsNull() ) + return false; + + TopTools_ListOfShape aWiresList; + TopExp_Explorer anExp( aChannel->GetShape3D(), TopAbs_WIRE ); + for ( ; anExp.More(); anExp.Next() ) { + if(!anExp.Current().IsNull()) { + const TopoDS_Wire& aWire = TopoDS::Wire( anExp.Current() ); + aWiresList.Append( aWire ); } } - aPrevProfile = aProfile; - aPrevPnt1 = aPnt1; - aPrevPnt2 = aPnt2; + if ( aWiresList.Extent() < 2 ) + return false; + + TopoDS_Wire aPrevWire; + gp_Pnt aPrevPnt1, aPrevPnt2; + + TopTools_ListIteratorOfListOfShape anIt( aWiresList ); + for ( ; anIt.More(); anIt.Next() ) { + TopoDS_Wire& aWire = TopoDS::Wire( anIt.Value() ); + if ( aWire.IsNull() ) + continue; + + TopoDS_Vertex aFirstVertex, aLastVertex; + TopExp::Vertices( aWire, aFirstVertex, aLastVertex ); + + gp_Pnt aPnt1( BRep_Tool::Pnt( aFirstVertex ) ); + aPnt1.SetZ( 0 ); + gp_Pnt aPnt2( BRep_Tool::Pnt( aLastVertex ) ); + aPnt2.SetZ( 0 ); + + if ( !aPrevWire.IsNull() ) { + if ( IsPointBetweenEdges( aPrevPnt1, aPrevPnt2, aPnt1, aPnt2, aTestPnt ) ) { + theLeftWire = aPrevWire; + theRightWire = aWire; + break; + } + } + + aPrevWire = aWire; + aPrevPnt1 = aPnt1; + aPrevPnt2 = aPnt2; + } } - return !theLeftProfile.IsNull() && !theRightProfile.IsNull(); + return !theLeftWire.IsNull() && !theRightWire.IsNull(); } double HYDROData_StreamAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) const { double aResAltitude = GetInvalidAltitude(); - Handle(HYDROData_Stream) aStream = - Handle(HYDROData_Stream)::DownCast( GetFatherObject() ); - if ( aStream.IsNull() ) + Handle(HYDROData_Object) anObject = + Handle(HYDROData_Object)::DownCast( GetFatherObject() ); + if ( anObject.IsNull() ) return aResAltitude; - - TopoDS_Shape aStreamShape = aStream->GetTopShape(); - if ( aStreamShape.IsNull() ) + + TopoDS_Shape aTopShape = anObject->GetTopShape(); + if ( aTopShape.IsNull() ) return aResAltitude; - TopExp_Explorer aStreamFaceExp( aStreamShape, TopAbs_FACE ); - if ( !aStreamFaceExp.More() ) + TopExp_Explorer aFaceExp( aTopShape, TopAbs_FACE ); + if ( !aFaceExp.More() ) return aResAltitude; // Get only face because of 2d profile wires is in compound - TopoDS_Face aStreamFace = TopoDS::Face( aStreamFaceExp.Current() ); + TopoDS_Face aFace = TopoDS::Face( aFaceExp.Current() ); - // Check if point is inside of stream presentation - TopAbs_State aPointState = HYDROData_Tool::ComputePointState(thePoint, aStreamFace); + // Check if point is inside of stream/channel presentation + TopAbs_State aPointState = HYDROData_Tool::ComputePointState(thePoint, aFace); #ifdef DEB_CLASS2D cout << "Point status is = " << aPointState <GetKind() == KIND_STREAM ) { + Handle(HYDROData_Stream) aStream = + Handle(HYDROData_Stream)::DownCast( GetFatherObject() ); + if ( !aStream.IsNull() ) { + aLeftEdge = TopoDS::Edge( aStream->GetLeftShape() ); + aRightEdge = TopoDS::Edge( aStream->GetRightShape() ); + } + } else if ( anObject->GetKind() == KIND_CHANNEL ) { + Handle(HYDROData_Channel) aChannel = + Handle(HYDROData_Channel)::DownCast( GetFatherObject() ); + if ( !aChannel.IsNull() ) { + aLeftEdge = TopoDS::Edge( aChannel->GetLeftShape() ); + aRightEdge = TopoDS::Edge( aChannel->GetRightShape() ); + } + } + // Find the two profiles between which the point is lies - Handle(HYDROData_Profile) aLeftProfile, aRightProfile; - if ( !getBoundaryProfilesForPoint( thePoint, aLeftProfile, aRightProfile ) ) - return aResAltitude; + TopoDS_Wire aLeftWire, aRightWire; + if ( !getBoundaryWiresForPoint( thePoint, aLeftWire, aRightWire ) ) + 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 ); + Handle(Geom_Curve) anEdgeLeftCurve = BRep_Tool::Curve( aLeftEdge, aFirst, aLast ); + Handle(Geom_Curve) anEdgeRightCurve = BRep_Tool::Curve( aRightEdge, aFirst, aLast ); GeomAPI_ProjectPointOnCurve aLeftProject( aPointToTest, anEdgeLeftCurve ); GeomAPI_ProjectPointOnCurve aRightProject( aPointToTest, anEdgeRightCurve ); + int aNbPoints1 = aRightProject.NbPoints(); + int aNbPoints2 = aLeftProject.NbPoints(); + if ( aNbPoints1 < 1 || aNbPoints2 < 1) + return aResAltitude; 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 ); + Standard_Real aLeftAlt, aRightAlt; + gp_Pnt aLeftProfileP1, aLeftProfileP2, aRightProfileP1, aRightProfileP2; + aLeftAlt = getAltitudeFromWire( aLeftWire, aLeftDist, aRightDist ); + aRightAlt = getAltitudeFromWire( aRightWire, aLeftDist, aRightDist ); + + TopoDS_Vertex aFirstVertex, aLastVertex; + TopExp::Vertices( aLeftWire, aFirstVertex, aLastVertex ); + aLeftProfileP1 = BRep_Tool::Pnt( aFirstVertex ); + aLeftProfileP2 = BRep_Tool::Pnt( aLastVertex ); + + TopExp::Vertices( aRightWire, aFirstVertex, aLastVertex ); + aRightProfileP1 = BRep_Tool::Pnt( aFirstVertex ); + aRightProfileP2 = BRep_Tool::Pnt( aLastVertex ); // 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 ) ); diff --git a/src/HYDROData/HYDROData_StreamAltitude.h b/src/HYDROData/HYDROData_StreamAltitude.h index 5cb6cc21..02cbc308 100644 --- a/src/HYDROData/HYDROData_StreamAltitude.h +++ b/src/HYDROData/HYDROData_StreamAltitude.h @@ -22,10 +22,10 @@ #include "HYDROData_IAltitudeObject.h" -class Handle(HYDROData_Profile); DEFINE_STANDARD_HANDLE(HYDROData_StreamAltitude, HYDROData_IAltitudeObject) +class TopoDS_Wire; /**\class HYDROData_StreamAltitude * \brief Class that stores/retreives information about the stream altitude. @@ -65,9 +65,9 @@ public: protected: - bool getBoundaryProfilesForPoint( const gp_XY& thePoint, - Handle(HYDROData_Profile)& theLeftProfile, - Handle(HYDROData_Profile)& theRightProfile ) const; + bool getBoundaryWiresForPoint( const gp_XY& thePoint, + TopoDS_Wire& theLeftWire, + TopoDS_Wire& theRightWire ) const; protected: diff --git a/src/HYDROData/HYDROData_Tool.cxx b/src/HYDROData/HYDROData_Tool.cxx index b7d734df..c30bff5e 100644 --- a/src/HYDROData/HYDROData_Tool.cxx +++ b/src/HYDROData/HYDROData_Tool.cxx @@ -22,6 +22,7 @@ #include "HYDROData_Image.h" #include "HYDROData_Iterator.h" #include "HYDROData_NaturalObject.h" +#include "HYDROData_ShapesGroup.h" #include #include @@ -220,7 +221,7 @@ double HYDROData_Tool::GetAltitudeForEdge( const TopoDS_Edge& theEdge, gp_Pnt2d aLastPnt2d( aLastPnt.X(), aLastPnt.Y() ); double aFirstDist = 0; - double aLastDist = aFirstPnt2d.SquareDistance( thePoint ); + double aLastDist = aFirstPnt2d.SquareDistance( aLastPnt2d ); double aNecDist = aFirstPnt2d.SquareDistance( thePoint ); while( fabs( aLast - aFirst ) > theParameterTolerance ) @@ -230,7 +231,7 @@ double HYDROData_Tool::GetAltitudeForEdge( const TopoDS_Edge& theEdge, aCurve->D0( aMid, aMidPnt ); double aDist = aFirstPnt2d.SquareDistance( gp_Pnt2d( aMidPnt.X(), aMidPnt.Y() ) ); - if( aDist > aNecDist ) + if( aDist < aNecDist ) aFirst = aMid; else aLast = aMid; @@ -263,3 +264,24 @@ double HYDROData_Tool::GetAltitudeForWire( const TopoDS_Wire& theWire, } return theInvalidAltitude; } + +TopoDS_Shape HYDROData_Tool::getFirstShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups, + const int theGroupId ) +{ + TopoDS_Shape aResShape; + if ( theGroupId < 1 || theGroupId > theGroups.Length() ) + return aResShape; + + Handle(HYDROData_ShapesGroup) aGroup = + Handle(HYDROData_ShapesGroup)::DownCast( theGroups.Value( theGroupId ) ); + if ( aGroup.IsNull() ) + return aResShape; + + TopTools_SequenceOfShape aGroupShapes; + aGroup->GetShapes( aGroupShapes ); + + if ( !aGroupShapes.IsEmpty() ) + aResShape = aGroupShapes.First(); + + return aResShape; +} \ No newline at end of file diff --git a/src/HYDROData/HYDROData_Tool.h b/src/HYDROData/HYDROData_Tool.h index a3b129ec..4bb77866 100644 --- a/src/HYDROData/HYDROData_Tool.h +++ b/src/HYDROData/HYDROData_Tool.h @@ -108,6 +108,14 @@ public: double theParameterTolerance, double theSquareDistanceTolerance, double theInvalidAltitude ); + + /** + * \brief Returns the first shape from the group. + * \param theGroups the list of groups + * \param theGroupId the group id + */ + static TopoDS_Shape getFirstShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups, + const int theGroupId ); }; inline bool ValuesEquals( const double& theFirst, const double& theSecond )