]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
lot 14 -> add edges (which are inside boundary polygon of type 1) as a separate group...
authorisn <isn@opencascade.com>
Thu, 20 Dec 2018 13:21:06 +0000 (16:21 +0300)
committerisn <isn@opencascade.com>
Thu, 20 Dec 2018 14:04:30 +0000 (17:04 +0300)
Signed-off-by: isn <isn@opencascade.com>
src/HYDROData/HYDROData_BoundaryPolygonTools.cxx
src/HYDROData/HYDROData_BoundaryPolygonTools.h
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDRO_tests/test_HYDROData_BoundaryPolygons.cxx

index e9f44e44a961ce876f9f199bd09dea1b56009b97..6a98011f4d62d903bc986f8f86f81790e2565f1a 100644 (file)
@@ -37,6 +37,7 @@
 #include <NCollection_IndexedDataMap.hxx>
 #include <BOPAlgo_BOP.hxx>
 #include <BOPAlgo_Section.hxx>
+#include <TopTools_MapOfShape.hxx>
 
 
 #include <Basics_OCCTVersion.hxx>
@@ -86,6 +87,91 @@ static bool FindInterBySection(const TopoDS_Face& IncF, TopoDS_Shape poly)
   return IsInter;
 }
 
+bool HYDROData_BoundaryPolygonTools::CutTool( const TopTools_SequenceOfShape& CutTools, 
+                                              NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
+                                              NCollection_IndexedDataMap<TopoDS_Shape, TopTools_MapOfShape, TopTools_ShapeMapHasher>& BPFaceToCutEdges)
+{
+  BOPAlgo_Builder anAlgo;
+  TopTools_MapOfShape cuttedEdges; //all new edges (Obj) after cut
+
+  for (int i=1; i<= CutTools.Length();i++)
+    anAlgo.AddArgument(CutTools(i));
+
+  for (int i = 1; i <= ObjToRes.Extent(); i++ )
+  {
+    const TopoDS_Shape& Obj = ObjToRes.FindKey(i);
+    if (!Obj.IsNull())
+      anAlgo.AddArgument(Obj);
+  }
+
+  anAlgo.Perform(); 
+#if OCC_VERSION_LARGE > 0x07020000
+  if (anAlgo.HasErrors())
+    return false;
+#endif
+  TopoDS_Shape aRes = anAlgo.Shape();  
+  
+  BRep_Builder BB;
+  for (int i = 1; i <= ObjToRes.Extent(); i++ )
+  {
+    const TopoDS_Shape& Obj = ObjToRes.FindKey(i);
+    Standard_Real aTol;
+    if (!Obj.IsNull()) 
+    {
+      TopTools_ListOfShape ls = anAlgo.Modified(Obj);
+      TopoDS_Shape aRes;
+      if (ls.IsEmpty())
+      {
+        aRes = Obj; //no changes
+        cuttedEdges.Add(aRes);
+      }
+      else if (ls.Extent() == 1)
+      {
+        aRes = ls.First();
+        cuttedEdges.Add(aRes);
+      }
+      else
+      {
+        TopoDS_Compound cmp;
+        BB.MakeCompound(cmp);
+        TopTools_ListIteratorOfListOfShape aItLS(ls);
+        for (; aItLS.More(); aItLS.Next()) 
+        {
+          const TopoDS_Shape& val = aItLS.Value();
+          BB.Add(cmp, val);
+          cuttedEdges.Add(val);
+        }
+        aRes = cmp;
+      }  
+      ObjToRes.ChangeFromKey(Obj) = aRes;
+    }
+  }
+
+  //determine the source face 
+  for (int i = 1; i <= CutTools.Length(); i++ )
+  {
+    TopoDS_Shape F = CutTools(i);
+    TopTools_ListOfShape lsF = anAlgo.Modified(F);
+    if (lsF.IsEmpty())
+      lsF.Append(F);
+    TopoDS_Compound cmpF;
+    BB.MakeCompound(cmpF);
+    TopTools_ListIteratorOfListOfShape aItLS(lsF);
+    for (; aItLS.More(); aItLS.Next()) 
+      BB.Add(cmpF, aItLS.Value());
+    //cmpF is a compound if connected faces => modified of boudnary polygon F
+    TopExp_Explorer expE(cmpF, TopAbs_EDGE);
+    TopTools_MapOfShape cmpFEdges;
+    for (;expE.More();expE.Next())
+      cmpFEdges.Add(expE.Current());
+    cmpFEdges.Intersect(cuttedEdges);
+    BPFaceToCutEdges.Add(F, cmpFEdges);
+  }
+
+  return true;
+}
+
+/* OLD WAY
 bool HYDROData_BoundaryPolygonTools::CutTool( const TopTools_SequenceOfShape& CutTools, 
                                               NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes )
 {
@@ -156,7 +242,7 @@ bool HYDROData_BoundaryPolygonTools::CutTool( const TopTools_SequenceOfShape& Cu
   }
 
   return true;
-}
+}*/
 
 
 bool HYDROData_BoundaryPolygonTools::IncludeTool( const TopTools_SequenceOfShape& IncludeTools, 
index 70f4d60c514b52f7283de4aa0067044abb0df7f6..c18802c0cf183afc6dc48104947ed1fc04dd3971 100644 (file)
 #include "HYDROData.h"
 #include <TopTools_SequenceOfShape.hxx>
 #include <NCollection_IndexedDataMap.hxx>
-
+#include <TopTools_ShapeMapHasher.hxx>
+#include <TopTools_MapOfShape.hxx>
 
 class TopoDS_Shape;
 
-class HYDRODATA_EXPORT HYDROData_BoundaryPolygonTools {
+class HYDRODATA_EXPORT HYDROData_BoundaryPolygonTools 
+{
 
 public:
 
-  static bool CutTool( const TopTools_SequenceOfShape& CutTools, 
-                                         NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes );
+  static bool CutTool( const TopTools_SequenceOfShape& CutTools, NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
+                                              NCollection_IndexedDataMap<TopoDS_Shape, TopTools_MapOfShape, TopTools_ShapeMapHasher>& BPFaceToCutEdges );
 
   static bool IncludeTool( const TopTools_SequenceOfShape& IncludeTools, 
                                   TopoDS_Shape Obj);
index 0328afdc0ec8128d903ba3a6b7b4cff5e06c1527..9fb52a8f4081cbd14ed75a49545d58fad28effe2 100755 (executable)
@@ -33,6 +33,7 @@
 #include <HYDROData_Tool.h>
 #include <HYDROData_BCPolygon.h>
 #include <HYDROData_BoundaryPolygonTools.h>
+#include <HYDROData_SplitToZonesTool.h>
 
 #ifdef WIN32
   #pragma warning ( disable: 4251 )
@@ -321,10 +322,13 @@ static void FilterEdgesByIncludeSelectionBoundaryPolygons( const HYDROData_Split
 
 static void SplitEdgesByBoundaryPolygons( const HYDROData_SplitToZonesTool::SplitDataList& anEdgesList,
                                           const HYDROData_SequenceOfObjects& aBoundaryPolygons,
-                                          NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes)
+                                          NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
+                                          HYDROData_SplitToZonesTool::SplitDataList& outBoundaryPolygonEdgesList)
 {
   //perform boundary condition polygons on EdgesList
   TopTools_SequenceOfShape CutTools;
+  NCollection_DataMap<TopoDS_Shape, QString, TopTools_ShapeMapHasher> BPolyToName;
+
   ObjToRes.Clear();
   HYDROData_SplitToZonesTool::SplitDataListIterator anIter(anEdgesList);
   for (int i=1; i<=aBoundaryPolygons.Size();i++)
@@ -333,7 +337,11 @@ static void SplitEdgesByBoundaryPolygons( const HYDROData_SplitToZonesTool::Spli
     TopoDS_Shape aPolyTopShape = aBCPoly->GetTopShape();
     int bType = aBCPoly->GetBoundaryType();
     if (bType == 1) 
+    {
       CutTools.Append(aPolyTopShape);
+      QString bp_name = aBCPoly->GetName();
+      BPolyToName.Bind(aPolyTopShape, bp_name);
+    }
   }
   
   while( anIter.hasNext() )
@@ -346,12 +354,33 @@ static void SplitEdgesByBoundaryPolygons( const HYDROData_SplitToZonesTool::Spli
     ObjToRes.Add(aSplitData.Shape, TopoDS_Shape());
   }
 
-  HYDROData_BoundaryPolygonTools::CutTool(CutTools, ObjToRes);
+  NCollection_IndexedDataMap<TopoDS_Shape, TopTools_MapOfShape, TopTools_ShapeMapHasher> BPFaceToCutEdges;
+  HYDROData_BoundaryPolygonTools::CutTool(CutTools, ObjToRes, BPFaceToCutEdges);
+  //
+  for (int i = 1; i <= CutTools.Length(); i++ )
+  {
+    TopoDS_Shape F = CutTools(i);
+    const QString* name = BPolyToName.Seek(F);
+    const TopTools_MapOfShape* EdgesIn = BPFaceToCutEdges.Seek(F); // EdgesIn : edges inside boudnary polygon F
+    if (name && EdgesIn)
+    {
+      TopTools_MapIteratorOfMapOfShape it(*EdgesIn);
+      for (;it.More();it.Next())
+      {
+        TopoDS_Edge E = TopoDS::Edge(it.Value());
+        if (!E.IsNull())
+        {
+          HYDROData_SplitToZonesTool::SplitData SD(HYDROData_SplitToZonesTool::SplitData::Data_Edge, E, *name);          
+          outBoundaryPolygonEdgesList.append(SD);
+        }
+      }
+    }
+  }
 }
 
 
 static void PerformEdgeReplInZones(const HYDROData_SplitToZonesTool::SplitDataList& ZoneList,
-                                   const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes,
+                                   const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
                                    HYDROData_SplitToZonesTool::SplitDataList& outZoneList)
 {
   HYDROData_SplitToZonesTool::SplitDataListIterator it( ZoneList ); 
@@ -398,7 +427,7 @@ static void PerformEdgeReplInZones(const HYDROData_SplitToZonesTool::SplitDataLi
 }
 
 static void CreateNewEdgeList( const HYDROData_SplitToZonesTool::SplitDataList& theEdges,
-                               const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes,
+                               const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
                                HYDROData_SplitToZonesTool::SplitDataList& newEdges)
 {
   HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
@@ -467,9 +496,10 @@ void HYDROData_CalculationCase::Update()
   //split edges by boundary polygons
   HYDROData_SequenceOfObjects aBoundaryPolygons = GetBoundaryPolygons();
   //edge to splitted edge (compound of edges or original edge)
-  NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape> ObjToRes;
+  NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> ObjToRes;
   //split edge list by BP
-  SplitEdgesByBoundaryPolygons(anEdgesList, aBoundaryPolygons, ObjToRes);
+  HYDROData_SplitToZonesTool::SplitDataList outBoundaryPolygonEdgesList; //new groups - for each BP of type 1 (cut) create a group of edges which are inside of this BP
+  SplitEdgesByBoundaryPolygons(anEdgesList, aBoundaryPolygons, ObjToRes, outBoundaryPolygonEdgesList);
   HYDROData_SplitToZonesTool::SplitDataList aNewZonesList;
   //replace splitted edges in zone list (faces)
   PerformEdgeReplInZones(aZonesList, ObjToRes, aNewZonesList);
@@ -477,6 +507,8 @@ void HYDROData_CalculationCase::Update()
   //create new edges list based on splitting info from ObjToRes
   HYDROData_SplitToZonesTool::SplitDataList newEdgesList1,newEdgesList2;
   CreateNewEdgeList(anEdgesList, ObjToRes, newEdgesList1);
+  //
+  newEdgesList1.append(outBoundaryPolygonEdgesList); //append new list of groups
   //filter out edges list by include&selection tools 
   FilterEdgesByIncludeSelectionBoundaryPolygons(newEdgesList1,aBoundaryPolygons,newEdgesList2);
   
index 18675aee835f2f119fed0aee03c5c6d224977593..1877e1a3be2408f93f6a3508f76edd03071acaed 100644 (file)
@@ -26,6 +26,7 @@
 #include <BRepGProp.hxx>
 #include <HYDROData_ShapesGroup.h>
 #include <HYDROData_BCPolygon.h>
+#include <TopExp_Explorer.hxx>
 
 extern QString REF_DATA_PATH;
 
@@ -44,15 +45,47 @@ void test_HYDROData_BoundaryPolygons::test_bp_1()
   aCase->Update();
   CPPUNIT_ASSERT_EQUAL(4, aCase->GetBoundaryPolygons().Size());
   HYDROData_SequenceOfObjects aSplitGroups = aCase->GetSplitGroups();
-  CPPUNIT_ASSERT_EQUAL(1, aSplitGroups.Size());
+  CPPUNIT_ASSERT_EQUAL(4, aSplitGroups.Size());
 
-  Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aSplitGroups.First() );
-  std::string name = aGroup->GetName().toStdString();
-  CPPUNIT_ASSERT_EQUAL( name, std::string("Case_1_Immersible zone_1_Outer") ); 
+  Handle(HYDROData_ShapesGroup) aGroup1;
+  TopTools_MapOfShape EdgesFromBPGroups;
+  for (int i=1; i<=4;i++)
+  {
+    Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aSplitGroups(i) );    
+    if (aGroup->GetName() == "Case_1_Immersible zone_1_Outer")
+    {
+      aGroup1 = aGroup;
+    }
+    else
+    {
+      TopTools_SequenceOfShape aSeqShapes1;
+      aGroup->GetShapes( aSeqShapes1 );
+      for (int j=1; j<=aSeqShapes1.Size();j++)
+      {
+        TopExp_Explorer exp(aSeqShapes1(j), TopAbs_EDGE);
+        for (;exp.More();exp.Next())
+          EdgesFromBPGroups.Add(exp.Current());
+      }
+    }
+  }
+  CPPUNIT_ASSERT( !aGroup1.IsNull() ); 
 
   TopTools_SequenceOfShape aSeqShapes;
-  aGroup->GetShapes( aSeqShapes );  
+  aGroup1->GetShapes( aSeqShapes );  
   CPPUNIT_ASSERT_EQUAL( 78, aSeqShapes.Size());
+  //
+  TopTools_MapOfShape EdgesFromOuter;
+
+  for (int i=1;i<=aSeqShapes.Size();i++)
+    EdgesFromOuter.Add(aSeqShapes(i));
+
+  //check that EdgesFromBPGroups is a PART of Case_1_Immersible zone_1_Outer group
+  int ext1 = EdgesFromBPGroups.Extent();
+  EdgesFromOuter.Intersect(EdgesFromBPGroups);
+  int ext2 = EdgesFromOuter.Extent();
+  CPPUNIT_ASSERT_EQUAL(35, ext1);
+  CPPUNIT_ASSERT_EQUAL(ext1, ext2);
+  //
   BRep_Builder BB;
   TopTools_IndexedMapOfShape ME, MV;
   GProp_GProps G;