From c96dac5411d7604cba01e5ff7cd2d407ce96fd26 Mon Sep 17 00:00:00 2001 From: isn Date: Thu, 28 Mar 2019 20:03:07 +0300 Subject: [PATCH] lot 11 : another way to build 2d-face based on intermediate profiles only + additional warning info --- .../HYDROData_StreamLinearInterpolation.cxx | 171 ++++++++++-------- 1 file changed, 91 insertions(+), 80 deletions(-) diff --git a/src/HYDROData/HYDROData_StreamLinearInterpolation.cxx b/src/HYDROData/HYDROData_StreamLinearInterpolation.cxx index 11ef389f..b731c088 100644 --- a/src/HYDROData/HYDROData_StreamLinearInterpolation.cxx +++ b/src/HYDROData/HYDROData_StreamLinearInterpolation.cxx @@ -226,8 +226,9 @@ static void GetPointsOnBanks(const std::vector& gua_params, const Handle(Geom2d_Curve)& Hax2d, const Handle(Geom2d_Curve)& LB2d, const Handle(Geom2d_Curve)& RB2d, - std::map>& parToBankPoints, - std::vector* warnings) + std::map>& parToBankPoints, + std::vector* warnings, + const std::map>* intermParamToProfPair) { for(int i = 0; i < gua_params.size(); i++) { @@ -249,19 +250,35 @@ static void GetPointsOnBanks(const std::vector& gua_params, if (warnings && intL.NbPoints()==0 ) { std::string coord = (QString::number(p2d.X()) + ", "+QString::number(p2d.Y())).toStdString(); - warnings->push_back("no intersection between intermediate profile (point on h.axis:("+ coord +")) and left bank found; skipped"); + if (intermParamToProfPair && intermParamToProfPair->count(par) != 0) + { + std::string fpn = intermParamToProfPair->at(par).first->GetName().toStdString(); + std::string spn = intermParamToProfPair->at(par).second->GetName().toStdString(); + warnings->push_back("no intersection between intermediate profile (point on h.axis:("+ + coord +"), located between " + fpn + " & " + spn + ") and left bank found; skipped"); + } + else + warnings->push_back("no intersection between intermediate profile (point on h.axis:("+ coord +")) and left bank found; skipped"); } if (warnings && intR.NbPoints()==0) { std::string coord = (QString::number(p2d.X()) + ", "+QString::number(p2d.Y())).toStdString(); - warnings->push_back("no intersection between intermediate profile (point on h.axis:("+ coord +")) and right bank found; skipped"); + if (intermParamToProfPair && intermParamToProfPair->count(par) != 0) + { + std::string fpn = intermParamToProfPair->at(par).first->GetName().toStdString(); + std::string spn = intermParamToProfPair->at(par).second->GetName().toStdString(); + warnings->push_back("no intersection between intermediate profile (point on h.axis:("+ + coord +"), located between " + fpn + " & " + spn + ") and right bank found; skipped"); + } + else + warnings->push_back("no intersection between intermediate profile (point on h.axis:("+ coord +")) and right bank found; skipped"); } if ( intL.NbPoints()==0 || intR.NbPoints()==0) continue; - gp_Pnt2d aNearSolL, aNearSolR; + IntRes2d_IntersectionPoint aNearSolL, aNearSolR; double min_sq_dist = Precision::Infinite(); for (int j=1;j<=intL.NbPoints();j++) { @@ -269,7 +286,8 @@ static void GetPointsOnBanks(const std::vector& gua_params, if (min_sq_dist > sq_dist) { min_sq_dist = sq_dist; - aNearSolL = intL.Point(j); + //aNearSolL = intL.Point(j); + aNearSolL = intL.Intersector().Point(j); } } min_sq_dist = Precision::Infinite(); @@ -279,42 +297,18 @@ static void GetPointsOnBanks(const std::vector& gua_params, if (min_sq_dist > sq_dist) { min_sq_dist = sq_dist; - aNearSolR = intR.Point(j); + //aNearSolR = intR.Point(j); + aNearSolR = intR.Intersector().Point(j); } } - std::pair int_pair(aNearSolL, aNearSolR); + std::pair int_pair(aNearSolL, aNearSolR); parToBankPoints[par]=int_pair; } } -bool GetItersectionParam(const Handle(HYDROData_Profile)& aProfile, const Handle(Geom2d_Curve)& B2d, double& outIntersectionParam) -{ - gp_XY LP, RP; - aProfile->GetLeftPoint( LP, true, true ); - aProfile->GetRightPoint( RP, true, true ); - gp_Pnt2d P1(LP), P2(RP); - double d = P2.Distance(P1); - if (d < gp::Resolution()) - return false; - Handle(Geom2d_Line) lin2d = new Geom2d_Line(P1,gp_Dir2d(P2.XY()-P1.XY())); - - Geom2dAdaptor_Curve linAd(lin2d, 0, d); - Geom2dAdaptor_Curve BAd(B2d); - Geom2dInt_GInter isec( linAd, BAd, 1.0e-6, 1.0e-6); - if (!isec.IsDone()) - return false; - if (isec.NbPoints() == 0) - return false; - if (isec.NbPoints() > 1) - return false; - outIntersectionParam = isec.Point(1).ParamOnSecond(); - return true; -} - -void BuildFace(const Handle(HYDROData_Profile)& F_prof, - const Handle(HYDROData_Profile)& S_prof, +void BuildFace(const std::map>& parToBankPoints, const Handle(Geom2d_Curve)& LB2d, const Handle(Geom2d_Curve)& RB2d, HYDROData_Stream::PrsDefinition& prsDef) @@ -326,46 +320,49 @@ void BuildFace(const Handle(HYDROData_Profile)& F_prof, prsDef.myInlet.Nullify(); prsDef.myOutlet.Nullify(); - bool stat = true; double lb_1, lb_2, rb_1, rb_2; - stat = GetItersectionParam(F_prof, LB2d, lb_1) && GetItersectionParam(F_prof, RB2d, rb_1) - && GetItersectionParam(S_prof, LB2d, lb_2) && GetItersectionParam(S_prof, RB2d, rb_2); - if (stat) + lb_1 = parToBankPoints.begin()->second.first.ParamOnFirst(); + rb_1 = parToBankPoints.begin()->second.second.ParamOnFirst(); + + lb_2 = parToBankPoints.rbegin()->second.first.ParamOnFirst(); + rb_2 = parToBankPoints.rbegin()->second.second.ParamOnFirst(); + + //stat = GetItersectionParam(F_prof, LB2d, lb_1) && GetItersectionParam(F_prof, RB2d, rb_1) + // && GetItersectionParam(S_prof, LB2d, lb_2) && GetItersectionParam(S_prof, RB2d, rb_2); + + BRepBuilderAPI_MakeEdge2d LEM(LB2d, lb_1, lb_2); + if (!LEM.IsDone()) + return; + BRepBuilderAPI_MakeEdge2d REM(RB2d, rb_1, rb_2); + if (!REM.IsDone()) + return; + TopoDS_Edge LBE = LEM.Edge(); + TopoDS_Edge RBE = REM.Edge(); + if (LBE.IsNull() || RBE.IsNull()) + return; + BRepBuilderAPI_MakeEdge PFEM(BRep_Tool::Pnt(LEM.Vertex1()), BRep_Tool::Pnt(REM.Vertex1())); + BRepBuilderAPI_MakeEdge PLEM(BRep_Tool::Pnt(LEM.Vertex2()), BRep_Tool::Pnt(REM.Vertex2())); + if (!PFEM.IsDone()) + return; + if (!PLEM.IsDone()) + return; + TopoDS_Edge FProfE = PFEM.Edge(); + TopoDS_Edge SProfE = PLEM.Edge(); + BRepBuilderAPI_MakeWire WM(FProfE, LBE, SProfE, RBE); + if (WM.IsDone()) { - BRepBuilderAPI_MakeEdge2d LEM(LB2d, lb_1, lb_2); - if (!LEM.IsDone()) - return; - BRepBuilderAPI_MakeEdge2d REM(RB2d, rb_1, rb_2); - if (!REM.IsDone()) - return; - TopoDS_Edge LBE = LEM.Edge(); - TopoDS_Edge RBE = REM.Edge(); - if (LBE.IsNull() || RBE.IsNull()) - return; - BRepBuilderAPI_MakeEdge PFEM(BRep_Tool::Pnt(LEM.Vertex1()), BRep_Tool::Pnt(REM.Vertex1())); - BRepBuilderAPI_MakeEdge PLEM(BRep_Tool::Pnt(LEM.Vertex2()), BRep_Tool::Pnt(REM.Vertex2())); - if (!PFEM.IsDone()) - return; - if (!PLEM.IsDone()) - return; - TopoDS_Edge FProfE = PFEM.Edge(); - TopoDS_Edge SProfE = PLEM.Edge(); - BRepBuilderAPI_MakeWire WM(FProfE, LBE, SProfE, RBE); - if (WM.IsDone()) + TopoDS_Wire W = WM.Wire(); + BRepLib::BuildCurves3d(W); + BRepBuilderAPI_MakeFace FM(Geom_Plane(gp::XOY()).Pln(), WM.Wire()); + if (FM.IsDone()) { - TopoDS_Wire W = WM.Wire(); - BRepLib::BuildCurves3d(W); - BRepBuilderAPI_MakeFace FM(Geom_Plane(gp::XOY()).Pln(), WM.Wire()); - if (FM.IsDone()) - { - prsDef.myPrs2D = FM.Face(); - prsDef.myLeftBank = LBE; - prsDef.myRightBank = RBE; - prsDef.myInlet = FProfE; - prsDef.myOutlet = SProfE; - } + prsDef.myPrs2D = FM.Face(); + prsDef.myLeftBank = LBE; + prsDef.myRightBank = RBE; + prsDef.myInlet = FProfE; + prsDef.myOutlet = SProfE; } - } + } } void HYDROData_StreamLinearInterpolation::Perform(const HYDROData_SequenceOfObjects& profiles, @@ -427,14 +424,25 @@ void HYDROData_StreamLinearInterpolation::Perform(const HYDROData_SequenceOfObje std::vector> ParamsPerSegm; std::set::iterator it_params_hax = paramsOnHAX.begin(); std::map::iterator it_p = InterParamToProf.begin(); + // + std::map> intermParamToProfPair; //for warnings only + // it_p++; ParamsPerSegm.resize(profilesPoints.size()-1); for( int k=0; it_p != InterParamToProf.end(); ) { if (*it_params_hax < it_p->first) { - ParamsPerSegm[k].push_back(*it_params_hax); - it_params_hax++; + double val = *it_params_hax; + ParamsPerSegm[k].push_back(val); + it_params_hax++; + + it_p--; + const Handle(HYDROData_Profile)& cp = it_p->second; + it_p++; + const Handle(HYDROData_Profile)& np = it_p->second; + std::pair profPair(cp, np); + intermParamToProfPair[val] = profPair; } else { @@ -444,7 +452,7 @@ void HYDROData_StreamLinearInterpolation::Perform(const HYDROData_SequenceOfObje } ParamsPerSegm.back().push_back(*paramsOnHAX.rbegin()); // - std::map> parToBankPoints; + std::map> parToBankPoints; std::vector paramHAXVec; paramHAXVec.reserve(paramsOnHAX.size()); for( std::set::iterator it = paramsOnHAX.begin(); it != paramsOnHAX.end(); ++it ) @@ -453,13 +461,16 @@ void HYDROData_StreamLinearInterpolation::Perform(const HYDROData_SequenceOfObje Handle(Geom2d_Curve) LB2d, RB2d; PolyToCurve2d(LB, LB2d); PolyToCurve2d(RB, RB2d); - GetPointsOnBanks( paramHAXVec, Hax2d, LB2d, RB2d, parToBankPoints, warnings); + GetPointsOnBanks( paramHAXVec, Hax2d, LB2d, RB2d, parToBankPoints, warnings, &intermParamToProfPair); if (buildPresentationShapes) { - Handle(HYDROData_Profile) F_prof = InterParamToProf.begin()->second; - Handle(HYDROData_Profile) S_prof = InterParamToProf.rbegin()->second; - BuildFace(F_prof, S_prof, LB2d, RB2d, prsDef); + //parToBankPoints.begin()->second.; + //double lp1 = parToBankPoints.rbegin()->first; + + //Handle(HYDROData_Profile) F_prof = InterParamToProf.begin()->second; + //Handle(HYDROData_Profile) S_prof = InterParamToProf.rbegin()->second; + BuildFace(parToBankPoints, LB2d, RB2d, prsDef); } // @@ -520,9 +531,9 @@ void HYDROData_StreamLinearInterpolation::Perform(const HYDROData_SequenceOfObje { const std::vector& im_prof = IntermProf[m]; double param = it->second; - const std::pair& BB = parToBankPoints[param]; //param is included in map; no checks - gp_Pnt2d LP = BB.first; - gp_Pnt2d RP = BB.second; + const std::pair& BB = parToBankPoints[param]; //param is included in map; no checks + gp_Pnt2d LP = BB.first.Value(); + gp_Pnt2d RP = BB.second.Value(); HYDROData_ProfileUZ::PointsList pl; for (int k=0;k