- fixed a compilation error if compiling without opencv
- some refactoring
This commit is contained in:
gdd 2011-11-24 14:01:29 +00:00
parent c7fa115a6f
commit 1ac1be4afb
2 changed files with 123 additions and 149 deletions

View File

@ -25,6 +25,7 @@
// Author : Renaud NEDELEC, Open CASCADE S.A.S. // Author : Renaud NEDELEC, Open CASCADE S.A.S.
#include "EntityGUI_FeatureDetectorDlg.h" #include "EntityGUI_FeatureDetectorDlg.h"
#include <ShapeRec_FeatureDetector.hxx>
#include <OCCViewer_ViewWindow.h> #include <OCCViewer_ViewWindow.h>
#include <OCCViewer_ViewManager.h> #include <OCCViewer_ViewManager.h>
@ -130,20 +131,26 @@ EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeom
// //
// myViewGroup->hide(); // myViewGroup->hide();
mySelectionGroup = new QGroupBox(tr("GEOM_DETECT"), centralWidget()); // Widgets for the selection of the picture and the Region Of Interest
mySelectionGroup = new QGroupBox(tr("GEOM_ARGUMENTS"), centralWidget());
QGridLayout* mySelectGrpLayout = new QGridLayout(mySelectionGroup); QGridLayout* mySelectGrpLayout = new QGridLayout(mySelectionGroup);
myPushButton = new QPushButton(mySelectionGroup); myPushButton = new QPushButton(mySelectionGroup);
myPushButton->setIcon(image0); myPushButton->setIcon(image0);
myPushButton->setCheckable(true); myPushButton->setCheckable(true);
myPushButton->setAutoExclusive(true);
mySelButton = new QPushButton(mySelectionGroup); mySelButton = new QPushButton(mySelectionGroup);
mySelButton->setIcon(image1); mySelButton->setIcon(image1);
mySelButton->setCheckable(true);
mySelButton->setAutoExclusive(true);
myLineEdit = new QLineEdit(mySelectionGroup); myLineEdit = new QLineEdit(mySelectionGroup);
mySnapshotLabel = new QLabel(mySelectionGroup); mySnapshotLabel = new QLabel(mySelectionGroup);
QFrame* myImgSampleFrame = new QFrame(mySelectionGroup); QFrame* myImgSampleFrame = new QFrame(mySelectionGroup);
// myImgSampleFrame->setFrameRect(QRect(0,0,10,10)); myImgSampleFrame->setFrameRect(QRect(0,0,40,10));
myImgSampleFrame->setFrameStyle(QFrame::Box); myImgSampleFrame->setFrameStyle(QFrame::Panel | QFrame::Sunken);
QLabel* myPictureLabel = new QLabel(tr( "GEOM_PICTURE" ),mySelectionGroup); QLabel* myPictureLabel = new QLabel(tr( "GEOM_PICTURE" ),mySelectionGroup);
mySelectGrpLayout->addWidget(myPictureLabel, 0, 0); mySelectGrpLayout->addWidget(myPictureLabel, 0, 0);
mySelectGrpLayout->addWidget(mySelButton, 0, 1); mySelectGrpLayout->addWidget(mySelButton, 0, 1);
@ -151,8 +158,8 @@ EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeom
mySelectGrpLayout->addWidget(mySnapshotLabel, 1, 0); mySelectGrpLayout->addWidget(mySnapshotLabel, 1, 0);
mySelectGrpLayout->addWidget(myPushButton, 1, 1); mySelectGrpLayout->addWidget(myPushButton, 1, 1);
mySelectGrpLayout->addWidget(myImgSampleFrame, 1, 2); mySelectGrpLayout->addWidget(myImgSampleFrame, 1, 2, 2, 1);
// mySelectGrpLayout->setColumnStretch(3, 1); mySelectGrpLayout->setRowStretch(3, 1);
QGridLayout* myFrameLayout = new QGridLayout(myImgSampleFrame); QGridLayout* myFrameLayout = new QGridLayout(myImgSampleFrame);
myImgSampleLabel = new QLabel(myImgSampleFrame); myImgSampleLabel = new QLabel(myImgSampleFrame);
@ -199,20 +206,14 @@ void EntityGUI_FeatureDetectorDlg::Init()
connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ); connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
connect( this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int))); connect( this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
connect( myPushButton, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );
connect( myPushButton, SIGNAL( toggled( bool ) ), this, SLOT( onButtonToggled( bool ) ) ); connect( mySelButton, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );
connect( mySelButton, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
// connect( myViewButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( onViewClicked( int ) ) ); // connect( myViewButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( onViewClicked( int ) ) );
connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),this, SLOT( SelectionIntoArgument() ) ); connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),this, SLOT( SelectionIntoArgument() ) );
myConstructorId = 0; myConstructorId = 0;
mySelButton->click(); mySelButton->click();
mySelButton->setDown(true);
// SetEditCurrentArgument(); // SetEditCurrentArgument();
SelectionIntoArgument(); SelectionIntoArgument();
@ -238,22 +239,6 @@ void EntityGUI_FeatureDetectorDlg::Init()
ConstructorsClicked(myConstructorId); ConstructorsClicked(myConstructorId);
} }
//=================================================================================
// function : SetEditCurrentArgument()
// purpose :
//=================================================================================
void EntityGUI_FeatureDetectorDlg::SetEditCurrentArgument()
{
QPushButton* send = (QPushButton*)sender();
if ( send == mySelButton ) {
myEditCurrentArgument = myLineEdit;
myLineEdit->setEnabled(true);
}
else
myLineEdit->setEnabled(false);
send->setDown(true);
}
//================================================================================= //=================================================================================
// function : SelectionIntoArgument() // function : SelectionIntoArgument()
// purpose : Called when selection as changed or other case // purpose : Called when selection as changed or other case
@ -261,6 +246,7 @@ void EntityGUI_FeatureDetectorDlg::SetEditCurrentArgument()
void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument() void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument()
{ {
// TODO supprimer les lignes qui ne servent à rien le cas échéant
SUIT_ViewWindow* theViewWindow = getDesktop()->activeWindow(); SUIT_ViewWindow* theViewWindow = getDesktop()->activeWindow();
std::map< std::string , std::vector<Handle(AIS_InteractiveObject)> >::iterator AISit; std::map< std::string , std::vector<Handle(AIS_InteractiveObject)> >::iterator AISit;
SOCC_Viewer* soccViewer = (SOCC_Viewer*)(theViewWindow->getViewManager()->getViewModel()); SOCC_Viewer* soccViewer = (SOCC_Viewer*)(theViewWindow->getViewManager()->getViewModel());
@ -312,7 +298,13 @@ void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument()
if ( theImgFileName == "" ) if ( theImgFileName == "" )
return ; return ;
// Setting the image caracteristics
aDetector->SetPath( theImgFileName ); aDetector->SetPath( theImgFileName );
height = aDetector->GetImgHeight();
width = aDetector->GetImgWidth();
pictureLeft = -0.5 * width; // X coordinate of the top left corner of the background image in the view
pictureTop = 0.5 * height; // Y coordinate of both top corners
} }
} }
@ -421,21 +413,23 @@ void EntityGUI_FeatureDetectorDlg::ConstructorsClicked(int id)
// } // }
//================================================================================= //=================================================================================
// function : onButtonToggled() // function : onButtonClicked()
// purpose : // purpose :
//================================================================================= //=================================================================================
void EntityGUI_FeatureDetectorDlg::onButtonToggled( bool checked) void EntityGUI_FeatureDetectorDlg::onButtonClicked()
{ {
if (!checked) QPushButton* send = (QPushButton*)sender();
{ if (send == myPushButton)
myStartPnt = gp_Pnt(0,0,0);
myEndPnt = myStartPnt;
myLineEdit->setEnabled(true);
}
else
{ {
myLineEdit->setEnabled(false); myLineEdit->setEnabled(false);
} }
else if (send == mySelButton)
{
myStartPnt = gp_Pnt(0,0,0);
myEndPnt = myStartPnt;
myEditCurrentArgument = myLineEdit;
myLineEdit->setEnabled(true);
}
} }
//================================================================================= //=================================================================================
@ -456,40 +450,40 @@ void EntityGUI_FeatureDetectorDlg::setEndPnt(const gp_Pnt& theEndPnt)
{ {
myEndPnt = theEndPnt; myEndPnt = theEndPnt;
MESSAGE("myEndPnt = ("<<theEndPnt.X()<<", "<<theEndPnt.Y()<<")") MESSAGE("myEndPnt = ("<<theEndPnt.X()<<", "<<theEndPnt.Y()<<")")
showImageSample(); if (setSelectionRect())
showImageSample();
}
//=================================================================================
// function : setSelectionRect()
// purpose :
//=================================================================================
bool EntityGUI_FeatureDetectorDlg::setSelectionRect()
{
// 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());
myRect = QRect(topLeft, bottomRight);
return (!myRect.isEmpty() && myRect.width() > 1);
} }
//================================================================================= //=================================================================================
// function : showImageSample() // function : showImageSample()
// purpose : // purpose : Display a preview of the image sample selected by the user
//================================================================================= //=================================================================================
void EntityGUI_FeatureDetectorDlg::showImageSample() void EntityGUI_FeatureDetectorDlg::showImageSample()
{ {
int height = aDetector->GetImgHeight(); // Cropp the image to the selection rectangle given by the user
int width = aDetector->GetImgWidth(); aDetector->SetROI( myRect );
std::string samplePicturePath = aDetector->CroppImage();
// Operations to display the corners properly in the 3D scene // Display the result
double pictureLeft = -0.5 * width; // X coordinate of the top left corner of the background image in the view QPixmap pixmap(QString(samplePicturePath.c_str()));
double pictureTop = 0.5 * height; // Y coordinate of both top corners myImgSampleLabel->setPixmap(pixmap);
myImgSampleLabel->setMask(pixmap.mask());
// 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 // function : createOperation
// purpose : // purpose :
@ -507,51 +501,23 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
{ {
bool res = false; 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;
//
// aDetector->SetPath( theImgFileName );
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);
GEOM::GEOM_IBasicOperations_var aBasicOperations = myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() ); GEOM::GEOM_IBasicOperations_var aBasicOperations = myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
GEOM::GEOM_IShapesOperations_var aShapesOperations = GEOM::GEOM_IShapesOperations::_narrow( getOperation() ); GEOM::GEOM_IShapesOperations_var aShapesOperations = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
if (myConstructorId == CORNERS) if (myConstructorId == CORNERS)
{ {
if( !aRect.isEmpty() ) double subPictureLeft;
double subPictureTop;
if( !myRect.isEmpty() )
{ {
aDetector->SetROI( aRect ); aDetector->SetROI( myRect );
pictureLeft = myStartPnt.X(); subPictureLeft = myStartPnt.X();
pictureTop = myStartPnt.Y(); subPictureTop = myStartPnt.Y();
}
else
{
subPictureLeft = pictureLeft;
subPictureTop = pictureTop;
} }
aDetector->ComputeCorners(); aDetector->ComputeCorners();
CvPoint2D32f* corners = aDetector->GetCorners(); CvPoint2D32f* corners = aDetector->GetCorners();
@ -566,8 +532,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++)
{ {
double x = pictureLeft + corners[i].x; double x = subPictureLeft + corners[i].x;
double y = pictureTop - corners[i].y; double y = subPictureTop - corners[i].y;
double z = 0; double z = 0;
aGeomCorner = aBasicOperations->MakePointXYZ( x,y,z ); aGeomCorner = aBasicOperations->MakePointXYZ( x,y,z );
@ -593,9 +559,9 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
else if (myConstructorId == CONTOURS) else if (myConstructorId == CONTOURS)
{ {
int method = 0 ; //CANNY int method = 0 ; //CANNY
if( !aRect.isEmpty() && aRect.width() > 1 ) if( !myRect.isEmpty() && myRect.width() > 1 )
{ {
aDetector->SetROI( aRect ); aDetector->SetROI( myRect );
method = 1 ; //COLORFILTER method = 1 ; //COLORFILTER
} }
@ -707,36 +673,38 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
res=true; res=true;
} }
else if(myConstructorId ==LINES) // TEST not very conclusive
{
aDetector->ComputeLines();
std::vector<cv::Vec4i> lines = aDetector->GetLines();
GEOM::GEOM_Object_var Pnt1;
GEOM::GEOM_Object_var Pnt2;
GEOM::GEOM_Object_var aLine;
GEOM::ListOfGO_var geomLines = new GEOM::ListOfGO(); // else if(myConstructorId ==LINES)
int linesCount=0; // {
for( int i = 0; i < lines.size(); i++ ) // aDetector->ComputeLines();
{ // std::vector<cv::Vec4i> lines = aDetector->GetLines();
Pnt1 = aBasicOperations->MakePointXYZ( -0.5 *width + lines[i][0], 0.5 *height - lines[i][1], 0 ); // GEOM::GEOM_Object_var Pnt1;
Pnt2 = aBasicOperations->MakePointXYZ( -0.5 *width + lines[i][2], 0.5 *height - lines[i][3], 0 ); // GEOM::GEOM_Object_var Pnt2;
aLine = aBasicOperations->MakeLineTwoPnt( Pnt1, Pnt2 ); // GEOM::GEOM_Object_var aLine;
if ( !aLine->_is_nil() ) //
{ // GEOM::ListOfGO_var geomLines = new GEOM::ListOfGO();
geomLines->length(linesCount + 1); // int linesCount=0;
geomLines[linesCount] = aLine; // for( int i = 0; i < lines.size(); i++ )
linesCount++; // {
} // Pnt1 = aBasicOperations->MakePointXYZ( -0.5 *width + lines[i][0], 0.5 *height - lines[i][1], 0 );
} // Pnt2 = aBasicOperations->MakePointXYZ( -0.5 *width + lines[i][2], 0.5 *height - lines[i][3], 0 );
GEOM::GEOM_Object_var aLinesCompound = aShapesOperations->MakeCompound(geomLines); // aLine = aBasicOperations->MakeLineTwoPnt( Pnt1, Pnt2 );
if ( !aLinesCompound->_is_nil() ) // if ( !aLine->_is_nil() )
{ // {
objects.push_back( aLinesCompound._retn() ); // geomLines->length(linesCount + 1);
} // geomLines[linesCount] = aLine;
// linesCount++;
res=true; // }
} // }
// GEOM::GEOM_Object_var aLinesCompound = aShapesOperations->MakeCompound(geomLines);
// if ( !aLinesCompound->_is_nil() )
// {
// objects.push_back( aLinesCompound._retn() );
// }
//
// res=true;
// }
return res; return res;
} }

View File

@ -22,7 +22,6 @@
#include <GEOMBase_Skeleton.h> #include <GEOMBase_Skeleton.h>
#include <gp_Ax3.hxx> #include <gp_Ax3.hxx>
#include <ShapeRec_FeatureDetector.hxx>
#include <QBitmap> #include <QBitmap>
class QLineEdit; class QLineEdit;
@ -35,6 +34,7 @@ class DlgRef_3Radio;
class DlgRef_1Sel; class DlgRef_1Sel;
class gp_Pnt; class gp_Pnt;
class ShapeRec_FeatureDetector;
//================================================================================= //=================================================================================
// class : EntityGUI_Dlg // class : EntityGUI_Dlg
@ -49,9 +49,8 @@ public:
~EntityGUI_FeatureDetectorDlg(); ~EntityGUI_FeatureDetectorDlg();
bool acceptMouseEvent() const; bool acceptMouseEvent() const;
// void OnPointSelected( const gp_Pnt& ); void setStartPnt ( const gp_Pnt& );
void setStartPnt ( const gp_Pnt& ); void setEndPnt ( const gp_Pnt& );
void setEndPnt ( const gp_Pnt& );
int getConstructorId() {return myConstructorId;}; int getConstructorId() {return myConstructorId;};
protected: protected:
@ -61,15 +60,15 @@ protected:
private: private:
void Init(); void Init();
bool setSelectionRect();
void showImageSample(); void showImageSample();
private slots: private slots:
void SetEditCurrentArgument();
void SelectionIntoArgument(); void SelectionIntoArgument();
void ConstructorsClicked( int ); void ConstructorsClicked( int );
// void onViewClicked( int ); // void onViewClicked( int );
void onButtonToggled( bool ); void onButtonClicked();
void ClickOnOk(); void ClickOnOk();
bool ClickOnApply(); bool ClickOnApply();
@ -77,6 +76,9 @@ private slots:
private: private:
ShapeRec_FeatureDetector* aDetector; ShapeRec_FeatureDetector* aDetector;
gp_Ax3 myWPlane;
gp_Ax3 aGlobalCS;
GEOM::GeomObjPtr myFace; GEOM::GeomObjPtr myFace;
QString myFaceEntry; QString myFaceEntry;
@ -91,15 +93,19 @@ private:
gp_Pnt myStartPnt; gp_Pnt myStartPnt;
gp_Pnt myEndPnt; gp_Pnt myEndPnt;
QRect myRect;
gp_Ax3 myWPlane;
gp_Ax3 aGlobalCS;
QPushButton* myPushButton;
QPushButton* mySelButton; QPushButton* mySelButton;
QLineEdit* myLineEdit; QLineEdit* myLineEdit;
QPushButton* myPushButton;
// Picture dimensions and position
int height;
int width;
double pictureLeft;
double pictureTop;
// Output slection widget
DlgRef_3Radio* myOutputGroup;; DlgRef_3Radio* myOutputGroup;;
}; };