From 8023d841c573017ae830ba0c35e77a991d8f8dbe Mon Sep 17 00:00:00 2001 From: gdd Date: Tue, 13 Sep 2011 13:01:59 +0000 Subject: [PATCH] rnc : previous work ... --- src/OCCViewer/Makefile.am | 14 ++++-- src/OCCViewer/OCCViewer_ViewModel.cxx | 16 ++++--- src/OCCViewer/OCCViewer_ViewPort3d.cxx | 45 +++++++++++++++++-- src/OCCViewer/OCCViewer_ViewPort3d.h | 5 +++ src/OCCViewer/OCCViewer_ViewWindow.cxx | 62 +++++++++++++++++++++++++- 5 files changed, 129 insertions(+), 13 deletions(-) diff --git a/src/OCCViewer/Makefile.am b/src/OCCViewer/Makefile.am index fb3081744..beaa3834c 100755 --- a/src/OCCViewer/Makefile.am +++ b/src/OCCViewer/Makefile.am @@ -23,6 +23,7 @@ # Author : Vladimir Klyachin (OCN) # Module : OCCViewer # $Header$ +# include $(top_srcdir)/adm_local/unix/make_common_starter.am @@ -46,7 +47,8 @@ salomeinclude_HEADERS = \ OCCViewer_FontWidget.h \ OCCViewer_CubeAxesDlg.h \ OCCViewer_ToolTip.h \ - OCCViewer_ViewFrame.h + OCCViewer_ViewFrame.h \ + OCCViewer_FeatureDetector.h dist_libOCCViewer_la_SOURCES = \ OCCViewer_AISSelector.cxx \ @@ -65,7 +67,8 @@ dist_libOCCViewer_la_SOURCES = \ OCCViewer_FontWidget.cxx \ OCCViewer_CubeAxesDlg.cxx \ OCCViewer_ToolTip.cxx \ - OCCViewer_ViewFrame.cxx + OCCViewer_ViewFrame.cxx \ + OCCViewer_FeatureDetector.cxx MOC_FILES = \ OCCViewer_AISSelector_moc.cxx \ @@ -125,8 +128,11 @@ nodist_salomeres_DATA = \ libOCCViewer_la_CPPFLAGS = $(QT_INCLUDES) $(OGL_INCLUDES) $(CAS_CPPFLAGS) @KERNEL_CXXFLAGS@ \ -I$(srcdir)/../SUIT -I$(srcdir)/../ViewerTools -I$(srcdir)/../Qtx \ - -I$(srcdir)/../OpenGLUtils -I$(srcdir)/../CASCatch + -I$(srcdir)/../OpenGLUtils -I$(srcdir)/../CASCatch \ + -I/home/palmco/OpenCV/OpenCV-2.3.0/install/include/opencv \ + -I/home/palmco/OpenCV/OpenCV-2.3.0/install/include -libOCCViewer_la_LDFLAGS = $(OGL_LIBS) $(QT_MT_LIBS) $(CAS_KERNEL) $(CAS_VIEWER) +libOCCViewer_la_LDFLAGS = $(OGL_LIBS) $(QT_MT_LIBS) $(CAS_KERNEL) $(CAS_VIEWER) \ + -L/home/palmco/OpenCV/OpenCV-2.3.0/install/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann libOCCViewer_la_LIBADD = ../Qtx/libqtx.la ../SUIT/libsuit.la \ ../ViewerTools/libViewerTools.la ../OpenGLUtils/libOpenGLUtils.la diff --git a/src/OCCViewer/OCCViewer_ViewModel.cxx b/src/OCCViewer/OCCViewer_ViewModel.cxx index 35c81ac3f..8bdb3b0d6 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.cxx +++ b/src/OCCViewer/OCCViewer_ViewModel.cxx @@ -18,6 +18,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include "OCCViewer_ViewModel.h" #include "OCCViewer_ViewWindow.h" @@ -56,6 +57,8 @@ #include #include +#include "utilities.h" + /*! Constructor \param DisplayTrihedron - is trihedron displayed @@ -215,6 +218,7 @@ void OCCViewer_Viewer::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* the */ void OCCViewer_Viewer::onMouseMove(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent) { +// MESSAGE("OCCViewer_Viewer::onMouseMove") if (!mySelectionEnabled) return; if (!theWindow->inherits("OCCViewer_ViewWindow")) return; @@ -240,6 +244,7 @@ void OCCViewer_Viewer::onMouseMove(SUIT_ViewWindow* theWindow, QMouseEvent* theE */ void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent) { + MESSAGE("OCCViewer_Viewer::onMouseRelease") if (!mySelectionEnabled) return; if (theEvent->button() != Qt::LeftButton) return; if (!theWindow->inherits("OCCViewer_ViewWindow")) return; @@ -461,9 +466,10 @@ void OCCViewer_Viewer::onChangeBgImageCentered() if ( !aView ) return; - QString selFile = QFileDialog::getOpenFileName(aView,tr( "SELECT_IMAGE"),aView->backgroundImageFilename(), tr("OCC_BG_IMAGE_FILES")); - if ( ! selFile.isEmpty() ) + QString selFile = QFileDialog::getOpenFileName(aView,tr( "SELECT_IMAGE"),aView->backgroundImageFilename(), tr("OCC_IMAGE_FILES")); + if ( ! selFile.isEmpty() ){ aView->setBackgroundImage(selFile,Aspect_FM_CENTERED); + } } /*! @@ -475,7 +481,7 @@ void OCCViewer_Viewer::onChangeBgImageTiled() if ( !aView ) return; - QString selFile = QFileDialog::getOpenFileName(aView,tr( "SELECT_IMAGE"),aView->backgroundImageFilename(), tr("OCC_BG_IMAGE_FILES")); + QString selFile = QFileDialog::getOpenFileName(aView,tr( "SELECT_IMAGE"),aView->backgroundImageFilename(), tr("OCC_IMAGE_FILES")); if ( ! selFile.isEmpty() ) aView->setBackgroundImage(selFile,Aspect_FM_TILED); } @@ -489,9 +495,9 @@ void OCCViewer_Viewer::onChangeBgImageStretched() if ( !aView ) return; - QString selFile = QFileDialog::getOpenFileName(aView,tr( "SELECT_IMAGE"),aView->backgroundImageFilename(), tr("OCC_BG_IMAGE_FILES")); + QString selFile = QFileDialog::getOpenFileName(aView,tr( "SELECT_IMAGE"),aView->backgroundImageFilename(), tr("OCC_IMAGE_FILES")); if ( ! selFile.isEmpty() ) - aView->setBackgroundImage(selFile,Aspect_FM_STRETCH); + aView->setBackgroundImage(selFile,Aspect_FM_STRETCH_NODEF); } /*! Updates OCC 3D viewer diff --git a/src/OCCViewer/OCCViewer_ViewPort3d.cxx b/src/OCCViewer/OCCViewer_ViewPort3d.cxx index 06801b37a..f6ebec16f 100755 --- a/src/OCCViewer/OCCViewer_ViewPort3d.cxx +++ b/src/OCCViewer/OCCViewer_ViewPort3d.cxx @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -41,6 +42,12 @@ #include #include +#include +#include +#include + +#include "utilities.h" + #if defined WNT #include #else @@ -299,9 +306,41 @@ QString OCCViewer_ViewPort3d::backgroundImageFilename() const void OCCViewer_ViewPort3d::setBackgroundImage( const QString& fileName,const Aspect_FillMethod& theFillMethod) { myBackgroundImageFilename=fileName; - if ( !activeView().IsNull() ) { - activeView()->SetBackgroundImage( (Standard_CString)fileName.toLatin1().constData(),theFillMethod,true); - } + //TEST +// if ( !activeView().IsNull() ) { +// activeView()->SetBackgroundImage( (Standard_CString)fileName.toLatin1().constData(),theFillMethod,true); + +// //TEST +// SUIT_ViewWindow* theViewWindow = getDesktop()->activeWindow(); +// OCCViewer_Viewer* anOCCViewer = ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer(); +// QString theImgFileName = backgroundImageFilename(); +// Handle(AIS_InteractiveContext) aContext = anOCCViewer->getAISContext(); +// +// gp_Pnt p1(0,0,0); +// gp_Pnt p2(0,100,0); +// gp_Pnt p3(100,100,0); +// gp_Pnt p4(100,0,0); +// +// BRepBuilderAPI_MakePolygon Wire(p1,p2,p3,p4, Standard_True); +// BRepBuilderAPI_MakeFace Face(Wire,Standard_True); +// const TopoDS_Shape& S = Face.Shape(); +// Handle(AIS_TexturedShape) anAIS = new AIS_TexturedShape(S); +// if (!theImgFileName.isEmpty()) +// { +// MESSAGE("filename is not empty") +// anAIS->SetTextureFileName(TCollection_AsciiString(theImgFileName.toStdString().c_str())); +// anAIS->SetTextureMapOn(); +// activeView()->SetSurfaceDetail(V3d_TEX_ALL); +// // anAIS->SetDisplayMode(AIS_Shaded); +// } +// else +// anAIS->SetTextureMapOff(); +// //creation of the presentable object +// aContext->SetDisplayMode(anAIS,3); +// aContext->SetMaterial(anAIS,Graphic3d_NOM_SATIN); +// aContext->Display(anAIS); +// aContext->UpdateCurrentViewer(); +// } } /*! diff --git a/src/OCCViewer/OCCViewer_ViewPort3d.h b/src/OCCViewer/OCCViewer_ViewPort3d.h index 7eccb6c43..72fc74de2 100755 --- a/src/OCCViewer/OCCViewer_ViewPort3d.h +++ b/src/OCCViewer/OCCViewer_ViewPort3d.h @@ -59,6 +59,9 @@ public: virtual QString backgroundImageFilename() const; virtual void setBackgroundImage( const QString& fileName , const Aspect_FillMethod& theFillMethod); + + virtual int getBgImgHeight(){return myBgImgHeight; }; + virtual int getBgImgWidth() {return myBgImgWidth; }; // void setActive( V3d_TypeOfView ); virtual bool syncronize( const OCCViewer_ViewPort3d* ); @@ -111,6 +114,8 @@ private: double myScale; bool myIsAdvancedZoomingEnabled; QString myBackgroundImageFilename; + int myBgImgHeight; + int myBgImgWidth; }; #ifdef WIN32 diff --git a/src/OCCViewer/OCCViewer_ViewWindow.cxx b/src/OCCViewer/OCCViewer_ViewWindow.cxx index 2388b95de..c5e8d1833 100755 --- a/src/OCCViewer/OCCViewer_ViewWindow.cxx +++ b/src/OCCViewer/OCCViewer_ViewWindow.cxx @@ -58,10 +58,20 @@ #include #include #include +#include + +#include +#include +#include +#include + +#include +#include #include #include #include +#include #include #include @@ -78,6 +88,12 @@ #include +#include "utilities.h" + +// OpenCV includes +#include +#include + static QEvent* l_mbPressEvent = 0; #ifdef WIN32 @@ -820,6 +836,7 @@ void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent ) myViewPort->setCursor( handCursor ); } } + emit mouseMoving( this, theEvent ); } else if ( anInteractionStyle == SUIT_ViewModel::STANDARD && aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) { @@ -2248,6 +2265,7 @@ void OCCViewer_ViewWindow::onSketchingStarted() */ void OCCViewer_ViewWindow::onSketchingFinished() { + MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()") if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept ) { Handle(AIS_InteractiveContext) ic = myModel->getAISContext(); @@ -2263,6 +2281,7 @@ void OCCViewer_ViewWindow::onSketchingFinished() int aRight = aRect->right(); int aTop = aRect->top(); int aBottom = aRect->bottom(); +// myRect = aRect; if( append ) ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False ); @@ -2398,7 +2417,48 @@ QString OCCViewer_ViewWindow::backgroundImageFilename() const void OCCViewer_ViewWindow::setBackgroundImage( const QString& theFileName,const Aspect_FillMethod& theFillMethod) { - if ( myViewPort ) myViewPort->setBackgroundImage( theFileName ,theFillMethod); + if ( myViewPort ) + { + myViewPort->setBackgroundImage( theFileName ,theFillMethod); + // set2dMode(XYPlane); + // onTopView(); + //TEST + OCCViewer_Viewer* anOCCViewer = ((OCCViewer_ViewManager*)getViewManager())->getOCCViewer(); + // QString theImgFileName = backgroundImageFilename(); + Handle(AIS_InteractiveContext) aContext = anOCCViewer->getAISContext(); + + IplImage* img = cvLoadImage( theFileName.toStdString().c_str(),CV_LOAD_IMAGE_GRAYSCALE); + int height = img->height; + int width = img->width; + + gp_Pnt p1(0,0,0); + gp_Pnt p2(0,height,0); + gp_Pnt p3(width,height,0); + gp_Pnt p4(width,0,0); + + BRepBuilderAPI_MakePolygon Wire(p1,p2,p3,p4, Standard_True); + BRepBuilderAPI_MakeFace Face(Wire,Standard_True); + const TopoDS_Shape& S = Face.Shape(); + Handle(AIS_TexturedShape) anAIS = new AIS_TexturedShape(S); + if (!theFileName.isEmpty()) + { + MESSAGE("filename is not empty") + anAIS->SetTextureFileName(TCollection_AsciiString(theFileName.toStdString().c_str())); + anAIS->SetTextureMapOn(); + anAIS->DisableTextureModulate(); + myViewPort->getView()->SetSurfaceDetail(V3d_TEX_ALL); + // anAIS->SetDisplayMode(AIS_Shaded); + } + else + anAIS->SetTextureMapOff(); + //creation of the presentable object + aContext->SetDisplayMode(anAIS,3); + aContext->SetMaterial(anAIS,Graphic3d_NOM_SATIN); + aContext->Display(anAIS); + onTopView(); + aContext->UpdateCurrentViewer(); + + } } /*! -- 2.39.2