]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
rnc: Import Picture and Feature Detection dialogs small modifications
authorgdd <gdd>
Wed, 23 Nov 2011 14:46:02 +0000 (14:46 +0000)
committergdd <gdd>
Wed, 23 Nov 2011 14:46:02 +0000 (14:46 +0000)
src/EntityGUI/EntityGUI.cxx
src/EntityGUI/EntityGUI.h
src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx
src/EntityGUI/EntityGUI_FeatureDetectorDlg.h
src/EntityGUI/EntityGUI_PictureImportDlg.cxx

index fe21d26574f9f4f59e6c7e368a98fd15c568595a..332de5de074ea63ea3635fba3331f370a243bfc2 100644 (file)
@@ -194,12 +194,12 @@ bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWi
 }
 
 //=================================================================================
-// function : 0nMouseMove()
+// function : 0nMouseRelease()
 // purpose  : [static] manage mouse events
 //=================================================================================
-bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
+bool EntityGUI::OnMouseRelease( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
 {
-//   MESSAGE("EntityGUI::OnMouseMove")
+  MESSAGE("EntityGUI::OnMouseRelease")
   QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
   if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 ) &&
        theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
@@ -209,8 +209,7 @@ bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWin
    
     gp_Pnt aPnt; 
       
-    if ( QApplication::mouseButtons() == Qt::LeftButton && 
-         aCornerDlg->acceptMouseEvent() )
+    if ( aCornerDlg->acceptMouseEvent() )
     {
 //       QPoint end = QPoint(pe->x(),pe->y());
       OCCViewer_ViewPort3d* vp =  ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
index d6a557ef63291bc437b88c8f5d487fbc34ab4de1..7c3cdf67f53f8b99a5a68ece161719fe778f3a25 100644 (file)
@@ -49,7 +49,8 @@ public :
 
   bool              OnGUIEvent( int, SUIT_Desktop* );
   bool              OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow );
-  bool              OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow );
+//   bool              OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow );
+  bool              OnMouseRelease( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow );
   
   static gp_Pnt     ConvertClickToPoint( int x, int y, Handle(V3d_View) aView );
 
index 2dc1adf3fe33c62bfd1e2b714ae4262d429cea4d..39e068263c877bffb4f31de3911f20f2e2792c54 100644 (file)
@@ -36,7 +36,6 @@
 #include <EntityGUI.h>
 #include <GEOMBase.h>
 #include <GEOM_Object.hxx>
-#include <ShapeRec_FeatureDetector.hxx>
 
 #include <SUIT_Desktop.h>
 #include <SUIT_ResourceMgr.h>
@@ -141,11 +140,23 @@ EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeom
   mySelButton->setIcon(image1);
   myLineEdit = new QLineEdit(mySelectionGroup);
   
-  mySnapshotLabel = new QLabel(mySelectionGroup);
-  mySelectGrpLayout->addWidget(myLineEdit,      0, 1);
-  mySelectGrpLayout->addWidget(mySelButton,     0, 0);
-  mySelectGrpLayout->addWidget(mySnapshotLabel, 1, 1);
-  mySelectGrpLayout->addWidget(myPushButton,    1, 0);
+  mySnapshotLabel          = new QLabel(mySelectionGroup);
+  QFrame* myImgSampleFrame = new QFrame(mySelectionGroup);
+//   myImgSampleFrame->setFrameRect(QRect(0,0,10,10));
+  myImgSampleFrame->setFrameStyle(QFrame::Box);
+  QLabel* myPictureLabel   = new QLabel(tr( "GEOM_PICTURE" ),mySelectionGroup);
+  mySelectGrpLayout->addWidget(myPictureLabel,   0, 0);
+  mySelectGrpLayout->addWidget(mySelButton,      0, 1);
+  mySelectGrpLayout->addWidget(myLineEdit,       0, 2);// 1, 2);
+  
+  mySelectGrpLayout->addWidget(mySnapshotLabel,  1, 0);
+  mySelectGrpLayout->addWidget(myPushButton,     1, 1);
+  mySelectGrpLayout->addWidget(myImgSampleFrame, 1, 2);
+//   mySelectGrpLayout->setColumnStretch(3, 1);
+  
+  QGridLayout* myFrameLayout = new QGridLayout(myImgSampleFrame);
+  myImgSampleLabel           = new QLabel(myImgSampleFrame);
+  myFrameLayout->addWidget(myImgSampleLabel,     0, 0);
   
   myOutputGroup = new DlgRef_3Radio(centralWidget());
   myOutputGroup->GroupBox1->setTitle(tr("GEOM_DETECT_OUTPUT"));
@@ -163,6 +174,9 @@ EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeom
   
 //   mainFrame()->GroupBoxName->hide();
   
+  // Build an instance of detection used to perform image processing operations
+  aDetector = new ShapeRec_FeatureDetector();
+  
   Init();
   
 }
@@ -246,6 +260,11 @@ void EntityGUI_FeatureDetectorDlg::SetEditCurrentArgument()
 //=================================================================================
 void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument()
 {
+  
+  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())
     return;
   
@@ -255,6 +274,7 @@ void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument()
   SALOME_ListIO aSelList;
   aSelMgr->selectedObjects(aSelList);
   SALOME_ListIteratorOfListIO anIt( aSelList );
+  
   for( ; anIt.More(); anIt.Next() )
     if( !anIt.Value().IsNull() )
     {
@@ -273,10 +293,29 @@ void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument()
   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
     QString aName = GEOMBase::GetName( aSelectedObject.get() );
     myEditCurrentArgument->setText( aName );
+    
     if ( myEditCurrentArgument == myLineEdit ) {
       myFace = aSelectedObject;
+      AISit = soccViewer->entry2aisobjects.find(myFaceEntry.toStdString());
+      if (AISit == soccViewer->entry2aisobjects.end())
+        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 ;
+
+      aDetector->SetPath( theImgFileName );   
     } 
   }
