From abab708d83b68396ab353ff300f2185297597178 Mon Sep 17 00:00:00 2001 From: stv Date: Mon, 30 Mar 2015 12:40:28 +0300 Subject: [PATCH] Image from QImage object converted to Image_PixMap object without save/load temp file. Image drown directly in special presentattion without any topology objects (AIS_TexturedShape not used). --- src/HYDROGUI/CMakeLists.txt | 2 + src/HYDROGUI/HYDROGUI_ImagePrs.cxx | 107 +++++++++ src/HYDROGUI/HYDROGUI_ImagePrs.h | 42 ++++ .../HYDROGUI_ProfileInterpolateDlg.cxx | 7 +- src/HYDROGUI/HYDROGUI_ProfileInterpolateDlg.h | 1 + src/HYDROGUI/HYDROGUI_ShapeImage.cxx | 218 ++++-------------- src/HYDROGUI/HYDROGUI_ShapeImage.h | 22 +- src/HYDROGUI/HYDROGUI_Tool.cxx | 47 ++++ src/HYDROGUI/HYDROGUI_Tool.h | 9 + 9 files changed, 270 insertions(+), 185 deletions(-) create mode 100644 src/HYDROGUI/HYDROGUI_ImagePrs.cxx create mode 100644 src/HYDROGUI/HYDROGUI_ImagePrs.h diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 963da067..d1586649 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -25,6 +25,7 @@ set(PROJECT_HEADERS HYDROGUI_Displayer.h HYDROGUI_ExportImageOp.h HYDROGUI_GVSelector.h + HYDROGUI_ImagePrs.h HYDROGUI_ImmersibleZoneDlg.h HYDROGUI_ImmersibleZoneOp.h HYDROGUI_ImportBathymetryDlg.h @@ -134,6 +135,7 @@ set(PROJECT_SOURCES HYDROGUI_Displayer.cxx HYDROGUI_ExportImageOp.cxx HYDROGUI_GVSelector.cxx + HYDROGUI_ImagePrs.cxx HYDROGUI_ImmersibleZoneDlg.cxx HYDROGUI_ImmersibleZoneOp.cxx HYDROGUI_ImportBathymetryDlg.cxx diff --git a/src/HYDROGUI/HYDROGUI_ImagePrs.cxx b/src/HYDROGUI/HYDROGUI_ImagePrs.cxx new file mode 100644 index 00000000..b178b6f3 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ImagePrs.cxx @@ -0,0 +1,107 @@ +#include "HYDROGUI_ImagePrs.h" + +#include + +#include +#include +#include +#include + +IMPLEMENT_STANDARD_TYPE(HYDROGUI_ImagePrs) +IMPLEMENT_STANDARD_SUPERTYPE_ARRAY() + STANDARD_TYPE(AIS_InteractiveObject), + STANDARD_TYPE(SelectMgr_SelectableObject), + STANDARD_TYPE(PrsMgr_PresentableObject), + STANDARD_TYPE(MMgt_TShared), + STANDARD_TYPE(Standard_Transient), +IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_END() +IMPLEMENT_STANDARD_TYPE_END(HYDROGUI_ImagePrs) + +IMPLEMENT_DOWNCAST(HYDROGUI_ImagePrs,Standard_Transient) +IMPLEMENT_STANDARD_RTTI(HYDROGUI_ImagePrs) + +HYDROGUI_ImagePrs::HYDROGUI_ImagePrs() + : AIS_InteractiveObject() +{ +// SetTransformPersistence( Graphic3d_TMF_2d ); +// SetZLayer( Graphic3d_ZLayerId_TopOSD ); +} + +HYDROGUI_ImagePrs::HYDROGUI_ImagePrs( const Handle(Image_PixMap)& theImage, const QPolygonF& theContour ) + : AIS_InteractiveObject(), + myImage( theImage ), + myContour( theContour ) +{ +} + +HYDROGUI_ImagePrs::~HYDROGUI_ImagePrs() +{ +} + +QPolygonF HYDROGUI_ImagePrs::GetContour() const +{ + return myContour; +} + +void HYDROGUI_ImagePrs::SetContour( const QPolygonF& theRect ) +{ + if ( myContour != theRect ) + SetToUpdate(); + + myContour = theRect; +} + +Handle(Image_PixMap) HYDROGUI_ImagePrs::GetImage() const +{ + return myImage; +} + +void HYDROGUI_ImagePrs::SetImage( const Handle(Image_PixMap)& theImage ) +{ + if ( myImage != theImage ) + SetToUpdate(); + + myImage = theImage; +} + +void HYDROGUI_ImagePrs::ComputeSelection( const Handle(SelectMgr_Selection)&, const Standard_Integer ) +{ +} + +void HYDROGUI_ImagePrs::Compute( const Handle(PrsMgr_PresentationManager3d)&, + const Handle(Prs3d_Presentation)& aPrs, const Standard_Integer ) +{ + aPrs->Clear(); + + if ( aPrs.IsNull() || myImage.IsNull() ) + return; + + Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aPrs ); + + Graphic3d_MaterialAspect aMat( Graphic3d_NOM_PLASTIC ); + aMat.SetTransparency( 0.5 ); + Handle(Graphic3d_AspectFillArea3d) aFillAspect = + new Graphic3d_AspectFillArea3d( Aspect_IS_SOLID, Quantity_NOC_WHITE, Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0, aMat, aMat ); + + Handle(Graphic3d_TextureMap) aTex = new Graphic3d_Texture2Dmanual( myImage ); + aFillAspect->SetTextureMapOn(); + aFillAspect->SetTextureMap( aTex ); + + Handle(Graphic3d_ArrayOfTriangles) aTriangles = new Graphic3d_ArrayOfTriangles( 6, 0, Standard_False, Standard_False, Standard_True ); + + aTriangles->AddVertex( convert( myContour[0] ), gp_Pnt2d( 0, myImage->IsTopDown() ? 0 : 1 ) ); + aTriangles->AddVertex( convert( myContour[1] ), gp_Pnt2d( 1, myImage->IsTopDown() ? 0 : 1 ) ); + aTriangles->AddVertex( convert( myContour[2] ), gp_Pnt2d( 1, myImage->IsTopDown() ? 1 : 0 ) ); + + aTriangles->AddVertex( convert( myContour[2] ), gp_Pnt2d( 1, myImage->IsTopDown() ? 1 : 0 ) ); + aTriangles->AddVertex( convert( myContour[3] ), gp_Pnt2d( 0, myImage->IsTopDown() ? 1 : 0 ) ); + aTriangles->AddVertex( convert( myContour[0] ), gp_Pnt2d( 0, myImage->IsTopDown() ? 0 : 1 ) ); + + aGroup->SetGroupPrimitivesAspect( aFillAspect ); + aGroup->AddPrimitiveArray( aTriangles ); +} + +gp_Pnt HYDROGUI_ImagePrs::convert( const QPointF& thePoint ) const +{ + return gp_Pnt( thePoint.x(), thePoint.y(), 0 ); +} diff --git a/src/HYDROGUI/HYDROGUI_ImagePrs.h b/src/HYDROGUI/HYDROGUI_ImagePrs.h new file mode 100644 index 00000000..3ad570f9 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ImagePrs.h @@ -0,0 +1,42 @@ +#ifndef HYDROGUI_IMAGEPRS_H +#define HYDROGUI_IMAGEPRS_H + +#include + +#include + +#include + +class Font_FTFont; +class HYDROGUI_ImagePrs; + +DEFINE_STANDARD_HANDLE(HYDROGUI_ImagePrs, AIS_InteractiveObject) + +class HYDROGUI_ImagePrs : public AIS_InteractiveObject +{ +public: + HYDROGUI_ImagePrs(); + HYDROGUI_ImagePrs( const Handle(Image_PixMap)&, const QPolygonF& ); + virtual ~HYDROGUI_ImagePrs(); + + QPolygonF GetContour() const; + void SetContour( const QPolygonF& ); + + Handle(Image_PixMap) GetImage() const; + void SetImage( const Handle(Image_PixMap)& ); + + virtual void Compute( const Handle(PrsMgr_PresentationManager3d)&, + const Handle(Prs3d_Presentation)&, const Standard_Integer = 0 ); + virtual void ComputeSelection( const Handle(SelectMgr_Selection)&, const Standard_Integer ); + + DEFINE_STANDARD_RTTI(HYDROGUI_ImagePrs) + +private: + gp_Pnt convert( const QPointF& ) const; + +private: + Handle(Image_PixMap) myImage; + QPolygonF myContour; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_ProfileInterpolateDlg.cxx b/src/HYDROGUI/HYDROGUI_ProfileInterpolateDlg.cxx index a66a7183..42351f79 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileInterpolateDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ProfileInterpolateDlg.cxx @@ -91,7 +91,7 @@ HYDROGUI_ProfileInterpolateDlg::HYDROGUI_ProfileInterpolateDlg( HYDROGUI_Module* connect( myProfileFinish, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( profileFinishChanged( const QString& ) ) ); connect( myProfileNumber, SIGNAL( valueChanged( int ) ), this, SIGNAL( profileNumberChanged( int ) ) ); - connect( myParams, SIGNAL( textChanged( const QString& ) ), this, SIGNAL( interpolatorParametersChanged( const QString& ) ) ); + connect( myParams, SIGNAL( editingFinished() ), this, SIGNAL( onParametersEditingFinished() ) ); new HYDROGUI_OCCSelector( module(), viewer(), selectionMgr() ); @@ -220,6 +220,11 @@ void HYDROGUI_ProfileInterpolateDlg::reset() myDescr->clear(); } +void HYDROGUI_ProfileInterpolateDlg::onParametersEditingFinished() +{ + emit interpolatorParametersChanged( myParams->text() ); +} + void HYDROGUI_ProfileInterpolateDlg::onRiverChanged( const QString& theName ) { myRiverProfiles.clear(); diff --git a/src/HYDROGUI/HYDROGUI_ProfileInterpolateDlg.h b/src/HYDROGUI/HYDROGUI_ProfileInterpolateDlg.h index ec7ef984..e24b30c7 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileInterpolateDlg.h +++ b/src/HYDROGUI/HYDROGUI_ProfileInterpolateDlg.h @@ -81,6 +81,7 @@ signals: void profileFinishChanged( const QString& ); private slots: + void onParametersEditingFinished(); void onRiverChanged( const QString& ); void onInterpolatorIndexChanged( int ); void onProfileChanged( const QString& ); diff --git a/src/HYDROGUI/HYDROGUI_ShapeImage.cxx b/src/HYDROGUI/HYDROGUI_ShapeImage.cxx index 8e54e983..9b56208a 100644 --- a/src/HYDROGUI/HYDROGUI_ShapeImage.cxx +++ b/src/HYDROGUI/HYDROGUI_ShapeImage.cxx @@ -21,20 +21,14 @@ // #include -#include + #include -#include +#include + #include +#include -#include -#include -#include #include -#include -#include - -#include -#include HYDROGUI_ShapeImage::HYDROGUI_ShapeImage( const Handle(AIS_InteractiveContext)& theContext, const Handle_HYDROData_Image& theImage, @@ -45,181 +39,71 @@ HYDROGUI_ShapeImage::HYDROGUI_ShapeImage( const Handle(AIS_InteractiveContext)& HYDROGUI_ShapeImage::~HYDROGUI_ShapeImage() { - removeTextureFile(); } void HYDROGUI_ShapeImage::update( bool theIsUpdateViewer, bool isDeactivateSelection ) { setIsToUpdate( false ); - // Try to retrieve information from object - Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( getObject() ); - - if( !anImageObj.IsNull() ) - { - removeTextureFile(); - - QString aTextureFileName = generateTextureFileName( anImageObj ); - - QImage anImage = anImageObj->Image(); - QString aFilePath = anImageObj->GetFilePath(); - QTransform aTrsf = anImageObj->Trsf(); - - int aWidth = anImage.width(); - int aHeight = anImage.height(); - - QString anImageError = ""; - - QTransform anInversion = QTransform::fromScale( -1, -1 ); - anImage = anImage.transformed( anInversion * aTrsf, Qt::SmoothTransformation ); - - if ( anImage.isNull() ) - anImageError = QObject::tr( "IMAGE_TRANSFORMATION_CAN_NOT_BE_APPLYED" ); - else - { - // Workaround: Scale the texture image to the nearest width multiple 4 due to the CASCADE bug 23813 - int aTrsfWidth = anImage.width(); - int aDelta = aTrsfWidth % 4; - if ( aDelta > 0 ) - { - aTrsfWidth += ( 4 - aDelta ); - } - anImage = anImage.scaledToWidth( aTrsfWidth ); - - // temporary optimization, to reduce the saved image size (and the texture quality) - QImage anImageToSave = anImage; //RKV:reduceTexture( anImage, 500 ); - - bool isSaved = anImageToSave.save( aTextureFileName ); - if ( !isSaved ) - anImageError = QObject::tr( "FILE_CAN_NOT_BE_CREATED" ).arg( aTextureFileName ); - else - QFile::setPermissions( aTextureFileName, (QFile::Permissions)0x4FFFF ); - } - - if ( !anImageError.isEmpty() ) - { - SUIT_MessageBox::warning( 0, QObject::tr( "SHAPE_IMAGE_ERROR" ), - QObject::tr( "IMAGE_CAN_NOT_BE_CREATED" ) + anImageError ); - } + buildShape(); - QPointF aPoint1( 0, 0 ); // 1: top left - QPointF aPoint2( aWidth, 0 ); // 2: top right - QPointF aPoint3( aWidth, aHeight ); // 3: bottom right - QPointF aPoint4( 0, aHeight ); // 4: bottom left - - aPoint1 = aTrsf.map( aPoint1 ); - aPoint2 = aTrsf.map( aPoint2 ); - aPoint3 = aTrsf.map( aPoint3 ); - aPoint4 = aTrsf.map( aPoint4 ); - - QPolygonF aPolygon = QPolygonF() << aPoint1 << aPoint2 << aPoint3 << aPoint4; - QRectF aRect = aPolygon.boundingRect(); - - gp_Pnt aPnt1( aRect.topLeft().x(), aRect.topLeft().y(), 0 ); - gp_Pnt aPnt2( aRect.topRight().x(), aRect.topRight().y(), 0 ); - gp_Pnt aPnt3( aRect.bottomRight().x(), aRect.bottomRight().y(), 0 ); - gp_Pnt aPnt4( aRect.bottomLeft().x(), aRect.bottomLeft().y(), 0 ); - - Handle_HYDROData_Document aDoc = HYDROData_Document::Document( anImageObj->Label() ); - aDoc->Transform( aPnt1, true ); - aDoc->Transform( aPnt2, true ); - aDoc->Transform( aPnt3, true ); - aDoc->Transform( aPnt4, true ); - - TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge(); - TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge( aPnt2, aPnt3 ).Edge(); - TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge( aPnt3, aPnt4 ).Edge(); - TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge( aPnt4, aPnt1 ).Edge(); - - TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge1, anEdge2, anEdge3, anEdge4 ).Wire(); - aWire.Closed( true ); - - setTextureFileName( aTextureFileName, false, false ); - setFace( aWire, false, false, aTextureFileName ); - isDeactivateSelection = true; - } - HYDROGUI_Shape::update( theIsUpdateViewer, isDeactivateSelection ); } -void HYDROGUI_ShapeImage::setTextureFileName( const QString& theFileName, - const bool theToDisplay, - const bool theIsUpdateViewer ) +Handle(AIS_InteractiveObject) HYDROGUI_ShapeImage::createShape() const { - myTextureFileName = theFileName; - updateShape( theToDisplay, theIsUpdateViewer ); -} - -QString HYDROGUI_ShapeImage::getTextureFileName() const -{ - return myTextureFileName; -} - -QString HYDROGUI_ShapeImage::generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj ) -{ - QString aResult; - if( !theImageObj.IsNull() ) - { - QString aTempDir = HYDROGUI_Tool::GetTempDir( true ); - - int aStudyId = HYDROGUI_Tool::GetActiveStudyId(); - QString aPrefix = QString( "image_%1" ).arg( aStudyId ); - - QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theImageObj, false ); - anEntry.replace( ':', '_' ); - - QString anExtension = "bmp"; + Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( getObject() ); + if ( anImageObj.IsNull() ) + return Handle_AIS_InteractiveObject(); - aResult = QString( "%1/%2_%3.%4" ).arg( aTempDir, aPrefix, anEntry, anExtension ); - } - return aResult; + Handle(HYDROGUI_ImagePrs) aPrs = new HYDROGUI_ImagePrs( imagePixMap( anImageObj ), imageContour( anImageObj ) ); + return aPrs; } -void HYDROGUI_ShapeImage::removeTextureFile() const +Handle(Image_PixMap) HYDROGUI_ShapeImage::imagePixMap( const Handle(HYDROData_Image)& theImageObj ) const { - QFile aFile( getTextureFileName() ); - if( aFile.exists() ) - aFile.remove(); -} - -QImage HYDROGUI_ShapeImage::reduceTexture( const QImage& theImage, const int theSizeLimit ) -{ - double aSizeLimit = (double)theSizeLimit; - double aWidth = (double)theImage.width(); - double aHeight = (double)theImage.height(); - if( aWidth > aSizeLimit || aHeight > aSizeLimit ) - { - if( aWidth > aHeight ) - { - aHeight /= ( aWidth / aSizeLimit ); - aWidth = aSizeLimit; - } - else + Handle(Image_PixMap) aPix; + if ( !theImageObj.IsNull() ) { - aWidth /= ( aHeight / aSizeLimit ); - aHeight = aSizeLimit; + QTransform aTrsf = theImageObj->Trsf(); + QImage anImage = theImageObj->Image(); +// anImage = anImage.transformed( QTransform::fromScale( -1, -1 ) * aTrsf, Qt::SmoothTransformation ); + + if ( !anImage.isNull() ) + { + // Workaround: Scale the texture image to the nearest width multiple 4 due to the CASCADE bug 23813 + int aTrsfWidth = anImage.width(); + int aDelta = aTrsfWidth % 4; + if ( aDelta > 0 ) + aTrsfWidth += ( 4 - aDelta ); + + anImage = anImage.scaledToWidth( aTrsfWidth ); + + aPix = HYDROGUI_Tool::Pixmap( anImage ); + } } - } - return theImage.scaled( aWidth, aHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation ); + return aPix; } -Handle_AIS_InteractiveObject HYDROGUI_ShapeImage::createShape() const +QPolygonF HYDROGUI_ShapeImage::imageContour( const Handle_HYDROData_Image& theImageObj ) const { - QString aTextureFileName = getTextureFileName(); - bool anIsTexture = !aTextureFileName.isEmpty(); - if ( anIsTexture ) - { - Handle_AIS_TexturedShape aTexturedShape = new AIS_TexturedShape( getTopoShape() ); - - aTexturedShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) ); - aTexturedShape->SetTextureMapOn(); - // Just use the texture image as is - aTexturedShape->DisableTextureModulate(); - aTexturedShape->SetTextureRepeat( false ); // don't repeat the texture image on the face - - return aTexturedShape; - } - else - return Handle_AIS_InteractiveObject(); + QPolygonF aContour; + if ( !theImageObj.IsNull() ) + { + QTransform aTrsf = theImageObj->Trsf(); + QImage anImage = theImageObj->Image(); + + QPolygonF aPolygon = QPolygonF() << QPointF( 0, 0 ) << QPointF( anImage.width(), 0 ) + << QPointF( anImage.width(), anImage.height() ) << QPointF( 0, anImage.height() ); + aPolygon = aTrsf.map( aPolygon ); + + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( theImageObj->Label() ); + for ( QPolygonF::iterator it = aPolygon.begin(); it != aPolygon.end(); ++it ) + { + gp_Pnt aPnt( (*it).x(), (*it).y(), 0 ); + aDoc->Transform( aPnt, true ); + aContour.append( QPointF( aPnt.X(), aPnt.Y() ) ); + } + } + return aContour; } - diff --git a/src/HYDROGUI/HYDROGUI_ShapeImage.h b/src/HYDROGUI/HYDROGUI_ShapeImage.h index f028dd75..ed7347f8 100644 --- a/src/HYDROGUI/HYDROGUI_ShapeImage.h +++ b/src/HYDROGUI/HYDROGUI_ShapeImage.h @@ -25,8 +25,9 @@ #include +#include + class Handle_HYDROData_Image; -class QImage; class HYDROGUI_ShapeImage : public HYDROGUI_Shape { @@ -36,25 +37,12 @@ public: const int theZLayer = -1 ); virtual ~HYDROGUI_ShapeImage(); - virtual void setTextureFileName( const QString& theFileName, - const bool theToDisplay = true, - const bool theIsUpdateViewer = true ); - virtual QString getTextureFileName() const; - - virtual void update( bool isUpdateViewer, - bool isDeactivateSelection ); + virtual void update( bool isUpdateViewer, bool isDeactivateSelection ); protected: virtual Handle_AIS_InteractiveObject createShape() const; - -private: - static QString generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj ); - void removeTextureFile() const; - - static QImage reduceTexture( const QImage& theImage, const int theSizeLimit ); - -private: - QString myTextureFileName; + Handle(Image_PixMap) imagePixMap( const Handle_HYDROData_Image& ) const; + QPolygonF imageContour( const Handle_HYDROData_Image& ) const; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index f2e3f6fe..dce2fd85 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -730,3 +730,50 @@ QString HYDROGUI_Tool::GetCoordinateString( const double theNumber, bool isInLoc return QString::number( theNumber, 'f', 2 ); } +Handle(Image_PixMap) HYDROGUI_Tool::Pixmap( const QImage& theImage ) +{ + Handle(Image_PixMap) pix; + if ( theImage.isNull() || theImage.format() == QImage::Format_Invalid ) + return pix; + + Handle(Image_PixMap) tmpPix = new Image_PixMap(); + tmpPix->SetTopDown( false ); + QImage anImage = theImage.mirrored(); + if ( !anImage.hasAlphaChannel() && anImage.allGray() ) + { + tmpPix->InitTrash( Image_PixMap::ImgGray, anImage.width(), anImage.height(), anImage.width() ); + for ( int r = 0; r < anImage.height(); r++ ) + { + Standard_Byte* aRowData = tmpPix->ChangeRow( anImage.height() - r - 1 ); + for ( int p = 0; p < anImage.width(); p++ ) + aRowData[p] = qRed( anImage.pixel( p, r ) ); + } + } + else + { + Image_PixMap::ImgFormat aFormat; + if ( anImage.hasAlphaChannel() ) + { + if ( anImage.format() != QImage::Format_ARGB32 ) + anImage = anImage.convertToFormat( QImage::Format_ARGB32 ); + aFormat = Image_PixMap::ImgRGBA; + } + else + { + if ( anImage.format() != QImage::Format_RGB888 ) + anImage = anImage.convertToFormat( QImage::Format_RGB888 ); + aFormat = Image_PixMap::ImgRGB; + } + + tmpPix->InitWrapper( aFormat, (Standard_Byte*)anImage.bits(), anImage.width(), anImage.height(), anImage.bytesPerLine() ); + } + + if ( !tmpPix.IsNull() ) + { + pix = new Image_PixMap(); + pix->InitCopy( *tmpPix.operator->() ); + pix->SetTopDown( tmpPix->IsTopDown() ); + } + + return pix; +} diff --git a/src/HYDROGUI/HYDROGUI_Tool.h b/src/HYDROGUI/HYDROGUI_Tool.h index 1fd8154c..1a9100b1 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.h +++ b/src/HYDROGUI/HYDROGUI_Tool.h @@ -33,6 +33,8 @@ #include #include +#include + // IDL includes #include #include CORBA_SERVER_HEADER(GEOM_Gen) @@ -344,6 +346,13 @@ public: * \return coordinate as a string */ static QString GetCoordinateString( const double theNumber, bool isInLocale ); + + /** + * \brief Converts Qt QImage object to OCCT Image_PixMap object. + * \param theImage QImage object + * \return Image_PixMap object + */ + static Handle(Image_PixMap) Pixmap( const QImage& theImage ); }; #endif -- 2.39.2