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