+  
 }
 
 //=================================================================================
@@ -417,8 +456,40 @@ void EntityGUI_FeatureDetectorDlg::setEndPnt(const gp_Pnt& theEndPnt)
 {
   myEndPnt = theEndPnt;
   MESSAGE("myEndPnt = ("<<theEndPnt.X()<<", "<<theEndPnt.Y()<<")")
+  showImageSample();
+}
+
+//=================================================================================
+// function : showImageSample()
+// purpose  :
+//=================================================================================
+void EntityGUI_FeatureDetectorDlg::showImageSample()
+{  
+  int height            =  aDetector->GetImgHeight();
+  int width             =  aDetector->GetImgWidth();
+  
+  // Operations to display the corners properly in the 3D scene
+  double pictureLeft  = -0.5 * width;   // X coordinate of the top left  corner of the background image in the view
+  double pictureTop   =  0.5 * height;  // Y coordinate of both top corners
+  
+  // Set detection rectangle in the background image coordinates system
+  QPoint topLeft     = QPoint(myStartPnt.X() - pictureLeft, pictureTop - myStartPnt.Y());
+  QPoint bottomRight = QPoint(myEndPnt.X()   - pictureLeft, pictureTop - myEndPnt.Y());
+  QRect aRect = QRect(topLeft, bottomRight);
+  
+  if( !aRect.isEmpty() && aRect.width() > 1 )
+  {
+    aDetector->SetROI( aRect );
+    std::string samplePicturePath = aDetector->CroppImage();
+    MESSAGE("samplePicturePath = "<<samplePicturePath)
+    QPixmap pixmap(QString(samplePicturePath.c_str()));
+    myImgSampleLabel->setPixmap(pixmap);
+    myImgSampleLabel->setMask(pixmap.mask());
+  }
 }
 
+
+
 //=================================================================================
 // function : createOperation
 // purpose  :
@@ -436,29 +507,28 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
 {
   bool res = false;
   
-  SUIT_ViewWindow*       theViewWindow  = getDesktop()->activeWindow();
-  std::map< std::string , std::vector<Handle(AIS_InteractiveObject)> >::iterator AISit;
-  SOCC_Viewer* soccViewer = (SOCC_Viewer*)(theViewWindow->getViewManager()->getViewModel());
-  
-  AISit = soccViewer->entry2aisobjects.find(myFaceEntry.toStdString());
-  if (AISit == soccViewer->entry2aisobjects.end())
-    return res;
-  
-  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 res;
-  
-  std::string theImgFileName = myAISShape->TextureFile();
-    
-  if ( theImgFileName == "" )
-    return res;
+//   SUIT_ViewWindow*       theViewWindow  = getDesktop()->activeWindow();
+//   std::map< std::string , std::vector<Handle(AIS_InteractiveObject)> >::iterator AISit;
+//   SOCC_Viewer* soccViewer = (SOCC_Viewer*)(theViewWindow->getViewManager()->getViewModel());
   
-  // Build an instance of detection used to perform image processing operations
-  ShapeRec_FeatureDetector* aDetector = new ShapeRec_FeatureDetector( theImgFileName );
+//   AISit = soccViewer->entry2aisobjects.find(myFaceEntry.toStdString());
+//   if (AISit == soccViewer->entry2aisobjects.end())
+//     return res;
+//   
+//   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 res;
+//   
+//   std::string theImgFileName = myAISShape->TextureFile();
+//     
+//   if ( theImgFileName == "" )
+//     return res;
+//   
+//   aDetector->SetPath( theImgFileName );
     
   int height            =  aDetector->GetImgHeight();
   int width             =  aDetector->GetImgWidth();
index 5d6e457ae9dda5876d306033eb3d5f0e38db0ada..78ef8e1594af1c5be5d63269bbcdcd37e35908f6 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <GEOMBase_Skeleton.h>
 #include <gp_Ax3.hxx>
+#include <ShapeRec_FeatureDetector.hxx>
+#include <QBitmap>
 
 class QLineEdit;
 class QCheckBox;
@@ -59,6 +61,7 @@ protected:
   
 private:
   void                               Init();
+  void                               showImageSample();
 
   
 private slots:
@@ -72,6 +75,8 @@ private slots:
   
   
 private:
+  ShapeRec_FeatureDetector*          aDetector;
+  
   GEOM::GeomObjPtr                   myFace;
   QString                            myFaceEntry;
   
@@ -80,6 +85,7 @@ private:
   QGroupBox*                         mySelectionGroup;
   
   QLabel*                            mySnapshotLabel;
+  QLabel*                            myImgSampleLabel;
   
   DlgRef_1Sel*                       mySelWidget;
   
index 12d10afa8199ebd2a68371af4e8053efa17dfc2c..d3e63c390e17b9300cfb309360632ccbacb0366b 100644 (file)
@@ -182,7 +182,8 @@ bool EntityGUI_PictureImportDlg::execute( ObjectList& objects )
   if ( theImgFileName.isEmpty() )
     return res;
   
-  ShapeRec_FeatureDetector* aDetector = new ShapeRec_FeatureDetector( theImgFileName.toStdString() );
+  ShapeRec_FeatureDetector* aDetector = new ShapeRec_FeatureDetector();
+  aDetector->SetPath( theImgFileName.toStdString() );
     
   int height            =  aDetector->GetImgHeight();
   int width             =  aDetector->GetImgWidth();