From: isn Date: Thu, 6 Oct 2016 18:34:44 +0000 (+0300) Subject: draft ver of dtm pres creation (2d + 2d) X-Git-Tag: v1.6~62 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=44d437c29f2611eecee2142fd161d516f899ad3d;p=modules%2Fhydro.git draft ver of dtm pres creation (2d + 2d) --- diff --git a/src/HYDROData/HYDROData_DTM.cxx b/src/HYDROData/HYDROData_DTM.cxx index 282f361b..f93b67f1 100644 --- a/src/HYDROData/HYDROData_DTM.cxx +++ b/src/HYDROData/HYDROData_DTM.cxx @@ -124,6 +124,45 @@ void HYDROData_DTM::SetSpatialStep( double theSpatialStep ) { SetDouble( DataTag_SpatialStep, theSpatialStep ); } +#include +#include +//#include +#include +#include +#include +#include +#include +#include +#include +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 +} diff --git a/src/HYDROData/HYDROData_DTM.h b/src/HYDROData/HYDROData_DTM.h index 18280a39..326e3571 100644 --- a/src/HYDROData/HYDROData_DTM.h +++ b/src/HYDROData/HYDROData_DTM.h @@ -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& theMainProfiles ); + + static void PointToWire(const AltitudePoints& pnts, TopoDS_Wire& W ); }; #endif diff --git a/src/HYDROData/HYDROData_Stream.cxx b/src/HYDROData/HYDROData_Stream.cxx index b57e666d..07b1755e 100644 --- a/src/HYDROData/HYDROData_Stream.cxx +++ b/src/HYDROData/HYDROData_Stream.cxx @@ -1034,30 +1034,6 @@ void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination, } } } -#include -#include -#include -#include -#include -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& 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; diff --git a/src/HYDRO_tests/test_HYDROData_Stream.cxx b/src/HYDRO_tests/test_HYDROData_Stream.cxx index 581f627a..652b890e 100644 --- a/src/HYDRO_tests/test_HYDROData_Stream.cxx +++ b/src/HYDRO_tests/test_HYDROData_Stream.cxx @@ -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();