rnc: some code refactoring

This commit is contained in:
gdd 2011-11-09 17:13:18 +00:00
parent 98e380060a
commit dfc97bd8a7
6 changed files with 40 additions and 122 deletions

View File

@ -171,20 +171,21 @@ bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWi
ic->Select(); // New selection ic->Select(); // New selection
ic->InitSelected(); ic->InitSelected();
if ( ic->MoreSelected() ) { TopoDS_Shape aShape;
TopoDS_Shape aShape = ic->SelectedShape(); if ( ic->MoreSelected() )
if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) aShape = ic->SelectedShape();
if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) ); aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
} else
else { {
OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
} }
// aCornerDlg->OnPointSelected( aPnt ); // "feed" the point to corner detection dialog // aCornerDlg->OnPointSelected( aPnt ); // "feed" the point to corner detection dialog
QPoint start = QPoint(pe->x(),pe->y()); // QPoint start = QPoint(pe->x(),pe->y());
aCornerDlg->setStartPnt( start ); aCornerDlg->setStartPnt( aPnt );
} // acceptMouseEvent() } // acceptMouseEvent()
} }
@ -202,8 +203,8 @@ bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWin
QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox(); QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 ) && if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 ) &&
theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() && theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
pe->modifiers() != Qt::ControlModifier ) { pe->modifiers() != Qt::ControlModifier )
{
EntityGUI_FeatureDetectorDlg* aCornerDlg = (EntityGUI_FeatureDetectorDlg*) aDlg; EntityGUI_FeatureDetectorDlg* aCornerDlg = (EntityGUI_FeatureDetectorDlg*) aDlg;
gp_Pnt aPnt; gp_Pnt aPnt;
@ -211,8 +212,10 @@ bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWin
if ( QApplication::mouseButtons() == Qt::LeftButton && if ( QApplication::mouseButtons() == Qt::LeftButton &&
aCornerDlg->acceptMouseEvent() ) aCornerDlg->acceptMouseEvent() )
{ {
QPoint end = QPoint(pe->x(),pe->y()); // QPoint end = QPoint(pe->x(),pe->y());
aCornerDlg->setEndPnt( end ); OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
aCornerDlg->setEndPnt( aPnt );
} }
} }
return false; return false;

View File

