]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
first ver. (creating of new channel => calc case => export calc case works OK)
authorisn <isn@opencascade.com>
Tue, 29 Nov 2016 13:03:34 +0000 (16:03 +0300)
committerisn <isn@opencascade.com>
Thu, 1 Dec 2016 11:23:03 +0000 (14:23 +0300)
src/HYDROData/HYDROData_DTM.cxx
src/HYDROData/HYDROData_DTM.h
src/HYDROData/HYDROData_SplitToZonesTool.cxx
src/HYDROData/HYDROData_Stream.cxx

index 78313e369503e30f90e024bd559b9a567ebd7d00..df831b619a110a4ba5dd9b61549e7c3be98774fd 100644 (file)
 #include <BRep_Builder.hxx>
 #include <ShapeAnalysis_Wire.hxx>
 #include <BRepAlgo_NormalProjection.hxx>
-
+#include <ShapeUpgrade_UnifySameDomain.hxx>
 #include <BRepBuilderAPI_MakePolygon.hxx>
+#include <BOPAlgo_Builder.hxx>
 
+#include <TopTools_IndexedDataMapOfShapeShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <TopTools_SequenceOfShape.hxx>
 
 IMPLEMENT_STANDARD_HANDLE( HYDROData_DTM, HYDROData_Bathymetry )
 IMPLEMENT_STANDARD_RTTIEXT( HYDROData_DTM, HYDROData_Bathymetry )
@@ -294,79 +298,167 @@ void HYDROData_DTM::CreateProfilesFromDTM (const HYDROData_SequenceOfObjects& In
     Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet, Create3dPres, Create2dPres, InvInd, WireIntersections );
 }
 
-void HYDROData_DTM::ProjWireOnPlane(const TopoDS_Wire& inpWire, const Handle_Geom_Plane& RefPlane, TopoDS_Wire& outWire)
+void HYDROData_DTM::ProjWireOnPlane(const TopoDS_Shape& inpWire, const Handle_Geom_Plane& RefPlane, 
+  TopTools_DataMapOfShapeListOfShape* E2PE)
 {
-  /*BRepTools_WireExplorer ex(TopoDS::Wire(inpWire.Oriented(TopAbs_FORWARD)));
-  BRepLib_MakeWire WM;
-  for (;ex.More();ex.Next())
-  {
-    const TopoDS_Edge& CE = ex.Current(); 
-    double f, l;
-    Handle(Geom_Curve) C3d = BRep_Tool::Curve(CE, f, l);
-    Handle(Geom_Curve) ProjectedCurve = GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3d, f, l), RefPlane, RefPlane->Position().Direction(), Standard_True);
-    if (!ProjectedCurve.IsNull())
-    {
-      TopoDS_Edge ProjEdge = BRepLib_MakeEdge(ProjectedCurve, f, l );
-      if (!BRep_Tool::Degenerated(ProjEdge))
-        WM.Add(ProjEdge); //auto sharing between edges if vertex is coincident
-    }
-  }*/
-
   BRep_Builder BB;
+
+  //project shape (edges) on planar face
   TopoDS_Face F;
   BB.MakeFace(F, RefPlane, Precision::Confusion());
-  BRepLib_MakeWire WM;
-
   BRepAlgo_NormalProjection nproj(F);
   nproj.Add(inpWire);
   nproj.SetDefaultParams();
   nproj.Build();
   if(!nproj.IsDone())
     return;
-  TopoDS_Shape projRes = nproj.Projection();
-  TopExp_Explorer exp(projRes, TopAbs_EDGE);
-  TopTools_ListOfShape llE;
-  for (;exp.More();exp.Next())
-    llE.Append(exp.Current());
 
-  WM.Add(llE);
-  outWire = WM.Wire();
+  TopoDS_Shape projRes = nproj.Projection();
 
-  outWire.Orientation(inpWire.Orientation()); //take from the original wire
+  // unite all vertexes/edges from projected result
+  BOPAlgo_Builder anAlgo;
+  TopExp_Explorer exp(projRes, TopAbs_EDGE);
+  for (;exp.More(); exp.Next())
+  {
+    const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
+    if (E.Orientation() != TopAbs_INTERNAL)
+      anAlgo.AddArgument(E);
+  }
+  anAlgo.Perform(); 
+  int stat = anAlgo.ErrorStatus();
+  TopoDS_Shape projResConn = anAlgo.Shape();
+
+  // make wire => vertexes and edges should be untouched after this operation!
+  exp.Init(projResConn, TopAbs_EDGE);
+  //TopTools_ListOfShape llE;
+  //TopoDS_Wire RW;
+  //BRepLib_MakeWire WM;
+
+  //for (;exp.More();exp.Next()) 
+  //  llE.Append(exp.Current());
+  //
+  //WM.Add(llE);
+  //outWire = WM.Wire();
+
+  //outWire.Orientation(inpWire.Orientation()); //take from the original wire
+
+  //history mode: edge to projected edges
+  if (E2PE)
+  {
+    TopExp_Explorer ex(inpWire, TopAbs_EDGE);
+    for (;ex.More();ex.Next())
+    {
+      const TopoDS_Edge& CE = TopoDS::Edge(ex.Current());
+      TopTools_ListOfShape NEL;
+      const TopTools_ListOfShape& LS = nproj.Generated(CE);
+      TopTools_ListIteratorOfListOfShape it(LS);
+      for (;it.More();it.Next())
+      {
+        const TopoDS_Shape& PCE = it.Value();
+        TopTools_ListOfShape PLS = anAlgo.Modified(PCE);
+        if (PLS.IsEmpty())
+          PLS.Append(PCE);
+        TopTools_ListIteratorOfListOfShape itp(PLS);
+        for (;itp.More();itp.Next())
+          NEL.Append(itp.Value());
+      }
+
+      E2PE->Bind(CE, NEL);
+    }
+  }
 }
-
-
-bool HYDROData_DTM::Get2dFaceFrom3dPres(const TopoDS_Compound& cmp, TopoDS_Face& outF )
+#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
+bool HYDROData_DTM::Get2dFaceFrom3dPres(const TopoDS_Compound& cmp, TopoDS_Face& outF,
+  TopTools_SequenceOfShape* Boundr, std::set<int> ind )
 {
+  //ind : set of indices (starts with 0). index == number of boundary (inlet, outlet, etc..)
+  //in compound cmp. 
+  //if Boundr is not null => this method will return sequence of boundary wires (inlet, outlet...)
+
   Handle_Geom_Plane refpl = new Geom_Plane(gp_Pnt(0,0,0), gp_Dir(0,0,1));
-  BRepLib_MakeWire WM;
+  TopTools_DataMapOfShapeListOfShape E2PE;
+  ProjWireOnPlane(cmp, refpl, &E2PE);
+  TopTools_ListOfShape ELL;
+
   TopoDS_Iterator it(cmp);
-  //TopTools_IndexedMapOfShape IntW;
+  int i = 0;
   for (;it.More(); it.Next())
   {
     const TopoDS_Wire& W = TopoDS::Wire(it.Value());
     if (W.Orientation() != TopAbs_INTERNAL)
     {
-      //use list of edges to protect againts non-manifold cases.
-      //auto sharing between edges will be added automatically
-      TopTools_IndexedMapOfShape ME;
-      TopTools_ListOfShape LE;
-      TopExp::MapShapes(W, TopAbs_EDGE, ME);
-      for (int i = 1; i <= ME.Extent(); i++)
-        LE.Append(ME(i));
-      WM.Add(LE);
+      TopoDS_Wire PW;
+      TopExp_Explorer ex(W, TopAbs_EDGE);   
+      TopTools_ListOfShape LEpW;
+      TopTools_ListOfShape LEpWDummy;
+      for (;ex.More();ex.Next())
+      {
+        const TopoDS_Edge& CE = TopoDS::Edge(ex.Current());
+        TopTools_ListOfShape LS = E2PE.Find(CE);
+        LEpW.Append(LS);
+      }
+      
+      if (ind.count(i) != 0)
+      {
+        BRepLib_MakeWire WM;
+        WM.Add(LEpW);
+        const TopoDS_Wire& WMW = WM.Wire();
+        //assume that wire is a straight line,
+        //take first and last vertex and make simple edge (RE)
+        TopoDS_Vertex VF, VL;
+        TopExp::Vertices(WMW, VF, VL);
+        TopoDS_Edge RE = BRepLib_MakeEdge(VF, VL).Edge();
+        if (RE.IsNull())
+        {
+          LEpWDummy = LEpW; //LEpW will be nullified after appending to ELL
+          ELL.Append(LEpW);
+        }
+        else
+        {
+          LEpWDummy.Append(RE); 
+          ELL.Append(RE);
+        }
+        //TODO: in the new version of OCCT, USD can process separate wires
+        //ShapeUpgrade_UnifySameDomain USD(WMW, 1U, 0U, 1U); //concat bsplines
+        //USD.Build();
+        //const TopoDS_Shape& RSU = USD.Shape();
+        //TopExp_Explorer exp(RSU, TopAbs_EDGE);
+        //TopTools_ListOfShape DummyL;
+        //for (;it.More();it.Next())
+        //  DummyL.Append(it.Value());
+        //if (DummyL.Extent() == 1)
+        //  ELL.Append(DummyL.First()); //if one edge => accept this result 
+        //else
+        //  ELL.Append(LEpW);  //else put 'as is'
+      }
+      else
+      {
+        LEpWDummy = LEpW;
+        ELL.Append(LEpW);
+      }
+
+      if (Boundr)
+      {
+        //make inlet, outlet, left/tight banks [wires]
+        //shouldn't change topology of the edges
+        BRepLib_MakeWire IWM;
+        IWM.Add(LEpWDummy);
+        Boundr->Append(IWM.Wire());
+      }
     }
-    //else
-    //  IntW.Add(W);
+    i++;
   }
 
-  TopoDS_Wire outW;
-  ProjWireOnPlane(WM.Wire(), refpl, outW);
-  BRepBuilderAPI_MakeFace mf(refpl, outW, true); //check inside is true by def
+  //make primary wire
+  BRepLib_MakeWire WME;
+  WME.Add(ELL);
+
+  const TopoDS_Wire& resW = WME.Wire();
+  BRepBuilderAPI_MakeFace mf(refpl, resW, true); //check inside is true by def
   outF = mf.Face();
 
-  ShapeAnalysis_Wire WA(outW, outF, Precision::Confusion());
-  bool res = WA.CheckSelfIntersection();
+  ShapeAnalysis_Wire WA(resW, outF, Precision::Confusion());
+  bool res = WA.CheckSelfIntersection(); //TODO check that this return false if OK
   return res;
 
   ///!!! the internal wires cant be added with 'internal' ori.
index 2a60f75a9335caa10c45e3b01fb009dc37f35ec0..0e4f746cf1286e297860640b9eae08a1fab8f326 100644 (file)
@@ -35,6 +35,8 @@ class TopoDS_Face;
 class TopoDS_Compound;
 class Handle_Geom_Plane;
 class TopTools_IndexedMapOfOrientedShape;
+class TopTools_DataMapOfShapeListOfShape;
+class TopTools_SequenceOfShape;
 
 DEFINE_STANDARD_HANDLE( HYDROData_DTM, HYDROData_Bathymetry )
 
@@ -155,7 +157,8 @@ protected:
 
   static void PointToWire(const AltitudePoints& pnts, TopoDS_Wire& W );
 
-  static void ProjWireOnPlane(const TopoDS_Wire& inpWire, const Handle_Geom_Plane& RefPlane, TopoDS_Wire& outWire);
+  static void ProjWireOnPlane(const TopoDS_Shape& inpWire, const Handle_Geom_Plane& RefPlane,
+    TopTools_DataMapOfShapeListOfShape* E2PE);
 
   static TopTools_IndexedMapOfOrientedShape Create3DShape(const AltitudePoints& left,
                                                           const AltitudePoints& right,
@@ -179,7 +182,8 @@ protected:
                              std::set<int>& InvInd,
                              bool& WireIntersections);
 
-  static bool Get2dFaceFrom3dPres(const TopoDS_Compound& cmp, TopoDS_Face& outF );
+  static bool Get2dFaceFrom3dPres(const TopoDS_Compound& cmp, TopoDS_Face& outF, 
+    TopTools_SequenceOfShape* Boundr = NULL, std::set<int> ind = std::set<int>() );
   
   static int EstimateNbPoints( const std::vector<Handle_HYDROData_Profile>& theProfiles,
                                double theDDZ, double theSpatialStep );
index 2836229ae258c99d95418898cae18777c6edae4e..12548ef236cf138357e9b7bba9bca796f1c5edd3 100644 (file)
@@ -343,7 +343,7 @@ HYDROData_SplitToZonesTool::SplitDataList
           aList.Clear();
           Standard_Boolean foundE(Standard_False);
           const TopTools_ListOfShape& aListM = splitTool.Modified(exp.Current()); 
-#ifdef NDEBUG
+#ifndef NDEBUG
           DEBTRACE("NB_EDGE_M = " << aListM.Extent());
 #endif
           if(aListM.Extent()) foundE = Standard_True;
@@ -423,7 +423,7 @@ HYDROData_SplitToZonesTool::SplitDataList
               const TopoDS_Shape& aFace = exp.Current();
               if(!aFace.IsNull()) {
                 const TopTools_ListOfShape& aListOfNew = mkCom.Modified(aFace);
-#ifdef NDEBUG
+#ifndef NDEBUG
                 DEBTRACE("Modified: " << aListOfNew.Extent());
 #endif
                 if(!aListOfNew.IsEmpty()) {
index 022cc30664aecc4bf3708c748afc7dab995dd0f0..9ffb8596baf5fefd6cc93515cf0bf13e63b874ea 100644 (file)
@@ -77,6 +77,9 @@
 
 #include <TopTools_HArray1OfShape.hxx>
 #include <TopTools_IndexedMapOfOrientedShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <TopTools_SequenceOfShape.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
 
 #include <SortTools_QuickSortOfReal.hxx>
 
@@ -91,6 +94,8 @@
 #include <TCollection_AsciiString.hxx>
 #endif
 
+#include <assert.h>
+
 typedef NCollection_DataMap<Standard_Real, Handle(HYDROData_Profile)> HYDROData_DataMapOfRealOfHDProfile;
 
 IMPLEMENT_STANDARD_HANDLE(HYDROData_Stream,HYDROData_NaturalObject)
@@ -1045,7 +1050,6 @@ void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination,
     }
   }
 }
-
 void HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt)     theArrayOfFPnt,
                                             const Handle(TColgp_HArray1OfPnt)     theArrayOfLPnt,
                                             const Handle(TopTools_HArray1OfShape) theArrOfProfiles,
@@ -1071,26 +1075,53 @@ void HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt)
   std::vector<HYDROData_Bathymetry::AltitudePoints> dummy;
   TopTools_IndexedMapOfOrientedShape ll = HYDROData_DTM::Create3DShape(left, right, dummy);
 
+  TopoDS_Shape LB, RB, IL, OL;
+
   if (!ll.IsEmpty())
   {
-    thePrs.myLeftBank = TopoDS::Wire(ll(1));
-    thePrs.myRightBank = TopoDS::Wire(ll(2));
+    LB = TopoDS::Wire(ll(1));
+    RB = TopoDS::Wire(ll(2));
   }
 
-  thePrs.myInlet = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Lower())); //TODO check that
-  thePrs.myOutlet = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Upper()));
+  IL = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Lower())); //TODO check that
+  OL = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Upper()));
 
   //make new compound so it's shapes will be in known order to build correct projection
   BRep_Builder BB;
   TopoDS_Compound newCmp;
   BB.MakeCompound(newCmp);
-  BB.Add(newCmp, thePrs.myLeftBank);
-  BB.Add(newCmp, thePrs.myInlet);
-  BB.Add(newCmp, thePrs.myOutlet);
-  BB.Add(newCmp, thePrs.myRightBank);
+  BB.Add(newCmp, LB);
+  BB.Add(newCmp, IL);
+  BB.Add(newCmp, OL);
+  BB.Add(newCmp, RB);
 
   thePrs.myPrs3D = newCmp;
