From c8ae1da7b2988de253fec52eb7583a5b0f291209 Mon Sep 17 00:00:00 2001 From: gdd Date: Tue, 8 Nov 2011 13:40:30 +0000 Subject: [PATCH] Merge from BR_OPENCV --- adm_local/unix/config_files/Makefile.am | 3 +- configure.ac | 15 +- resources/GEOM_en.xml | 1 + src/BasicGUI/Makefile.am | 4 +- src/DisplayGUI/DisplayGUI.cxx | 34 +- src/EntityGUI/EntityGUI.cxx | 129 ++- src/EntityGUI/EntityGUI.h | 3 +- .../EntityGUI_FeatureDetectorDlg.cxx | 796 ++++++++++++++++++ src/EntityGUI/EntityGUI_FeatureDetectorDlg.h | 102 +++ src/EntityGUI/EntityGUI_PictureImportDlg.cxx | 209 +++++ src/EntityGUI/EntityGUI_PictureImportDlg.h | 74 ++ src/EntityGUI/EntityGUI_SketcherDlg.cxx | 11 +- src/EntityGUI/Makefile.am | 31 +- src/GEOMBase/GEOMBase_Helper.cxx | 23 +- src/GEOMBase/Makefile.am | 6 +- src/GEOMGUI/GEOM_Displayer.cxx | 39 + src/GEOMGUI/GEOM_Displayer.h | 6 + src/GEOMGUI/GEOM_msg_en.ts | 96 ++- src/GEOMGUI/GEOM_msg_fr.ts | 31 + src/GEOMGUI/GeometryGUI.cxx | 36 +- src/GEOMGUI/GeometryGUI_Operations.h | 6 + src/GEOMGUI/Makefile.am | 7 +- src/GEOMToolsGUI/GEOMToolsGUI.cxx | 3 + src/GEOMToolsGUI/GEOMToolsGUI.h | 1 + src/GEOMToolsGUI/GEOMToolsGUI_1.cxx | 45 + src/Makefile.am | 5 + src/OBJECT/GEOM_AISShape.cxx | 15 +- src/OperationGUI/Makefile.am | 6 +- src/ShapeRecognition/Makefile.am | 50 ++ .../ShapeRec_FeatureDetector.cxx | 264 ++++++ .../ShapeRec_FeatureDetector.hxx | 80 ++ 31 files changed, 2049 insertions(+), 82 deletions(-) create mode 100644 src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx create mode 100644 src/EntityGUI/EntityGUI_FeatureDetectorDlg.h create mode 100644 src/EntityGUI/EntityGUI_PictureImportDlg.cxx create mode 100644 src/EntityGUI/EntityGUI_PictureImportDlg.h create mode 100644 src/ShapeRecognition/Makefile.am create mode 100644 src/ShapeRecognition/ShapeRec_FeatureDetector.cxx create mode 100644 src/ShapeRecognition/ShapeRec_FeatureDetector.hxx diff --git a/adm_local/unix/config_files/Makefile.am b/adm_local/unix/config_files/Makefile.am index 66230c1fe..b2687da74 100644 --- a/adm_local/unix/config_files/Makefile.am +++ b/adm_local/unix/config_files/Makefile.am @@ -21,4 +21,5 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am dist_admlocalm4_DATA = \ check_GEOM.m4 \ -check_GUI.m4 +check_GUI.m4 \ +check_OpenCV.m4 diff --git a/configure.ac b/configure.ac index 8be0b6c53..8849337c3 100644 --- a/configure.ac +++ b/configure.ac @@ -331,6 +331,14 @@ echo --------------------------------------------- echo CHECK_SPHINX +echo +echo --------------------------------------------- +echo testing Opencv +echo --------------------------------------------- +echo +CHECK_OPENCV +AC_DEFINE_UNQUOTED(WITH_OPENCV,${WITH_OPENCV}) + echo echo --------------------------------------------- echo Testing Kernel @@ -348,11 +356,11 @@ echo echo Configure if test "${gui_ok}" = "yes"; then - variables="cc_ok lex_yacc_ok python_ok swig_ok threads_ok OpenGL_ok qt_ok vtk_ok hdf5_ok omniORB_ok boost_ok occ_ok doxygen_ok graphviz_ok sphinx_ok Kernel_ok gui_ok" + variables="cc_ok lex_yacc_ok python_ok swig_ok threads_ok OpenGL_ok qt_ok vtk_ok hdf5_ok omniORB_ok boost_ok occ_ok doxygen_ok graphviz_ok sphinx_ok opencv_ok Kernel_ok gui_ok" elif test "${SalomeGUI_need}" != "no"; then - variables="cc_ok lex_yacc_ok python_ok swig_ok threads_ok vtk_ok hdf5_ok omniORB_ok boost_ok occ_ok doxygen_ok graphviz_ok Kernel_ok gui_ok" + variables="cc_ok lex_yacc_ok python_ok swig_ok threads_ok vtk_ok hdf5_ok omniORB_ok boost_ok occ_ok doxygen_ok graphviz_ok opencv_ok Kernel_ok gui_ok" else - variables="cc_ok lex_yacc_ok python_ok swig_ok threads_ok vtk_ok hdf5_ok omniORB_ok boost_ok occ_ok doxygen_ok graphviz_ok Kernel_ok" + variables="cc_ok lex_yacc_ok python_ok swig_ok threads_ok vtk_ok hdf5_ok omniORB_ok boost_ok occ_ok doxygen_ok graphviz_ok opencv_ok Kernel_ok" fi for var in $variables @@ -463,6 +471,7 @@ AC_OUTPUT([ \ src/STEPImport/Makefile \ src/STLExport/Makefile \ src/ShHealOper/Makefile \ + src/ShapeRecognition/Makefile \ src/TransformationGUI/Makefile \ src/VTKExport/Makefile \ resources/Makefile \ diff --git a/resources/GEOM_en.xml b/resources/GEOM_en.xml index d664cfd5b..033ccbd86 100644 --- a/resources/GEOM_en.xml +++ b/resources/GEOM_en.xml @@ -293,6 +293,7 @@ + diff --git a/src/BasicGUI/Makefile.am b/src/BasicGUI/Makefile.am index 08fde9c7d..5aad443b1 100644 --- a/src/BasicGUI/Makefile.am +++ b/src/BasicGUI/Makefile.am @@ -93,6 +93,7 @@ libBasicGUI_la_CPPFLAGS = \ $(GUI_CXXFLAGS) \ $(CORBA_CXXFLAGS) \ $(CORBA_INCLUDES) \ + $(OPENCV_INCLUDES) \ -I$(srcdir)/../OBJECT \ -I$(srcdir)/../DlgRef \ -I$(srcdir)/../GEOMGUI \ @@ -109,4 +110,5 @@ libBasicGUI_la_LDFLAGS = \ ../GEOMBase/libGEOMBase.la \ ../GEOMGUI/libGEOM.la \ $(CAS_LDFLAGS) -lTKGeomBase \ - $(GUI_LDFLAGS) -lsuit + $(GUI_LDFLAGS) -lsuit \ + $(OPENCV_LIBS) diff --git a/src/DisplayGUI/DisplayGUI.cxx b/src/DisplayGUI/DisplayGUI.cxx index 53c04c204..a0d6812ce 100644 --- a/src/DisplayGUI/DisplayGUI.cxx +++ b/src/DisplayGUI/DisplayGUI.cxx @@ -128,6 +128,9 @@ bool DisplayGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent) case GEOMOp::OpShading: // POPUP MENU - DISPLAY MODE - SHADING ChangeDisplayMode( 1 ); break; + case GEOMOp::OpTexture: // POPUP MENU - DISPLAY MODE - TEXTURE + ChangeDisplayMode( 3 ); + break; case GEOMOp::OpVectors: // POPUP MENU - DISPLAY MODE - SHOW EDGE DIRECTION ChangeDisplayMode( 2 ); break; @@ -509,15 +512,16 @@ void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow anActors->InitTraversal(); while (vtkActor* anAct = anActors->GetNextActor()) { GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(anAct); - vectorMode = !aGeomActor->GetVectorMode(); - aGeomActor->SetVectorMode(vectorMode); + vectorMode = !aGeomActor->GetVectorMode(); + aGeomActor->SetVectorMode(vectorMode); } } - if(mode == 0 || mode == 1) { - aStudy->setObjectProperty(mgrId,It.Value()->getEntry(),DISPLAY_MODE_PROP, mode); - } else if (mode == 3) { - aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),VECTOR_MODE_PROP , vectorMode); - } + if(mode == 0 || mode == 1) { + aStudy->setObjectProperty(mgrId,It.Value()->getEntry(),DISPLAY_MODE_PROP, mode); + } + else if (mode == 3) { + aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),VECTOR_MODE_PROP , vectorMode); + } } } aView->Repaint(); @@ -543,20 +547,22 @@ void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false ); else if ( mode == 1 ) ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false ); - if (mode == 2 ) { + else if ( mode == 3 ) + ic->SetDisplayMode( interIter.Value(), AIS_ExactHLR, false ); + else if (mode == 2 ) { Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( interIter.Value() ); if ( !aSh.IsNull() ) { - vectorMode = !aSh->isShowVectors(); + vectorMode = !aSh->isShowVectors(); aSh->SetDisplayVectors(vectorMode); ic->RecomputePrsOnly(interIter.Value()); } } } - if(mode == 0 || mode == 1) { - aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),DISPLAY_MODE_PROP, mode); - } else if (mode == 2) { - aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),VECTOR_MODE_PROP, vectorMode); - } + if(mode == 0 || mode == 1) { + aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),DISPLAY_MODE_PROP, mode); + } else if (mode == 2) { + aStudy->setObjectProperty(mgrId, It.Value()->getEntry(),VECTOR_MODE_PROP, vectorMode); + } } } ic->UpdateCurrentViewer(); diff --git a/src/EntityGUI/EntityGUI.cxx b/src/EntityGUI/EntityGUI.cxx index a6b0bdf23..02985b328 100644 --- a/src/EntityGUI/EntityGUI.cxx +++ b/src/EntityGUI/EntityGUI.cxx @@ -46,10 +46,13 @@ #include #include +#include -#include "EntityGUI_SketcherDlg.h" // Sketcher -#include "EntityGUI_3DSketcherDlg.h" // Sketcher -#include "EntityGUI_SubShapeDlg.h" // Method SUBSHAPE +#include "EntityGUI_SketcherDlg.h" // Sketcher +#include "EntityGUI_3DSketcherDlg.h" // Sketcher +#include "EntityGUI_SubShapeDlg.h" // Method SUBSHAPE +#include "EntityGUI_FeatureDetectorDlg.h" // Feature Detection +#include "EntityGUI_PictureImportDlg.h" // Import Picture in viewer //======================================================================= // function : EntityGUI() @@ -93,6 +96,14 @@ bool EntityGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent ) case GEOMOp::OpExplode: // EXPLODE aDlg = new EntityGUI_SubShapeDlg( getGeometryGUI(), parent ); break; +#ifdef WITH_OPENCV + case GEOMOp::OpFeatureDetect: // FEATURE DETECTION + aDlg = new EntityGUI_FeatureDetectorDlg( getGeometryGUI(), parent ); + break; + case GEOMOp::OpPictureImport: // IMPORT PICTURE IN VIEWER + aDlg = new EntityGUI_PictureImportDlg( getGeometryGUI(), parent ); + break; +#endif default: app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) ); break; @@ -113,38 +124,96 @@ bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWi QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox(); // Create Point dialog, OCC viewer - if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_SketcherDlg" ) == 0 ) && + if ( aDlg && theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() && pe->modifiers() != Qt::ControlModifier ) { - MESSAGE("Premier if ok!") - EntityGUI_SketcherDlg* aPntDlg = (EntityGUI_SketcherDlg*) aDlg; - if ( aPntDlg->acceptMouseEvent() ) { - OCCViewer_Viewer* anOCCViewer = - ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer(); - Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext(); - - gp_Pnt aPnt; - - ic->InitSelected(); - if ( pe->modifiers() == Qt::ShiftModifier ) - ic->ShiftSelect(); // Append selection - else + + gp_Pnt aPnt; + + if ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_SketcherDlg" ) == 0 ) + { + EntityGUI_SketcherDlg* aSketcherDlg = (EntityGUI_SketcherDlg*) aDlg; + if ( aSketcherDlg->acceptMouseEvent() ) { + OCCViewer_Viewer* anOCCViewer = + ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer(); + Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext(); + + ic->InitSelected(); + if ( pe->modifiers() == Qt::ShiftModifier ) + ic->ShiftSelect(); // Append selection + else + ic->Select(); // New selection + + ic->InitSelected(); + if ( ic->MoreSelected() ) { + TopoDS_Shape aShape = ic->SelectedShape(); + if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) + aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) ); + } + else { + OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); + aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); + } + + Qt::KeyboardModifiers modifiers = pe->modifiers(); + aSketcherDlg->OnPointSelected( modifiers, aPnt ); // "feed" the point to point construction dialog + } // acceptMouseEvent() + } + if ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 ) + { + EntityGUI_FeatureDetectorDlg* aCornerDlg = (EntityGUI_FeatureDetectorDlg*) aDlg; + if ( aCornerDlg->acceptMouseEvent() ) { + OCCViewer_Viewer* anOCCViewer = + ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer(); + Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext(); + + ic->InitSelected(); ic->Select(); // New selection - ic->InitSelected(); - if ( ic->MoreSelected() ) { - TopoDS_Shape aShape = ic->SelectedShape(); - if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) - aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) ); - } - else { - OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); - aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); - } + ic->InitSelected(); + if ( ic->MoreSelected() ) { + TopoDS_Shape aShape = ic->SelectedShape(); + if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) + aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) ); + } + 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 ); + } // acceptMouseEvent() + + } + } + return false; +} + +//================================================================================= +// function : 0nMouseMove() +// purpose : [static] manage mouse events +//================================================================================= +bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow ) +{ +// MESSAGE("EntityGUI::OnMouseMove") + QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox(); + if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 ) && + theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() && + pe->modifiers() != Qt::ControlModifier ) { + + EntityGUI_FeatureDetectorDlg* aCornerDlg = (EntityGUI_FeatureDetectorDlg*) aDlg; + + gp_Pnt aPnt; - Qt::KeyboardModifiers modifiers = pe->modifiers(); - aPntDlg->OnPointSelected( modifiers, aPnt ); // "feed" the point to point construction dialog - } // acceptMouseEvent() + if ( QApplication::mouseButtons() == Qt::LeftButton && + aCornerDlg->acceptMouseEvent() ) + { + QPoint end = QPoint(pe->x(),pe->y()); + aCornerDlg->setEndPnt( end ); + } } return false; } diff --git a/src/EntityGUI/EntityGUI.h b/src/EntityGUI/EntityGUI.h index cfc0addef..d6a557ef6 100644 --- a/src/EntityGUI/EntityGUI.h +++ b/src/EntityGUI/EntityGUI.h @@ -49,8 +49,9 @@ 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 ); - gp_Pnt ConvertClickToPoint( int x, int y, Handle(V3d_View) aView ); + static gp_Pnt ConvertClickToPoint( int x, int y, Handle(V3d_View) aView ); void DisplaySimulationShape( const TopoDS_Shape&, const TopoDS_Shape& ); void EraseSimulationShape(); diff --git a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx new file mode 100644 index 000000000..8be541587 --- /dev/null +++ b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx @@ -0,0 +1,796 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// GEOM GEOMGUI : GUI for Geometry component +// File : EntityGUI_SketcherDlg.cxx +// Author : Renaud NEDELEC, Open CASCADE S.A.S. + +#include "EntityGUI_FeatureDetectorDlg.h" + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include + +#include +#include + +#include + +// Constructors +enum{ + CONTOURS, + CORNERS, + LINES +}; + +enum { + RADIO_BUTTONS, + MSG, + PUSH_BUTTON, +}; + +// // // View +// // enum { +// // XY, +// // YZ, +// // XZ +// // }; + + +//================================================================================= +// class : EntityGUI_FeatureDetectorDlg() +// purpose : Constructs a EntityGUI_FeatureDetectorDlg which is a child of 'parent', with the +// name 'name' and widget flags set to 'f'. +// The dialog will by default be modeless, unless you set 'modal' to +// TRUE to construct a modal dialog. +//================================================================================= +EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeometryGUI, QWidget* parent, + bool modal, Qt::WindowFlags fl) + : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl) +{ + QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_DUMP"))); + QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT"))); + + setWindowTitle(tr("GEOM_DETECT_TITLE")); + + /***************************************************************/ + + mainFrame()->GroupConstructors->setTitle(tr("GEOM_FEATURES")); + mainFrame()->RadioButton1->setText(tr("GEOM_CONTOURS")); + mainFrame()->RadioButton2->setText(tr("GEOM_CORNERS")); +// mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose); +// mainFrame()->RadioButton2->close(); +// mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose); +// mainFrame()->RadioButton3->close(); + +// myViewGroup = new DlgRef_3Radio(centralWidget()); +// myViewGroup->GroupBox1->setTitle(tr("GEOM_VIEW")); +// myViewGroup->RadioButton1->setText(tr( "GEOM_TOP" )); +// myViewGroup->RadioButton2->setText(tr( "GEOM_FRONT")); +// myViewGroup->RadioButton3->setText(tr( "GEOM_LEFT" )); +// myViewButtonGroup = new QButtonGroup( this ); +// myViewButtonGroup->addButton( myViewGroup->RadioButton1, XY ); // Top view +// myViewButtonGroup->addButton( myViewGroup->RadioButton2, YZ ); // Front View +// myViewButtonGroup->addButton( myViewGroup->RadioButton3, XZ ); // Left View +// +// myViewGroup->hide(); + + mySelectionGroup = new QGroupBox(tr("GEOM_DETECT"), centralWidget()); + QGridLayout* mySelectGrpLayout = new QGridLayout(mySelectionGroup); + myPushButton = new QPushButton(mySelectionGroup); + myPushButton->setIcon(image0); + myPushButton->setCheckable(true); + + mySelButton = new QPushButton(mySelectionGroup); + mySelButton->setIcon(image1); + myLineEdit = new QLineEdit(mySelectionGroup); + myCheckBox = new QCheckBox(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); + mySelectGrpLayout->addWidget(myCheckBox, 2, 0); + + myOutputGroup = new DlgRef_3Radio(centralWidget()); + myOutputGroup->GroupBox1->setTitle(tr("GEOM_DETECT_OUTPUT")); + myOutputGroup->RadioButton2->setText(tr( "GEOM_POLYLINE" )); + myOutputGroup->RadioButton1->setText(tr( "GEOM_SPLINE")); + myOutputGroup->RadioButton3->hide(); + +// myOutputGroup->hide(); //caché pour la demo + + QVBoxLayout* layout = new QVBoxLayout(centralWidget()); + layout->setMargin(0); layout->setSpacing(6); +// layout->addWidget( myViewGroup); + layout->addWidget( mySelectionGroup); + layout->addWidget( myOutputGroup); + +// mainFrame()->GroupBoxName->hide(); + + Init(); + +} + +//================================================================================= +// function : ~EntityGUI_FeatureDetectorDlg() +// purpose : Destroys the object and frees any allocated resources +//================================================================================= +EntityGUI_FeatureDetectorDlg::~EntityGUI_FeatureDetectorDlg() +{ + +} + +//================================================================================= +// function : Init() +// purpose : +//================================================================================= +void EntityGUI_FeatureDetectorDlg::Init() +{ + connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ); + connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); + connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); + + connect( this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int))); + + connect( myPushButton, SIGNAL( toggled( bool ) ), this, SLOT( onButtonToggled( bool ) ) ); + connect( mySelButton, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); + +// connect( myViewButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( onViewClicked( int ) ) ); + + connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),this, SLOT( SelectionIntoArgument() ) ); + + myConstructorId = 0; + + mySelButton->click(); + mySelButton->setDown(true); + +// SetEditCurrentArgument(); + SelectionIntoArgument(); + + initName(tr("GEOM_CONTOURS")); + resize(100,100); + +// myViewGroup->RadioButton1->setChecked(true); + myOutputGroup->RadioButton1->setChecked(true); + + gp_Pnt aOrigin = gp_Pnt(0, 0, 0); + gp_Dir aDirZ = gp_Dir(0, 0, 1); + gp_Dir aDirX = gp_Dir(1, 0, 0); + + aGlobalCS = gp_Ax3(aOrigin, aDirZ, aDirX); + + myStartPnt = QPoint(0,0); + myEndPnt = myStartPnt; + + myGeomGUI->SetWorkingPlane( aGlobalCS ); + myGeomGUI->ActiveWorkingPlane(); + + 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() +// purpose : Called when selection as changed or other case +//================================================================================= +void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument() +{ + if (!myEditCurrentArgument->isEnabled()) + return; + + myEditCurrentArgument->setText( "" ); + + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); + SALOME_ListIO aSelList; + aSelMgr->selectedObjects(aSelList); + SALOME_ListIteratorOfListIO anIt( aSelList ); + for( ; anIt.More(); anIt.Next() ) + if( !anIt.Value().IsNull() ) + { + myFaceEntry = anIt.Value()->getEntry(); + } + + if (aSelList.Extent() != 1) { + if (myEditCurrentArgument == myLineEdit) + myFace.nullify(); + return; + } + + TopAbs_ShapeEnum aNeedType = TopAbs_FACE ; + GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType ); + TopoDS_Shape aShape; + if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) { + QString aName = GEOMBase::GetName( aSelectedObject.get() ); + myEditCurrentArgument->setText( aName ); + if ( myEditCurrentArgument == myLineEdit ) { + 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 : +//================================================================================= +bool EntityGUI_FeatureDetectorDlg::acceptMouseEvent() const +{ + return myPushButton->isChecked(); +} + +//======================================================================= +// function : ClickOnOk() +// purpose : +//======================================================================= +void EntityGUI_FeatureDetectorDlg::ClickOnOk() +{ + setIsApplyAndClose( true ); + if (onAccept()) + ClickOnCancel(); +} + +//================================================================================= +// function : ClickOnApply() +// purpose : +//================================================================================= +bool EntityGUI_FeatureDetectorDlg::ClickOnApply() +{ + if (!onAccept()) + return false; + +// initName(); + ConstructorsClicked(getConstructorId()); + return true; +} + +//================================================================================= +// function : onConstructorClicked(int) +// purpose : +//================================================================================= +void EntityGUI_FeatureDetectorDlg::ConstructorsClicked(int id) +{ + MESSAGE("Constructor id ="<show(); +// mySelectionGroup->show(); + mySnapshotLabel->setText(tr("GEOM_DETECT_ZONE")); + initName(tr("GEOM_CORNERS")); + break; + case CONTOURS: +// myViewGroup->hide(); +// mySelectionGroup->hide(); +// mySelectionGroup->show(); + mySnapshotLabel->setText(tr("GEOM_COLOR_FILTER")); + initName(tr("GEOM_CONTOURS")); + break; + case LINES: +// myViewGroup->hide(); +// mySelectionGroup->hide(); +// mySelectionGroup->show(); + mySnapshotLabel->setText(tr("")); + initName(tr("GEOM_LINES")); + break; + } +} + +// //================================================================================= +// // function : onViewClicked() +// // purpose : +// //================================================================================= +// void EntityGUI_FeatureDetectorDlg::onViewClicked(int id) +// { +// gp_Pnt aOrigin = gp_Pnt(0, 0, 0); +// gp_Dir aDirZ; +// gp_Dir aDirX; +// +// switch(id) +// { +// case XY: +// aDirZ = gp_Dir(0, 0, 1); +// aDirX = gp_Dir(1, 0, 0); +// break; +// case YZ: +// aDirZ = gp_Dir(1, 0, 0); +// aDirX = gp_Dir(0, 1, 0); +// break; +// case XZ: +// aDirZ = gp_Dir(0, -1, 0); +// aDirX = gp_Dir(1, 0 , 0); +// break; +// } +// +// myWPlane = gp_Ax3(aOrigin, aDirZ, aDirX); +// myGeomGUI->SetWorkingPlane( myWPlane ); +// myGeomGUI->ActiveWorkingPlane(); +// +// } + +//================================================================================= +// function : onButtonToggled() +// purpose : +//================================================================================= +void EntityGUI_FeatureDetectorDlg::onButtonToggled( bool checked) +{ + if (!checked) + { + myStartPnt = QPoint(0,0); + myEndPnt = myStartPnt; + myLineEdit->setEnabled(true); + } + else + { + myLineEdit->setEnabled(false); + } +} + +//================================================================================= +// function : setStartPnt( const QPoint& ) +// purpose : +//================================================================================= +void EntityGUI_FeatureDetectorDlg::setStartPnt(const QPoint& theStartPnt) +{ + myStartPnt = theStartPnt; +} + +//================================================================================= +// function : setEndPnt( const QPoint& ) +// purpose : +//================================================================================= +void EntityGUI_FeatureDetectorDlg::setEndPnt(const QPoint& theEndPnt) +{ + myEndPnt = theEndPnt; +} + +//================================================================================= +// function : createOperation +// purpose : +//================================================================================= +GEOM::GEOM_IOperations_ptr EntityGUI_FeatureDetectorDlg::createOperation() +{ + return myGeomGUI->GetGeomGen()->GetIShapesOperations( getStudyId() ); +} + +//================================================================================= +// function : execute() +// purpose : +//================================================================================= +bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects ) +{ + MESSAGE("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 >::iterator AISit; + SOCC_Viewer* soccViewer = (SOCC_Viewer*)(theViewWindow->getViewManager()->getViewModel()); + + MESSAGE("repere1") + 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; + + QString theImgFileName = QString::fromStdString( myAISShape->TextureFile() ); + + + if ( theImgFileName.isEmpty() ) + return res; + + // Build an instance of detection used to perform image processing operations + ShapeRec_FeatureDetector* aDetector = new ShapeRec_FeatureDetector( theImgFileName ); + + int height = aDetector->GetImgHeight(); + int width = aDetector->GetImgWidth(); + +// NOTE: OLD + int winHeight = vp->height(); + int winWidth = vp->width(); + double x_offset, y_offset; + int i; + +// NOTE: OLD + // 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 * winWidth - x_offset; // X coordinate of the top left corner of the background image in the view + double viewTop = 0.5 * winHeight - y_offset; // Y coordinate of both top corners + + // Set detection rectangle in the background image coordinates system and detect the corners + 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); + + + GEOM::GEOM_IBasicOperations_var aBasicOperations = myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() ); + GEOM::GEOM_IShapesOperations_var aShapesOperations = GEOM::GEOM_IShapesOperations::_narrow( getOperation() ); + if (myConstructorId == CORNERS) + { + if( !aRect.isEmpty() ) + { + aDetector->SetROI( aRect ); + viewLeft = rectLeft; + viewTop = rectTop; + } + aDetector->ComputeCorners(); + CvPoint2D32f* corners = aDetector->GetCorners(); + int cornerCount = aDetector->GetCornerCount(); + + // Build the geom objects associated to the detected corners and returned by execute + if( !aBasicOperations->_is_nil() && !aShapesOperations->_is_nil() ) + { + GEOM::GEOM_Object_var aGeomCorner; + GEOM::ListOfGO_var geomCorners = new GEOM::ListOfGO(); + 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 = -0.5*width + corners[i].x; + double y = 0.5*height - corners[i].y; + double z = 0; + + aGeomCorner = aBasicOperations->MakePointXYZ( x,y,z ); + + geomCorners[i] = aGeomCorner; + } + GEOM::GEOM_Object_var aCompound = aShapesOperations->MakeCompound(geomCorners); + if ( !aCompound->_is_nil() ) + { + // Dark blue color + SALOMEDS::Color aColor; + aColor.R = 0; + aColor.G = 0; + aColor.B = 0.8; + + aCompound->SetColor(aColor); + aCompound->SetMarkerStd(GEOM::MT_POINT,GEOM::MS_30); + objects.push_back( aCompound._retn() ); + res = true; + } + } + } + else if (myConstructorId == CONTOURS) + { + int method = 0 ; //CANNY + if( !aRect.isEmpty() && aRect.width() > 1 ) + { + aDetector->SetROI( aRect ); + method = 1 ; //COLORFILTER + } + + GEOM::GEOM_ICurvesOperations_var aCurveOperations = myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() ); +// GEOM::GEOM_ICurvesOperations::_narrow( getOperation() ); + + aDetector->ComputeContours( method ); + std::vector< std::vector > contours = aDetector->GetContours(); + std::vector hierarchy = aDetector->GetContoursHierarchy(); + + std::vector< cv::Point > contour; + int idx = 0; + + GEOM::ListOfGO_var geomContours = new GEOM::ListOfGO(); + int contourCount = 0; + + bool insert; + + // TEST for debug only +// GEOM::GEOM_Object_var aRemovedPnt; +// GEOM::ListOfGO_var removedPnts = new GEOM::ListOfGO(); +// int r = 0; + + MESSAGE("hierarchy.size() =" << hierarchy.size()) + for( ; idx >= 0; idx = hierarchy[idx][0]) + { +// for(int count=0, child=idx; child>=0, count<1; child=hierarchy[idx][2], count++) +// { +// contour = contours[child]; + contour = contours[idx]; + std::vector< cv::Point >::iterator it; + std::vector< cv::Point >::iterator it_previous; + std::vector< cv::Point >::iterator it_next; + GEOM::GEOM_Object_var aGeomContourPnt; + GEOM::ListOfGO_var geomContourPnts = new GEOM::ListOfGO(); + + geomContourPnts->length( contour.size() ); + + int j = 0; + std::set< std::vector > existing_points; + 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) ); + + pnt_it=existing_points.insert(pnt); + if (pnt_it.second == true || !myCheckBox->isChecked() ) // To avoid double points in the contours + { + insert = true; + if (it!=contour.begin()) // From the second point on perform some checking to avoid loops in the contours we build + { + it_previous = boost::prior(it); + it_next = boost::next(it); + + double u_v_scalar_product = (it->x - it_previous->x) * (it_next->x - it->x) + + (it->y - it_previous->y) * (it_next->y - it->y); + if (u_v_scalar_product < 0) + { + double u_v_det = (it->x - it_previous->x) * (it_next->y - it->y) - + (it->y - it_previous->y) * (it_next->x - it->x); + + double norme_u = sqrt ( (it->x - it_previous->x)*(it->x - it_previous->x) + + (it->y - it_previous->y)*(it->y - it_previous->y) ); + + double norme_v = sqrt ( (it->x - it_next->x)*(it->x - it_next->x) + + (it->y - it_next->y)*(it->y - it_next->y) ); + + double u_v_sinus = u_v_det / (norme_u * norme_v); + + if (fabs(u_v_sinus) < Precision::Confusion()) + { + // TEST for debug only +// if (myCheckBox->isChecked()) +// { +// MESSAGE("correction appliquee : fabs(u_v_sinus) ="<x = "<x) +// MESSAGE("it->y = "<y) +// MESSAGE("it_previous->x = "<x) +// MESSAGE("it_previous->y = "<y) +// MESSAGE("it_next->x = "<x) +// MESSAGE("it_next->y = "<y) +// MESSAGE("norme_u = "< +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include + +//================================================================================= +// class : EntityGUI_PictureImportDlg() +// purpose : Constructs a EntityGUI_PictureImportDlg which is a child of 'parent', with the +// name 'name' and widget flags set to 'f'. +// The dialog will by default be modeless, unless you set 'modal' to +// TRUE to construct a modal dialog. +//================================================================================= +EntityGUI_PictureImportDlg::EntityGUI_PictureImportDlg( GeometryGUI* theGeometryGUI, QWidget* parent, + bool modal, Qt::WindowFlags fl ) + : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ) +{ +// QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_LINE_2P" ) ) ); + setWindowTitle( tr( "GEOM_IMPORT_PICT_TITLE" ) ); + mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PICTURE" ) ); +// mainFrame()->RadioButton1->setIcon( image0 ); +// mainFrame()->RadioButton2->setIcon( image2 ); + + mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose); + mainFrame()->RadioButton2->close(); + mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose); + mainFrame()->RadioButton3->close(); + + QGroupBox* GroupFileSel = new QGroupBox( centralWidget() ); + GroupFileSel->setTitle( tr( "GEOM_FILE" ) ); + QHBoxLayout* myFileSelGrpLayout = new QHBoxLayout(GroupFileSel ); + myPushButton = new QPushButton( GroupFileSel ); + myLineEdit = new QLineEdit( GroupFileSel ); + myPushButton->setText("..."); + + myFileSelGrpLayout->addWidget( myLineEdit, 1); + myFileSelGrpLayout->addWidget( myPushButton, 0); + + QVBoxLayout* layout = new QVBoxLayout( centralWidget() ); + layout->setMargin( 0 ); layout->setSpacing( 6 ); + layout->addWidget( GroupFileSel ); + +// setHelpFileName( "import_picture_page.html" ); + + Init(); +} + + +//================================================================================= +// function : ~EntityGUI_PictureImportDlg() +// purpose : Destroys the object and frees any allocated resources +//================================================================================= +EntityGUI_PictureImportDlg::~EntityGUI_PictureImportDlg() +{ +} + + +//================================================================================= +// function : Init() +// purpose : +//================================================================================= +void EntityGUI_PictureImportDlg::Init() +{ + connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); + connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); + connect( myPushButton, SIGNAL( clicked() ), this, SLOT( FileSelectionClicked() ) ); + + resize(100,100); + + gp_Pnt aOrigin = gp_Pnt(0, 0, 0); + gp_Dir aDirZ = gp_Dir(0, 0, 1); + gp_Dir aDirX = gp_Dir(1, 0, 0); + + gp_Ax3 aGlobalCS = gp_Ax3(aOrigin, aDirZ, aDirX); + + myGeomGUI->SetWorkingPlane( aGlobalCS ); + myGeomGUI->ActiveWorkingPlane(); + + initName( tr( "GEOM_PICTURE" ) ); +} + +// ================================================================================= +// function : FileSelectionClicked() +// purpose : +// ================================================================================= +void EntityGUI_PictureImportDlg::FileSelectionClicked() +{ + QString selFile = QFileDialog::getOpenFileName(this,tr( "SELECT_IMAGE"),"/home", tr("OCC_IMAGE_FILES")); + if ( ! selFile.isEmpty() ) + myLineEdit->setText(selFile); +} + +//================================================================================= +// function : ClickOnOk() +// purpose : +//================================================================================= +void EntityGUI_PictureImportDlg::ClickOnOk() +{ + MESSAGE("EntityGUI_PictureImportDlg::ClickOnOk()") + setIsApplyAndClose( true ); + if ( ClickOnApply() ) + ClickOnCancel(); +} + +//================================================================================= +// function : ClickOnApply() +// purpose : +//================================================================================= +bool EntityGUI_PictureImportDlg::ClickOnApply() +{ + MESSAGE("EntityGUI_PictureImportDlg::ClickOnApply()") + if ( !onAccept() ) + return false; + + initName(); + myLineEdit->setText( "" ); + + return true; +} + +//================================================================================= +// function : createOperation +// purpose : +//================================================================================= +GEOM::GEOM_IOperations_ptr EntityGUI_PictureImportDlg::createOperation() +{ + return myGeomGUI->GetGeomGen()->GetIBlocksOperations( getStudyId() ); +} + +//================================================================================= +// function : execute +// purpose : +//================================================================================= +bool EntityGUI_PictureImportDlg::execute( ObjectList& objects ) +{ + bool res = false; + + GEOM::GEOM_Object_var anObj; + GEOM::GEOM_IBasicOperations_var aBasicOperations = myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() ); + GEOM::GEOM_IBlocksOperations_var aBlocksOperations = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() ); + QString theImgFileName = myLineEdit->text(); + if ( theImgFileName.isEmpty() ) + return res; + + ShapeRec_FeatureDetector* aDetector = new ShapeRec_FeatureDetector( theImgFileName ); + + int height = aDetector->GetImgHeight(); + int width = aDetector->GetImgWidth(); + + + GEOM::GEOM_Object_var P1 = aBasicOperations->MakePointXYZ( -0.5*width, -0.5*height, 0 ); + GEOM::GEOM_Object_var P2 = aBasicOperations->MakePointXYZ( -0.5*width, 0.5*height, 0 ); + GEOM::GEOM_Object_var P3 = aBasicOperations->MakePointXYZ( 0.5*width, 0.5*height, 0 ); + GEOM::GEOM_Object_var P4 = aBasicOperations->MakePointXYZ( 0.5*width, -0.5*height, 0 ); + + GEOM::GEOM_Object_var aFace = aBlocksOperations->MakeQuad4Vertices(P1,P2,P3,P4); + getDisplayer()->SetTexture(theImgFileName.toStdString()); + + if ( !aFace->_is_nil() ) + { + objects.push_back( aFace._retn() ); + } + + res=true; + + + return res; +} + diff --git a/src/EntityGUI/EntityGUI_PictureImportDlg.h b/src/EntityGUI/EntityGUI_PictureImportDlg.h new file mode 100644 index 000000000..74c2c32af --- /dev/null +++ b/src/EntityGUI/EntityGUI_PictureImportDlg.h @@ -0,0 +1,74 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// GEOM GEOMGUI : GUI for Geometry component +// File : EntityGUI_PictureImportDlg.h +// Author : Renaud NEDELEC, Open CASCADE S.A.S. +// +#ifndef BASICGUI_LINEDLG_H +#define BASICGUI_LINEDLG_H + +#include "GEOMBase_Skeleton.h" +#include "GEOM_GenericObjPtr.h" + +class QGroupBox; +//================================================================================= +// class : EntityGUI_PictureImportDlg +// purpose : +//================================================================================= +class EntityGUI_PictureImportDlg : public GEOMBase_Skeleton +{ + Q_OBJECT + +public: + EntityGUI_PictureImportDlg( GeometryGUI*, QWidget* = 0, bool = false, Qt::WindowFlags = 0 ); + ~EntityGUI_PictureImportDlg(); + +protected: +// // redefined from GEOMBase_Helper + virtual GEOM::GEOM_IOperations_ptr createOperation(); +// virtual bool isValid( QString& ); + virtual bool execute( ObjectList& ); +// virtual void addSubshapesToStudy(); + +private: + void Init(); +// void enterEvent( QEvent* ); + +private: + QGroupBox* GroupSelFile; + QPushButton* myPushButton; + QLineEdit* myLineEdit; + +private slots: + void ClickOnOk(); + bool ClickOnApply(); +// +// void ActivateThisDialog(); +// void DeactivateActiveDialog(); + void FileSelectionClicked( ); +// +// void SelectionIntoArgument(); +// void SetEditCurrentArgument(); +}; + +#endif // BASICGUI_LINEDLG_H diff --git a/src/EntityGUI/EntityGUI_SketcherDlg.cxx b/src/EntityGUI/EntityGUI_SketcherDlg.cxx index c2b167b98..27604981e 100644 --- a/src/EntityGUI/EntityGUI_SketcherDlg.cxx +++ b/src/EntityGUI/EntityGUI_SketcherDlg.cxx @@ -28,6 +28,9 @@ #include "EntityGUI_Widgets.h" #include +#include +#include + #include #include #include @@ -1525,6 +1528,10 @@ void EntityGUI_SketcherDlg::OnPointSelected(Qt::KeyboardModifiers modifiers, con { MESSAGE("EntityGUI_SketcherDlg::OnPointSelected") + SUIT_ViewWindow* theViewWindow = getDesktop()->activeWindow(); + OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); + QString theImgFileName = vp->backgroundImageFilename(); + double x, y; x = y = 0; @@ -1542,8 +1549,8 @@ void EntityGUI_SketcherDlg::OnPointSelected(Qt::KeyboardModifiers modifiers, con gp_Pnt aTrsfPnt; GEOMBase::VertexToPoint( aShape, aTrsfPnt ); - autoApply = ( getPnt2ConstructorId() == 1 && false ); // If no additional argument needed after selection - // -> apply automatically --> disabled for now + autoApply = ( (getPnt2ConstructorId() == 1) && (!theImgFileName.isEmpty()) ); // If no additional argument needed after selection and there is a backgroundimage + // -> apply automatically if ( getPnt1ConstructorId() == 0 ){ // Relative selection mode x = aTrsfPnt.X() - myLastX1; diff --git a/src/EntityGUI/Makefile.am b/src/EntityGUI/Makefile.am index e8331a454..a1fbbcb93 100644 --- a/src/EntityGUI/Makefile.am +++ b/src/EntityGUI/Makefile.am @@ -24,6 +24,17 @@ # include $(top_srcdir)/adm_local/unix/make_common_starter.am +if WITH_OPENCV + FeatureDetectorDlg_Header = EntityGUI_FeatureDetectorDlg.h + FeatureDetectorDlg_Sources = EntityGUI_FeatureDetectorDlg.cxx + FeatureDetectorDlg_moc = EntityGUI_FeatureDetectorDlg_moc.cxx + PictureImportDlg_Header = EntityGUI_PictureImportDlg.h + PictureImportDlg_Sources = EntityGUI_PictureImportDlg.cxx + PictureImportDlg_moc = EntityGUI_PictureImportDlg_moc.cxx + Opencv_libs = $(OPENCV_LIBS) + Opencv_includes = $(OPENCV_INCLUDES) +endif + # Libraries targets lib_LTLIBRARIES = libEntityGUI.la @@ -33,20 +44,26 @@ salomeinclude_HEADERS = \ EntityGUI_Widgets.h \ EntityGUI_SketcherDlg.h \ EntityGUI_3DSketcherDlg.h \ - EntityGUI_SubShapeDlg.h + EntityGUI_SubShapeDlg.h \ + $(FeatureDetectorDlg_Header) \ + $(PictureImportDlg_Header) dist_libEntityGUI_la_SOURCES = \ EntityGUI.cxx \ EntityGUI_Widgets.cxx \ EntityGUI_SketcherDlg.cxx \ EntityGUI_3DSketcherDlg.cxx \ - EntityGUI_SubShapeDlg.cxx + EntityGUI_SubShapeDlg.cxx \ + $(FeatureDetectorDlg_Sources) \ + $(PictureImportDlg_Sources) MOC_FILES = \ EntityGUI_Widgets_moc.cxx \ EntityGUI_SketcherDlg_moc.cxx \ EntityGUI_3DSketcherDlg_moc.cxx \ - EntityGUI_SubShapeDlg_moc.cxx + EntityGUI_SubShapeDlg_moc.cxx \ + $(FeatureDetectorDlg_moc) \ + $(PictureImportDlg_moc) nodist_libEntityGUI_la_SOURCES = \ $(MOC_FILES) @@ -80,6 +97,7 @@ libEntityGUI_la_CPPFLAGS = \ $(GUI_CXXFLAGS) \ $(CORBA_CXXFLAGS) \ $(CORBA_INCLUDES) \ + $(Opencv_includes) \ -I$(srcdir)/../GEOMGUI \ -I$(srcdir)/../DlgRef \ -I$(srcdir)/../GEOMBase \ @@ -88,6 +106,8 @@ libEntityGUI_la_CPPFLAGS = \ -I$(srcdir)/../GEOMImpl \ -I$(srcdir)/../GEOMFiltersSelection \ -I$(srcdir)/../SKETCHER \ + -I$(srcdir)/../ShapeRecognition \ + -I$(srcdir)/../GEOM \ -I$(top_builddir)/src/DlgRef \ -I$(top_builddir)/idl @@ -96,6 +116,7 @@ libEntityGUI_la_LDFLAGS = \ ../GEOMBase/libGEOMBase.la \ ../SKETCHER/libGEOMSketcher.la \ ../GEOMGUI/libGEOM.la \ + ../ShapeRecognition/libGEOMShapeRec.la \ $(QT_MT_LIBS) \ - $(CAS_TKTopAlgo) -lTKernel - + $(CAS_TKTopAlgo) -lTKernel \ + $(Opencv_libs) diff --git a/src/GEOMBase/GEOMBase_Helper.cxx b/src/GEOMBase/GEOMBase_Helper.cxx index d62615d87..71355da4d 100755 --- a/src/GEOMBase/GEOMBase_Helper.cxx +++ b/src/GEOMBase/GEOMBase_Helper.cxx @@ -142,8 +142,10 @@ void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateVi { // Unset color of shape ( this color may be set during preview displaying ) // Default color will be used - getDisplayer()->UnsetColor(); +// getDisplayer()->UnsetColor(); getDisplayer()->UnsetWidth(); + + MESSAGE("GEOMBase_Helper::display myTexture = "<GetTexture()) // Enable activisation of selection getDisplayer()->SetToActivate( true ); @@ -359,7 +361,7 @@ void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs, if ( myViewWindow == 0 ) return; - + // Display prs SUIT_ViewManager* aViewManager = myViewWindow->getViewManager(); if ( aViewManager->getType() == OCCViewer_Viewer::Type() || @@ -700,7 +702,10 @@ bool GEOMBase_Helper::openCommand() { bool res = false; if ( !getStudy() || hasCommand() ) + { + MESSAGE("Getting out from openCommand()") return res; + } GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() ); if ( !anOp->_is_nil() ) { @@ -708,6 +713,10 @@ bool GEOMBase_Helper::openCommand() myCommand->start(); res = true; } + else + { + MESSAGE("anOp->_is_nil() = true") + } return res; } @@ -750,6 +759,8 @@ bool GEOMBase_Helper::commitCommand( const char* ) //================================================================ bool GEOMBase_Helper::hasCommand() const { + bool res = (bool) myCommand; + MESSAGE("hasCommand = "<( SUIT_Session::session()->activeApplication()->activeStudy() ); - if ( !appStudy ) return false; + if ( !appStudy ) + { + MESSAGE("appStudy is empty") + return false; + } _PTR(Study) aStudy = appStudy->studyDS(); bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked(); @@ -889,10 +904,12 @@ bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction ) catch( const SALOME::SALOME_Exception& e ) { SalomeApp_Tools::QtCatchCorbaException( e ); abortCommand(); + MESSAGE("Exception catched") } updateViewer(); + MESSAGE("result ="< #include #include +#include #include #include #include @@ -87,6 +88,8 @@ #include #include +#include + #include // VTK Includes @@ -314,6 +317,7 @@ GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st ) myColor = -1; // This color is used for shape displaying. If it is equal -1 then // default color is used. + myTexture = ""; myWidth = -1; myType = -1; @@ -661,6 +665,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) } else useObjColor = true; }else { + MESSAGE("myDisplayMode = "<< myDisplayMode) AISShape->SetDisplayMode( myDisplayMode ); AISShape->SetShadingColor( myShadingColor ); } @@ -735,6 +740,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) } } } + else { if ( onlyVertex ) @@ -822,6 +828,14 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) } } + if ( HasTexture() ) + { + AISShape->SetTextureFileName(TCollection_AsciiString(myTexture.c_str())); + AISShape->SetTextureMapOn(); + AISShape->DisableTextureModulate(); + AISShape->SetDisplayMode(3); + } + if ( HasWidth() ) AISShape->SetWidth( GetWidth() ); @@ -1531,6 +1545,31 @@ void GEOM_Displayer::UnsetColor() myShadingColor = SalomeApp_Tools::color( col ); } +//================================================================= +/*! + * GEOM_Displayer::SetTexture + * Set color for shape displaying. If it is equal -1 then default color is used. + * Available values are from Quantity_NameOfColor enumeration + */ +//================================================================= +void GEOM_Displayer::SetTexture( const std::string& texureFileName ) +{ + if(texureFileName!="") + { + myTexture = texureFileName; + } +} + +bool GEOM_Displayer::HasTexture() const +{ + return myTexture != ""; +} + +std::string GEOM_Displayer::GetTexture() const +{ + return myTexture; +} + //================================================================= /*! * GEOM_Displayer::SetWidth diff --git a/src/GEOMGUI/GEOM_Displayer.h b/src/GEOMGUI/GEOM_Displayer.h index 70f5342a1..30337eaac 100644 --- a/src/GEOMGUI/GEOM_Displayer.h +++ b/src/GEOMGUI/GEOM_Displayer.h @@ -123,6 +123,11 @@ public: void UnsetColor(); int GetColor () const; bool HasColor () const; + + /* Set texture for shape displaying. */ + void SetTexture ( const std::string& ); + bool HasTexture () const; + std::string GetTexture () const; /* Set width for shape displaying. If it is equal -1 then default width is used. */ void SetWidth ( const double ); @@ -202,6 +207,7 @@ protected: Handle(SALOME_InteractiveObject) myIO; TopoDS_Shape myShape; std::string myName; + std::string myTexture; int myType; SALOME_View* myViewFrame; diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index f3c0edbbb..a060413a9 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -2181,6 +2181,14 @@ Please, select face, shell or solid and try again MEN_BUILD Build + + MEN_FEATURE_DETECTION + Feature detection + + + MEN_PICTURE_IMPORT + Import picture in viewer + MEN_CHAMFER Chamfer @@ -3156,11 +3164,11 @@ Please, select face, shell or solid and try again STB_POP_UNPUBLISH_OBJ Unpublish object - + STB_POP_PUBLISH_OBJ Publish object - + STB_POP_HIDE_CHILDREN Hide child objects @@ -3704,7 +3712,7 @@ Please, select face, shell or solid and try again TOP_POP_PUBLISH_OBJ Publish object - + TOP_POP_HIDE_CHILDREN Hide Children @@ -4345,7 +4353,7 @@ Otherwise the dimensions will be kept without modifications. GEOM_CURVE_ANALITICAL Analytical - + BasicGUI_ParamCurveWidget @@ -4372,7 +4380,7 @@ Otherwise the dimensions will be kept without modifications. GEOM_PCURVE_MAX Max t - + GEOM_PCURVE_STEP Step @@ -4552,6 +4560,76 @@ Otherwise the dimensions will be kept without modifications. Number of sketch points too small + + EntityGUI_FeatureDetectorDlg + + GEOM_DETECT_TITLE + Feature Detection + + + GEOM_SCALING + Scaling + + + GEOM_PNT1 + Top left corner + + + GEOM_PNT2 + Top right corner + + + GEOM_CORNER + Detected_corners + + + GEOM_CORNERS + Corners + + + GEOM_CONTOURS + Contours + + + GEOM_FEATURES + Features + + + GEOM_DETECT_ZONE + Select a detection zone (default is whole picture) + + + GEOM_COLOR_FILTER + Select the color of the zone you want to find the frontier of + + + GEOM_VIEW + View + + + GEOM_FRONT + Front (Y-Z) + + + GEOM_TOP + Top (X-Y) + + + GEOM_LEFT + Left (X-Z) + + + + EntityGUI_PictureImportDlg + + GEOM_PICTURE + Picture + + + GEOM_IMPORT_PICT_TITLE + Import picture in viewer + + EntityGUI_SubShapeDlg @@ -4963,12 +5041,12 @@ Would you like to continue? Publish Objects - OBJECT_NAME - Name + OBJECT_NAME + Name - OBJECT_ENTRY - Entry + OBJECT_ENTRY + Entry UNSELECT_ALL diff --git a/src/GEOMGUI/GEOM_msg_fr.ts b/src/GEOMGUI/GEOM_msg_fr.ts index 594d1ead8..efe2dd7e5 100644 --- a/src/GEOMGUI/GEOM_msg_fr.ts +++ b/src/GEOMGUI/GEOM_msg_fr.ts @@ -2181,6 +2181,10 @@ Choisissez une face, une coque ou un solide et essayez de nouveau MEN_BUILD Construire + + MEN_CORNER_DETECTION + Détecter les angles (image ou plan) + MEN_CHAMFER Chanfrein @@ -4552,6 +4556,33 @@ le paramètre '%1' aux préférences du module Géométrie. + + EntityGUI_CornerDetectionDlg + + GEOM_DETECT_TITLE + Détecter les angles + + + GEOM_SCALING + Mise à l'échelle + + + GEOM_PNT1 + Coin supérieur gauche + + + GEOM_PNT2 + Coin supérieur droit + + + GEOM_CORNER + Angles_détectés + + + GEOM_CORNERS + Angles + + EntityGUI_SubShapeDlg diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index 5d138bbf7..d15bec532 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -281,8 +281,7 @@ void GeometryGUI::ActiveWorkingPlane() view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z()); view3d->SetUp(DY.X(), DY.Y(), DY.Z()); - - vw->onViewFitAll(); + vw->onViewFitAll(); } } else if( ViewVTK ) { @@ -404,6 +403,7 @@ void GeometryGUI::OnGUIEvent( int id ) case GEOMOp::OpCheckGeom: // MENU TOOLS - CHECK GEOMETRY case GEOMOp::OpDeflection: // POPUP MENU - DEFLECTION COEFFICIENT case GEOMOp::OpColor: // POPUP MENU - COLOR + case GEOMOp::OpSetTexture: // POPUP MENU - SETTEXTURE case GEOMOp::OpTransparency: // POPUP MENU - TRANSPARENCY case GEOMOp::OpIncrTransparency: // SHORTCUT - INCREASE TRANSPARENCY case GEOMOp::OpDecrTransparency: // SHORTCUT - DECREASE TRANSPARENCY @@ -428,6 +428,7 @@ void GeometryGUI::OnGUIEvent( int id ) case GEOMOp::OpSwitchVectors: // MENU VIEW - VECTOR MODE case GEOMOp::OpWireframe: // POPUP MENU - WIREFRAME case GEOMOp::OpShading: // POPUP MENU - SHADING + case GEOMOp::OpTexture: // POPUP MENU - TEXTURE case GEOMOp::OpVectors: // POPUP MENU - VECTORS libName = "DisplayGUI"; break; @@ -460,6 +461,10 @@ void GeometryGUI::OnGUIEvent( int id ) case GEOMOp::Op2dSketcher: // MENU ENTITY - SKETCHER case GEOMOp::Op3dSketcher: // MENU ENTITY - 3D SKETCHER case GEOMOp::OpExplode: // MENU ENTITY - EXPLODE +#ifdef WITH_OPENCV + case GEOMOp::OpFeatureDetect: // MENU ENTITY - FEATURE DETECTION + case GEOMOp::OpPictureImport: // MENU ENTITY - IMPORT PICTURE IN VIEWER +#endif libName = "EntityGUI"; break; case GEOMOp::OpEdge: // MENU BUILD - EDGE @@ -707,6 +712,10 @@ void GeometryGUI::initialize( CAM_Application* app ) createGeomAction( GEOMOp::Op2dSketcher, "SKETCH" ); createGeomAction( GEOMOp::Op3dSketcher, "3DSKETCH" ); createGeomAction( GEOMOp::OpExplode, "EXPLODE" ); +#ifdef WITH_OPENCV + createGeomAction( GEOMOp::OpFeatureDetect,"FEATURE_DETECTION" ); + createGeomAction( GEOMOp::OpPictureImport,"PICTURE_IMPORT" ); +#endif createGeomAction( GEOMOp::OpEdge, "EDGE" ); createGeomAction( GEOMOp::OpWire, "WIRE" ); @@ -795,9 +804,11 @@ void GeometryGUI::initialize( CAM_Application* app ) createGeomAction( GEOMOp::OpWireframe, "POP_WIREFRAME", "", 0, true ); createGeomAction( GEOMOp::OpShading, "POP_SHADING", "", 0, true ); + createGeomAction( GEOMOp::OpTexture, "POP_TEXTURE", "", 0, true ); createGeomAction( GEOMOp::OpVectors, "POP_VECTORS", "", 0, true ); createGeomAction( GEOMOp::OpDeflection, "POP_DEFLECTION" ); createGeomAction( GEOMOp::OpColor, "POP_COLOR" ); + createGeomAction( GEOMOp::OpSetTexture, "POP_SETTEXTURE" ); createGeomAction( GEOMOp::OpTransparency, "POP_TRANSPARENCY" ); createGeomAction( GEOMOp::OpIsos, "POP_ISOS" ); createGeomAction( GEOMOp::OpAutoColor, "POP_AUTO_COLOR" ); @@ -900,6 +911,13 @@ void GeometryGUI::initialize( CAM_Application* app ) createMenu( GEOMOp::OpShell, buildId, -1 ); createMenu( GEOMOp::OpSolid, buildId, -1 ); createMenu( GEOMOp::OpCompound, buildId, -1 ); + + createMenu( separator(), newEntId, -1 ); + +#ifdef WITH_OPENCV + createMenu( GEOMOp::OpFeatureDetect, newEntId, -1 ); + createMenu( GEOMOp::OpPictureImport, newEntId, -1 ); +#endif int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 ); @@ -1065,6 +1083,11 @@ void GeometryGUI::initialize( CAM_Application* app ) createTool( separator(), operTbId ); createTool( GEOMOp::OpExplode, operTbId ); createTool( separator(), operTbId ); +#ifdef WITH_OPENCV + createTool( GEOMOp::OpFeatureDetect, operTbId ); + createTool( GEOMOp::OpPictureImport, operTbId ); + createTool( separator(), operTbId ); +#endif createTool( GEOMOp::OpPartition, operTbId ); createTool( GEOMOp::OpArchimede, operTbId ); createTool( GEOMOp::OpShapesOnShape, operTbId ); @@ -1109,10 +1132,14 @@ void GeometryGUI::initialize( CAM_Application* app ) // ---- create popup menus -------------------------- QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')"; + QString clientOCC = "(client='OCCViewer')"; QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible"; + QString clientOCC_AndSomeVisible = clientOCC + " and selcount>0 and isVisible"; + QString clientOCCorOB = "(client='ObjectBrowser' or client='OCCViewer')"; QString clientOCCorVTKorOB = "(client='ObjectBrowser' or client='OCCViewer' or client='VTKViewer')"; QString clientOCCorVTKorOB_AndSomeVisible = clientOCCorVTKorOB + " and selcount>0 and isVisible"; + QString clientOCCorOB_AndSomeVisible = clientOCCorOB + " and selcount>0 and isVisible"; QString autoColorPrefix = "(client='ObjectBrowser' or client='OCCViewer') and type='Shape' and selcount=1 and isOCC=true"; @@ -1138,6 +1165,9 @@ void GeometryGUI::initialize( CAM_Application* app ) mgr->insert( action( GEOMOp::OpShading ), dispmodeId, -1 ); // shading mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule ); mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK + " and displaymode='Shading'", QtxPopupMgr::ToggleRule ); + mgr->insert( action( GEOMOp::OpTexture ), dispmodeId, -1 ); // wireframe + mgr->setRule( action( GEOMOp::OpTexture ), clientOCC_AndSomeVisible, QtxPopupMgr::VisibleRule ); + mgr->setRule( action( GEOMOp::OpTexture), clientOCC + " and displaymode='Texture'", QtxPopupMgr::ToggleRule ); mgr->insert( separator(), dispmodeId, -1 ); mgr->insert( action( GEOMOp::OpVectors ), dispmodeId, -1 ); // vectors mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule ); @@ -1154,6 +1184,8 @@ void GeometryGUI::initialize( CAM_Application* app ) mgr->insert( action( GEOMOp::OpPointMarker ), -1, -1 ); // point marker //mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and $typeid in {%1}" ).arg(GEOM_POINT ), QtxPopupMgr::VisibleRule ); mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and ( $typeid in {%1} or compoundOfVertices=true ) " ).arg(GEOM::VERTEX).arg(GEOM::COMPOUND), QtxPopupMgr::VisibleRule ); + mgr->insert( action( GEOMOp::OpSetTexture ), -1, -1 ); // texture + mgr->setRule( action( GEOMOp::OpSetTexture ), clientOCCorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule ); mgr->insert( separator(), -1, -1 ); // ----------- mgr->insert( action( GEOMOp::OpAutoColor ), -1, -1 ); // auto color mgr->setRule( action( GEOMOp::OpAutoColor ), autoColorPrefix + " and isAutoColor=false", QtxPopupMgr::VisibleRule ); diff --git a/src/GEOMGUI/GeometryGUI_Operations.h b/src/GEOMGUI/GeometryGUI_Operations.h index 73b68f2f2..eb21885c6 100644 --- a/src/GEOMGUI/GeometryGUI_Operations.h +++ b/src/GEOMGUI/GeometryGUI_Operations.h @@ -48,6 +48,7 @@ namespace GEOMOp { OpAutoColor = 1208, // POPUP MENU - AUTO COLOR OpNoAutoColor = 1209, // POPUP MENU - DISABLE AUTO COLOR OpPointMarker = 1210, // POPUP MENU - POINT MARKER + OpSetTexture = 1211, // POPUP MENU - SETTEXTURE OpShowChildren = 1250, // POPUP MENU - SHOW CHILDREN OpHideChildren = 1251, // POPUP MENU - HIDE CHILDREN OpUnpublishObject = 1253, // POPUP MENU - UNPUBLISH @@ -64,6 +65,7 @@ namespace GEOMOp { OpWireframe = 2200, // POPUP MENU - DISPLAY MODE - WIREFRAME OpShading = 2201, // POPUP MENU - DISPLAY MODE - SHADING OpVectors = 2202, // POPUP MENU - DISPLAY MODE - SHOW EDGE DIRECTION + OpTexture = 2203, // POPUP MENU - DISPLAY MODE - TEXTURE // BasicGUI ------------------//-------------------------------- OpPoint = 3000, // MENU NEW ENTITY - BASIC - POINT OpLine = 3001, // MENU NEW ENTITY - BASIC - LINE @@ -92,6 +94,10 @@ namespace GEOMOp { Op2dSketcher = 3300, // MENU NEW ENTITY - SKETCHER Op3dSketcher = 3301, // MENU NEW ENTITY - 3D SKETCHER OpExplode = 3302, // MENU NEW ENTITY - EXPLODE +#ifdef WITH_OPENCV + OpFeatureDetect = 3303, // MENU NEW ENTITY - FEATURE DETECTION + OpPictureImport = 3304, // MENU NEW ENTITY - IMPORT PICTURE IN VIEWER +#endif // BuildGUI ------------------//-------------------------------- OpEdge = 3400, // MENU NEW ENTITY - BUILD - EDGE OpWire = 3401, // MENU NEW ENTITY - BUILD - WIRE diff --git a/src/GEOMGUI/Makefile.am b/src/GEOMGUI/Makefile.am index d65f42496..bfd12147f 100644 --- a/src/GEOMGUI/Makefile.am +++ b/src/GEOMGUI/Makefile.am @@ -71,11 +71,12 @@ libGEOM_la_CPPFLAGS = \ $(GUI_CXXFLAGS) \ $(CORBA_CXXFLAGS) \ $(CORBA_INCLUDES) \ + $(OPENCV_INCLUDES) \ -I$(srcdir)/../OBJECT \ -I$(srcdir)/../GEOMFiltersSelection \ -I$(srcdir)/../GEOMClient \ -I$(srcdir)/../GEOMImpl \ - -I$(top_builddir)/idl \ + -I$(top_builddir)/idl \ -I$(top_builddir) libGEOM_la_LDFLAGS = \ @@ -84,7 +85,9 @@ libGEOM_la_LDFLAGS = \ ../GEOMClient/libGEOMClient.la \ ../OBJECT/libGEOMObject.la \ $(KERNEL_LDFLAGS) -lSalomeLifeCycleCORBA -lSalomeNS -lSalomeDSClient \ - $(GUI_LDFLAGS) -lOCCViewer -lVTKViewer -lCAM -lSOCC -lSVTK -lEvent -lSalomePrs -lstd + $(GUI_LDFLAGS) -lOCCViewer -lVTKViewer -lCAM -lSOCC -lSVTK -lEvent -lSalomePrs -lstd \ + $(OPENCV_LIBS) + # -lSalomeApp # -lToolsGUI # $(CORBA_LIBS) \ diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.cxx b/src/GEOMToolsGUI/GEOMToolsGUI.cxx index 008d71b86..cc95e6831 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI.cxx @@ -328,6 +328,9 @@ bool GEOMToolsGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent) case GEOMOp::OpColor: // POPUP - COLOR OnColor(); break; + case GEOMOp::OpSetTexture: // POPUP - TEXTURE + OnTexture(); + break; case GEOMOp::OpTransparency: // POPUP - TRANSPARENCY OnTransparency(); break; diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.h b/src/GEOMToolsGUI/GEOMToolsGUI.h index bb20a9687..12cead468 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.h +++ b/src/GEOMToolsGUI/GEOMToolsGUI.h @@ -66,6 +66,7 @@ private: void OnAutoColor(); void OnDisableAutoColor(); void OnColor(); + void OnTexture(); void OnTransparency(); void OnNbIsos( ActionType actionType = SHOWDLG ); void OnDeflection(); diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx index f9d1c20b0..cb3497dd1 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx @@ -33,6 +33,7 @@ #include "GEOMToolsGUI_PublishDlg.h" #include +#include #include #include @@ -86,6 +87,7 @@ // QT Includes #include #include +#include #include #include @@ -370,6 +372,49 @@ void GEOMToolsGUI::OnColor() app->updateActions(); //SRN: To update a Save button in the toolbar } +void GEOMToolsGUI::OnTexture() +{ + SALOME_ListIO selected; + SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); + SalomeApp_Study* appStudy = dynamic_cast( app->activeStudy() ); + if ( app && appStudy ) { + LightApp_SelectionMgr* aSelMgr = app->selectionMgr(); + if ( aSelMgr ) { + aSelMgr->selectedObjects( selected ); + if ( !selected.IsEmpty() ) { + SUIT_ViewWindow* window = app->desktop()->activeWindow(); + bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() ); + int mgrId = window->getViewManager()->getGlobalId(); + if ( isOCC ) { + QString aTexture = QFileDialog::getOpenFileName(window,tr( "SELECT_IMAGE"),QString("/home"), tr("OCC_IMAGE_FILES")); + if( !aTexture.isEmpty() ) + { + SUIT_OverrideCursor(); + OCCViewer_Viewer* vm = dynamic_cast ( window->getViewManager()->getViewModel() ); + Handle (AIS_InteractiveContext) ic = vm->getAISContext(); + Handle(AIS_InteractiveObject) io ; + for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) { + io = GEOMBase::GetAIS( It.Value(), true ); + if ( !io.IsNull() ) { + if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) ) + Handle(GEOM_AISShape)::DownCast( io )->SetTextureFileName(TCollection_AsciiString(aTexture.toStdString().c_str())); + + io->Redisplay( Standard_True ); + } + } // for + ic->UpdateCurrentViewer(); + GeometryGUI::Modified(); + GeometryGUI* myGeomGUI = getGeometryGUI(); + myGeomGUI->OnGUIEvent(GEOMOp::OpTexture); + } // if ( !selFile.isEmpty() ) + } // if ( isOCC ) + } // if ( selection not empty ) + } + } + + app->updateActions(); //SRN: To update a Save button in the toolbar +} + void GEOMToolsGUI::OnTransparency() { GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() ); diff --git a/src/Makefile.am b/src/Makefile.am index b160442bd..61851d56e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,11 +21,16 @@ # Author : Alexander BORODIN, Open CASCADE S.A.S. (alexander.borodin@opencascade.com) # Package : src (source files directory) # + SUBDIRS = ARCHIMEDE NMTDS NMTTools GEOMAlgo SKETCHER OCC2VTK GEOM \ BREPExport BREPImport IGESExport IGESImport STEPExport \ STEPImport STLExport VTKExport ShHealOper GEOMImpl GEOM_I \ GEOMClient GEOM_I_Superv GEOM_SWIG GEOM_PY +if WITH_OPENCV + SUBDIRS += ShapeRecognition +endif + if GEOM_ENABLE_GUI SUBDIRS += OBJECT DlgRef GEOMFiltersSelection GEOMGUI GEOMBase GEOMToolsGUI \ DisplayGUI BasicGUI PrimitiveGUI GenerationGUI EntityGUI BuildGUI \ diff --git a/src/OBJECT/GEOM_AISShape.cxx b/src/OBJECT/GEOM_AISShape.cxx index af0be3e5e..f50b29ed0 100644 --- a/src/OBJECT/GEOM_AISShape.cxx +++ b/src/OBJECT/GEOM_AISShape.cxx @@ -168,15 +168,15 @@ void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresent { if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //pas de prise en compte lors du FITALL - StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode; - - switch (d) { - case StdSelect_DM_Wireframe: +// StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode; + std::cout<<"aMode = "<ShadingAspect()->Aspect()->SetDistinguishOn(); @@ -207,6 +207,11 @@ void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresent AIS_Shape::Compute(aPresentationManager, aPrs, aMode); break; } + case 3: //StdSelect_DM_HLR: + { + AIS_TexturedShape::Compute(aPresentationManager, aPrs, aMode); + break; + } } if (isShowVectors()) diff --git a/src/OperationGUI/Makefile.am b/src/OperationGUI/Makefile.am index 324616632..e5f3a27d8 100644 --- a/src/OperationGUI/Makefile.am +++ b/src/OperationGUI/Makefile.am @@ -73,6 +73,7 @@ libOperationGUI_la_CPPFLAGS = \ $(GUI_CXXFLAGS) \ $(CORBA_CXXFLAGS) \ $(CORBA_INCLUDES) \ + $(OPENCV_INCLUDES) \ -I$(srcdir)/../GEOMGUI \ -I$(srcdir)/../DlgRef \ -I$(srcdir)/../GEOMBase \ @@ -83,10 +84,11 @@ libOperationGUI_la_CPPFLAGS = \ -I$(top_builddir)/src/DlgRef \ -I$(top_builddir)/idl + libOperationGUI_la_LDFLAGS = \ ../GEOMBase/libGEOMBase.la \ - $(CAS_LDPATH) -lTKFillet - + $(CAS_LDPATH) -lTKFillet \ + $(OPENCV_LIBS) ############################### # Obsolete files ? ############################### diff --git a/src/ShapeRecognition/Makefile.am b/src/ShapeRecognition/Makefile.am new file mode 100644 index 000000000..214987055 --- /dev/null +++ b/src/ShapeRecognition/Makefile.am @@ -0,0 +1,50 @@ +# Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +# GEOM ShapeRecognition : tools for the shape recognition +# File : Makefile.am +# Author : Renaud NEDELEC (OCC) +# Module : GEOM +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +# header files +salomeinclude_HEADERS = \ + ShapeRec_FeatureDetector.hxx + +# Libraries targets +lib_LTLIBRARIES = libGEOMShapeRec.la + +dist_libGEOMShapeRec_la_SOURCES = \ + ShapeRec_FeatureDetector.cxx + +# additional information to compile and link file + +libGEOMShapeRec_la_CPPFLAGS = \ + $(KERNEL_CXXFLAGS)\ + $(OPENCV_INCLUDES)\ + $(QT_INCLUDES) + + +libGEOMShapeRec_la_LDFLAGS = \ + $(KERNEL_LDFLAGS) -lSALOMELocalTrace \ + $(STDLIB) \ + $(OPENCV_LIBS) \ + $(QT_MT_LIBS) diff --git a/src/ShapeRecognition/ShapeRec_FeatureDetector.cxx b/src/ShapeRecognition/ShapeRec_FeatureDetector.cxx new file mode 100644 index 000000000..ca6caa10d --- /dev/null +++ b/src/ShapeRecognition/ShapeRec_FeatureDetector.cxx @@ -0,0 +1,264 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +// File : ShapeRec_FeatureDetector.cxx +// Author : Renaud NEDELEC, Open CASCADE S.A.S. + +#include "ShapeRec_FeatureDetector.hxx" +#include +#include "utilities.h" + +using namespace cv; + +//TODO : All the following methods but ComputeContours use the C API of OpenCV while ComputContours +// uses the C++ API of the library. +// This should be homogenized and preferably by using the C++ API (which is more recent for all the methods + +// The code has to be "cleaned up" too + +/*! + Constructor + \param theFilename - image to process +*/ +ShapeRec_FeatureDetector::ShapeRec_FeatureDetector(const QString& theFilename): + corners() +{ + cornerCount = 2000; + rect=cvRect(0,0,0,0); + imagePath = theFilename.toStdString(); + // Store the dimensions of the picture + IplImage* bg_img = cvLoadImage (imagePath.c_str(), CV_LOAD_IMAGE_GRAYSCALE); + imgHeight = bg_img->height; + imgWidth = bg_img->width; +} + +/*! + Computes the corners of the image located at imagePath +*/ +void ShapeRec_FeatureDetector::ComputeCorners(){ + + // Parameters for the corner detection + double qualityLevel = 0.2; + double minDistance = 1; + + // Images to be used for detection + IplImage *eig_img, *temp_img, *src_img_gray; + + // Load image + src_img_gray = cvLoadImage (imagePath.c_str(), CV_LOAD_IMAGE_GRAYSCALE); + + if ( rect.width > 1 ) + { + // If a ROI as been set use it for detection + cvSetImageROI( src_img_gray, rect ); + } + + eig_img = cvCreateImage (cvGetSize (src_img_gray), IPL_DEPTH_32F, 1); + temp_img = cvCreateImage (cvGetSize (src_img_gray), IPL_DEPTH_32F, 1); + corners = (CvPoint2D32f *) cvAlloc (cornerCount * sizeof (CvPoint2D32f)); + + // image height and width + imgHeight = src_img_gray->height; + imgWidth = src_img_gray->width; + + // Corner detection using cvCornerMinEigenVal + // (one of the methods available inOpenCV, there is also a cvConerHarris method that can be used by setting a flag in cvGoodFeaturesToTrack) + cvGoodFeaturesToTrack (src_img_gray, eig_img, temp_img, corners, &cornerCount, /*quality-level=*/qualityLevel, /*min-distance=*/minDistance); + cvFindCornerSubPix (src_img_gray, corners, cornerCount, + cvSize (3, 3), cvSize (-1, -1), cvTermCriteria (CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03)); + + cvReleaseImage (&eig_img); + cvReleaseImage (&temp_img); + cvReleaseImage (&src_img_gray); + +} + +/*! + Computes the contours of the image located at imagePath +*/ +bool ShapeRec_FeatureDetector::ComputeContours( int detection_method ){ + + // Initialising images + Mat src, src_gray; + Mat detected_edges; + + // Read image + src = imread( imagePath.c_str() ); + if( !src.data ) + return false; + + if ( detection_method == CANNY ) // The problem is that with that filter the detector detects double contours + { + // Thresholds for Canny detector + int lowThreshold = 100; + int ratio = 3; + int kernel_size = 3; // 3,5 or 7 + + // Convert the image to grayscale + if (src.channels() == 3) + cvtColor( src, src_gray, CV_BGR2GRAY ); + else if (src.channels() == 1) + src_gray = src; + + // Reduce noise with a kernel 3x3 + blur( src_gray, detected_edges, Size(3,3) ); + // Canny detector + Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size, /*L2gradient =*/true ); + } + else if ( detection_method == COLORFILTER ) + { + if ( !rect.width > 1 ) + return false; + detected_edges = _colorFiltering(); + } + else if ( detection_method == RIDGE_DETECTOR ) // Method adapted for engineering drawings (e.g. watershed functionnality could be used here cf.OpenCV documentation and samples) + { + // TODO + return false; + } + _detectAndRetrieveContours( detected_edges ); + + return true; + +} + +/*! + Computes the lines in the image located at imagePath +*/ +bool ShapeRec_FeatureDetector::ComputeLines(){ + MESSAGE("ShapeRec_FeatureDetector::ComputeLines()") + // Initialising images + Mat src, src_gray, detected_edges, dst; + + src=imread(imagePath.c_str(), 0); + + Canny( src, dst, 50, 200, 3 ); + HoughLinesP( dst, lines, 1, CV_PI/180, 80, 30, 10 ); + return true; + +} + +/*! + Stores a region of interest given by user in rect + \param theRect - Region Of Interest of the image located at imagePath +*/ +void ShapeRec_FeatureDetector::SetROI( const QRect& theRect ) +{ + if (!theRect.isEmpty()){ + rect = cvRect(theRect.x(),theRect.y(),theRect.width(),theRect.height()); + } +} + +/*! + Performs contours detection and store them in contours + \param src - src image to find contours of +*/ +void ShapeRec_FeatureDetector::_detectAndRetrieveContours( Mat src ) +{ + src = src > 1; + int method = CV_CHAIN_APPROX_NONE; + findContours( src, contours, hierarchy,CV_RETR_CCOMP, method); + // Other possible approximations CV_CHAIN_APPROX_TC89_KCOS, CV_CHAIN_APPROX_TC89_L1, CV_CHAIN_APPROX_SIMPLE cf. OpenCV documentation + // for precise information +} + +/*! + Performs color filtering from the image sample contained in the ROI rect of the image + located at imagePath + Thresholds the result in order ot obtain a binary image + \return binary image resulting from filtering and thersholding +*/ +Mat ShapeRec_FeatureDetector::_colorFiltering() +{ + IplImage* find_image = cvLoadImage(imagePath.c_str(),CV_LOAD_IMAGE_COLOR); + // Reduce noise with a kernel 3x3 + cvSmooth( find_image, find_image, CV_GAUSSIAN, 3, 3 ); + + if ( !rect.width > 1 ) + return Mat(find_image); + + // Crop the image to build an histogram from the selected part + cvSetImageROI(find_image, rect); + IplImage* test_image = cvCreateImage(cvGetSize(find_image), + find_image->depth, + find_image->nChannels); + cvCopy(find_image, test_image, NULL); + cvResetImageROI(find_image); + + IplImage* test_hsv = cvCreateImage(cvGetSize(test_image),8,3); + IplImage* test_hue = cvCreateImage(cvGetSize(test_image),8,1); + CvHistogram* hist; + + cvCvtColor(test_image, test_hsv, CV_BGR2HSV); + cvCvtPixToPlane(test_hsv, test_hue, 0, 0, 0); + + //create hist + int size_hist = 10; + float hranges[] = {0, 180}; + float* ranges = hranges; + hist = cvCreateHist(1, &size_hist, CV_HIST_ARRAY, &ranges, 1); + + //calculate hue` histogram + cvCalcHist(&test_hue, hist, 0 ,0); + +// // TEST print of the histogram for debugging +// IplImage* hist_image = cvCreateImage(cvSize(320,300),8,3); +// +// //draw hist on hist_test image. +// cvZero(hist_image); +// float max_value = 0; +// cvGetMinMaxHistValue(hist, 0 , &max_value, 0, 0); +// int bin_w = hist_image->width/size_hist; +// for(int i = 0; i < size_hist; i++ ) +// { +// //prevent overflow +// int val = cvRound( cvGetReal1D(hist->bins,i)*hist_image-> +// height/max_value); +// CvScalar color = CV_RGB(200,0,0); +// //hsv2rgb(i*180.f/size_hist); +// cvRectangle( hist_image, cvPoint(i*bin_w,hist_image->height), +// cvPoint((i+1)*bin_w,hist_image->height - val), +// color, -1, 8, 0 ); +// } +// +// +// cvNamedWindow("hist", 1); cvShowImage("hist",hist_image); + + + //calculate back projection of hue plane of input image + IplImage* backproject = cvCreateImage(cvGetSize(find_image), 8, 1); + IplImage* binary_backproject = cvCreateImage(cvGetSize(find_image), 8, 1); + IplImage* find_hsv = cvCreateImage(cvGetSize(find_image),8,3); + IplImage* find_hue = cvCreateImage(cvGetSize(find_image),8,1); + + cvCvtColor(find_image, find_hsv, CV_BGR2HSV); + cvCvtPixToPlane(find_hsv, find_hue, 0, 0, 0); + cvCalcBackProject(&find_hue, backproject, hist); + + // Threshold in order to obtain binary image + cvThreshold(backproject, binary_backproject, 1, 255, CV_THRESH_BINARY); // NOTE it would be good to think about the best threshold to use (it's 1 for now) + cvReleaseImage(&test_image); + cvReleaseImage(&test_hsv); + cvReleaseImage(&test_hue); + cvReleaseImage(&backproject); + + return Mat(binary_backproject); +} diff --git a/src/ShapeRecognition/ShapeRec_FeatureDetector.hxx b/src/ShapeRecognition/ShapeRec_FeatureDetector.hxx new file mode 100644 index 000000000..bbe37d91c --- /dev/null +++ b/src/ShapeRecognition/ShapeRec_FeatureDetector.hxx @@ -0,0 +1,80 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +// File : ShapeRec_FeatureDetector.h +// Author : Renaud NEDELEC, Open CASCADE S.A.S. + +// OpenCV includes +#include +#include +#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui/highgui.hpp" + +// Qt +#include +#include + +enum // Method used for contour detection +{ + CANNY, + COLORFILTER, + RIDGE_DETECTOR +}; + +class ShapeRec_FeatureDetector +{ +public: + + typedef std::vector CvContour; + typedef std::vector > CvContoursArray; + + ShapeRec_FeatureDetector( const QString& ); // Constructor + + void ComputeCorners(); // Detects the corners from the image located at imagePath + bool ComputeLines(); // Detects the lines from the image located at imagePath + bool ComputeContours( int method ); // Detects the contours from the image located at imagePath + + void SetROI( const QRect& ); // Sets a Region Of Interest in the image + CvPoint2D32f* GetCorners() { return corners; }; + CvContoursArray GetContours() { return contours; }; + std::vector GetLines() { return lines; }; + std::vector GetContoursHierarchy() { return hierarchy; }; + int GetCornerCount() { return cornerCount; }; + int GetImgHeight() { return imgHeight; }; + int GetImgWidth() { return imgWidth; }; + + +private: + std::string imagePath; + + CvPoint2D32f* corners; + int cornerCount; + + CvContoursArray contours; + std::vector hierarchy; + std::vector lines; + int imgHeight; + int imgWidth; + CvRect rect; + + void _detectAndRetrieveContours( cv::Mat binaryImg ); + cv::Mat _colorFiltering(); +}; -- 2.39.2