From 4454864d484a0b0197d4a8aa061d4b4715676b46 Mon Sep 17 00:00:00 2001 From: asl Date: Fri, 16 Oct 2015 11:48:04 +0300 Subject: [PATCH] refs #673: edge discretization algorithm --- src/HYDROData/HYDROData_LandCoverMap.cxx | 46 ++++++++++++++++++++---- src/HYDROData/HYDROData_LandCoverMap.h | 2 +- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index 6f7ecb62..574b1e00 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -26,8 +26,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -191,11 +193,43 @@ bool HYDROData_LandCoverMap::ExportQGIS( const QString& theFileName ) const return false; } -void EdgeDiscretization( const TopoDS_Edge& theEdge, +int HashCode( const gp_Pnt& thePoint, const Standard_Integer theUpper ) +{ + int aHashX = HashCode( thePoint.X(), theUpper ); + int aHashY = HashCode( thePoint.Y(), theUpper ); + return (aHashX^aHashY)%theUpper; +} + +bool operator == ( const gp_Pnt& thePoint1, const gp_Pnt& thePoint2 ) +{ + return thePoint1.IsEqual( thePoint2, Precision::Confusion() ); +} + +bool EdgeDiscretization( const TopoDS_Edge& theEdge, + Standard_Real theDeflection, NCollection_IndexedMap& theVerticesMap, QList& theVerticesIds ) { - //TODO + BRepAdaptor_Curve aCurve( theEdge ); + GCPnts_QuasiUniformDeflection aDiscrete( aCurve, theDeflection ); + if( !aDiscrete.IsDone() ) + return false; + + int n = aDiscrete.NbPoints(); + for( int i=1; i<=n; i++ ) + { + gp_Pnt aPnt = aDiscrete.Value( i ); + int anId; + if( theVerticesMap.Contains( aPnt ) ) + anId = theVerticesMap.FindIndex( aPnt ); + else + { + anId = theVerticesMap.Size(); + theVerticesMap.Add( aPnt ); + } + theVerticesIds.append( anId ); + } + return true; } /** @@ -203,7 +237,7 @@ void EdgeDiscretization( const TopoDS_Edge& theEdge, @param theFileName the name of file @return if the export is successful */ -bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName ) const +bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName, Standard_Real theDeflection ) const { TopoDS_Shell aShell; //TODO: unite all the faces of land covers into the shell @@ -217,8 +251,8 @@ bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName ) const { TopoDS_Edge anEdge = TopoDS::Edge( anExp1.Current() ); QList aVerticesIdsList; - EdgeDiscretization( anEdge, aVerticesMap, aVerticesIdsList ); - anEdgesMap.Add( anEdge, aVerticesIdsList ); + if( EdgeDiscretization( anEdge, theDeflection, aVerticesMap, aVerticesIdsList ) ) + anEdgesMap.Add( anEdge, aVerticesIdsList ); } // add into the map all faces existing in the shell and correspondence between face and edges ids @@ -389,7 +423,7 @@ bool HYDROData_LandCoverMap::Merge( const TopTools_ListOfShape& theFaces, const // 2. to fuse the faces into the new face /*BOPAlgo_PaveFiller aPF; aPF.SetArguments( theFaces ); - aPF.SetFuzzyValue( 1E-2 ); + aPF.SetFuzzyValue( 1E-5 ); aPF.SetRunParallel( Standard_False ); aPF.Perform(); int iErr = aPF.ErrorStatus(); diff --git a/src/HYDROData/HYDROData_LandCoverMap.h b/src/HYDROData/HYDROData_LandCoverMap.h index 09ae68eb..fe79b2ec 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@ -73,7 +73,7 @@ public: bool ImportQGIS( const QString& theFileName ); bool ExportQGIS( const QString& theFileName ) const; - bool ExportTelemac( const QString& theFileName ) const; + bool ExportTelemac( const QString& theFileName, Standard_Real theDeflection ) const; bool Add( const Handle( HYDROData_Object )&, const QString& theType ); bool Add( const Handle( HYDROData_PolylineXY )&, const QString& theType ); -- 2.39.2