]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
Merge from BR_OPENCV
authorgdd <gdd>
Tue, 8 Nov 2011 13:40:30 +0000 (13:40 +0000)
committergdd <gdd>
Tue, 8 Nov 2011 13:40:30 +0000 (13:40 +0000)
31 files changed:
adm_local/unix/config_files/Makefile.am
configure.ac
resources/GEOM_en.xml
src/BasicGUI/Makefile.am
src/DisplayGUI/DisplayGUI.cxx
src/EntityGUI/EntityGUI.cxx
src/EntityGUI/EntityGUI.h
src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx [new file with mode: 0644]
src/EntityGUI/EntityGUI_FeatureDetectorDlg.h [new file with mode: 0644]
src/EntityGUI/EntityGUI_PictureImportDlg.cxx [new file with mode: 0644]
src/EntityGUI/EntityGUI_PictureImportDlg.h [new file with mode: 0644]
src/EntityGUI/EntityGUI_SketcherDlg.cxx
src/EntityGUI/Makefile.am
src/GEOMBase/GEOMBase_Helper.cxx
src/GEOMBase/Makefile.am
src/GEOMGUI/GEOM_Displayer.cxx
src/GEOMGUI/GEOM_Displayer.h
src/GEOMGUI/GEOM_msg_en.ts
src/GEOMGUI/GEOM_msg_fr.ts
src/GEOMGUI/GeometryGUI.cxx
src/GEOMGUI/GeometryGUI_Operations.h
src/GEOMGUI/Makefile.am
src/GEOMToolsGUI/GEOMToolsGUI.cxx
src/GEOMToolsGUI/GEOMToolsGUI.h
src/GEOMToolsGUI/GEOMToolsGUI_1.cxx
src/Makefile.am
src/OBJECT/GEOM_AISShape.cxx
src/OperationGUI/Makefile.am
src/ShapeRecognition/Makefile.am [new file with mode: 0644]
src/ShapeRecognition/ShapeRec_FeatureDetector.cxx [new file with mode: 0644]
src/ShapeRecognition/ShapeRec_FeatureDetector.hxx [new file with mode: 0644]

index 66230c1fe600ec6e41777ceadf34b30e8c8623be..b2687da746449a65352b513971680efbe12f00b0 100644 (file)
@@ -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
index 8be0b6c5389074871cfd16f27b0e229b6120bd9c..8849337c387421d0f8a65afdd6df5de29b8fdeea 100644 (file)
@@ -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 \
index d664cfd5b947f7b2b036be079469e9b72f74e342..033ccbd860ab1bf0ee6defc331b1cd1cdb4ba41a 100644 (file)
    <submenu label-id="Display Mode" item-id="803" pos-id="6">
       <popup-item item-id="80311" pos-id="" label-id="Wireframe" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>
       <popup-item item-id="80312" pos-id="" label-id="Shading" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>
+      <popup-item item-id="80312" pos-id="" label-id="Texture" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>
    </submenu>
    <endsubmenu />
    <popup-item item-id="8032" pos-id="" label-id="Color" icon-id="" tooltip-id="" accel-id="" toggle-id="" execute-action=""/>
index 08fde9c7df35d42d5c939a54200769f80102aea8..5aad443b1b8e00fc756b1e00df75c9ad0eed4c8b 100644 (file)
@@ -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) 
index 53c04c20430eb272baf87eb6ff3c1264258409cb..a0d6812cec3deb7bc9e9a8687401a73e398e5e88 100644 (file)
@@ -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();
index a6b0bdf23ae7fdbf4a180969f35333c3af684a0d..02985b32876c5e0c7df2d026129c5ec0098013ce 100644 (file)
 #include <ElSLib.hxx>
 
 #include <QMouseEvent>
+#include <QApplication>
 
-#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;
 }
