From: Florian BRUNET Date: Thu, 23 Apr 2015 14:46:20 +0000 (+0200) Subject: first try for fix (doesn't compile) X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Frnc%2Fcontours_detection_bugfix;p=modules%2Fgeom.git first try for fix (doesn't compile) --- diff --git a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx index a2d7c67a2..303861beb 100644 --- a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx +++ b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx @@ -396,7 +396,7 @@ void EntityGUI_FeatureDetectorDlg::Init() //================================================================================= void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument() { - + MESSAGE("EntityGUI_FeatureDetectorDlg::SelectionIntoArgument()") // TODO supprimer les lignes qui ne servent à rien le cas échéant SUIT_ViewWindow* theViewWindow = getDesktop()->activeWindow(); std::map< std::string , std::vector >::iterator AISit; @@ -428,6 +428,7 @@ void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument() GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType ); TopoDS_Shape aShape; if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) { + MESSAGE("EntityGUI_FeatureDetectorDlg::SelectionIntoArgument() # REPERE 1") QString aName = GEOMBase::GetName( aSelectedObject.get() ); myEditCurrentArgument->setText( aName ); @@ -445,12 +446,17 @@ void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument() else return ; - std::string theImgFileName = myAISShape->TextureFile(); - if ( theImgFileName == "" ) - return ; + MESSAGE("EntityGUI_FeatureDetectorDlg::SelectionIntoArgument() # REPERE 2") + //std::string theImgFileName = myAISShape->TextureFile(); + Image_PixMap anImage = myAISShape->Image_PixMap(); +// MESSAGE("theImgFileName = "<SetPath( theImgFileName ); +// MESSAGE("theImgFileName = "<SetPath( theImgFileName ); + myDetector->SetImage( anImage ); height = myDetector->GetImgHeight(); width = myDetector->GetImgWidth(); pictureLeft = -0.5 * width; // X coordinate of the top left corner of the background image in the view @@ -677,8 +683,13 @@ void EntityGUI_FeatureDetectorDlg::setEndPnt(const gp_Pnt& theEndPnt) { myEndPnt = theEndPnt; MESSAGE("myEndPnt = ("<GetImgHeight() > 0; + MESSAGE("REPERE 0 : setSelectionRect() = "<GetImgHeight()"<GetImgHeight()) if (setSelectionRect() && myDetector->GetImgHeight() > 0) + { + MESSAGE("REPERE 1") showImageSample(); + } } //================================================================================= @@ -710,6 +721,7 @@ void EntityGUI_FeatureDetectorDlg::showImageSample() // Cropp the image to the selection rectangle given by the user myDetector->SetROI( myRect ); std::string samplePicturePath = myDetector->CroppImage(); + MESSAGE("samplePicturePath = "< +#include #ifdef WIN32 #if defined GEOM_SHAPEREC_EXPORTS || defined GEOMShapeRec_EXPORTS @@ -42,6 +43,57 @@ #define GEOM_SHAPEREC_EXPORT #endif + +// If inImage exists for the lifetime of the resulting cv::Mat, pass false to inCloneImageData to share inImage's +// data with the cv::Mat directly +// NOTE: Format_RGB888 is an exception since we need to use a local QImage and thus must clone the data regardless +inline cv::Mat QImageToCvMat( const QImage &inImage, bool inCloneImageData = true ) +{ + switch ( inImage.format() ) + { + // 8-bit, 4 channel + case QImage::Format_RGB32: + { + cv::Mat mat( inImage.height(), inImage.width(), CV_8UC4, const_cast(inImage.bits()), inImage.bytesPerLine() ); + + return (inCloneImageData ? mat.clone() : mat); + } + + // 8-bit, 3 channel + case QImage::Format_RGB888: + { + if ( !inCloneImageData ) + qWarning() << "ASM::QImageToCvMat() - Conversion requires cloning since we use a temporary QImage"; + + QImage swapped = inImage.rgbSwapped(); + + return cv::Mat( swapped.height(), swapped.width(), CV_8UC3, const_cast(swapped.bits()), swapped.bytesPerLine() ).clone(); + } + + // 8-bit, 1 channel + case QImage::Format_Indexed8: + { + cv::Mat mat( inImage.height(), inImage.width(), CV_8UC1, const_cast(inImage.bits()), inImage.bytesPerLine() ); + + return (inCloneImageData ? mat.clone() : mat); + } + + default: + qWarning() << "ASM::QImageToCvMat() - QImage format not handled in switch:" << inImage.format(); + break; + } + + return cv::Mat(); +} + +// If inPixmap exists for the lifetime of the resulting cv::Mat, pass false to inCloneImageData to share inPixmap's data +// with the cv::Mat directly +// NOTE: Format_RGB888 is an exception since we need to use a local QImage and thus must clone the data regardless +inline cv::Mat QPixmapToCvMat( const QPixmap &inPixmap, bool inCloneImageData = true ) +{ + return QImageToCvMat( inPixmap.toImage(), inCloneImageData ); +} + class GEOM_SHAPEREC_EXPORT ShapeRec_Parameters { public: