Salome HOME
draft ver of dtm pres creation (2d + 2d)
authorisn <isn@opencascade.com>
Thu, 6 Oct 2016 18:34:44 +0000 (21:34 +0300)
committerisn <isn@opencascade.com>
Thu, 6 Oct 2016 18:59:46 +0000 (21:59 +0300)
src/HYDROData/HYDROData_DTM.cxx
src/HYDROData/HYDROData_DTM.h
src/HYDROData/HYDROData_Stream.cxx
src/HYDRO_tests/test_HYDROData_Stream.cxx

index 282f361bfd214ff3509c8cd145e1d5e6280bded6..f93b67f1eaabd82ae0e1a55e7bf304c0a092e435 100644 (file)
@@ -124,6 +124,45 @@ void HYDROData_DTM::SetSpatialStep( double theSpatialStep )
 {
   SetDouble( DataTag_SpatialStep, theSpatialStep );
 }
+#include <BRepLib_MakeEdge.hxx>
+#include <BRepLib_MakeWire.hxx>
+//#include <BRepLib_MakeFace.hxx>
+#include <BRep_Builder.hxx>
+#include <GeomProjLib.hxx>
+#include <Geom_TrimmedCurve.hxx>
+#include <Geom_Plane.hxx>
+#include <BRepTools_WireExplorer.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
+void HYDROData_DTM::PointToWire(const AltitudePoints& pnts, TopoDS_Wire& W )
+{
+  BRepLib_MakeWire WM;
+  for (int i =0; i < pnts.size() - 1; i++)
+  {
+    gp_Pnt p1(pnts[i].X, pnts[i].Y, pnts[i].Z);
+    gp_Pnt p2(pnts[i+1].X, pnts[i+1].Y, pnts[i+1].Z);    
+    WM.Add(BRepLib_MakeEdge(p1, p2).Edge()); 
+  }
+  W = WM.Wire();
+}
+
+static void ProjWireOnPlane(const TopoDS_Wire& inpWire, const Handle_Geom_Plane& RefPlane, TopoDS_Wire& outWire)
+{
+  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);
+    TopoDS_Edge ProjEdge = BRepLib_MakeEdge(ProjectedCurve);
+    WM.Add(ProjEdge); //auto sharing between edges if vertex is coincident
+  }
+  outWire = WM.Wire();
+  outWire.Orientation(inpWire.Orientation()); //take from the original wire
+}
+
 
 void HYDROData_DTM::Update()
 {
@@ -151,16 +190,65 @@ void HYDROData_DTM::Update()
   if( ddz>EPS && step>EPS )
     points = Interpolate( profiles, ddz, step, left, right, main_profiles );
 
-  SetAltitudePoints( points );
-  //SetTopShape(); //2d
-  //SetShape3D(); //3d
-}
 
+  BRep_Builder BB;
+  TopoDS_Compound cmp;
+  BB.MakeCompound(cmp);
+  TopoDS_Wire LWire, RWire;
+  PointToWire(left, LWire);
+  PointToWire(right, RWire);
+  BB.Add(cmp, LWire.Oriented(TopAbs_FORWARD));
+
+  for (int k = 0; k < main_profiles.size(); k++)
+  {
+    TopoDS_Wire W;
+    PointToWire(main_profiles[k], W);
+    TopAbs_Orientation Ori = TopAbs_INTERNAL;
+    if (k == 0 || k == main_profiles.size() - 1)
+      Ori = TopAbs_FORWARD;
+    BB.Add(cmp, W.Oriented(Ori));
+  }
+  
+  BB.Add(cmp, RWire.Oriented(TopAbs_FORWARD)); 
+  //in this order (left + profiles + right)
+  //otherwise the projected wire will be non-manifold!!!
 
+  //cmp = 3d pres
 
+  Handle_Geom_Plane refpl = new Geom_Plane(gp_Pnt(0,0,0), gp_Dir(0,0,1));
+  BRepLib_MakeWire WM;
+  TopoDS_Iterator it(cmp);
+  TopTools_IndexedMapOfShape IntW;
+  for (;it.More(); it.Next())
+  {
+    const TopoDS_Wire& W = TopoDS::Wire(it.Value());
+    if (W.Orientation() != TopAbs_INTERNAL)
+      WM.Add(W); 
+    else
+      IntW.Add(W);
+  }
 
+  TopoDS_Wire outW;
+  ProjWireOnPlane(WM.Wire(), refpl, outW);
+  BRepBuilderAPI_MakeFace mf(refpl, outW); //check inside is true by def
+  TopoDS_Face outF = mf.Face();
 
+  ///!!! the internal wires cant be added with 'internal' ori.
+  // it's possible to do with brep builder yet the result will not be correct!
+  // more proper way is to use BOP operation here.
+  for (int i = 1; i <= IntW.Extent(); i++)
+  {
+    TopoDS_Wire outIW;
+    const TopoDS_Wire& W = TopoDS::Wire(IntW(i));
+    ProjWireOnPlane(W, refpl, outIW);
+    BB.Add(outF, outIW);
+  }
 
+  //outF == 2d pres
+  SetAltitudePoints( points );
+  //SetTopShape(); //2d
+  //this->SetShape(cmp); //3d
+}
 
 
 
index 18280a394c5f8ff51eadcecf310eaaab3b20e7b5..326e35711b999a0c193ca789ce6f79616ee9e841 100644 (file)
@@ -29,6 +29,7 @@ class Handle_Geom2d_Curve;
 class gp_Pnt;
 class gp_Vec2d;
 class TopoDS_Edge;
+class TopoDS_Wire;
 
 DEFINE_STANDARD_HANDLE( HYDROData_DTM, HYDROData_Bathymetry )
 
@@ -134,6 +135,8 @@ protected:
                                      AltitudePoints& theLeft,
                                      AltitudePoints& theRight,
                                      std::vector<AltitudePoints>& theMainProfiles );
+
+  static void PointToWire(const AltitudePoints& pnts, TopoDS_Wire& W );
 };
 
 #endif
index b57e666d443e6952c4f13601592e6dc59ebd2dcb..07b1755e2b642ba4ad80402e24b45905ea7bb20c 100644 (file)
@@ -1034,30 +1034,6 @@ void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination,
     }
   }
 }
-#include <GeomProjLib.hxx>
-#include <Geom_TrimmedCurve.hxx>
-#include <Geom_Plane.hxx>
-#include <BRepTools.hxx>
-#include <BRepTools_WireExplorer.hxx>
-static void ProjEdgeOnPlane(const TopoDS_Wire& inpWire, const Handle_Geom_Plane& RefPlane, TopoDS_Wire& outWire, TopoDS_Vertex V1, TopoDS_Vertex V2)
-{
-  BRepTools_WireExplorer ex(inpWire);
-  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);
-    TopoDS_Edge ProjEdge = BRepLib_MakeEdge(ProjectedCurve);
-    WM.Add(ProjEdge); //auto sharing between edges if vertex is coincident
-  }
-  outWire = WM.Wire();
- //if (V1.IsNull() || V2.IsNull())
- //  outSh = BRepLib_MakeEdge(ProjectedCurve); //create new vertices
- //else
- //  outSh = BRepLib_MakeEdge(ProjectedCurve, V1, V2);
-}
 
 
 bool HYDROData_Stream::CreatePresentations( const TopoDS_Edge&          theLeftBank,
@@ -1065,20 +1041,20 @@ bool HYDROData_Stream::CreatePresentations( const TopoDS_Edge&          theLeftB
                                             const std::vector<TopoDS_Wire>& theProfiles3d,
                                             PrsDefinition&              thePrs )
 {
 thePrs.myLeftBank = theLeftBank;
 thePrs.myRightBank = theRightBank;
-
 BRep_Builder aBB;
 TopoDS_Compound aCmp;
 aBB.MakeCompound(aCmp);
 for (size_t i = 0; i < theProfiles3d.size(); i++ )  
   aBB.Add(aCmp, theProfiles3d[i]);
-
 aBB.Add(aCmp, theLeftBank);
 aBB.Add(aCmp, theRightBank);
-
 thePrs.myPrs3D = aCmp; //3d pres
-  
//thePrs.myLeftBank = theLeftBank;
//thePrs.myRightBank = theRightBank;
+ //
//BRep_Builder aBB;
//TopoDS_Compound aCmp;
//aBB.MakeCompound(aCmp);
//for (size_t i = 0; i < theProfiles3d.size(); i++ )  
//  aBB.Add(aCmp, theProfiles3d[i]);
+ //
//aBB.Add(aCmp, theLeftBank);
//aBB.Add(aCmp, theRightBank);
+ //
//thePrs.myPrs3D = aCmp; //3d pres
+ //
   /*Handle_Geom_Plane RefPlane = new Geom_Plane(gp_Pnt(0,0,0), gp_Dir(0,0,1));
   TopoDS_Vertex V1, V2;
   TopoDS_Wire W;
index 581f627af6171466a5bff20c64cffca68571eb00..652b890e35da6d690205739b058c2f4d1ca4908c 100644 (file)
@@ -241,7 +241,7 @@ void test_HYDROData_Stream::test_presentation()
   HYDROData_Iterator it( aDoc, KIND_PROFILE );
   for( int i=0; it.More(); it.Next(), i++ )
   {
-    if( i>=25 && i<=26 )
+    if( i>=25 && i<=35 )
     {
       it.Current()->Update();
       profiles.Append( Handle(HYDROData_Profile)::DownCast( it.Current() ) );
@@ -253,7 +253,7 @@ void test_HYDROData_Stream::test_presentation()
 
   aStream->SetProfiles( profiles, false );
   aStream->SetDDZ( 0.2 );
-  aStream->SetSpatialStep( 1000 );
+  aStream->SetSpatialStep( 10 );
   aStream->Update();
 
   TopoDS_Shape aPrs3d = aStream->GetShape3D();