]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx
Salome HOME
Merge V8_4_BR branch.
[modules/geom.git] / src / EntityGUI / EntityGUI_FeatureDetectorDlg.cxx
index cbb5645fded338fc123f0a8c7a71888c40028e25..b33b7a7d6613642816024a649c54503765870a0c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // 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.
+// 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
@@ -26,7 +26,8 @@
 
 // SALOME includes
 #include "EntityGUI_FeatureDetectorDlg.h"
-#include <ShapeRec_FeatureDetector.hxx>
+#include "ShapeRec_FeatureDetector.hxx"
+#include "GEOM_Constants.h"
 
 #include <OCCViewer_ViewWindow.h>
 #include <OCCViewer_ViewManager.h>
@@ -46,7 +47,7 @@
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
 
-#include <SALOME_ListIteratorOfListIO.hxx>
+#include <SALOME_ListIO.hxx>
 
 #include <SalomeApp_Study.h>
 
@@ -63,7 +64,8 @@
 #include <BRepBuilderAPI_MakePolygon.hxx>
 #include <BRepBuilderAPI_Transform.hxx>
 
-#include <AIS_TexturedShape.hxx>
+#include <AIS_Shape.hxx>
+
 #include <TCollection_AsciiString.hxx>
 #include <StdSelect_DisplayMode.hxx>
 
@@ -83,12 +85,6 @@ enum{
   LINES
 };
 
