From e323dc450ed4a5632af036823bf091da74bd9b39 Mon Sep 17 00:00:00 2001 From: isn Date: Thu, 6 Oct 2016 15:13:43 +0300 Subject: [PATCH] for DTM --- src/HYDROData/HYDROData_DTM.cxx | 51 +++++++++++------------ src/HYDROData/HYDROData_DTM.h | 2 +- src/HYDROData/HYDROData_Stream.cxx | 42 +++++++++++++------ src/HYDROData/HYDROData_Stream.h | 3 +- src/HYDRO_tests/test_HYDROData_Stream.cxx | 7 +++- 5 files changed, 62 insertions(+), 43 deletions(-) diff --git a/src/HYDROData/HYDROData_DTM.cxx b/src/HYDROData/HYDROData_DTM.cxx index 61e1f6be..036936fc 100644 --- a/src/HYDROData/HYDROData_DTM.cxx +++ b/src/HYDROData/HYDROData_DTM.cxx @@ -389,26 +389,14 @@ std::vector HYDROData_DTM::ProfileToParametric( } -double CalcGC( const std::vector& intersections ) -{ - double u = 0; - size_t n = intersections.size(); - for( size_t i = 0; i < n; i++ ) - { - u += intersections[i].X(); - } - u /= n; - return u; -} - -double CalcWidth( const std::vector& intersections ) +bool CalcMidWidth( const std::vector& intersections, double& theMid, double& theWid ) { double umin = std::numeric_limits::max(), umax = -umin; size_t n = intersections.size(); if( n <= 1 ) - return 0; + return false; for( size_t i = 0; i < n; i++ ) { @@ -418,7 +406,9 @@ double CalcWidth( const std::vector& intersections ) if( u>umax ) umax = u; } - return umax-umin; + theMid = ( umin+umax )/2; + theWid = umax-umin; + return true; } void HYDROData_DTM::ProfileDiscretization( const Handle_HYDROData_Profile& theProfile, @@ -473,13 +463,15 @@ void HYDROData_DTM::ProfileDiscretization( const Handle_HYDROData_Profile& thePr if( intersections.size() >= 2 ) { - double u_mid = CalcGC( intersections ); + double u_mid, u_wid; + if( !CalcMidWidth( intersections, u_mid, u_wid ) ) + continue; + PointUZ p_mid; p_mid.U = u_mid; p_mid.Z = z; theMidPointCurve.push_back( p_mid ); - double u_wid = CalcWidth( intersections ); PointUZ p_wid; p_wid.U = u_wid; p_wid.Z = z; @@ -506,13 +498,14 @@ void HYDROData_DTM::Interpolate( const CurveUZ& theCurveA, const CurveUZ& theCur if( isAddSecond ) theInterpolation.push_back( theCurveB ); } - +#include void HYDROData_DTM::CurveTo3D( const Handle_Geom2d_BSplineCurve& theHydraulicAxis, const CurveUZ& theMidCurve, const CurveUZ& theWidthCurve, AltitudePoints& thePoints, Bank* theLeft, Bank* theRight, double dz ) { Geom2dAdaptor_Curve anAdaptor( theHydraulicAxis ); + TopoDS_Edge E2d = BRepLib_MakeEdge2d(theHydraulicAxis).Edge(); GCPnts_AbscissaPoint ap( anAdaptor, theMidCurve.Xcurv(), anAdaptor.FirstParameter() ); double aParam = ap.Parameter(); @@ -521,8 +514,8 @@ void HYDROData_DTM::CurveTo3D( const Handle_Geom2d_BSplineCurve& theHydraulicAxi anAdaptor.D1( aParam, point, tangent ); profile_dir.SetCoord( tangent.Y(), -tangent.X() ); profile_dir.Normalize(); - gp_Dir tangent_n( tangent.X(), tangent.Y(), dz ); - + gp_Dir tangent_n( tangent.X(), tangent.Y(), -dz ); + //gp_Dir tangent_n( 0, 0, 1 ); size_t n = theMidCurve.size(); double min_param = 1E+15; double max_param = -1E+15; @@ -532,8 +525,8 @@ void HYDROData_DTM::CurveTo3D( const Handle_Geom2d_BSplineCurve& theHydraulicAxi double param1 = theMidCurve[i].U - theWidthCurve[i].U / 2; double param2 = theMidCurve[i].U + theWidthCurve[i].U / 2; - gp_Pnt2d p1 = point.Translated( param1 * profile_dir / 2 ); - gp_Pnt2d p2 = point.Translated( param2 * profile_dir / 2 ); + gp_Pnt2d p1 = point.Translated( param1 * profile_dir); + gp_Pnt2d p2 = point.Translated( param2 * profile_dir); double z = theMidCurve[i].Z; @@ -565,13 +558,13 @@ void HYDROData_DTM::CurveTo3D( const Handle_Geom2d_BSplineCurve& theHydraulicAxi if( theLeft ) { - gp_Pnt2d left2d = point.Translated( min_param * profile_dir / 2 ); + gp_Pnt2d left2d = point/*.Translated( min_param * profile_dir )*/; gp_Pnt left( left2d.X(), left2d.Y(), z1 ); theLeft->push_back( left, tangent_n ); } if( theRight ) { - gp_Pnt2d right2d = point.Translated( max_param * profile_dir / 2 ); + gp_Pnt2d right2d = point.Translated( max_param * profile_dir ); gp_Pnt right( right2d.X(), right2d.Y(), z2 ); theRight->push_back( right, tangent_n ); } @@ -585,6 +578,8 @@ inline double max( double a, double b ) return b; } +#include + HYDROData_Bathymetry::AltitudePoints HYDROData_DTM::Interpolate ( const Handle_Geom2d_BSplineCurve& theHydraulicAxis, const Handle_HYDROData_Profile& theProfileA, @@ -623,6 +618,10 @@ HYDROData_Bathymetry::AltitudePoints HYDROData_DTM::Interpolate for( size_t i=0; imyPoints.size() - 1; i++) + WM.Add(BRepLib_MakeEdge(theLeft->myPoints[i], theLeft->myPoints[i+1]).Edge()); + TopoDS_Wire W = WM.Wire(); return points; } @@ -646,7 +645,7 @@ HYDROData_Bathymetry::AltitudePoints HYDROData_DTM::Interpolate for( size_t i=0, n1=n-1; ireserve( aNbStepsComplete ); @@ -656,7 +655,7 @@ HYDROData_Bathymetry::AltitudePoints HYDROData_DTM::Interpolate for( size_t i=0, n1=n-1; i myPoints; std::vector myDirs; }; diff --git a/src/HYDROData/HYDROData_Stream.cxx b/src/HYDROData/HYDROData_Stream.cxx index 1d76a26a..6713b4f7 100644 --- a/src/HYDROData/HYDROData_Stream.cxx +++ b/src/HYDROData/HYDROData_Stream.cxx @@ -199,7 +199,8 @@ bool HYDROData_Stream::CreatePresentations( const Handle_HYDROData_DTM& theDTM, if( profiles.Length() < 2 ) return false; - TopTools_ListOfShape profiles3d; + std::vector profiles3d; + profiles3d.reserve(profiles.Length()); // Pre-processing HYDROData_SequenceOfObjects::Iterator anIter( profiles ); @@ -212,7 +213,8 @@ bool HYDROData_Stream::CreatePresentations( const Handle_HYDROData_DTM& theDTM, continue; const TopoDS_Shape& aProfileShape = aProfile->GetShape3D(); - profiles3d.Append( aProfileShape ); + //TopExp_Explorer exp(aProfileShape, TopAbs_EDGE); + profiles3d.push_back( TopoDS::Wire(aProfileShape) ); } TopoDS_Edge aLeftBank, aRightBank; @@ -1036,21 +1038,31 @@ void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination, #include #include #include -static void ProjEdgeOnPlane(const TopoDS_Edge& inpEdge, const Handle_Geom_Plane& RefPlane, TopoDS_Edge& outSh, TopoDS_Vertex V1, TopoDS_Vertex V2) +#include +static void ProjEdgeOnPlane(const TopoDS_Wire& inpWire, const Handle_Geom_Plane& RefPlane, TopoDS_Wire& outWire, TopoDS_Vertex V1, TopoDS_Vertex V2) { - double f, l; - Handle(Geom_Curve) C3d = BRep_Tool::Curve(inpEdge, f, l); - Handle(Geom_Curve) ProjectedCurve = GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3d, f, l), RefPlane, RefPlane->Position().Direction(), Standard_True); - if (V1.IsNull() || V2.IsNull()) - outSh = BRepLib_MakeEdge(ProjectedCurve); //create new vertices - else - outSh = BRepLib_MakeEdge(ProjectedCurve, V1, V2); + BRepTools_WireExplorer ex(inpWire); + BRepLib_MakeWire WM; + for (;ex.More();ex.Next()) + { + const TopoDS_Edge& CE = ex.Current(); + double f, l; + Handle(Geom_Curve) C3d = BRep_Tool::Curve(CE, f, l); + Handle(Geom_Curve) ProjectedCurve = GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3d, f, l), RefPlane, RefPlane->Position().Direction(), Standard_True); + TopoDS_Edge ProjEdge = BRepLib_MakeEdge(ProjectedCurve); + WM.Add(ProjEdge); //auto sharing between edges if vertex is coincident + } + outWire = WM.Wire(); + //if (V1.IsNull() || V2.IsNull()) + // outSh = BRepLib_MakeEdge(ProjectedCurve); //create new vertices + //else + // outSh = BRepLib_MakeEdge(ProjectedCurve, V1, V2); } bool HYDROData_Stream::CreatePresentations( const TopoDS_Edge& theLeftBank, const TopoDS_Edge& theRightBank, - const std::vector& theProfiles3d, + const std::vector& theProfiles3d, PrsDefinition& thePrs ) { thePrs.myLeftBank = theLeftBank; @@ -1067,8 +1079,12 @@ bool HYDROData_Stream::CreatePresentations( const TopoDS_Edge& theLeftB thePrs.myPrs3D = aCmp; //3d pres + /*Handle_Geom_Plane RefPlane = new Geom_Plane(gp_Pnt(0,0,0), gp_Dir(0,0,1)); + TopoDS_Vertex V1, V2; + TopoDS_Wire W; + ProjEdgeOnPlane(theProfiles3d[0], RefPlane, W, V1, V2);*/ - Handle_Geom_Plane RefPlane = new Geom_Plane(gp_Pnt(0,0,0), gp_Dir(0,0,1)); + /* Handle_Geom_Plane RefPlane = new Geom_Plane(gp_Pnt(0,0,0), gp_Dir(0,0,1)); std::vector internProf; internProf.reserve(theProfiles3d.size() - 2); @@ -1098,7 +1114,7 @@ bool HYDROData_Stream::CreatePresentations( const TopoDS_Edge& theLeftB WM.Add(internProf[i]); TopoDS_Face outF = BRepLib_MakeFace(RefPlane, WM.Wire()).Face(); - thePrs.myPrs2D = outF; + thePrs.myPrs2D = outF;*/ return true; /*if ( theArrayOfFPnt.IsNull() || theArrayOfLPnt.IsNull() || theArrOfProfiles.IsNull() ) { diff --git a/src/HYDROData/HYDROData_Stream.h b/src/HYDROData/HYDROData_Stream.h index eb96c872..7abc7c29 100644 --- a/src/HYDROData/HYDROData_Stream.h +++ b/src/HYDROData/HYDROData_Stream.h @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -88,7 +89,7 @@ public: */ HYDRODATA_EXPORT static bool CreatePresentations( const TopoDS_Edge& theLeftBank, const TopoDS_Edge& theRightBank, - const std::vector& theProfiles3d, + const std::vector& theProfiles3d, PrsDefinition& thePrs ); public: diff --git a/src/HYDRO_tests/test_HYDROData_Stream.cxx b/src/HYDRO_tests/test_HYDROData_Stream.cxx index e3754b2e..3fe4109a 100644 --- a/src/HYDRO_tests/test_HYDROData_Stream.cxx +++ b/src/HYDRO_tests/test_HYDROData_Stream.cxx @@ -240,8 +240,11 @@ void test_HYDROData_Stream::test_presentation() HYDROData_Iterator it( aDoc, KIND_PROFILE ); for( int i=0; it.More(); it.Next(), i++ ) { - if( i>=25 && i<=35 ) + if( i>=31 && i<=32 ) + { + it.Current()->Update(); profiles.Append( Handle(HYDROData_Profile)::DownCast( it.Current() ) ); + } } Handle(HYDROData_Stream) aStream = @@ -249,7 +252,7 @@ void test_HYDROData_Stream::test_presentation() aStream->SetProfiles( profiles, false ); aStream->SetDDZ( 0.2 ); - aStream->SetSpatialStep( 2.0 ); + aStream->SetSpatialStep( 10 ); aStream->Update(); TopoDS_Shape aPrs3d = aStream->GetShape3D(); -- 2.39.2