@ -26,7 +26,6 @@
#include "EntityGUI_FeatureDetectorDlg.h" #include "EntityGUI_FeatureDetectorDlg.h"
#include <OCCViewer_ViewPort3d.h>
#include <OCCViewer_ViewWindow.h> #include <OCCViewer_ViewWindow.h>
#include <OCCViewer_ViewManager.h> #include <OCCViewer_ViewManager.h>
@ -216,7 +215,7 @@ void EntityGUI_FeatureDetectorDlg::Init()
aGlobalCS = gp_Ax3(aOrigin, aDirZ, aDirX); aGlobalCS = gp_Ax3(aOrigin, aDirZ, aDirX);
myStartPnt = QPoint(0,0); myStartPnt = gp_Pnt(0,0,0);
myEndPnt = myStartPnt; myEndPnt = myStartPnt;
myGeomGUI->SetWorkingPlane( aGlobalCS ); myGeomGUI->SetWorkingPlane( aGlobalCS );
@ -278,47 +277,8 @@ void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument()
myFace = aSelectedObject; 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() // function : acceptMouseEvent()
// purpose : // purpose :
@ -429,7 +389,7 @@ void EntityGUI_FeatureDetectorDlg::onButtonToggled( bool checked)
{ {
if (!checked) if (!checked)
{ {
myStartPnt = QPoint(0,0); myStartPnt = gp_Pnt(0,0,0);
myEndPnt = myStartPnt; myEndPnt = myStartPnt;
myLineEdit->setEnabled(true); myLineEdit->setEnabled(true);
} }
@ -443,18 +403,20 @@ void EntityGUI_FeatureDetectorDlg::onButtonToggled( bool checked)
// function : setStartPnt( const QPoint& ) // function : setStartPnt( const QPoint& )
// purpose : // purpose :
//================================================================================= //=================================================================================
void EntityGUI_FeatureDetectorDlg::setStartPnt(const QPoint& theStartPnt) void EntityGUI_FeatureDetectorDlg::setStartPnt(const gp_Pnt& theStartPnt)
{ {
myStartPnt = theStartPnt; myStartPnt = theStartPnt;
MESSAGE("myStartPnt = ("<<theStartPnt.X()<<", "<<theStartPnt.Y()<<")")
} }
//================================================================================= //=================================================================================
// function : setEndPnt( const QPoint& ) // function : setEndPnt( const QPoint& )
// purpose : // purpose :
//================================================================================= //=================================================================================
void EntityGUI_FeatureDetectorDlg::setEndPnt(const QPoint& theEndPnt) void EntityGUI_FeatureDetectorDlg::setEndPnt(const gp_Pnt& theEndPnt)
{ {
myEndPnt = theEndPnt; myEndPnt = theEndPnt;
MESSAGE("myEndPnt = ("<<theEndPnt.X()<<", "<<theEndPnt.Y()<<")")
} }
//================================================================================= //=================================================================================
@ -476,7 +438,6 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
bool res = false; bool res = false;
SUIT_ViewWindow* theViewWindow = getDesktop()->activeWindow(); SUIT_ViewWindow* theViewWindow = getDesktop()->activeWindow();
OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
MESSAGE("myFaceEntry = "<< myFaceEntry.toStdString()); MESSAGE("myFaceEntry = "<< myFaceEntry.toStdString());
std::map< std::string , std::vector<Handle(AIS_InteractiveObject)> >::iterator AISit; std::map< std::string , std::vector<Handle(AIS_InteractiveObject)> >::iterator AISit;
@ -495,10 +456,9 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
else else
return res; return res;
QString theImgFileName = QString::fromStdString( myAISShape->TextureFile() ); std::string theImgFileName = myAISShape->TextureFile();
if ( theImgFileName == "" )
if ( theImgFileName.isEmpty() )
return res; return res;
// Build an instance of detection used to perform image processing operations // 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 height = aDetector->GetImgHeight();
int width = aDetector->GetImgWidth(); 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 // 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 pictureLeft = -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 pictureTop = 0.5 * height; // Y coordinate of both top corners
// Set detection rectangle in the background image coordinates system // Set detection rectangle in the background image coordinates system
myStartPnt.setX( (myStartPnt.x() - (0.5 * winWidth - x_offset)) * 1.0 / imgZoomRatio ); QPoint topLeft = QPoint(myStartPnt.X() - pictureLeft, pictureTop - myStartPnt.Y());
myStartPnt.setY( (myStartPnt.y() - (0.5 * winHeight - y_offset)) * 1.0 / imgZoomRatio ); QPoint bottomRight = QPoint(myEndPnt.X() - pictureLeft, pictureTop - myEndPnt.Y());
myEndPnt.setX( (myEndPnt.x() - (0.5 * winWidth - x_offset)) * 1.0 / imgZoomRatio ); QRect aRect = QRect(topLeft, bottomRight);
myEndPnt.setY( (myEndPnt.y() - (0.5 * winHeight - y_offset)) * 1.0 / imgZoomRatio );
QRect aRect = QRect(myStartPnt, myEndPnt);
GEOM::GEOM_IBasicOperations_var aBasicOperations = myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() ); GEOM::GEOM_IBasicOperations_var aBasicOperations = myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
@ -553,8 +484,8 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
if( !aRect.isEmpty() ) if( !aRect.isEmpty() )
{ {
aDetector->SetROI( aRect ); aDetector->SetROI( aRect );
// viewLeft = rectLeft; pictureLeft = myStartPnt.X();
// viewTop = rectTop; pictureTop = myStartPnt.Y();
} }
aDetector->ComputeCorners(); aDetector->ComputeCorners();
CvPoint2D32f* corners = aDetector->GetCorners(); CvPoint2D32f* corners = aDetector->GetCorners();
@ -569,16 +500,8 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
geomCorners->length( cornerCount ); geomCorners->length( cornerCount );
for (i = 0; i < cornerCount; i++) for (i = 0; i < cornerCount; i++)
{ {
// gp_Pnt aCornerPnt = EntityGUI::ConvertClickToPoint( viewLeft + corners[i].x*imgZoomRatio, double x = pictureLeft + corners[i].x;
// viewTop + corners[i].y*imgZoomRatio, vp->getView() ); double y = pictureTop - corners[i].y;
//
// 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 z = 0; double z = 0;
aGeomCorner = aBasicOperations->MakePointXYZ( x,y,z ); 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_var aCurveOperations = myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
// GEOM::GEOM_ICurvesOperations::_narrow( getOperation() );
aDetector->ComputeContours( method ); aDetector->ComputeContours( method );
std::vector< std::vector<cv::Point> > contours = aDetector->GetContours(); std::vector< std::vector<cv::Point> > contours = aDetector->GetContours();
@ -645,12 +567,6 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
std::pair< std::set< std::vector<int> >::iterator,bool > pnt_it; std::pair< std::set< std::vector<int> >::iterator,bool > pnt_it;
for ( it=contour.begin() ; it < contour.end(); 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}; int pnt_array[] = {it->x,it->y};
std::vector<int> pnt (pnt_array, pnt_array + sizeof(pnt_array) / sizeof(int) ); std::vector<int> pnt (pnt_array, pnt_array + sizeof(pnt_array) / sizeof(int) );

View File

@ -48,8 +48,8 @@ public:
bool acceptMouseEvent() const; bool acceptMouseEvent() const;
// void OnPointSelected( const gp_Pnt& ); // void OnPointSelected( const gp_Pnt& );
void setStartPnt ( const QPoint& ); void setStartPnt ( const gp_Pnt& );
void setEndPnt ( const QPoint& ); void setEndPnt ( const gp_Pnt& );
int getConstructorId() {return myConstructorId;}; int getConstructorId() {return myConstructorId;};
protected: protected:
@ -83,8 +83,8 @@ private:
DlgRef_1Sel* mySelWidget; DlgRef_1Sel* mySelWidget;
QPoint myStartPnt; gp_Pnt myStartPnt;
QPoint myEndPnt; gp_Pnt myEndPnt;
gp_Ax3 myWPlane; gp_Ax3 myWPlane;
gp_Ax3 aGlobalCS; gp_Ax3 aGlobalCS;

View File

@ -182,7 +182,7 @@ bool EntityGUI_PictureImportDlg::execute( ObjectList& objects )
if ( theImgFileName.isEmpty() ) if ( theImgFileName.isEmpty() )
return res; return res;
ShapeRec_FeatureDetector* aDetector = new ShapeRec_FeatureDetector( theImgFileName ); ShapeRec_FeatureDetector* aDetector = new ShapeRec_FeatureDetector( theImgFileName.toStdString() );
int height = aDetector->GetImgHeight(); int height = aDetector->GetImgHeight();
int width = aDetector->GetImgWidth(); int width = aDetector->GetImgWidth();

View File

@ -38,12 +38,12 @@ using namespace cv;
Constructor Constructor
\param theFilename - image to process \param theFilename - image to process
*/ */
ShapeRec_FeatureDetector::ShapeRec_FeatureDetector(const QString& theFilename): ShapeRec_FeatureDetector::ShapeRec_FeatureDetector(const std::string& theFilename):
corners() corners()
{ {
cornerCount = 2000; cornerCount = 2000;
rect=cvRect(0,0,0,0); rect=cvRect(0,0,0,0);
imagePath = theFilename.toStdString(); imagePath = theFilename;
// Store the dimensions of the picture // Store the dimensions of the picture
IplImage* bg_img = cvLoadImage (imagePath.c_str(), CV_LOAD_IMAGE_GRAYSCALE); IplImage* bg_img = cvLoadImage (imagePath.c_str(), CV_LOAD_IMAGE_GRAYSCALE);
imgHeight = bg_img->height; imgHeight = bg_img->height;

View File

@ -29,7 +29,6 @@
#include "opencv2/highgui/highgui.hpp" #include "opencv2/highgui/highgui.hpp"
// Qt // Qt
#include <QString>
#include <QRect> #include <QRect>
enum // Method used for contour detection enum // Method used for contour detection
@ -46,7 +45,7 @@ public:
typedef std::vector<cv::Point> CvContour; typedef std::vector<cv::Point> CvContour;
typedef std::vector<std::vector<cv::Point> > CvContoursArray; typedef std::vector<std::vector<cv::Point> > CvContoursArray;
ShapeRec_FeatureDetector( const QString& ); // Constructor ShapeRec_FeatureDetector( const std::string& ); // Constructor
void ComputeCorners(); // Detects the corners from the image located at imagePath void ComputeCorners(); // Detects the corners from the image located at imagePath
bool ComputeLines(); // Detects the lines from the image located at imagePath bool ComputeLines(); // Detects the lines from the image located at imagePath