From dfc97bd8a75f6b3d5c10e95ece75db5921019250 Mon Sep 17 00:00:00 2001 From: gdd Date: Wed, 9 Nov 2011 17:13:18 +0000 Subject: [PATCH] rnc: some code refactoring --- src/EntityGUI/EntityGUI.cxx | 25 ++-- .../EntityGUI_FeatureDetectorDlg.cxx | 120 +++--------------- src/EntityGUI/EntityGUI_FeatureDetectorDlg.h | 8 +- src/EntityGUI/EntityGUI_PictureImportDlg.cxx | 2 +- .../ShapeRec_FeatureDetector.cxx | 4 +- .../ShapeRec_FeatureDetector.hxx | 3 +- 6 files changed, 40 insertions(+), 122 deletions(-) diff --git a/src/EntityGUI/EntityGUI.cxx b/src/EntityGUI/EntityGUI.cxx index 02985b328..fe21d2657 100644 --- a/src/EntityGUI/EntityGUI.cxx +++ b/src/EntityGUI/EntityGUI.cxx @@ -171,20 +171,21 @@ bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWi ic->Select(); // New selection ic->InitSelected(); - if ( ic->MoreSelected() ) { - TopoDS_Shape aShape = ic->SelectedShape(); - if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) + TopoDS_Shape aShape; + if ( ic->MoreSelected() ) + aShape = ic->SelectedShape(); + if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) ); - } - else { + else + { OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); } // aCornerDlg->OnPointSelected( aPnt ); // "feed" the point to corner detection dialog - QPoint start = QPoint(pe->x(),pe->y()); - aCornerDlg->setStartPnt( start ); +// QPoint start = QPoint(pe->x(),pe->y()); + aCornerDlg->setStartPnt( aPnt ); } // acceptMouseEvent() } @@ -202,8 +203,8 @@ bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWin QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox(); if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 ) && theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() && - pe->modifiers() != Qt::ControlModifier ) { - + pe->modifiers() != Qt::ControlModifier ) + { EntityGUI_FeatureDetectorDlg* aCornerDlg = (EntityGUI_FeatureDetectorDlg*) aDlg; gp_Pnt aPnt; @@ -211,8 +212,10 @@ bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWin if ( QApplication::mouseButtons() == Qt::LeftButton && aCornerDlg->acceptMouseEvent() ) { - QPoint end = QPoint(pe->x(),pe->y()); - aCornerDlg->setEndPnt( end ); +// QPoint end = QPoint(pe->x(),pe->y()); + OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); + aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); + aCornerDlg->setEndPnt( aPnt ); } } return false; diff --git a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx index 9949400db..d9b8a9533 100644 --- a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx +++ b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx @@ -26,7 +26,6 @@ #include "EntityGUI_FeatureDetectorDlg.h" -#include #include #include @@ -216,7 +215,7 @@ void EntityGUI_FeatureDetectorDlg::Init() aGlobalCS = gp_Ax3(aOrigin, aDirZ, aDirX); - myStartPnt = QPoint(0,0); + myStartPnt = gp_Pnt(0,0,0); myEndPnt = myStartPnt; myGeomGUI->SetWorkingPlane( aGlobalCS ); @@ -278,47 +277,8 @@ void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument() myFace = aSelectedObject; } } - } - -// //================================================================================= -// // function : OnPointSelected -// // purpose : -// //================================================================================= -// void EntityGUI_FeatureDetectorDlg::OnPointSelected(const gp_Pnt& thePnt) -// { -// SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); -// int aPrecision = resMgr->integerValue("Geometry", "length_precision", 6); -// if (myPushButton1->isDown()) -// { -// // myX->setValue(thePnt.X()); -// // myY->setValue(thePnt.Y()); -// // myZ->setValue(thePnt.Z()); -// myX->setText(DlgRef::PrintDoubleValue(thePnt.X(), aPrecision)); -// myY->setText(DlgRef::PrintDoubleValue(thePnt.Y(), aPrecision)); -// myZ->setText(DlgRef::PrintDoubleValue(thePnt.Z(), aPrecision)); -// x1 = thePnt.X(); -// y1 = thePnt.Y(); -// z1 = thePnt.Z(); -// -// myPushButton2->click(); -// } -// else -// { -// // myX2->setValue(thePnt.X()); -// // myY2->setValue(thePnt.Y()); -// // myZ2->setValue(thePnt.Z()); -// myX2->setText(DlgRef::PrintDoubleValue(thePnt.X(), aPrecision)); -// myY2->setText(DlgRef::PrintDoubleValue(thePnt.Y(), aPrecision)); -// myZ2->setText(DlgRef::PrintDoubleValue(thePnt.Z(), aPrecision)); -// x2 = thePnt.X(); -// y2 = thePnt.Y(); -// z2 = thePnt.Z(); -// -// } -// } - //================================================================================= // function : acceptMouseEvent() // purpose : @@ -429,7 +389,7 @@ void EntityGUI_FeatureDetectorDlg::onButtonToggled( bool checked) { if (!checked) { - myStartPnt = QPoint(0,0); + myStartPnt = gp_Pnt(0,0,0); myEndPnt = myStartPnt; myLineEdit->setEnabled(true); } @@ -443,18 +403,20 @@ void EntityGUI_FeatureDetectorDlg::onButtonToggled( bool checked) // function : setStartPnt( const QPoint& ) // purpose : //================================================================================= -void EntityGUI_FeatureDetectorDlg::setStartPnt(const QPoint& theStartPnt) +void EntityGUI_FeatureDetectorDlg::setStartPnt(const gp_Pnt& theStartPnt) { myStartPnt = theStartPnt; + MESSAGE("myStartPnt = ("<activeWindow(); - OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); MESSAGE("myFaceEntry = "<< myFaceEntry.toStdString()); std::map< std::string , std::vector >::iterator AISit; @@ -495,10 +456,9 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects ) else return res; - QString theImgFileName = QString::fromStdString( myAISShape->TextureFile() ); - - - if ( theImgFileName.isEmpty() ) + std::string theImgFileName = myAISShape->TextureFile(); + + if ( theImgFileName == "" ) return res; // Build an instance of detection used to perform image processing operations @@ -507,43 +467,14 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects ) int height = aDetector->GetImgHeight(); int width = aDetector->GetImgWidth(); -// NOTE: OLD - int winHeight = vp->height(); - int winWidth = vp->width(); - double x_offset, y_offset; - - // Recompute of the values computed in OCC OpenGl_view.c - // while waiting for a function to retrieve parameters of the displayed backgroun image - double hratio = winHeight * 1.0 / height; - double wratio = winWidth * 1.0 / width ; - double imgZoomRatio = 1.0; - - if (hratio < wratio){ - x_offset = 0.5 * width * hratio; - y_offset = 0.5 * winHeight; - imgZoomRatio = hratio; - } - else { - y_offset = 0.5 * height * wratio; - x_offset = 0.5 * winWidth; - imgZoomRatio = wratio; - } - -// // Selection rectangle coordinates in the view -// double rectLeft = myStartPnt.x(); -// double rectTop = myStartPnt.y(); - // Operations to display the corners properly in the 3D scene - double viewLeft = -0.5 * width; // X coordinate of the top left corner of the background image in the view - double viewTop = 0.5 * height; // Y coordinate of both top corners + 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 - myStartPnt.setX( (myStartPnt.x() - (0.5 * winWidth - x_offset)) * 1.0 / imgZoomRatio ); - myStartPnt.setY( (myStartPnt.y() - (0.5 * winHeight - y_offset)) * 1.0 / imgZoomRatio ); - myEndPnt.setX( (myEndPnt.x() - (0.5 * winWidth - x_offset)) * 1.0 / imgZoomRatio ); - myEndPnt.setY( (myEndPnt.y() - (0.5 * winHeight - y_offset)) * 1.0 / imgZoomRatio ); - - QRect aRect = QRect(myStartPnt, myEndPnt); + QPoint topLeft = QPoint(myStartPnt.X() - pictureLeft, pictureTop - myStartPnt.Y()); + QPoint bottomRight = QPoint(myEndPnt.X() - pictureLeft, pictureTop - myEndPnt.Y()); + QRect aRect = QRect(topLeft, bottomRight); GEOM::GEOM_IBasicOperations_var aBasicOperations = myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() ); @@ -553,8 +484,8 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects ) if( !aRect.isEmpty() ) { aDetector->SetROI( aRect ); -// viewLeft = rectLeft; -// viewTop = rectTop; + pictureLeft = myStartPnt.X(); + pictureTop = myStartPnt.Y(); } aDetector->ComputeCorners(); CvPoint2D32f* corners = aDetector->GetCorners(); @@ -569,16 +500,8 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects ) geomCorners->length( cornerCount ); for (i = 0; i < cornerCount; i++) { -// gp_Pnt aCornerPnt = EntityGUI::ConvertClickToPoint( viewLeft + corners[i].x*imgZoomRatio, -// viewTop + corners[i].y*imgZoomRatio, vp->getView() ); -// -// double x = aCornerPnt.X(); -// double y = aCornerPnt.Y(); -// double z = aCornerPnt.Z(); - - // When using the new way with textures on shapes we just have to do the following - double x = viewLeft + corners[i].x; - double y = viewTop - corners[i].y; + double x = pictureLeft + corners[i].x; + double y = pictureTop - corners[i].y; double z = 0; aGeomCorner = aBasicOperations->MakePointXYZ( x,y,z ); @@ -611,7 +534,6 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects ) } GEOM::GEOM_ICurvesOperations_var aCurveOperations = myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() ); -// GEOM::GEOM_ICurvesOperations::_narrow( getOperation() ); aDetector->ComputeContours( method ); std::vector< std::vector > contours = aDetector->GetContours(); @@ -645,12 +567,6 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects ) std::pair< std::set< std::vector >::iterator,bool > pnt_it; for ( it=contour.begin() ; it < contour.end(); it++ ) { - // gp_Pnt aContourPnt = EntityGUI::ConvertClickToPoint(viewLeft + it->x*imgZoomRatio, viewTop + it->y*imgZoomRatio, vp->getView()); - // double x = aContourPnt.X(); - // double y = aContourPnt.Y(); - // double z = aContourPnt.Z(); - - // When using the new way with textures on shapes we just have to do the following int pnt_array[] = {it->x,it->y}; std::vector pnt (pnt_array, pnt_array + sizeof(pnt_array) / sizeof(int) ); diff --git a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.h b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.h index f3d815145..5d6e457ae 100644 --- a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.h +++ b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.h @@ -48,8 +48,8 @@ public: bool acceptMouseEvent() const; // void OnPointSelected( const gp_Pnt& ); - void setStartPnt ( const QPoint& ); - void setEndPnt ( const QPoint& ); + void setStartPnt ( const gp_Pnt& ); + void setEndPnt ( const gp_Pnt& ); int getConstructorId() {return myConstructorId;}; protected: @@ -83,8 +83,8 @@ private: DlgRef_1Sel* mySelWidget; - QPoint myStartPnt; - QPoint myEndPnt; + gp_Pnt myStartPnt; + gp_Pnt myEndPnt; gp_Ax3 myWPlane; gp_Ax3 aGlobalCS; diff --git a/src/EntityGUI/EntityGUI_PictureImportDlg.cxx b/src/EntityGUI/EntityGUI_PictureImportDlg.cxx index dbd02bd5b..12d10afa8 100644 --- a/src/EntityGUI/EntityGUI_PictureImportDlg.cxx +++ b/src/EntityGUI/EntityGUI_PictureImportDlg.cxx @@ -182,7 +182,7 @@ bool EntityGUI_PictureImportDlg::execute( ObjectList& objects ) if ( theImgFileName.isEmpty() ) return res; - ShapeRec_FeatureDetector* aDetector = new ShapeRec_FeatureDetector( theImgFileName ); + ShapeRec_FeatureDetector* aDetector = new ShapeRec_FeatureDetector( theImgFileName.toStdString() ); int height = aDetector->GetImgHeight(); int width = aDetector->GetImgWidth(); diff --git a/src/ShapeRecognition/ShapeRec_FeatureDetector.cxx b/src/ShapeRecognition/ShapeRec_FeatureDetector.cxx index ca6caa10d..532cba0c3 100644 --- a/src/ShapeRecognition/ShapeRec_FeatureDetector.cxx +++ b/src/ShapeRecognition/ShapeRec_FeatureDetector.cxx @@ -38,12 +38,12 @@ using namespace cv; Constructor \param theFilename - image to process */ -ShapeRec_FeatureDetector::ShapeRec_FeatureDetector(const QString& theFilename): +ShapeRec_FeatureDetector::ShapeRec_FeatureDetector(const std::string& theFilename): corners() { cornerCount = 2000; rect=cvRect(0,0,0,0); - imagePath = theFilename.toStdString(); + imagePath = theFilename; // Store the dimensions of the picture IplImage* bg_img = cvLoadImage (imagePath.c_str(), CV_LOAD_IMAGE_GRAYSCALE); imgHeight = bg_img->height; diff --git a/src/ShapeRecognition/ShapeRec_FeatureDetector.hxx b/src/ShapeRecognition/ShapeRec_FeatureDetector.hxx index bbe37d91c..a56afcbe4 100644 --- a/src/ShapeRecognition/ShapeRec_FeatureDetector.hxx +++ b/src/ShapeRecognition/ShapeRec_FeatureDetector.hxx @@ -29,7 +29,6 @@ #include "opencv2/highgui/highgui.hpp" // Qt -#include #include enum // Method used for contour detection @@ -46,7 +45,7 @@ public: typedef std::vector CvContour; typedef std::vector > CvContoursArray; - ShapeRec_FeatureDetector( const QString& ); // Constructor + ShapeRec_FeatureDetector( const std::string& ); // Constructor void ComputeCorners(); // Detects the corners from the image located at imagePath bool ComputeLines(); // Detects the lines from the image located at imagePath -- 2.39.2