]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
getting nb of intersections (non-gui) + add of profiles of stream to tree
authorisn <isn@opencascade.com>
Wed, 12 Oct 2016 09:03:56 +0000 (12:03 +0300)
committerisn <isn@opencascade.com>
Wed, 12 Oct 2016 09:04:37 +0000 (12:04 +0300)
src/HYDROData/HYDROData_DTM.cxx
src/HYDROData/HYDROData_DTM.h
src/HYDROData/HYDROData_Stream.cxx
src/HYDROData/HYDROData_Stream.h
src/HYDROGUI/HYDROGUI_StreamDlg.cxx
src/HYDROGUI/HYDROGUI_StreamOp.cxx
src/HYDRO_tests/test_HYDROData_DTM.cxx

index f44f98a22ec0f82a7cf755625a6d7459b3a82085..8311b147137017d32704d7306e3ba9d779d29973 100644 (file)
@@ -47,6 +47,8 @@
 #include <BRepLib_MakeWire.hxx>
 #include <BRep_Builder.hxx>
 
+
+
 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<int>() );
   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<int> 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<Handle_HYDROData_Profile>&
                                    TopoDS_Shape& OutInlet,
                                    TopoDS_Shape& OutOutlet,
                                    bool Create3dPres,
-                                   bool Create2dPres)
+                                   bool Create2dPres,
+                                   std::set<int> 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<gp_Pnt2d>& 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<double>::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_Bathymetry::AltitudePoints> 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_Bathymetry::AltitudePoints> 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<CurveUZ> 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<AltitudePoints>& theMainProfiles )
+    std::vector<AltitudePoints>& theMainProfiles,
+    std::set<int> 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<AltitudePoints> 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<lps; j++ )
     {
index fec5fe05e3855d5b418ba49a780b146fb98ed4c7..0dc1a89191f7627b285e4272a43f9278a84de0f4 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "HYDROData_Bathymetry.h"
 #include <vector>
+#include <set>
 #include <gp_Pnt2d.hxx>
 
 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<Handle_HYDROData_Profile>& theProfiles,
                                      double theDDZ, double theSpatialStep,
                                      AltitudePoints& theLeft,
                                      AltitudePoints& theRight,
-                                     std::vector<AltitudePoints>& theMainProfiles );
+                                     std::vector<AltitudePoints>& theMainProfiles,
+                                     std::set<int> 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<int> 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<int> InvInd );
 };
 
 
index 6fbe09f427b49dfd6f0b40f0ff61d6affdb08254..d4a04ef4b5ed4140aea4d6b99b1fc8a72ce6feb2 100644 (file)
@@ -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 );
 
index 36a1a248082b6272471ca7e4c24fadb8f91bb559..0eb6cde9e060ca71c0a8e726ead3ca2706592410 100644 (file)
@@ -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.
index a1cc548fb6ded0853b6d350d6eed1469bedeee3d..9693fd7fce569433979ccd759bb13af67aa045b1 100644 (file)
@@ -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 );
index 467d128568a534524d22e0aa2d4c1e0e0af44b2b..2a1b43c936b4f18935e15d0cb75ce7e9dd71f929 100755 (executable)
@@ -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<HYDROGUI_StreamDlg*>( inputPanel() );
   double ddz = aPanel->getDDZ();
   double ss = aPanel->getSpatialStep();
+
+  std::set<int> 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<double> aNewProfileParams;
index fa55f1db939c66f81d9e57aad9f99c2a24c3e683..4b265dca71a7ed3476df26ccf9235b63423b9285 100644 (file)
@@ -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 );