From: mzn Date: Tue, 6 Dec 2016 08:48:25 +0000 (+0300) Subject: Initial merge of branch 'BR_HYDRO_IMPS_2016' into BR_PORTING_OCCT_7 X-Git-Tag: Salome_8_3_Hydro_1_1rc1~58^2~17 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=58bb6b7459bebeeb089c9ed486c4683a8bae7288;p=modules%2Fhydro.git Initial merge of branch 'BR_HYDRO_IMPS_2016' into BR_PORTING_OCCT_7 --- 58bb6b7459bebeeb089c9ed486c4683a8bae7288 diff --cc src/HYDROData/HYDROData_Bathymetry.cxx index 45123472,f0a871a3..3ed80c06 --- a/src/HYDROData/HYDROData_Bathymetry.cxx +++ b/src/HYDROData/HYDROData_Bathymetry.cxx @@@ -53,6 -58,9 +58,8 @@@ #define _DEVDEBUG_ #include "HYDRO_trace.hxx" + const int BLOCK_SIZE = 1000; + -IMPLEMENT_STANDARD_HANDLE(HYDROData_Bathymetry, HYDROData_IAltitudeObject) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Bathymetry, HYDROData_IAltitudeObject) //HYDROData_QuadtreeNode* HYDROData_Bathymetry::myQuadtree = 0; @@@ -478,46 -573,59 +572,59 @@@ bool HYDROData_Bathymetry::IsAltitudesI return aRes; } - bool HYDROData_Bathymetry::ImportFromFile( const TCollection_AsciiString& theFileName ) + bool HYDROData_Bathymetry::ImportFromFile( const QString& theFileName ) { - // Try to open the file - QFile aFile( theFileName.ToCString() ); - if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) ) - return false; + return ImportFromFiles(QStringList(theFileName)); + } - bool aRes = false; + bool HYDROData_Bathymetry::ImportFromFiles( const QStringList& theFileNames ) + { + AltitudePoints AllPoints; + bool Stat = false; - QString aFileSuf = QFileInfo( aFile ).suffix().toLower(); + foreach (QString theFileName, theFileNames) + { + // Try to open the file + QFile aFile( theFileName ); + if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) ) + continue; - AltitudePoints aPoints; + QString aFileSuf = QFileInfo( aFile ).suffix().toLower(); - // Try to import the file - if ( aFileSuf == "xyz" ) - aRes = importFromXYZFile( aFile, aPoints ); - else if ( aFileSuf == "asc" ) - aRes = importFromASCFile( aFile, aPoints ); + HYDROData_Bathymetry::AltitudePoints aPoints; - // Close the file - aFile.close(); - + // Try to import the file + if ( aFileSuf == "xyz" ) + Stat = importFromXYZFile( aFile, aPoints ); + else if ( aFileSuf == "asc" ) + Stat = importFromASCFile( aFile, aPoints ); + + if (!Stat) + continue; //ignore this points + + // Close the file + aFile.close(); + + AllPoints.insert(AllPoints.end(), aPoints.begin(), aPoints.end()); + } // Convert from global to local CS - Handle_HYDROData_Document aDoc = HYDROData_Document::Document( myLab ); + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab ); - AltitudePoints::Iterator anIter( aPoints ); - for ( ; anIter.More(); anIter.Next() ) + HYDROData_Bathymetry::AltitudePoints::iterator anIter = AllPoints.begin(), aLast = AllPoints.end(); + for ( ; anIter!=aLast; ++anIter ) { - AltitudePoint& aPoint = anIter.ChangeValue(); - aDoc->Transform( aPoint, true ); + HYDROData_Bathymetry::AltitudePoint& aPoint = *anIter; + aDoc->Transform( aPoint.X, aPoint.Y, aPoint.Z, true ); } - if ( aRes ) + if ( Stat ) { // Update file path and altitude points of this Bathymetry - SetFilePath( theFileName ); - SetAltitudePoints( aPoints ); + SetFilePaths (theFileNames ); + SetAltitudePoints( AllPoints ); } - return aRes && !aPoints.IsEmpty(); + return Stat && !AllPoints.empty(); } bool HYDROData_Bathymetry::importFromXYZFile( QFile& theFile, diff --cc src/HYDROData/HYDROData_Bathymetry.h index 39ac30b1,8a0d8504..60568473 --- a/src/HYDROData/HYDROData_Bathymetry.h +++ b/src/HYDROData/HYDROData_Bathymetry.h @@@ -27,9 -25,13 +25,11 @@@ class QFile; class gp_XYZ; class gp_XY; -class Handle_HYDROData_PolylineXY; +class HYDROData_PolylineXY; - + class HYDROData_QuadtreeNode; + class vtkPolyData; + class vtkIdList; -DEFINE_STANDARD_HANDLE(HYDROData_Bathymetry, HYDROData_IAltitudeObject) - /**\class HYDROData_Bathymetry * \brief Class that stores/retreives information about the Bathymetry. @@@ -136,9 -153,11 +150,11 @@@ public * \param theFileName the path to file * \return \c true if file has been successfully read */ - HYDRODATA_EXPORT virtual bool ImportFromFile( const TCollection_AsciiString& theFileName ); + HYDRODATA_EXPORT virtual bool ImportFromFiles( const QStringList& theFileNames ); + + HYDRODATA_EXPORT virtual bool ImportFromFile( const QString& theFileName ); - HYDRODATA_EXPORT Handle_HYDROData_PolylineXY CreateBoundaryPolyline() const; + HYDRODATA_EXPORT Handle(HYDROData_PolylineXY) CreateBoundaryPolyline() const; HYDRODATA_EXPORT virtual void UpdateLocalCS( double theDx, double theDy ); diff --cc src/HYDROData/HYDROData_DTM.cxx index 00000000,df831b61..76962d9b mode 000000,100644..100644 --- a/src/HYDROData/HYDROData_DTM.cxx +++ b/src/HYDROData/HYDROData_DTM.cxx @@@ -1,0 -1,1028 +1,1025 @@@ + + #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 + #include + + #include + #include + #include + #include + #include -#include + #include + #include + #include + #include -#include + + #include + #include + #include + #include + #include + #include + #include + #include + + #include + #include -#include + -IMPLEMENT_STANDARD_HANDLE( HYDROData_DTM, HYDROData_Bathymetry ) -IMPLEMENT_STANDARD_RTTIEXT( HYDROData_DTM, HYDROData_Bathymetry ) ++//@MZN zzz IMPLEMENT_STANDARD_HANDLE( HYDROData_DTM, HYDROData_Bathymetry ) ++//@MZN zzz IMPLEMENT_STANDARD_RTTIEXT( HYDROData_DTM, HYDROData_Bathymetry ) + + HYDROData_DTM::CurveUZ::CurveUZ( double theXCurv, const gp_Vec2d& theProfileDir, double theDeltaZ ) + : myXcurv( theXCurv ), myProfileDir( theProfileDir ), myDeltaZ( theDeltaZ ) + { + } + + HYDROData_DTM::CurveUZ::~CurveUZ() + { + } + + double HYDROData_DTM::CurveUZ::Xcurv() const + { + return myXcurv; + } + + gp_Vec2d HYDROData_DTM::CurveUZ::ProfileDir() const + { + return myProfileDir; + } + + double HYDROData_DTM::CurveUZ::DeltaZ() const + { + return myDeltaZ; + } + + HYDROData_DTM::CurveUZ HYDROData_DTM::CurveUZ::operator + ( const CurveUZ& c ) const + { + HYDROData_DTM::CurveUZ res( Xcurv() + c.Xcurv(), ProfileDir() + c.ProfileDir(), DeltaZ() + c.DeltaZ() ); + size_t n = size(), n1 = c.size(); + if( n!=n1 ) + { + std::cout << "Warning: different number of points in curves: " << n << ", " << n1 << std::endl; + } + res.reserve( n ); + for( int i=0; i& main_profiles) + { + TopTools_IndexedMapOfOrientedShape ll; + TopoDS_Wire LWire, RWire; + PointToWire(left, LWire); + PointToWire(right, RWire); + if (!LWire.IsNull()) + ll.Add(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; + ll.Add(W.Oriented(Ori)); + } + + if (!RWire.IsNull()) + ll.Add(RWire.Oriented(TopAbs_FORWARD)); + //yes, add subshapes in this order (left + profiles + right) + //otherwise the projected wire will be non-manifold + + return ll; + } + + + void HYDROData_DTM::Update() + { + AltitudePoints points; + TopoDS_Shape Out3dPres; + TopoDS_Shape Out2dPres; + TopoDS_Shape OutLeftB; + TopoDS_Shape OutRightB; + TopoDS_Shape OutInlet; + TopoDS_Shape OutOutlet; + + HYDROData_SequenceOfObjects objs = GetProfiles(); + double ddz = GetDDZ(); + double step = GetSpatialStep(); + std::set InvInd; + bool WireIntersections; //__TODO + CreateProfilesFromDTM( objs, ddz, step, points, Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet, true, true, InvInd, -1, WireIntersections ); + SetAltitudePoints( points ); + + SetShape( DataTag_LeftBankShape, OutLeftB); + SetShape( DataTag_RightBankShape, OutRightB); + SetShape( DataTag_InletShape, OutInlet); + SetShape( DataTag_OutletShape, OutOutlet ); + SetShape( DataTag_3DShape, Out3dPres ); + SetShape( DataTag_2DShape, Out2dPres ); + + HYDROData_Bathymetry::Update(); + } + + void HYDROData_DTM::GetPresentationShapes( TopoDS_Shape& Out3dPres, + TopoDS_Shape& Out2dPres, + TopoDS_Shape& OutLeftB, + TopoDS_Shape& OutRightB, + TopoDS_Shape& OutInlet, + TopoDS_Shape& OutOutlet ) + { + //without update! + OutLeftB = GetShape( DataTag_LeftBankShape); + OutRightB = GetShape( DataTag_RightBankShape); + OutInlet = GetShape( DataTag_InletShape); + OutOutlet = GetShape( DataTag_OutletShape ); + Out3dPres = GetShape( DataTag_3DShape ); + Out2dPres = GetShape( DataTag_2DShape ); + } + void HYDROData_DTM::CreateProfilesFromDTM (const HYDROData_SequenceOfObjects& InpProfiles, + double ddz, + double step, + AltitudePoints& points, + TopoDS_Shape& Out3dPres, + TopoDS_Shape& Out2dPres, + TopoDS_Shape& OutLeftB, + TopoDS_Shape& OutRightB, + TopoDS_Shape& OutInlet, + TopoDS_Shape& OutOutlet, + bool Create3dPres, + bool Create2dPres, + std::set& InvInd, + int thePntsLimit, + bool& WireIntersections) + { + int aLower = InpProfiles.Lower(), anUpper = InpProfiles.Upper(); + size_t n = anUpper - aLower + 1; + - std::vector profiles; ++ std::vector profiles; + profiles.reserve( n ); + for( int i=aLower; i<=anUpper; i++ ) + { + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( InpProfiles.Value( i ) ); + if( !aProfile.IsNull() ) + profiles.push_back( aProfile ); + } + const double EPS = 1E-3; + AltitudePoints left; + AltitudePoints right; + std::vector main_profiles; + + if( thePntsLimit > 0 ) + { + int aNbPoints = EstimateNbPoints( profiles, ddz, step ); + if( aNbPoints < 0 || aNbPoints > thePntsLimit ) + return; + } + + if( ddz>EPS && step>EPS ) + CreateProfiles(profiles, ddz, step, left, right, points, main_profiles, + Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet, Create3dPres, Create2dPres, InvInd, WireIntersections ); + } + -void HYDROData_DTM::ProjWireOnPlane(const TopoDS_Shape& inpWire, const Handle_Geom_Plane& RefPlane, ++void HYDROData_DTM::ProjWireOnPlane(const TopoDS_Shape& inpWire, const Handle(Geom_Plane)& RefPlane, + TopTools_DataMapOfShapeListOfShape* E2PE) + { + BRep_Builder BB; + + //project shape (edges) on planar face + TopoDS_Face F; + BB.MakeFace(F, RefPlane, Precision::Confusion()); + BRepAlgo_NormalProjection nproj(F); + nproj.Add(inpWire); + nproj.SetDefaultParams(); + nproj.Build(); + if(!nproj.IsDone()) + return; + + TopoDS_Shape projRes = nproj.Projection(); + + // 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); + } + } + } + #include + bool HYDROData_DTM::Get2dFaceFrom3dPres(const TopoDS_Compound& cmp, TopoDS_Face& outF, + TopTools_SequenceOfShape* Boundr, std::set 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)); ++ Handle(Geom_Plane) refpl = new Geom_Plane(gp_Pnt(0,0,0), gp_Dir(0,0,1)); + TopTools_DataMapOfShapeListOfShape E2PE; + ProjWireOnPlane(cmp, refpl, &E2PE); + TopTools_ListOfShape ELL; + + TopoDS_Iterator it(cmp); + int i = 0; + for (;it.More(); it.Next()) + { + const TopoDS_Wire& W = TopoDS::Wire(it.Value()); + if (W.Orientation() != TopAbs_INTERNAL) + { + 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()); + } + } + i++; + } + + //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(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. + // 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); + }*/ + } + -void HYDROData_DTM::CreateProfiles(const std::vector& theProfiles, ++void HYDROData_DTM::CreateProfiles(const std::vector& theProfiles, + double theDDZ, + double theSpatialStep, + AltitudePoints& theOutLeft, + AltitudePoints& theOutRight, + AltitudePoints& theOutPoints, + std::vector& theOutMainProfiles, + TopoDS_Shape& Out3dPres, + TopoDS_Shape& Out2dPres, + TopoDS_Shape& OutLeftB, + TopoDS_Shape& OutRightB, + TopoDS_Shape& OutInlet, + TopoDS_Shape& OutOutlet, + bool Create3dPres, + bool Create2dPres, + std::set& InvInd, + bool& WireIntersections) + { + if (theProfiles.empty()) + return; + theOutPoints = Interpolate( theProfiles, theDDZ, theSpatialStep, theOutLeft, theOutRight, theOutMainProfiles, InvInd ); + //note that if Create3dPres is false => Create2dPres flag is meaningless! + if (Create3dPres) + { + TopTools_IndexedMapOfOrientedShape ll = Create3DShape( theOutLeft, theOutRight, theOutMainProfiles); + + if (ll.IsEmpty()) + return; + BRep_Builder BB; + TopoDS_Compound cmp; + BB.MakeCompound(cmp); + for (int i = 1; i <= ll.Extent(); i++) + BB.Add(cmp, ll(i)); + + Out3dPres = cmp; + + //same order as in HYDROData_DTM::Update() + OutLeftB = ll(1); + OutRightB = ll(ll.Extent()); + OutInlet = ll(2); + OutOutlet = ll(ll.Extent() - 1); + + if (Create2dPres) + { + TopoDS_Face outF; + WireIntersections = Get2dFaceFrom3dPres(cmp, outF); //__TODO + Out2dPres = outF; + }; + } + } + + + + -void HYDROData_DTM::GetProperties( const Handle_HYDROData_Profile& theProfile, ++void HYDROData_DTM::GetProperties( const Handle(HYDROData_Profile)& theProfile, + gp_Pnt& theLowestPoint, gp_Vec2d& theDir, + bool isNormalDir, + double& theZMin, double& theZMax ) + { + theLowestPoint = theProfile->GetBottomPoint(); + + gp_XY aLeft, aRight; + theProfile->GetLeftPoint( aLeft, true, true ); + theProfile->GetRightPoint( aRight, true, true ); + double x = aRight.X()-aLeft.X(); + double y = aRight.Y()-aLeft.Y(); + if( isNormalDir ) + theDir = gp_Vec2d( -y, x ); + else + theDir = gp_Vec2d( x, y ); + + HYDROData_Profile::ProfilePoints points = theProfile->GetProfilePoints(); + int lo = points.Lower(); + int up = points.Upper(); + theZMin = std::numeric_limits::max(); + theZMax = -theZMin; + for( int i=lo; i<=up; i++ ) + { + double z = points.Value( i ).Z(); + if( z>theZMax ) + theZMax = z; + if( ztheUMax ) + theUMax = u; + return gp_Pnt2d( u, z ); + } + + Handle(TColgp_HArray1OfPnt2d) To2D( const TColgp_Array1OfPnt& thePoints, + const gp_Trsf& theTr, + double& theUMin, double& theUMax ) + { + int low = thePoints.Lower(), up = thePoints.Upper(); + Handle(TColgp_HArray1OfPnt2d) points = new TColgp_HArray1OfPnt2d( low, up ); + for( int i=low; i<=up; i++ ) + points->SetValue( i, To2D( thePoints.Value( i ), theTr, theUMin, theUMax ) ); + return points; + } + + Handle(Geom2d_Curve) CurveTo2D( const Handle(Geom_Curve)& theCurve, + Standard_Real theFirst, Standard_Real theLast, + const gp_Trsf& theTr, + double& theUMin, double& theUMax ) + { + if( theCurve->IsKind( STANDARD_TYPE( Geom_Line ) ) ) + { + gp_Pnt aFirstPnt, aLastPnt; + theCurve->D0( theFirst, aFirstPnt ); + theCurve->D0( theLast, aLastPnt ); + + gp_Pnt2d + aFirst2d = To2D( aFirstPnt, theTr, theUMin, theUMax ), + aLast2d = To2D( aLastPnt, theTr, theUMin, theUMax ); + + gp_Vec2d dir( aFirst2d, aLast2d ); - Handle_Geom2d_Line aLine2d = new Geom2d_Line( aFirst2d, gp_Dir2d( dir.X(), dir.Y() ) ); ++ Handle(Geom2d_Line) aLine2d = new Geom2d_Line( aFirst2d, gp_Dir2d( dir.X(), dir.Y() ) ); + return new Geom2d_TrimmedCurve( aLine2d, 0, aLast2d.Distance( aFirst2d ) ); + } + + if( theCurve->IsKind( STANDARD_TYPE( Geom_BSplineCurve ) ) ) + { + Handle(Geom_BSplineCurve) aSpline = Handle(Geom_BSplineCurve)::DownCast( theCurve ); + + Handle(TColgp_HArray1OfPnt2d) poles = To2D( aSpline->Poles(), theTr, theUMin, theUMax ); + const TColStd_Array1OfReal& knots = aSpline->Knots(); + const TColStd_Array1OfInteger& multiplicities = aSpline->Multiplicities(); + int aDegree = aSpline->Degree(); + + return new Geom2d_BSplineCurve( poles->Array1(), knots, multiplicities, aDegree ); + } + + return Handle(Geom2d_Curve)(); + } + -Handle_Geom2d_BSplineCurve HYDROData_DTM::CreateHydraulicAxis( - const std::vector& theProfiles, ++Handle(Geom2d_BSplineCurve) HYDROData_DTM::CreateHydraulicAxis( ++ const std::vector& theProfiles, + std::vector& theDistances ) + { + size_t n = theProfiles.size(); - Handle_Geom2d_BSplineCurve aResult; ++ Handle(Geom2d_BSplineCurve) aResult; + + Handle(TColgp_HArray1OfPnt2d) points = new TColgp_HArray1OfPnt2d( 1, (int)n ); + TColgp_Array1OfVec2d tangents( 1, (int)n ); + Handle(TColStd_HArray1OfBoolean) flags = new TColStd_HArray1OfBoolean( 1, (int)n ); + + for( size_t i = 1; i <= n; i++ ) + { - Handle_HYDROData_Profile aProfile = theProfiles[i-1]; ++ Handle(HYDROData_Profile) aProfile = theProfiles[i-1]; + aProfile->Update(); + + gp_Pnt aLowest; + gp_Vec2d aTangent; + double zmin, zmax; + GetProperties( aProfile, aLowest, aTangent, true, zmin, zmax ); + aTangent.Normalize(); + + points->SetValue( (int)i, gp_Pnt2d( aLowest.X(), aLowest.Y() ) ); + tangents.SetValue( (int)i, aTangent ); + flags->SetValue( (int)i, Standard_True ); + } + + Geom2dAPI_Interpolate anInterpolator( points, Standard_False, Standard_False ); + anInterpolator.Load( tangents, flags ); + anInterpolator.Perform(); + if( anInterpolator.IsDone() ) + { + aResult = anInterpolator.Curve(); + + //fill the distances vector + Geom2dAdaptor_Curve anAdaptor( aResult ); + + theDistances.clear(); + theDistances.reserve( n ); + Standard_Real aParamFirst = anAdaptor.FirstParameter(), aParamLast = anAdaptor.LastParameter(); + for( size_t i = 1; i <= n; i++ ) + { + gp_Pnt2d aPnt = points->Value( (Standard_Integer)i ); + Geom2dAPI_ProjectPointOnCurve aProject( aPnt, aResult ); + Standard_Real aParam = aProject.LowerDistanceParameter(); + double aDistance = GCPnts_AbscissaPoint::Length( anAdaptor, aParamFirst, aParam ); + theDistances.push_back( aDistance ); + } + } + return aResult; + } + -std::vector HYDROData_DTM::ProfileToParametric( - const Handle_HYDROData_Profile& theProfile, ++std::vector HYDROData_DTM::ProfileToParametric( ++ const Handle(HYDROData_Profile)& theProfile, + double& theUMin, double& theUMax, gp_Vec2d& theDir ) + { - std::vector curves; ++ std::vector curves; + + // Transformation of the coordinate systems + gp_Pnt aLowest; + double zmin, zmax; + GetProperties( theProfile, aLowest, theDir, false, zmin, zmax ); + + gp_Ax3 aStd3d( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ), gp_Dir( 1, 0, 0 ) ); + gp_Ax3 aLocal( gp_Pnt( aLowest.X(), aLowest.Y(), 0 ), gp_Dir( 0, 0, 1 ), gp_Dir( theDir.X(), theDir.Y(), 0 ) ); + + gp_Trsf aTransf; + aTransf.SetTransformation( aStd3d, aLocal ); + + // Iteration via edges + TopoDS_Wire aWire = TopoDS::Wire( theProfile->GetShape3D() ); + TopExp_Explorer anExp( aWire, TopAbs_EDGE ); + for( ; anExp.More(); anExp.Next() ) + { + // Extract an edge from wire + TopoDS_Edge anEdge = TopoDS::Edge( anExp.Current() ); + + // Extract a curve corresponding to the edge + TopLoc_Location aLoc; + Standard_Real aFirst, aLast; + Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aLoc, aFirst, aLast ); + + // Convert the curve to 2d CS + Handle(Geom2d_Curve) aCurve2d = CurveTo2D( aCurve, aFirst, aLast, aTransf, theUMin, theUMax ); + if( !aCurve2d.IsNull() ) + curves.push_back( aCurve2d ); + } + return curves; + } + + + bool CalcMidWidth( const std::set& intersections, double& theMid, double& theWid ) + { + double umin = std::numeric_limits::max(), + umax = -umin; + + size_t n = intersections.size(); + if( n <= 0 ) + return false; + + std::set::const_iterator it = intersections.begin(), last = intersections.end(); + for( ; it!=last; it++ ) + { + double u = *it; + if( uumax ) + umax = u; + } + theMid = ( umin+umax )/2; + theWid = umax-umin; + return true; + } + -void HYDROData_DTM::ProfileDiscretization( const Handle_HYDROData_Profile& theProfile, ++void HYDROData_DTM::ProfileDiscretization( const Handle(HYDROData_Profile)& theProfile, + double theXCurv, double theMinZ, double theMaxZ, double theDDZ, + CurveUZ& theMidPointCurve, + CurveUZ& theWidthCurve, + int& intersection_nb, + double theTolerance) + { + double aDblMax = std::numeric_limits::max(), + aUMin = aDblMax, + aUMax = -aUMin, + aVMax = 1000000; + + gp_Vec2d aProfileDir; - std::vector curves = ProfileToParametric( theProfile, aUMin, aUMax, aProfileDir ); ++ std::vector curves = ProfileToParametric( theProfile, aUMin, aUMax, aProfileDir ); + size_t n = curves.size(); + + if( n==0 ) + return; + + // we add the "virtual" vertical lines to simulate the intersection with profile + gp_Pnt2d aFirst, aLast; + curves[0]->D0( curves[0]->FirstParameter(), aFirst ); + curves[n-1]->D0( curves[n-1]->LastParameter(), aLast ); + Handle(Geom2d_Line) aV1 = new Geom2d_Line( aFirst, gp_Dir2d( 0, 1 ) ); + Handle(Geom2d_TrimmedCurve) aT1 = new Geom2d_TrimmedCurve( aV1, 0.0, aVMax ); + + Handle(Geom2d_Line) aV2 = new Geom2d_Line( aLast, gp_Dir2d( 0, 1 ) ); + Handle(Geom2d_TrimmedCurve) aT2 = new Geom2d_TrimmedCurve( aV2, 0.0, aVMax ); + + curves.push_back( aT1 ); + curves.push_back( aT2 ); + + int psize = ( int )( ( theMaxZ-theMinZ ) / theDDZ + 1 ); + theMidPointCurve = CurveUZ( theXCurv, aProfileDir, theMinZ ); + theMidPointCurve.reserve( psize ); + theWidthCurve = CurveUZ( theXCurv, aProfileDir, theMinZ ); + theWidthCurve.reserve( psize ); + + n = curves.size(); + // for each discrete value of z we search intersection with profile + for( double z1 = theMinZ; z1 <= theMaxZ; z1 += theDDZ ) + { + Handle(Geom2d_Line) aLine = new Geom2d_Line( gp_Pnt2d( 0, z1 ), gp_Dir2d( 1, 0 ) ); + std::set intersections; + for( size_t i = 0; i < n; i++ ) + { - Handle_Geom2d_Curve aCurve = curves[i]; ++ Handle(Geom2d_Curve) aCurve = curves[i]; + Geom2dAPI_InterCurveCurve anIntersect( aCurve, aLine, theTolerance ); + for( int k=1, m=anIntersect.NbPoints(); k<=m; k++ ) + intersections.insert( anIntersect.Point( k ).X() ); + } + + intersection_nb = intersections.size(); + if( intersection_nb >= 1 ) + { + double u_mid, u_wid; + if( !CalcMidWidth( intersections, u_mid, u_wid ) ) + continue; + + double z = z1 - theMinZ; + PointUZ p_mid; + p_mid.U = u_mid; + p_mid.Z = z; + theMidPointCurve.push_back( p_mid ); + + PointUZ p_wid; + p_wid.U = u_wid; + p_wid.Z = z; + theWidthCurve.push_back( p_wid ); + } + } + } + + void HYDROData_DTM::Interpolate( const CurveUZ& theCurveA, const CurveUZ& theCurveB, + int theNbSteps, std::vector& theInterpolation, + bool isAddSecond ) + { + theInterpolation.clear(); + int d = isAddSecond ? 2 : 1; + theInterpolation.reserve( theNbSteps+d ); + double dt = 1.0 / double( theNbSteps + 1 ); + double t = dt; + theInterpolation.push_back( theCurveA ); + for( int i=0; i -void HYDROData_DTM::CurveTo3D( const Handle_Geom2d_BSplineCurve& theHydraulicAxis, ++void HYDROData_DTM::CurveTo3D( const Handle(Geom2d_BSplineCurve)& theHydraulicAxis, + const CurveUZ& theMidCurve, const CurveUZ& theWidthCurve, + AltitudePoints& thePoints ) + { + Geom2dAdaptor_Curve anAdaptor( theHydraulicAxis ); + TopoDS_Edge E2d = BRepLib_MakeEdge2d(theHydraulicAxis).Edge(); + GCPnts_AbscissaPoint ap( anAdaptor, theMidCurve.Xcurv(), anAdaptor.FirstParameter() ); + double aParam = ap.Parameter(); + + gp_Pnt2d point; + anAdaptor.D0( aParam, point ); + gp_Vec2d profile_dir = theMidCurve.ProfileDir(); + //gp_Dir tangent_n( -profile_dir.Y(), profile_dir.X(), dz ); + profile_dir.Normalize(); + + size_t n = theMidCurve.size(); + std::map sorted_points; + for( size_t i=0; i::const_iterator it = sorted_points.begin(), last = sorted_points.end(); + for( ; it!=last; it++ ) + if( thePoints.empty() || thePoints.back().SquareDistance( it->second ) > EPS ) + thePoints.push_back( it->second ); + } + + inline double max( double a, double b ) + { + if( a>b ) + return a; + else + return b; + } + + inline double min( double a, double b ) + { + if( a + + std::vector HYDROData_DTM::Interpolate - ( const Handle_Geom2d_BSplineCurve& theHydraulicAxis, - const Handle_HYDROData_Profile& theProfileA, ++ ( const Handle(Geom2d_BSplineCurve)& theHydraulicAxis, ++ const Handle(HYDROData_Profile)& theProfileA, + double theXCurvA, - const Handle_HYDROData_Profile& theProfileB, ++ const Handle(HYDROData_Profile)& theProfileB, + double theXCurvB, + double theDDZ, int theNbSteps, bool isAddSecond, + int& inter_nb_1, int& inter_nb_2) + { + double zminA, zmaxA, zminB, zmaxB; + gp_Pnt lowestA, lowestB; + gp_Vec2d dirA, dirB; + + GetProperties( theProfileA, lowestA, dirA, false, zminA, zmaxA ); + GetProperties( theProfileB, lowestB, dirB, false, zminB, zmaxB ); + + + double hmax = max( zmaxA-zminA, zmaxB-zminB ); + + //double dz = zminB - zminA; + //double zmin = min( zminA, zminB ); + //double zmax = max( zmaxA, zmaxB ); + + CurveUZ midA(0, gp_Vec2d(), 0), midB(0, gp_Vec2d(), 0); + CurveUZ widA(0, gp_Vec2d(), 0), widB(0, gp_Vec2d(), 0); + + ProfileDiscretization( theProfileA, theXCurvA, zminA, zminA+hmax, theDDZ, midA, widA, inter_nb_1 ); + ProfileDiscretization( theProfileB, theXCurvB, zminB, zminB+hmax, theDDZ, midB, widB, inter_nb_2 ); + + std::vector mid, wid; + Interpolate( midA, midB, theNbSteps, mid, isAddSecond ); + Interpolate( widA, widB, theNbSteps, wid, isAddSecond ); + + size_t p = mid.size(); + size_t q = p>0 ? 2*mid[0].size() : 1; + std::vector points; + points.resize( p ); + + for( size_t i=0; i& theProfiles, ++ ( const std::vector& theProfiles, + double theDDZ, double theSpatialStep, + AltitudePoints& theLeft, + AltitudePoints& theRight, + std::vector& theMainProfiles, + std::set& invalInd) + { + AltitudePoints points; + size_t n = theProfiles.size(); + if( n<=1 ) + return points; + + std::vector distances; - Handle_Geom2d_BSplineCurve aHydraulicAxis = CreateHydraulicAxis( theProfiles, distances ); ++ Handle(Geom2d_BSplineCurve) aHydraulicAxis = CreateHydraulicAxis( theProfiles, distances ); + if( aHydraulicAxis.IsNull() ) + return points; + + theMainProfiles.reserve( n ); + + for( size_t i=0, n1=n-1; i local_points = Interpolate( aHydraulicAxis, theProfiles[i], distances[i], + theProfiles[i+1], distances[i+1], theDDZ, aNbSteps, isAddSecond, inter_nb_1, inter_nb_2 ); + int lps = local_points.size(); + + if (inter_nb_1 > 2) + invalInd.insert(i); + + if (inter_nb_2 > 2) + invalInd.insert(i+1); + + // 2. Put all points into the global container + for( size_t j=0; j& theProfiles, ++int HYDROData_DTM::EstimateNbPoints( const std::vector& theProfiles, + double theDDZ, double theSpatialStep ) + { + size_t n = theProfiles.size(); + if( n<=1 ) + return 0; + if( theDDZ<1E-6 || theSpatialStep<1E-6 ) + return 1 << 20; + + std::vector distances; - Handle_Geom2d_BSplineCurve aHydraulicAxis = CreateHydraulicAxis( theProfiles, distances ); ++ Handle(Geom2d_BSplineCurve) aHydraulicAxis = CreateHydraulicAxis( theProfiles, distances ); + if( aHydraulicAxis.IsNull() ) + return 0; + + double aCompleteDistance = distances[n-1]; + int aNbSteps = int( aCompleteDistance / theSpatialStep ) + 1; + gp_Pnt aLowest; + gp_Vec2d aDir; + double aZMin, aZMax; + GetProperties( theProfiles[0], aLowest, aDir, true, aZMin, aZMax ); + int aNbZSteps = (aZMax-aZMin)/theDDZ; + + if( aNbSteps > ( 1<<16 ) || aNbZSteps > ( 1<<16 ) ) + return 1 << 20; + + return aNbSteps * aNbZSteps; + } diff --cc src/HYDROData/HYDROData_DTM.h index 00000000,0e4f746c..844e4e89 mode 000000,100644..100644 --- a/src/HYDROData/HYDROData_DTM.h +++ b/src/HYDROData/HYDROData_DTM.h @@@ -1,0 -1,219 +1,222 @@@ + // Copyright (C) 2014-2015 EDF-R&D + // This library is free software; you can redistribute it and/or + // modify it under the terms of the GNU Lesser General Public + // License as published by the Free Software Foundation; either + // version 2.1 of the License, or (at your option) any later version. + // + // This library is distributed in the hope that it will be useful, + // but WITHOUT ANY WARRANTY; without even the implied warranty of + // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + // Lesser General Public License for more details. + // + // You should have received a copy of the GNU Lesser General Public + // License along with this library; if not, write to the Free Software + // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + // + // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + // + + #ifndef HYDROData_DTM_HeaderFile + #define HYDROData_DTM_HeaderFile + + #include "HYDROData_Bathymetry.h" ++#include "HYDROData_Profile.h" ++ ++#include ++ ++#include ++#include ++#include ++ ++#include ++#include ++#include ++ + #include + #include -#include + -class Handle_HYDROData_Profile; -class Handle_Geom2d_BSplineCurve; -class Handle_Geom2d_Curve; + class gp_Pnt; + class gp_Vec2d; + class TopoDS_Edge; + class TopoDS_Wire; + 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 ) + + /**\class HYDROData_DTM + * \brief Class that represents the Digital Terrain Model + */ + class HYDROData_DTM : public HYDROData_Bathymetry + { + protected: + /** + * Enumeration of tags corresponding to the persistent object parameters. + */ + enum DataTag + { + DataTag_First = HYDROData_Bathymetry::DataTag_First + 100, ///< first tag, to reserve + DataTag_Profiles, + DataTag_DDZ, + DataTag_SpatialStep, + DataTag_LeftBankShape, + DataTag_RightBankShape, + DataTag_InletShape, + DataTag_OutletShape, + DataTag_3DShape, + DataTag_2DShape + }; + + public: - DEFINE_STANDARD_RTTI( HYDROData_DTM ); ++ DEFINE_STANDARD_RTTIEXT( HYDROData_DTM, HYDROData_Bathymetry ); + + HYDRODATA_EXPORT HYDROData_SequenceOfObjects GetProfiles() const; + HYDRODATA_EXPORT void SetProfiles( const HYDROData_SequenceOfObjects& ); + + HYDRODATA_EXPORT double GetDDZ() const; + HYDRODATA_EXPORT void SetDDZ( double ); + + HYDRODATA_EXPORT double GetSpatialStep() const; + HYDRODATA_EXPORT void SetSpatialStep( double ); + + HYDRODATA_EXPORT virtual void Update(); + + public: + struct PointUZ + { + PointUZ( double u=0, double z=0 ) { U=u; Z=z; } + double U; + double Z; + }; + class CurveUZ : public std::vector + { + public: + CurveUZ( double theXcurv, const gp_Vec2d& theProfileDir, double theDeltaZ ); + ~CurveUZ(); + + double Xcurv() const; + gp_Vec2d ProfileDir() const; + double DeltaZ() const; + + CurveUZ operator + ( const CurveUZ& ) const; + CurveUZ operator * ( double ) const; + + private: + double myXcurv; + gp_Vec2d myProfileDir; + double myDeltaZ; + }; + + protected: + friend class HYDROData_Stream; + friend class HYDROData_Iterator; + friend class test_HYDROData_DTM; + + HYDRODATA_EXPORT HYDROData_DTM(); + virtual HYDRODATA_EXPORT ~HYDROData_DTM(); + - static Handle_Geom2d_BSplineCurve CreateHydraulicAxis( - const std::vector& theProfiles, ++ static Handle(Geom2d_BSplineCurve) CreateHydraulicAxis( ++ const std::vector& theProfiles, + std::vector& theDistances ); + - static std::vector ProfileToParametric( const Handle_HYDROData_Profile& theProfile, - double& theUMin, double& theUMax, - gp_Vec2d& theDir ); ++ static std::vector ProfileToParametric( const Handle(HYDROData_Profile)& theProfile, ++ double& theUMin, double& theUMax, ++ gp_Vec2d& theDir ); + - static void GetProperties( const Handle_HYDROData_Profile& theProfile, ++ static void GetProperties( const Handle(HYDROData_Profile)& theProfile, + gp_Pnt& theLowestPoint, gp_Vec2d& theDir, + bool isNormalDir, + double& theZMin, double& theZMax ); + - static void ProfileDiscretization( const Handle_HYDROData_Profile& theProfile, ++ static void ProfileDiscretization( const Handle(HYDROData_Profile)& theProfile, + double theXCurv, double theMinZ, double theMaxZ, double theDDZ, + CurveUZ& theMidPointCurve, + CurveUZ& theWidthCurve, + int& intersection_nb, + double theTolerance = 1E-6 ); + - static void CurveTo3D( const Handle_Geom2d_BSplineCurve& theHydraulicAxis, ++ static void CurveTo3D( const Handle(Geom2d_BSplineCurve)& theHydraulicAxis, + const CurveUZ& theMidCurve, const CurveUZ& theWidthCurve, + AltitudePoints& thePoints ); + + static void Interpolate( const CurveUZ& theCurveA, const CurveUZ& theCurveB, + int theNbSteps, std::vector& theInterpolation, + bool isAddSecond ); + + static std::vector Interpolate - ( const Handle_Geom2d_BSplineCurve& theHydraulicAxis, - const Handle_HYDROData_Profile& theProfileA, ++ ( const Handle(Geom2d_BSplineCurve)& theHydraulicAxis, ++ const Handle(HYDROData_Profile)& theProfileA, + double theXCurvA, - const Handle_HYDROData_Profile& theProfileB, ++ const Handle(HYDROData_Profile)& theProfileB, + double theXCurvB, + double theDDZ, int theNbSteps, bool isAddSecond, + int& inter_nb_1, int& inter_nb_2 ); + - static AltitudePoints Interpolate( const std::vector& theProfiles, ++ static AltitudePoints Interpolate( const std::vector& theProfiles, + double theDDZ, double theSpatialStep, + AltitudePoints& theLeft, + AltitudePoints& theRight, + std::vector& theMainProfiles, + std::set& invalInd ); + + static void PointToWire(const AltitudePoints& pnts, TopoDS_Wire& W ); + - static void ProjWireOnPlane(const TopoDS_Shape& inpWire, const Handle_Geom_Plane& RefPlane, ++ 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, + const std::vector& main_profiles); + - static void CreateProfiles(const std::vector& theProfiles, ++ static void CreateProfiles(const std::vector& theProfiles, + double theDDZ, + double theSpatialStep, + AltitudePoints& theOutLeft, + AltitudePoints& theOutRight, + AltitudePoints& theOutPoints, + std::vector& theOutMainProfiles, + TopoDS_Shape& Out3dPres, + TopoDS_Shape& Out2dPres, + TopoDS_Shape& OutLeftB, + TopoDS_Shape& OutRightB, + TopoDS_Shape& OutInlet, + TopoDS_Shape& OutOutlet, + bool Create3dPres, + bool Create2dPres, + std::set& InvInd, + bool& WireIntersections); + + static bool Get2dFaceFrom3dPres(const TopoDS_Compound& cmp, TopoDS_Face& outF, + TopTools_SequenceOfShape* Boundr = NULL, std::set ind = std::set() ); + - static int EstimateNbPoints( const std::vector& theProfiles, ++ static int EstimateNbPoints( const std::vector& theProfiles, + double theDDZ, double theSpatialStep ); + + void GetPresentationShapes( TopoDS_Shape& Out3dPres, + TopoDS_Shape& Out2dPres, + TopoDS_Shape& OutLeftB, + TopoDS_Shape& OutRightB, + TopoDS_Shape& OutInlet, + TopoDS_Shape& OutOutlet ); + public: + + HYDRODATA_EXPORT static void CreateProfilesFromDTM ( const HYDROData_SequenceOfObjects& InpProfiles, + double ddz, + double step, + AltitudePoints& points, + TopoDS_Shape& Out3dPres, + TopoDS_Shape& Out2dPres, + TopoDS_Shape& OutLeftB, + TopoDS_Shape& OutRightB, + TopoDS_Shape& OutInlet, + TopoDS_Shape& OutOutlet, + bool Create3dPres, + bool Create2dPres, + std::set& InvInd, + int thePntsLimit, + bool& WireIntersections); + }; + + + + + #endif diff --cc src/HYDROData/HYDROData_Entity.h index 3cfa0bc7,37bdcc66..d82b3d7b --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@@ -66,8 -65,11 +66,9 @@@ const ObjectKind KIND_STRICKLER_TABL const ObjectKind KIND_LAND_COVER_OBSOLETE = 27; const ObjectKind KIND_CHANNEL_ALTITUDE = 28; const ObjectKind KIND_LAND_COVER_MAP = 29; + const ObjectKind KIND_DTM = 30; const ObjectKind KIND_LAST = KIND_LAND_COVER_MAP; -DEFINE_STANDARD_HANDLE(HYDROData_Entity, MMgt_TShared) - class MapOfTreatedObjects : public QMap { }; diff --cc src/HYDROData/HYDROData_LandCoverMap.h index 7abf5e12,f6e681b0..e00eaebd --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@@ -25,8 -25,10 +25,10 @@@ #include #include #include + #include + #include -class Handle_HYDROData_StricklerTable; +class HYDROData_StricklerTable; #include typedef NCollection_IndexedDataMap HYDROData_MapOfFaceToStricklerType; @@@ -34,9 -36,12 +36,9 @@@ class TopoDS_Shape; class TopoDS_Wire; class TopoDS_Iterator; -class TopTools_ListOfShape; -class Handle( HYDROData_PolylineXY ); -class Handle( HYDROData_Object ); +class HYDROData_PolylineXY; +class HYDROData_Object; - class gp_Pnt2d; + class gp_XY; class HYDROData_LandCoverMap : public HYDROData_Entity { @@@ -106,7 -111,8 +108,8 @@@ public HYDRODATA_EXPORT bool ExportTelemac( const QString& theFileName, double theDeflection, - const Handle(HYDROData_StricklerTable)& theTable ) const; - const Handle_HYDROData_StricklerTable& theTable, ++ const Handle(HYDROData_StricklerTable)& theTable, + QString& statMessage) const; HYDRODATA_EXPORT bool Add( const Handle( HYDROData_Object )&, const QString& theType ); HYDRODATA_EXPORT bool Add( const Handle( HYDROData_PolylineXY )&, const QString& theType ); diff --cc src/HYDROData/HYDROData_Profile.h index 1809a02c,a1571150..198cb241 --- a/src/HYDROData/HYDROData_Profile.h +++ b/src/HYDROData/HYDROData_Profile.h @@@ -20,12 -20,13 +20,11 @@@ #define HYDROData_Profile_HeaderFile #include "HYDROData_Object.h" - #include "HYDROData_ProfileUZ.h" -DEFINE_STANDARD_HANDLE(HYDROData_Profile, HYDROData_Object) - class gp_XYZ; class OSD_File; -class Handle(HYDROData_Document); +class HYDROData_Document; /**\class HYDROData_Profile * \brief Class that stores/retreives information about the profile. diff --cc src/HYDROData/HYDROData_Region.cxx index f74956ce,226e0e46..0f47ed2a --- a/src/HYDROData/HYDROData_Region.cxx +++ b/src/HYDROData/HYDROData_Region.cxx @@@ -46,8 -47,14 +47,12 @@@ #include #include -#include "Handle_Geom_Plane.hxx" + #include "Geom_Plane.hxx" + #include "gp_Pln.hxx" + #include "BRepTools_ReShape.hxx" + //#define DEB_GET_REGION_SHAPE -IMPLEMENT_STANDARD_HANDLE(HYDROData_Region, HYDROData_Entity) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Region, HYDROData_Entity) diff --cc src/HYDROData/HYDROData_ShapeFile.cxx index b928ce8d,a66bc81b..2a38a86d --- a/src/HYDROData/HYDROData_ShapeFile.cxx +++ b/src/HYDROData/HYDROData_ShapeFile.cxx @@@ -562,7 -563,7 +563,7 @@@ void HYDROData_ShapeFile::Free( void HYDROData_ShapeFile::ReadSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, - int theInd, NCollection_Sequence& theEntities) - int theInd, NCollection_Sequence& theEntities, bool bReadAsPolyline) ++ int theInd, NCollection_Sequence& theEntities, bool bReadAsPolyline) { Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) ); @@@ -577,19 -578,28 +578,28 @@@ else EndIndex = anObj->nVertices; - bool IsClosed = false; HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE; - if (anObj->padfX[StartIndex] == anObj->padfX[EndIndex - 1] && - anObj->padfY[StartIndex] == anObj->padfY[EndIndex - 1] ) + if (!bReadAsPolyline) { - IsClosed = true; - aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toLatin1()), aSectType, true); + bool IsClosed = false; + if (anObj->padfX[StartIndex] == anObj->padfX[EndIndex - 1] && + anObj->padfY[StartIndex] == anObj->padfY[EndIndex - 1] ) + { + IsClosed = true; - aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, true); ++ aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toLatin1()), aSectType, true); + } + else - aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, false); ++ aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toLatin1()), aSectType, false); + + if (IsClosed) + EndIndex--; } else - aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toLatin1()), aSectType, false); - - if (IsClosed) + { + //polygon; contours always closed - aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toAscii()), aSectType, true); ++ aPolylineXY->AddSection( TCollection_AsciiString( ("poly_section_" + QString::number(i)).data()->toLatin1()), aSectType, true); EndIndex--; + } for ( int k = StartIndex; k < EndIndex ; k++ ) { HYDROData_PolylineXY::Point aSectPoint = gp_XY(anObj->padfX[k], anObj->padfY[k]); @@@ -675,10 -689,24 +689,24 @@@ void HYDROData_ShapeFile::ReadSHPPoly3D } - + void HYDROData_ShapeFile::GetFreeIndices(std::vector& theAllowedIndexes, QString strName, size_t theObjsSize, + QStringList theExistingNames, QString theBaseFileName) + { + int anInd = 0; + for (;theAllowedIndexes.size() < theObjsSize;) + { + if (!theExistingNames.contains(theBaseFileName + strName + QString::number(anInd))) + { + theAllowedIndexes.push_back(anInd); + anInd++; + } + else + anInd++; + } + } int HYDROData_ShapeFile::ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, - NCollection_Sequence& theEntities, int& theShapeTypeOfFile) + NCollection_Sequence& theEntities, int& theShapeTypeOfFile) { //Free(); int aStat = TryOpenShapeFile(theFileName); diff --cc src/HYDROData/HYDROData_ShapeFile.h index 10dec110,d74e63d5..41f2200f --- a/src/HYDROData/HYDROData_ShapeFile.h +++ b/src/HYDROData/HYDROData_ShapeFile.h @@@ -19,12 -19,11 +19,17 @@@ #ifndef HYDRODATA_SHAPEFILE_H #define HYDRODATA_SHAPEFILE_H --#include - #include - #include +#include "HYDROData.h" ++ + #include ++ +#include + + #include -#include "HYDROData.h" ++ ++#include ++ + //extern "C" { #include //}; @@@ -118,13 -118,13 +123,14 @@@ public //Import Polyline void ReadSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, - int theInd, NCollection_Sequence& theEntities); - int theInd, NCollection_Sequence& theEntities, bool bReadAsPolyline = false); ++ int theInd, NCollection_Sequence& theEntities, ++ bool bReadAsPolylin = false); void ReadSHPPoly3D(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, - int theInd, NCollection_Sequence& theEntities); + int theInd, NCollection_Sequence& theEntities); HYDRODATA_EXPORT int ImportPolylines(Handle(HYDROData_Document) theDocument, const QString& theFileName, - NCollection_Sequence& theEntities, int& theShapeTypeOfFile); + NCollection_Sequence& theEntities, int& theShapeTypeOfFile); HYDRODATA_EXPORT QString GetShapeTypeName(int theType); diff --cc src/HYDROData/HYDROData_ShapesGroup.cxx index 1a086b76,92fd7e17..9db2e01c --- a/src/HYDROData/HYDROData_ShapesGroup.cxx +++ b/src/HYDROData/HYDROData_ShapesGroup.cxx @@@ -30,7 -30,9 +30,8 @@@ #include #include #include + #include -IMPLEMENT_STANDARD_HANDLE(HYDROData_ShapesGroup,HYDROData_Entity) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ShapesGroup,HYDROData_Entity) void HYDROData_ShapesGroup::GroupDefinition::Update( SeqOfGroupsDefs* theGroupsDefs, diff --cc src/HYDROData/HYDROData_ShapesGroup.h index 92018bf5,394bf16e..71c4c4be --- a/src/HYDROData/HYDROData_ShapesGroup.h +++ b/src/HYDROData/HYDROData_ShapesGroup.h @@@ -25,9 -26,13 +25,10 @@@ #include class TopoDS_Shape; -class TopTools_ListOfShape; class BRepBuilderAPI_MakeShape; class ShapeUpgrade_UnifySameDomain; + class BRepTools_ReShape; -DEFINE_STANDARD_HANDLE(HYDROData_ShapesGroup, HYDROData_Entity) - /**\class HYDROData_ShapesGroup * \brief Class that stores/retreives the sequence of shapes. */ diff --cc src/HYDROData/HYDROData_SplitToZonesTool.h index c5545978,367b22cd..2e3b8711 --- a/src/HYDROData/HYDROData_SplitToZonesTool.h +++ b/src/HYDROData/HYDROData_SplitToZonesTool.h @@@ -30,11 -30,13 +30,13 @@@ #include #include #include - #include + #include + #include #include #include + #include -class Handle(HYDROData_PolylineXY); +class HYDROData_PolylineXY; /** * \class HYDROData_SplitToZonesTool diff --cc src/HYDROData/HYDROData_Stream.cxx index 518753aa,9ffb8596..3ecb3e77 --- a/src/HYDROData/HYDROData_Stream.cxx +++ b/src/HYDROData/HYDROData_Stream.cxx @@@ -73,10 -76,15 +75,14 @@@ #include #include + #include + #include + #include + #include -#include - #include #include +#include //#define DEB_STREAM 1 #ifdef DEB_STREAM @@@ -86,8 -94,11 +92,10 @@@ #include #endif + #include + typedef NCollection_DataMap HYDROData_DataMapOfRealOfHDProfile; -IMPLEMENT_STANDARD_HANDLE(HYDROData_Stream,HYDROData_NaturalObject) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Stream,HYDROData_NaturalObject) @@@ -170,7 -187,11 +184,11 @@@ void HYDROData_Stream::Update( } } - UpdatePrs(); - Handle_HYDROData_DTM dtm = DTM(); ++ Handle(HYDROData_DTM) dtm = DTM(); + dtm->Update(); + UpdatePrs( dtm ); + + HYDROData_NaturalObject::Update(); } bool HYDROData_Stream::IsHas2dPrs() const @@@ -178,64 -199,58 +196,58 @@@ return true; } - bool HYDROData_Stream::CreatePresentations( const Handle(HYDROData_PolylineXY)& theHydAxis, - const HYDROData_SequenceOfObjects& theProfiles, - PrsDefinition& thePrs ) -bool HYDROData_Stream::CreatePresentations( const Handle_HYDROData_DTM& theDTM, ++bool HYDROData_Stream::CreatePresentations( const Handle(HYDROData_DTM)& theDTM, + PrsDefinition& thePrs ) { - if ( theHydAxis.IsNull() || theProfiles.Length() < 2 ) + if ( theDTM.IsNull() ) + return false; + + HYDROData_SequenceOfObjects profiles = theDTM->GetProfiles(); + if( profiles.Length() < 2 ) return false; - Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, theProfiles.Length()); - Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, theProfiles.Length()); - Handle(TopTools_HArray1OfShape) anArrOfProfiles = new TopTools_HArray1OfShape(1, theProfiles.Length()); - Handle(TopTools_HArray1OfShape) anArrOf2DProfiles = new TopTools_HArray1OfShape(1, theProfiles.Length()); + TopoDS_Shape Out3dPres; + TopoDS_Shape Out2dPres; + TopoDS_Shape OutLeftB; + TopoDS_Shape OutRightB; + TopoDS_Shape OutInlet; + TopoDS_Shape OutOutlet; + + theDTM->GetPresentationShapes(Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet); + + thePrs.myInlet = TopoDS::Wire(OutInlet); + thePrs.myOutlet = TopoDS::Wire(OutOutlet); + thePrs.myLeftBank = TopoDS::Wire(OutLeftB); + thePrs.myRightBank = TopoDS::Wire(OutRightB); + thePrs.myPrs2D = Out2dPres; + thePrs.myPrs3D = Out3dPres; + /*std::vector profiles3d; + profiles3d.reserve(profiles.Length()); // Pre-processing - HYDROData_SequenceOfObjects::Iterator anIter( theProfiles ); + HYDROData_SequenceOfObjects::Iterator anIter( profiles ); for (int i=1 ; anIter.More(); anIter.Next(),i++ ) { Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( anIter.Value() ); - if ( aProfile.IsNull() ) - continue; - const TopoDS_Shape& aProf3d = aProfile->GetShape3D(); - gp_XY aPnt1, aPnt2; - if ( !aProfile->GetLeftPoint( aPnt1, false ) || !aProfile->GetRightPoint( aPnt2, false ) ) + if ( aProfile.IsNull() ) continue; - anArrOfProfiles->SetValue(i,aProfile->GetShape3D());//aProfile->GetTopShape(); - anArrOf2DProfiles->SetValue(i,aProfile->GetTopShape()); + const TopoDS_Shape& aProfileShape = aProfile->GetShape3D(); + //TopExp_Explorer exp(aProfileShape, TopAbs_EDGE); + profiles3d.push_back( TopoDS::Wire(aProfileShape) ); + }*/ - gp_Pnt aCurFP, aCurLP; - TopoDS_Vertex aV1, aV2; - TopExp::Vertices(TopoDS::Wire(aProf3d), aV1, aV2); - gp_Pnt aP1 = BRep_Tool::Pnt(aV1); - if(aP1.X() == aPnt1.X() && aP1.Y() == aPnt1.Y()) - aCurFP = aP1; - else - aCurLP = aP1; - aP1 = BRep_Tool::Pnt(aV2); - if(aP1.X() == aPnt2.X() && aP1.Y() == aPnt2.Y()) - aCurLP = aP1; - else - aCurFP = aP1; - anArrayOfFPnt->SetValue(i,aCurFP); - anArrayOfLPnt->SetValue(i,aCurLP); - } - - return CreatePresentations( anArrayOfFPnt, anArrayOfLPnt, anArrOfProfiles, anArrOf2DProfiles, thePrs ); + return true; } - void HYDROData_Stream::UpdatePrs() -void HYDROData_Stream::UpdatePrs( const Handle_HYDROData_DTM& theDTM ) ++void HYDROData_Stream::UpdatePrs( const Handle(HYDROData_DTM)& theDTM ) { HYDROData_NaturalObject::Update(); - - Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis(); - HYDROData_SequenceOfObjects aRefProfiles = GetProfiles(); - + PrsDefinition aResultPrs; - if ( !CreatePresentations( aHydAxis, aRefProfiles, aResultPrs ) ) + if ( !CreatePresentations( theDTM, aResultPrs ) ) return; SetShape3D( aResultPrs.myPrs3D ); @@@ -315,6 -330,34 +327,34 @@@ TopoDS_Shape HYDROData_Stream::GetOutle return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 4); } -Handle_HYDROData_DTM HYDROData_Stream::DTM() const ++Handle(HYDROData_DTM) HYDROData_Stream::DTM() const + { + const_cast( this )->checkAndSetAltitudeObject(); + return Handle(HYDROData_DTM)::DownCast( GetAltitudeObject() ); + } + + double HYDROData_Stream::GetDDZ() const + { + return DTM()->GetDDZ(); + } + + void HYDROData_Stream::SetDDZ( double theDDZ ) + { + DTM()->SetDDZ( theDDZ ); + Changed( Geom_3d ); + } + + double HYDROData_Stream::GetSpatialStep() const + { + return DTM()->GetSpatialStep(); + } + + void HYDROData_Stream::SetSpatialStep( double theSpatialStep ) + { + DTM()->SetSpatialStep( theSpatialStep ); + Changed( Geom_3d ); + } + bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis ) { if ( !IsValidAsAxis( theAxis ) ) @@@ -711,12 -748,12 +746,12 @@@ void HYDROData_Stream::updateProfilesOr ObjectKind HYDROData_Stream::getAltitudeObjectType() const { - return KIND_STREAM_ALTITUDE; + return KIND_DTM; } -void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray ) +void HYDROData_Stream::setParametersArray( const QVector& theArray ) { - if ( theArray.Length() == 0 ) + if ( theArray.size() == 0 ) { removeParametersArray(); return; @@@ -1013,155 -1050,78 +1048,78 @@@ void HYDROData_Stream::CopyTo( const Ha } } } - - bool HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt) theArrayOfFPnt, + void HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt) theArrayOfFPnt, const Handle(TColgp_HArray1OfPnt) theArrayOfLPnt, const Handle(TopTools_HArray1OfShape) theArrOfProfiles, - const Handle(TopTools_HArray1OfShape) theArrOf2DProfiles, PrsDefinition& thePrs ) { - if ( theArrayOfFPnt.IsNull() || theArrayOfLPnt.IsNull() || theArrOfProfiles.IsNull() ) { - return false; - } - if ( theArrayOfFPnt->Length() != theArrayOfLPnt->Length() ) { - return false; - } - - // Construct of the 3D presentation - Handle(Geom_BSplineCurve) aBSpline = buildInterpolationCurve (theArrayOfFPnt); - if(aBSpline.IsNull()) - return false; - - TopoDS_Edge anEdgLeft, anEdgRight; - - BRepBuilderAPI_MakeEdge aMakeEdge(aBSpline); - if(aMakeEdge.IsDone()) - anEdgLeft = aMakeEdge.Edge(); - - if(anEdgLeft.IsNull()) - return false; - - aBSpline.Nullify(); - aBSpline = buildInterpolationCurve (theArrayOfLPnt); - if(aBSpline.IsNull()) - return false; - - aMakeEdge.Init(aBSpline); - if(aMakeEdge.IsDone()) - anEdgRight = aMakeEdge.Edge(); - - if(anEdgRight.IsNull()) - return false; - - BRep_Builder aBB; - TopoDS_Compound aCmp; - aBB.MakeCompound(aCmp); - for (int i=1 ; i < theArrOfProfiles->Length() +1; i++ ) - aBB.Add(aCmp, theArrOfProfiles->Value(i)); - - aBB.Add(aCmp,anEdgLeft); - aBB.Add(aCmp,anEdgRight); - BRepCheck_Analyzer aCh(aCmp); - if(aCh.IsValid()) - thePrs.myPrs3D = aCmp; - #ifdef DEB_UPDATE - else { - BRepTools::Write(aCmp, "str3d.brep"); - thePrs.myPrs3D = aCmp; + HYDROData_Bathymetry::AltitudePoints left; + for (int i = theArrayOfLPnt->Lower(); i <= theArrayOfLPnt->Upper(); i++) + { + left.push_back(HYDROData_Bathymetry::AltitudePoint(theArrayOfLPnt->Value(i).X(), + theArrayOfLPnt->Value(i).Y(), + theArrayOfLPnt->Value(i).Z())); } - #endif - // Construct the top presentation - int aNbPoints = theArrayOfFPnt->Length(); - Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, aNbPoints); - Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, aNbPoints); - for( int i=1; i <= aNbPoints; i++ ) { - gp_Pnt aPnt = theArrayOfFPnt->Value(i); - aPnt.SetZ(.0); // make 2d - anArrayOfFPnt->SetValue(i, aPnt); - aPnt = theArrayOfLPnt->Value(i); - aPnt.SetZ(.0); - anArrayOfLPnt->SetValue(i, aPnt); + HYDROData_Bathymetry::AltitudePoints right; + for (int i = theArrayOfFPnt->Lower(); i <= theArrayOfFPnt->Upper(); i++) + { + right.push_back(HYDROData_Bathymetry::AltitudePoint(theArrayOfFPnt->Value(i).X(), + theArrayOfFPnt->Value(i).Y(), + theArrayOfFPnt->Value(i).Z())); } - aBSpline.Nullify(); - aBSpline = buildInterpolationCurve (anArrayOfFPnt); - if(aBSpline.IsNull()) - return false; - - aMakeEdge.Init(aBSpline); - if(aMakeEdge.IsDone()) - anEdgLeft = aMakeEdge.Edge(); - - aBSpline.Nullify(); - aBSpline = buildInterpolationCurve (anArrayOfLPnt); - if(aBSpline.IsNull()) - return false; - - aMakeEdge.Init(aBSpline); - if(aMakeEdge.IsDone()) - anEdgRight = aMakeEdge.Edge(); - if(anEdgRight.IsNull()) - return false; - - BRepBuilderAPI_MakeEdge aMakeEdge2(anArrayOfFPnt->Value(1),anArrayOfLPnt->Value(1)); - TopoDS_Edge aBotEdge, aTopEdge; - if(aMakeEdge2.IsDone()) - aBotEdge = aMakeEdge2.Edge(); - - BRepBuilderAPI_MakeEdge aMakeEdge3(anArrayOfFPnt->Value(anArrayOfFPnt->Length()),anArrayOfLPnt->Value(anArrayOfLPnt->Length())); - if(aMakeEdge3.IsDone()) - aTopEdge = aMakeEdge3.Edge(); + std::vector dummy; + TopTools_IndexedMapOfOrientedShape ll = HYDROData_DTM::Create3DShape(left, right, dummy); - // Make wire for 2D presentation with updating of corresponding edges - BRepBuilderAPI_MakeWire aMakeWire; - - aMakeWire.Add( aBotEdge ); - thePrs.myInlet = aMakeWire.Edge(); - - aMakeWire.Add( anEdgLeft ); - thePrs.myLeftBank = aMakeWire.Edge(); - - aMakeWire.Add( aTopEdge ); - thePrs.myOutlet = aMakeWire.Edge(); - - aMakeWire.Add( anEdgRight ); - thePrs.myRightBank = aMakeWire.Edge(); - - TopoDS_Wire aSectProfileWire; - if(aMakeWire.IsDone()) - aSectProfileWire = aMakeWire.Wire(); - - BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True ); - TopoDS_Face aFace; - aMakeFace.Build(); - if( aMakeFace.IsDone() ) - aFace = aMakeFace.Face(); + TopoDS_Shape LB, RB, IL, OL; - TopoDS_Shape aPrs2D; - - if ( !theArrOf2DProfiles.IsNull() ) { - aCmp.Nullify(); - aBB.MakeCompound(aCmp); - aBB.Add(aCmp,aFace); - for(int i=1;i <= theArrOf2DProfiles->Length(); i++) - aBB.Add(aCmp, theArrOf2DProfiles->Value(i)); - - aPrs2D = aCmp; - } else { - aPrs2D = aFace; + if (!ll.IsEmpty()) + { + LB = TopoDS::Wire(ll(1)); + RB = TopoDS::Wire(ll(2)); } - aCh.Init(aPrs2D); - if(aCh.IsValid()) - thePrs.myPrs2D = aPrs2D; - #ifdef DEB_UPDATE - else { - BRepTools::Write(aPrs2D, "str2d.brep"); - thePrs.myPrs2D = aPrs2D; + 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, LB); + BB.Add(newCmp, IL); + BB.Add(newCmp, OL); + BB.Add(newCmp, RB); + + thePrs.myPrs3D = newCmp; + std::set 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 - return true; + thePrs.myLeftBank = TopoDS::Wire(LS(1)); + thePrs.myInlet = TopoDS::Wire(LS(2)); + thePrs.myOutlet = TopoDS::Wire(LS(3)); + thePrs.myRightBank = TopoDS::Wire(LS(4)); + -} +} diff --cc src/HYDROData/HYDROData_Stream.h index ee72a164,0eb6cde9..923c23f5 --- a/src/HYDROData/HYDROData_Stream.h +++ b/src/HYDROData/HYDROData_Stream.h @@@ -23,14 -23,21 +23,17 @@@ #include #include + #include #include + #include -DEFINE_STANDARD_HANDLE(HYDROData_Stream, HYDROData_NaturalObject) - -class Handle(HYDROData_PolylineXY); -class Handle(HYDROData_Polyline3D); -class Handle(HYDROData_Profile); ++class HYDROData_DTM; +class HYDROData_PolylineXY; +class HYDROData_Polyline3D; +class HYDROData_Profile; class HYDROData_IProfilesInterpolator; -class TColStd_Array1OfReal; -class Handle(TopTools_HArray1OfShape); -class Handle_HYDROData_DTM; -class TopTools_ListOfShape; +class TopTools_HArray1OfShape; /**\class HYDROData_Stream @@@ -72,18 -80,12 +75,12 @@@ public /** * Creates the presentations(2D and 3D) by given hydraulic axis and profiles. */ - HYDRODATA_EXPORT static bool CreatePresentations( const Handle(HYDROData_PolylineXY)& theHydAxis, - const HYDROData_SequenceOfObjects& theProfiles, - PrsDefinition& thePrs ); - HYDRODATA_EXPORT static bool CreatePresentations( const Handle_HYDROData_DTM& theDTM, - PrsDefinition& thePrs ); ++ HYDRODATA_EXPORT static bool CreatePresentations( const Handle(HYDROData_DTM)& theDTM, ++ PrsDefinition& thePrs ); - /** - * Creates the presentations(2D and 3D) by given first points, last points and profiles. - * If 2D profiles is null - they will not used in the presentation. - */ - HYDRODATA_EXPORT static bool CreatePresentations( const Handle(TColgp_HArray1OfPnt) theArrayOfFPnt, + HYDRODATA_EXPORT static void CreatePresentations( const Handle(TColgp_HArray1OfPnt) theArrayOfFPnt, const Handle(TColgp_HArray1OfPnt) theArrayOfLPnt, const Handle(TopTools_HArray1OfShape) theArrOfProfiles, - const Handle(TopTools_HArray1OfShape) theArrOf2DProfiles, PrsDefinition& thePrs ); public: @@@ -118,7 -120,7 +115,7 @@@ /** * Update the shape presentations of stream. */ - HYDRODATA_EXPORT virtual void UpdatePrs(); - HYDRODATA_EXPORT void UpdatePrs( const Handle_HYDROData_DTM& ); ++ HYDRODATA_EXPORT void UpdatePrs( const Handle(HYDROData_DTM)& ); /** * @@@ -298,9 -306,12 +301,12 @@@ private void removeParameter( const int& theIndex ); - protected: - Handle_HYDROData_DTM DTM() const; ++ Handle(HYDROData_DTM) DTM() const; + + protected: friend class HYDROData_Iterator; + friend class test_HYDROData_Stream; /** * Creates new object in the internal data structure. Use higher level objects diff --cc src/HYDROGUI/HYDROGUI_CalculationOp.cxx index 797e5fca,6200d72c..134c3bd0 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@@ -1221,7 -1276,9 +1276,9 @@@ void HYDROGUI_CalculationOp::createPrev HYDROData_SequenceOfObjects::Iterator anIter( aSeq ); for ( ; anIter.More(); anIter.Next() ) { - setObjectVisibility( anIter.Value(), true ); - const Handle_HYDROData_Entity& ent = anIter.Value(); ++ const Handle(HYDROData_Entity)& ent = anIter.Value(); + if (!ent.IsNull()) + setObjectVisibility( ent, true ); } //Process the draw events for viewer diff --cc src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx index 5685a5f2,196bd70d..73e755e7 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx @@@ -31,8 -31,8 +31,8 @@@ const Quantity_Color EDGES_COLOR = Quantity_NOC_SLATEGRAY; const int HILIGHT_ISO_NB = 10; --IMPLEMENT_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape ) --IMPLEMENT_STANDARD_RTTIEXT( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape ) ++//@MZN zzz IMPLEMENT_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape ) ++//@MZN zzz IMPLEMENT_STANDARD_RTTIEXT( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape ) HYDROGUI_LandCoverMapPrs::HYDROGUI_LandCoverMapPrs( const Handle(HYDROData_LandCoverMap)& theMap ) : AIS_ColoredShape( theMap->GetShape() ) diff --cc src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx index 72150112,e8e7941b..a88b5069 --- a/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx +++ b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx @@@ -77,10 -75,12 +77,10 @@@ Handle(AIS_InteractiveObject) HYDROGUI_ aThat->myCoords = new TColgp_HArray1OfPnt( aLower, anUpper ); aThat->myColors = new Quantity_HArray1OfColor( aLower, anUpper ); for( int i=aLower; i<=anUpper; i++ ) - aThat->myCoords->SetValue( i, aBathPoints.Value( i ) ); + aThat->myCoords->SetValue( i, gp_Pnt( aBathPoints[i].X, aBathPoints[i].Y, aBathPoints[i].Z ) ); - - return aPntCloud; } - else - return Handle_AIS_InteractiveObject(); + + return aPntCloud; } void HYDROGUI_ShapeBathymetry::GetRange( double& theMin, double& theMax ) const @@@ -102,8 -102,10 +102,10 @@@ } } -void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(Aspect_ColorScale)& theColorScale ) +void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(AIS_ColorScale)& theColorScale ) { + if (!myCoords) + return; for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ ) { double z = myCoords->Value( i ).Z(); diff --cc src/HYDROGUI/HYDROGUI_ShapeBathymetry.h index 459acd58,8a644721..c736c60f --- a/src/HYDROGUI/HYDROGUI_ShapeBathymetry.h +++ b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.h @@@ -48,13 -48,15 +48,15 @@@ public virtual void setVisible( const bool theState, const bool theIsUpdateViewer = true ); protected: - virtual Handle_AIS_InteractiveObject createShape() const; + virtual Handle(AIS_InteractiveObject) createShape() const; virtual void displayShape( const bool theIsUpdateViewer ); + void setToUpdateColorScale( bool isChanged ); + private: HYDROGUI_OCCDisplayer* myDisplayer; - Handle_TColgp_HArray1OfPnt myCoords; - Handle_Quantity_HArray1OfColor myColors; + Handle(TColgp_HArray1OfPnt) myCoords; + Handle(Quantity_HArray1OfColor) myColors; }; #endif diff --cc src/HYDROPy/CMakeLists.txt index 7a28b970,6eedb591..80464125 --- a/src/HYDROPy/CMakeLists.txt +++ b/src/HYDROPy/CMakeLists.txt @@@ -1,8 -1,6 +1,6 @@@ include(../../CMake/Common.cmake) -include(UsePyQt4) +INCLUDE(UsePyQt) - # --- options --- - # additional include directories INCLUDE_DIRECTORIES( ${CAS_INCLUDE_DIRS} @@@ -35,49 -33,48 +33,48 @@@ SET(_sip_input_fil ) SET(_add_SOURCES - sipHYDROPyNCollection_Sequence0100HYDROData_IPolylineSectionType.cc + sipHYDROPycmodule.cc - sipHYDROPygp_XY.cc + sipHYDROPyNCollection_Sequence0600opencascadehandle0100HYDROData_Entity.cc - sipHYDROPyNCollection_Sequence0100TCollection_AsciiString.cc + sipHYDROPygp_XYZ.cc + sipHYDROPyHYDROData_AltitudeObject.cc + sipHYDROPyHYDROData_Application.cc + sipHYDROPyHYDROData_ArtificialObject.cc + sipHYDROPyHYDROData_BathymetryAltitudePoint.cc + sipHYDROPyHYDROData_Bathymetry.cc + sipHYDROPyHYDROData_CalculationCase.cc + sipHYDROPyHYDROData_Channel.cc + sipHYDROPyHYDROData_Confluence.cc + sipHYDROPyHYDROData_Digue.cc + sipHYDROPyHYDROData_Document.cc + sipHYDROPyHYDROData_Entity.cc + sipHYDROPyHYDROData_IAltitudeObject.cc + sipHYDROPyHYDROData_IInterpolator.cc + sipHYDROPyHYDROData_Image.cc + sipHYDROPyHYDROData_ImmersibleZone.cc + sipHYDROPyHYDROData_IPolyline.cc + sipHYDROPyHYDROData_IProfilesInterpolator.cc + sipHYDROPyHYDROData_LandCoverMap.cc + sipHYDROPyHYDROData_NaturalObject.cc + sipHYDROPyHYDROData_Object.cc + sipHYDROPyHYDROData_ObstacleAltitude.cc + sipHYDROPyHYDROData_Obstacle.cc + sipHYDROPyHYDROData_Polyline3D.cc + sipHYDROPyHYDROData_PolylineXY.cc + sipHYDROPyHYDROData_Profile.cc + sipHYDROPyHYDROData_ProfileUZ.cc + sipHYDROPyHYDROData_Region.cc + sipHYDROPyHYDROData_River.cc + sipHYDROPyHYDROData_ShapesGroup.cc + sipHYDROPyHYDROData_SplitShapesGroup.cc + sipHYDROPyHYDROData_StreamAltitude.cc + sipHYDROPyHYDROData_Stream.cc + sipHYDROPyHYDROData_StricklerTable.cc + sipHYDROPyHYDROData_Zone.cc sipHYDROPyNCollection_Sequence0100gp_XY.cc sipHYDROPyNCollection_Sequence0100gp_XYZ.cc + sipHYDROPyNCollection_Sequence0100Handle_HYDROData_Entity.cc + sipHYDROPyNCollection_Sequence0100HYDROData_IPolylineSectionType.cc + sipHYDROPyNCollection_Sequence0100TCollection_AsciiString.cc sipHYDROPyNCollection_Sequence1800.cc sipHYDROPyNCollection_Sequence2400.cc sipHYDROPyNCollection_Sequence2600.cc @@@ -84,10 -85,8 +85,8 @@@ sipHYDROPyTCollection_AsciiString.cc ) - # --- sources --- - # sources / sip wrappings -PYQT4_WRAP_SIP(_sip_SOURCES ${_sip_input_file} SOURCES ${_add_SOURCES}) +PYQT_WRAP_SIP(_sip_SOURCES ${_sip_files} SOURCES ${_add_SOURCES}) # sources / to compile SET(HYDROPy_SOURCES ${_sip_SOURCES}) diff --cc src/HYDROPy/HYDROData_Profile.sip index c5b91a60,601be203..e67faaea --- a/src/HYDROPy/HYDROData_Profile.sip +++ b/src/HYDROPy/HYDROData_Profile.sip @@@ -172,8 -172,9 +172,9 @@@ public */ static int ImportFromFile( HYDROData_Document theDoc, const TCollection_AsciiString& theFileName, - NCollection_Sequence& theBadProfilesIds ) + NCollection_Sequence& theBadProfilesIds, - bool isToProject = true ) - [int ( const Handle_HYDROData_Document&, ++ bool isToProject = true ) + [int ( const opencascade::handle&, const TCollection_AsciiString&, NCollection_Sequence& )]; %MethodCode diff --cc src/HYDRO_tests/CMakeLists.txt index 4eb4bde3,7ee64231..041a55d0 --- a/src/HYDRO_tests/CMakeLists.txt +++ b/src/HYDRO_tests/CMakeLists.txt @@@ -52,17 -59,15 +59,15 @@@ set(PROJECT_SOURCE TestLib_Runner.cxx ) - add_definitions( - -DLIGHT_MODE -DHYDRODATA_STATIC -DHYDROGUI_STATIC - ) + add_definitions( -DLIGHT_MODE -DHYDRODATA_STATIC -DHYDROGUI_STATIC ) IF( ${WIN32} ) - add_definitions( -DWNT ) + add_definitions( -DWNT -D__WIN32__ -D__x86__ -D_WIN64 -D_WIN32_WINNT=0x0400 -D__NT__ -D__OSVERSION__=4 ) ENDIF() - SET( CPPUNIT_INCLUDES $ENV{cppUNIT_ROOT}/include ) + SET( CPPUNIT_INCLUDES $ENV{CPPUNIT_ROOT}/include ) SET( CAS_INCLUDES $ENV{CASROOT}/inc ) -SET( QT_INCLUDES $ENV{QTDIR}/include $ENV{QTDIR}/include/QtCore $ENV{QTDIR}/include/QtGui $ENV{QTDIR}/include/QtTest ) +SET( QT_INCLUDES $ENV{QT5_ROOT_DIR}/include $ENV{QT5_ROOT_DIR}/include/QtCore $ENV{QT5_ROOT_DIR}/include/QtGui $ENV{QT5_ROOT_DIR}/include/QtTest ) SET( KERNEL_INCLUDES $ENV{KERNEL_ROOT_DIR}/include/salome ) SET( GUI_INCLUDES $ENV{GUI_ROOT_DIR}/include/salome ) SET( GEOM_INCLUDES $ENV{GEOM_ROOT_DIR}/include/salome ) diff --cc src/HYDRO_tests/ExternalFiles.cmake index 79f07699,004295c1..b093912a --- a/src/HYDRO_tests/ExternalFiles.cmake +++ b/src/HYDRO_tests/ExternalFiles.cmake @@@ -72,6 -81,9 +82,9 @@@ set( EXTERNAL_FILE set( MOC_HEADERS ../HYDROGUI/HYDROGUI_InputPanel.h ../HYDROGUI/HYDROGUI_StricklerTableDlg.h + ../HYDROGUI/HYDROGUI_StreamDlg.h + ../HYDROGUI/HYDROGUI_ListSelector.h + ../HYDROGUI/HYDROGUI_OrderedListWidget.h ) -QT4_WRAP_CPP( PROJECT_MOC_HEADERS ${MOC_HEADERS} ) +QT_WRAP_MOC( PROJECT_MOC_HEADERS ${MOC_HEADERS} ) diff --cc src/HYDRO_tests/TestViewer.cxx index c5e8e513,64155ea6..144545e1 --- a/src/HYDRO_tests/TestViewer.cxx +++ b/src/HYDRO_tests/TestViewer.cxx @@@ -332,6 -346,14 +341,11 @@@ void TestViewer::showColorScale( bool i } } + bool TestViewer::ColorScaleIsDisplayed() + { - Handle(V3d_View) aView = myViewWindow->getViewPort()->getView(); - if( aView.IsNull() ) - return false; - return aView->ColorScaleIsDisplayed(); ++ return context()->IsDisplayed( colorScale() ); + } + void TestViewer::select( int theViewX, int theViewY ) { Handle(V3d_View) aView = myViewWindow->getViewPort()->getView(); diff --cc src/HYDRO_tests/TestViewer.h index de076a1e,f3dea715..c27e5d36 --- a/src/HYDRO_tests/TestViewer.h +++ b/src/HYDRO_tests/TestViewer.h @@@ -26,8 -24,10 +26,9 @@@ class OCCViewer_ViewWindow class TopoDS_Shape; class QString; class QColor; + class QImage; -class Handle_AIS_InteractiveContext; -class Handle_AIS_InteractiveObject; -class Handle_Aspect_ColorScale; +class AIS_InteractiveObject; +class AIS_ColorScale; class TestViewer { @@@ -42,11 -42,12 +43,12 @@@ public int theMode, int theSelectionMode, bool isFitAll, const char* theKey ); static void show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const QColor& theColor ); static void show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const char* theKey ); - static bool AssertImages( QString& theMessage ); + static bool AssertImages( QString& theMessage, const QImage* = 0, const char* theCase = 0 ); static QColor GetColor(int i); - static Handle_Aspect_ColorScale colorScale(); + static Handle(AIS_ColorScale) colorScale(); static void showColorScale( bool ); + static bool ColorScaleIsDisplayed(); static void select( int theViewX, int theViewY ); diff --cc src/HYDRO_tests/test_HYDROData_CalcCase.cxx index 00000000,7e3c9b72..af0c7427 mode 000000,100644..100644 --- a/src/HYDRO_tests/test_HYDROData_CalcCase.cxx +++ b/src/HYDRO_tests/test_HYDROData_CalcCase.cxx @@@ -1,0 -1,108 +1,107 @@@ + // Copyright (C) 2014-2015 EDF-R&D + // This library is free software; you can redistribute it and/or + // modify it under the terms of the GNU Lesser General Public + // License as published by the Free Software Foundation; either + // version 2.1 of the License, or (at your option) any later version. + // + // This library is distributed in the hope that it will be useful, + // but WITHOUT ANY WARRANTY; without even the implied warranty of + // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + // Lesser General Public License for more details. + // + // You should have received a copy of the GNU Lesser General Public + // License along with this library; if not, write to the Free Software + // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + // + // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + // + + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include -#include + #include + #include + #include + #include + + + QString REF_DATA_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/bin/salome/test"; + + + void test_HYDROData_CalcCase::test_add_int_wires() + { + { + TopoDS_Shape out; + TopTools_ListOfShape Wires; + + BRep_Builder B; + TopoDS_Shape InF; + TopoDS_Shape InP; + BRepTools::Read(InP, (REF_DATA_PATH + "/p1.brep").toStdString().c_str(), B); + BRepTools::Read(InF, (REF_DATA_PATH + "/r2.brep").toStdString().c_str(), B); + Wires.Append(InP); + + TopTools_ListOfShape OutSh; + TopTools_IndexedDataMapOfShapeShape ls; + HYDROData_SplitToZonesTool::CutByEdges(InF, Wires, OutSh, &ls, NULL); + + CPPUNIT_ASSERT_EQUAL(2, OutSh.Extent()); + TopoDS_Compound cmp; + B.MakeCompound(cmp); + B.Add(cmp, OutSh.First()); + B.Add(cmp, OutSh.Last()); + TestViewer::show( cmp, AIS_Shaded, true, "cc_int_w_1" ); + //CPPUNIT_ASSERT_IMAGES + } + + { + TopoDS_Shape out; + TopTools_ListOfShape Wires; + + BRep_Builder B; + TopoDS_Shape InF; + TopoDS_Shape InP; + BRepTools::Read(InP, (REF_DATA_PATH + "/p2.brep").toStdString().c_str(), B); + BRepTools::Read(InF, (REF_DATA_PATH + "/r2.brep").toStdString().c_str(), B); + Wires.Append(InP); + + TopTools_ListOfShape OutSh; + TopTools_IndexedDataMapOfShapeShape ls; + HYDROData_SplitToZonesTool::CutByEdges(InF, Wires, OutSh, &ls, NULL); + CPPUNIT_ASSERT_EQUAL(1, OutSh.Extent()); + TestViewer::show( OutSh.First(), AIS_WireFrame, true, "cc_int_w_2" ); + //CPPUNIT_ASSERT_IMAGES + } + + { + TopoDS_Shape out; + TopTools_ListOfShape Wires; + + BRep_Builder B; + TopoDS_Shape InF; + TopoDS_Shape InP; + BRepTools::Read(InP, (REF_DATA_PATH + "/p3.brep").toStdString().c_str(), B); + BRepTools::Read(InF, (REF_DATA_PATH + "/r2.brep").toStdString().c_str(), B); + Wires.Append(InP); + + TopTools_ListOfShape OutSh; + TopTools_IndexedDataMapOfShapeShape ls; + HYDROData_SplitToZonesTool::CutByEdges(InF, Wires, OutSh, &ls, NULL); + CPPUNIT_ASSERT_EQUAL(1, OutSh.Extent()); + TestViewer::show( OutSh.First(), AIS_WireFrame, true, "cc_int_w_3" ); + CPPUNIT_ASSERT_IMAGES + } + + } + + + diff --cc src/HYDRO_tests/test_HYDROData_DTM.cxx index 00000000,175b42b8..0436c8fb mode 000000,100644..100644 --- a/src/HYDRO_tests/test_HYDROData_DTM.cxx +++ b/src/HYDRO_tests/test_HYDROData_DTM.cxx @@@ -1,0 -1,624 +1,624 @@@ + // Copyright (C) 2014-2015 EDF-R&D + // This library is free software; you can redistribute it and/or + // modify it under the terms of the GNU Lesser General Public + // License as published by the Free Software Foundation; either + // version 2.1 of the License, or (at your option) any later version. + // + // This library is distributed in the hope that it will be useful, + // but WITHOUT ANY WARRANTY; without even the implied warranty of + // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + // Lesser General Public License for more details. + // + // You should have received a copy of the GNU Lesser General Public + // License along with this library; if not, write to the Free Software + // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + // + // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + // + + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include -#include ++#include + #include + #include + #include + #include + #include + + const double EPS = 1E-3; + + extern QString REF_DATA_PATH; + NCollection_Sequence points; + + class DTM_item : public QGraphicsItem + { + public: + DTM_item( HYDROGUI_ShapeBathymetry* theDTM, double d ) + { + Handle(AIS_PointCloud) pc = Handle(AIS_PointCloud)::DownCast( theDTM->getAISObject() ); + Handle(Graphic3d_ArrayOfPoints) pp = pc->GetPoints(); + myBB = QRectF(); + double xmin, xmax, ymin, ymax; + myD = d; + + int n = pp->VertexNumber(); + + for( int i=1; i<=n; i++ ) + { + gp_Pnt pnt = pp->Vertice( i ); + Quantity_Color col = pp->VertexColor( i ); + + int r = col.Red()*255; + int g = col.Green()*255; + int b = col.Blue()*255; + int val = ( r << 16 ) + ( g << 8 ) + b; + double x = pnt.X(); + double y = -pnt.Y(); + QPointF aPnt( x, y ); + myPoints[val].append( aPnt ); + if( i==1 ) + { + xmin = x; + xmax = x; + ymin = y; + ymax = y; + } + else + { + if( x>xmax ) + xmax = x; + if( xymax ) + ymax = y; + if( y >::const_iterator it = myPoints.begin(), last = myPoints.end(); + for( ; it!=last; it++ ) + { + int r = ( it.key() >> 16 ) % 256; + int g = ( it.key() >> 8 ) % 256; + int b = ( it.key() >> 0 ) % 256; + QColor aColor( r, g, b ); + QBrush aBrush( aColor ); + foreach( QPointF pnt, it.value() ) + { + QRectF r( pnt.x()-myD/2, pnt.y()-myD/2, myD, myD ); + p->fillRect( r, aBrush ); + } + } + } + + private: + QRectF myBB; + double myD; + QMap > myPoints; + }; + + QImage draw_DTM( HYDROGUI_ShapeBathymetry* theDTM, double theD, int theWidth, int theHeight ) + { + QGraphicsScene aScene; + QGraphicsView aView; + DTM_item anItem( theDTM, theD ); + + aView.setScene( &aScene ); + aView.setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + aView.setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + aScene.addItem( &anItem ); + + aView.resize( theWidth, theHeight ); + QRectF bb = anItem.boundingRect(); + aView.fitInView( bb, Qt::KeepAspectRatio ); + QApplication::processEvents(); + + QPixmap aPixmap = QPixmap::grabWidget( &aView ); + return aPixmap.toImage(); + } + + + void test_HYDROData_DTM::setUp() + { + points.Clear(); + points.Append( gp_XY( 0.0, 5.0 ) ); + points.Append( gp_XY( 1.0, 1.0 ) ); + points.Append( gp_XY( 1.5, 0.0 ) ); + points.Append( gp_XY( 4.0, 4.0 ) ); + } + + void test_HYDROData_DTM::test_creation() + { + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_DTM) DTM = + Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) ); + + CPPUNIT_ASSERT_EQUAL( false, (bool)DTM.IsNull() ); + + aDoc->Close(); + } + + void test_HYDROData_DTM::test_hydraulic_axis() + { + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Profile) aProfile1 = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + Handle(HYDROData_Profile) aProfile2 = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + Handle(HYDROData_Profile) aProfile3 = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + aProfile1->SetParametricPoints( points ); + aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE ); + aProfile1->SetLeftPoint( gp_XY( 10, 10 ) ); + aProfile1->SetRightPoint( gp_XY( 20, 0 ) ); + + aProfile2->SetParametricPoints( points ); + aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE ); + aProfile2->SetLeftPoint( gp_XY( 50, 0 ) ); + aProfile2->SetRightPoint( gp_XY( 60, 10 ) ); + + aProfile3->SetParametricPoints( points ); + aProfile3->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE ); + aProfile3->SetLeftPoint( gp_XY( 200, 50 ) ); + aProfile3->SetRightPoint( gp_XY( 210, 40 ) ); + + std::vector distances; + std::vector profiles; + profiles.push_back( aProfile1 ); + profiles.push_back( aProfile2 ); + profiles.push_back( aProfile3 ); + + Handle_Geom2d_BSplineCurve HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances ); + CPPUNIT_ASSERT_EQUAL( false, (bool)HA.IsNull() ); + CPPUNIT_ASSERT_EQUAL( 3, (int)distances.size() ); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, distances[0], EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 43.499, distances[1], EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 211.474, distances[2], EPS ); + + gp_Pnt2d p; + gp_Vec2d q; + HA->D1( 0, p, q ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, p.X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 6.25, p.Y(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.568, q.X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.568, q.Y(), EPS ); + + aDoc->Close(); + } + + void test_HYDROData_DTM::test_profile_conversion_to_2d() + { + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Profile) aProfile1 = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + Handle(HYDROData_Profile) aProfile2 = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + aProfile1->SetParametricPoints( points ); + aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE ); + aProfile1->SetLeftPoint( gp_XY( 10, 10 ) ); + aProfile1->SetRightPoint( gp_XY( 20, 20 ) ); + + aProfile2->SetParametricPoints( points ); + aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE ); + aProfile2->SetLeftPoint( gp_XY( 10, 10 ) ); + aProfile2->SetRightPoint( gp_XY( 20, 20 ) ); + + double aUMin1 = std::numeric_limits::max(), + aUMax1 = -aUMin1, + aUMin2 = aUMin1, + aUMax2 = aUMax1; + gp_Vec2d aProfileDir; + std::vector curves1 = HYDROData_DTM::ProfileToParametric( aProfile1, aUMin1, aUMax1, aProfileDir ); + std::vector curves2 = HYDROData_DTM::ProfileToParametric( aProfile2, aUMin2, aUMax2, aProfileDir ); + + gp_Pnt2d aFirst, aLast; + CPPUNIT_ASSERT_EQUAL( 3, (int)curves1.size() ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aUMin1, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aUMax1, EPS ); + curves1[0]->D0( curves1[0]->FirstParameter(), aFirst ); + curves1[0]->D0( curves1[0]->LastParameter(), aLast ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aFirst.X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aFirst.Y(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aLast.X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, aLast.Y(), EPS ); + curves1[1]->D0( curves1[1]->FirstParameter(), aFirst ); + curves1[1]->D0( curves1[1]->LastParameter(), aLast ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aFirst.X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, aFirst.Y(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aLast.X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aLast.Y(), EPS ); + curves1[2]->D0( curves1[2]->FirstParameter(), aFirst ); + curves1[2]->D0( curves1[2]->LastParameter(), aLast ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aFirst.X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aFirst.Y(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aLast.X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 4.0, aLast.Y(), EPS ); + + CPPUNIT_ASSERT_EQUAL( 1, (int)curves2.size() ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aUMin2, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aUMax2, EPS ); + Handle(Geom2d_BSplineCurve) aBSpline = Handle(Geom2d_BSplineCurve)::DownCast( curves2[0] ); + CPPUNIT_ASSERT_EQUAL( false, (bool)aBSpline.IsNull() ); + const TColgp_Array1OfPnt2d& poles = aBSpline->Poles(); + CPPUNIT_ASSERT_EQUAL( 1, (int)poles.Lower() ); + CPPUNIT_ASSERT_EQUAL( 8, (int)poles.Upper() ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, poles.Value( 1 ).X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, poles.Value( 1 ).Y(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( -4.125, poles.Value( 2 ).X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.667, poles.Value( 2 ).Y(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( -3.150, poles.Value( 3 ).X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.120, poles.Value( 3 ).Y(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.242, poles.Value( 4 ).X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.574, poles.Value( 4 ).Y(), EPS ); + + aDoc->Close(); + } + + void test_HYDROData_DTM::test_profile_properties() + { + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + aProfile->SetParametricPoints( points ); + aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE ); + aProfile->SetLeftPoint( gp_XY( 10, 10 ) ); + aProfile->SetRightPoint( gp_XY( 20, 25 ) ); + + gp_Pnt lp; + gp_Vec2d dd; + double zmin, zmax; + HYDROData_DTM::GetProperties( aProfile, lp, dd, false, zmin, zmax ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 10, dd.X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 15, dd.Y(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS ); + + HYDROData_DTM::GetProperties( aProfile, lp, dd, true, zmin, zmax ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, dd.X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 10, dd.Y(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS ); + + aDoc->Close(); + } + + void test_HYDROData_DTM::test_profile_discretization_polyline() + { + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + aProfile->SetParametricPoints( points ); + aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE ); + aProfile->SetLeftPoint( gp_XY( 10, 10 ) ); + aProfile->SetRightPoint( gp_XY( 20, 20 ) ); + + HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0 ), aWid( 0.0, gp_Vec2d(), 0 ); + int dummy = 0; + HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 0.5, aMid, aWid, dummy ); + CPPUNIT_ASSERT_EQUAL( 11, (int)aMid.size() ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].Z, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.11, aMid[1].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aMid[1].Z, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.215, aMid[5].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aMid[5].Z, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.768, aMid[10].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aMid[10].Z, EPS ); + + CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].Z, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.989, aWid[1].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aWid[1].Z, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.618, aWid[5].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aWid[5].Z, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.142, aWid[10].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aWid[10].Z, EPS ); + + aDoc->Close(); + } + + void test_HYDROData_DTM::test_profile_discretization_spline() + { + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + aProfile->SetParametricPoints( points ); + aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE ); + aProfile->SetLeftPoint( gp_XY( 10, 10 ) ); + aProfile->SetRightPoint( gp_XY( 20, 20 ) ); + + HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0 ), aWid( 0.0, gp_Vec2d(), 0 ); + int dummy = 0 ; + HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 0.5, aMid, aWid, dummy ); + CPPUNIT_ASSERT_EQUAL( 11, (int)aMid.size() ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.242, aMid[0].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].Z, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.755, aMid[1].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aMid[1].Z, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.473, aMid[5].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aMid[5].Z, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.768, aMid[10].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aMid[10].Z, EPS ); + + CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.484, aWid[0].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].Z, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.809, aWid[1].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aWid[1].Z, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 9.472, aWid[5].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aWid[5].Z, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.142, aWid[10].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aWid[10].Z, EPS ); + + aDoc->Close(); + } + + void operator << ( std::ostream& s, const HYDROData_DTM::PointUZ& p ) + { + s << "(" << p.U << "; " << p.Z << ") "; + } + + void operator << ( std::ostream& s, const HYDROData_DTM::AltitudePoint& p ) + { + s << "(" << p.X << "; " << p.Y << "; " << p.Z << ") "; + } + + bool operator == ( const HYDROData_DTM::PointUZ& p1, const HYDROData_DTM::PointUZ& p2 ) + { + return fabs(p1.U-p2.U) i1; + HYDROData_DTM::Interpolate( A, B, 1, i1, false ); + + CPPUNIT_ASSERT_EQUAL( 2, (int)i1.size() ); + CPPUNIT_ASSERT_EQUAL( A, i1[0] ); + CPPUNIT_ASSERT_EQUAL( 3, (int)i1[1].size() ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 5, 0 ), i1[1][0] ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 8, 1 ), i1[1][1] ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 11, 2 ), i1[1][2] ); + + std::vector i2; + HYDROData_DTM::Interpolate( A, B, 1, i2, true ); + + CPPUNIT_ASSERT_EQUAL( 3, (int)i2.size() ); + CPPUNIT_ASSERT_EQUAL( A, i2[0] ); + CPPUNIT_ASSERT_EQUAL( 3, (int)i2[1].size() ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 5, 0 ), i2[1][0] ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 8, 1 ), i2[1][1] ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 11, 2 ), i2[1][2] ); + CPPUNIT_ASSERT_EQUAL( B, i2[2] ); + + std::vector i3; + HYDROData_DTM::Interpolate( A, B, 3, i3, false ); + + CPPUNIT_ASSERT_EQUAL( 4, (int)i3.size() ); + CPPUNIT_ASSERT_EQUAL( A, i3[0] ); + CPPUNIT_ASSERT_EQUAL( 3, (int)i3[1].size() ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 2.5, 0 ), i3[1][0] ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 4.5, 1 ), i3[1][1] ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 6.5, 2 ), i3[1][2] ); + } + + void test_HYDROData_DTM::test_curve_to_3d() + { + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Profile) aProfile1 = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + Handle(HYDROData_Profile) aProfile2 = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + aProfile1->SetParametricPoints( points ); + aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE ); + aProfile1->SetLeftPoint( gp_XY( 20, 0 ) ); + aProfile1->SetRightPoint( gp_XY( 10, 10 ) ); + + aProfile2->SetParametricPoints( points ); + aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE ); + aProfile2->SetLeftPoint( gp_XY( 100, 0 ) ); + aProfile2->SetRightPoint( gp_XY( 110, 0 ) ); + + std::vector distances; + std::vector profiles; + profiles.push_back( aProfile1 ); + profiles.push_back( aProfile2 ); + + Handle_Geom2d_BSplineCurve HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances ); + HYDROData_DTM::AltitudePoints points; + HYDROData_DTM::CurveUZ mid( 5.0, gp_Vec2d(-10,10), 0 ); + mid.push_back( HYDROData_DTM::PointUZ( 0, 5 ) ); + mid.push_back( HYDROData_DTM::PointUZ( 1, 6 ) ); + HYDROData_DTM::CurveUZ wid( 5.0, gp_Vec2d(-10,10), 0 ); + wid.push_back( HYDROData_DTM::PointUZ( 2, 5 ) ); + wid.push_back( HYDROData_DTM::PointUZ( 6, 6 ) ); + HYDROData_DTM::CurveTo3D( HA, mid, wid, points ); + + CPPUNIT_ASSERT_EQUAL( 4, (int)points.size() ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 16.380, -2.186, 6.0 ), points[0] ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 15.673, -1.479, 5.0 ), points[1] ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 14.259, -0.065, 5.0 ), points[2] ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 12.137, 2.056, 6.0 ), points[3] ); + + aDoc->Close(); + } + + void test_HYDROData_DTM::test_presentation() + { + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) ); + + Handle(HYDROData_Profile) aProfile1 = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + Handle(HYDROData_Profile) aProfile2 = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + aProfile1->SetParametricPoints( points ); + aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE ); + aProfile1->SetLeftPoint( gp_XY( 10, 10 ) ); + aProfile1->SetRightPoint( gp_XY( 20, 0 ) ); + + aProfile2->SetParametricPoints( points ); + aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE ); + aProfile2->SetLeftPoint( gp_XY( 110, 10 ) ); + aProfile2->SetRightPoint( gp_XY( 100, 0 ) ); + + HYDROData_SequenceOfObjects seq; + seq.Append( aProfile1 ); + seq.Append( aProfile2 ); + DTM->SetProfiles( seq ); + DTM->SetDDZ( 0.1 ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.1, DTM->GetDDZ(), EPS ); + DTM->SetSpatialStep( 1.0 ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS ); + DTM->Update(); + + CPPUNIT_ASSERT_EQUAL( 9177, (int)DTM->GetAltitudePoints().size() ); + + Handle_AIS_InteractiveContext aContext = TestViewer::context(); + HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM ); + aBathPrs->update( true, false ); + + bool ColorScaleIsDisp = TestViewer::ColorScaleIsDisplayed(); + TestViewer::showColorScale( true ); - Handle_Aspect_ColorScale aCS = TestViewer::colorScale(); ++ Handle(AIS_ColorScale) aCS = TestViewer::colorScale(); + aCS->SetMin( 0.0 ); + aCS->SetMax( 5.0 ); + aCS->SetNumberOfIntervals( 10 ); + aBathPrs->UpdateWithColorScale( aCS ); + + QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 ); + CPPUNIT_ASSERT_IMAGES2( &aDTMPrs, "DTM_1" ); + delete aBathPrs; + TestViewer::showColorScale( ColorScaleIsDisp ); + + aDoc->Close(); + } + + void test_HYDROData_DTM::test_garonne() + { + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data(); + fname += "/Profiles.xyz"; + NCollection_Sequence bad_ids; + + int aSize = HYDROData_Profile::ImportFromFile( aDoc, fname, bad_ids, true ); + + CPPUNIT_ASSERT_EQUAL( 0, bad_ids.Size() ); + CPPUNIT_ASSERT_EQUAL( 46, aSize ); + + HYDROData_SequenceOfObjects profiles; + HYDROData_Iterator it( aDoc, KIND_PROFILE ); + for( int i=0; it.More(); it.Next(), i++ ) + { + if( i>=25 && i<=35 ) + profiles.Append( Handle(HYDROData_Profile)::DownCast( it.Current() ) ); + } + + CPPUNIT_ASSERT_EQUAL( 11, (int)profiles.Size() ); + + Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) ); + DTM->SetProfiles( profiles ); + DTM->SetDDZ( 0.1 ); + DTM->SetSpatialStep( 1.0 ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.1, DTM->GetDDZ(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS ); + DTM->Update(); + + CPPUNIT_ASSERT_EQUAL( 282338, (int)DTM->GetAltitudePoints().size() ); + + Handle_AIS_InteractiveContext aContext = TestViewer::context(); + HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM ); + aBathPrs->update( true, false ); + + bool ColorScaleIsDisp = TestViewer::ColorScaleIsDisplayed(); + + TestViewer::showColorScale( true ); - Handle_Aspect_ColorScale aCS = TestViewer::colorScale(); ++ Handle(AIS_ColorScale) aCS = TestViewer::colorScale(); + aCS->SetMin( 0.0 ); + aCS->SetMax( 25.0 ); + aCS->SetNumberOfIntervals( 30 ); + aBathPrs->UpdateWithColorScale( aCS ); + + QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 ); + CPPUNIT_ASSERT_IMAGES2( &aDTMPrs, "DTM_2" ); + TestViewer::showColorScale( ColorScaleIsDisp ); + delete aBathPrs; + aDoc->Close(); + + } diff --cc src/HYDRO_tests/test_HYDROData_Stream.cxx index 00000000,6bf3c37d..52388f33 mode 000000,100644..100644 --- a/src/HYDRO_tests/test_HYDROData_Stream.cxx +++ b/src/HYDRO_tests/test_HYDROData_Stream.cxx @@@ -1,0 -1,273 +1,272 @@@ + // Copyright (C) 2014-2015 EDF-R&D + // This library is free software; you can redistribute it and/or + // modify it under the terms of the GNU Lesser General Public + // License as published by the Free Software Foundation; either + // version 2.1 of the License, or (at your option) any later version. + // + // This library is distributed in the hope that it will be useful, + // but WITHOUT ANY WARRANTY; without even the implied warranty of + // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + // Lesser General Public License for more details. + // + // You should have received a copy of the GNU Lesser General Public + // License along with this library; if not, write to the Free Software + // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + // + // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + // + + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + + extern QString REF_DATA_PATH; + NCollection_Sequence points2; + const double EPS = 1E-3; + + void test_HYDROData_Stream::setUp() + { + points2.Clear(); + points2.Append( gp_XY( 0.0, 5.0 ) ); + points2.Append( gp_XY( 1.0, 1.0 ) ); + points2.Append( gp_XY( 1.5, 0.0 ) ); + points2.Append( gp_XY( 4.0, 4.0 ) ); + } + + void test_HYDROData_Stream::tearDown() + { + } + + void test_HYDROData_Stream::test_dialog() + { + HYDROGUI_StreamDlg* aDlg = new HYDROGUI_StreamDlg( 0, "stream" ); + aDlg->show(); + qApp->processEvents(); + + QImage aStreamDlgImage = QPixmap::grabWidget( aDlg ).toImage(); + CPPUNIT_ASSERT_IMAGES2( &aStreamDlgImage, "StreamDlg" ); + + aDlg->setDDZ( 12.34 ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 12.34, aDlg->getDDZ(), EPS ); + + aDlg->setSpatialStep( 56.78 ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 56.78, aDlg->getSpatialStep(), EPS ); + + delete aDlg; + } + + void test_HYDROData_Stream::test_alt_object() + { + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Stream) aStream = + Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) ); + + CPPUNIT_ASSERT_EQUAL( false, (bool)aStream.IsNull() ); + CPPUNIT_ASSERT_EQUAL( true, (bool)aStream->GetAltitudeObject().IsNull() ); + CPPUNIT_ASSERT_EQUAL( false, (bool)aStream->DTM().IsNull() ); + CPPUNIT_ASSERT_EQUAL( false, (bool)aStream->GetAltitudeObject().IsNull() ); + CPPUNIT_ASSERT_EQUAL( KIND_DTM, aStream->getAltitudeObjectType() ); + + Handle(HYDROData_DTM) aDTM = + Handle(HYDROData_DTM)::DownCast( aStream->GetAltitudeObject() ); + CPPUNIT_ASSERT_EQUAL( false, (bool)aDTM.IsNull() ); + + aDoc->Close(); + } + + void test_HYDROData_Stream::test_params_sync() + { + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Stream) aStream = + Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) ); - Handle(HYDROData_DTM) aDTM = - Handle(HYDROData_DTM)::DownCast( aStream->DTM() ); ++ Handle(HYDROData_DTM) aDTM = aStream->DTM(); + CPPUNIT_ASSERT_EQUAL( false, (bool)aDTM.IsNull() ); + + Handle(HYDROData_Profile) aProfile1 = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + Handle(HYDROData_Profile) aProfile2 = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + aProfile1->SetParametricPoints( points2 ); + aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE ); + aProfile1->SetLeftPoint( gp_XY( 10, 10 ) ); + aProfile1->SetRightPoint( gp_XY( 20, 0 ) ); + + aProfile2->SetParametricPoints( points2 ); + aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE ); + aProfile2->SetLeftPoint( gp_XY( 50, 0 ) ); + aProfile2->SetRightPoint( gp_XY( 60, 10 ) ); + + HYDROData_SequenceOfObjects profiles; + profiles.Append( aProfile1 ); + profiles.Append( aProfile2 ); + + aStream->SetProfiles( profiles, false ); + aStream->SetDDZ( 3.14 ); + aStream->SetSpatialStep( 4.14 ); + + CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.14, aStream->GetDDZ(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.14, aDTM->GetDDZ(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 4.14, aStream->GetSpatialStep(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 4.14, aDTM->GetSpatialStep(), EPS ); + + HYDROData_SequenceOfObjects profiles1 = aStream->GetProfiles(); + CPPUNIT_ASSERT_EQUAL( 2, profiles1.Size() ); + CPPUNIT_ASSERT( profiles.Value(1)->Label() == profiles1.Value(1)->Label() ); + CPPUNIT_ASSERT( profiles.Value(2)->Label() == profiles1.Value(2)->Label() ); + + HYDROData_SequenceOfObjects profiles2 = aDTM->GetProfiles(); + CPPUNIT_ASSERT_EQUAL( 2, profiles2.Size() ); + CPPUNIT_ASSERT( profiles.Value(1)->Label() == profiles2.Value(1)->Label() ); + CPPUNIT_ASSERT( profiles.Value(2)->Label() == profiles2.Value(2)->Label() ); + + aDoc->Close(); + } + + void test_HYDROData_Stream::test_dump() + { + // Case 1. Without hydraulic axis + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_Stream) aStream1 = + Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) ); + aStream1->SetName( "stream_1" ); + + Handle(HYDROData_Profile) aProfile1 = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + aProfile1->SetName( "p1" ); + + Handle(HYDROData_Profile) aProfile2 = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + aProfile2->SetName( "p2" ); + + aProfile1->SetParametricPoints( points2 ); + aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE ); + aProfile1->SetLeftPoint( gp_XY( 10, 10 ) ); + aProfile1->SetRightPoint( gp_XY( 20, 0 ) ); + + aProfile2->SetParametricPoints( points2 ); + aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE ); + aProfile2->SetLeftPoint( gp_XY( 50, 0 ) ); + aProfile2->SetRightPoint( gp_XY( 60, 10 ) ); + + HYDROData_SequenceOfObjects profiles; + profiles.Append( aProfile1 ); + profiles.Append( aProfile2 ); + + aStream1->SetProfiles( profiles, false ); + aStream1->SetDDZ( 0.2 ); + aStream1->SetSpatialStep( 3.0 ); + + MapOfTreatedObjects objs; + objs["p1"] = aProfile1; + objs["p2"] = aProfile2; + + QStringList aScript1 = aStream1->DumpToPython( "", objs ); + CPPUNIT_ASSERT_EQUAL( 10, aScript1.size() ); + CPPUNIT_ASSERT_EQUAL( std::string( "stream_1 = hydro_doc.CreateObject( KIND_STREAM )" ), aScript1[0].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.SetName( \"stream_1\" )" ), aScript1[1].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript1[2].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.AddProfile( p1 )" ), aScript1[3].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.AddProfile( p2 )" ), aScript1[4].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.SetDDZ( 0.200 )" ), aScript1[5].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.SetSpatialStep( 3.000 )" ), aScript1[6].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript1[7].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "stream_1.Update()" ), aScript1[8].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript1[9].toStdString() ); + + // Case 2. With hydraulic axis + + Handle(HYDROData_Stream) aStream2 = + Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) ); + aStream2->SetName( "stream_2" ); + + Handle(HYDROData_PolylineXY) anHAxis = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + anHAxis->SetName( "axis" ); + + aStream2->SetProfiles( profiles, false ); + aStream2->SetDDZ( 0.2 ); + aStream2->SetSpatialStep( 3.0 ); + aStream2->SetReferenceObject( anHAxis, HYDROData_Stream::DataTag_HydraulicAxis ); + + objs.clear(); + objs["p1"] = aProfile1; + objs["p2"] = aProfile2; + objs["axis"] = anHAxis; + + QStringList aScript2 = aStream2->DumpToPython( "", objs ); + CPPUNIT_ASSERT_EQUAL( 11, aScript2.size() ); + CPPUNIT_ASSERT_EQUAL( std::string( "stream_2 = hydro_doc.CreateObject( KIND_STREAM )" ), aScript2[0].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.SetName( \"stream_2\" )" ), aScript2[1].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript2[2].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.SetHydraulicAxis( axis )" ), aScript2[3].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.AddProfile( p1 )" ), aScript2[4].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.AddProfile( p2 )" ), aScript2[5].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.SetDDZ( 0.200 )" ), aScript2[6].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.SetSpatialStep( 3.000 )" ), aScript2[7].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript2[8].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "stream_2.Update()" ), aScript2[9].toStdString() ); + CPPUNIT_ASSERT_EQUAL( std::string( "" ), aScript2[10].toStdString() ); + + aDoc->Close(); + } + + void test_HYDROData_Stream::test_presentation() + { + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data(); + fname += "/Profiles.xyz"; + NCollection_Sequence bad_ids; + + int aSize = HYDROData_Profile::ImportFromFile( aDoc, fname, bad_ids, true ); + + CPPUNIT_ASSERT_EQUAL( 0, bad_ids.Size() ); + CPPUNIT_ASSERT_EQUAL( 46, aSize ); + + HYDROData_SequenceOfObjects profiles; + HYDROData_Iterator it( aDoc, KIND_PROFILE ); + for( int i=0; it.More(); it.Next(), i++ ) + { + if( i>=25 && i<=35 ) + { + it.Current()->Update(); + profiles.Append( Handle(HYDROData_Profile)::DownCast( it.Current() ) ); + } + } + + Handle(HYDROData_Stream) aStream = + Handle(HYDROData_Stream)::DownCast( aDoc->CreateObject( KIND_STREAM ) ); + + aStream->SetProfiles( profiles, false ); + aStream->SetDDZ( 0.2 ); + aStream->SetSpatialStep( 10 ); + aStream->Update(); + + TopoDS_Shape aPrs3d = aStream->GetShape3D(); + TopoDS_Shape aPrs2d = aStream->GetTopShape(); + + TestViewer::show( aPrs2d, 0, true, "stream_dtm_2d" ); + CPPUNIT_ASSERT_IMAGES; + + TestViewer::eraseAll( true ); + TestViewer::show( aPrs3d, 0, true, "stream_dtm_3d" ); + CPPUNIT_ASSERT_IMAGES + + aDoc->Close(); + } +