index cfc0addefbb859ea5c847414e2abdbf1a13b3266..d6a557ef63291bc437b88c8f5d487fbc34ab4de1 100644 (file)
@@ -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 (file)
index 0000000..8be5415
--- /dev/null
@@ -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 <OCCViewer_ViewPort3d.h>
+#include <OCCViewer_ViewWindow.h>
+#include <OCCViewer_ViewManager.h>
+
+#include <SOCC_ViewModel.h>
+
+#include <DlgRef.h>
+#include <GeometryGUI.h>
+#include <EntityGUI.h>
+#include <GEOMBase.h>
+#include <GEOM_Object.hxx>
+#include <ShapeRec_FeatureDetector.hxx>
+
+#include <SUIT_Desktop.h>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_Session.h>
+#include <SUIT_ViewWindow.h>
+#include <SalomeApp_Application.h>
+#include <LightApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+
+#include <SALOME_ListIteratorOfListIO.hxx>
+
+#include <SalomeApp_Study.h>
+
+#include <utilities.h>
+
+#include <gp_Pnt.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Wire.hxx>
+
+#include <BRepBuilderAPI_MakeVertex.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
+#include <BRepBuilderAPI_MakePolygon.hxx>
+#include <BRepBuilderAPI_Transform.hxx>
+
+#include <AIS_TexturedShape.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <StdSelect_DisplayMode.hxx>
+
+#include <Graphic3d_MaterialAspect.hxx>
+
+#include <Precision.hxx>
+
+#include <set>
+#include <utility>
+
+#include <boost/utility.hpp>
+
+// 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 ="<<id)
+  myConstructorId = id;
+  switch (id)
+  {
+    case CORNERS:
+//       myViewGroup->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<Handle(AIS_InteractiveObject)> >::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<cv::Point> >   contours  = aDetector->GetContours();
+    std::vector<cv::Vec4i>                  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<int> > existing_points;
+        std::pair< std::set< std::vector<int> >::iterator,bool > pnt_it;
+        for ( it=contour.begin() ; it < contour.end(); it++ )
+        {
+  //         gp_Pnt  aContourPnt = EntityGUI::ConvertClickToPoint(viewLeft + it->x*imgZoomRatio, viewTop + it->y*imgZoomRatio, vp->getView());
+  //         double x = aContourPnt.X();
+  //         double y = aContourPnt.Y();
+  //         double z = aContourPnt.Z();
+          
+          // When using the new way with textures on shapes we just have to do the following
+          int pnt_array[] = {it->x,it->y};     
+          std::vector<int> pnt (pnt_array, pnt_array + sizeof(pnt_array) / sizeof(int) );
+
+          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) ="<<fabs(u_v_sinus))
+//                     MESSAGE("it->x = "<<it->x)
+//                     MESSAGE("it->y = "<<it->y)
+//                     MESSAGE("it_previous->x = "<<it_previous->x)
+//                     MESSAGE("it_previous->y = "<<it_previous->y)
+//                     MESSAGE("it_next->x = "<<it_next->x)
+//                     MESSAGE("it_next->y = "<<it_next->y)
+//                     MESSAGE("norme_u = "<<norme_u)
+//                     MESSAGE("norme_v = "<<norme_v)
+//                     MESSAGE("u_v_det = "<<u_v_det)
+//                   }
+                  insert = !myCheckBox->isChecked();  // TEST correction appliquee que si la checkbox est cochee
+                }                         
+              }
+            }
+            double x = -0.5 *width  + it->x;
+            double y =  0.5 *height - it->y;
+            double z =  0;
+            if (insert)
+            {
+              aGeomContourPnt    = aBasicOperations->MakePointXYZ( x,y,z );
+              geomContourPnts->length( j+1 );
+              geomContourPnts[j] = aGeomContourPnt;
+              j++;
+            }
+//             TEST for debug only
+//             else
+//             { 
+//               aRemovedPnt   = aBasicOperations->MakePointXYZ( x,y,z );
+//               removedPnts->length( r+1 );
+//               removedPnts[r] = aRemovedPnt;
+//               r++;
+//             }
+          }
+        }
+        
+        GEOM::GEOM_Object_var aWire;
+        if(myOutputGroup->RadioButton2->isChecked())
+        {
+          aWire = aCurveOperations->MakePolyline(geomContourPnts.in(), false);
+        }
+        else if(myOutputGroup->RadioButton1->isChecked())
+        {
+          aWire = aCurveOperations->MakeSplineInterpolation(geomContourPnts.in(), /*closed =*/ false, /*reordering =*/ false);
+        }
+        else
+          return res;
+        
+        if ( !aWire->_is_nil() )
+        {
+          geomContours->length(contourCount + 1);
+          geomContours[contourCount] = aWire;
+          contourCount++;
+        }
+//       }
+    }
+    GEOM::GEOM_Object_var aContoursCompound = aShapesOperations->MakeCompound(geomContours);
+//   TEST for debu only  GEOM::GEOM_Object_var aRemovedPntsCompound = aShapesOperations->MakeCompound(removedPnts);
+    if ( !aContoursCompound->_is_nil() )
+    {
+      objects.push_back( aContoursCompound._retn() );
+    }
+//   TEST for debug only
+//     if ( !aRemovedPntsCompound->_is_nil() )
+//     {
+//       objects.push_back( aRemovedPntsCompound._retn() );
+//     }
+
+    res=true;
+  }
+  
+  else if(myConstructorId ==LINES)
+  {
+    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();
+    int linesCount=0;
+    for( int i = 0; i < lines.size(); i++ )
+    {
+      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 );
+      aLine = aBasicOperations->MakeLineTwoPnt( Pnt1, Pnt2 );
+      if ( !aLine->_is_nil() )
+      {
+        geomLines->length(linesCount + 1);
+        geomLines[linesCount] = aLine;
+        linesCount++;
+      }
+    }
+    GEOM::GEOM_Object_var aLinesCompound = aShapesOperations->MakeCompound(geomLines);
+    if ( !aLinesCompound->_is_nil() )
+    {
+      objects.push_back( aLinesCompound._retn() );
+    }
+
+    res=true;
+  }
+  
+  return res;
+}
diff --git a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.h b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.h
new file mode 100644 (file)
index 0000000..5c6c011
--- /dev/null
@@ -0,0 +1,102 @@
+// 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 <GEOMBase_Skeleton.h>
+#include <gp_Ax3.hxx>
+
+class QLineEdit;
+class QCheckBox;
+class QGroupBox;
+class QPushButton;
+class QLabel;
+class QPoint;
+class DlgRef_3Radio;
+class DlgRef_1Sel;
+
+class gp_Pnt;
+
+//=================================================================================
+// class    : EntityGUI_Dlg
+// purpose  :
+//=================================================================================
+class EntityGUI_FeatureDetectorDlg : public GEOMBase_Skeleton
+{ 
+  Q_OBJECT
+
+public:
+  EntityGUI_FeatureDetectorDlg(GeometryGUI*, QWidget* = 0, bool = false, Qt::WindowFlags = 0);
+  ~EntityGUI_FeatureDetectorDlg();
+  
+  bool                               acceptMouseEvent() const;
+//   void                               OnPointSelected( const gp_Pnt& );
+  void                               setStartPnt    ( const QPoint& );
+  void                               setEndPnt      ( const QPoint& );
+  int                                getConstructorId() {return myConstructorId;};
+  
+protected:
+  // redefined from GEOMBase_Helper
+  virtual GEOM::GEOM_IOperations_ptr createOperation();
+  virtual bool                       execute( ObjectList& );
+  
+private:
+  void                               Init();
+
+  
+private slots:
+  void                               SetEditCurrentArgument();
+  void                               SelectionIntoArgument();
+  void                               ConstructorsClicked( int );
+//   void                               onViewClicked( int );
+  void                               onButtonToggled( bool ); 
+  void                               ClickOnOk();
+  bool                               ClickOnApply();
+  
+  
+private:
+  GEOM::GeomObjPtr                   myFace;
+  QString                            myFaceEntry;
+  
+  int                                myConstructorId;
+  
+  QGroupBox*                         mySelectionGroup;
+  
+  QLabel*                            mySnapshotLabel;
+  
+  DlgRef_1Sel*                       mySelWidget;
+  
+  QPoint                             myStartPnt;
+  QPoint                             myEndPnt;
+  
+  gp_Ax3                             myWPlane;
+  gp_Ax3                             aGlobalCS;
+  
+  QPushButton*                       myPushButton;
+  QPushButton*                       mySelButton;
+  
+  QLineEdit*                         myLineEdit;
+  QCheckBox*                         myCheckBox;
+  
+//   DlgRef_3Radio*                     myViewGroup;
+  DlgRef_3Radio*                     myOutputGroup;
+//   QButtonGroup*                      myViewButtonGroup;
+
+};
diff --git a/src/EntityGUI/EntityGUI_PictureImportDlg.cxx b/src/EntityGUI/EntityGUI_PictureImportDlg.cxx
new file mode 100644 (file)
index 0000000..dbd02bd
--- /dev/null
@@ -0,0 +1,209 @@
+// 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.cxx
+// Author : Renaud NEDELEC, Open CASCADE S.A.S.
+//
+#include "EntityGUI_PictureImportDlg.h"
+
+#include <DlgRef.h>
+#include <GeometryGUI.h>
+#include <GEOMBase.h>
+
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_Session.h>
+#include <SalomeApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+
+#include <TopoDS_Shape.hxx>
+#include <TopoDS.hxx>
+
+#include <GEOMImpl_Types.hxx>
+
+#include <ShapeRec_FeatureDetector.hxx>
+
+#include <QFileDialog>
+
+//=================================================================================
+// 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 (file)
index 0000000..74c2c32
--- /dev/null
@@ -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
index c2b167b9890cb878f17c89de934404efa5966f9a..27604981e15383083916dec23ca9ecec26e23307 100644 (file)
@@ -28,6 +28,9 @@
 #include "EntityGUI_Widgets.h"
 #include <SalomeApp_DoubleSpinBox.h>
 
