]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
for DTM
authorisn <isn@opencascade.com>
Thu, 6 Oct 2016 12:13:43 +0000 (15:13 +0300)
committerisn <isn@opencascade.com>
Thu, 6 Oct 2016 12:13:43 +0000 (15:13 +0300)
src/HYDROData/HYDROData_DTM.cxx
src/HYDROData/HYDROData_DTM.h
src/HYDROData/HYDROData_Stream.cxx
src/HYDROData/HYDROData_Stream.h
src/HYDRO_tests/test_HYDROData_Stream.cxx

index 61e1f6be39878d998fb5210fbbf73b5263abeaa5..036936fcc10d1dadc69330289cd498bce1e23284 100644 (file)
@@ -389,26 +389,14 @@ std::vector<Handle_Geom2d_Curve> HYDROData_DTM::ProfileToParametric(
 }
 
 
-double CalcGC( const std::vector<gp_Pnt2d>& 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<gp_Pnt2d>& intersections )
+bool CalcMidWidth( const std::vector<gp_Pnt2d>& intersections, double& theMid, double& theWid )
 {
   double umin = std::numeric_limits<double>::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<gp_Pnt2d>& 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 <BRepLib_MakeEdge2d.hxx>
 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 <BRepLib_MakeWire.hxx>
+
 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; i<p; i++ )
     CurveTo3D( theHydraulicAxis, mid[i], wid[i], points, theLeft, theRight, dz );
 
+  BRepLib_MakeWire WM;
+  for (int i =0; i < theLeft->myPoints.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; i<n1; i++ )
   {
     double aDistance = distances[i+1]-distances[i];
-    aNbStepsComplete += ( int(aDistance/theSpatialStep) + 1 );
+    aNbStepsComplete += ( int(aDistance/theSpatialStep) /*+ 1*/ );
   }
   if( theLeft )
     theLeft->reserve( aNbStepsComplete );
@@ -656,7 +655,7 @@ HYDROData_Bathymetry::AltitudePoints HYDROData_DTM::Interpolate
   for( size_t i=0, n1=n-1; i<n1; i++ )
   {
     double aDistance = distances[i+1]-distances[i];
-    int aNbSteps = int(aDistance/theSpatialStep) + 1;
+    int aNbSteps = int(aDistance/theSpatialStep) /*+ 1*/;
     bool isAddSecond = i==n1-1;
 
     AltitudePoints local_points = Interpolate( aHydraulicAxis, theProfiles[i], distances[i], 
index 22bdcaa7dc6ea943c6a3951b7faa1a1006e91e9b..4a78ed7f4502be5ec473039d9c3c60772f631118 100644 (file)
@@ -94,7 +94,7 @@ public:
     void clear();
     TopoDS_Edge createEdge3d() const;
 
-  private:
+  public:
     std::vector<gp_Pnt> myPoints;
     std::vector<gp_Dir> myDirs;
   };
index 1d76a26aaf8755d38ebd5d5941e309423a29980e..6713b4f705872355b37c71959a9179c29ebe5140 100644 (file)
@@ -199,7 +199,8 @@ bool HYDROData_Stream::CreatePresentations( const Handle_HYDROData_DTM& theDTM,
   if( profiles.Length() < 2 )
     return false;
 
-  TopTools_ListOfShape profiles3d;
+  std::vector<TopoDS_Wire> 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 <Geom_TrimmedCurve.hxx>
 #include <Geom_Plane.hxx>
 #include <BRepTools.hxx>
-static void ProjEdgeOnPlane(const TopoDS_Edge& inpEdge, const Handle_Geom_Plane& RefPlane, TopoDS_Edge& outSh, TopoDS_Vertex V1, TopoDS_Vertex V2)
+#include <BRepTools_WireExplorer.hxx>
+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<TopoDS_Edge>& theProfiles3d,
+                                            const std::vector<TopoDS_Wire>& 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<TopoDS_Edge> 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() ) {
index eb96c872ea8070730e17cc8ea3e928e80b28642b..7abc7c299b94730c6b3a22911b830413b201de6e 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <TopoDS_Face.hxx>
 #include <TopoDS_Edge.hxx>
+#include <TopoDS_Wire.hxx>
 
 #include <Geom_BSplineCurve.hxx>
 #include <vector>
@@ -88,7 +89,7 @@ public:
    */
   HYDRODATA_EXPORT static bool CreatePresentations( const TopoDS_Edge&          theLeftBank,
                                                     const TopoDS_Edge&          theRightBank,
-                                                    const std::vector<TopoDS_Edge>& theProfiles3d,
+                                                    const std::vector<TopoDS_Wire>& theProfiles3d,
                                                     PrsDefinition&              thePrs );
 
 public:
index e3754b2e55ec03446b16b96eb5076e50a0200738..3fe4109af9ca251fb30823784b2213408973f8e8 100644 (file)
@@ -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();