+  std::set<int> ind;
+  ind.insert(1); //inlet ind
+  ind.insert(2); //outlet ind
+
+  TopTools_SequenceOfShape LS;
+  HYDROData_DTM::Get2dFaceFrom3dPres( newCmp, TopoDS::Face(thePrs.myPrs2D), &LS, ind );
+
+#ifndef NDEBUG
+  TopTools_IndexedMapOfShape EE;
+  TopExp::MapShapes(thePrs.myPrs2D, TopAbs_EDGE, EE);
+  int noncontNb = 0;
+  for (int i = 1; i <= 4; i++)
+  {
+    TopoDS_Shape W = LS(i);
+    TopTools_IndexedMapOfShape EW;
+    TopExp::MapShapes(W, TopAbs_EDGE, EW);
+    for (int k = 1; k <= EW.Extent(); k++)
+      noncontNb += !EE.Contains(EW(k));
+  }
+  //noncontNb > 0 => some problem with edge history
+  assert(noncontNb == 0);
+#endif
 
-  HYDROData_DTM::Get2dFaceFrom3dPres( newCmp, TopoDS::Face(thePrs.myPrs2D) ); //__TODO
+  thePrs.myLeftBank = TopoDS::Wire(LS(1));  
+  thePrs.myInlet = TopoDS::Wire(LS(2));  
+  thePrs.myOutlet = TopoDS::Wire(LS(3));  
+  thePrs.myRightBank = TopoDS::Wire(LS(4));
 
 }
\ No newline at end of file