X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_LandCoverMap.cxx;h=1ecf2586848aa701f27cc82bfbe4946822b6095e;hb=ef808bb1b445ecb9dec6ebc5030eaf63a00c3763;hp=8f257c79df3c7a623739ff0c014cf619b1e527f5;hpb=7b0a8d9a2ff1f97785ebefd2ee38ff6fa190bfe6;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index 8f257c79..1ecf2586 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -60,13 +61,19 @@ #include #include #include +#include +#include +#include #include #include #include #include +#define _DEVDEBUG_ +#include "HYDRO_trace.hxx" + const char TELEMAC_FORMAT = 'f'; const int TELEMAC_PRECISION = 3; @@ -361,7 +368,8 @@ bool EdgeDiscretization( const TopoDS_Edge& theEdge, */ bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName, double theDeflection, - const Handle(HYDROData_StricklerTable)& theTable ) const + const Handle(HYDROData_StricklerTable)& theTable, + QString& statMessage) const { TopoDS_Shape aLandCoverMapShape = GetShape(); TopTools_ListOfShape aListOfFaces; @@ -412,7 +420,19 @@ bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName, QFile aFile( theFileName ); if( !aFile.open( QFile::WriteOnly | QFile::Text ) ) - return false; + { + QString homeFilePath = QDir::home().absoluteFilePath( theFileName ); + aFile.setFileName(homeFilePath); + if (aFile.open( QFile::WriteOnly | QFile::Text ) ) + statMessage = "Telemac file have been exported to the home directory: " + homeFilePath; + else + return false; + } + else + { + QString absFilePath = QDir::current().absoluteFilePath( theFileName ); + statMessage = "Telemac file have been exported to the current directory: " + absFilePath; + } QTextStream aStream( &aFile ); aStream << "# nodes\n"; @@ -641,6 +661,7 @@ TopoDS_Shape HYDROData_LandCoverMap::MergeFaces( const TopTools_ListOfShape& the TopTools_IndexedDataMapOfShapeListOfShape* theShHistory, double theTolerance) { + //DEBTRACE("MergeFaces"); int anError; TopTools_ListIteratorOfListOfShape anIt; BOPCol_ListOfShape aLC; @@ -825,6 +846,7 @@ bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, co aShapesList.Append( anIt.Face() ); aShapesList.Append( theNewShape ); + //DEBTRACE("theNewType " << theNewType); if( aShapesList.Size()==1 && theNewShape.ShapeType()==TopAbs_FACE ) { aNewFaces.Add( TopoDS::Face( theNewShape ), theNewType ); @@ -862,6 +884,7 @@ bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, co for( ; aMIt.More(); aMIt.Next() ) { //std::cout << " " << aMIt.Value() << std::endl; + //DEBTRACE(aMIt.Value()); int aKey = (int)(uintptr_t)aMIt.Value().TShape().operator->(); aShapesFromNewFace.Add( aKey ); } @@ -871,11 +894,13 @@ bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, co for( ; anIt.More(); anIt.Next() ) { QString aSType = anIt.StricklerType(); + //DEBTRACE(anIt.StricklerType() << " " << anIt.Face()); //std::cout << "from " << anIt.Face() << ": " << anIt.StricklerType() << std::endl; TopTools_ListOfShape aModified = aBuilder.Modified( anIt.Face() ); // if( aModified.Extent() == 0 ) aModified.Append( anIt.Face() ); + //DEBTRACE(anIt.StricklerType() << " " << anIt.Face()); TopTools_ListIteratorOfListOfShape aMIt( aModified ); for( ; aMIt.More(); aMIt.Next() ) @@ -888,14 +913,21 @@ bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, co if( isFace && !isAlsoFromNew ) aNewFaces.Add( TopoDS::Face( aShape ), aSType ); } + //DEBTRACE(anIt.StricklerType() << " " << anIt.Face()); } - // c. add the new shape if it is face with its type if( theNewShape.ShapeType()==TopAbs_FACE ) aNewFaces.Add( TopoDS::Face( theNewShape ), theNewType ); + //DEBTRACE(theNewShape << " " << theNewType); // convert map of shape to type to compound and list of types StoreLandCovers( aNewFaces ); + +// anIt.Init( *this ); +// for( ; anIt.More(); anIt.Next() ) +// { +// DEBTRACE(anIt.StricklerType() << " " << anIt.Face()); +// } return true; } @@ -907,6 +939,7 @@ void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStrickl { TopTools_ListOfShape aListOfFaces; + //DEBTRACE("theMap.Extent() " << theMap.Extent()); for( int i = 1; i <= theMap.Extent(); i++ ) { TopoDS_Face aFace = theMap.FindKey(i); @@ -916,6 +949,7 @@ void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStrickl } TopTools_IndexedDataMapOfShapeListOfShape ShHistory; + ShHistory.Clear(); TopoDS_Shape aResult; if( aListOfFaces.Extent() == 1 ) @@ -940,28 +974,57 @@ void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStrickl for( int i = 1; i <= theMap.Extent(); i++ ) { TopoDS_Face aFF = theMap.FindKey(i); + //DEBTRACE(" --- " << aFF); if( aFF.IsNull() ) continue; - TopTools_ListOfShape aLS = ShHistory.FindFromKey(aFF); + //DEBTRACE(ShHistory.IsEmpty()); + //DEBTRACE(aFF.Checked()); + TopTools_ListOfShape aLS; + try + { + aLS = ShHistory.FindFromKey(aFF); //TODO: bug to fix. Observed on an incomplete split of a face + } + catch (...) + { + DEBTRACE("TODO: bug to fix. Observed on an incomplete split of a face"); + //continue; // No, keep aLS empty and propagate the type of the original face + } if (aLS.IsEmpty()) { + //DEBTRACE("--- aLS.IsEmpty()"); QString aSType = theMap.FindFromKey(aFF); + //DEBTRACE(" --- " << aSType.toStdString()); if (ShF2FHistory.Contains(aFF)) - aChF2ST.Add(ShF2FHistory.FindFromKey(aFF), aSType); + { + //DEBTRACE("ShF2FHistory.FindFromKey(aFF) " << ShF2FHistory.FindFromKey(aFF)); + aChF2ST.Add(ShF2FHistory.FindFromKey(aFF), aSType); + } else - aChF2ST.Add(aFF, aSType); + { + //DEBTRACE("aFF " << aFF); + aChF2ST.Add(aFF, aSType); + } } else { + //DEBTRACE("--- !aLS.IsEmpty()"); TopTools_ListIteratorOfListOfShape anIt(aLS); for (; anIt.More(); anIt.Next()) { QString aSType = theMap.FindFromKey(aFF); + //DEBTRACE(" --- " << aSType.toStdString()); const TopoDS_Face& aMF = TopoDS::Face(anIt.Value()); - if (ShF2FHistory.Contains(aFF)) - aChF2ST.Add(ShF2FHistory.FindFromKey(aFF), aSType); + //if (ShF2FHistory.Contains(aFF)) + if (ShF2FHistory.Contains(aMF)) + { + //DEBTRACE("ShF2FHistory.FindFromKey(aMF) " << ShF2FHistory.FindFromKey(aFF)); + aChF2ST.Add(ShF2FHistory.FindFromKey(aMF), aSType); + } else - aChF2ST.Add(aFF, aSType); + { + //DEBTRACE("aMF " << aMF); + aChF2ST.Add(aMF, aSType); + } } } } @@ -976,6 +1039,7 @@ void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStrickl QString aST = ""; if (aChF2ST.Contains(aFace)) aST = aChF2ST.FindFromKey(aFace); + //DEBTRACE("aFace " << aFace << " aST " << aST.toStdString()); aSTypes << aST; } @@ -983,6 +1047,7 @@ void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStrickl int k = 0; foreach (QString aST, aSTypes) { + //DEBTRACE("aST " << aST.toStdString()); aTypes->SetValue( k, HYDROData_Tool::toExtString( aST ) ); k++; } @@ -1060,6 +1125,7 @@ QStringList HYDROData_LandCoverMap::DumpToPython( const QString& thePyScri void HYDROData_LandCoverMap::RemoveInternal(TopoDS_Shape& ShToRebuild, NCollection_IndexedDataMap* aF2FReplace) { + //DEBTRACE("RemoveInternal"); //Shape must be topologically correct TopExp_Explorer anExpF(ShToRebuild, TopAbs_FACE); // @@ -1102,6 +1168,10 @@ void HYDROData_LandCoverMap::RemoveInternal(TopoDS_Shape& ShToRebuild, NCollecti anExtReshape->Replace(aFK, aFV); ShToRebuild = anExtReshape->Apply(ShToRebuild); } +// for (int i = 1; i <= aF2FReplace->Extent(); i++) +// { +// DEBTRACE("aF2FReplace key,value " << aF2FReplace->FindKey(i) << " " << aF2FReplace->FindFromIndex(i)); +// } } @@ -1122,7 +1192,7 @@ bool HYDROData_LandCoverMap::ImportSHP( const QString& theSHPFileName, QStringList aPolyList; TopTools_SequenceOfShape aFaces; int aSHapeType = -1; - int Stat = anImporter.ImportPolygons(theSHPFileName, aPolyList, aFaces, aSHapeType); + int Stat = anImporter.ImportPolygons(HYDROData_Document::Document(1), theSHPFileName, aPolyList, aFaces, aSHapeType); // if (Stat != 1) return false; @@ -1163,7 +1233,7 @@ bool HYDROData_LandCoverMap::ExportSHP( const QString& theSHPFileName, bool bUse { HYDROData_ShapeFile anExporter; QStringList aList; - anExporter.Export(theSHPFileName, this, aList, bUseDiscr, theDefl ); + anExporter.Export(HYDROData_Document::Document(1), theSHPFileName, this, aList, bUseDiscr, theDefl ); if (aList.empty()) return true; else @@ -1195,3 +1265,45 @@ bool HYDROData_LandCoverMap::CheckLinear() } return true; } + +void HYDROData_LandCoverMap::UpdateLocalCS( double theDx, double theDy ) +{ + TopoDS_Shape aShape = GetShape(); + TopoDS_Shape aLocatedShape = HYDROData_ShapesTool::Translated( aShape, theDx, theDy, 0 ); + SetShape( aLocatedShape ); +} + +void HYDROData_LandCoverMap::ClassifyPoints( const std::vector& thePoints, std::vector >& theTypes ) const +{ + HYDROData_LCM_FaceClassifier FC(this); + FC.Classify(thePoints, theTypes, NULL); +} + +void HYDROData_LandCoverMap::ClassifyPoints( const std::vector& thePoints, + Handle(HYDROData_StricklerTable) theTable, + std::vector& theCoeffs, double DefValue, bool UseMax ) const +{ + std::vector > Types; + HYDROData_LCM_FaceClassifier FC(this); + FC.Classify(thePoints, Types, NULL); + theCoeffs.resize(thePoints.size()); + for (size_t i = 0; i < Types.size(); i++) + { + const std::set& SStr = Types[i]; + if (SStr.empty()) + theCoeffs[i] = DefValue; + else + { + std::set::const_iterator it; + std::vector C1; + for (it = SStr.begin(); it != SStr.end(); ++it) + C1.push_back(theTable->Get( *it, DefValue )); + double Val; + if (UseMax) + Val = *(std::max_element( C1.begin(), C1.end() ) ); + else + Val = *(std::min_element( C1.begin(), C1.end() ) ); + theCoeffs[i] = Val; + } + } +}