From b4100f7bda1606e214941fd08309898082ab73e9 Mon Sep 17 00:00:00 2001 From: szy Date: Thu, 26 Dec 2013 13:25:07 +0000 Subject: [PATCH] 26.12.2013. Update of SplitToZonesTool + new Transform files. --- src/HYDROData/CMakeLists.txt | 2 + src/HYDROData/HYDROData_SplitToZonesTool.cxx | 285 ++++++++++--- src/HYDROData/HYDROData_Transform.cxx | 403 +++++++++++++++++++ src/HYDROData/HYDROData_Transform.h | 116 ++++++ 4 files changed, 757 insertions(+), 49 deletions(-) create mode 100644 src/HYDROData/HYDROData_Transform.cxx create mode 100644 src/HYDROData/HYDROData_Transform.h diff --git a/src/HYDROData/CMakeLists.txt b/src/HYDROData/CMakeLists.txt index 4ef25b8b..df55dbc0 100644 --- a/src/HYDROData/CMakeLists.txt +++ b/src/HYDROData/CMakeLists.txt @@ -40,6 +40,7 @@ set(PROJECT_HEADERS HYDROData_Stream.h HYDROData_StreamAltitude.h HYDROData_Tool.h + HYDROData_Transform.h HYDROData_VisualState.h HYDROData_Zone.h ) @@ -83,6 +84,7 @@ set(PROJECT_SOURCES HYDROData_Stream.cxx HYDROData_StreamAltitude.cxx HYDROData_Tool.cxx + HYDROData_Transform.cxx HYDROData_VisualState.cxx HYDROData_Zone.cxx ) diff --git a/src/HYDROData/HYDROData_SplitToZonesTool.cxx b/src/HYDROData/HYDROData_SplitToZonesTool.cxx index 04e212a7..a4312ab4 100644 --- a/src/HYDROData/HYDROData_SplitToZonesTool.cxx +++ b/src/HYDROData/HYDROData_SplitToZonesTool.cxx @@ -3,32 +3,43 @@ #include "HYDROData_PolylineXY.h" #include "HYDROData_ShapesGroup.h" - -#include +#include #include +#include #include - +#include #include #include -#include -#include +#include +#include #include +#include #include #include #include #include #include +#include #include #include #include #include +#include +#include +#include +#include +#include + + +typedef NCollection_Map HYDROData_MapOfShape; +typedef HYDROData_MapOfShape::Iterator HYDROData_MapIteratorOfMapOfShape; 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 +//#define DEB_SPLIT_TO_ZONES 1 #ifdef DEB_SPLIT_TO_ZONES #include #endif @@ -54,6 +65,29 @@ TopoDS_Face HYDROData_SplitToZonesTool::SplitData::Face() const return aResFace; } +Standard_Boolean buildLimFace(const TopoDS_Wire& theBndWire, TopoDS_Face& outFace) +{ + GProp_GProps G; + BRepGProp::LinearProperties(theBndWire,G); + const gp_Pnt& aCPnt = G.CentreOfMass(); + gp_Pln aPln; + BRepBuilderAPI_FindPlane fndPlane (theBndWire, Precision::Confusion()); + if(fndPlane.Found()) + aPln = fndPlane.Plane()->Pln(); + else + aPln = gp_Pln(aCPnt, gp::OZ().Direction()); + BRepBuilderAPI_MakeFace aMkFace(aPln, theBndWire); + if(aMkFace.IsDone()) { + outFace = aMkFace.Face(); + if(!outFace.IsNull()) { +#ifdef DEB_SPLIT_TO_ZONES +// BRepTools::Write(limFace,"FL.brep"); +#endif + return Standard_True; + } + } + return Standard_False; +} HYDROData_SplitToZonesTool::SplitDataList HYDROData_SplitToZonesTool::Split( const HYDROData_SequenceOfObjects& theObjectList, const HYDROData_SequenceOfObjects& theGroupsList, @@ -64,7 +98,7 @@ HYDROData_SplitToZonesTool::SplitDataList // Preparation. // Collect the object shapes to split. InputDataList will contain elements which will hold shape & name_of_shape. SplitDataList anInputSplitDataList; - //TCollection_AsciiString aNam("Faces_"); + TCollection_AsciiString aNam("Faces_"); for( int anIndex = 1, aLength = theObjectList.Length(); anIndex <= aLength; anIndex++ ) { Handle(HYDROData_Object) aGeomObj = @@ -75,8 +109,8 @@ HYDROData_SplitToZonesTool::SplitDataList TopoDS_Shape aShape = aGeomObj->GetTopShape(); if ( aShape.IsNull() ) continue; -//TCollection_AsciiString aName = aNam + anIndex + ".brep"; -//BRepTools::Write(aShape, aName.ToCString()); + //TCollection_AsciiString aName = aNam + anIndex + ".brep"; + //BRepTools::Write(aShape, aName.ToCString()); if ( aShape.ShapeType() == TopAbs_COMPOUND ) { // Create split data for each face contained in the compound @@ -132,7 +166,6 @@ HYDROData_SplitToZonesTool::SplitDataList anOutputSplitDataList.append(anInputGroupList); return anOutputSplitDataList; } - HYDROData_DataMapOfShapeListOfString aDM3; if(!anInputGroupList.isEmpty()) {// Old edge ==> List_Of_Names QStringList aListOfNames; @@ -146,15 +179,38 @@ HYDROData_SplitToZonesTool::SplitDataList BOPAlgo_PaveFiller* aPaveFiller = new BOPAlgo_PaveFiller(pA1); BOPAlgo_Builder* aBuilder = new BOPAlgo_Builder(pA2); BOPCol_ListOfShape aLS; + QStringList aListOfNames; + TopoDS_Compound aCmp; + BRep_Builder aBB; + aBB.MakeCompound(aCmp); 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); + aBB.Add(aCmp,aSh); + //TCollection_AsciiString aName = aNam + i + ".brep"; + //BRepTools::Write(aSh, aName.ToCString()); } + HYDROData_Transform sTool; + sTool.Clear(); + sTool.SetArgument(aCmp); + sTool.Detect(); + const Standard_Boolean bToTransform = sTool.ToTransform(); + Standard_Integer anErr(0); + sTool.SetToTransform(bToTransform); + sTool.Perform(); + anErr = sTool.ErrorStatus(); + if(anErr) + return anOutputSplitDataList; + const TopoDS_Shape& aResult = sTool.Shape(); + + /* + else { + BOP == aPaveFiller->SetArguments(aLS); aPaveFiller->Perform(); - Standard_Integer anErr = aPaveFiller->ErrorStatus(); + anErr = aPaveFiller->ErrorStatus(); if(anErr) return anOutputSplitDataList; BOPDS_PDS pDS = aPaveFiller->PDS(); @@ -163,16 +219,20 @@ HYDROData_SplitToZonesTool::SplitDataList aBuilder->Clear(); // Step 2. Split faces - BOPCol_ListIteratorOfListOfShape anIt(aPaveFiller->Arguments()); + BOPCol_ListIteratorOfListOfShape anIt(aLS); 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(); + aResult = aBuilder->Shape(); + } */ + if (aResult.IsNull()) return anOutputSplitDataList; BRepCheck_Analyzer aCheck (aResult); @@ -184,17 +244,17 @@ HYDROData_SplitToZonesTool::SplitDataList return anOutputSplitDataList; } #ifdef DEB_SPLIT_TO_ZONES - //BRepTools::Write(aResult, "SplitFacesV.brep"); + BRepTools::Write(aResult, "SplitFacesV.brep"); #endif // Step 3. Collect history HYDROData_DataMapOfShapeListOfShape aDM1; - anIt.Init(aLS); + BOPCol_ListIteratorOfListOfShape anIt(aLS); //TCollection_AsciiString aNamM ("EdgM_"); //TCollection_AsciiString aNamG ("EdgG_"); for (int i =1;anIt.More();anIt.Next(),i++) { Standard_Boolean foundF(Standard_False); - const TopTools_ListOfShape& aListOfNew = aBuilder->Modified(anIt.Value()); + const TopTools_ListOfShape& aListOfNew = /*aBuilder->*/sTool.Modified(anIt.Value()); if(!aListOfNew.IsEmpty()) foundF = Standard_True; TopTools_ListOfShape aList; @@ -202,7 +262,7 @@ HYDROData_SplitToZonesTool::SplitDataList for(;it.More();it.Next()) aList.Append(it.Value()); // Bug in History: partition should give only modified entities! => temporary solution is used - const TopTools_ListOfShape& aListOfGen = aBuilder->Generated(anIt.Value()); + const TopTools_ListOfShape& aListOfGen = /*aBuilder->*/sTool.Generated(anIt.Value()); if(!aListOfGen.IsEmpty()) foundF = Standard_True; it.Initialize(aListOfGen); @@ -217,7 +277,7 @@ HYDROData_SplitToZonesTool::SplitDataList TopExp_Explorer exp (anIt.Value(), TopAbs_EDGE); for (int j =1;exp.More();exp.Next(),j++) { Standard_Boolean foundE(Standard_False); - const TopTools_ListOfShape& aListM = aBuilder->Modified(exp.Current()); + const TopTools_ListOfShape& aListM = /*aBuilder->*/sTool.Modified(exp.Current()); //cout << "NB_EDGE_M = " << aListM.Extent() <Generated(exp.Current()); + const TopTools_ListOfShape& aListG = /*aBuilder->*/sTool.Generated(exp.Current()); if(aListG.Extent()) foundE = Standard_True; it.Initialize(aListG); for(int k=1;it.More();it.Next(),k++) { @@ -247,25 +307,159 @@ HYDROData_SplitToZonesTool::SplitDataList // aDM2: NewShape ==> 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); - } - } + // make limiting face + HYDROData_DataMapOfShapeListOfShape aDM4; + Standard_Boolean hasLimits(Standard_False); + if (! thePolyline.IsNull()) { + //const TopoDS_Shape aShape = thePolyline->GetShape(); + const TopoDS_Wire aBndWire = TopoDS::Wire(thePolyline->GetShape()); + if(!aBndWire.IsNull()) { + TopoDS_Face limFace; + if(buildLimFace(aBndWire, limFace)) { + TopoDS_Shape aComResult; + BRepAlgoAPI_Common mkCom(aResult, limFace); + if(mkCom.IsDone()) { + aComResult = mkCom.Shape(); + BRepCheck_Analyzer aCheck (aComResult); + if(aCheck.IsValid()) { +#ifdef DEB_SPLIT_TO_ZONES + BRepTools::Write(aComResult,"CommonV.brep"); +#endif + + hasLimits = Standard_True; // DM2 should filled here + HYDROData_MapOfShape aView; + TopExp_Explorer exp (aResult, TopAbs_FACE); + for (int i =1;exp.More();exp.Next(),i++) { + const TopoDS_Shape& aFace = exp.Current(); + if(!aFace.IsNull()) { + const TopTools_ListOfShape& aListOfNew = mkCom.Modified(aFace); + //cout << "Modified: " << aListOfNew.Extent() <myTreshold || + fabs(aYc)>myTreshold || + fabs(aZc)>myTreshold) { + myToTransform=!myToTransform; + } + // + aVec.SetCoord(-aXc, -aYc, -aZc); + myTrsf1.SetTranslation(aVec); + // + aVec.SetCoord(aXc, aYc, aZc); + myTrsf2.SetTranslation(aVec); +} +//======================================================================= +//function : ComputeTrsf +//purpose : +//======================================================================= +void HYDROData_Transform::ComputeTrsf() +{ + if (!myToTransform) { + gp_Trsf aTrsf; + // + myTrsf1=aTrsf; + myTrsf2=aTrsf; + } +} +//======================================================================= +//function : Transform1 +//purpose : +//======================================================================= +void HYDROData_Transform::Transform1() +{ + Standard_Boolean bIsDone; + // + myErrorStatus=0; + // + myTransform1=new BRepBuilderAPI_Transform(myTrsf1); + // + myTransform1->Perform(myArgument); + bIsDone=myTransform1->IsDone(); + if (!bIsDone) { + myErrorStatus=11; + return; + } +} +//======================================================================= +//function : BuildFuse +//purpose : +//======================================================================= +void HYDROData_Transform::BuildFuse() +{ + Standard_Integer iErr; + TopoDS_Iterator aIt; + BOPCol_ListOfShape aLC; + BOPAlgo_PaveFiller aPF; + // + myErrorStatus=0; + // + const TopoDS_Shape& aS1=myTransform1->Shape(); + // + aIt.Initialize(aS1); + for (; aIt.More(); aIt.Next()) { + const TopoDS_Shape& aS1x=aIt.Value(); + aLC.Append(aS1x); + } + // + aPF.SetArguments(aLC); + // + aPF.Perform(); + iErr=aPF.ErrorStatus(); + if (iErr) { + myErrorStatus=20; + return; + } + // + myBuilder=new BOPAlgo_Builder; + // + aIt.Initialize(aS1); + for (; aIt.More(); aIt.Next()) { + const TopoDS_Shape& aS1x=aIt.Value(); + myBuilder->AddArgument(aS1x); + } + // + myBuilder->PerformWithFiller(aPF); + iErr=myBuilder->ErrorStatus(); + if (iErr) { + myErrorStatus=21; + return; + } +} +//======================================================================= +//function : Transform2 +//purpose : +//======================================================================= +void HYDROData_Transform::Transform2() +{ + Standard_Boolean bIsDone; + // + myErrorStatus=0; + // + const TopoDS_Shape& aR1=myBuilder->Shape(); + // + myTransform2=new BRepBuilderAPI_Transform(myTrsf2); + // + myTransform2->Perform(aR1); + bIsDone=myTransform2->IsDone(); + if (!bIsDone) { + myErrorStatus=12; + return; + } + // + const TopoDS_Shape& aR2=myTransform2->Shape(); + // + myShape=aR2; +} +// +//======================================================================= +//function : Modified +//purpose : +//======================================================================= +const TopTools_ListOfShape& HYDROData_Transform::Modified + (const TopoDS_Shape& aS) +{ + TopTools_ListOfShape* pHistShapes; + TopTools_ListIteratorOfListOfShape aItLS; + // + pHistShapes=(TopTools_ListOfShape*)&myHistShapes; + pHistShapes->Clear(); + // + const TopTools_ListOfShape& aLS1=myTransform1->Modified(aS); + const TopoDS_Shape& aS1=aLS1.First(); + // + const TopTools_ListOfShape& aLS1B=myBuilder->Modified(aS1); + aItLS.Initialize(aLS1B); + for (; aItLS.More(); aItLS.Next()) { + const TopoDS_Shape& aS1B=aItLS.Value(); + const TopTools_ListOfShape& aLS2B=myTransform2->Modified(aS1B); + const TopoDS_Shape& aS2B=aLS2B.First(); + pHistShapes->Append(aS2B); + } + // + return myHistShapes; +} +//======================================================================= +//function : Generated +//purpose : +//======================================================================= +const TopTools_ListOfShape& HYDROData_Transform::Generated + (const TopoDS_Shape& aS) +{ + TopTools_ListOfShape* pHistShapes; + TopTools_ListIteratorOfListOfShape aItLS; + // + pHistShapes=(TopTools_ListOfShape*)&myHistShapes; + pHistShapes->Clear(); + // + const TopTools_ListOfShape& aLS1=myTransform1->Modified(aS); + const TopoDS_Shape& aS1=aLS1.First(); + // + const TopTools_ListOfShape& aLS1B=myBuilder->Generated(aS1); + aItLS.Initialize(aLS1B); + for (; aItLS.More(); aItLS.Next()) { + const TopoDS_Shape& aS1B=aItLS.Value(); + const TopTools_ListOfShape& aLS2B=myTransform2->Modified(aS1B); + const TopoDS_Shape& aS2B=aLS2B.First(); + pHistShapes->Append(aS2B); + } + // + return myHistShapes; +} +//======================================================================= +//function : IsDeleted +//purpose : +//======================================================================= +Standard_Boolean HYDROData_Transform::IsDeleted(const TopoDS_Shape& aS) +{ + Standard_Boolean bIsDeleted; + // + const TopTools_ListOfShape& aLS1=myTransform1->Modified(aS); + const TopoDS_Shape& aS1=aLS1.First(); + // + bIsDeleted=myBuilder->IsDeleted(aS1); + // + return bIsDeleted; +} +//======================================================================= +//function : HasDeleted +//purpose : +//======================================================================= +Standard_Boolean HYDROData_Transform::HasDeleted() +{ + return myBuilder->HasDeleted(); +} +//======================================================================= +//function : HasGenerated +//purpose : +//======================================================================= +Standard_Boolean HYDROData_Transform::HasGenerated() +{ + return myBuilder->HasGenerated(); +} +//======================================================================= +//function : HasModified +//purpose : +//======================================================================= +Standard_Boolean HYDROData_Transform::HasModified() +{ + return myBuilder->HasModified(); +} diff --git a/src/HYDROData/HYDROData_Transform.h b/src/HYDROData/HYDROData_Transform.h new file mode 100644 index 00000000..d0d6a4ea --- /dev/null +++ b/src/HYDROData/HYDROData_Transform.h @@ -0,0 +1,116 @@ +#ifndef HYDROData_Transform_HeaderFile +#define HYDROData_Transform_HeaderFile + +#include +#include +#include +#include + +#include + +#include +#include + +#include + +#include +#include + +#include +#include + +//======================================================================= +//class : HYDROData_Transform +//purpose : +//======================================================================= +class HYDROData_Transform : public BOPAlgo_BuilderShape +{ + public: + Standard_EXPORT + HYDROData_Transform(); + // + Standard_EXPORT + virtual ~HYDROData_Transform(); + // + Standard_EXPORT + void SetArgument(const TopoDS_Shape& theShape); + // + Standard_EXPORT + const TopoDS_Shape& Argument()const; + // + Standard_EXPORT + void SetToTransform(const Standard_Boolean theFlag); + // + Standard_EXPORT + Standard_Boolean ToTransform()const; + // + Standard_EXPORT + void SetTreshold(const Standard_Real theTreshold); + // + Standard_EXPORT + Standard_Real Treshold()const; + // + Standard_EXPORT + void Detect(); + // + Standard_EXPORT + virtual void Clear(); + // + Standard_EXPORT + virtual void Perform(); + // + // History + Standard_EXPORT + virtual const TopTools_ListOfShape& Generated + (const TopoDS_Shape& theShape); + // + Standard_EXPORT + virtual const TopTools_ListOfShape& Modified + (const TopoDS_Shape& theShape); + // + Standard_EXPORT + virtual Standard_Boolean IsDeleted + (const TopoDS_Shape& theShape); + // + Standard_EXPORT + virtual Standard_Boolean HasDeleted(); + // + Standard_EXPORT + virtual Standard_Boolean HasGenerated(); + // + Standard_EXPORT + virtual Standard_Boolean HasModified(); + // + // Inner content + protected: + Standard_EXPORT + virtual void CheckData(); + // + Standard_EXPORT + void Prepare(); + // + Standard_EXPORT + void Transform1(); + // + Standard_EXPORT + void Transform2(); + // + Standard_EXPORT + void BuildFuse(); + // + Standard_EXPORT + void ComputeTrsf(); + // + protected: + Standard_Boolean myToTransform; + Standard_Real myTreshold; + TopoDS_Shape myArgument; + // + gp_Trsf myTrsf1; + gp_Trsf myTrsf2; + BRepBuilderAPI_Transform* myTransform1; + BRepBuilderAPI_Transform* myTransform2; + BOPAlgo_Builder* myBuilder; +}; + +#endif -- 2.39.2