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->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;

View File

@ -26,7 +26,6 @@
#include "EntityGUI_FeatureDetectorDlg.h"
#include <OCCViewer_ViewPort3d.h>
#include <OCCViewer_ViewWindow.h>
#include <OCCViewer_ViewManager.h>
@ -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 = ("<<theStartPnt.X()<<", "<<theStartPnt.Y()<<")")
}
//=================================================================================
// function : setEndPnt( const QPoint& )
// purpose :
//=================================================================================
void EntityGUI_FeatureDetectorDlg::setEndPnt(const QPoint& theEndPnt)
void EntityGUI_FeatureDetectorDlg::setEndPnt(const gp_Pnt& theEndPnt)
{
myEndPnt = theEndPnt;
MESSAGE("myEndPnt = ("<<theEndPnt.X()<<", "<<theEndPnt.Y()<<")")
}
//=================================================================================
@ -476,7 +438,6 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
bool res = false;
SUIT_ViewWindow* theViewWindow = getDesktop()->activeWindow();
OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
MESSAGE("myFaceEntry = "<< myFaceEntry.toStdString());
std::map< std::string , std::vector<Handle(AIS_InteractiveObject)> >::iterator AISit;
@ -495,10 +456,9 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
else
return res;
QString theImgFileName = QString::fromStdString( myAISShape->TextureFile() );
std::string theImgFileName = myAISShape->TextureFile();
if ( theImgFileName.isEmpty() )
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<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;
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<int> pnt (pnt_array, pnt_array + sizeof(pnt_array) / sizeof(int) );

View File

@ -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;

View File

@ -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();

View File

@ -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;

View File

@ -29,7 +29,6 @@
#include "opencv2/highgui/highgui.hpp"
// Qt
#include <QString>
#include <QRect>
enum // Method used for contour detection
@ -46,7 +45,7 @@ public:
typedef std::vector<cv::Point> CvContour;
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
bool ComputeLines(); // Detects the lines from the image located at imagePath