From 71d480a5504be340a6d5ef99702022872cd4572b Mon Sep 17 00:00:00 2001 From: gdd Date: Wed, 23 Nov 2011 14:46:02 +0000 Subject: [PATCH] rnc: Import Picture and Feature Detection dialogs small modifications --- src/EntityGUI/EntityGUI.cxx | 9 +- src/EntityGUI/EntityGUI.h | 3 +- .../EntityGUI_FeatureDetectorDlg.cxx | 126 ++++++++++++++---- src/EntityGUI/EntityGUI_FeatureDetectorDlg.h | 6 + src/EntityGUI/EntityGUI_PictureImportDlg.cxx | 3 +- 5 files changed, 112 insertions(+), 35 deletions(-) diff --git a/src/EntityGUI/EntityGUI.cxx b/src/EntityGUI/EntityGUI.cxx index fe21d2657..332de5de0 100644 --- a/src/EntityGUI/EntityGUI.cxx +++ b/src/EntityGUI/EntityGUI.cxx @@ -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(); diff --git a/src/EntityGUI/EntityGUI.h b/src/EntityGUI/EntityGUI.h index d6a557ef6..7c3cdf67f 100644 --- a/src/EntityGUI/EntityGUI.h +++ b/src/EntityGUI/EntityGUI.h @@ -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 ); diff --git a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx index 2dc1adf3f..39e068263 100644 --- a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx +++ b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx @@ -36,7 +36,6 @@ #include #include #include -#include #include #include @@ -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 >::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 = ("<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 = "<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 >::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 >::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(); diff --git a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.h b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.h index 5d6e457ae..78ef8e159 100644 --- a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.h +++ b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.h @@ -22,6 +22,8 @@ #include #include +#include +#include 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; diff --git a/src/EntityGUI/EntityGUI_PictureImportDlg.cxx b/src/EntityGUI/EntityGUI_PictureImportDlg.cxx index 12d10afa8..d3e63c390 100644 --- a/src/EntityGUI/EntityGUI_PictureImportDlg.cxx +++ b/src/EntityGUI/EntityGUI_PictureImportDlg.cxx @@ -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(); -- 2.39.2