dist_admlocalm4_DATA = \
check_GEOM.m4 \
-check_GUI.m4
+check_GUI.m4 \
+check_OpenCV.m4
echo
CHECK_SPHINX
+echo
+echo ---------------------------------------------
+echo testing Opencv
+echo ---------------------------------------------
+echo
+CHECK_OPENCV
+AC_DEFINE_UNQUOTED(WITH_OPENCV,${WITH_OPENCV})
+
echo
echo ---------------------------------------------
echo Testing Kernel
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
src/STEPImport/Makefile \
src/STLExport/Makefile \
src/ShHealOper/Makefile \
+ src/ShapeRecognition/Makefile \
src/TransformationGUI/Makefile \
src/VTKExport/Makefile \
resources/Makefile \
<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=""/>
$(GUI_CXXFLAGS) \
$(CORBA_CXXFLAGS) \
$(CORBA_INCLUDES) \
+ $(OPENCV_INCLUDES) \
-I$(srcdir)/../OBJECT \
-I$(srcdir)/../DlgRef \
-I$(srcdir)/../GEOMGUI \
../GEOMBase/libGEOMBase.la \
../GEOMGUI/libGEOM.la \
$(CAS_LDFLAGS) -lTKGeomBase \
- $(GUI_LDFLAGS) -lsuit
+ $(GUI_LDFLAGS) -lsuit \
+ $(OPENCV_LIBS)
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;
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();
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();
#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()
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;
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;
}
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();
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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;
+
+};
--- /dev/null
+// 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;
+}
+
--- /dev/null
+// 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
#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>
{
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;
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;
#
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
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)
$(GUI_CXXFLAGS) \
$(CORBA_CXXFLAGS) \
$(CORBA_INCLUDES) \
+ $(Opencv_includes) \
-I$(srcdir)/../GEOMGUI \
-I$(srcdir)/../DlgRef \
-I$(srcdir)/../GEOMBase \
-I$(srcdir)/../GEOMImpl \
-I$(srcdir)/../GEOMFiltersSelection \
-I$(srcdir)/../SKETCHER \
+ -I$(srcdir)/../ShapeRecognition \
+ -I$(srcdir)/../GEOM \
-I$(top_builddir)/src/DlgRef \
-I$(top_builddir)/idl
../GEOMBase/libGEOMBase.la \
../SKETCHER/libGEOMSketcher.la \
../GEOMGUI/libGEOM.la \
+ ../ShapeRecognition/libGEOMShapeRec.la \
$(QT_MT_LIBS) \
- $(CAS_TKTopAlgo) -lTKernel
-
+ $(CAS_TKTopAlgo) -lTKernel \
+ $(Opencv_libs)
{
// 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 );
if ( myViewWindow == 0 )
return;
-
+
// Display prs
SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
{
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() ) {
myCommand->start();
res = true;
}
+ else
+ {
+ MESSAGE("anOp->_is_nil() = true")
+ }
return res;
}
//================================================================
bool GEOMBase_Helper::hasCommand() const
{
+ bool res = (bool) myCommand;
+ MESSAGE("hasCommand = "<<res)
return (bool)myCommand;
}
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();
catch( const SALOME::SALOME_Exception& e ) {
SalomeApp_Tools::QtCatchCorbaException( e );
abortCommand();
+ MESSAGE("Exception catched")
}
updateViewer();
+ MESSAGE("result ="<<result)
return result;
}
$(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 \
../DlgRef/libDlgRef.la \
$(KERNEL_LDFLAGS) -lOpUtil \
$(GUI_LDFLAGS) -lsuit -lOCCViewer -lVTKViewer -lSVTK -lSalomePrs -lSalomeApp -lCAM \
- $(CAS_LDPATH) -lTKPrim
+ $(CAS_LDPATH) -lTKPrim \
+ $(OPENCV_LIBS)
#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>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopoDS.hxx>
+#include <Prs3d_ShadingAspect.hxx>
+
#include <BRepMesh_IncrementalMesh.hxx>
// VTK Includes
myColor = -1;
// This color is used for shape displaying. If it is equal -1 then
// default color is used.
+ myTexture = "";
myWidth = -1;
myType = -1;
} else
useObjColor = true;
}else {
+ MESSAGE("myDisplayMode = "<< myDisplayMode)
AISShape->SetDisplayMode( myDisplayMode );
AISShape->SetShadingColor( myShadingColor );
}
}
}
}
+
else
{
if ( onlyVertex )
}
}
+ if ( HasTexture() )
+ {
+ AISShape->SetTextureFileName(TCollection_AsciiString(myTexture.c_str()));
+ AISShape->SetTextureMapOn();
+ AISShape->DisableTextureModulate();
+ AISShape->SetDisplayMode(3);
+ }
+
if ( HasWidth() )
AISShape->SetWidth( GetWidth() );
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
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 );
Handle(SALOME_InteractiveObject) myIO;
TopoDS_Shape myShape;
std::string myName;
+ std::string myTexture;
int myType;
SALOME_View* myViewFrame;
<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>
<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>
<message>
<source>TOP_POP_PUBLISH_OBJ</source>
<translation>Publish object</translation>
- </message>
+ </message>
<message>
<source>TOP_POP_HIDE_CHILDREN</source>
<translation>Hide Children</translation>
<message>
<source>GEOM_CURVE_ANALITICAL</source>
<translation>Analytical</translation>
- </message>
+ </message>
</context>
<context>
<name>BasicGUI_ParamCurveWidget</name>
<message>
<source>GEOM_PCURVE_MAX</source>
<translation>Max t</translation>
- </message>
+ </message>
<message>
<source>GEOM_PCURVE_STEP</source>
<translation>Step</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>
<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>
<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>
Le nombre de points n'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'é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>
view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
view3d->SetUp(DY.X(), DY.Y(), DY.Z());
-
- vw->onViewFitAll();
+ vw->onViewFitAll();
}
}
else if( ViewVTK ) {
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
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;
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
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" );
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" );
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 );
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 );
// ---- 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";
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 );
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 );
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
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
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
$(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 = \
../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) \
case GEOMOp::OpColor: // POPUP - COLOR
OnColor();
break;
+ case GEOMOp::OpSetTexture: // POPUP - TEXTURE
+ OnTexture();
+ break;
case GEOMOp::OpTransparency: // POPUP - TRANSPARENCY
OnTransparency();
break;
void OnAutoColor();
void OnDisableAutoColor();
void OnColor();
+ void OnTexture();
void OnTransparency();
void OnNbIsos( ActionType actionType = SHOWDLG );
void OnDeflection();
#include "GEOMToolsGUI_PublishDlg.h"
#include <GeometryGUI.h>
+#include <GeometryGUI_Operations.h>
#include <GEOM_Displayer.h>
#include <GEOMBase.h>
// QT Includes
#include <QColorDialog>
#include <QInputDialog>
+#include <QFileDialog>
#include <QList>
#include <QGridLayout>
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() );
# 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 \
{
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();
AIS_Shape::Compute(aPresentationManager, aPrs, aMode);
break;
}
+ case 3: //StdSelect_DM_HLR:
+ {
+ AIS_TexturedShape::Compute(aPresentationManager, aPrs, aMode);
+ break;
+ }
}
if (isShowVectors())
$(GUI_CXXFLAGS) \
$(CORBA_CXXFLAGS) \
$(CORBA_INCLUDES) \
+ $(OPENCV_INCLUDES) \
-I$(srcdir)/../GEOMGUI \
-I$(srcdir)/../DlgRef \
-I$(srcdir)/../GEOMBase \
-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 ?
###############################
--- /dev/null
+# 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)
--- /dev/null
+// 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);
+}
--- /dev/null
+// 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();
+};