Salome HOME
fix test on stream linear interpolation
[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 //#define _DEVDEBUG_
26 #include "HYDRO_trace.hxx"
27 #include <QString>
28
29 #include <Precision.hxx>
30
31 #include <TopoDS_Shape.hxx>
32 #include <BRepTools.hxx>
33
34 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ObstacleAltitude, HYDROData_IAltitudeObject)
35
36 HYDROData_ObstacleAltitude::HYDROData_ObstacleAltitude()
37 : HYDROData_IAltitudeObject()
38 {
39 }
40
41 HYDROData_ObstacleAltitude::~HYDROData_ObstacleAltitude()
42 {
43 }
44
45 double HYDROData_ObstacleAltitude::GetAltitudeForPoint( const gp_XY& thePoint,
46                                                         int theMethod) const
47 {
48   DEBTRACE("HYDROData_ObstacleAltitude::GetAltitudeForPoint");
49   double aResAltitude = GetInvalidAltitude();
50
51   Handle(HYDROData_Object) anObject =
52     Handle(HYDROData_Object)::DownCast( GetFatherObject() );
53   if ( anObject.IsNull() )
54   {
55         DEBTRACE("anObject.IsNull()");
56     return aResAltitude;
57   }
58 //  DEBTRACE("object: " << anObject->GetName().toStdString());
59
60   TopoDS_Shape anObjectShape3D = anObject->GetShape3D();
61   if ( anObjectShape3D.IsNull() )
62   {
63         DEBTRACE("anObjectShape3D.IsNull()");
64     return aResAltitude;
65   }
66 //  else
67 //  {
68 //      DEBTRACE("anObjectShape3D type " << anObjectShape3D.ShapeType());
69 //      BRepTools::Write(anObjectShape3D, "digue3D.brep");
70 //  }
71
72   HYDROData_Make3dMesh aMesher3D( anObjectShape3D, Precision::Intersection() );
73
74   gp_Pnt aHighestPoint;
75   if ( aMesher3D.GetHighestOriginal( thePoint.X(), thePoint.Y(), aHighestPoint ) )
76     aResAltitude = aHighestPoint.Z();
77   DEBTRACE("aResAltitude=" << aResAltitude);
78   return aResAltitude;
79 }
80
81
82
83