+#include <OCCViewer_ViewPort3d.h>
+#include <OCCViewer_ViewWindow.h>
+
 #include <GEOMBase.h>
 #include <GeometryGUI.h>
 #include <GEOMImpl_Types.hxx>
@@ -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;
index e8331a45457d5924431c141f8a3d008c147fab85..a1fbbcb93783ae7a0465533c3340ce7a7f72f1aa 100644 (file)
 #
 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)
index d62615d87fb9a8223118230ecbfe68a4fe5d4439..71355da4d27e2d56efa95186bfeab7f2e292d29d 100755 (executable)
@@ -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 = "<<getDisplayer()->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 = "<<res)
   return (bool)myCommand;
 }
 
@@ -795,7 +806,11 @@ bool GEOMBase_Helper::checkViewWindow()
 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
 {
   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( 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 ="<<result)
   return result;
 }
 
index 3360c44c31b5b41180e22aa1921f30ed952a4351..77d1624c31d47a1f4c1baaf9489b281f489f064b 100644 (file)
@@ -61,13 +61,14 @@ libGEOMBase_la_CPPFLAGS =           \
        $(GUI_CXXFLAGS)                 \
        $(CORBA_CXXFLAGS)               \
        $(CORBA_INCLUDES)               \
+       $(OPENCV_INCLUDES)              \
        -I$(srcdir)/../OBJECT           \
        -I$(srcdir)/../GEOMClient       \
        -I$(srcdir)/../GEOMImpl         \
        -I$(srcdir)/../GEOMGUI          \
        -I$(srcdir)/../DlgRef           \
        -I$(top_builddir)/src/DlgRef    \
-       -I$(top_builddir)/idl
+       -I$(top_builddir)/idl           
 
 libGEOMBase_la_LDFLAGS  =              \
        ../../idl/libSalomeIDLGEOM.la   \
@@ -75,4 +76,5 @@ libGEOMBase_la_LDFLAGS  =             \
        ../DlgRef/libDlgRef.la          \
        $(KERNEL_LDFLAGS) -lOpUtil      \
        $(GUI_LDFLAGS) -lsuit -lOCCViewer -lVTKViewer -lSVTK -lSalomePrs -lSalomeApp -lCAM \
-       $(CAS_LDPATH) -lTKPrim
+       $(CAS_LDPATH) -lTKPrim          \
+       $(OPENCV_LIBS)
index a3c3aff6d8d7145402cb08f5c32b5db16b19bc3f..ca2b6c92fd692ee49c4110058d09be298d2be490 100644 (file)
@@ -73,6 +73,7 @@
 #include <Prs3d_PointAspect.hxx>
 #include <StdSelect_TypeOfEdge.hxx>
 #include <StdSelect_TypeOfFace.hxx>
+#include <StdSelect_DisplayMode.hxx>
 #include <TopoDS_Face.hxx>
 #include <BRep_Tool.hxx>
 #include <Geom_Plane.hxx>
@@ -87,6 +88,8 @@
 #include <TopTools_ListIteratorOfListOfShape.hxx>
 #include <TopoDS.hxx>
 
+#include <Prs3d_ShadingAspect.hxx>
+
 #include <BRepMesh_IncrementalMesh.hxx>
 
 // 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
index 70f5342a1ef8929c97f6ce3be11e2148540e641e..30337eaac4264c6b685fa714572b8a2f1f91bac2 100644 (file)
@@ -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;
 
index f3c0edbbb563006c924788a97d01388334a281da..a060413a9c8c2c9c6a13f7a5fbeae3bb152e8876 100644 (file)
@@ -2181,6 +2181,14 @@ Please, select face, shell or solid and try again</translation>
         <source>MEN_BUILD</source>
         <translation>Build</translation>
     </message>
+    <message>
+        <source>MEN_FEATURE_DETECTION</source>
+        <translation>Feature detection</translation>
+    </message>
+    <message>
+        <source>MEN_PICTURE_IMPORT</source>
+        <translation>Import picture in viewer</translation>
+    </message>
     <message>
         <source>MEN_CHAMFER</source>
         <translation>Chamfer</translation>
@@ -3156,11 +3164,11 @@ Please, select face, shell or solid and try again</translation>
     <message>
         <source>STB_POP_UNPUBLISH_OBJ</source>
         <translation>Unpublish object</translation>
-   </message>
+    </message>
     <message>
         <source>STB_POP_PUBLISH_OBJ</source>
         <translation>Publish object</translation>
-   </message>
+    </message>
     <message>
         <source>STB_POP_HIDE_CHILDREN</source>
         <translation>Hide child objects</translation>
@@ -3704,7 +3712,7 @@ Please, select face, shell or solid and try again</translation>
     <message>
         <source>TOP_POP_PUBLISH_OBJ</source>
         <translation>Publish object</translation>
-   </message>
+    </message>
     <message>
         <source>TOP_POP_HIDE_CHILDREN</source>
         <translation>Hide Children</translation>
@@ -4345,7 +4353,7 @@ Otherwise the dimensions will be kept without modifications.</translation>
     <message>
         <source>GEOM_CURVE_ANALITICAL</source>
         <translation>Analytical</translation>
-    </message>        
+    </message>
 </context>
 <context>
     <name>BasicGUI_ParamCurveWidget</name>
@@ -4372,7 +4380,7 @@ Otherwise the dimensions will be kept without modifications.</translation>
     <message>
         <source>GEOM_PCURVE_MAX</source>
         <translation>Max t</translation>
-    </message>        
+    </message>
     <message>
         <source>GEOM_PCURVE_STEP</source>
         <translation>Step</translation>
@@ -4552,6 +4560,76 @@ Otherwise the dimensions will be kept without modifications.</translation>
 Number of sketch points too small</translation>
     </message>
 </context>
+<context>
+    <name>EntityGUI_FeatureDetectorDlg</name>
+    <message>
+        <source>GEOM_DETECT_TITLE</source>
+        <translation>Feature Detection</translation>
+    </message>
+    <message>
+        <source>GEOM_SCALING</source>
+        <translation>Scaling</translation>
+    </message>
+    <message>
+        <source>GEOM_PNT1</source>
+        <translation>Top left corner</translation>
+    </message>
+    <message>
+        <source>GEOM_PNT2</source>
+        <translation>Top right corner</translation>
+    </message>
+    <message>
+        <source>GEOM_CORNER</source>
+        <translation>Detected_corners</translation>
+    </message>
+    <message>
+        <source>GEOM_CORNERS</source>
+        <translation>Corners</translation>
+    </message>
+    <message>
+        <source>GEOM_CONTOURS</source>
+        <translation>Contours</translation>
+    </message>
+    <message>
+        <source>GEOM_FEATURES</source>
+        <translation>Features</translation>
+    </message>
+    <message>
+        <source>GEOM_DETECT_ZONE</source>
+        <translation>Select a detection zone (default is whole picture)</translation>
+    </message>
+    <message>
+        <source>GEOM_COLOR_FILTER</source>
+        <translation>Select the color of the zone you want to find the frontier of</translation>
+    </message>
+    <message>
+        <source>GEOM_VIEW</source>
+        <translation>View</translation>
+    </message>
+    <message>
+        <source>GEOM_FRONT</source>
+        <translation>Front (Y-Z)</translation>
+    </message>
+    <message>
+        <source>GEOM_TOP</source>
+        <translation>Top (X-Y)</translation>
+    </message>
+    <message>
+        <source>GEOM_LEFT</source>
+        <translation>Left (X-Z)</translation>
+    </message>
+</context>
+<context>
+    <name>EntityGUI_PictureImportDlg</name>
+    <message>
+        <source>GEOM_PICTURE</source>
+        <translation>Picture</translation>
+    </message>
+    <message>
+        <source>GEOM_IMPORT_PICT_TITLE</source>
+        <translation>Import picture in viewer</translation>
+    </message>
+</context>
 <context>
     <name>EntityGUI_SubShapeDlg</name>
     <message>
@@ -4963,12 +5041,12 @@ Would you like to continue?</translation>
         <translation>Publish Objects</translation>
     </message>
     <message>
-      <source>OBJECT_NAME</source>
-      <translation>Name</translation>
+        <source>OBJECT_NAME</source>
+        <translation>Name</translation>
     </message>
     <message>
-      <source>OBJECT_ENTRY</source>
-      <translation>Entry</translation>
+        <source>OBJECT_ENTRY</source>
+        <translation>Entry</translation>
     </message>
     <message>
         <source>UNSELECT_ALL</source>
index 594d1ead8f36f666e39fa6902147aa9ff11024ce..efe2dd7e59e0ceec0e803ddabdf6b38ae208b715 100644 (file)
@@ -2181,6 +2181,10 @@ Choisissez une face, une coque ou un solide et essayez de nouveau</translation>
         <source>MEN_BUILD</source>
         <translation>Construire</translation>
     </message>
+    <message>
+        <source>MEN_CORNER_DETECTION</source>
+        <translation>Détecter les angles (image ou plan)</translation>
+    </message>
     <message>
         <source>MEN_CHAMFER</source>
         <translation>Chanfrein</translation>
@@ -4552,6 +4556,33 @@ le paramètre &apos;%1&apos; aux préférences du module Géométrie.</translati
 Le nombre de points n&apos;est pas suffisant</translation>
     </message>
 </context>
+<context>
+    <name>EntityGUI_CornerDetectionDlg</name>
+    <message>
+        <source>GEOM_DETECT_TITLE</source>
+        <translation>Détecter les angles</translation>
+    </message>
+    <message>
+        <source>GEOM_SCALING</source>
+        <translation>Mise à l&apos;échelle</translation>
+    </message>
+    <message>
+        <source>GEOM_PNT1</source>
+        <translation>Coin supérieur gauche</translation>
+    </message>
+    <message>
+        <source>GEOM_PNT2</source>
+        <translation>Coin supérieur droit</translation>
+    </message>
+    <message>
+        <source>GEOM_CORNER</source>
+        <translation>Angles_détectés</translation>
+    </message>
+    <message>
+        <source>GEOM_CORNERS</source>
+        <translation>Angles</translation>
+    </message>
+</context>
 <context>
     <name>EntityGUI_SubShapeDlg</name>
     <message>
index 5d138bbf756226b5d125f311790ab83466f51502..d15bec532bc641ca2dd37bbc3ea5a027d712fffd 100644 (file)
@@ -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 );
index 73b68f2f2e1384a5422cb35eb093f5802ecf08d8..eb21885c6d1cf5b62b75dd48260249957ef353c1 100644 (file)
@@ -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
index d65f42496cbf00a80ffd0dcfd3e279a6f9e045e6..bfd12147f143d3a463a75165023f784c8aab8d38 100644 (file)
@@ -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) \
index 008d71b8621f9bf61c0b68109f8b9d2c3242c682..cc95e6831cb7f9a2411e2993da468138be3fc490 100644 (file)
@@ -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;
index bb20a9687b3aa8159408e8ba4788ebb7a3025f3a..12cead468218d1bcb3afef44e75f8ca93b7368a7 100644 (file)
@@ -66,6 +66,7 @@ private:
   void         OnAutoColor();
   void         OnDisableAutoColor();
   void         OnColor();
