Salome HOME
refs #1094
[modules/hydro.git] / src / HYDROData / HYDROData_DTM.h
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 #ifndef HYDROData_DTM_HeaderFile
20 #define HYDROData_DTM_HeaderFile
21
22 #include "HYDROData_Bathymetry.h"
23 #include <vector>
24 #include <set>
25 #include <gp_Pnt2d.hxx>
26
27 class Handle_HYDROData_Profile;
28 class Handle_Geom2d_BSplineCurve;
29 class Handle_Geom2d_Curve;
30 class gp_Pnt;
31 class gp_Vec2d;
32 class TopoDS_Edge;
33 class TopoDS_Wire;
34 class TopoDS_Face;
35 class TopoDS_Compound;
36 class Handle_Geom_Plane;
37 class TopTools_IndexedMapOfOrientedShape;
38 class TopTools_DataMapOfShapeListOfShape;
39 class TopTools_SequenceOfShape;
40
41 DEFINE_STANDARD_HANDLE( HYDROData_DTM, HYDROData_Bathymetry )
42
43 /**\class HYDROData_DTM
44  * \brief Class that represents the Digital Terrain Model
45  */
46 class HYDROData_DTM : public HYDROData_Bathymetry
47 {
48 protected:
49   /**
50    * Enumeration of tags corresponding to the persistent object parameters.
51    */
52   enum DataTag
53   {
54     DataTag_First = HYDROData_Bathymetry::DataTag_First + 100, ///< first tag, to reserve
55     DataTag_Profiles,
56     DataTag_DDZ,
57     DataTag_SpatialStep,
58     DataTag_LeftBankShape,
59     DataTag_RightBankShape,
60     DataTag_InletShape,
61     DataTag_OutletShape,
62     DataTag_3DShape,
63     DataTag_2DShape
64   };
65
66 public:
67   DEFINE_STANDARD_RTTI( HYDROData_DTM );
68
69   HYDRODATA_EXPORT HYDROData_SequenceOfObjects GetProfiles() const;
70   HYDRODATA_EXPORT void SetProfiles( const HYDROData_SequenceOfObjects& );
71
72   HYDRODATA_EXPORT double GetDDZ() const;
73   HYDRODATA_EXPORT void SetDDZ( double );
74
75   HYDRODATA_EXPORT double GetSpatialStep() const;
76   HYDRODATA_EXPORT void SetSpatialStep( double );
77
78   HYDRODATA_EXPORT virtual void Update();
79
80 public:
81   struct PointUZ
82   {
83     PointUZ( double u=0, double z=0 ) { U=u; Z=z; }
84     double U;
85     double Z;
86   };
87   class CurveUZ : public std::vector<PointUZ>
88   {
89   public:
90     CurveUZ( double theXcurv, const gp_Vec2d& theProfileDir, double theDeltaZ );
91     ~CurveUZ();
92
93     double Xcurv() const;
94     gp_Vec2d ProfileDir() const;
95     double DeltaZ() const;
96
97     CurveUZ operator + ( const CurveUZ& ) const;
98     CurveUZ operator * ( double ) const;
99
100   private:
101     double myXcurv;
102     gp_Vec2d myProfileDir;
103     double myDeltaZ;
104   };
105
106 protected:
107   friend class HYDROData_Stream;
108   friend class HYDROData_Iterator;
109   friend class test_HYDROData_DTM;
110
111   HYDRODATA_EXPORT HYDROData_DTM();
112   virtual HYDRODATA_EXPORT ~HYDROData_DTM();
113
114   static Handle_Geom2d_BSplineCurve CreateHydraulicAxis( 
115     const std::vector<Handle_HYDROData_Profile>& theProfiles,
116     std::vector<double>& theDistances );
117
118   static std::vector<Handle_Geom2d_Curve> ProfileToParametric( const Handle_HYDROData_Profile& theProfile,
119                                                                double& theUMin, double& theUMax,
120                                                                gp_Vec2d& theDir );
121
122   static void GetProperties( const Handle_HYDROData_Profile& theProfile,
123                              gp_Pnt& theLowestPoint, gp_Vec2d& theDir,
124                              double& theZMin, double& theZMax );
125
126   static void ProfileDiscretization( const Handle_HYDROData_Profile& theProfile,
127                                      double theXCurv, double theMinZ, double theMaxZ, double theDDZ,
128                                      CurveUZ& theMidPointCurve,
129                                      CurveUZ& theWidthCurve,
130                                      int& intersection_nb,
131                                      double theTolerance = 1E-6 );
132
133   static void CurveTo3D( const Handle_Geom2d_BSplineCurve& theHydraulicAxis,
134                          const CurveUZ& theMidCurve, const CurveUZ& theWidthCurve,
135                          AltitudePoints& thePoints );
136   
137   static void Interpolate( const CurveUZ& theCurveA, const CurveUZ& theCurveB, 
138                            int theNbSteps, std::vector<CurveUZ>& theInterpolation,
139                            bool isAddSecond );
140
141   static std::vector<AltitudePoints> Interpolate
142     ( const Handle_Geom2d_BSplineCurve& theHydraulicAxis,
143       const Handle_HYDROData_Profile& theProfileA,
144       double theXCurvA,
145       const Handle_HYDROData_Profile& theProfileB,
146       double theXCurvB,
147       double theDDZ, int theNbSteps, bool isAddSecond,
148       int& inter_nb_1, int& inter_nb_2 );
149
150   static AltitudePoints Interpolate( const std::vector<Handle_HYDROData_Profile>& theProfiles,
151                                      double theDDZ, double theSpatialStep,
152                                      AltitudePoints& theLeft,
153                                      AltitudePoints& theRight,
154                                      std::vector<AltitudePoints>& theMainProfiles,
155                                      std::set<int>& invalInd );
156
157   static void PointsToWire(const AltitudePoints& pnts, TopoDS_Wire& W );
158
159   static void PointsToEdge(const AltitudePoints& pnts, TopoDS_Edge& E );
160
161   //static void ProjWireOnPlane(const TopoDS_Shape& inpWire, const Handle_Geom_Plane& RefPlane,
162     //TopTools_DataMapOfShapeListOfShape* E2PE);
163
164   static bool GetPlanarFaceFromBanks(const TopoDS_Edge& LB, const TopoDS_Edge& RB, TopoDS_Face& outF,
165     TopTools_SequenceOfShape* Boundr);
166
167   static TopTools_IndexedMapOfOrientedShape Create3DShape(const AltitudePoints& left,
168                                                           const AltitudePoints& right,
169                                                           const std::vector<AltitudePoints>& main_profiles);
170
171   static void CreateProfiles(const std::vector<Handle_HYDROData_Profile>& theProfiles,
172                              double theDDZ,
173                              double theSpatialStep,
174                              AltitudePoints& theOutLeft,
175                              AltitudePoints& theOutRight,
176                              AltitudePoints& theOutPoints,
177                              std::vector<AltitudePoints>& theOutMainProfiles,
178                              TopoDS_Shape& Out3dPres,
179                              TopoDS_Shape& Out2dPres,
180                              TopoDS_Shape& OutLeftB,
181                              TopoDS_Shape& OutRightB,
182                              TopoDS_Shape& OutInlet,
183                              TopoDS_Shape& OutOutlet,
184                              bool Create3dPres,
185                              bool Create2dPres,
186                              std::set<int>& InvInd,
187                              bool& ProjStat);
188
189   //static bool Get2dFaceFrom3dPres(const TopoDS_Compound& cmp, TopoDS_Face& outF, 
190     //TopTools_SequenceOfShape* Boundr = NULL, std::set<int> ind = std::set<int>() );
191   
192   static int EstimateNbPoints( const std::vector<Handle_HYDROData_Profile>& theProfiles,
193                                double theDDZ, double theSpatialStep );
194
195   void GetPresentationShapes( TopoDS_Shape& Out3dPres,
196                               TopoDS_Shape& Out2dPres,
197                               TopoDS_Shape& OutLeftB,
198                               TopoDS_Shape& OutRightB,
199                               TopoDS_Shape& OutInlet,
200                               TopoDS_Shape& OutOutlet );
201 public:
202
203   HYDRODATA_EXPORT static void CreateProfilesFromDTM ( const HYDROData_SequenceOfObjects& InpProfiles,
204                                                        double ddz,
205                                                        double step, 
206                                                        AltitudePoints& points,
207                                                        TopoDS_Shape& Out3dPres,
208                                                        TopoDS_Shape& Out2dPres,
209                                                        TopoDS_Shape& OutLeftB,
210                                                        TopoDS_Shape& OutRightB,
211                                                        TopoDS_Shape& OutInlet,
212                                                        TopoDS_Shape& OutOutlet,
213                                                        bool Create3dPres,
214                                                        bool Create2dPres,
215                                                        std::set<int>& InvInd,
216                                                        int thePntsLimit,
217                                                        bool& WireIntersections);
218 };
219
220
221
222
223 #endif