From 4c1ccf71f6e25cd39583d61dd7bea9b1db3eaa7f Mon Sep 17 00:00:00 2001 From: szy Date: Tue, 17 Dec 2013 14:58:27 +0000 Subject: [PATCH] 17.12.2013. Added Partition algorithm (draft version). --- src/HYDROData/HYDROData_SplitToZonesTool.cxx | 125 ++++++++++++++++++- 1 file changed, 121 insertions(+), 4 deletions(-) diff --git a/src/HYDROData/HYDROData_SplitToZonesTool.cxx b/src/HYDROData/HYDROData_SplitToZonesTool.cxx index a3fe087a..4960a9b7 100644 --- a/src/HYDROData/HYDROData_SplitToZonesTool.cxx +++ b/src/HYDROData/HYDROData_SplitToZonesTool.cxx @@ -11,7 +11,25 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +typedef NCollection_DataMap HYDROData_DataMapOfShapeListOfShape; +typedef HYDROData_DataMapOfShapeListOfShape::Iterator HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape; +typedef NCollection_DataMap HYDROData_DataMapOfShapeListOfString; +typedef HYDROData_DataMapOfShapeListOfString::Iterator HYDROData_DataMapIteratorOfDataMapOfShapeListOfString; +#undef _NCollection_MapHasher +#define DEB_SPLIT_TO_ZONES 1 +#ifdef DEB_SPLIT_TO_ZONES +#include +#endif TopoDS_Face HYDROData_SplitToZonesTool::SplitData::Face() const { TopoDS_Face aResFace; @@ -41,7 +59,7 @@ HYDROData_SplitToZonesTool::SplitDataList { SplitDataList anOutputSplitDataList; - // Preparation. Collect the object shapes to split. + // Preparation. Collect the object shapes to split. InputDataList will contain elements which will hold shape & name_of_shape. SplitDataList anInputSplitDataList; for( int anIndex = 1, aLength = theObjectList.Length(); anIndex <= aLength; anIndex++ ) { @@ -70,7 +88,106 @@ HYDROData_SplitToZonesTool::SplitDataList } } - // Step 1. Split the paths. + // Step 1. Prepare Partition structures. + Handle(NCollection_BaseAllocator) pA1 = new NCollection_IncAllocator, pA2 = new NCollection_IncAllocator; + BOPAlgo_PaveFiller* aPaveFiller = new BOPAlgo_PaveFiller(pA1); + BOPAlgo_Builder* aBuilder = new BOPAlgo_Builder(pA2); + BOPCol_ListOfShape aLS; + HYDROData_DataMapOfShapeListOfString aDM3; + QStringList aListOfNames; + for (int i=0;i < anInputSplitDataList.size() ;i++) { + const TopoDS_Shape& aSh = anInputSplitDataList.at(i).Shape; + aDM3.Bind(aSh, anInputSplitDataList.at(i).ObjectNames); + aLS.Append(aSh); + } + aPaveFiller->SetArguments(aLS); + aPaveFiller->Perform(); + Standard_Integer anErr = aPaveFiller->ErrorStatus(); + if(anErr) + return anOutputSplitDataList; + BOPDS_PDS pDS = aPaveFiller->PDS(); + if (!pDS) + return anOutputSplitDataList; + aBuilder->Clear(); + + // Step 2. Split faces + BOPCol_ListIteratorOfListOfShape anIt(aPaveFiller->Arguments()); + for (; anIt.More(); anIt.Next()) { + const TopoDS_Shape& aS = anIt.Value(); + aBuilder->AddArgument(aS); + } + aBuilder->PerformWithFiller(*aPaveFiller); + anErr = aBuilder->ErrorStatus(); + if(anErr) + return anOutputSplitDataList; + const TopoDS_Shape& aResult = aBuilder->Shape(); + if (aResult.IsNull()) + return anOutputSplitDataList; + BRepCheck_Analyzer aCheck (aResult); + if(!aCheck.IsValid()) { +#ifdef DEB_SPLIT_TO_ZONES + cout << "result is not valid" <Modified(anIt.Value()); + aDM1.Bind(anIt.Value(), aListOfNew); + //cout << "NB_Face = " << aList.Extent() <Modified(exp.Current()); + // cout << "NB_EDGE = " << aList2.Extent() < ListOfOldShapes + HYDROData_DataMapOfShapeListOfShape aDM2; + HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1); + for(;aMIt.More();aMIt.Next()) { + const TopoDS_Shape& aKey = aMIt.Key(); + TopTools_ListOfShape aList; + aList.Append(aKey); + const TopTools_ListOfShape& aListOfNew = aMIt.Value(); + TopTools_ListIteratorOfListOfShape it(aListOfNew); + for(;it.More();it.Next()) { + if(!aDM2.IsBound(it.Value())) + aDM2.Bind(it.Value(), aList); + else { + TopTools_ListOfShape& aList = aDM2.ChangeFind(it.Value()); + aList.Prepend(aKey); + } + } + } + + // Step 4. Fill output structure. + aMIt.Initialize(aDM2); + for(;aMIt.More();aMIt.Next()) { + const TopoDS_Shape& aKey = aMIt.Key(); //new + const TopTools_ListOfShape& aListOfOld = aMIt.Value(); + SplitData aDestSplitData; + QStringList aListOfNames; + TopTools_ListIteratorOfListOfShape it(aListOfOld); + for(;it.More();it.Next()) { + const TopoDS_Shape& aSh = it.Value(); //old + if(aDM3.IsBound(aSh)) { + const QStringList& ObjectNames = aDM3.Find(aSh); + aListOfNames.append(ObjectNames); + } + } + aDestSplitData.Shape = aKey; + aDestSplitData.ObjectNames = aListOfNames; + anOutputSplitDataList.append(aDestSplitData); + } + return anOutputSplitDataList; + /* SplitDataListIterator anInputIter( anInputSplitDataList ); while( anInputIter.hasNext() ) { @@ -143,8 +260,8 @@ HYDROData_SplitToZonesTool::SplitDataList const SplitData& anOutputSplitData = anOutputIter.next(); anExtractedSplitDataList.append( ExtractSeparateData( anOutputSplitData ) ); } - - return anExtractedSplitDataList; +*/ + // return anExtractedSplitDataList; } bool HYDROData_SplitToZonesTool::SplitTwoData( const SplitData& theData1, -- 2.39.2