+  void         OnTexture();
   void         OnTransparency();
   void         OnNbIsos( ActionType actionType = SHOWDLG );
   void         OnDeflection();
index f9d1c20b072f1eef8c4d1a6bc1cdd935a633cf16..cb3497dd1e4463c86160512a181d7aedcadda6cf 100644 (file)
@@ -33,6 +33,7 @@
 #include "GEOMToolsGUI_PublishDlg.h"
 
 #include <GeometryGUI.h>
+#include <GeometryGUI_Operations.h>
 #include <GEOM_Displayer.h>
 
 #include <GEOMBase.h>
@@ -86,6 +87,7 @@
 // QT Includes
 #include <QColorDialog>
 #include <QInputDialog>
+#include <QFileDialog>
 #include <QList>
 
 #include <QGridLayout>
@@ -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<SalomeApp_Study*>( 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<OCCViewer_Viewer*> ( 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() );
index b160442bd95347d511a0e6a322b6ef542ff61e69..61851d56ea45656b640e41d601a21635f6a29640 100644 (file)
 # 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 \
index af0be3e5e33acb0f15c2f6f74a25ceb948e55c3b..f50b29ed092a6ba9a39d124aeb362f450e65e59e 100644 (file)
@@ -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 = "<<aMode<<" ======================= GEOM_AISShape::Compute ========================="<<std::endl;
+  switch (aMode) {
+    case 0://StdSelect_DM_Wireframe: 
     {
       StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
       break;
     }
-  case StdSelect_DM_Shading:
+    case 1://StdSelect_DM_Shading:
     {
       myDrawer->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())
index 3246166328c89bc50b68f21a8591324a36d0ee2e..e5f3a27d8a3c6e64f53c1287f13a95120f944aca 100644 (file)
@@ -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 (file)
index 0000000..2149870
--- /dev/null
@@ -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 (file)
index 0000000..ca6caa1
--- /dev/null
@@ -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 <stdio.h>
+#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 (file)
index 0000000..bbe37d9
--- /dev/null
@@ -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 <cv.h>
+#include <highgui.h>
+#include "opencv2/imgproc/imgproc.hpp"
+#include "opencv2/highgui/highgui.hpp"
+
+// Qt
+#include <QString>
+#include <QRect>
+
+enum              // Method used for contour detection
+{
+  CANNY,
+  COLORFILTER,
+  RIDGE_DETECTOR
+};
+
+class ShapeRec_FeatureDetector
+{
+public:
+  
+  typedef std::vector<cv::Point>               CvContour;
+  typedef std::vector<std::vector<cv::Point> > 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<cv::Vec4i>  GetLines()             { return lines;       };
+  std::vector<cv::Vec4i>  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<cv::Vec4i>  hierarchy;
+  std::vector<cv::Vec4i>  lines;
+  int                     imgHeight;
+  int                     imgWidth; 
+  CvRect                  rect;
+  
+  void                    _detectAndRetrieveContours( cv::Mat binaryImg );
+  cv::Mat                 _colorFiltering();
+};