-enum {
-  RADIO_BUTTONS,
-  MSG,
-  PUSH_BUTTON,
-};
-
 enum {
   KERNEL_SIZE,
   FIND_CONTOURS_METHOD,
@@ -282,7 +278,16 @@ EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeom
   myWidgets.insert( HIST_TYPE, histType );
   QDoubleSpinBox* thresholdValue = new QDoubleSpinBox();
   thresholdValue->setRange( 0, 254 );
-  thresholdValue->setValue( 128 );
+  // 1 is a good default value for the threshold. It means that we are very permissive
+  // about what will be considered INSIDE the zone we want to find the frontier of
+  // This makes the algorithm more robust against a bit inhomogeneous parts in the zone
+  // that we want to delimitate.
+  // The drawback is if we want to delimitate a zone which color is very similar to the zone
+  // we consider as the OUTSIDE, the result will be bad.
+  // The current use cases are more of the first form : 
+  //  - Strongly contrasted INSIDE and OUTSIDE zones
+  //  - Small inhomogenities in each zone
+  thresholdValue->setValue( 1 );
   myWidgets.insert( THRESHOLD_VALUE, thresholdValue );
   QDoubleSpinBox* maxThreshold = new QDoubleSpinBox();
   maxThreshold->setRange( 1, 255 );
@@ -327,7 +332,7 @@ EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeom
 //   mainFrame()->GroupBoxName->hide();
   
   // Build an instance of detection used to perform image processing operations
-  aDetector = new ShapeRec_FeatureDetector();
+  myDetector = new ShapeRec_FeatureDetector();
   
   setHelpFileName( "shape_recognition_page.html" );
   
@@ -341,7 +346,7 @@ EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeom
 //=================================================================================
 EntityGUI_FeatureDetectorDlg::~EntityGUI_FeatureDetectorDlg()
 {
-  
+  delete myDetector;
 }
 
 //=================================================================================
@@ -396,7 +401,6 @@ void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument()
   
   // TODO supprimer les lignes qui ne servent à rien le cas échéant
   SUIT_ViewWindow*       theViewWindow  = getDesktop()->activeWindow();
-  std::map< std::string , std::vector<Handle(AIS_InteractiveObject)> >::iterator AISit;
   SOCC_Viewer* soccViewer = (SOCC_Viewer*)(theViewWindow->getViewManager()->getViewModel());
 
   if (!myEditCurrentArgument->isEnabled())
@@ -430,26 +434,22 @@ void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument()
     
     if ( myEditCurrentArgument == mySelectionGroup->LineEdit1 ) {
       myFace = aSelectedObject;
-      AISit = soccViewer->entry2aisobjects.find(myFaceEntry.toStdString());
-      if (AISit == soccViewer->entry2aisobjects.end())
+
+      SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+      if ( !study ) return;
+      LightApp_Application* app = ::qobject_cast<LightApp_Application*>( study->application() );
+      if ( !app ) return;
+      SUIT_ViewManager* vm = app->activeViewManager();
+      if ( !vm ) return;
+      PropMap propMap = study->getObjectProperties( vm->getGlobalId(), myFaceEntry );
+      QString theImgFileName = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
+      if ( theImgFileName.isEmpty() )
         return;
-      
-      Handle(AIS_InteractiveObject) myAIS = (*AISit).second[0];
-      Handle(GEOM_AISShape) myAISShape;
-      if( myAIS->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
-        myAISShape = Handle(GEOM_AISShape)::DownCast( myAIS );
-      }
-      else
-        return ;
-      
-      std::string theImgFileName = myAISShape->TextureFile();      
-      if ( theImgFileName == "" )
-        return ;
 
       // Setting the image caracteristics
-      aDetector->SetPath( theImgFileName );
-      height            =  aDetector->GetImgHeight();
-      width             =  aDetector->GetImgWidth();
+      myDetector->SetPath( theImgFileName.toStdString() );
+      height            =  myDetector->GetImgHeight();
+      width             =  myDetector->GetImgWidth();
       pictureLeft       = -0.5 * width;              // X coordinate of the top left  corner of the background image in the view
       pictureTop        =  0.5 * height;             // Y coordinate of both top corners
       
@@ -674,7 +674,7 @@ void EntityGUI_FeatureDetectorDlg::setEndPnt(const gp_Pnt& theEndPnt)
 {
   myEndPnt = theEndPnt;
   MESSAGE("myEndPnt = ("<<theEndPnt.X()<<", "<<theEndPnt.Y()<<")")
-  if (setSelectionRect() && aDetector->GetImgHeight() > 0)
+  if (setSelectionRect() && myDetector->GetImgHeight() > 0)
     showImageSample();
 }
 
@@ -705,8 +705,8 @@ bool EntityGUI_FeatureDetectorDlg::setSelectionRect()
 void EntityGUI_FeatureDetectorDlg::showImageSample()
 { 
   // Cropp the image to the selection rectangle given by the user
-  aDetector->SetROI( myRect ); 
-  std::string samplePicturePath = aDetector->CroppImage();
+  myDetector->SetROI( myRect ); 
+  std::string samplePicturePath = myDetector->CroppImage();
   
   // Display the result
   QPixmap pixmap(QString(samplePicturePath.c_str()));
@@ -753,9 +753,9 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
        subPictureLeft    = pictureLeft;
        subPictureTop     = pictureTop;
       }
-      aDetector->ComputeCorners( useROI, parameters );
-      CvPoint2D32f* corners     = aDetector->GetCorners();
-      int cornerCount           = aDetector->GetCornerCount();
+      myDetector->ComputeCorners( useROI, parameters );
+      CvPoint2D32f* corners     = myDetector->GetCorners();
+      int cornerCount           = myDetector->GetCornerCount();
       int i;
     
       // Build the geom objects associated to the detected corners and returned by execute   
@@ -794,9 +794,9 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
     {    
       GEOM::GEOM_ICurvesOperations_var aCurveOperations = myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
 
-      aDetector->ComputeContours( useROI, parameters );
-      std::vector< std::vector<cv::Point> >   contours  = aDetector->GetContours();
-      std::vector<cv::Vec4i>                  hierarchy = aDetector->GetContoursHierarchy();
+      myDetector->ComputeContours( useROI, parameters );
+      std::vector< std::vector<cv::Point> >   contours  = myDetector->GetContours();
+      std::vector<cv::Vec4i>                  hierarchy = myDetector->GetContoursHierarchy();
     
       std::vector< cv::Point >                contour;
       int idx = 0;
@@ -850,11 +850,11 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
                 double u_v_det = (it->x - it_previous->x) * (it_next->y - it->y) - 
                                  (it->y - it_previous->y) * (it_next->x - it->x);
                                           
-                double norme_u = sqrt ( (it->x - it_previous->x)*(it->x - it_previous->x) +
-                                        (it->y - it_previous->y)*(it->y - it_previous->y) );
+                double norme_u = sqrt ( double(it->x - it_previous->x) * double(it->x - it_previous->x) +
+                                        double(it->y - it_previous->y) * double(it->y - it_previous->y) );
                 
-                double norme_v = sqrt ( (it->x - it_next->x)*(it->x - it_next->x) +
-                                        (it->y - it_next->y)*(it->y - it_next->y) );
+                double norme_v = sqrt ( double(it->x - it_next->x) * double(it->x - it_next->x) +
+                                        double(it->y - it_next->y) * double(it->y - it_next->y) );
                                                                                                 
                 double u_v_sinus = u_v_det / (norme_u * norme_v);
                 
@@ -914,8 +914,8 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
   
 //   else if(myConstructorId ==LINES)
 //   {
-//     aDetector->ComputeLines();
-//     std::vector<cv::Vec4i>  lines = aDetector->GetLines();
+//     myDetector->ComputeLines();
+//     std::vector<cv::Vec4i>  lines = myDetector->GetLines();
 //     GEOM::GEOM_Object_var  Pnt1;
 //     GEOM::GEOM_Object_var  Pnt2;
 //     GEOM::GEOM_Object_var  aLine;
@@ -945,3 +945,14 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
   
   return res;
 }
+
+//=================================================================================
+// function : getSourceObjects
+// purpose  : virtual method to get source objects
+//=================================================================================
+QList<GEOM::GeomObjPtr> EntityGUI_FeatureDetectorDlg::getSourceObjects()
+{
+  QList<GEOM::GeomObjPtr> res;
+  res << myFace;
+  return res;
+}