From: isn Date: Wed, 12 Oct 2016 09:03:56 +0000 (+0300) Subject: getting nb of intersections (non-gui) + add of profiles of stream to tree X-Git-Tag: v1.6~57 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3627a8d6abf2c69fa15adc51056578fb41100841;p=modules%2Fhydro.git getting nb of intersections (non-gui) + add of profiles of stream to tree --- diff --git a/src/HYDROData/HYDROData_DTM.cxx b/src/HYDROData/HYDROData_DTM.cxx index f44f98a2..8311b147 100644 --- a/src/HYDROData/HYDROData_DTM.cxx +++ b/src/HYDROData/HYDROData_DTM.cxx @@ -47,6 +47,8 @@ #include #include + + IMPLEMENT_STANDARD_HANDLE( HYDROData_DTM, HYDROData_Bathymetry ) IMPLEMENT_STANDARD_RTTIEXT( HYDROData_DTM, HYDROData_Bathymetry ) @@ -199,7 +201,7 @@ void HYDROData_DTM::Update() HYDROData_SequenceOfObjects objs = GetProfiles(); double ddz = GetDDZ(); double step = GetSpatialStep(); - CreateProfilesFromDTM( objs, ddz, step, points, Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet, true, true ); + CreateProfilesFromDTM( objs, ddz, step, points, Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet, true, true, std::set() ); SetAltitudePoints( points ); SetShape( DataTag_LeftBankShape, OutLeftB); @@ -238,7 +240,8 @@ void HYDROData_DTM::CreateProfilesFromDTM (const HYDROData_SequenceOfObjects& In TopoDS_Shape& OutInlet, TopoDS_Shape& OutOutlet, bool Create3dPres, - bool Create2dPres) + bool Create2dPres, + std::set InvInd) { int aLower = InpProfiles.Lower(), anUpper = InpProfiles.Upper(); @@ -259,7 +262,7 @@ void HYDROData_DTM::CreateProfilesFromDTM (const HYDROData_SequenceOfObjects& In if( ddz>EPS && step>EPS ) CreateProfiles(profiles, ddz, step, left, right, points, main_profiles, - Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet, Create3dPres, Create2dPres ); + Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet, Create3dPres, Create2dPres, InvInd ); } void HYDROData_DTM::ProjWireOnPlane(const TopoDS_Wire& inpWire, const Handle_Geom_Plane& RefPlane, TopoDS_Wire& outWire) @@ -336,11 +339,12 @@ void HYDROData_DTM::CreateProfiles(const std::vector& TopoDS_Shape& OutInlet, TopoDS_Shape& OutOutlet, bool Create3dPres, - bool Create2dPres) + bool Create2dPres, + std::set InvInd) { if (theProfiles.empty()) return; - theOutPoints = Interpolate( theProfiles, theDDZ, theSpatialStep, theOutLeft, theOutRight, theOutMainProfiles ); + theOutPoints = Interpolate( theProfiles, theDDZ, theSpatialStep, theOutLeft, theOutRight, theOutMainProfiles, InvInd ); //note that if Create3dPres is false => Create2dPres flag is meaningless! if (Create3dPres) { @@ -581,8 +585,9 @@ bool CalcMidWidth( const std::vector& intersections, double& theMid, d void HYDROData_DTM::ProfileDiscretization( const Handle_HYDROData_Profile& theProfile, double theXCurv, double theMinZ, double theMaxZ, double theDDZ, CurveUZ& theMidPointCurve, - CurveUZ& theWidthCurve, - double theTolerance ) + CurveUZ& theWidthCurve, + int& intersection_nb, + double theTolerance) { double aDblMax = std::numeric_limits::max(), aUMin = aDblMax, @@ -629,7 +634,8 @@ void HYDROData_DTM::ProfileDiscretization( const Handle_HYDROData_Profile& thePr intersections.push_back( anIntersect.Point( k ) ); } - if( intersections.size() >= 2 ) + intersection_nb = intersections.size(); + if( intersection_nb >= 2 ) { double u_mid, u_wid; if( !CalcMidWidth( intersections, u_mid, u_wid ) ) @@ -722,7 +728,8 @@ std::vector HYDROData_DTM::Interpolate double theXCurvA, const Handle_HYDROData_Profile& theProfileB, double theXCurvB, - double theDDZ, int theNbSteps, bool isAddSecond ) + double theDDZ, int theNbSteps, bool isAddSecond, + int& inter_nb_1, int& inter_nb_2) { double zminA, zmaxA, zminB, zmaxB; gp_Pnt lowestA, lowestB; @@ -739,8 +746,8 @@ std::vector HYDROData_DTM::Interpolate CurveUZ midA(0, gp_Vec2d()), midB(0, gp_Vec2d()); CurveUZ widA(0, gp_Vec2d()), widB(0, gp_Vec2d()); - ProfileDiscretization( theProfileA, theXCurvA, zmin, zmax, theDDZ, midA, widA ); - ProfileDiscretization( theProfileB, theXCurvB, zmin, zmax, theDDZ, midB, widB ); + ProfileDiscretization( theProfileA, theXCurvA, zmin, zmax, theDDZ, midA, widA, inter_nb_1 ); + ProfileDiscretization( theProfileB, theXCurvB, zmin, zmax, theDDZ, midB, widB, inter_nb_2 ); std::vector mid, wid; Interpolate( midA, midB, theNbSteps, mid, isAddSecond ); @@ -765,7 +772,8 @@ HYDROData_Bathymetry::AltitudePoints HYDROData_DTM::Interpolate double theDDZ, double theSpatialStep, AltitudePoints& theLeft, AltitudePoints& theRight, - std::vector& theMainProfiles ) + std::vector& theMainProfiles, + std::set invalInd) { AltitudePoints points; size_t n = theProfiles.size(); @@ -786,10 +794,17 @@ HYDROData_Bathymetry::AltitudePoints HYDROData_DTM::Interpolate bool isAddSecond = i==n1-1; // 1. Calculate interpolated profiles + int inter_nb_1, inter_nb_2; std::vector local_points = Interpolate( aHydraulicAxis, theProfiles[i], distances[i], - theProfiles[i+1], distances[i+1], theDDZ, aNbSteps, isAddSecond ); + 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 +#include #include class Handle_HYDROData_Profile; @@ -123,6 +124,7 @@ protected: 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, @@ -139,13 +141,15 @@ protected: double theXCurvA, const Handle_HYDROData_Profile& theProfileB, double theXCurvB, - double theDDZ, int theNbSteps, bool isAddSecond ); + double theDDZ, int theNbSteps, bool isAddSecond, + int& inter_nb_1, int& inter_nb_2 ); static AltitudePoints Interpolate( const std::vector& theProfiles, double theDDZ, double theSpatialStep, AltitudePoints& theLeft, AltitudePoints& theRight, - std::vector& theMainProfiles ); + std::vector& theMainProfiles, + std::set invalInd ); static void PointToWire(const AltitudePoints& pnts, TopoDS_Wire& W ); @@ -169,7 +173,8 @@ protected: TopoDS_Shape& OutInlet, TopoDS_Shape& OutOutlet, bool Create3dPres, - bool Create2dPres ); + bool Create2dPres, + std::set InvInd ); static void Get2dFaceFrom3dPres(const TopoDS_Compound& cmp, TopoDS_Face& outF ); @@ -192,7 +197,8 @@ public: TopoDS_Shape& OutInlet, TopoDS_Shape& OutOutlet, bool Create3dPres, - bool Create2dPres ); + bool Create2dPres, + std::set InvInd ); }; diff --git a/src/HYDROData/HYDROData_Stream.cxx b/src/HYDROData/HYDROData_Stream.cxx index 6fbe09f4..d4a04ef4 100644 --- a/src/HYDROData/HYDROData_Stream.cxx +++ b/src/HYDROData/HYDROData_Stream.cxx @@ -167,7 +167,8 @@ Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve( void HYDROData_Stream::Update() { - updateProfilesOrder(); + if (!GetHydraulicAxis().IsNull()) + updateProfilesOrder(); // Update bottom polyline if exists const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline(); @@ -513,13 +514,12 @@ bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile ) if ( theProfile.IsNull() ) return false; - Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis(); - if ( aHydAxis.IsNull() ) - return false; + // Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis(); + // if ( aHydAxis.IsNull() ) + // return false; TopoDS_Face aPlane; - if(!BuildFace(aHydAxis, aPlane)) - return false; + BuildRefFace( aPlane ); Standard_Real aPar(.0); if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) ) @@ -640,13 +640,13 @@ void HYDROData_Stream::RemoveProfiles() void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile, const int theBeforeIndex ) { - Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis(); - if ( theProfile.IsNull() || aHydAxis.IsNull() ) + //Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis(); + if ( theProfile.IsNull() ) return; - TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() ); + //TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() ); TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() ); - if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() ) + if ( aProfileWire.IsNull() ) return; if ( theBeforeIndex == -1 ) @@ -655,25 +655,9 @@ void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex ); } -bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis, - TopoDS_Face& thePlane ) +void HYDROData_Stream::BuildRefFace( TopoDS_Face& thePlane ) { - //if ( !IsValidAsAxis( theHydAxis ) ) - // return false; - - //TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); - // - //gp_Ax2 aX2(gp::XOY()); - //gp_Ax3 aX3(aX2); - //gp_Pln aPln(aX3); - //Bnd_Box B; - //BRepBndLib::Add(aHydraulicWire,B); - //Standard_Real axmin,aymin,azmin,axmax,aymax,azmax; - //B.Get(axmin,aymin,azmin,axmax,aymax,azmax); - //BRepBuilderAPI_MakeFace aMkr(aPln, axmin-500., axmax+500., aymin-500., aymax+500.); // to be tuned later according max/ Profile deviation - //if(!aMkr.IsDone() || aMkr.Shape().IsNull()) return false; thePlane = BRepBuilderAPI_MakeFace(gp_Pln(gp_Pnt(0,0,0),gp_Dir(0,0,1))).Face(); - return true; } void HYDROData_Stream::updateProfilesOrder() @@ -690,8 +674,7 @@ void HYDROData_Stream::updateProfilesOrder() return; TopoDS_Face aPlane; - if ( !BuildFace( aHydAxis, aPlane ) ) - return; + BuildRefFace( aPlane ); Standard_Real aPar( .0 ); diff --git a/src/HYDROData/HYDROData_Stream.h b/src/HYDROData/HYDROData_Stream.h index 36a1a248..0eb6cde9 100644 --- a/src/HYDROData/HYDROData_Stream.h +++ b/src/HYDROData/HYDROData_Stream.h @@ -208,8 +208,7 @@ public: /** * Builds a planar face */ - HYDRODATA_EXPORT static bool BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis, - TopoDS_Face& thePlane ); + HYDRODATA_EXPORT static void BuildRefFace( TopoDS_Face& thePlane ); /** * Add new one reference profile object for stream. diff --git a/src/HYDROGUI/HYDROGUI_StreamDlg.cxx b/src/HYDROGUI/HYDROGUI_StreamDlg.cxx index a1cc548f..9693fd7f 100644 --- a/src/HYDROGUI/HYDROGUI_StreamDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_StreamDlg.cxx @@ -97,9 +97,7 @@ HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QStrin aParamLayout->addLayout( aParam1Layout ); aParamLayout->addWidget( myProfiles ); aParamLayout->addLayout( aButtonsLayout ); - - - + aParamGroup->setLayout( aParamLayout ); // Common @@ -203,6 +201,7 @@ void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles ) myProfiles->setObjects( aProfiles ); + myRemoveButton->setEnabled( myProfiles->getObjects().count() > 0 ); myProfiles->setUpdatesEnabled( true ); diff --git a/src/HYDROGUI/HYDROGUI_StreamOp.cxx b/src/HYDROGUI/HYDROGUI_StreamOp.cxx index 467d1285..2a1b43c9 100755 --- a/src/HYDROGUI/HYDROGUI_StreamOp.cxx +++ b/src/HYDROGUI/HYDROGUI_StreamOp.cxx @@ -121,25 +121,25 @@ void HYDROGUI_StreamOp::startOperation() myHydAxis = aHydraulicAxis->GetName(); TopoDS_Face aPlane; - if ( HYDROData_Stream::BuildFace( aHydraulicAxis, aPlane ) ) + HYDROData_Stream::BuildRefFace( aPlane ) ; + + // Stream profiles + HYDROData_SequenceOfObjects aStreamProfiles = myEditedObject->GetProfiles(); + for ( int i = 1, n = aStreamProfiles.Length(); i <= n; ++i ) { - // Stream profiles - HYDROData_SequenceOfObjects aStreamProfiles = myEditedObject->GetProfiles(); - for ( int i = 1, n = aStreamProfiles.Length(); i <= n; ++i ) - { - Handle(HYDROData_Profile) aProfile = - Handle(HYDROData_Profile)::DownCast( aStreamProfiles.Value( i ) ); - if ( aProfile.IsNull() ) - continue; - - QString aProfileName = aProfile->GetName(); - - Standard_Real aProfilePar = 0.0; - HYDROData_Stream::HasIntersection( aHydraulicAxis, aProfile, aPlane, aProfilePar ); - - myProfiles << aProfileName; - myProfileParams << aProfilePar; - } + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aStreamProfiles.Value( i ) ); + if ( aProfile.IsNull() ) + continue; + + QString aProfileName = aProfile->GetName(); + + Standard_Real aProfilePar = 0.0; + HYDROData_Stream::HasIntersection( aHydraulicAxis, aProfile, aPlane, aProfilePar ); + + myProfiles << aProfileName; + myProfileParams << aProfilePar; + } } } @@ -248,10 +248,16 @@ bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags, return false; } - // Set the object name + bool ToOrder = true; + + if (aHydAxis.IsNull()) + ToOrder = false; + + myEditedObject->SetProfiles (aRefProfiles, ToOrder) ; myEditedObject->SetName( anObjectName ); - myEditedObject->SetHydraulicAxis( aHydAxis ); + if (!aHydAxis.IsNull()) + myEditedObject->SetHydraulicAxis( aHydAxis ); myEditedObject->SetProfiles( aRefProfiles, false ); myEditedObject->SetDDZ( aPanel->getDDZ() ); myEditedObject->SetSpatialStep( aPanel->getSpatialStep() ); @@ -347,9 +353,13 @@ void HYDROGUI_StreamOp::createPreview() HYDROGUI_StreamDlg* aPanel = ::qobject_cast( inputPanel() ); double ddz = aPanel->getDDZ(); double ss = aPanel->getSpatialStep(); + + std::set InvInd; HYDROData_DTM::CreateProfilesFromDTM( aRefProfiles, ddz, ss, HYDROData_Bathymetry::AltitudePoints(), Out3dPres, Out2dPres, OutLeftB, OutRightB, - OutInlet, OutOutlet, true, true); + OutInlet, OutOutlet, true, true, InvInd); + + //TODO!! aPanel->my---; aPrsDef.myInlet = TopoDS::Wire(OutInlet); aPrsDef.myOutlet = TopoDS::Wire(OutOutlet); @@ -378,9 +388,7 @@ void HYDROGUI_StreamOp::onAddProfiles() // return; TopoDS_Face aPlane; - - if ( !HYDROData_Stream::BuildFace( aHydAxis, aPlane ) ) - return; + HYDROData_Stream::BuildRefFace( aPlane ); // Get the current profiles list QStringList aCurrentProfiles = myProfiles; @@ -515,15 +523,15 @@ void HYDROGUI_StreamOp::onAxisChanged( const QString& theNewAxis ) // Prepare data for intersection check TopoDS_Face aPlane; - if ( !HYDROData_Stream::BuildFace( aNewAxis, aPlane ) ) - { - SUIT_MessageBox::critical( module()->getApp()->desktop(), - tr( "BAD_SELECTED_POLYLINE_TLT" ), - tr( "BAD_SELECTED_POLYLINE_MSG" ).arg( theNewAxis ) ); - // To restore the old axis - updatePanelData(); - return; - } + HYDROData_Stream::BuildRefFace( aPlane ); + //{ + // SUIT_MessageBox::critical( module()->getApp()->desktop(), + // tr( "BAD_SELECTED_POLYLINE_TLT" ), + // tr( "BAD_SELECTED_POLYLINE_MSG" ).arg( theNewAxis ) ); + // // To restore the old axis + // updatePanelData(); + // return; + //} QStringList aNewProfiles; QList aNewProfileParams; diff --git a/src/HYDRO_tests/test_HYDROData_DTM.cxx b/src/HYDRO_tests/test_HYDROData_DTM.cxx index fa55f1db..4b265dca 100644 --- a/src/HYDRO_tests/test_HYDROData_DTM.cxx +++ b/src/HYDRO_tests/test_HYDROData_DTM.cxx @@ -339,7 +339,8 @@ void test_HYDROData_DTM::test_profile_discretization_polyline() aProfile->SetRightPoint( gp_XY( 20, 20 ) ); HYDROData_DTM::CurveUZ aMid( 0.0 ), aWid( 0.0 ); - HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 0.5, aMid, aWid ); + 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 ); @@ -376,7 +377,8 @@ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); aProfile->SetRightPoint( gp_XY( 20, 20 ) ); HYDROData_DTM::CurveUZ aMid( 0.0 ), aWid( 0.0 ); - HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 0.5, aMid, aWid ); + 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 );