]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Use discretization to write non-linear borders of LCM to SHP file // p.1
authorisn <isn@opencascade.com>
Mon, 16 Nov 2015 18:13:45 +0000 (21:13 +0300)
committerisn <isn@opencascade.com>
Mon, 16 Nov 2015 18:13:45 +0000 (21:13 +0300)
src/HYDROData/HYDROData_ShapeFile.cxx
src/HYDROData/HYDROData_ShapeFile.h

index 9f2608fc3da51a94a2c7b59452a610ef1678679f..b2c30411aa0ab03c46fb8765d5089b6fde6fc555 100644 (file)
@@ -54,6 +54,8 @@
 #include <NCollection_List.hxx>
 #include <GC_MakeSegment.hxx>
 #include <BRep_Builder.hxx>
+#include <BRepAdaptor_Curve.hxx>
+#include <GCPnts_QuasiUniformDeflection.hxx>
 
 #ifdef WIN32
   #pragma warning( disable: 4996 )
@@ -243,7 +245,8 @@ int HYDROData_ShapeFile::WriteObjectPolygon(SHPHandle theShpHandle, const TopoDS
  
 }
 
-void HYDROData_ShapeFile::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle)
+void HYDROData_ShapeFile::ProcessFace(const TopoDS_Face& theFace, SHPHandle theShpHandle,
+                                      bool bUseDiscr, double theDefl )
 {
   if (theFace.ShapeType() != TopAbs_FACE)
      return;
@@ -264,7 +267,6 @@ void HYDROData_ShapeFile::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandl
     aWires.Append(aW); 
   }
 
-  //TopExp_Explorer Ex(theFace, TopAbs_WIRE);
   int NbWires = 0;
   for (int k = 1; k <= aWires.Length(); k++) 
   {
@@ -290,11 +292,26 @@ void HYDROData_ShapeFile::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandl
     for (Standard_Integer i = 1; i <= nbE; i++)
     {
       TopoDS_Edge E = aSEWD->Edge(i);
-      TopoDS_Vertex aV = TopExp::LastVertex(E, 1);
-      if (aV.IsNull())
-        continue;
-      gp_Pnt P = BRep_Tool::Pnt(aV);
-      aPnts.Append(gp_Pnt2d(P.X(), P.Y()));
+      if (bUseDiscr)
+      {
+        TopoDS_Vertex aV = TopExp::LastVertex(E, 1);
+        if (aV.IsNull())
+          continue;
+        gp_Pnt P = BRep_Tool::Pnt(aV);
+        aPnts.Append(gp_Pnt2d(P.X(), P.Y()));
+      }
+      else
+      {
+        BRepAdaptor_Curve Cur( E );
+        GCPnts_QuasiUniformDeflection Discr( Cur, theDefl );
+        if( !Discr.IsDone() )
+          continue; //skip all edge?
+        for( int i = 1; i <= Discr.NbPoints(); i++ )
+        {
+          gp_Pnt P = Discr.Value( i );
+          aPnts.Append(gp_Pnt2d(P.X(), P.Y()));
+        }
+      }
     }
     NCollection_Sequence<gp_Pnt2d> aNPnts;
     aNPnts.Append(aPnts.First());
@@ -304,7 +321,7 @@ void HYDROData_ShapeFile::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandl
         aNPnts.Append(aPnts(j + 1));
     }
 
-    //assume that the orientation of extrenal wire & internal wires is correct
+    //assume that the orientation of external wire & internal wires is correct
     //so just write all points "as-is"
     //External wire will be written in clockwise direction
     //any other wires (holes) - in anticlockwise direction
@@ -313,8 +330,10 @@ void HYDROData_ShapeFile::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandl
       x.push_back( aNPnts(j).X());
       y.push_back( aNPnts(j).Y()); 
     }
+    //first point is same as the last one => closed polygon
     x.push_back( aNPnts(1).X());
     y.push_back( aNPnts(1).Y()); 
+
   }
   
   aSHPObj = SHPCreateObject( SHPT_POLYGON, -1, NbWires, &anPartStart[0], NULL, x.size(), &x[0], &y[0], NULL, NULL );
@@ -385,7 +404,7 @@ void HYDROData_ShapeFile::ReadSHPPolygon(SHPObject* anObj, int i, TopoDS_Face& F
     BRepBuilderAPI_MakeFace aDB(pln, W);
     TopoDS_Face aDummyFace = TopoDS::Face(aDB.Shape());
     BRepTopAdaptor_FClass2d FClass(aDummyFace, Precision::PConfusion());
-    if ( i == 0 && FClass.PerformInfinitePoint() == TopAbs_OUT) 
+    if ( i == 0 && FClass.PerformInfinitePoint() != TopAbs_OUT) 
       W.Reverse();
     if ( i > 0 && FClass.PerformInfinitePoint() != TopAbs_IN) 
       W.Reverse();
index ec7b0ff3602caf610bfc6fbb30c7f696ec31e864..4046f0b8562466173ccb70b81164bf39b118da45 100644 (file)
@@ -131,7 +131,9 @@ public:
   HYDRODATA_EXPORT bool DBF_WriteFieldAndValues(const QString& theFileName, const QString& theFieldName, DBF_FieldType theType, const std::vector<DBF_AttrValue>& theAttrV, bool bUseStrValue);
 
 private:
-  void ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle);
+  
+  void ProcessFace(const TopoDS_Face& theFace, SHPHandle theShpHandle,
+                   bool bUseDiscr = false, double theDefl = 0.1);
 
   int TryOpenShapeFile(QString theFileName);