Salome HOME
Merge remote-tracking branch 'origin/BR_SHAPE_RECOGNITION' into BR_v14_rc
[modules/hydro.git] / src / HYDROData / HYDROData_ObstacleAltitude.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROData_ObstacleAltitude.h"
20
21 #include "HYDROData_Document.h"
22 #include "HYDROData_Object.h"
23 #include "HYDROData_Projection.h"
24
25 #include <Precision.hxx>
26
27 #include <TopoDS_Shape.hxx>
28
29 IMPLEMENT_STANDARD_HANDLE(HYDROData_ObstacleAltitude, HYDROData_IAltitudeObject)
30 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ObstacleAltitude, HYDROData_IAltitudeObject)
31
32 HYDROData_ObstacleAltitude::HYDROData_ObstacleAltitude()
33 : HYDROData_IAltitudeObject()
34 {
35 }
36
37 HYDROData_ObstacleAltitude::~HYDROData_ObstacleAltitude()
38 {
39 }
40
41 double HYDROData_ObstacleAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) const
42 {
43   double aResAltitude = GetInvalidAltitude();
44
45   Handle(HYDROData_Object) anObject =
46     Handle(HYDROData_Object)::DownCast( GetFatherObject() );
47   if ( anObject.IsNull() )
48     return aResAltitude;
49
50   TopoDS_Shape anObjectShape3D = anObject->GetShape3D();
51   if ( anObjectShape3D.IsNull() )
52     return aResAltitude;
53
54   HYDROData_Make3dMesh aMesher3D( anObjectShape3D, Precision::Intersection() );
55
56   gp_Pnt aHighestPoint;
57   if ( aMesher3D.GetHighestOriginal( thePoint.X(), thePoint.Y(), aHighestPoint ) )
58     aResAltitude = aHighestPoint.Z();
59
60   return aResAltitude;
61 }
62
63
64
65