From: isn Date: Mon, 16 Nov 2015 18:13:45 +0000 (+0300) Subject: Use discretization to write non-linear borders of LCM to SHP file // p.1 X-Git-Tag: v1.5~37^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1ffac64bed30636e9d4043786b70720ad8ac4ade;p=modules%2Fhydro.git Use discretization to write non-linear borders of LCM to SHP file // p.1 --- diff --git a/src/HYDROData/HYDROData_ShapeFile.cxx b/src/HYDROData/HYDROData_ShapeFile.cxx index 9f2608fc..b2c30411 100644 --- a/src/HYDROData/HYDROData_ShapeFile.cxx +++ b/src/HYDROData/HYDROData_ShapeFile.cxx @@ -54,6 +54,8 @@ #include #include #include +#include +#include #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 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(); diff --git a/src/HYDROData/HYDROData_ShapeFile.h b/src/HYDROData/HYDROData_ShapeFile.h index ec7b0ff3..4046f0b8 100644 --- a/src/HYDROData/HYDROData_ShapeFile.h +++ b/src/HYDROData/HYDROData_ShapeFile.h @@ -131,7 +131,9 @@ public: HYDRODATA_EXPORT bool DBF_WriteFieldAndValues(const QString& theFileName, const QString& theFieldName, DBF_FieldType theType, const std::vector& 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);