2 #include <HYDROData_DTM.h>
3 #include <HYDROData_Profile.h>
5 #include <Geom2d_BSplineCurve.hxx>
6 #include <Geom2dAPI_Interpolate.hxx>
7 #include <TColgp_HArray1OfPnt2d.hxx>
8 #include <TColgp_Array1OfVec2d.hxx>
9 #include <TColStd_HArray1OfBoolean.hxx>
11 #include <TopoDS_Edge.hxx>
12 #include <TopoDS_Wire.hxx>
13 #include <TopExp_Explorer.hxx>
14 #include <BRep_Tool.hxx>
16 #include <Geom_Line.hxx>
17 #include <Geom2d_Line.hxx>
18 #include <Geom2d_TrimmedCurve.hxx>
19 #include <Geom_BSplineCurve.hxx>
20 #include <Geom2d_BSplineCurve.hxx>
21 #include <TColStd_Array1OfReal.hxx>
22 #include <TColStd_Array1OfInteger.hxx>
23 #include <TColgp_Array1OfPnt.hxx>
25 IMPLEMENT_STANDARD_HANDLE( HYDROData_DTM, HYDROData_Bathymetry )
26 IMPLEMENT_STANDARD_RTTIEXT( HYDROData_DTM, HYDROData_Bathymetry )
28 HYDROData_DTM::HYDROData_DTM()
32 HYDROData_DTM::~HYDROData_DTM()
37 void GetProperties( const Handle_HYDROData_Profile& theProfile,
38 gp_Pnt& theLowestPoint,
42 theLowestPoint = theProfile->GetBottomPoint();
45 theProfile->GetLeftPoint( aLeft, true, true );
46 theProfile->GetRightPoint( aRight, true, true );
47 double x = aRight.X()-aLeft.X();
48 double y = aRight.Y()-aLeft.Y();
50 theDir = gp_Vec2d( -y, x );
52 theDir = gp_Vec2d( x, y );
55 inline gp_Pnt2d To2D( const gp_Pnt& thePnt, const gp_Trsf& theTr )
57 gp_Pnt p = thePnt.Transformed( theTr );
58 return gp_Pnt2d( p.X(), p.Z() );
61 Handle(TColgp_HArray1OfPnt2d) To2D( const TColgp_Array1OfPnt& thePoints, const gp_Trsf& theTr )
63 int low = thePoints.Lower(), up = thePoints.Upper();
64 Handle(TColgp_HArray1OfPnt2d) points = new TColgp_HArray1OfPnt2d( low, up );
65 for( int i=low; i<=up; i++ )
66 points->SetValue( i, To2D( thePoints.Value( i ), theTr ) );
70 Handle(Geom2d_Curve) CurveTo2D( const Handle(Geom_Curve)& theCurve,
71 Standard_Real theFirst, Standard_Real theLast,
72 const gp_Trsf& theTr )
74 if( theCurve->IsKind( STANDARD_TYPE( Geom_Line ) ) )
76 gp_Pnt aFirstPnt, aLastPnt;
77 theCurve->D0( theFirst, aFirstPnt );
78 theCurve->D0( theLast, aLastPnt );
81 aFirst2d = To2D( aFirstPnt, theTr ),
82 aLast2d = To2D( aLastPnt, theTr );
84 gp_Vec2d dir( aFirst2d, aLast2d );
85 Handle_Geom2d_Line aLine2d = new Geom2d_Line( aFirst2d, gp_Dir2d( dir.X(), dir.Y() ) );
86 return new Geom2d_TrimmedCurve( aLine2d, 0, aLast2d.Distance( aFirst2d ) );
89 if( theCurve->IsKind( STANDARD_TYPE( Geom_BSplineCurve ) ) )
91 Handle(Geom_BSplineCurve) aSpline = Handle(Geom_BSplineCurve)::DownCast( theCurve );
93 Handle(TColgp_HArray1OfPnt2d) poles = To2D( aSpline->Poles(), theTr );
94 const TColStd_Array1OfReal& knots = aSpline->Knots();
95 const TColStd_Array1OfInteger& multiplicities = aSpline->Multiplicities();
96 int aDegree = aSpline->Degree();
98 return new Geom2d_BSplineCurve( poles->Array1(), knots, multiplicities, aDegree );
101 return Handle(Geom2d_Curve)();
104 Handle_Geom2d_BSplineCurve HYDROData_DTM::CreateHydraulicAxis(
105 const std::vector<Handle_HYDROData_Profile>& theProfiles )
107 size_t n = theProfiles.size();
108 Handle_Geom2d_BSplineCurve aResult;
110 Handle(TColgp_HArray1OfPnt2d) points = new TColgp_HArray1OfPnt2d( 1, (int)n );
111 TColgp_Array1OfVec2d tangents( 1, (int)n );
112 Handle(TColStd_HArray1OfBoolean) flags = new TColStd_HArray1OfBoolean( 1, (int)n );
114 for( size_t i = 1; i <= n; i++ )
116 Handle_HYDROData_Profile aProfile = theProfiles[i-1];
119 GetProperties( aProfile, aLowest, aTangent, true );
120 aTangent.Normalize();
122 points->SetValue( (int)i, gp_Pnt2d( aLowest.X(), aLowest.Y() ) );
123 tangents.SetValue( (int)i, aTangent );
124 flags->SetValue( (int)i, Standard_True );
127 Geom2dAPI_Interpolate anInterpolator( points, Standard_False, Standard_False );
128 anInterpolator.Load( tangents, flags );
129 anInterpolator.Perform();
130 if( anInterpolator.IsDone() )
131 aResult = anInterpolator.Curve();
135 std::vector<Handle_Geom2d_Curve> HYDROData_DTM::ProfileToParametric( const Handle_HYDROData_Profile& theProfile )
137 std::vector<Handle_Geom2d_Curve> curves;
138 theProfile->Update();
140 // Transformation of the coordinate systems
143 GetProperties( theProfile, aLowest, aDir, false );
145 gp_Ax3 aStd3d( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ), gp_Dir( 1, 0, 0 ) );
146 gp_Ax3 aLocal( aLowest, gp_Dir( 0, 0, 1 ), gp_Dir( aDir.X(), aDir.Y(), 0 ) );
149 aTransf.SetTransformation( aStd3d, aLocal );
151 // Iteration via edges
152 TopoDS_Wire aWire = TopoDS::Wire( theProfile->GetShape3D() );
153 TopExp_Explorer anExp( aWire, TopAbs_EDGE );
154 for( ; anExp.More(); anExp.Next() )
156 // Extract an edge from wire
157 TopoDS_Edge anEdge = TopoDS::Edge( anExp.Current() );
159 // Extract a curve corresponding to the edge
160 TopLoc_Location aLoc;
161 Standard_Real aFirst, aLast;
162 Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aLoc, aFirst, aLast );
164 // Convert the curve to 2d CS
165 Handle(Geom2d_Curve) aCurve2d = CurveTo2D( aCurve, aFirst, aLast, aTransf );
166 if( !aCurve2d.IsNull() )
167 curves.push_back( aCurve2d );
172 void HYDROData_DTM::ProfileDiscretization( const Handle_HYDROData_Profile& theProfile,
173 double theMinZ, double theMaxZ, double theDDZ,
174 CurveUZ& theMidPointCurve,
175 CurveUZ& theWidthCurve )
177 /*for( double z = theMinZ; z<=theMaxZ; z += theDDZ )
183 void HYDROData_DTM::Interpolate( const CurveUZ& theCurveA, const CurveUZ& theCurveB,
184 int theNbSteps, std::vector<CurveUZ>& theInterpolation )
188 void HYDROData_DTM::CurveTo3d( const CurveUZ& theCurve, const CurveUZ& theCurveB,
189 int theNbSteps, std::vector<CurveUZ>& theInterpolation )