Salome HOME
refs #2002
authorisn <isn@opencascade.com>
Fri, 7 Jun 2019 11:45:39 +0000 (14:45 +0300)
committerisn <isn@opencascade.com>
Fri, 7 Jun 2019 13:17:57 +0000 (16:17 +0300)
swap LB/RB points of profile depending on orientation of profile relative to h.axis

src/HYDROData/HYDROData_StreamLinearInterpolation.cxx

index 9cecdf096761059c2fddb18e0c7b01662e92b813..68a06bac127b06c3d290ff82894f98035755ee6a 100644 (file)
@@ -168,6 +168,7 @@ static void PolyToCurve2d(const Handle(HYDROData_PolylineXY)& poly, Handle(Geom2
 static void InterProfilesAndHAX(const HYDROData_SequenceOfObjects& profiles, 
   const Handle(Geom2d_Curve)& Hax2d, 
   std::map<double, Handle(HYDROData_Profile)>& profToInterParam,
+  std::vector<bool>& paramToSwapFlag,
   std::vector<std::string>* warnings)
 {
   for (int i=1;i<=profiles.Size();i++)
@@ -185,6 +186,7 @@ static void InterProfilesAndHAX(const HYDROData_SequenceOfObjects& profiles,
       continue;
     }
     Handle(Geom2d_Line) lin2d = new Geom2d_Line(P1,gp_Dir2d(P2.XY()-P1.XY()));
+    gp_Dir2d prof_dir2d = lin2d->Direction();
 
     Geom2dAdaptor_Curve linAd(lin2d, 0, d);
     Geom2dAdaptor_Curve haxAd(Hax2d);
@@ -208,6 +210,15 @@ static void InterProfilesAndHAX(const HYDROData_SequenceOfObjects& profiles,
       continue; 
     }
     double param = isec.Point(1).ParamOnSecond();
+    gp_Pnt2d int_p2d;
+    gp_Vec2d vec_on_hax_intersec;
+    haxAd.D1(param, int_p2d, vec_on_hax_intersec);
+    gp_Dir2d d_hax(vec_on_hax_intersec);
+    double ang = d_hax.Angle(prof_dir2d);
+    if (ang>0)    
+      paramToSwapFlag.push_back(true);
+    else
+      paramToSwapFlag.push_back(false);
     profToInterParam[param] = aProfile;
   }
 }
@@ -368,6 +379,11 @@ void BuildFace(const std::map<double, std::pair<IntRes2d_IntersectionPoint, IntR
   }  
 }
 
+void reversePoints(std::vector<gp_Pnt2d>& points)
+{
+  std::reverse(points.begin(), points.end());
+}
+
 void HYDROData_StreamLinearInterpolation::Perform(const HYDROData_SequenceOfObjects& profiles,
   int pointsToInsert,
   double stepOnHA, 
@@ -394,8 +410,9 @@ void HYDROData_StreamLinearInterpolation::Perform(const HYDROData_SequenceOfObje
   }
 
   std::map<double, Handle(HYDROData_Profile)> InterParamToProf;
+  std::vector<bool> paramToSwapFlag;
   //profToInterParam is output param map: profile to intersection param on hydr.axis
-  InterProfilesAndHAX(profiles, Hax2d, InterParamToProf, warnings);
+  InterProfilesAndHAX(profiles, Hax2d, InterParamToProf, paramToSwapFlag, warnings);
   //
   std::vector<std::vector<gp_Pnt2d>> profilesPoints;
   profilesPoints.reserve(InterParamToProf.size());
@@ -490,6 +507,16 @@ void HYDROData_StreamLinearInterpolation::Perform(const HYDROData_SequenceOfObje
     InsertPoints(profilesPoints[i], nbPointsToInsert);
   }
 
+  for (int i=0;i<profilesPoints.size();i++)
+  {
+    bool toSwap = paramToSwapFlag[i];     
+    if (toSwap)
+    {
+      std::vector<gp_Pnt2d>& prof = profilesPoints[i];
+      reversePoints(prof);
+    }
+  }
+
   TopoDS_Compound cmp2d;
   if ( buildPresentationShapes)
   {