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>
49 #include <ShapeAnalysis_Wire.hxx>
53 IMPLEMENT_STANDARD_HANDLE( HYDROData_DTM, HYDROData_Bathymetry )
54 IMPLEMENT_STANDARD_RTTIEXT( HYDROData_DTM, HYDROData_Bathymetry )
57 HYDROData_DTM::CurveUZ::CurveUZ( double theXCurv, const gp_Vec2d& theProfileDir, double theDeltaZ )
58 : myXcurv( theXCurv ), myProfileDir( theProfileDir ), myDeltaZ( theDeltaZ )
62 HYDROData_DTM::CurveUZ::~CurveUZ()
66 double HYDROData_DTM::CurveUZ::Xcurv() const
71 gp_Vec2d HYDROData_DTM::CurveUZ::ProfileDir() const
76 double HYDROData_DTM::CurveUZ::DeltaZ() const
81 HYDROData_DTM::CurveUZ HYDROData_DTM::CurveUZ::operator + ( const CurveUZ& c ) const
83 HYDROData_DTM::CurveUZ res( Xcurv() + c.Xcurv(), ProfileDir() + c.ProfileDir(), DeltaZ() + c.DeltaZ() );
84 size_t n = size(), n1 = c.size();
87 std::cout << "Warning: different number of points in curves: " << n << ", " << n1 << std::endl;
90 for( int i=0; i<n; i++ )
93 p.U = operator[]( i ).U + c[i].U;
94 p.Z = operator[]( i ).Z;
100 HYDROData_DTM::CurveUZ HYDROData_DTM::CurveUZ::operator * ( double d ) const
102 HYDROData_DTM::CurveUZ res( Xcurv()*d, ProfileDir()*d, DeltaZ()*d );
105 for( int i=0; i<n; i++ )
108 p.U = operator[]( i ).U * d;
109 p.Z = operator[]( i ).Z;
118 HYDROData_DTM::HYDROData_DTM()
122 HYDROData_DTM::~HYDROData_DTM()
126 HYDROData_SequenceOfObjects HYDROData_DTM::GetProfiles() const
128 return GetReferenceObjects( DataTag_Profiles );
131 void HYDROData_DTM::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles )
133 SetReferenceObjects( theProfiles, DataTag_Profiles );
137 double HYDROData_DTM::GetDDZ() const
139 return GetDouble( DataTag_DDZ );
142 void HYDROData_DTM::SetDDZ( double theDDZ )
144 SetDouble( DataTag_DDZ, theDDZ );
148 double HYDROData_DTM::GetSpatialStep() const
150 return GetDouble( DataTag_SpatialStep );
153 void HYDROData_DTM::SetSpatialStep( double theSpatialStep )
155 SetDouble( DataTag_SpatialStep, theSpatialStep );
159 void HYDROData_DTM::PointToWire(const AltitudePoints& pnts, TopoDS_Wire& W )
164 for (int i = 0; i < pnts.size() - 1; i++)
166 gp_Pnt p1(pnts[i].X, pnts[i].Y, pnts[i].Z);
167 gp_Pnt p2(pnts[i+1].X, pnts[i+1].Y, pnts[i+1].Z);
168 WM.Add(BRepLib_MakeEdge(p1, p2).Edge());
174 TopTools_IndexedMapOfOrientedShape HYDROData_DTM::Create3DShape(const AltitudePoints& left,
175 const AltitudePoints& right,
176 const std::vector<AltitudePoints>& main_profiles)
178 TopTools_IndexedMapOfOrientedShape ll;
179 TopoDS_Wire LWire, RWire;
180 PointToWire(left, LWire);
181 PointToWire(right, RWire);
183 ll.Add(LWire.Oriented(TopAbs_FORWARD));
185 for (int k = 0; k < main_profiles.size(); k++)
188 PointToWire(main_profiles[k], W);
189 TopAbs_Orientation Ori = TopAbs_INTERNAL;
190 if (k == 0 || k == main_profiles.size() - 1)
191 Ori = TopAbs_FORWARD;
192 ll.Add(W.Oriented(Ori));
196 ll.Add(RWire.Oriented(TopAbs_FORWARD));
197 //yes, add subshapes in this order (left + profiles + right)
198 //otherwise the projected wire will be non-manifold
204 void HYDROData_DTM::Update()
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;
214 HYDROData_SequenceOfObjects objs = GetProfiles();
215 double ddz = GetDDZ();
216 double step = GetSpatialStep();
217 std::set<int> InvInd;
218 bool WireIntersections; //__TODO
219 CreateProfilesFromDTM( objs, ddz, step, points, Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet, true, true, InvInd, -1, WireIntersections );
220 SetAltitudePoints( points );
222 SetShape( DataTag_LeftBankShape, OutLeftB);
223 SetShape( DataTag_RightBankShape, OutRightB);
224 SetShape( DataTag_InletShape, OutInlet);
225 SetShape( DataTag_OutletShape, OutOutlet );
226 SetShape( DataTag_3DShape, Out3dPres );
227 SetShape( DataTag_2DShape, Out2dPres );
229 HYDROData_Bathymetry::Update();
232 void HYDROData_DTM::GetPresentationShapes( TopoDS_Shape& Out3dPres,
233 TopoDS_Shape& Out2dPres,
234 TopoDS_Shape& OutLeftB,
235 TopoDS_Shape& OutRightB,
236 TopoDS_Shape& OutInlet,
237 TopoDS_Shape& OutOutlet )
240 OutLeftB = GetShape( DataTag_LeftBankShape);
241 OutRightB = GetShape( DataTag_RightBankShape);
242 OutInlet = GetShape( DataTag_InletShape);
243 OutOutlet = GetShape( DataTag_OutletShape );
244 Out3dPres = GetShape( DataTag_3DShape );
245 Out2dPres = GetShape( DataTag_2DShape );
248 void HYDROData_DTM::CreateProfilesFromDTM (const HYDROData_SequenceOfObjects& InpProfiles,
251 AltitudePoints& points,
252 TopoDS_Shape& Out3dPres,
253 TopoDS_Shape& Out2dPres,
254 TopoDS_Shape& OutLeftB,
255 TopoDS_Shape& OutRightB,
256 TopoDS_Shape& OutInlet,
257 TopoDS_Shape& OutOutlet,
260 std::set<int>& InvInd,
262 bool& WireIntersections)
264 int aLower = InpProfiles.Lower(), anUpper = InpProfiles.Upper();
265 size_t n = anUpper - aLower + 1;
267 std::vector<Handle_HYDROData_Profile> profiles;
268 profiles.reserve( n );
269 for( int i=aLower; i<=anUpper; i++ )
271 Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( InpProfiles.Value( i ) );
272 if( !aProfile.IsNull() )
273 profiles.push_back( aProfile );
275 const double EPS = 1E-3;
277 AltitudePoints right;
278 std::vector<AltitudePoints> main_profiles;
280 if( thePntsLimit > 0 )
282 int aNbPoints = EstimateNbPoints( profiles, ddz, step );
283 if( aNbPoints < 0 || aNbPoints > thePntsLimit )
287 if( ddz>EPS && step>EPS )
288 CreateProfiles(profiles, ddz, step, left, right, points, main_profiles,
289 Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet, Create3dPres, Create2dPres, InvInd, WireIntersections );
292 void HYDROData_DTM::ProjWireOnPlane(const TopoDS_Wire& inpWire, const Handle_Geom_Plane& RefPlane, TopoDS_Wire& outWire)
294 //its also possible to use BrepAlgo_NormalProjection here!
295 BRepTools_WireExplorer ex(TopoDS::Wire(inpWire.Oriented(TopAbs_FORWARD)));
297 for (;ex.More();ex.Next())
299 const TopoDS_Edge& CE = ex.Current();
301 Handle(Geom_Curve) C3d = BRep_Tool::Curve(CE, f, l);
302 Handle(Geom_Curve) ProjectedCurve = GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3d, f, l), RefPlane, RefPlane->Position().Direction(), Standard_True);
303 TopoDS_Edge ProjEdge = BRepLib_MakeEdge(ProjectedCurve);
304 WM.Add(ProjEdge); //auto sharing between edges if vertex is coincident
307 outWire.Orientation(inpWire.Orientation()); //take from the original wire
311 bool HYDROData_DTM::Get2dFaceFrom3dPres(const TopoDS_Compound& cmp, TopoDS_Face& outF )
313 Handle_Geom_Plane refpl = new Geom_Plane(gp_Pnt(0,0,0), gp_Dir(0,0,1));
315 TopoDS_Iterator it(cmp);
316 //TopTools_IndexedMapOfShape IntW;
317 for (;it.More(); it.Next())
319 const TopoDS_Wire& W = TopoDS::Wire(it.Value());
320 if (W.Orientation() != TopAbs_INTERNAL)
322 //use list of edges to protect againts non-manifold cases.
323 //auto sharing between edges will be added automatically
324 TopTools_IndexedMapOfShape ME;
325 TopTools_ListOfShape LE;
326 TopExp::MapShapes(W, TopAbs_EDGE, ME);
327 for (int i = 1; i <= ME.Extent(); i++)
336 ProjWireOnPlane(WM.Wire(), refpl, outW);
337 BRepBuilderAPI_MakeFace mf(refpl, outW, true); //check inside is true by def
340 ShapeAnalysis_Wire WA(outW, outF, Precision::Confusion());
341 bool res = WA.CheckSelfIntersection();
344 ///!!! the internal wires cant be added with 'internal' ori.
345 // it's possible to do with brep builder yet the result will not be correct!
346 // more proper way is to use BOP operation here.
347 /*for (int i = 1; i <= IntW.Extent(); i++)
350 const TopoDS_Wire& W = TopoDS::Wire(IntW(i));
351 ProjWireOnPlane(W, refpl, outIW);
356 void HYDROData_DTM::CreateProfiles(const std::vector<Handle_HYDROData_Profile>& theProfiles,
358 double theSpatialStep,
359 AltitudePoints& theOutLeft,
360 AltitudePoints& theOutRight,
361 AltitudePoints& theOutPoints,
362 std::vector<AltitudePoints>& theOutMainProfiles,
363 TopoDS_Shape& Out3dPres,
364 TopoDS_Shape& Out2dPres,
365 TopoDS_Shape& OutLeftB,
366 TopoDS_Shape& OutRightB,
367 TopoDS_Shape& OutInlet,
368 TopoDS_Shape& OutOutlet,
371 std::set<int>& InvInd,
372 bool& WireIntersections)
374 if (theProfiles.empty())
376 theOutPoints = Interpolate( theProfiles, theDDZ, theSpatialStep, theOutLeft, theOutRight, theOutMainProfiles, InvInd );
377 //note that if Create3dPres is false => Create2dPres flag is meaningless!
380 TopTools_IndexedMapOfOrientedShape ll = Create3DShape( theOutLeft, theOutRight, theOutMainProfiles);
386 BB.MakeCompound(cmp);
387 for (int i = 1; i <= ll.Extent(); i++)
392 //same order as in HYDROData_DTM::Update()
394 OutRightB = ll(ll.Extent());
396 OutOutlet = ll(ll.Extent() - 1);
401 WireIntersections = Get2dFaceFrom3dPres(cmp, outF); //__TODO
410 void HYDROData_DTM::GetProperties( const Handle_HYDROData_Profile& theProfile,
411 gp_Pnt& theLowestPoint, gp_Vec2d& theDir,
413 double& theZMin, double& theZMax )
415 theLowestPoint = theProfile->GetBottomPoint();
418 theProfile->GetLeftPoint( aLeft, true, true );
419 theProfile->GetRightPoint( aRight, true, true );
420 double x = aRight.X()-aLeft.X();
421 double y = aRight.Y()-aLeft.Y();
423 theDir = gp_Vec2d( -y, x );
425 theDir = gp_Vec2d( x, y );
427 HYDROData_Profile::ProfilePoints points = theProfile->GetProfilePoints();
428 int lo = points.Lower();
429 int up = points.Upper();
430 theZMin = std::numeric_limits<double>::max();
432 for( int i=lo; i<=up; i++ )
434 double z = points.Value( i ).Z();
442 inline gp_Pnt2d To2D( const gp_Pnt& thePnt, const gp_Trsf& theTr,
443 double& theUMin, double& theUMax )
445 gp_Pnt p = thePnt.Transformed( theTr );
452 return gp_Pnt2d( u, z );
455 Handle(TColgp_HArray1OfPnt2d) To2D( const TColgp_Array1OfPnt& thePoints,
456 const gp_Trsf& theTr,
457 double& theUMin, double& theUMax )
459 int low = thePoints.Lower(), up = thePoints.Upper();
460 Handle(TColgp_HArray1OfPnt2d) points = new TColgp_HArray1OfPnt2d( low, up );
461 for( int i=low; i<=up; i++ )
462 points->SetValue( i, To2D( thePoints.Value( i ), theTr, theUMin, theUMax ) );
466 Handle(Geom2d_Curve) CurveTo2D( const Handle(Geom_Curve)& theCurve,
467 Standard_Real theFirst, Standard_Real theLast,
468 const gp_Trsf& theTr,
469 double& theUMin, double& theUMax )
471 if( theCurve->IsKind( STANDARD_TYPE( Geom_Line ) ) )
473 gp_Pnt aFirstPnt, aLastPnt;
474 theCurve->D0( theFirst, aFirstPnt );
475 theCurve->D0( theLast, aLastPnt );
478 aFirst2d = To2D( aFirstPnt, theTr, theUMin, theUMax ),
479 aLast2d = To2D( aLastPnt, theTr, theUMin, theUMax );
481 gp_Vec2d dir( aFirst2d, aLast2d );
482 Handle_Geom2d_Line aLine2d = new Geom2d_Line( aFirst2d, gp_Dir2d( dir.X(), dir.Y() ) );
483 return new Geom2d_TrimmedCurve( aLine2d, 0, aLast2d.Distance( aFirst2d ) );
486 if( theCurve->IsKind( STANDARD_TYPE( Geom_BSplineCurve ) ) )
488 Handle(Geom_BSplineCurve) aSpline = Handle(Geom_BSplineCurve)::DownCast( theCurve );
490 Handle(TColgp_HArray1OfPnt2d) poles = To2D( aSpline->Poles(), theTr, theUMin, theUMax );
491 const TColStd_Array1OfReal& knots = aSpline->Knots();
492 const TColStd_Array1OfInteger& multiplicities = aSpline->Multiplicities();
493 int aDegree = aSpline->Degree();
495 return new Geom2d_BSplineCurve( poles->Array1(), knots, multiplicities, aDegree );
498 return Handle(Geom2d_Curve)();
501 Handle_Geom2d_BSplineCurve HYDROData_DTM::CreateHydraulicAxis(
502 const std::vector<Handle_HYDROData_Profile>& theProfiles,
503 std::vector<double>& theDistances )
505 size_t n = theProfiles.size();
506 Handle_Geom2d_BSplineCurve aResult;
508 Handle(TColgp_HArray1OfPnt2d) points = new TColgp_HArray1OfPnt2d( 1, (int)n );
509 TColgp_Array1OfVec2d tangents( 1, (int)n );
510 Handle(TColStd_HArray1OfBoolean) flags = new TColStd_HArray1OfBoolean( 1, (int)n );
512 for( size_t i = 1; i <= n; i++ )
514 Handle_HYDROData_Profile aProfile = theProfiles[i-1];
520 GetProperties( aProfile, aLowest, aTangent, true, zmin, zmax );
521 aTangent.Normalize();
523 points->SetValue( (int)i, gp_Pnt2d( aLowest.X(), aLowest.Y() ) );
524 tangents.SetValue( (int)i, aTangent );
525 flags->SetValue( (int)i, Standard_True );
528 Geom2dAPI_Interpolate anInterpolator( points, Standard_False, Standard_False );
529 anInterpolator.Load( tangents, flags );
530 anInterpolator.Perform();
531 if( anInterpolator.IsDone() )
533 aResult = anInterpolator.Curve();
535 //fill the distances vector
536 Geom2dAdaptor_Curve anAdaptor( aResult );
538 theDistances.clear();
539 theDistances.reserve( n );
540 Standard_Real aParamFirst = anAdaptor.FirstParameter(), aParamLast = anAdaptor.LastParameter();
541 for( size_t i = 1; i <= n; i++ )
543 gp_Pnt2d aPnt = points->Value( (Standard_Integer)i );
544 Geom2dAPI_ProjectPointOnCurve aProject( aPnt, aResult );
545 Standard_Real aParam = aProject.LowerDistanceParameter();
546 double aDistance = GCPnts_AbscissaPoint::Length( anAdaptor, aParamFirst, aParam );
547 theDistances.push_back( aDistance );
553 std::vector<Handle_Geom2d_Curve> HYDROData_DTM::ProfileToParametric(
554 const Handle_HYDROData_Profile& theProfile,
555 double& theUMin, double& theUMax, gp_Vec2d& theDir )
557 std::vector<Handle_Geom2d_Curve> curves;
559 // Transformation of the coordinate systems
562 GetProperties( theProfile, aLowest, theDir, false, zmin, zmax );
564 gp_Ax3 aStd3d( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ), gp_Dir( 1, 0, 0 ) );
565 gp_Ax3 aLocal( gp_Pnt( aLowest.X(), aLowest.Y(), 0 ), gp_Dir( 0, 0, 1 ), gp_Dir( theDir.X(), theDir.Y(), 0 ) );
568 aTransf.SetTransformation( aStd3d, aLocal );
570 // Iteration via edges
571 TopoDS_Wire aWire = TopoDS::Wire( theProfile->GetShape3D() );
572 TopExp_Explorer anExp( aWire, TopAbs_EDGE );
573 for( ; anExp.More(); anExp.Next() )
575 // Extract an edge from wire
576 TopoDS_Edge anEdge = TopoDS::Edge( anExp.Current() );
578 // Extract a curve corresponding to the edge
579 TopLoc_Location aLoc;
580 Standard_Real aFirst, aLast;
581 Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aLoc, aFirst, aLast );
583 // Convert the curve to 2d CS
584 Handle(Geom2d_Curve) aCurve2d = CurveTo2D( aCurve, aFirst, aLast, aTransf, theUMin, theUMax );
585 if( !aCurve2d.IsNull() )
586 curves.push_back( aCurve2d );
592 bool CalcMidWidth( const std::set<double>& intersections, double& theMid, double& theWid )
594 double umin = std::numeric_limits<double>::max(),
597 size_t n = intersections.size();
601 std::set<double>::const_iterator it = intersections.begin(), last = intersections.end();
602 for( ; it!=last; it++ )
610 theMid = ( umin+umax )/2;
615 void HYDROData_DTM::ProfileDiscretization( const Handle_HYDROData_Profile& theProfile,
616 double theXCurv, double theMinZ, double theMaxZ, double theDDZ,
617 CurveUZ& theMidPointCurve,
618 CurveUZ& theWidthCurve,
619 int& intersection_nb,
622 double aDblMax = std::numeric_limits<double>::max(),
627 gp_Vec2d aProfileDir;
628 std::vector<Handle_Geom2d_Curve> curves = ProfileToParametric( theProfile, aUMin, aUMax, aProfileDir );
629 size_t n = curves.size();
634 // we add the "virtual" vertical lines to simulate the intersection with profile
635 gp_Pnt2d aFirst, aLast;
636 curves[0]->D0( curves[0]->FirstParameter(), aFirst );
637 curves[n-1]->D0( curves[n-1]->LastParameter(), aLast );
638 Handle(Geom2d_Line) aV1 = new Geom2d_Line( aFirst, gp_Dir2d( 0, 1 ) );
639 Handle(Geom2d_TrimmedCurve) aT1 = new Geom2d_TrimmedCurve( aV1, 0.0, aVMax );
641 Handle(Geom2d_Line) aV2 = new Geom2d_Line( aLast, gp_Dir2d( 0, 1 ) );
642 Handle(Geom2d_TrimmedCurve) aT2 = new Geom2d_TrimmedCurve( aV2, 0.0, aVMax );
644 curves.push_back( aT1 );
645 curves.push_back( aT2 );
647 int psize = ( int )( ( theMaxZ-theMinZ ) / theDDZ + 1 );
648 theMidPointCurve = CurveUZ( theXCurv, aProfileDir, theMinZ );
649 theMidPointCurve.reserve( psize );
650 theWidthCurve = CurveUZ( theXCurv, aProfileDir, theMinZ );
651 theWidthCurve.reserve( psize );
654 // for each discrete value of z we search intersection with profile
655 for( double z1 = theMinZ; z1 <= theMaxZ; z1 += theDDZ )
657 Handle(Geom2d_Line) aLine = new Geom2d_Line( gp_Pnt2d( 0, z1 ), gp_Dir2d( 1, 0 ) );
658 std::set<double> intersections;
659 for( size_t i = 0; i < n; i++ )
661 Handle_Geom2d_Curve aCurve = curves[i];
662 Geom2dAPI_InterCurveCurve anIntersect( aCurve, aLine, theTolerance );
663 for( int k=1, m=anIntersect.NbPoints(); k<=m; k++ )
664 intersections.insert( anIntersect.Point( k ).X() );
667 intersection_nb = intersections.size();
668 if( intersection_nb >= 1 )
671 if( !CalcMidWidth( intersections, u_mid, u_wid ) )
674 double z = z1 - theMinZ;
678 theMidPointCurve.push_back( p_mid );
683 theWidthCurve.push_back( p_wid );
688 void HYDROData_DTM::Interpolate( const CurveUZ& theCurveA, const CurveUZ& theCurveB,
689 int theNbSteps, std::vector<CurveUZ>& theInterpolation,
692 theInterpolation.clear();
693 int d = isAddSecond ? 2 : 1;
694 theInterpolation.reserve( theNbSteps+d );
695 double dt = 1.0 / double( theNbSteps + 1 );
697 theInterpolation.push_back( theCurveA );
698 for( int i=0; i<theNbSteps; i++, t+=dt )
700 CurveUZ anInterp = theCurveA*(1-t) + theCurveB*t;
701 theInterpolation.push_back( anInterp );
704 theInterpolation.push_back( theCurveB );
706 #include <BRepLib_MakeEdge2d.hxx>
707 void HYDROData_DTM::CurveTo3D( const Handle_Geom2d_BSplineCurve& theHydraulicAxis,
708 const CurveUZ& theMidCurve, const CurveUZ& theWidthCurve,
709 AltitudePoints& thePoints )
711 Geom2dAdaptor_Curve anAdaptor( theHydraulicAxis );
712 TopoDS_Edge E2d = BRepLib_MakeEdge2d(theHydraulicAxis).Edge();
713 GCPnts_AbscissaPoint ap( anAdaptor, theMidCurve.Xcurv(), anAdaptor.FirstParameter() );
714 double aParam = ap.Parameter();
717 anAdaptor.D0( aParam, point );
718 gp_Vec2d profile_dir = theMidCurve.ProfileDir();
719 //gp_Dir tangent_n( -profile_dir.Y(), profile_dir.X(), dz );
720 profile_dir.Normalize();
722 size_t n = theMidCurve.size();
723 std::map<double, AltitudePoint> sorted_points;
724 for( size_t i=0; i<n; i++ )
726 double param1 = theMidCurve[i].U - theWidthCurve[i].U / 2;
727 double param2 = theMidCurve[i].U + theWidthCurve[i].U / 2;
729 gp_Pnt2d p1 = point.Translated( param1 * profile_dir);
730 gp_Pnt2d p2 = point.Translated( param2 * profile_dir);
732 double z = theMidCurve[i].Z + theMidCurve.DeltaZ();
734 AltitudePoint p3d_1( p1.X(), p1.Y(), z ), p3d_2( p2.X(), p2.Y(), z );
736 sorted_points[param1] = p3d_1;
737 sorted_points[param2] = p3d_2;
740 thePoints.reserve( sorted_points.size() );
741 std::map<double, AltitudePoint>::const_iterator it = sorted_points.begin(), last = sorted_points.end();
742 for( ; it!=last; it++ )
743 thePoints.push_back( it->second );
746 inline double max( double a, double b )
754 inline double min( double a, double b )
762 #include <BRepLib_MakeWire.hxx>
764 std::vector<HYDROData_Bathymetry::AltitudePoints> HYDROData_DTM::Interpolate
765 ( const Handle_Geom2d_BSplineCurve& theHydraulicAxis,
766 const Handle_HYDROData_Profile& theProfileA,
768 const Handle_HYDROData_Profile& theProfileB,
770 double theDDZ, int theNbSteps, bool isAddSecond,
771 int& inter_nb_1, int& inter_nb_2)
773 double zminA, zmaxA, zminB, zmaxB;
774 gp_Pnt lowestA, lowestB;
777 GetProperties( theProfileA, lowestA, dirA, false, zminA, zmaxA );
778 GetProperties( theProfileB, lowestB, dirB, false, zminB, zmaxB );
781 double hmax = max( zmaxA-zminA, zmaxB-zminB );
783 //double dz = zminB - zminA;
784 //double zmin = min( zminA, zminB );
785 //double zmax = max( zmaxA, zmaxB );
787 CurveUZ midA(0, gp_Vec2d(), 0), midB(0, gp_Vec2d(), 0);
788 CurveUZ widA(0, gp_Vec2d(), 0), widB(0, gp_Vec2d(), 0);
790 ProfileDiscretization( theProfileA, theXCurvA, zminA, zminA+hmax, theDDZ, midA, widA, inter_nb_1 );
791 ProfileDiscretization( theProfileB, theXCurvB, zminB, zminB+hmax, theDDZ, midB, widB, inter_nb_2 );
793 std::vector<CurveUZ> mid, wid;
794 Interpolate( midA, midB, theNbSteps, mid, isAddSecond );
795 Interpolate( widA, widB, theNbSteps, wid, isAddSecond );
797 size_t p = mid.size();
798 size_t q = p>0 ? 2*mid[0].size() : 1;
799 std::vector<AltitudePoints> points;
802 for( size_t i=0; i<p; i++ )
804 points[i].reserve( q );
805 CurveTo3D( theHydraulicAxis, mid[i], wid[i], points[i] );
811 HYDROData_Bathymetry::AltitudePoints HYDROData_DTM::Interpolate
812 ( const std::vector<Handle_HYDROData_Profile>& theProfiles,
813 double theDDZ, double theSpatialStep,
814 AltitudePoints& theLeft,
815 AltitudePoints& theRight,
816 std::vector<AltitudePoints>& theMainProfiles,
817 std::set<int>& invalInd)
819 AltitudePoints points;
820 size_t n = theProfiles.size();
824 std::vector<double> distances;
825 Handle_Geom2d_BSplineCurve aHydraulicAxis = CreateHydraulicAxis( theProfiles, distances );
826 if( aHydraulicAxis.IsNull() )
829 theMainProfiles.reserve( n );
831 for( size_t i=0, n1=n-1; i<n1; i++ )
833 double aDistance = distances[i+1]-distances[i];
834 int aNbSteps = int(aDistance/theSpatialStep);
835 bool isAddSecond = i==n1-1;
837 // 1. Calculate interpolated profiles
838 int inter_nb_1, inter_nb_2;
839 std::vector<AltitudePoints> local_points = Interpolate( aHydraulicAxis, theProfiles[i], distances[i],
840 theProfiles[i+1], distances[i+1], theDDZ, aNbSteps, isAddSecond, inter_nb_1, inter_nb_2 );
841 int lps = local_points.size();
847 invalInd.insert(i+1);
849 // 2. Put all points into the global container
850 for( size_t j=0; j<lps; j++ )
852 const AltitudePoints& lp = local_points[j];
854 points.reserve( lp.size() * n );
855 for( size_t k=0, ks=lp.size(); k<ks; k++ )
856 points.push_back( lp[k] );
859 // 3. Get left/right banks' points
862 theLeft.reserve( lps * n );
863 theRight.reserve( lps * n );
865 for( size_t j=0; j<lps; j++ )
867 const AltitudePoints& lp = local_points[j];
868 theLeft.push_back( lp[0] );
869 theRight.push_back( lp[lp.size()-1] );
872 // 4. Get main profiles points
873 theMainProfiles.push_back( local_points[0] );
875 theMainProfiles.push_back( local_points[lps-1] );
880 int HYDROData_DTM::EstimateNbPoints( const std::vector<Handle_HYDROData_Profile>& theProfiles,
881 double theDDZ, double theSpatialStep )
883 size_t n = theProfiles.size();
886 if( theDDZ<1E-6 || theSpatialStep<1E-6 )
889 std::vector<double> distances;
890 Handle_Geom2d_BSplineCurve aHydraulicAxis = CreateHydraulicAxis( theProfiles, distances );
891 if( aHydraulicAxis.IsNull() )
894 double aCompleteDistance = distances[n-1];
895 int aNbSteps = int( aCompleteDistance / theSpatialStep ) + 1;
899 GetProperties( theProfiles[0], aLowest, aDir, true, aZMin, aZMax );
900 int aNbZSteps = (aZMax-aZMin)/theDDZ;
902 if( aNbSteps > ( 1<<16 ) || aNbZSteps > ( 1<<16 ) )
905 return aNbSteps * aNbZSteps;