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 <GeomAPI_Interpolate.hxx>
22 #include <TColStd_Array1OfReal.hxx>
23 #include <TColStd_Array1OfInteger.hxx>
24 #include <TColgp_Array1OfPnt.hxx>
25 #include <TColgp_Array1OfVec.hxx>
26 #include <TColgp_HArray1OfPnt.hxx>
27 #include <Geom2dAPI_InterCurveCurve.hxx>
28 #include <Geom2dAPI_ProjectPointOnCurve.hxx>
29 #include <Geom2dAdaptor_Curve.hxx>
30 #include <GCPnts_AbscissaPoint.hxx>
31 #include <BRepBuilderAPI_MakeEdge.hxx>
34 #include <BRepLib_MakeEdge.hxx>
35 #include <BRepLib_MakeWire.hxx>
36 #include <BRep_Builder.hxx>
37 #include <GeomProjLib.hxx>
38 #include <Geom_TrimmedCurve.hxx>
39 #include <Geom_Plane.hxx>
40 #include <BRepTools_WireExplorer.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
42 #include <BRepBuilderAPI_MakeFace.hxx>
44 #include <TopTools_IndexedMapOfOrientedShape.hxx>
46 #include <BRepLib_MakeEdge.hxx>
47 #include <BRepLib_MakeWire.hxx>
48 #include <BRep_Builder.hxx>
52 IMPLEMENT_STANDARD_HANDLE( HYDROData_DTM, HYDROData_Bathymetry )
53 IMPLEMENT_STANDARD_RTTIEXT( HYDROData_DTM, HYDROData_Bathymetry )
56 HYDROData_DTM::CurveUZ::CurveUZ( double theXCurv, const gp_Vec2d& theProfileDir )
57 : myXcurv( theXCurv ), myProfileDir( theProfileDir )
61 HYDROData_DTM::CurveUZ::~CurveUZ()
65 double HYDROData_DTM::CurveUZ::Xcurv() const
70 gp_Vec2d HYDROData_DTM::CurveUZ::ProfileDir() const
75 HYDROData_DTM::CurveUZ HYDROData_DTM::CurveUZ::operator + ( const CurveUZ& c ) const
77 HYDROData_DTM::CurveUZ res( Xcurv() + c.Xcurv(), ProfileDir() + c.ProfileDir() );
80 for( int i=0; i<n; i++ )
83 p.U = operator[]( i ).U + c[i].U;
84 p.Z = operator[]( i ).Z;
90 HYDROData_DTM::CurveUZ HYDROData_DTM::CurveUZ::operator * ( double d ) const
92 HYDROData_DTM::CurveUZ res( Xcurv()*d, ProfileDir()*d );
95 for( int i=0; i<n; i++ )
98 p.U = operator[]( i ).U * d;
99 p.Z = operator[]( i ).Z;
108 HYDROData_DTM::HYDROData_DTM()
112 HYDROData_DTM::~HYDROData_DTM()
116 HYDROData_SequenceOfObjects HYDROData_DTM::GetProfiles() const
118 return GetReferenceObjects( DataTag_Profiles );
121 void HYDROData_DTM::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles )
123 SetReferenceObjects( theProfiles, DataTag_Profiles );
126 double HYDROData_DTM::GetDDZ() const
128 return GetDouble( DataTag_DDZ );
131 void HYDROData_DTM::SetDDZ( double theDDZ )
133 SetDouble( DataTag_DDZ, theDDZ );
136 double HYDROData_DTM::GetSpatialStep() const
138 return GetDouble( DataTag_SpatialStep );
141 void HYDROData_DTM::SetSpatialStep( double theSpatialStep )
143 SetDouble( DataTag_SpatialStep, theSpatialStep );
146 void HYDROData_DTM::PointToWire(const AltitudePoints& pnts, TopoDS_Wire& W )
151 for (int i = 0; i < pnts.size() - 1; i++)
153 gp_Pnt p1(pnts[i].X, pnts[i].Y, pnts[i].Z);
154 gp_Pnt p2(pnts[i+1].X, pnts[i+1].Y, pnts[i+1].Z);
155 WM.Add(BRepLib_MakeEdge(p1, p2).Edge());
161 TopTools_IndexedMapOfOrientedShape HYDROData_DTM::Create3DShape(const AltitudePoints& left,
162 const AltitudePoints& right,
163 const std::vector<AltitudePoints>& main_profiles)
165 TopTools_IndexedMapOfOrientedShape ll;
166 TopoDS_Wire LWire, RWire;
167 PointToWire(left, LWire);
168 PointToWire(right, RWire);
170 ll.Add(LWire.Oriented(TopAbs_FORWARD));
172 for (int k = 0; k < main_profiles.size(); k++)
175 PointToWire(main_profiles[k], W);
176 TopAbs_Orientation Ori = TopAbs_INTERNAL;
177 if (k == 0 || k == main_profiles.size() - 1)
178 Ori = TopAbs_FORWARD;
179 ll.Add(W.Oriented(Ori));
183 ll.Add(RWire.Oriented(TopAbs_FORWARD));
184 //yes, add subshapes in this order (left + profiles + right)
185 //otherwise the projected wire will be non-manifold
191 void HYDROData_DTM::Update()
193 AltitudePoints points;
194 TopoDS_Shape Out3dPres;
195 TopoDS_Shape Out2dPres;
196 TopoDS_Shape OutLeftB;
197 TopoDS_Shape OutRightB;
198 TopoDS_Shape OutInlet;
199 TopoDS_Shape OutOutlet;
201 HYDROData_SequenceOfObjects objs = GetProfiles();
202 double ddz = GetDDZ();
203 double step = GetSpatialStep();
204 std::set<int> InvInd;
205 CreateProfilesFromDTM( objs, ddz, step, points, Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet, true, true, InvInd, -1 );
206 SetAltitudePoints( points );
208 SetShape( DataTag_LeftBankShape, OutLeftB);
209 SetShape( DataTag_RightBankShape, OutRightB);
210 SetShape( DataTag_InletShape, OutInlet);
211 SetShape( DataTag_OutletShape, OutOutlet );
212 SetShape( DataTag_3DShape, Out3dPres );
213 SetShape( DataTag_2DShape, Out2dPres );
215 HYDROData_Bathymetry::Update();
218 void HYDROData_DTM::GetPresentationShapes( TopoDS_Shape& Out3dPres,
219 TopoDS_Shape& Out2dPres,
220 TopoDS_Shape& OutLeftB,
221 TopoDS_Shape& OutRightB,
222 TopoDS_Shape& OutInlet,
223 TopoDS_Shape& OutOutlet )
226 OutLeftB = GetShape( DataTag_LeftBankShape);
227 OutRightB = GetShape( DataTag_RightBankShape);
228 OutInlet = GetShape( DataTag_InletShape);
229 OutOutlet = GetShape( DataTag_OutletShape );
230 Out3dPres = GetShape( DataTag_3DShape );
231 Out2dPres = GetShape( DataTag_2DShape );
234 void HYDROData_DTM::CreateProfilesFromDTM (const HYDROData_SequenceOfObjects& InpProfiles,
237 AltitudePoints& points,
238 TopoDS_Shape& Out3dPres,
239 TopoDS_Shape& Out2dPres,
240 TopoDS_Shape& OutLeftB,
241 TopoDS_Shape& OutRightB,
242 TopoDS_Shape& OutInlet,
243 TopoDS_Shape& OutOutlet,
246 std::set<int>& InvInd,
249 int aLower = InpProfiles.Lower(), anUpper = InpProfiles.Upper();
250 size_t n = anUpper - aLower + 1;
252 std::vector<Handle_HYDROData_Profile> profiles;
253 profiles.reserve( n );
254 for( int i=aLower; i<=anUpper; i++ )
256 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( InpProfiles.Value( i ) );
257 if( !aProfile.IsNull() )
258 profiles.push_back( aProfile );
260 const double EPS = 1E-3;
262 AltitudePoints right;
263 std::vector<AltitudePoints> main_profiles;
265 if( thePntsLimit > 0 )
267 int aNbPoints = EstimateNbPoints( profiles, ddz, step );
268 if( aNbPoints < 0 || aNbPoints > thePntsLimit )
272 if( ddz>EPS && step>EPS )
273 CreateProfiles(profiles, ddz, step, left, right, points, main_profiles,
274 Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet, Create3dPres, Create2dPres, InvInd );
277 void HYDROData_DTM::ProjWireOnPlane(const TopoDS_Wire& inpWire, const Handle_Geom_Plane& RefPlane, TopoDS_Wire& outWire)
279 //its also possible to use BrepAlgo_NormalProjection here!
280 BRepTools_WireExplorer ex(TopoDS::Wire(inpWire.Oriented(TopAbs_FORWARD)));
282 for (;ex.More();ex.Next())
284 const TopoDS_Edge& CE = ex.Current();
286 Handle(Geom_Curve) C3d = BRep_Tool::Curve(CE, f, l);
287 Handle(Geom_Curve) ProjectedCurve = GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3d, f, l), RefPlane, RefPlane->Position().Direction(), Standard_True);
288 TopoDS_Edge ProjEdge = BRepLib_MakeEdge(ProjectedCurve);
289 WM.Add(ProjEdge); //auto sharing between edges if vertex is coincident
292 outWire.Orientation(inpWire.Orientation()); //take from the original wire
296 void HYDROData_DTM::Get2dFaceFrom3dPres(const TopoDS_Compound& cmp, TopoDS_Face& outF )
298 Handle_Geom_Plane refpl = new Geom_Plane(gp_Pnt(0,0,0), gp_Dir(0,0,1));
300 TopoDS_Iterator it(cmp);
301 //TopTools_IndexedMapOfShape IntW;
302 for (;it.More(); it.Next())
304 const TopoDS_Wire& W = TopoDS::Wire(it.Value());
305 if (W.Orientation() != TopAbs_INTERNAL)
307 //use list of edges to protect againts non-manifold cases.
308 //auto sharing between edges will be added automatically
309 TopTools_IndexedMapOfShape ME;
310 TopTools_ListOfShape LE;
311 TopExp::MapShapes(W, TopAbs_EDGE, ME);
312 for (int i = 1; i <= ME.Extent(); i++)
321 ProjWireOnPlane(WM.Wire(), refpl, outW);
322 BRepBuilderAPI_MakeFace mf(refpl, outW); //check inside is true by def
325 ///!!! the internal wires cant be added with 'internal' ori.
326 // it's possible to do with brep builder yet the result will not be correct!
327 // more proper way is to use BOP operation here.
328 /*for (int i = 1; i <= IntW.Extent(); i++)
331 const TopoDS_Wire& W = TopoDS::Wire(IntW(i));
332 ProjWireOnPlane(W, refpl, outIW);
337 void HYDROData_DTM::CreateProfiles(const std::vector<Handle_HYDROData_Profile>& theProfiles,
339 double theSpatialStep,
340 AltitudePoints& theOutLeft,
341 AltitudePoints& theOutRight,
342 AltitudePoints& theOutPoints,
343 std::vector<AltitudePoints>& theOutMainProfiles,
344 TopoDS_Shape& Out3dPres,
345 TopoDS_Shape& Out2dPres,
346 TopoDS_Shape& OutLeftB,
347 TopoDS_Shape& OutRightB,
348 TopoDS_Shape& OutInlet,
349 TopoDS_Shape& OutOutlet,
352 std::set<int>& InvInd)
354 if (theProfiles.empty())
356 theOutPoints = Interpolate( theProfiles, theDDZ, theSpatialStep, theOutLeft, theOutRight, theOutMainProfiles, InvInd );
357 //note that if Create3dPres is false => Create2dPres flag is meaningless!
360 TopTools_IndexedMapOfOrientedShape ll = Create3DShape( theOutLeft, theOutRight, theOutMainProfiles);
366 BB.MakeCompound(cmp);
367 for (int i = 1; i <= ll.Extent(); i++)
372 //same order as in HYDROData_DTM::Update()
374 OutRightB = ll(ll.Extent());
376 OutOutlet = ll(ll.Extent() - 1);
381 Get2dFaceFrom3dPres(cmp, outF);
390 void HYDROData_DTM::GetProperties( const Handle_HYDROData_Profile& theProfile,
391 gp_Pnt& theLowestPoint, gp_Vec2d& theDir,
393 double& theZMin, double& theZMax )
395 theLowestPoint = theProfile->GetBottomPoint();
398 theProfile->GetLeftPoint( aLeft, true, true );
399 theProfile->GetRightPoint( aRight, true, true );
400 double x = aRight.X()-aLeft.X();
401 double y = aRight.Y()-aLeft.Y();
403 theDir = gp_Vec2d( -y, x );
405 theDir = gp_Vec2d( x, y );
407 HYDROData_Profile::ProfilePoints points = theProfile->GetProfilePoints();
408 int lo = points.Lower();
409 int up = points.Upper();
410 theZMin = std::numeric_limits<double>::max();
412 for( int i=lo; i<=up; i++ )
414 double z = points.Value( i ).Z();
422 inline gp_Pnt2d To2D( const gp_Pnt& thePnt, const gp_Trsf& theTr,
423 double& theUMin, double& theUMax )
425 gp_Pnt p = thePnt.Transformed( theTr );
432 return gp_Pnt2d( u, z );
435 Handle(TColgp_HArray1OfPnt2d) To2D( const TColgp_Array1OfPnt& thePoints,
436 const gp_Trsf& theTr,
437 double& theUMin, double& theUMax )
439 int low = thePoints.Lower(), up = thePoints.Upper();
440 Handle(TColgp_HArray1OfPnt2d) points = new TColgp_HArray1OfPnt2d( low, up );
441 for( int i=low; i<=up; i++ )
442 points->SetValue( i, To2D( thePoints.Value( i ), theTr, theUMin, theUMax ) );
446 Handle(Geom2d_Curve) CurveTo2D( const Handle(Geom_Curve)& theCurve,
447 Standard_Real theFirst, Standard_Real theLast,
448 const gp_Trsf& theTr,
449 double& theUMin, double& theUMax )
451 if( theCurve->IsKind( STANDARD_TYPE( Geom_Line ) ) )
453 gp_Pnt aFirstPnt, aLastPnt;
454 theCurve->D0( theFirst, aFirstPnt );
455 theCurve->D0( theLast, aLastPnt );
458 aFirst2d = To2D( aFirstPnt, theTr, theUMin, theUMax ),
459 aLast2d = To2D( aLastPnt, theTr, theUMin, theUMax );
461 gp_Vec2d dir( aFirst2d, aLast2d );
462 Handle_Geom2d_Line aLine2d = new Geom2d_Line( aFirst2d, gp_Dir2d( dir.X(), dir.Y() ) );
463 return new Geom2d_TrimmedCurve( aLine2d, 0, aLast2d.Distance( aFirst2d ) );
466 if( theCurve->IsKind( STANDARD_TYPE( Geom_BSplineCurve ) ) )
468 Handle(Geom_BSplineCurve) aSpline = Handle(Geom_BSplineCurve)::DownCast( theCurve );
470 Handle(TColgp_HArray1OfPnt2d) poles = To2D( aSpline->Poles(), theTr, theUMin, theUMax );
471 const TColStd_Array1OfReal& knots = aSpline->Knots();
472 const TColStd_Array1OfInteger& multiplicities = aSpline->Multiplicities();
473 int aDegree = aSpline->Degree();
475 return new Geom2d_BSplineCurve( poles->Array1(), knots, multiplicities, aDegree );
478 return Handle(Geom2d_Curve)();
481 Handle_Geom2d_BSplineCurve HYDROData_DTM::CreateHydraulicAxis(
482 const std::vector<Handle_HYDROData_Profile>& theProfiles,
483 std::vector<double>& theDistances )
485 size_t n = theProfiles.size();
486 Handle_Geom2d_BSplineCurve aResult;
488 Handle(TColgp_HArray1OfPnt2d) points = new TColgp_HArray1OfPnt2d( 1, (int)n );
489 TColgp_Array1OfVec2d tangents( 1, (int)n );
490 Handle(TColStd_HArray1OfBoolean) flags = new TColStd_HArray1OfBoolean( 1, (int)n );
492 for( size_t i = 1; i <= n; i++ )
494 Handle_HYDROData_Profile aProfile = theProfiles[i-1];
500 GetProperties( aProfile, aLowest, aTangent, true, zmin, zmax );
501 aTangent.Normalize();
503 points->SetValue( (int)i, gp_Pnt2d( aLowest.X(), aLowest.Y() ) );
504 tangents.SetValue( (int)i, aTangent );
505 flags->SetValue( (int)i, Standard_True );
508 Geom2dAPI_Interpolate anInterpolator( points, Standard_False, Standard_False );
509 anInterpolator.Load( tangents, flags );
510 anInterpolator.Perform();
511 if( anInterpolator.IsDone() )
513 aResult = anInterpolator.Curve();
515 //fill the distances vector
516 Geom2dAdaptor_Curve anAdaptor( aResult );
518 theDistances.clear();
519 theDistances.reserve( n );
520 Standard_Real aParamFirst = anAdaptor.FirstParameter(), aParamLast = anAdaptor.LastParameter();
521 for( size_t i = 1; i <= n; i++ )
523 gp_Pnt2d aPnt = points->Value( (Standard_Integer)i );
524 Geom2dAPI_ProjectPointOnCurve aProject( aPnt, aResult );
525 Standard_Real aParam = aProject.LowerDistanceParameter();
526 double aDistance = GCPnts_AbscissaPoint::Length( anAdaptor, aParamFirst, aParam );
527 theDistances.push_back( aDistance );
533 std::vector<Handle_Geom2d_Curve> HYDROData_DTM::ProfileToParametric(
534 const Handle_HYDROData_Profile& theProfile,
535 double& theUMin, double& theUMax, gp_Vec2d& theDir )
537 std::vector<Handle_Geom2d_Curve> curves;
539 // Transformation of the coordinate systems
542 GetProperties( theProfile, aLowest, theDir, false, zmin, zmax );
545 gp_Ax3 aStd3d( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ), gp_Dir( 1, 0, 0 ) );
546 gp_Ax3 aLocal( aLowest, gp_Dir( 0, 0, 1 ), gp_Dir( theDir.X(), theDir.Y(), 0 ) );
549 aTransf.SetTransformation( aStd3d, aLocal );
551 // Iteration via edges
552 TopoDS_Wire aWire = TopoDS::Wire( theProfile->GetShape3D() );
553 TopExp_Explorer anExp( aWire, TopAbs_EDGE );
554 for( ; anExp.More(); anExp.Next() )
556 // Extract an edge from wire
557 TopoDS_Edge anEdge = TopoDS::Edge( anExp.Current() );
559 // Extract a curve corresponding to the edge
560 TopLoc_Location aLoc;
561 Standard_Real aFirst, aLast;
562 Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aLoc, aFirst, aLast );
564 // Convert the curve to 2d CS
565 Handle(Geom2d_Curve) aCurve2d = CurveTo2D( aCurve, aFirst, aLast, aTransf, theUMin, theUMax );
566 if( !aCurve2d.IsNull() )
567 curves.push_back( aCurve2d );
573 bool CalcMidWidth( const std::vector<gp_Pnt2d>& intersections, double& theMid, double& theWid )
575 double umin = std::numeric_limits<double>::max(),
578 size_t n = intersections.size();
582 for( size_t i = 0; i < n; i++ )
584 double u = intersections[i].X();
590 theMid = ( umin+umax )/2;
595 void HYDROData_DTM::ProfileDiscretization( const Handle_HYDROData_Profile& theProfile,
596 double theXCurv, double theMinZ, double theMaxZ, double theDDZ,
597 CurveUZ& theMidPointCurve,
598 CurveUZ& theWidthCurve,
599 int& intersection_nb,
602 double aDblMax = std::numeric_limits<double>::max(),
607 gp_Vec2d aProfileDir;
608 std::vector<Handle_Geom2d_Curve> curves = ProfileToParametric( theProfile, aUMin, aUMax, aProfileDir );
609 size_t n = curves.size();
614 // we add the "virtual" vertical lines to simulate the intersection with profile
615 gp_Pnt2d aFirst, aLast;
616 curves[0]->D0( curves[0]->FirstParameter(), aFirst );
617 curves[n-1]->D0( curves[n-1]->LastParameter(), aLast );
618 Handle(Geom2d_Line) aV1 = new Geom2d_Line( aFirst, gp_Dir2d( 0, 1 ) );
619 Handle(Geom2d_TrimmedCurve) aT1 = new Geom2d_TrimmedCurve( aV1, 0.0, aVMax );
621 Handle(Geom2d_Line) aV2 = new Geom2d_Line( aLast, gp_Dir2d( 0, 1 ) );
622 Handle(Geom2d_TrimmedCurve) aT2 = new Geom2d_TrimmedCurve( aV2, 0.0, aVMax );
624 curves.push_back( aT1 );
625 curves.push_back( aT2 );
627 int psize = ( int )( ( theMaxZ-theMinZ ) / theDDZ + 1 );
628 theMidPointCurve = CurveUZ( theXCurv, aProfileDir );
629 theMidPointCurve.reserve( psize );
630 theWidthCurve = CurveUZ( theXCurv, aProfileDir );
631 theWidthCurve.reserve( psize );
634 // for each discrete value of z we search intersection with profile
635 for( double z = theMinZ; z <= theMaxZ; z += theDDZ )
637 Handle(Geom2d_Line) aLine = new Geom2d_Line( gp_Pnt2d( 0, z ), gp_Dir2d( 1, 0 ) );
638 std::vector<gp_Pnt2d> intersections;
639 for( size_t i = 0; i < n; i++ )
641 Handle_Geom2d_Curve aCurve = curves[i];
642 Geom2dAPI_InterCurveCurve anIntersect( aCurve, aLine, theTolerance );
643 for( int k=1, m=anIntersect.NbPoints(); k<=m; k++ )
644 intersections.push_back( anIntersect.Point( k ) );
647 intersection_nb = intersections.size();
648 if( intersection_nb >= 2 )
651 if( !CalcMidWidth( intersections, u_mid, u_wid ) )
657 theMidPointCurve.push_back( p_mid );
662 theWidthCurve.push_back( p_wid );
667 void HYDROData_DTM::Interpolate( const CurveUZ& theCurveA, const CurveUZ& theCurveB,
668 int theNbSteps, std::vector<CurveUZ>& theInterpolation,
671 theInterpolation.clear();
672 int d = isAddSecond ? 2 : 1;
673 theInterpolation.reserve( theNbSteps+d );
674 double dt = 1.0 / double( theNbSteps + 1 );
676 theInterpolation.push_back( theCurveA );
677 for( int i=0; i<theNbSteps; i++, t+=dt )
679 CurveUZ anInterp = theCurveA*(1-t) + theCurveB*t;
680 theInterpolation.push_back( anInterp );
683 theInterpolation.push_back( theCurveB );
685 #include <BRepLib_MakeEdge2d.hxx>
686 void HYDROData_DTM::CurveTo3D( const Handle_Geom2d_BSplineCurve& theHydraulicAxis,
687 const CurveUZ& theMidCurve, const CurveUZ& theWidthCurve,
688 AltitudePoints& thePoints, double dz )
690 Geom2dAdaptor_Curve anAdaptor( theHydraulicAxis );
691 TopoDS_Edge E2d = BRepLib_MakeEdge2d(theHydraulicAxis).Edge();
692 GCPnts_AbscissaPoint ap( anAdaptor, theMidCurve.Xcurv(), anAdaptor.FirstParameter() );
693 double aParam = ap.Parameter();
696 anAdaptor.D0( aParam, point );
697 gp_Vec2d profile_dir = theMidCurve.ProfileDir();
698 gp_Dir tangent_n( -profile_dir.Y(), profile_dir.X(), dz );
699 profile_dir.Normalize();
701 size_t n = theMidCurve.size();
702 std::map<double, AltitudePoint> sorted_points;
703 for( size_t i=0; i<n; i++ )
705 double param1 = theMidCurve[i].U - theWidthCurve[i].U / 2;
706 double param2 = theMidCurve[i].U + theWidthCurve[i].U / 2;
708 gp_Pnt2d p1 = point.Translated( param1 * profile_dir);
709 gp_Pnt2d p2 = point.Translated( param2 * profile_dir);
711 double z = theMidCurve[i].Z;
713 AltitudePoint p3d_1( p1.X(), p1.Y(), z ), p3d_2( p2.X(), p2.Y(), z );
715 sorted_points[param1] = p3d_1;
716 sorted_points[param2] = p3d_2;
719 thePoints.reserve( sorted_points.size() );
720 std::map<double, AltitudePoint>::const_iterator it = sorted_points.begin(), last = sorted_points.end();
721 for( ; it!=last; it++ )
722 thePoints.push_back( it->second );
725 inline double max( double a, double b )
733 #include <BRepLib_MakeWire.hxx>
735 std::vector<HYDROData_Bathymetry::AltitudePoints> HYDROData_DTM::Interpolate
736 ( const Handle_Geom2d_BSplineCurve& theHydraulicAxis,
737 const Handle_HYDROData_Profile& theProfileA,
739 const Handle_HYDROData_Profile& theProfileB,
741 double theDDZ, int theNbSteps, bool isAddSecond,
742 int& inter_nb_1, int& inter_nb_2)
744 double zminA, zmaxA, zminB, zmaxB;
745 gp_Pnt lowestA, lowestB;
748 GetProperties( theProfileA, lowestA, dirA, false, zminA, zmaxA );
749 GetProperties( theProfileB, lowestB, dirB, false, zminB, zmaxB );
751 double dz = zminB - zminA;
753 double zmin = max( zminA, zminB );
754 double zmax = max( zmaxA, zmaxB );
756 CurveUZ midA(0, gp_Vec2d()), midB(0, gp_Vec2d());
757 CurveUZ widA(0, gp_Vec2d()), widB(0, gp_Vec2d());
759 ProfileDiscretization( theProfileA, theXCurvA, zmin, zmax, theDDZ, midA, widA, inter_nb_1 );
760 ProfileDiscretization( theProfileB, theXCurvB, zmin, zmax, theDDZ, midB, widB, inter_nb_2 );
762 std::vector<CurveUZ> mid, wid;
763 Interpolate( midA, midB, theNbSteps, mid, isAddSecond );
764 Interpolate( widA, widB, theNbSteps, wid, isAddSecond );
766 size_t p = mid.size();
767 size_t q = p>0 ? 2*mid[0].size() : 1;
768 std::vector<AltitudePoints> points;
771 for( size_t i=0; i<p; i++ )
773 points[i].reserve( q );
774 CurveTo3D( theHydraulicAxis, mid[i], wid[i], points[i], dz );
780 HYDROData_Bathymetry::AltitudePoints HYDROData_DTM::Interpolate
781 ( const std::vector<Handle_HYDROData_Profile>& theProfiles,
782 double theDDZ, double theSpatialStep,
783 AltitudePoints& theLeft,
784 AltitudePoints& theRight,
785 std::vector<AltitudePoints>& theMainProfiles,
786 std::set<int>& invalInd)
788 AltitudePoints points;
789 size_t n = theProfiles.size();
793 std::vector<double> distances;
794 Handle_Geom2d_BSplineCurve aHydraulicAxis = CreateHydraulicAxis( theProfiles, distances );
795 if( aHydraulicAxis.IsNull() )
798 theMainProfiles.reserve( n );
800 for( size_t i=0, n1=n-1; i<n1; i++ )
802 double aDistance = distances[i+1]-distances[i];
803 int aNbSteps = int(aDistance/theSpatialStep);
804 bool isAddSecond = i==n1-1;
806 // 1. Calculate interpolated profiles
807 int inter_nb_1, inter_nb_2;
808 std::vector<AltitudePoints> local_points = Interpolate( aHydraulicAxis, theProfiles[i], distances[i],
809 theProfiles[i+1], distances[i+1], theDDZ, aNbSteps, isAddSecond, inter_nb_1, inter_nb_2 );
810 int lps = local_points.size();
816 invalInd.insert(i+1);
818 // 2. Put all points into the global container
819 for( size_t j=0; j<lps; j++ )
821 const AltitudePoints& lp = local_points[j];
823 points.reserve( lp.size() * n );
824 for( size_t k=0, ks=lp.size(); k<ks; k++ )
825 points.push_back( lp[k] );
828 // 3. Get left/right banks' points
831 theLeft.reserve( lps * n );
832 theRight.reserve( lps * n );
834 for( size_t j=0; j<lps; j++ )
836 const AltitudePoints& lp = local_points[j];
837 theLeft.push_back( lp[0] );
838 theRight.push_back( lp[lp.size()-1] );
841 // 4. Get main profiles points
842 theMainProfiles.push_back( local_points[0] );
844 theMainProfiles.push_back( local_points[lps-1] );
849 int HYDROData_DTM::EstimateNbPoints( const std::vector<Handle_HYDROData_Profile>& theProfiles,
850 double theDDZ, double theSpatialStep )
852 size_t n = theProfiles.size();
855 if( theDDZ<1E-6 || theSpatialStep<1E-6 )
858 std::vector<double> distances;
859 Handle_Geom2d_BSplineCurve aHydraulicAxis = CreateHydraulicAxis( theProfiles, distances );
860 if( aHydraulicAxis.IsNull() )
863 double aCompleteDistance = distances[n-1];
864 int aNbSteps = int( aCompleteDistance / theSpatialStep ) + 1;
868 GetProperties( theProfiles[0], aLowest, aDir, true, aZMin, aZMax );
869 int aNbZSteps = (aZMax-aZMin)/theDDZ;
871 if( aNbSteps > ( 1<<16 ) || aNbZSteps > ( 1<<16 ) )
874 return aNbSteps * aNbZSteps;